36#ifndef _AAX_FASTPOW_H_
37#define _AAX_FASTPOW_H_
40#if defined(MAC_VERSION) || defined(LINUX_VERSION)
41namespace std {using ::powf;using ::log10f;using ::fabsf;}
47static const float _2p23 = 8388608.0f;
65static inline void PowFastSetTable(
66 float*
const AAX_RESTRICT pTable,
67 const unsigned int precision,
68 const unsigned int extent,
72 float zeroToOne = !isRound ?
73 0.0f : (1.0f / (
static_cast<float>(1 << precision) * 2.0f));
74 for(
int i = 0; i < (1 << extent); ++i )
77 pTable[i] = std::powf( 2.0f, zeroToOne );
79 zeroToOne += 1.0f /
static_cast<float>(1 << precision);
128static inline float PowFastLookup(
131 const float*
const AAX_RESTRICT tableH,
132 const float*
const AAX_RESTRICT tableL)
136 const int i =
static_cast<int>( (val * (_2p23 * ilog2)) + (127.0f * _2p23) );
139 const float t = tableH[(i >> 14) & 0x1FF] * tableL[(i >> 5) & 0x1FF];
140 const int it = (i & 0xFF800000) |
141 (*
reinterpret_cast<const int*
>( &t ) & 0x7FFFFF);
144 return *
reinterpret_cast<const float*
>( &it );
159static inline float Pow2FastLookup(
161 const float*
const AAX_RESTRICT tableH,
162 const float*
const AAX_RESTRICT tableL)
166 const int i =
static_cast<int>((val + 127.0f) * _2p23);
169 const float t = tableH[(i >> 14) & 0x1FF] * tableL[(i >> 5) & 0x1FF];
170 const int it = (i & 0xFF800000) |
171 (*
reinterpret_cast<const int*
>( &t ) & 0x007FFFFF);
174 return *
reinterpret_cast<const float*
>( &it );
180static const int kMantissaBitSize = 23;
181static const int kExpBias = 127;
182static const int kLogMantissaMSBs = 9;
183static const int kLogTableSize = (1 << kLogMantissaMSBs) + 1;
195static inline void LogFastSetTable(
196 float*
const AAX_RESTRICT logTable,
197 int tableSize = kLogTableSize)
199 const float kInv = 1.0f/float(tableSize - 1);
200 float mantissaVal = 1.0f;
201 const float invLog10Base2 = 1.0f / std::log10f(2.0f);
202 for (
int j = 0; j < tableSize; j++)
204 logTable[j] = std::log10f(mantissaVal) * invLog10Base2;
230template <
int kMantMSBs>
231static inline void LogFloatToExpMantissa(
233 int *
const AAX_RESTRICT outExp,
234 int *
const AAX_RESTRICT outMant,
235 float*
const AAX_RESTRICT fract)
237 const int mantissaSize = 1 << (kMantissaBitSize - kMantMSBs);
238 const float invMantissaSize = 1.0f/(float)mantissaSize;
239 const int intEquiv = *
reinterpret_cast<const int*
>(&number);
242 const int exponent = (intEquiv & 0x7f800000) >> 23;
243 const int mantissa = intEquiv & 0x007fffff;
249 *outExp = exponent - kExpBias;
251 *outMant = mantissa >> (kMantissaBitSize - kMantMSBs);
253 *fract = (float)(mantissa & (mantissaSize - 1)) * invMantissaSize;
271template <
int kPrecision>
272static inline float LogFastLookup(
274 const float*
const AAX_RESTRICT logTable)
277 int exponent, mantissa;
280 AAX::LogFloatToExpMantissa<kPrecision>(num, &exponent, &mantissa, &fract);
282 const float mantLog1 = logTable[mantissa];
283 const float mantLog2 = logTable[mantissa+1];
285 const float logOfNum = (mantLog1 * (1.0f - fract) + fract * mantLog2) + exponent;
Various utility definitions for AAX.
Definition: AAX_EnvironmentUtilities.h:59
const unsigned int kPowExtent
Definition: AAX_FastPow.h:48
const unsigned int kPowTableSize
Definition: AAX_FastPow.h:49