std1.0.0-beta-7 SafeC docs

Module bit

#include <std/bit.h> source

Bit manipulation (C23 <stdbit.h> + compiler builtins) All functions are const-eligible (pure, no side effects).

Functions

popcount32
popcount64Count set bits in a 64-bit value.
clz32Number of leading 0-bits before the most significant 1-bit. Returns 32 for x == 0.
clz64Returns 64 for x == 0.
ctz32Number of trailing 0-bits after the least significant 1-bit. Returns 32 for x == 0.
ctz64Returns 64 for x == 0.
bsf32Index of the least-significant set bit (0-based). Returns -1 for x == 0.
bsf64
bsr32Index of the most-significant set bit (0-based). Returns -1 for x == 0.
bsr64
rotl32Rotate x left/right by n bits (n is taken modulo 32/64).
rotr32
rotl64
rotr64
bswap32
bswap64
is_pow2Return 1 if x is a power of two (x > 0).
next_pow2Round x up to the next power of two (returns x if already a power of two). Returns 1 for x == 0.
ilog2Integer log2 (floor). Returns -1 for x == 0.
bits32Extract bits [hi:lo] (inclusive) from x.
bits64
set_bits32Set bits [hi:lo] to val in x, return new value.