\doxysection{include/osmocom/core/log2.h File Reference}
\label{log2_8h}\index{include/osmocom/core/log2.h@{include/osmocom/core/log2.h}}
{\ttfamily \#include $<$stdint.\+h$>$}\newline
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ const\+\_\+ilog2}(\textbf{ n})
\begin{DoxyCompactList}\small\item\em const\+\_\+ilog2 -\/ log base 2 of 32-\/bit or a 64-\/bit constant unsigned value ~\newline
\+: parameter \end{DoxyCompactList}\item 
\#define \textbf{ ilog2}(\textbf{ n})
\begin{DoxyCompactList}\small\item\em ilog2 -\/ log base 2 of 32-\/bit or a 64-\/bit unsigned value ~\newline
\+: parameter \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static \textbf{ \+\_\+\+\_\+attribute\+\_\+\+\_\+} ((always\+\_\+inline)) int fls(unsigned int \textbf{ x})
\begin{DoxyCompactList}\small\item\em fls -\/ find last (most-\/significant) bit set @x\+: the word to search \end{DoxyCompactList}\item 
static \textbf{ \+\_\+\+\_\+attribute\+\_\+\+\_\+} ((const)) int \+\_\+\+\_\+ilog2\+\_\+u32(uint32\+\_\+t \textbf{ n})
\end{DoxyCompactItemize}


\doxysubsection{Macro Definition Documentation}
\mbox{\label{log2_8h_a0e7c5d1dd4692f218a831d07bca5c644}} 
\index{log2.h@{log2.h}!const\_ilog2@{const\_ilog2}}
\index{const\_ilog2@{const\_ilog2}!log2.h@{log2.h}}
\doxysubsubsection{const\_ilog2}
{\footnotesize\ttfamily \#define const\+\_\+ilog2(\begin{DoxyParamCaption}\item[{}]{\textbf{ n} }\end{DoxyParamCaption})}



const\+\_\+ilog2 -\/ log base 2 of 32-\/bit or a 64-\/bit constant unsigned value ~\newline
\+: parameter 

Use this where sparse expects a true constant expression, e.\+g. for array indices. \mbox{\label{log2_8h_a2696c6303d4c53b65a3a7f7ff771d5eb}} 
\index{log2.h@{log2.h}!ilog2@{ilog2}}
\index{ilog2@{ilog2}!log2.h@{log2.h}}
\doxysubsubsection{ilog2}
{\footnotesize\ttfamily \#define ilog2(\begin{DoxyParamCaption}\item[{}]{\textbf{ n} }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{( \(\backslash\)}
\DoxyCodeLine{        \_\_builtin\_constant\_p(n) ?      \(\backslash\)}
\DoxyCodeLine{        const\_ilog2(n) :               \(\backslash\)}
\DoxyCodeLine{        (sizeof(n) <= 4) ?             \(\backslash\)}
\DoxyCodeLine{        \_\_ilog2\_u32(n) :               \(\backslash\)}
\DoxyCodeLine{        \_\_ilog2\_u64(n)                 \(\backslash\)}
\DoxyCodeLine{ )}

\end{DoxyCode}


ilog2 -\/ log base 2 of 32-\/bit or a 64-\/bit unsigned value ~\newline
\+: parameter 

constant-\/capable log of base 2 calculation
\begin{DoxyItemize}
\item this can be used to initialise global variables from constant data, hence the massive ternary operator construction
\end{DoxyItemize}

selects the appropriately-\/sized optimised version depending on sizeof(n) 

\doxysubsection{Function Documentation}
\mbox{\label{log2_8h_ae65d92d58bfeb475d2e2b2a66b2383bd}} 
\index{log2.h@{log2.h}!\_\_attribute\_\_@{\_\_attribute\_\_}}
\index{\_\_attribute\_\_@{\_\_attribute\_\_}!log2.h@{log2.h}}
\doxysubsubsection{\_\_attribute\_\_()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily static \+\_\+\+\_\+attribute\+\_\+\+\_\+ (\begin{DoxyParamCaption}\item[{(always\+\_\+inline)}]{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



fls -\/ find last (most-\/significant) bit set @x\+: the word to search 

fls64 -\/ find last set bit in a 64-\/bit word @x\+: the word to search

This is defined the same way as ffs. Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.

This is defined in a similar way as the libc and compiler builtin ffsll, but returns the position of the most significant set bit.

fls64(value) returns 0 if value is 0 or the position of the last set bit if value is nonzero. The last (most significant) bit is at position 64. 

References \textbf{ x}.

\mbox{\label{log2_8h_a9d5473a6b33c7daafcf50f3849a40830}} 
\index{log2.h@{log2.h}!\_\_attribute\_\_@{\_\_attribute\_\_}}
\index{\_\_attribute\_\_@{\_\_attribute\_\_}!log2.h@{log2.h}}
\doxysubsubsection{\_\_attribute\_\_()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily static \+\_\+\+\_\+attribute\+\_\+\+\_\+ (\begin{DoxyParamCaption}\item[{(const)}]{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



References \textbf{ n}.

