IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Atan2Pack.h
Go to the documentation of this file.
1 // Atan2Pack.h:
3 // -----------------
4 //
14 
15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_ATAN2PACK_H__
16 #define __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_ATAN2PACK_H__
17 
21 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/Atan2Reg.h>
26 #include <boost/type_traits/is_float.hpp>
27 
28 namespace ipsdk {
29 namespace simd {
30 namespace detail {
31 
34 
41 template <eInstructionSet::domain instructionSet, typename T,
42  typename Enable=void>
43 struct Atan2Pack;
44 
46 
47 // implementation for standard instruction set and floating points type
48 template <typename T>
50  typename boost::enable_if<boost::is_float<T> >::type>
51 {
52  static
53  IPSDK_FORCEINLINE
57  {
60  }
61 
62  static
63  IPSDK_FORCEINLINE
64  void
68  {
71  }
72 };
73 
74 // implementation for floating points type
75 template <eInstructionSet::domain IS, typename T>
76 struct Atan2Pack<IS, T,
77  typename boost::enable_if<boost::is_float<T> >::type>
78 {
79  static
80  IPSDK_FORCEINLINE
81  const typename IS2Pack<IS, T>::Type
82  act(const typename IS2Pack<IS, T>::Type& yPack,
83  const typename IS2Pack<IS, T>::Type& xPack)
84  {
85  typename IS2Pack<IS, T>::Type outPack;
86  act(yPack, xPack, outPack);
87 
88  return outPack;
89  }
90 
91  static
92  IPSDK_FORCEINLINE
93  void
94  act(const typename IS2Pack<IS, T>::Type& yPack,
95  const typename IS2Pack<IS, T>::Type& xPack,
96  typename IS2Pack<IS, T>::Type& outPack)
97  {
98  // define used constants
99  typedef typename IS2Pack<IS, T>::Type PackT;
100  typedef typename IS2MaskPack<IS, T>::Type MaskPackT;
101  const T epsilon = NumericLimits<T>::sqrt_epsilon();
102  PackT cste0Pack, csteEpsilonPack, cste1Pack, cstePiPack, csteMPiPack, cstePiD2Pack, csteMPiD2Pack;
103  simd::assign<IS>(cste0Pack, 0);
104  simd::assign<IS>(csteEpsilonPack, epsilon);
105  simd::assign<IS>(cste1Pack, 1);
106  simd::assign<IS>(cstePiPack, static_cast<T>(M_PI));
107  simd::assign<IS>(csteMPiPack, -static_cast<T>(M_PI));
108  simd::assign<IS>(cstePiD2Pack, static_cast<T>(M_PI_2));
109  simd::assign<IS>(csteMPiD2Pack, -static_cast<T>(M_PI_2));
110 
111  // compute absolute value for x and y
112  PackT absXPack, absYPack;
113  simd::abs<IS>(xPack, absXPack);
114  simd::abs<IS>(yPack, absYPack);
115 
116  // test for data range
117  MaskPackT testAbsXEpsilonPack, testAbsYEpsilonPack, testX0Pack, testY0Pack;
118  simd::isGreater<IS>(absXPack, csteEpsilonPack, testAbsXEpsilonPack);
119  simd::isGreater<IS>(absYPack, csteEpsilonPack, testAbsYEpsilonPack);
120  simd::isGreater<IS>(xPack, cste0Pack, testX0Pack);
121  simd::isGreater<IS>(yPack, cste0Pack, testY0Pack);
122 
123  // compute atan value associated to y / x
124  PackT usedValuePack, resValuePack;
125  simd::ifElse<IS>(testAbsXEpsilonPack, xPack, cste1Pack, usedValuePack);
126  simd::div<IS>(yPack, usedValuePack, usedValuePack);
127  resValuePack = simd::atan<IS>(usedValuePack);
128 
129  // modify computed value in function of y and x sign
130  PackT wPack;
131  simd::ifElse<IS>(testY0Pack, cstePiPack, csteMPiPack, wPack);
132  simd::ifElse<IS>(testX0Pack, cste0Pack, wPack, wPack);
133  simd::add<IS>(resValuePack, wPack, resValuePack);
134 
135  // handle case where x < epsilon
136  PackT ePack;
137  simd::ifElse<IS>(testY0Pack, cstePiD2Pack, csteMPiD2Pack, ePack);
138  simd::ifElse<IS>(testAbsYEpsilonPack, ePack, cste0Pack, ePack);
139  simd::ifElse<IS>(testAbsXEpsilonPack, resValuePack, ePack, outPack);
140  }
141 };
142 
144 
147 
148 } // end of namespace detail
149 } // end of namespace simd
150 } // end of namespace ipsdk
151 
152 #endif // __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_ATAN2PACK_H__
Defines the IPSDK_FORCEINLINE.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: Atan2Pack.h:43
structure used to retrieve pack type from enumerate instruction set value and data type ...
Definition: DataItemNodeHdrMacrosDetails.h:48
eInstructionSet
Enumerate for processor instruction set description.
Definition: InstructionSetTypes.h:31
Predefined types associated to instruction set management.
atan function; returns the calculation of the arctan function on all the elements of one input pack o...
Definition of import/export macro for library.
Atan2Reg template specialization for instruction set Standard.
Definition: Atan2Reg.h:31
compiler optimisations only
Definition: InstructionSetTypes.h:34
Definition: BinaryPackOp.h:31
Definition: IS2Pack.h:34