\hypertarget{a00863_source}{}\doxysection{AAX\+\_\+\+Fast\+Pow.\+h}
\label{a00863_source}\index{AAX\_FastPow.h@{AAX\_FastPow.h}}
\mbox{\hyperlink{a00863}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ \ Copyright\ 2009-\/2015,\ 2023\ Avid\ Technology,\ Inc.}}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ \ All\ rights\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *\ \ }}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ \ CONFIDENTIAL:\ this\ document\ contains\ confidential\ information\ of\ Avid.\ Do}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ \ not\ disclose\ to\ any\ third\ party.\ Use\ of\ the\ information\ contained\ in\ this}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ \ document\ is\ subject\ to\ an\ Avid\ SDK\ license.}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00029\ \textcolor{comment}{/*================================================================================================*/}}
\DoxyCodeLine{00030\ }
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ }
\DoxyCodeLine{00034\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ \textcolor{preprocessor}{\#ifndef\ \_AAX\_FASTPOW\_H\_}}
\DoxyCodeLine{00037\ \textcolor{preprocessor}{\#define\ \_AAX\_FASTPOW\_H\_}}
\DoxyCodeLine{00038\ }
\DoxyCodeLine{00039\ \textcolor{preprocessor}{\#include\ <cmath>}\ }
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#if\ defined(MAC\_VERSION)\ ||\ defined(LINUX\_VERSION)}}
\DoxyCodeLine{00041\ \textcolor{keyword}{namespace\ }std\ \ \{using\ ::powf;using\ ::log10f;using\ ::fabsf;\}}
\DoxyCodeLine{00042\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00043\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{a00533}{AAX.h}}"{}}\ \ \ \textcolor{comment}{//\ For\ AAX\_RESTRICT}}
\DoxyCodeLine{00044\ }
\DoxyCodeLine{00045\ \textcolor{keyword}{namespace\ }\mbox{\hyperlink{a00935}{AAX}}}
\DoxyCodeLine{00046\ \{}
\DoxyCodeLine{00047\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ \_2p23\ =\ 8388608.0f;}
\DoxyCodeLine{00048\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{a00935_a4e6fcac015bb083018e8897563966cf6}{kPowExtent}}\ =\ 9;\ \ \ \ \textcolor{comment}{//\ 9\ results\ in\ \string~-\/80dB\ cancellation}}
\DoxyCodeLine{00049\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ \mbox{\hyperlink{a00935_a59f1ab59ea51ed94f87e8d935870df9e}{kPowTableSize}}\ =\ 1\ <<\ \mbox{\hyperlink{a00935_a4e6fcac015bb083018e8897563966cf6}{kPowExtent}};}
\DoxyCodeLine{00050\ \ \ \ \ }
\DoxyCodeLine{00065\ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ PowFastSetTable(}
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ pTable,}
\DoxyCodeLine{00067\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ precision,}
\DoxyCodeLine{00068\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ extent,}
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{bool}\ isRound)}
\DoxyCodeLine{00070\ \{}
\DoxyCodeLine{00071\ \ \ \ \textcolor{comment}{//\ step\ along\ table\ elements\ and\ x-\/axis\ positions}}
\DoxyCodeLine{00072\ \ \ \ \textcolor{keywordtype}{float}\ zeroToOne\ =\ !isRound\ ?}
\DoxyCodeLine{00073\ \ \ \ \ \ \ 0.0f\ :\ (1.0f\ /\ (\textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{float}\textcolor{keyword}{>}(1\ <<\ precision)\ *\ 2.0f));}
\DoxyCodeLine{00074\ \ \ \ \textcolor{keywordflow}{for}(\ \textcolor{keywordtype}{int}\ i\ =\ 0;\ \ i\ <\ (1\ <<\ extent);\ \ ++i\ )}
\DoxyCodeLine{00075\ \ \ \ \{}
\DoxyCodeLine{00076\ \ \ \ \ \ \ \textcolor{comment}{//\ make\ y-\/axis\ value\ for\ table\ element}}
\DoxyCodeLine{00077\ \ \ \ \ \ \ pTable[i]\ =\ std::powf(\ 2.0f,\ zeroToOne\ );}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00079\ \ \ \ \ \ \ zeroToOne\ +=\ 1.0f\ /\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{float}\textcolor{keyword}{>}(1\ <<\ precision);}
\DoxyCodeLine{00080\ \ \ \ \}}
\DoxyCodeLine{00081\ \}}
\DoxyCodeLine{00082\ \ \ \ \ }
\DoxyCodeLine{00128\ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{float}\ PowFastLookup(}
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ \ \ \ \ \ \ \ \ val,}
\DoxyCodeLine{00130\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ \ \ \ \ \ \ \ \ ilog2,}
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ tableH,}
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ tableL)}
\DoxyCodeLine{00133\ \{}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ \ \ \ \ \textcolor{comment}{//\ build\ float\ bits}}
\DoxyCodeLine{00136\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ i\ =\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{int}\textcolor{keyword}{>}(\ (val\ *\ (\_2p23\ *\ ilog2))\ +\ (127.0f\ *\ \_2p23)\ );}
\DoxyCodeLine{00137\ }
\DoxyCodeLine{00138\ \ \ \ \ \textcolor{comment}{//\ replace\ mantissa\ with\ combined\ lookups}}
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ t\ \ =\ tableH[(i\ >>\ 14)\ \&\ 0x1FF]\ *\ tableL[(i\ >>\ 5)\ \&\ 0x1FF];}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ \ \ it\ =\ (i\ \&\ 0xFF800000)\ |}
\DoxyCodeLine{00141\ \ \ \ \ \ \ (*\textcolor{keyword}{reinterpret\_cast<}\textcolor{keyword}{const\ }\textcolor{keywordtype}{int}*\textcolor{keyword}{>}(\ \&t\ )\ \&\ 0x7FFFFF);}
\DoxyCodeLine{00142\ }
\DoxyCodeLine{00143\ \ \ \ \ \textcolor{comment}{//\ convert\ bits\ to\ float}}
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{reinterpret\_cast<}\textcolor{keyword}{const\ }\textcolor{keywordtype}{float}*\textcolor{keyword}{>}(\ \&it\ );}
\DoxyCodeLine{00145\ }
\DoxyCodeLine{00146\ \}}
\DoxyCodeLine{00147\ }
\DoxyCodeLine{00159\ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{float}\ Pow2FastLookup(}
\DoxyCodeLine{00160\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ \ \ \ \ \ \ \ \ val,}
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ tableH,}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ tableL)}
\DoxyCodeLine{00163\ \{}
\DoxyCodeLine{00164\ }
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{comment}{//\ build\ float\ bits}}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ i\ =\ \textcolor{keyword}{static\_cast<}\textcolor{keywordtype}{int}\textcolor{keyword}{>}((val\ +\ 127.0f)\ *\ \_2p23);}
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{comment}{//\ replace\ mantissa\ with\ combined\ lookups}}
\DoxyCodeLine{00169\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ t\ \ =\ tableH[(i\ >>\ 14)\ \&\ 0x1FF]\ *\ tableL[(i\ >>\ 5)\ \&\ 0x1FF];}
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ \ \ it\ =\ (i\ \&\ 0xFF800000)\ |}
\DoxyCodeLine{00171\ \ \ \ \ \ \ (*\textcolor{keyword}{reinterpret\_cast<}\textcolor{keyword}{const\ }\textcolor{keywordtype}{int}*\textcolor{keyword}{>}(\ \&t\ )\ \&\ 0x007FFFFF);}
\DoxyCodeLine{00172\ }
\DoxyCodeLine{00173\ \ \ \ \ \textcolor{comment}{//\ convert\ bits\ to\ float}}
\DoxyCodeLine{00174\ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{reinterpret\_cast<}\textcolor{keyword}{const\ }\textcolor{keywordtype}{float}*\textcolor{keyword}{>}(\ \&it\ );}
\DoxyCodeLine{00175\ }
\DoxyCodeLine{00176\ \}}
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00179\ }
\DoxyCodeLine{00180\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ kMantissaBitSize\ =\ 23;}
\DoxyCodeLine{00181\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ kExpBias\ =\ 127;}
\DoxyCodeLine{00182\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ kLogMantissaMSBs\ =\ 9;}
\DoxyCodeLine{00183\ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ kLogTableSize\ =\ (1\ <<\ kLogMantissaMSBs)\ +\ 1;\textcolor{comment}{//\ 513;\ \ \ \ }}
\DoxyCodeLine{00184\ }
\DoxyCodeLine{00195\ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ LogFastSetTable(}
\DoxyCodeLine{00196\ \ \ \ \ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ logTable,\ }
\DoxyCodeLine{00197\ \ \ \ \ \textcolor{keywordtype}{int}\ tableSize\ =\ kLogTableSize)}
\DoxyCodeLine{00198\ \{}
\DoxyCodeLine{00199\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ kInv\ =\ 1.0f/float(tableSize\ -\/\ 1);\ \textcolor{comment}{//\ 0.001953125}}
\DoxyCodeLine{00200\ \ \ \ \ \textcolor{keywordtype}{float}\ mantissaVal\ =\ 1.0f;\ \ \ \textcolor{comment}{//Start\ here.}}
\DoxyCodeLine{00201\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ invLog10Base2\ =\ 1.0f\ /\ std::log10f(2.0f);}
\DoxyCodeLine{00202\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ j\ =\ 0;\ j\ <\ tableSize;\ j++)}
\DoxyCodeLine{00203\ \ \ \ \ \{}
\DoxyCodeLine{00204\ \ \ \ \ \ \ \ \ logTable[j]\ =\ std::log10f(mantissaVal)\ *\ invLog10Base2;\ \textcolor{comment}{//By\ log\ equivalency:\ log2(x)\ =\ log10(x)/log10(2)}}
\DoxyCodeLine{00205\ \ \ \ \ \ \ \ \ mantissaVal\ +=\ kInv;}
\DoxyCodeLine{00206\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00207\ \ \ \ \ \}}
\DoxyCodeLine{00208\ }
\DoxyCodeLine{00209\ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00210\ \}}
\DoxyCodeLine{00211\ }
\DoxyCodeLine{00230\ \textcolor{keyword}{template}\ <\textcolor{keywordtype}{int}\ kMantMSBs>}
\DoxyCodeLine{00231\ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{void}\ LogFloatToExpMantissa(}
\DoxyCodeLine{00232\ \ \ \ \ \textcolor{keywordtype}{float}\ number,\ }
\DoxyCodeLine{00233\ \ \ \ \ \textcolor{keywordtype}{int}\ *\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ outExp,\ }
\DoxyCodeLine{00234\ \ \ \ \ \textcolor{keywordtype}{int}\ *\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ outMant,\ }
\DoxyCodeLine{00235\ \ \ \ \ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ fract)}
\DoxyCodeLine{00236\ \{\ \ \ }
\DoxyCodeLine{00237\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ mantissaSize\ =\ 1\ <<\ (kMantissaBitSize\ -\/\ kMantMSBs);}
\DoxyCodeLine{00238\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ invMantissaSize\ =\ 1.0f/(float)mantissaSize;}
\DoxyCodeLine{00239\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ intEquiv\ =\ *\textcolor{keyword}{reinterpret\_cast<}\textcolor{keyword}{const\ }\textcolor{keywordtype}{int}*\textcolor{keyword}{>}(\&number);}
\DoxyCodeLine{00240\ }
\DoxyCodeLine{00241\ \ \ \ \ \textcolor{comment}{//bool\ isNegative\ =\ (result\ \&\ 0x80000000)\ !=\ 0;\ //Sign\ bit}}
\DoxyCodeLine{00242\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ exponent\ \ \ \ \ \ =\ (intEquiv\ \&\ 0x7f800000)\ >>\ 23;\ \textcolor{comment}{//Exponent\ bits}}
\DoxyCodeLine{00243\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ mantissa\ \ \ \ \ \ =\ \ intEquiv\ \&\ 0x007fffff;\ \textcolor{comment}{//Mantissa\ bits.}}
\DoxyCodeLine{00244\ }
\DoxyCodeLine{00245\ \ \ \ \ \textcolor{comment}{//\ 0\ 000|0\ 000|0\ 1\ 010|\ 0000\ 0000\ 0000\ 0000\ 0000}}
\DoxyCodeLine{00246\ \ \ \ \ \textcolor{comment}{//\ 0111\ 1111\ 1000\ 0000\ 0000\ 0000\ 0000\ 0000\ =\ 7f800000\ (Exp)\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }}
\DoxyCodeLine{00247\ \ \ \ \ \textcolor{comment}{//\ 0000\ 0000\ 0111\ 1111\ 1111\ 1111\ 1111\ 1111\ =\ 007fffff\ (Mant)}}
\DoxyCodeLine{00248\ }
\DoxyCodeLine{00249\ \ \ \ \ *outExp\ =\ exponent\ -\/\ kExpBias;\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//Compensate\ for\ exponent\ bias\ for\ caller.}}
\DoxyCodeLine{00250\ \ \ \ \ \textcolor{comment}{//To\ do:\ add\ halfLSBShifted\ to\ mantissa\ before\ shifting;\ *outMant\ =\ (mantissa\ +\ halfLSBShifted)\ >>\ (kMantissaBitSize\ -\/\ mantMSBs)}}
\DoxyCodeLine{00251\ \ \ \ \ *outMant\ =\ mantissa\ >>\ (kMantissaBitSize\ -\/\ kMantMSBs);\ \ \ \ \ \ \textcolor{comment}{//Shift\ to\ provide\ only\ mantMSBs\ for\ log\ LUT.}}
\DoxyCodeLine{00252\ \ \ \ \ \textcolor{comment}{//\ Provide\ a\ linear\ interpolation\ fraction}}
\DoxyCodeLine{00253\ \ \ \ \ *fract\ =\ (float)(mantissa\ \&\ (mantissaSize\ -\/\ 1))\ *\ invMantissaSize;}
\DoxyCodeLine{00254\ }
\DoxyCodeLine{00255\ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00256\ \}\ \ \ \ \ }
\DoxyCodeLine{00257\ }
\DoxyCodeLine{00271\ \textcolor{keyword}{template}\ <\textcolor{keywordtype}{int}\ kPrecision>}
\DoxyCodeLine{00272\ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{float}\ LogFastLookup(}
\DoxyCodeLine{00273\ \ \ \ \ \textcolor{keywordtype}{float}\ num,\ }
\DoxyCodeLine{00274\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}*\ \textcolor{keyword}{const}\ AAX\_RESTRICT\ logTable)}
\DoxyCodeLine{00275\ \{}
\DoxyCodeLine{00276\ }
\DoxyCodeLine{00277\ \ \ \ \ \textcolor{keywordtype}{int}\ exponent,\ mantissa;}
\DoxyCodeLine{00278\ \ \ \ \ \textcolor{keywordtype}{float}\ fract;}
\DoxyCodeLine{00279\ }
\DoxyCodeLine{00280\ \ \ \ \ AAX::LogFloatToExpMantissa<kPrecision>(num,\ \&exponent,\ \&mantissa,\ \&fract);}
\DoxyCodeLine{00281\ }
\DoxyCodeLine{00282\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ mantLog1\ =\ logTable[mantissa];}
\DoxyCodeLine{00283\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ mantLog2\ =\ logTable[mantissa+1];}
\DoxyCodeLine{00284\ }
\DoxyCodeLine{00285\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{float}\ logOfNum\ =\ (mantLog1\ *\ (1.0f\ -\/\ fract)\ +\ fract\ *\ mantLog2)\ +\ exponent;}
\DoxyCodeLine{00286\ \ \ \ \ \textcolor{keywordflow}{return}\ logOfNum;}
\DoxyCodeLine{00287\ \}\ \ }
\DoxyCodeLine{00288\ }
\DoxyCodeLine{00289\ }
\DoxyCodeLine{00290\ }
\DoxyCodeLine{00291\ \}\ \textcolor{comment}{//\ namespace\ AAX}}
\DoxyCodeLine{00292\ }
\DoxyCodeLine{00293\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//\ \#ifndef\ \_AAX\_FASTPOW\_H\_}}

\end{DoxyCode}
