49#ifndef _AAX_FASTPOW_H_
50#define _AAX_FASTPOW_H_
53#if defined(MAC_VERSION) || defined(LINUX_VERSION)
54namespace std {using ::powf;using ::log10f;using ::fabsf;}
60static const float _2p23 = 8388608.0f;
78static inline void PowFastSetTable(
79 float*
const AAX_RESTRICT pTable,
80 const unsigned int precision,
81 const unsigned int extent,
85 float zeroToOne = !isRound ?
86 0.0f : (1.0f / (
static_cast<float>(1 << precision) * 2.0f));
87 for(
int i = 0; i < (1 << extent); ++i )
90 pTable[i] = std::powf( 2.0f, zeroToOne );
92 zeroToOne += 1.0f /
static_cast<float>(1 << precision);
141static inline float PowFastLookup(
144 const float*
const AAX_RESTRICT tableH,
145 const float*
const AAX_RESTRICT tableL)
149 const int i =
static_cast<int>( (val * (_2p23 * ilog2)) + (127.0f * _2p23) );
152 const float t = tableH[(i >> 14) & 0x1FF] * tableL[(i >> 5) & 0x1FF];
153 const int it = (i & 0xFF800000) |
154 (*
reinterpret_cast<const int*
>( &t ) & 0x7FFFFF);
157 return *
reinterpret_cast<const float*
>( &it );
172static inline float Pow2FastLookup(
174 const float*
const AAX_RESTRICT tableH,
175 const float*
const AAX_RESTRICT tableL)
179 const int i =
static_cast<int>((val + 127.0f) * _2p23);
182 const float t = tableH[(i >> 14) & 0x1FF] * tableL[(i >> 5) & 0x1FF];
183 const int it = (i & 0xFF800000) |
184 (*
reinterpret_cast<const int*
>( &t ) & 0x007FFFFF);
187 return *
reinterpret_cast<const float*
>( &it );
193static const int kMantissaBitSize = 23;
194static const int kExpBias = 127;
195static const int kLogMantissaMSBs = 9;
196static const int kLogTableSize = (1 << kLogMantissaMSBs) + 1;
208static inline void LogFastSetTable(
209 float*
const AAX_RESTRICT logTable,
210 int tableSize = kLogTableSize)
212 const float kInv = 1.0f/float(tableSize - 1);
213 float mantissaVal = 1.0f;
214 const float invLog10Base2 = 1.0f / std::log10f(2.0f);
215 for (
int j = 0; j < tableSize; j++)
217 logTable[j] = std::log10f(mantissaVal) * invLog10Base2;
243template <
int kMantMSBs>
244static inline void LogFloatToExpMantissa(
246 int *
const AAX_RESTRICT outExp,
247 int *
const AAX_RESTRICT outMant,
248 float*
const AAX_RESTRICT fract)
250 const int mantissaSize = 1 << (kMantissaBitSize - kMantMSBs);
251 const float invMantissaSize = 1.0f/(float)mantissaSize;
252 const int intEquiv = *
reinterpret_cast<const int*
>(&number);
255 const int exponent = (intEquiv & 0x7f800000) >> 23;
256 const int mantissa = intEquiv & 0x007fffff;
262 *outExp = exponent - kExpBias;
264 *outMant = mantissa >> (kMantissaBitSize - kMantMSBs);
266 *fract = (float)(mantissa & (mantissaSize - 1)) * invMantissaSize;
284template <
int kPrecision>
285static inline float LogFastLookup(
287 const float*
const AAX_RESTRICT logTable)
290 int exponent, mantissa;
293 AAX::LogFloatToExpMantissa<kPrecision>(num, &exponent, &mantissa, &fract);
295 const float mantLog1 = logTable[mantissa];
296 const float mantLog2 = logTable[mantissa+1];
298 const float logOfNum = (mantLog1 * (1.0f - fract) + fract * mantLog2) + exponent;
Various utility definitions for AAX.
Definition: AAX_EnvironmentUtilities.h:72
const unsigned int kPowExtent
Definition: AAX_FastPow.h:61
const unsigned int kPowTableSize
Definition: AAX_FastPow.h:62