IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
PowReg.h
Go to the documentation of this file.
1 // PowReg.h:
3 // -------------------
4 //
14 
15 #ifndef __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_COMMON_POWREG_H__
16 #define __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_COMMON_POWREG_H__
17 
20 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/AbsReg.h>
22 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/IsOddReg.h>
23 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/PowReg.h>
24 #include <IPSDKUtil/InstructionSet/Arithmetic/detail/PowNoCheckReg.h>
38 
39 #include <boost/mpl/not_equal_to.hpp>
40 
41 namespace ipsdk {
42 namespace simd {
43 namespace detail {
44 
47 
49 template <eInstructionSet::domain IS, eInstructionSet::domain ISFma>
50 struct PowReg<
51  IS,
52  ISFma,
53  ipReal32,
54  typename boost::enable_if<
55  typename boost::mpl::not_equal_to<
56  boost::mpl::int_<IS>,
57  boost::mpl::int_<eInstructionSet::eIS_Standard>
58  >::type
59  >::type
60 >
61 {
62  static IPSDK_FORCEINLINE
64  act(const typename RegType<IS, ipReal32>::Type& base,
65  const typename RegType<IS, ipReal32>::Type& exp)
66  {
67  typename RegType<IS, ipReal32>::Type out;
68  act(base, exp, out);
69  return out;
70  }
71 
72  static IPSDK_FORCEINLINE
73  void
74  act(const typename RegType<IS, ipReal32>::Type& base,
75  const typename RegType<IS, ipReal32>::Type& exp,
76  typename RegType<IS, ipReal32>::Type& out)
77  {
78  typedef typename RegType<IS, ipReal32>::Type Reg;
79  typedef typename RegMaskType<IS, ipReal32>::Type RegMask;
80  Reg o;
82 
83  Reg zero, one, inf, minf, nan;
86  AssignReg<IS, ipReal32>::act(minf, -std::numeric_limits<ipReal32>::infinity());
87  AssignReg<IS, ipReal32>::act(inf, std::numeric_limits<ipReal32>::infinity());
88  AssignReg<IS, ipReal32>::act(nan, std::numeric_limits<ipReal32>::quiet_NaN());
89  Reg invBase;
90  DivReg<IS, ipReal32>::act(one, base, invBase);
91  RegMask invBaseIsNeg;
92  IsLessReg<IS, ipReal32>::act(invBase, zero, invBaseIsNeg);
93  RegMask baseIsNull;
94  IsEqualReg<IS, ipReal32>::act(base, zero, baseIsNull);
95 
96  RegMask baseIsMinusZero;
97  LogicalAndReg<IS, ipReal32>::act(baseIsNull, invBaseIsNeg, baseIsMinusZero);
98  RegMask expIsPos, expIsNeg, expIsOdd;
99  RegMask expIsNegOdd;
100  IsGreaterReg<IS, ipReal32>::act(exp, zero, expIsPos);
101  IsLessReg<IS, ipReal32>::act(exp, zero, expIsNeg);
102  IsOddReg<IS, ipReal32>::act(exp, expIsOdd);
103 
104  LogicalAndReg<IS, ipReal32>::act(expIsNeg, expIsOdd, expIsNegOdd);
105  Reg absBase;
106  AbsReg<IS, ipReal32>::act(base, absBase);
107 
108  RegMask baseEqualsToInfinity;
109  IsEqualReg<IS, ipReal32>::act(base, inf, baseEqualsToInfinity);
110  RegMask baseEqualsToMinusInfinity;
111  IsEqualReg<IS, ipReal32>::act(base, minf, baseEqualsToMinusInfinity);
112 
113  RegMask expEqualsToInfinity;
114  IsEqualReg<IS, ipReal32>::act(exp, inf, expEqualsToInfinity);
115  RegMask expEqualsToMinusInfinity;
116  IsEqualReg<IS, ipReal32>::act(exp, minf, expEqualsToMinusInfinity);
117 
118  // pow(+0, exp), where exp is a negative odd integer, returns +infinity (and should raise FE_DIVBYZERO, not the case here for the moment)
119  // pow(+/-0, exp) where exp is negative, finite and is an even integer or a non-integer, returns +infinity (and should raise FE_DIVBYZERO, but this is not the case here for the moment
120  RegMask baseIsNullAndExpIsNeg;
121  LogicalAndReg<IS, ipReal32>::act(baseIsNull, expIsNeg, baseIsNullAndExpIsNeg);
122  IfElseReg<IS, ipReal32>::act(baseIsNullAndExpIsNeg, inf, o, o);
123 
124  // pow(-0, exp), where exp is a negative odd integer, returns -infinity (and should raise FE_DIVBYZERO, not the case here for the moment)
125  RegMask baseIsMinusZeroAndExpIsNegOdd;
126  LogicalAndReg<IS, ipReal32>::act(baseIsMinusZero, expIsNegOdd, baseIsMinusZeroAndExpIsNegOdd);
127  IfElseReg<IS, ipReal32>::act(baseIsMinusZeroAndExpIsNegOdd, minf, o, o);
128 
129  // pow(base, -inf) returns +inf for any |base| < 1
130  // pow(base, -inf) returns 0 for any |base| > 1
131  RegMask absBaseLessThanOne;
132  IsLessReg<IS, ipReal32>::act(absBase, one, absBaseLessThanOne);
133  Reg regFromAbsBaseLessThanOne;
134  CastReg<IS, ipReal32, ipReal32>::act(absBaseLessThanOne, regFromAbsBaseLessThanOne);
135  Reg infIfAbsBaseLessThanOneElse0;
136  BitwiseAndReg<IS, ipReal32>::act(regFromAbsBaseLessThanOne, inf, infIfAbsBaseLessThanOneElse0);
137  IfElseReg<IS, ipReal32>::act(expEqualsToMinusInfinity, infIfAbsBaseLessThanOneElse0, o, o);
138 
139  // pow(base, inf) returns 0 for any |base| < 1
140  // pow(base, inf) returns +infinity for any |base| > 1
141  Reg zeroIfAbsBaseLessThanOneElseInf;
142  BitwiseAndNotReg<IS, ipReal32>::act(inf, regFromAbsBaseLessThanOne, zeroIfAbsBaseLessThanOneElseInf);
143  IfElseReg<IS, ipReal32>::act(expEqualsToInfinity, zeroIfAbsBaseLessThanOneElseInf, o, o);
144 
145  // pow(-1, +/-infinity) returns 1
146  RegMask expEqualsToPlusInfinity;
147  IsEqualReg<IS, ipReal32>::act(exp, inf, expEqualsToPlusInfinity);
148  LogicalOrReg<IS, ipReal32>::act(expEqualsToPlusInfinity, expEqualsToMinusInfinity, expEqualsToPlusInfinity);
149  RegMask baseEqualsToMinusOne;
150  const Reg minusOne = AssignReg<IS, ipReal32>::act(-1.0f);
152  base,
153  minusOne,
154  baseEqualsToMinusOne);
155 
156  RegMask baseEqualsToMinusOneAndAbsExpEqualsToInf;
157  LogicalAndReg<IS, ipReal32>::act(baseEqualsToMinusOne, expEqualsToPlusInfinity, baseEqualsToMinusOneAndAbsExpEqualsToInf);
158  IfElseReg<IS, ipReal32>::act(baseEqualsToMinusOneAndAbsExpEqualsToInf, one, o, o);
159 
160  // pow(-inf, exp) returns -0 if exp is a negative odd integer
161  // pow(-inf, exp) returns +0 if exp is a negative non-integer or even integer
162  // pow(-inf, exp) returns -inf if exp is a positive odd integer
163  // pow(-inf, exp) returns +inf if exp is a positive non-integer or even integer
164  Reg mzeroIfExpisOddElseZero, minfIfExpIsOddElseInf, zeroIfExpIsNegElseInf;
165  const Reg minusZero = AssignReg<IS, ipReal32>::act(-.0f);
166  IfElse0Reg<IS, ipReal32>::act(expIsOdd, minusZero, mzeroIfExpisOddElseZero);
167  IfElseReg<IS, ipReal32>::act(expIsOdd, minf, inf, minfIfExpIsOddElseInf);
169  expIsNeg,
170  mzeroIfExpisOddElseZero,
171  minfIfExpIsOddElseInf,
172  zeroIfExpIsNegElseInf);
173  IfElseReg<IS, ipReal32>::act(baseEqualsToMinusInfinity, zeroIfExpIsNegElseInf, o, o);
174 
175  // pow(+inf, exp) returns +0 for any negative exp
176  // pow(+inf, exp) returns +inf for any positive exp
177  IfElse0Reg<IS, ipReal32>::act(expIsPos, inf, zeroIfExpIsNegElseInf);
178  IfElseReg<IS, ipReal32>::act(baseEqualsToInfinity, zeroIfExpIsNegElseInf, o, o);
179 
180  // pow(nan, exp) returns nan if exp not null
181  RegMask baseIsNan;
182  IsNotEqualReg<IS, ipReal32>::act(base, base, baseIsNan);
183  IfElseReg<IS, ipReal32>::act(baseIsNan, nan, o, o);
184 
185  // pow(base, nan) returns nan if base is different from 1
186  RegMask expIsNan;
187  IsNotEqualReg<IS, ipReal32>::act(exp, exp, expIsNan);
188  IfElseReg<IS, ipReal32>::act(expIsNan, nan, o, o);
189 
190  // pow(1, exp) returns one for any exp
191  RegMask baseEqualsToOne;
192  IsEqualReg<IS, ipReal32>::act(base, one, baseEqualsToOne);
193  IfElseReg<IS, ipReal32>::act(baseEqualsToOne, one, o, o);
194 
195  // pow(base, +/-0) returns one for any base
196  RegMask expIsNull;
197  IsEqualReg<IS, ipReal32>::act(exp, zero, expIsNull);
198  IfElseReg<IS, ipReal32>::act(expIsNull, one, o, out);
199  }
200 };
201 
204 
205 } // end of namespace detail
206 } // end of namespace simd
207 } // end of namespace ipsdk
208 
209 #endif // __IPSDKUTIL_INSTRUCTIONSET_ARITHMETIC_DETAIL_COMMON_POWREG_H__
Defines the IPSDK_FORCEINLINE.
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
Definition: DivReg.h:39
Definition: BitwiseAndNotReg.h:30
Definition: IsEqualRegDecl.h:35
IsEqualReg<eInstructionSet::domain instructionSet, typename T, typename Enable=void> structure...
Definition: IsGreaterRegDecl.h:30
template structure which is specialized to implement the computation of pow function on scalars or re...
Definition: PowNoCheckReg.h:38
Definition: CastReg.h:30
Definition: DataItemNodeHdrMacrosDetails.h:48
RegType class.
Definition: IfElse0Reg.h:33
Definition of import/export macro for library.
Definition: LogicalOrReg.h:30
Definition: IfElseReg.h:33
Definition: IsNotEqualRegDecl.h:30
Definition: RegMaskType.h:29
template structure which is specialized to implement the computation of abs function on a scalar or a...
Definition: AbsReg.h:46
template structure which is specialized to implement the computation of pow function on scalars or re...
Definition: PowReg.h:38
Definition: LogicalAndReg.h:30
Definition: IsLessRegDecl.h:30
Definition: RegType.h:29
Definition: BitwiseAndReg.h:30
Definition: AssignRegDecl.h:31
float ipReal32
Base types definition.
Definition: BaseTypes.h:56
template structure which is specialized to implement the isOdd function
Definition: IsOddReg.h:35