Detect fast hardware support for PDEP/PEXT.
A single-function, no-std library that returns true if the current CPU implements PDEP and PEXT with fast, non-microcoded hardware.
[]
= "0.1"
Compiler support: requires rustc 1.85+
Rationale
Zen, Zen+, Zen 2, and Hygon Dhyana CPUs implement PDEP and PEXT using microcode in a way that makes them slower than well-optimized, non-intrinsic fallbacks. In performance-critical code, checking for BMI2 support isn't enough—you could end up hurting performance on said CPUs where these instructions exist but are slow. This crate helps you avoid that by detecting speed, not just support.
Examples
Basic usage:
use has_fast_pdep;
You can view the documentation on docs.rs here.
Implementation Details
The result of the hardware check is determined once at runtime. After the initial check, all future
calls to has_fast_pdep becomes a simple true or false with zero branching or logic.
On x86 targets, CPUID is used directly without probing for its existence. This is intentional. For every tier 1 x86 Rust target, CPUID is guaranteed to be present. If you're targeting old hardware, such as an i486, this crate might not be for you. If you happen to be that individual, make an issue, and I'll reimplement the probing logic via inline assembly.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.