bitintr 0.1.5

Portable Bit Manipulation Intrinsics.
Documentation

Portable Bitwise Manipulation Intrinsics

crates.io version Travis build status Coveralls.io code coverage Docs License

0b0000_0010_1001_1010

The intrinsics are named after their CPU instruction and organized in modules named after their instruction set: bitintr::{instruction_set}::{intrinsic_name}.

They are implemented for all integer types except u128/i128. Whether a fallback software implementation is used depends on the integer types involved and the instruction sets supported by the target.

The following instruction sets are implemented:

  • ABM: Advanced Bit Manipulation instructions.
  • TBM: Trailing Bit Manipulation instructions.
  • BMI: Bit Manipulation Instruction Set 1.0.
  • BMI2: Bit Manipulation Instruction Set 2.0.

Example

extern crate bitintr;
use bitintr::bmi2::*;

fn main() {
    let x = 1;
    let y = 0;
    // Intrinsics can be used as methods:
    let method_call = x.pdep(y);
    // And as free function calls:
    let free_call = pdep(x, y);
    assert_eq!(method_call, free_call);
}

Supported compilers

The minimum required rustc version is >= 1.4.0.

When compiled with a rust stable compiler the intrinsics are implemented using the software fallback. In release builds LLVM often generates the corresponding CPU instruction.

When compiled with a rust nightly compiler the following features are used to generate the corresponding CPU instruction in all cases:

  • cfg_target_feature for target-dependent behavior,
  • platform_intrinsics for using the bitwise manipulation intrinsics, and
  • u128 support for efficient 64bit multiplication.

License

Licensed under the MIT license.

Contribution

Yes please! Just note that all contributions shall be licensed as above without any additional terms or conditions.