IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
ModuloReg.h
Go to the documentation of this file.
1 // ModuloReg.h:
3 // -------------------
4 //
13 
14 #ifndef __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_COMMON_MODULOREG_H__
15 #define __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_COMMON_MODULOREG_H__
16 
21 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/FloorReg.h>
30 
31 namespace ipsdk {
32 namespace simd {
33 namespace detail {
34 
37 
39 template <eInstructionSet::domain IS, typename T>
40 struct ModuloReg<
41  IS,
42  T,
43  typename boost::enable_if<typename boost::is_integral<T>::type>::type
44 >
45 {
46  static IPSDK_FORCEINLINE
47  typename RegType<IS, T>::Type
48  act(const typename RegType<IS, T>::Type& in1,
49  const typename RegType<IS, T>::Type& in2)
50  {
51  typename RegType<IS, T>::Type out;
52  act(in1, in2, out);
53  return out;
54  }
55 
56  static IPSDK_FORCEINLINE
57  void
58  act(const typename RegType<IS, T>::Type& in,
59  const typename RegType<IS, T>::Type& m,
60  typename RegType<IS, T>::Type& out)
61  {
62  typename RegType<IS, T>::Type cste0, cste1;
63  AssignReg<IS, T>::act(cste0, 0);
64  AssignReg<IS, T>::act(cste1, 1);
65 
66  // process integer division
67  typename RegType<IS, T>::Type n, nM1;
68  DivReg<IS, T>::act(in, m, n);
69  SubReg<IS, T>::act(n, cste1, nM1);
70 
71  // compute two solutions for modulo operation :
72  // -> in - n*mod if in >= 0
73  // -> in - (n-1)*mod if in < 0
74  typename RegMaskType<IS, T>::Type test;
75  IsGreaterEqualReg<IS, T>::act(in, cste0, test);
76  typename RegType<IS, T>::Type res;
77  IfElseReg<IS, T>::act(test, n, nM1, res);
78  MulReg<IS, T>::act(res, m, res);
79  SubReg<IS, T>::act(in, res, out);
80  }
81 };
82 
84 template <eInstructionSet::domain IS, typename T>
85 struct ModuloReg<
86  IS,
87  T,
88  typename boost::enable_if<
89  typename boost::mpl::not_<
90  typename boost::is_integral<T>::type
91  >::type
92  >::type
93 >
94 {
95  static IPSDK_FORCEINLINE
96  typename RegType<IS, T>::Type
97  act(const typename RegType<IS, T>::Type& in1,
98  const typename RegType<IS, T>::Type& in2)
99  {
100  typename RegType<IS, T>::Type out;
101  act(in1, in2, out);
102  return out;
103  }
104 
105  static IPSDK_FORCEINLINE
106  void
107  act(const typename RegType<IS, T>::Type& in,
108  const typename RegType<IS, T>::Type& m,
109  typename RegType<IS, T>::Type& out)
110  {
111  // process integer division
112  typename RegType<IS, T>::Type n;
113  DivReg<IS, T>::act(in, m, n);
114  FloorReg<IS, T>::act(n, n);
115 
116  typename RegType<IS, T>::Type res;
117  MulReg<IS, T>::act(n, m, res);
118  SubReg<IS, T>::act(in, res, res);
119 
120  // bound result to range [0; m[
121  typename RegType<IS, T>::Type zero;
122  AssignReg<IS, T>::act(zero, 0);
123  MaxReg<IS, T>::act(res, zero, res);
124 
125  typename RegMaskType<IS, T>::Type test;
126  IsGreaterEqualReg<IS, T>::act(res, m, test);
127  IfElseReg<IS, T>::act(test, m, res, out);
128  }
129 };
130 
133 
134 } // end of namespace detail
135 } // end of namespace simd
136 } // end of namespace ipsdk
137 
138 #endif // __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_COMMON_MODULOREG_H__
Defines the IPSDK_FORCEINLINE.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: DivReg.h:39
template structure which is specialized to implement the minimum computation on 2 scalars or 2 regist...
Definition: SubReg.h:39
Definition: ModuloReg.h:34
template structure which is specialized to implement the maximum computation on 2 scalars or 2 regist...
template structure which is specialized to implement the computation of value rounded to closest even...
Definition: FloorReg.h:36
Definition: DataItemNodeHdrMacrosDetails.h:48
Definition: IsGreaterEqualRegDecl.h:30
RegType class.
Definition: MaxRegDecl.h:29
RegMaskType class.
Definition of import/export macro for library.
Definition: IfElseReg.h:33
Definition: MulReg.h:39
Definition: RegMaskType.h:29
Definition: RegType.h:29
Definition: AssignRegDecl.h:31