39 #ifndef _AAX_FASTPOW_H_
40 #define _AAX_FASTPOW_H_
43 #if defined(MAC_VERSION) || defined(LINUX_VERSION)
50 static const float _2p23 = 8388608.0f;
68 static inline void PowFastSetTable(
69 float*
const AAX_RESTRICT pTable,
70 const unsigned int precision,
71 const unsigned int extent,
75 float zeroToOne = !isRound ?
76 0.0f : (1.0f / (
static_cast<float>(1 << precision) * 2.0f));
77 for(
int i = 0; i < (1 << extent); ++i )
80 pTable[i] = std::powf( 2.0f, zeroToOne );
82 zeroToOne += 1.0f /
static_cast<float>(1 << precision);
131 static inline float PowFastLookup(
134 const float*
const AAX_RESTRICT tableH,
135 const float*
const AAX_RESTRICT tableL)
139 const int i =
static_cast<int>( (val * (_2p23 * ilog2)) + (127.0f * _2p23) );
142 const float t = tableH[(i >> 14) & 0x1FF] * tableL[(i >> 5) & 0x1FF];
143 const int it = (i & 0xFF800000) |
144 (*
reinterpret_cast<const int*
>( &t ) & 0x7FFFFF);
147 return *
reinterpret_cast<const float*
>( &it );
162 static inline float Pow2FastLookup(
164 const float*
const AAX_RESTRICT tableH,
165 const float*
const AAX_RESTRICT tableL)
169 const int i =
static_cast<int>((val + 127.0f) * _2p23);
172 const float t = tableH[(i >> 14) & 0x1FF] * tableL[(i >> 5) & 0x1FF];
173 const int it = (i & 0xFF800000) |
174 (*
reinterpret_cast<const int*
>( &t ) & 0x007FFFFF);
177 return *
reinterpret_cast<const float*
>( &it );
183 static const int kMantissaBitSize = 23;
184 static const int kExpBias = 127;
185 static const int kLogMantissaMSBs = 9;
186 static const int kLogTableSize = (1 << kLogMantissaMSBs) + 1;
198 static inline void LogFastSetTable(
199 float*
const AAX_RESTRICT logTable,
200 int tableSize = kLogTableSize)
202 const float kInv = 1.0f/float(tableSize - 1);
203 float mantissaVal = 1.0f;
204 const float invLog10Base2 = 1.0f / std::log10f(2.0f);
205 for (
int j = 0; j < tableSize; j++)
207 logTable[j] = std::log10f(mantissaVal) * invLog10Base2;
233 template <
int kMantMSBs>
234 static inline void LogFloatToExpMantissa(
236 int *
const AAX_RESTRICT outExp,
237 int *
const AAX_RESTRICT outMant,
238 float*
const AAX_RESTRICT fract)
240 const int mantissaSize = 1 << (kMantissaBitSize - kMantMSBs);
241 const float invMantissaSize = 1.0f/(float)mantissaSize;
242 const int intEquiv = *
reinterpret_cast<const int*
>(&number);
245 const int exponent = (intEquiv & 0x7f800000) >> 23;
246 const int mantissa = intEquiv & 0x007fffff;
252 *outExp = exponent - kExpBias;
254 *outMant = mantissa >> (kMantissaBitSize - kMantMSBs);
256 *fract = (float)(mantissa & (mantissaSize - 1)) * invMantissaSize;
274 template <
int kPrecision>
275 static inline float LogFastLookup(
277 const float*
const AAX_RESTRICT logTable)
280 int exponent, mantissa;
283 AAX::LogFloatToExpMantissa<kPrecision>(num, &exponent, &mantissa, &fract);
285 const float mantLog1 = logTable[mantissa];
286 const float mantLog2 = logTable[mantissa+1];
288 const float logOfNum = (mantLog1 * (1.0f - fract) + fract * mantLog2) + exponent;
Various utility definitions for AAX.
Definition: AAX_Exception.h:42
const unsigned int kPowExtent
Definition: AAX_FastPow.h:51
const unsigned int kPowTableSize
Definition: AAX_FastPow.h:52
float fabsf(float iVal)
Definition: AAX_MiscUtils.h:185