Module bit
Bit manipulation (C23 <stdbit.h> + compiler builtins) All functions are const-eligible (pure, no side effects).
Functions
| popcount32 | |
| popcount64 | Count set bits in a 64-bit value. |
| clz32 | Number of leading 0-bits before the most significant 1-bit. Returns 32 for x == 0. |
| clz64 | Returns 64 for x == 0. |
| ctz32 | Number of trailing 0-bits after the least significant 1-bit. Returns 32 for x == 0. |
| ctz64 | Returns 64 for x == 0. |
| bsf32 | Index of the least-significant set bit (0-based). Returns -1 for x == 0. |
| bsf64 | |
| bsr32 | Index of the most-significant set bit (0-based). Returns -1 for x == 0. |
| bsr64 | |
| rotl32 | Rotate x left/right by n bits (n is taken modulo 32/64). |
| rotr32 | |
| rotl64 | |
| rotr64 | |
| bswap32 | |
| bswap64 | |
| is_pow2 | Return 1 if x is a power of two (x > 0). |
| next_pow2 | Round x up to the next power of two (returns x if already a power of two). Returns 1 for x == 0. |
| ilog2 | Integer log2 (floor). Returns -1 for x == 0. |
| bits32 | Extract bits [hi:lo] (inclusive) from x. |
| bits64 | |
| set_bits32 | Set bits [hi:lo] to val in x, return new value. |