Loading...
Searching...
No Matches
log2.h File Reference
`#include <stdint.h>`

Go to the source code of this file.

## Macros

#define | const_ilog2(n)
| const_ilog2 - log base 2 of 32-bit or a 64-bit constant unsigned value : parameter
#define | ilog2(n)
| ilog2 - log base 2 of 32-bit or a 64-bit unsigned value : parameter

## Functions

static | __attribute__ ((always_inline)) int fls(unsigned int x)
| fls - find last (most-significant) bit set @x: the word to search
static | __attribute__ ((const)) int __ilog2_u32(uint32_t n)

## Macro Definition Documentation

## const_ilog2

#define const_ilog2 | ( |  | n | ) |

const_ilog2 - log base 2 of 32-bit or a 64-bit constant unsigned value
: parameter

Use this where sparse expects a true constant expression, e.g. for array indices.

## ilog2

#define ilog2 | ( |  | n | ) |

Value:
( \
__builtin_constant_p(n) ? \
const_ilog2(n) : \
(sizeof(n) <= 4) ? \
__ilog2_u32(n) : \
__ilog2_u64(n) \
)
n
write Write running configuration to or terminal n Write configuration to the copy running config startup Copy configuration n Copy running config to n Copy running config to startup write Write running configuration to or terminal n Write to terminal n

ilog2 - log base 2 of 32-bit or a 64-bit unsigned value
: parameter

constant-capable log of base 2 calculation

- this can be used to initialise global variables from constant data, hence the massive ternary operator construction

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

## Function Documentation

## __attribute__() [1/2]

__attribute__ | ( | (always_inline) |  | ) |

inline 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 x.

## __attribute__() [2/2]

__attribute__ | ( | (const) |  | ) |

inline static