cpudetect 0.2.0

Ergonomic helpers for CPU feature detection
Documentation
//! CPU feature detection helpers for AArch64/ARM64 CPUs.

use pastey::paste;

macro_rules! aarch64_feature {
    ($feature:literal) => {
        aarch64_feature!($feature, $feature);
    };
    ($feature:literal, $fn_suffix:literal) => {
        paste! {
            #[doc = concat!(
                "Returns `true` if the current machine supports the ",
                $feature,
                " instruction set."
            )]
            #[must_use]
            #[inline(always)]
            pub fn [<has_ $fn_suffix>]() -> bool {
                cfg_select! {
                    not(all(feature = "enabled", target_arch = "aarch64")) => false,
                    all(feature = "static", target_feature = $feature) => true,
                    feature = "static" => false,
                    _ => std::arch::is_aarch64_feature_detected!($feature),
                }
            }
        }
    };
}

// Enable AES support.
aarch64_feature!("aes");

// Enable BFloat16 Extension.
aarch64_feature!("bf16");

// Enable Branch Target Identification.
aarch64_feature!("bti");

// Enable Armv8.0-A CRC-32 checksum instructions.
aarch64_feature!("crc");

// Enable Common Short Sequence Compression (CSSC) instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("cssc");

// Enable Armv8.4-A Data Independent Timing instructions.
aarch64_feature!("dit");

// Enable dot product support.
aarch64_feature!("dotprod");

// Enable Armv8.2-A data Cache Clean to Point of Persistence.
aarch64_feature!("dpb");

// Enable Armv8.5-A Cache Clean to Point of Deep Persistence.
aarch64_feature!("dpb2");

// Enable enhanced counter virtualization extension.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("ecv");

// Enable Matrix Multiply FP32 Extension.
aarch64_feature!("f32mm");

// Enable Matrix Multiply FP64 Extension.
aarch64_feature!("f64mm");

// Enable FAMIN and FAMAX instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("faminmax");

// Enable Armv8.3-A Floating-point complex number support.
aarch64_feature!("fcma");

// Enable FP16 FML instructions.
aarch64_feature!("fhm");

// Enable Armv8.4-A Flag Manipulation instructions.
aarch64_feature!("flagm");

// Enable alternative NZCV format for floating point comparisons.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("flagm2");

// Enable half-precision floating-point data processing.
aarch64_feature!("fp16");

// Enable FP8 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("fp8");

// Enable FP8 2-way dot instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("fp8dot2");

// Enable FP8 4-way dot instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("fp8dot4");

// Enable Armv9.5-A FP8 multiply-add instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("fp8fma");

// Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an integer (in FP format) forcing it to fit into a 32- or 64-bit int.
aarch64_feature!("frintts");

// Enable Armv8.8-A Hinted Conditional Branches Extension.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("hbc");

// Enable Matrix Multiply Int8 Extension.
aarch64_feature!("i8mm");

// Enable Armv8.3-A JavaScript FP conversion instructions.
aarch64_feature!("jsconv");

// Enable Armv8.1-A Large System Extension (LSE) atomic instructions.
aarch64_feature!("lse");

// Enable Armv9.4-A 128-bit Atomic instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("lse128");

// Enable Armv8.4-A Large System Extension 2 (LSE2) atomicity rules.
aarch64_feature!("lse2");

// Enable Lookup Table instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("lut");

// Enable Armv8.8-A memcpy and memset acceleration instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("mops");

// Enable Memory Tagging Extension.
aarch64_feature!("mte");

// Enable Advanced SIMD instructions.
aarch64_feature!("neon");

// Enable Armv8.3-A Pointer Authentication extension.
aarch64_feature!("paca");

// Enable Armv8.3-A Pointer Authentication extension.
aarch64_feature!("pacg");

// Enable Armv9.5-A PAC enhancements.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("pauth-lr", "pauth_lr");

// Enable Random Number generation instructions.
aarch64_feature!("rand");

// Enable support for RCPC extension.
aarch64_feature!("rcpc");

// Enable Armv8.4-A RCPC instructions with Immediate Offsets.
aarch64_feature!("rcpc2");

// Enable Armv8.9-A RCPC instructions for A64 and Advanced SIMD and floating-point instruction set.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("rcpc3");

// Enable Armv8.1-A Rounding Double Multiply Add/Subtract instructions.
aarch64_feature!("rdm");

// Enable Armv8.5-A Speculation Barrier.
aarch64_feature!("sb");

// Enable SHA1 and SHA256 support.
aarch64_feature!("sha2");

// Enable SHA512 and SHA3 support.
aarch64_feature!("sha3");

// Enable SM3 and SM4 support.
aarch64_feature!("sm4");

// Enable Scalable Matrix Extension (SME).
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme");

// Enable SME2.1 ZA-targeting non-widening BFloat16 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-b16b16", "sme_b16b16");

// Enable SME non-widening Float16 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-f16f16", "sme_f16f16");

// Enable Scalable Matrix Extension (SME) F64F64 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-f64f64", "sme_f64f64");

// Enable Scalable Matrix Extension (SME) F8F16 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-f8f16", "sme_f8f16");

// Enable Scalable Matrix Extension (SME) F8F32 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-f8f32", "sme_f8f32");

// Enable the full A64 instruction set in streaming SVE mode.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-fa64", "sme_fa64");

// Enable Scalable Matrix Extension (SME) I16I64 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-i16i64", "sme_i16i64");

// Enable Scalable Matrix Extension (SME) LUTv2 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme-lutv2", "sme_lutv2");

// Enable Scalable Matrix Extension 2 (SME2) instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme2");

// Enable Scalable Matrix Extension 2.1 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sme2p1");

// Enable Speculative Store Bypass Safe bit.
aarch64_feature!("ssbs");

// Enable SVE2 FP8 2-way dot product instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("ssve-fp8dot2", "ssve_fp8dot2");

// Enable SVE2 FP8 4-way dot product instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("ssve-fp8dot4", "ssve_fp8dot4");

// Enable SVE2 FP8 multiply-add instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("ssve-fp8fma", "ssve_fp8fma");

// Enable Scalable Vector Extension (SVE) instructions.
aarch64_feature!("sve");

// Enable SVE2 non-widening and SME2 Z-targeting non-widening BFloat16 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sve-b16b16", "sve_b16b16");

// Enable Scalable Vector Extension 2 (SVE2) instructions.
aarch64_feature!("sve2");

// Shorthand for +sve2+sve-aes.
aarch64_feature!("sve2-aes", "sve2_aes");

// Shorthand for +sve2+sve-bitperm.
aarch64_feature!("sve2-bitperm", "sve2_bitperm");

// Shorthand for +sve2+sve-sha3.
aarch64_feature!("sve2-sha3", "sve2_sha3");

// Shorthand for +sve2+sve-sm4.
aarch64_feature!("sve2-sm4", "sve2_sm4");

// Enable Scalable Vector Extension 2.1 instructions.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("sve2p1");

// Enable Armv8.7-A WFET and WFIT instruction.
// DISABLED: Unstable library feature as of 1.96.0
// aarch64_feature!("wfxt");