Skip to content

std::math::bits

Status: experimental

Integer bit-manipulation operations (Go's math/bits shape).

API details and source

The implementation source contains the complete declarations and implementation notes. The table below lists canonical Gossamer call signatures; every item name links directly to its implementation file.

Item Canonical signature or declaration Description
add fn add(x: u64, y: u64, carry: u64) -> (u64, u64) x + y + carry; returns (sum, carry_out).
count_ones fn count_ones(x: u64) -> i64 Number of set bits (popcount).
count_zeros fn count_zeros(x: u64) -> i64 Number of clear bits.
div fn div(hi: u64, lo: u64, y: u64) -> (u64, u64) 128-bit dividend / 64-bit divisor; returns (quotient, remainder).
leading_zeros fn leading_zeros(x: u64) -> i64 Leading zero bit count.
len fn len(x: u64) -> i64 Minimum bits required to represent x.
mul fn mul(x: u64, y: u64) -> (u64, u64) Full 128-bit product; returns (hi, lo).
reverse_bits fn reverse_bits(x: u64) -> i64 Reverses bit order of x.
reverse_bytes fn reverse_bytes(x: u64) -> i64 Reverses byte order of x.
rotate_left fn rotate_left(x: u64, n: i64) -> u64 Rotates x left by n bits.
rotate_right fn rotate_right(x: u64, n: i64) -> u64 Rotates x right by n bits.
sub fn sub(x: u64, y: u64, borrow: u64) -> (u64, u64) x - y - borrow; returns (diff, borrow_out).
trailing_zeros fn trailing_zeros(x: u64) -> i64 Trailing zero bit count.