IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
SaturatedRoundPack.h
Go to the documentation of this file.
1 // SaturatedRoundPack.h:
3 // -----------------
4 //
18 
19 #ifndef __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_SATURATEDROUNDPACK_H__
20 #define __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_SATURATEDROUNDPACK_H__
21 
25 #include <IPSDKUtil/InstructionSet/saturated_cast.h>
29 
30 namespace ipsdk {
31 namespace simd {
32 namespace detail {
33 
36 
41 template <eInstructionSet::domain instructionSet,
42  typename TIn, typename TOut, typename Enable=void>
44 {
45 };
46 
47 template <eInstructionSet::domain instructionSet,
48  typename TIn, typename TOut>
49 struct SaturatedRoundPack<instructionSet, TIn, TOut,
50  typename boost::enable_if_c<!boost::is_integral<TIn>::value && boost::is_integral<TOut>::value>::type>
51 {
52  static
53  IPSDK_FORCEINLINE
56  {
58  assign<instructionSet>(zero, 0);
59  assign<instructionSet>(half, .5);
60  assign<instructionSet>(mHalf, -.5);
61 
64  isLess<instructionSet>(in, zero, ltz);
65  ifElse<instructionSet>(ltz, mHalf, half, addRes);
66  add<instructionSet>(in, addRes, addRes);
67  return saturated_cast<instructionSet, TOut>(addRes);
68  }
69 
70  static
71  IPSDK_FORCEINLINE
72  void
75  {
77  assign<instructionSet>(zero, 0);
78  assign<instructionSet>(half, .5);
79  assign<instructionSet>(mHalf, -.5);
80 
83  isLess<instructionSet>(in, zero, ltz);
84  ifElse<instructionSet>(ltz, mHalf, half, addRes);
85  add<instructionSet>(in, addRes, addRes);
86  saturated_cast<instructionSet>(addRes, out);
87  }
88 };
89 
90 template <eInstructionSet::domain instructionSet,
91  typename TIn, typename TOut>
92 struct SaturatedRoundPack<instructionSet, TIn, TOut,
93  typename boost::enable_if_c<!boost::is_integral<TIn>::value && !boost::is_integral<TOut>::value>::type>
94 {
95  static
96  IPSDK_FORCEINLINE
99  {
100  return saturated_cast<instructionSet, TOut>(in);
101  }
102 
103  static
104  IPSDK_FORCEINLINE
105  void
108  {
109  saturated_cast<instructionSet>(in, out);
110  }
111 };
112 
115 
116 } // end of namespace detail
117 } // end of namespace simd
118 } // end of namespace ipsdk
119 
120 #endif // __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_SATURATEDROUNDPACK_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
structure containing set of masks for vectorized operations
Definition: BaseMaskPackDecl.h:29
Definition: DataItemNodeHdrMacrosDetails.h:48
function assigning a given value of type T to a given Pack<instructionSet, T>
IPSDK_FORCEINLINE ipsdk::simd::IS2Pack< instructionSet, TOut >::Type saturated_cast(const PackIn &in)
casts from PackIn type to PackOut type
Definition: saturated_cast.h:36
Predefined types associated to instruction set management.
Definition: PackTypes.h:56
Definition of import/export macro for library.
add function; returns the result of an arithmetic add operation on all the elements of 2 input pack o...
Definition: SaturatedRoundPack.h:43
structure containing intrinsic registers used to store vectorized data
Definition: BasePackDecl.h:29