IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
CastPack.h
Go to the documentation of this file.
1 // CastPack.h:
3 // ------------
4 //
14 
15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_DETAIL_SSE2_CASTPACK_H__
16 #define __IPSDKUTIL_INSTRUCTIONSET_DETAIL_SSE2_CASTPACK_H__
17 
27 
28 #include <boost/type_traits/is_same.hpp>
29 #include <boost/type_traits/is_signed.hpp>
30 
31 namespace ipsdk {
32 namespace simd {
33 namespace detail {
34 
37 
38 template <typename TIn, typename TOut>
39 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
40  typename boost::enable_if_c<sizeof(TIn)==1 && sizeof(TOut)==1>::type>
41 {
43  IPSDK_FORCEINLINE
45  {
48  return out;
49  }
50 
51  static
52  IPSDK_FORCEINLINE
53  void
56  {
58  }
59 
60  static
61  IPSDK_FORCEINLINE
62  void
63  act(const BaseMaskPack<ePackType::ePT_Sse, TIn>& inMask,
65  {
67  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[0], in._val[0]);
69  }
70 };
71 
72 template <typename TIn, typename TOut>
73 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
74  typename boost::enable_if_c<sizeof(TIn)==2 && sizeof(TOut)==2>::type>
75 {
77  IPSDK_FORCEINLINE
79  {
83  return out;
84  }
85 
86  static
87  IPSDK_FORCEINLINE
88  void
91  {
94  }
95 
96  static
97  IPSDK_FORCEINLINE
98  void
99  act(const BaseMaskPack<ePackType::ePT_Sse, TIn>& inMask,
101  {
103  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[0], in._val[0]);
104  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[1], in._val[1]);
107  }
108 };
109 
110 template <typename TIn, typename TOut>
111 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
112  typename boost::enable_if_c<sizeof(TIn)==4 && sizeof(TOut)==4>::type>
113 {
115  IPSDK_FORCEINLINE
116  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
117  {
123  return out;
124  }
125 
126  static
127  IPSDK_FORCEINLINE
128  void
129  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
131  {
136  }
137 
138  static
139  IPSDK_FORCEINLINE
140  void
141  act(const BaseMaskPack<ePackType::ePT_Sse, TIn>& inMask,
143  {
145  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[0], in._val[0]);
146  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[1], in._val[1]);
147  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[2], in._val[2]);
148  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[3], in._val[3]);
153  }
154 };
155 
156 template <typename TIn, typename TOut>
157 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
158  typename boost::enable_if_c<sizeof(TIn)==8 && sizeof(TOut)==8>::type>
159 {
161  IPSDK_FORCEINLINE
162  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
163  {
173  return out;
174  }
175 
176  static
177  IPSDK_FORCEINLINE
178  void
179  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
181  {
190  }
191 
192  static
193  IPSDK_FORCEINLINE
194  void
195  act(const BaseMaskPack<ePackType::ePT_Sse, TIn>& inMask,
197  {
199  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[0], in._val[0]);
200  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[1], in._val[1]);
201  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[2], in._val[2]);
202  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[3], in._val[3]);
203  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[4], in._val[4]);
204  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[5], in._val[5]);
205  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[6], in._val[6]);
206  CastReg<eInstructionSet::eIS_Sse2, TIn, TIn>::act(inMask._val[7], in._val[7]);
215  }
216 };
217 
218 template <typename TIn, typename TOut>
219 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
220  typename boost::enable_if_c<sizeof(TIn)==1 && sizeof(TOut)==2>::type>
221 {
222  static IPSDK_FORCEINLINE
224  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
225  {
227  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(in._val[0], out._val[0], out._val[1]);
228  return out;
229  }
230 
231  static
232  IPSDK_FORCEINLINE
233  void
234  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
236  {
237  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(in._val[0], out._val[0], out._val[1]);
238  }
239 };
240 
241 template <typename TIn, typename TOut>
242 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
243  typename boost::enable_if_c<sizeof(TIn)==2 && sizeof(TOut)==4>::type>
244 {
245  static IPSDK_FORCEINLINE
247  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
248  {
250  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(in._val[0], out._val[0], out._val[1]);
251  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(in._val[1], out._val[2], out._val[3]);
252  return out;
253  }
254 
255  static
256  IPSDK_FORCEINLINE
257  void
258  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
260  {
261  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(in._val[0], out._val[0], out._val[1]);
262  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(in._val[1], out._val[2], out._val[3]);
263  }
264 };
265 
266 template <typename TIn, typename TOut>
267 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
268  typename boost::enable_if_c<sizeof(TIn)==1 && sizeof(TOut)==4>::type>
269 {
270  static IPSDK_FORCEINLINE
272  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
273  {
274  typedef typename UpperType<TIn>::Type T16;
276  CastReg<eInstructionSet::eIS_Sse2, TIn, T16>::act(in._val[0], in16._val[0], in16._val[1]);
278  CastReg<eInstructionSet::eIS_Sse2, T16, TOut>::act(in16._val[0], out._val[0], out._val[1]);
279  CastReg<eInstructionSet::eIS_Sse2, T16, TOut>::act(in16._val[1], out._val[2], out._val[3]);
280  return out;
281  }
282 
283  static
284  IPSDK_FORCEINLINE
285  void
286  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
288  {
289  typedef typename UpperType<TIn>::Type T16;
292  in._val[0], in16._val[0], in16._val[1]);
293 
295  in16._val[0], out._val[0], out._val[1]);
297  in16._val[1], out._val[2], out._val[3]);
298  }
299 };
300 
301 template <typename TIn, typename TOut>
302 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
303  typename boost::enable_if_c<sizeof(TIn)==4 && sizeof(TOut)==8>::type>
304 {
305  static IPSDK_FORCEINLINE
307  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
308  {
311  Cast::act(in._val[0], out._val[0], out._val[1]);
312  Cast::act(in._val[1], out._val[2], out._val[3]);
313  Cast::act(in._val[2], out._val[4], out._val[5]);
314  Cast::act(in._val[3], out._val[6], out._val[7]);
315  return out;
316  }
317 
318  static
319  IPSDK_FORCEINLINE
320  void
321  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
323  {
325  Cast::act(in._val[0], out._val[0], out._val[1]);
326  Cast::act(in._val[1], out._val[2], out._val[3]);
327  Cast::act(in._val[2], out._val[4], out._val[5]);
328  Cast::act(in._val[3], out._val[6], out._val[7]);
329  }
330 };
331 
332 template <typename TIn, typename TOut>
333 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
334  typename boost::enable_if_c<sizeof(TIn) <= 2 && sizeof(TOut)==8>::type>
335 {
336  static IPSDK_FORCEINLINE
338  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
339  {
340  const BasePack<ePackType::ePT_Sse, ipInt32> packInt32 =
343  }
344 
345  static
346  IPSDK_FORCEINLINE
347  void
348  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
350  {
352  CastPack<eInstructionSet::eIS_Sse2, TIn, ipInt32>::act(in, packInt32);
353  CastPack<eInstructionSet::eIS_Sse2, ipInt32, TOut>::act(packInt32, out);
354  }
355 };
356 
357 template <typename TIn, typename TOut>
358 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
359  typename boost::enable_if_c<sizeof(TIn)==2 && sizeof(TOut)==1>::type>
360 {
361  static IPSDK_FORCEINLINE
362  BasePack<ePackType::ePT_Sse, TOut>
363  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
364  {
365  BasePack<ePackType::ePT_Sse, TOut> out;
366  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(
367  in._val[0], in._val[1], out._val[0]);
368  return out;
369  }
370 
371  static
372  IPSDK_FORCEINLINE
373  void
374  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
375  BasePack<ePackType::ePT_Sse, TOut>& out)
376  {
377  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(
378  in._val[0], in._val[1], out._val[0]);
379  }
380 };
381 
382 template <typename TIn, typename TOut>
383 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
384  typename boost::enable_if_c<sizeof(TIn)==4 && sizeof(TOut)==2>::type>
385 {
386  static IPSDK_FORCEINLINE
387  BasePack<ePackType::ePT_Sse, TOut>
388  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
389  {
390  BasePack<ePackType::ePT_Sse, TOut> out;
391  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(
392  in._val[0], in._val[1], out._val[0]);
393  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(
394  in._val[2], in._val[3], out._val[1]);
395  return out;
396  }
397 
398  static
399  IPSDK_FORCEINLINE
400  void
401  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
402  BasePack<ePackType::ePT_Sse, TOut>& out)
403  {
404  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(
405  in._val[0], in._val[1], out._val[0]);
406  CastReg<eInstructionSet::eIS_Sse2, TIn, TOut>::act(
407  in._val[2], in._val[3], out._val[1]);
408  }
409 };
410 
411 template <typename TIn, typename TOut>
412 struct CastPack<eInstructionSet::eIS_Sse2, TIn, TOut,
413  typename boost::enable_if_c<sizeof(TIn)==4 && sizeof(TOut)==1>::type>
414 {
415  static IPSDK_FORCEINLINE
416  BasePack<ePackType::ePT_Sse, TOut>
417  act(const BasePack<ePackType::ePT_Sse, TIn>& in)
418  {
419  typedef typename UpperType<TOut>::Type T16;
420  BasePack<ePackType::ePT_Sse, T16> in16;
421  CastPack<eInstructionSet::eIS_Sse2, TIn, T16>::act(in, in16);
422  BasePack<ePackType::ePT_Sse, TOut> out;
423  CastReg<eInstructionSet::eIS_Sse2, T16, TOut>::act(
424  in16._val[0], in16._val[1], out._val[0]);
425  return out;
426  }
427 
428  static
429  IPSDK_FORCEINLINE
430  void
431  act(const BasePack<ePackType::ePT_Sse, TIn>& in,
432  BasePack<ePackType::ePT_Sse, TOut>& out)
433  {
434  typedef typename UpperType<TOut>::Type T16;
435  BasePack<ePackType::ePT_Sse, T16> in16;
436  CastPack<eInstructionSet::eIS_Sse2, TIn, T16>::act(in, in16);
437  CastReg<eInstructionSet::eIS_Sse2, T16, TOut>::act(
438  in16._val[0], in16._val[1], out._val[0]);
439  }
440 };
441 /*
442 template <>
443 struct CastPack<eInstructionSet::eIS_Sse2, ipReal32, ipUInt64>
444 {
445  static IPSDK_FORCEINLINE
446  BasePack<ePackType::ePT_Sse, ipUInt64>
447  act(const BasePack<ePackType::ePT_Sse, ipReal32>& in)
448  {
449  return CastPack<eInstructionSet::eIS_Sse2, ipUInt32, ipUInt64>::act(
450  CastPack<eInstructionSet::eIS_Sse2, ipReal32, ipUInt32>::act(in));
451  }
452 
453  static IPSDK_FORCEINLINE
454  void
455  act(const BasePack<ePackType::ePT_Sse, ipReal32>& in,
456  BasePack<ePackType::ePT_Sse, ipUInt64>& out)
457  {
458  BasePack<ePackType::ePT_Sse, ipUInt32> interm;
459  CastPack<eInstructionSet::eIS_Sse2, ipReal32, ipUInt32>::act(in, interm);
460  CastPack<eInstructionSet::eIS_Sse2, ipUInt32, ipUInt64>::act(interm, out);
461  }
462 };*/
463 
464 template <>
465 struct CastPack<eInstructionSet::eIS_Sse2, ipReal64, ipReal32>
466 {
467  static IPSDK_FORCEINLINE
468  BasePack<ePackType::ePT_Sse, ipReal32>
469  act(const BasePack<ePackType::ePT_Sse, ipReal64>& in)
470  {
471  BasePack<ePackType::ePT_Sse, ipReal32> out;
472  typedef CastReg<eInstructionSet::eIS_Sse2, ipReal64, ipReal32> Cast;
473 
474  Cast::act(in._val[0], in._val[1], out._val[0]);
475  Cast::act(in._val[2], in._val[3], out._val[1]);
476  Cast::act(in._val[4], in._val[5], out._val[2]);
477  Cast::act(in._val[6], in._val[7], out._val[3]);
478  return out;
479  }
480 
481  static
482  IPSDK_FORCEINLINE
483  void
484  act(const BasePack<ePackType::ePT_Sse, ipReal64>& in,
485  BasePack<ePackType::ePT_Sse, ipReal32>& out)
486  {
487  typedef CastReg<eInstructionSet::eIS_Sse2, ipReal64, ipReal32> Cast;
488  Cast::act(in._val[0], in._val[1], out._val[0]);
489  Cast::act(in._val[2], in._val[3], out._val[1]);
490  Cast::act(in._val[4], in._val[5], out._val[2]);
491  Cast::act(in._val[6], in._val[7], out._val[3]);
492  }
493 };
494 
495 template <typename TOut>
496 struct CastPack<eInstructionSet::eIS_Sse2, ipReal64, TOut,
497  typename boost::enable_if_c<
498  sizeof(TOut)==4 &&
499  boost::is_integral<TOut>::value
500  >::type
501 >
502 {
503  static IPSDK_FORCEINLINE
504  BasePack<ePackType::ePT_Sse, TOut>
505  act(const BasePack<ePackType::ePT_Sse, ipReal64>& in)
506  {
507  BasePack<ePackType::ePT_Sse, TOut> out;
508  typedef CastReg<eInstructionSet::eIS_Sse2, ipReal64, TOut> Cast;
509 
510  Cast::act(in._val[0], in._val[1], out._val[0]);
511  Cast::act(in._val[2], in._val[3], out._val[1]);
512  Cast::act(in._val[4], in._val[5], out._val[2]);
513  Cast::act(in._val[6], in._val[7], out._val[3]);
514  return out;
515  }
516 
517  static
518  IPSDK_FORCEINLINE
519  void
520  act(const BasePack<ePackType::ePT_Sse, ipReal64>& in,
521  BasePack<ePackType::ePT_Sse, TOut>& out)
522  {
523  typedef CastReg<eInstructionSet::eIS_Sse2, ipReal64, TOut> Cast;
524  Cast::act(in._val[0], in._val[1], out._val[0]);
525  Cast::act(in._val[2], in._val[3], out._val[1]);
526  Cast::act(in._val[4], in._val[5], out._val[2]);
527  Cast::act(in._val[6], in._val[7], out._val[3]);
528  }
529 };
530 
531 template <typename TOut>
532 struct CastPack<eInstructionSet::eIS_Sse2, ipReal64, TOut,
533  typename boost::enable_if_c<
534  sizeof(TOut)<4 &&
535  boost::is_integral<TOut>::value
536  >::type
537 >
538 {
539  static IPSDK_FORCEINLINE
540  BasePack<ePackType::ePT_Sse, TOut>
541  act(const BasePack<ePackType::ePT_Sse, ipReal64>& in)
542  {
543  BasePack<ePackType::ePT_Sse, TOut> out;
544  BasePack<ePackType::ePT_Sse, ipInt32> inInt32;
545 
546  CastPack<eInstructionSet::eIS_Sse2, ipReal64, ipInt32>::act(in, inInt32);
547  CastPack<eInstructionSet::eIS_Sse2, ipInt32, TOut>::act(inInt32, out);
548  return out;
549  }
550 
551  static
552  IPSDK_FORCEINLINE
553  void
554  act(const BasePack<ePackType::ePT_Sse, ipReal64>& in,
555  BasePack<ePackType::ePT_Sse, TOut>& out)
556  {
557  BasePack<ePackType::ePT_Sse, ipInt32> inInt32;
558 
559  CastPack<eInstructionSet::eIS_Sse2, ipReal64, ipInt32>::act(in, inInt32);
560  CastPack<eInstructionSet::eIS_Sse2, ipInt32, TOut>::act(inInt32, out);
561  }
562 };
563 
566 
567 } // end of namespace detail
568 } // end of namespace simd
569 } // end of namespace ipsdk
570 
571 #endif // __IPSDKUTIL_INSTRUCTIONSET_DETAIL_SSE2_CASTPACK_H__
Defines the IPSDK_FORCEINLINE.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: CastPack.h:33
structure containing set of masks for vectorized operations
Definition: BaseMaskPackDecl.h:29
BaseMaskPack class; defines a set of masks; the number of masks in this set depends on the type of th...
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
utility functions for array operations
Definition: CastReg.h:30
BasePack class; defines a set of scalars (for instruction set "standard") or registers (for all other...
template structures used for immediate type promotion
eInstructionSet
Enumerate for processor instruction set description.
Definition: InstructionSetTypes.h:31
template structure UpperType<typename T>; its typedef Type gives the type just upper to T...
Definition: UpperType.h:42
function assigning a given value of type T to a given Pack<instructionSet, T>
Definition of import/export macro for library.
Streaming SIMD Extensions 2.
Definition: InstructionSetTypes.h:36
float ipReal32
Base types definition.
Definition: BaseTypes.h:56
structure containing intrinsic registers used to store vectorized data
Definition: BasePackDecl.h:29