Expand description
Bit-manipulation operations beyond PrimInt: unbounded and funnel
shifts, exact (lossless) shifts, bit isolation/indexing, bit width and
PDEP/PEXT-style bit deposit/extract, mirroring the corresponding inherent
methods on the primitive integer types.
Stability in std (as of nightly 2026): unbounded_shl/unbounded_shr
are stable since 1.87; highest_one/lowest_one/isolate_highest_one/
isolate_lowest_one/bit_width since 1.98; funnel shifts, exact shifts
and deposit_bits/extract_bits are still nightly-only. Everything
newer than the crate’s MSRV is hand-rolled with the same semantics.
CT tiers: IsolateHighestOne/IsolateLowestOne, BitWidth and
the funnel/unbounded shifts (under the public-parameter convention for shift
amounts) are Tier A. DepositBits/ExtractBits are branchless on the
operand but this portable fallback’s loop count is popcount(mask), so
they are Tier A only when the mask is public (it is the analogue of a
shift amount); for a secret mask they are Tier C. HighestOne/LowestOne
and ShlExact/ShrExact are Tier B (Option returns).
Traits§
- BitWidth
- Computes the minimal number of bits required to represent an unsigned value.
- Deposit
Bits - Scatters bits through a mask (the PDEP operation).
- Extract
Bits - Gathers bits through a mask (the PEXT operation).
- Funnel
Shl - Performs a funnel left shift on a double-width value formed from two words.
- Funnel
Shr - Performs a funnel right shift on a double-width value formed from two words.
- Highest
One - Finds the index of the highest one-bit.
- Isolate
Highest One - Isolates the highest one-bit, branchlessly.
- Isolate
Lowest One - Isolates the lowest one-bit, branchlessly.
- Lowest
One - Finds the index of the lowest one-bit.
- ShlExact
- Performs a lossless (exactly reversible) left shift.
- ShrExact
- Performs a lossless (exactly reversible) right shift.
- Unbounded
Shl - Performs a left shift that never panics, returning 0 for large shifts.
- Unbounded
Shr - Performs a right shift that never panics, shifting in zero or sign bits for large shift amounts.