macro

is_x86_feature_detected! — Detect CPU support

On x86 and x86_64, query a named CPU feature, normally at runtime; a feature already enabled for compilation can yield true directly. Test each feature separately with a supported literal. Gate architecture-specific code with cfg and provide a fallback. Detection alone does not satisfy every precondition of unsafe intrinsics. Result: bool. Expected output (not executed): 'AVX2: true\n' or 'AVX2: false\n' or 'Use portable path\n' Common mistake: Assuming every processor supports AVX2, or substituting a dynamic string for the feature literal.

Formal Syntax & Structure

rust syntaxrust
std::is_x86_feature_detected!("avx2")

Working Example

Example Snippetrust
fn main() {    #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]    println!("AVX2: {}", std::is_x86_feature_detected!("avx2"));    #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]    println!("Use portable path");}
Rust Reference