Skip to content

SCX eBPF function log2_u32

v6.12

The log2_u32 function computes the base 2 logarithm of a 32-bit exponential value.

Definition

static inline u32 log2_u32(u32 v)
{
    u32 r;
    u32 shift;

    r = (v > 0xFFFF) << 4; v >>= r;
    shift = (v > 0xFF) << 3; v >>= shift; r |= shift;
    shift = (v > 0xF) << 2; v >>= shift; r |= shift;
    shift = (v > 0x3) << 1; v >>= shift; r |= shift;
    r |= (v >> 1);
    return r;
}

Usage

Compute the base 2 logarithm of a 32-bit value.

Parameters

  • v: The value for which we're computing the base 2 logarithm.

Example

Docs could be improved

This part of the docs is incomplete, contributions are very welcome