SUNphi  1.0
LoopUnroll.hpp
Go to the documentation of this file.
1 #ifndef _LOOP_UNROLL_HPP
2 #define _LOOP_UNROLL_HPP
3 
4 /// \file LoopUnroll.hpp
5 ///
6 /// \brief Unroll iteratively a loop
7 
8 #include <metaprogramming/Inline.hpp>
9 #include <metaprogramming/UniversalReferences.hpp>
10 
11 namespace SUNphi
12 {
13  /// Unroll a loop in the range [min,max)
14  ///
15  /// The called function must take as a first argument the iteration
16  template <int min, // Minimal value
17  int max, // Maximal (excluded) value
18  typename F, // Type of the function
19  typename...Args> // Types of the arguments to pass
20  ALWAYS_INLINE void loopUnroll(F f, ///< Function to cal
21  Args&&...args) ///< Arguments to pass
22  {
23  /// Current value
24  constexpr int cur=
25  min;
26 
27  /// Next value
28  constexpr int next=
29  cur+1;
30 
31  // Exec the function
32  f(cur,forw<Args>(args)...);
33 
34  // Iterates on the loop
35  if constexpr(next<max)
36  loopUnroll<next,max,F,Args...>(f,forw<Args>(args)...);
37  }
38 }
39 
40 #endif
decltype(auto) operator+(T1 &&smet1, T2 &&smet2)
Implement smet1+smet2.
Definition: Add.hpp:87
Args && args
< Function to cal
Definition: LoopUnroll.hpp:22
#define ALWAYS_INLINE
Force inlining of a function.
Definition: Inline.hpp:9