IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
SignedUnsignedOpReg.h
Go to the documentation of this file.
1 // SignedUnsignedOpReg.h:
3 // -------------------
4 //
14 
15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_AVX2_SIGNEDUNSIGNEDOPREG_H__
16 #define __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_AVX2_SIGNEDUNSIGNEDOPREG_H__
17 
20 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/SignedUnsignedOpReg.h>
32 
33 namespace ipsdk {
34 namespace simd {
35 namespace detail {
36 
39 
42 template<typename T>
44  T, /* signed */ false>
45 {
46  typedef typename AvxType<T>::Type result_type;
47 
48  static IPSDK_FORCEINLINE
49  result_type act(const typename AvxType<T>::Type& x,
50  const typename AvxType<T>::Type& y)
51  {
53  }
54 
55  static IPSDK_FORCEINLINE
56  void act(const typename AvxType<T>::Type& x,
57  const typename AvxType<T>::Type& y,
58  result_type& out)
59  {
61  }
62 };
63 
66 template<typename T>
68  T, /* signed */ true>
69 {
70  typedef typename boost::make_unsigned<T>::type unsigned_type;
71  typedef typename AvxType<unsigned_type>::Type result_type;
72 
73  static IPSDK_FORCEINLINE
74  result_type act(const typename AvxType<T>::Type& x,
75  const typename AvxType<T>::Type& y)
76  {
77  const typename AvxType<T>::Type zero =
79 
80  const typename AvxType<T>::Type yNeg =
82 
83  const typename AvxType<T>::Type xNeg =
85 
86  const typename AvxType<T>::Type yNegAndXNotNeg =
88 
89  const typename AvxType<T>::Type one =
91 
93  yNegAndXNotNeg,
94 
95  // avoid the nasty two's complement case for y == min()
96  // return result_type(x) + result_type(-(y+1)) + 1;
99  x,
102  one),
103 
104  // return result_type(x - y);
106  //return SubReg<eInstructionSet::eIS_Avx2, unsigned_type>::act(x, y);
107  }
108 
109  static IPSDK_FORCEINLINE
110  void act(const typename AvxType<T>::Type& x,
111  const typename AvxType<T>::Type& y,
112  result_type& out)
113  {
114  const typename AvxType<T>::Type zero =
116 
117  const typename AvxType<T>::Type one =
119 
120  typename AvxType<T>::Type yNeg;
122 
123  typename AvxType<T>::Type xNeg;
125 
126  typename AvxType<T>::Type yNegAndXNotNeg;
127  BitwiseAndNotReg<eInstructionSet::eIS_Avx2, T>::act(yNeg, xNeg, yNegAndXNotNeg);
128 
129  typename AvxType<T>::Type a_t;
130  typename AvxType<unsigned_type>::Type a, b;
131 
134  cast<eInstructionSet::eIS_Avx2, T, unsigned_type>(a_t, a);
137 
139 
141  yNegAndXNotNeg, a, b, out);
142  }
143 };
144 
147 template<typename T1, typename T2>
149  T1, T2, /* signed */ false>
150 {
151  typedef typename AvxType<T2>::Type result_type;
152 
153  static IPSDK_FORCEINLINE
154  result_type act(const typename AvxType<T1>::Type& x,
155  const typename AvxType<T2>::Type& y)
156  {
158  }
159 
160  static IPSDK_FORCEINLINE
161  void act(const typename AvxType<T1>::Type& x,
162  const typename AvxType<T2>::Type& y,
163  result_type& out)
164  {
166  }
167 };
168 
171 template<typename T1, typename T2>
173  T1, T2, /* signed */ true>
174 {
175  typedef typename AvxType<T2>::Type result_type;
176 
177  static IPSDK_FORCEINLINE
178  result_type act(const typename AvxType<T1>::Type& x,
179  const typename AvxType<T2>::Type& y)
180  {
181  const typename AvxType<T1>::Type zero =
183 
184  const typename AvxType<T2>::Type one =
186 
187  const typename AvxType<T1>::Type yNeg =
189 
190  const typename AvxType<T1>::Type minusYPlusOne =
193 
194  const typename AvxType<T1>::Type xGtThnMinusYPlusOne =
196 
197  const typename AvxType<T1>::Type yNegAndXGtThnMinusYPlusOne =
199  yNeg, xGtThnMinusYPlusOne);
200 
201 
203  yNegAndXGtThnMinusYPlusOne,
204 
205  // avoid the nasty two's complement edge case for y == min()
206  // return T2(x - T1(-(y+1)) - 1);
209  x, minusYPlusOne),
210  one),
211  // return T2(x) + y;
213  //return AddReg<eInstructionSet::eIS_Avx2, T2>::act(x, y);
214  }
215 
216  static IPSDK_FORCEINLINE
217  void act(const typename AvxType<T1>::Type& x,
218  const typename AvxType<T2>::Type& y,
219  result_type& out)
220  {
221  const typename AvxType<T1>::Type zero =
223 
224  const typename AvxType<T2>::Type one =
226 
227  typename AvxType<T1>::Type yNeg;
229 
230  typename AvxType<T2>::Type minusYPlusOne_t2;
231  AddReg<eInstructionSet::eIS_Avx2, T2>::act(y, one, minusYPlusOne_t2);
232  UnaryMinusReg<eInstructionSet::eIS_Avx2, T2>::act(minusYPlusOne_t2, minusYPlusOne_t2);
233 
234  typename AvxType<T1>::Type minusYPlusOne;
235  cast<eInstructionSet::eIS_Avx2, T2, T1>(minusYPlusOne_t2, minusYPlusOne);
236 
237  typename AvxType<T1>::Type xGtThnMinusYPlusOne;
238  IsGreaterReg<eInstructionSet::eIS_Avx2, T1>::act(x, minusYPlusOne, xGtThnMinusYPlusOne);
239 
240  typename AvxType<T1>::Type yNegAndXGtThnMinusYPlusOne;
242  yNeg, xGtThnMinusYPlusOne, yNegAndXGtThnMinusYPlusOne);
243 
244  typename AvxType<T1>::Type a;
245  SubReg<eInstructionSet::eIS_Avx2, T1>::act(x, minusYPlusOne, a);
247 
248  typename AvxType<T2>::Type b;
251  yNegAndXGtThnMinusYPlusOne, a, b, out);
252  }
253 };
254 
257 
258 } // end of namespace detail
259 } // end of namespace simd
260 } // end of namespace ipsdk
261 
262 #endif // __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_AVX2_ADDREG_H__
specialization of ipsdk::simd::detail::UnaryMinusReg structure for AVX2 instruction set ...
Defines the IPSDK_FORCEINLINE.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: BitwiseAndNotReg.h:30
Definition: SubReg.h:39
Definition: SignedUnsignedOpReg.h:69
Definition: IsGreaterRegDecl.h:30
Predefined types for Avx instruction set management.
Definition: BitwiseSelectReg.h:30
specialization of ipsdk::simd::detail::SubReg structure for AVX2 instruction set
eInstructionSet
Enumerate for processor instruction set description.
Definition: InstructionSetTypes.h:31
Advanced Vector Extensions 2.
Definition: InstructionSetTypes.h:48
Predefined types associated to instruction set management.
Definition of import/export macro for library.
template structure which is specialized to implement the arithmetic addition on 2 scalars or 2 regist...
Definition: AddReg.h:37
specialization of ipsdk::simd::detail::AddReg structure for AVX2 instruction set
Definition: UnaryMinusReg.h:40
structure used to retrieve AVX type associated to a base type
Definition: AvxTypes.h:33
Definition: IsLessRegDecl.h:30
Definition: SignedUnsignedOpReg.h:51
Definition: BitwiseAndReg.h:30
Definition: AssignRegDecl.h:31