Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
log2.h File Reference
#include <linux/types.h>
#include <linux/bitops.h>

Go to the source code of this file.

Macros

#define ilog2(n)
 
#define roundup_pow_of_two(n)
 
#define rounddown_pow_of_two(n)
 
#define order_base_2(n)   ilog2(roundup_pow_of_two(n))
 

Functions

 __attribute__ ((const, noreturn)) int ____ilog2_NaN(void)
 

Macro Definition Documentation

#define ilog2 (   n)

ilog2 - log of 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)

Definition at line 85 of file log2.h.

#define order_base_2 (   n)    ilog2(roundup_pow_of_two(n))

order_base_2 - calculate the (rounded up) base 2 order of the argument
: parameter

The first few values calculated by this routine: ob2(0) = 0 ob2(1) = 0 ob2(2) = 1 ob2(3) = 2 ob2(4) = 2 ob2(5) = 3 ... and so on.

Definition at line 206 of file log2.h.

#define rounddown_pow_of_two (   n)
Value:
( \
__builtin_constant_p(n) ? ( \
(1UL << ilog2(n))) : \
__rounddown_pow_of_two(n) \
)

rounddown_pow_of_two - round the given value down to nearest power of two
- parameter

round the given value down to the nearest power of two

  • the result is undefined when n == 0
  • this can be used to initialise global variables from constant data

Definition at line 185 of file log2.h.

#define roundup_pow_of_two (   n)
Value:
( \
__builtin_constant_p(n) ? ( \
(n == 1) ? 1 : \
(1UL << (ilog2((n) - 1) + 1)) \
) : \
__roundup_pow_of_two(n) \
)

roundup_pow_of_two - round the given value up to nearest power of two
- parameter

round the given value up to the nearest power of two

  • the result is undefined when n == 0
  • this can be used to initialise global variables from constant data

Definition at line 168 of file log2.h.

Function Documentation