\doxysection{fixlog.\+c}
\label{fixlog_8c_source}\index{src/libsphinxbase/fe/fixlog.c@{src/libsphinxbase/fe/fixlog.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{/*\ -\/*-\/\ c-\/basic-\/offset:\ 4;\ indent-\/tabs-\/mode:\ nil\ -\/*-\/\ */}}
\DoxyCodeLine{00002\ \textcolor{comment}{/*\ ====================================================================}}
\DoxyCodeLine{00003\ \textcolor{comment}{\ *\ Copyright\ (c)\ 2005\ Carnegie\ Mellon\ University.\ \ All\ rights\ }}
\DoxyCodeLine{00004\ \textcolor{comment}{\ *\ reserved.}}
\DoxyCodeLine{00005\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00006\ \textcolor{comment}{\ *\ Redistribution\ and\ use\ in\ source\ and\ binary\ forms,\ with\ or\ without}}
\DoxyCodeLine{00007\ \textcolor{comment}{\ *\ modification,\ are\ permitted\ provided\ that\ the\ following\ conditions}}
\DoxyCodeLine{00008\ \textcolor{comment}{\ *\ are\ met:}}
\DoxyCodeLine{00009\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00010\ \textcolor{comment}{\ *\ 1.\ Redistributions\ of\ source\ code\ must\ retain\ the\ above\ copyright}}
\DoxyCodeLine{00011\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer.\ }}
\DoxyCodeLine{00012\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00013\ \textcolor{comment}{\ *\ 2.\ Redistributions\ in\ binary\ form\ must\ reproduce\ the\ above\ copyright}}
\DoxyCodeLine{00014\ \textcolor{comment}{\ *\ \ \ \ notice,\ this\ list\ of\ conditions\ and\ the\ following\ disclaimer\ in}}
\DoxyCodeLine{00015\ \textcolor{comment}{\ *\ \ \ \ the\ documentation\ and/or\ other\ materials\ provided\ with\ the}}
\DoxyCodeLine{00016\ \textcolor{comment}{\ *\ \ \ \ distribution.}}
\DoxyCodeLine{00017\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00018\ \textcolor{comment}{\ *\ This\ work\ was\ supported\ in\ part\ by\ funding\ from\ the\ Defense\ Advanced\ }}
\DoxyCodeLine{00019\ \textcolor{comment}{\ *\ Research\ Projects\ Agency\ and\ the\ National\ Science\ Foundation\ of\ the\ }}
\DoxyCodeLine{00020\ \textcolor{comment}{\ *\ United\ States\ of\ America,\ and\ the\ CMU\ Sphinx\ Speech\ Consortium.}}
\DoxyCodeLine{00021\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00022\ \textcolor{comment}{\ *\ THIS\ SOFTWARE\ IS\ PROVIDED\ BY\ CARNEGIE\ MELLON\ UNIVERSITY\ \`{}\`{}AS\ IS''\ AND\ }}
\DoxyCodeLine{00023\ \textcolor{comment}{\ *\ ANY\ EXPRESSED\ OR\ IMPLIED\ WARRANTIES,\ INCLUDING,\ BUT\ NOT\ LIMITED\ TO,\ }}
\DoxyCodeLine{00024\ \textcolor{comment}{\ *\ THE\ IMPLIED\ WARRANTIES\ OF\ MERCHANTABILITY\ AND\ FITNESS\ FOR\ A\ PARTICULAR}}
\DoxyCodeLine{00025\ \textcolor{comment}{\ *\ PURPOSE\ ARE\ DISCLAIMED.\ \ IN\ NO\ EVENT\ SHALL\ CARNEGIE\ MELLON\ UNIVERSITY}}
\DoxyCodeLine{00026\ \textcolor{comment}{\ *\ NOR\ ITS\ EMPLOYEES\ BE\ LIABLE\ FOR\ ANY\ DIRECT,\ INDIRECT,\ INCIDENTAL,}}
\DoxyCodeLine{00027\ \textcolor{comment}{\ *\ SPECIAL,\ EXEMPLARY,\ OR\ CONSEQUENTIAL\ DAMAGES\ (INCLUDING,\ BUT\ NOT\ }}
\DoxyCodeLine{00028\ \textcolor{comment}{\ *\ LIMITED\ TO,\ PROCUREMENT\ OF\ SUBSTITUTE\ GOODS\ OR\ SERVICES;\ LOSS\ OF\ USE,\ }}
\DoxyCodeLine{00029\ \textcolor{comment}{\ *\ DATA,\ OR\ PROFITS;\ OR\ BUSINESS\ INTERRUPTION)\ HOWEVER\ CAUSED\ AND\ ON\ ANY\ }}
\DoxyCodeLine{00030\ \textcolor{comment}{\ *\ THEORY\ OF\ LIABILITY,\ WHETHER\ IN\ CONTRACT,\ STRICT\ LIABILITY,\ OR\ TORT\ }}
\DoxyCodeLine{00031\ \textcolor{comment}{\ *\ (INCLUDING\ NEGLIGENCE\ OR\ OTHERWISE)\ ARISING\ IN\ ANY\ WAY\ OUT\ OF\ THE\ USE\ }}
\DoxyCodeLine{00032\ \textcolor{comment}{\ *\ OF\ THIS\ SOFTWARE,\ EVEN\ IF\ ADVISED\ OF\ THE\ POSSIBILITY\ OF\ SUCH\ DAMAGE.}}
\DoxyCodeLine{00033\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00034\ \textcolor{comment}{\ *\ ====================================================================}}
\DoxyCodeLine{00035\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00036\ \textcolor{comment}{\ *\ File:\ fixlog.c}}
\DoxyCodeLine{00037\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00038\ \textcolor{comment}{\ *\ Description:\ Fast\ approximate\ fixed-\/point\ logarithms}}
\DoxyCodeLine{00039\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00040\ \textcolor{comment}{\ *\ Author:\ David\ Huggins-\/Daines\ <dhuggins@cs.cmu.edu>}}
\DoxyCodeLine{00041\ \textcolor{comment}{\ *}}
\DoxyCodeLine{00042\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \textcolor{preprocessor}{\#ifdef\ HAVE\_CONFIG\_H}}
\DoxyCodeLine{00045\ \textcolor{preprocessor}{\#include\ <config.h>}}
\DoxyCodeLine{00046\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00047\ }
\DoxyCodeLine{00048\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/prim\_type.h"{}}}
\DoxyCodeLine{00049\ \textcolor{preprocessor}{\#include\ "{}sphinxbase/fixpoint.h"{}}}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ \textcolor{preprocessor}{\#include\ "{}fe\_internal.h"{}}}
\DoxyCodeLine{00052\ }
\DoxyCodeLine{00053\ \textcolor{comment}{/*\ Table\ of\ log2(x/64)*(1<<DEFAULT\_RADIX)\ */}}
\DoxyCodeLine{00054\ \textcolor{comment}{/*\ perl\ -\/e\ 'for\ (0..63)\ \{my\ \$x\ =\ 1\ +\ \$\_/64;\ print\ "{}\(\backslash\)t(uint32)("{},\ log(\$x)/log(2),\ "{}*(1<<DEFAULT\_RADIX)),\(\backslash\)n"{}\}'\ */}}
\DoxyCodeLine{00055\ \textcolor{keyword}{static}\ uint32\ logtable[]\ =\ \{}
\DoxyCodeLine{00056\ \ \ \ \ (uint32)\ (0\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00057\ \ \ \ \ (uint32)\ (0.0223678130284545\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00058\ \ \ \ \ (uint32)\ (0.0443941193584534\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00059\ \ \ \ \ (uint32)\ (0.0660891904577724\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00060\ \ \ \ \ (uint32)\ (0.0874628412503394\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00061\ \ \ \ \ (uint32)\ (0.108524456778169\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00062\ \ \ \ \ (uint32)\ (0.129283016944966\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00063\ \ \ \ \ (uint32)\ (0.149747119504682\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00064\ \ \ \ \ (uint32)\ (0.169925001442312\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00065\ \ \ \ \ (uint32)\ (0.189824558880017\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00066\ \ \ \ \ (uint32)\ (0.20945336562895\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00067\ \ \ \ \ (uint32)\ (0.228818690495881\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00068\ \ \ \ \ (uint32)\ (0.247927513443586\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00069\ \ \ \ \ (uint32)\ (0.266786540694901\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00070\ \ \ \ \ (uint32)\ (0.285402218862248\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00071\ \ \ \ \ (uint32)\ (0.303780748177103\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00072\ \ \ \ \ (uint32)\ (0.321928094887362\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00073\ \ \ \ \ (uint32)\ (0.339850002884625\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00074\ \ \ \ \ (uint32)\ (0.357552004618084\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00075\ \ \ \ \ (uint32)\ (0.375039431346925\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00076\ \ \ \ \ (uint32)\ (0.39231742277876\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00077\ \ \ \ \ (uint32)\ (0.409390936137702\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00078\ \ \ \ \ (uint32)\ (0.426264754702098\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00079\ \ \ \ \ (uint32)\ (0.442943495848728\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00080\ \ \ \ \ (uint32)\ (0.459431618637297\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00081\ \ \ \ \ (uint32)\ (0.475733430966398\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00082\ \ \ \ \ (uint32)\ (0.491853096329675\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00083\ \ \ \ \ (uint32)\ (0.507794640198696\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00084\ \ \ \ \ (uint32)\ (0.523561956057013\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00085\ \ \ \ \ (uint32)\ (0.539158811108031\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00086\ \ \ \ \ (uint32)\ (0.554588851677637\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00087\ \ \ \ \ (uint32)\ (0.569855608330948\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00088\ \ \ \ \ (uint32)\ (0.584962500721156\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00089\ \ \ \ \ (uint32)\ (0.599912842187128\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00090\ \ \ \ \ (uint32)\ (0.614709844115208\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00091\ \ \ \ \ (uint32)\ (0.62935662007961\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00092\ \ \ \ \ (uint32)\ (0.643856189774725\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00093\ \ \ \ \ (uint32)\ (0.658211482751795\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00094\ \ \ \ \ (uint32)\ (0.672425341971496\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00095\ \ \ \ \ (uint32)\ (0.686500527183218\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00096\ \ \ \ \ (uint32)\ (0.700439718141092\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00097\ \ \ \ \ (uint32)\ (0.714245517666123\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00098\ \ \ \ \ (uint32)\ (0.727920454563199\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00099\ \ \ \ \ (uint32)\ (0.741466986401147\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00100\ \ \ \ \ (uint32)\ (0.754887502163469\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00101\ \ \ \ \ (uint32)\ (0.768184324776926\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00102\ \ \ \ \ (uint32)\ (0.78135971352466\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00103\ \ \ \ \ (uint32)\ (0.794415866350106\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00104\ \ \ \ \ (uint32)\ (0.807354922057604\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00105\ \ \ \ \ (uint32)\ (0.820178962415188\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00106\ \ \ \ \ (uint32)\ (0.832890014164742\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00107\ \ \ \ \ (uint32)\ (0.845490050944375\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00108\ \ \ \ \ (uint32)\ (0.857980995127572\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00109\ \ \ \ \ (uint32)\ (0.870364719583405\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00110\ \ \ \ \ (uint32)\ (0.882643049361841\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00111\ \ \ \ \ (uint32)\ (0.894817763307944\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00112\ \ \ \ \ (uint32)\ (0.906890595608518\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00113\ \ \ \ \ (uint32)\ (0.918863237274595\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00114\ \ \ \ \ (uint32)\ (0.930737337562886\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00115\ \ \ \ \ (uint32)\ (0.94251450533924\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00116\ \ \ \ \ (uint32)\ (0.954196310386875\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00117\ \ \ \ \ (uint32)\ (0.965784284662087\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00118\ \ \ \ \ (uint32)\ (0.977279923499917\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00119\ \ \ \ \ (uint32)\ (0.988684686772166\ *\ (1\ <<\ DEFAULT\_RADIX)),}
\DoxyCodeLine{00120\ \};}
\DoxyCodeLine{00121\ }
\DoxyCodeLine{00122\ int32}
\DoxyCodeLine{00123\ fixlog2(uint32\ x)}
\DoxyCodeLine{00124\ \{}
\DoxyCodeLine{00125\ \ \ \ \ uint32\ y;}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{keywordflow}{if}\ (x\ ==\ 0)}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ MIN\_FIXLOG2;}
\DoxyCodeLine{00129\ }
\DoxyCodeLine{00130\ \ \ \ \ \textcolor{comment}{/*\ Get\ the\ exponent.\ */}}
\DoxyCodeLine{00131\ \textcolor{preprocessor}{\#if\ defined(\_\_GNUC\_\_)\ \&\&\ defined(\_\_i386\_\_)\ }}
\DoxyCodeLine{00132\ \ \ \_\_asm\_\_(\textcolor{stringliteral}{"{}bsrl\ \%1,\ \%0\(\backslash\)n"{}}:\ \textcolor{stringliteral}{"{}=r"{}}(y):\ \textcolor{stringliteral}{"{}g"{}}(x):\textcolor{stringliteral}{"{}cc"{}});}
\DoxyCodeLine{00133\ \ \ \ \ x\ <<=\ (31\ -\/\ y);}
\DoxyCodeLine{00134\ \textcolor{preprocessor}{\#elif\ defined(\_\_ppc\_\_)}}
\DoxyCodeLine{00135\ \ \ \_\_asm\_\_(\textcolor{stringliteral}{"{}cntlzw\ \%0,\ \%1\(\backslash\)n"{}}:\ \textcolor{stringliteral}{"{}=r"{}}(y):\textcolor{stringliteral}{"{}r"{}}(x));}
\DoxyCodeLine{00136\ \ \ \ \ x\ <<=\ y;}
\DoxyCodeLine{00137\ \ \ \ \ y\ =\ 31\ -\/\ y;}
\DoxyCodeLine{00138\ \textcolor{preprocessor}{\#elif\ ((defined(\_\_ARM\_ARCH\_5\_\_)\ ||\ defined(\_\_ARM\_ARCH\_5T\_\_)\ ||\ \(\backslash\)}}
\DoxyCodeLine{00139\ \textcolor{preprocessor}{\ \ \ \ \ \ \ \ defined(\_\_ARM\_ARCH\_5TE\_\_))\ \&\&\ !defined(\_\_thumb\_\_))}}
\DoxyCodeLine{00140\ \ \ \_\_asm\_\_(\textcolor{stringliteral}{"{}clz\ \%0,\ \%1\(\backslash\)n"{}}:\ \textcolor{stringliteral}{"{}=r"{}}(y):\textcolor{stringliteral}{"{}r"{}}(x));}
\DoxyCodeLine{00141\ \ \ \ \ x\ <<=\ y;}
\DoxyCodeLine{00142\ \ \ \ \ y\ =\ 31\ -\/\ y;}
\DoxyCodeLine{00143\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00144\ \ \ \ \ \textcolor{keywordflow}{for}\ (y\ =\ 31;\ y\ >\ 0;\ -\/-\/y)\ \{}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (x\ \&\ 0x80000000)}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ x\ <<=\ 1;}
\DoxyCodeLine{00148\ \ \ \ \ \}}
\DoxyCodeLine{00149\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00150\ \ \ \ \ y\ <<=\ DEFAULT\_RADIX;}
\DoxyCodeLine{00151\ \ \ \ \ \textcolor{comment}{/*\ Do\ a\ table\ lookup\ for\ the\ MSB\ of\ the\ mantissa.\ */}}
\DoxyCodeLine{00152\ \ \ \ \ x\ =\ (x\ >>\ 25)\ \&\ 0x3f;}
\DoxyCodeLine{00153\ \ \ \ \ \textcolor{keywordflow}{return}\ y\ +\ logtable[x];}
\DoxyCodeLine{00154\ \}}
\DoxyCodeLine{00155\ }
\DoxyCodeLine{00156\ \textcolor{keywordtype}{int}}
\DoxyCodeLine{00157\ fixlog(uint32\ x)}
\DoxyCodeLine{00158\ \{}
\DoxyCodeLine{00159\ \ \ \ \ int32\ y;}
\DoxyCodeLine{00160\ }
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{keywordflow}{if}\ (x\ ==\ 0)}
\DoxyCodeLine{00162\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ MIN\_FIXLOG;}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \ \ \ \ y\ =\ fixlog2(x);}
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{keywordflow}{return}\ FIXMUL(y,\ FIXLN\_2);}
\DoxyCodeLine{00166\ \}}

\end{DoxyCode}
