Skip to main content

Crate bit_arch

Crate bit_arch 

Source
Expand description

Fast and efficient architecture-tuned bit operations.

By default, bit_arch uses a static target_feature approach. You can enable the dynamic feature but it might be a little bit slower. It is highly recommended that you compile your binary with the exact feature flags your target supports. Otherwise, you will be paying for a runtime feature check every time you use a function.

bit_arch also supports complete no_std (and no_alloc) environments. It doesn’t need an operating system to run (unless you use the dynamic feature).

All operations have x86_64-optimized paths and generic fallback paths. More architectures and features may be added in the future. Currently supports BMI 1/2, TBM, and ABM on x86_64.

Modules§

arch
Low-level u32 and u64 operations.

Functions§

clear_lowest_set
Extracts and clears the lowest set bit from x. Replaces x & (x - 1).
complement_lowest_set
Clears the least significant set bit and sets the rest. Replaces !x | x.wrapping_sub(1).
count_ones
Counts all one bits of x.
deposit
Scatters (deposits) lower bits of x into all set bits of mask.
extract
Extracts bits of x masked by mask into lower contiguous bits of output.
extract_bitfield
Extracts a bitfield at index start of size len of `x``.
from_lowest_set
Sets all bits below the least significant one. Replaces x | x.wrapping_sub(1).
inverted_and
Performs a bitwise logical !a & b.
isolate_lowest_clear
Extracts and isolates the lowest clear bit from x``. Replaces x | !x.wrapping_add(1)`.
leading_zeros
Counts leading zero bits of x.
set_lowest_clear
Sets the least significant zero bit and clears the rest. Replaces !x & x.wrapping_add(1).
set_lowest_zero
Sets the least significant zero bit from x. Replaces x | x.wrapping_add(1).
through_lowest_set
Mask up to the lowest set bit from x. Replaces x ^ (x - 1).
trailing_one_mask
Inverse mask from trailing ones of x. Replaces !x | x.wrapping_add(1).
trailing_zero_mask
Mask from trailing zeros of x. Replaces !x & x.wrapping_sub(1).
trailing_zeros
Counts trailing zero bits of x.
zero_upper
Zeros all bits of x above the specified index.