Skip to main content

SimdToken

Trait SimdToken 

Source
pub trait SimdToken:
    Sealed
    + Copy
    + Clone
    + Send
    + Sync
    + 'static {
    const NAME: &'static str;
    const TARGET_FEATURES: &'static str;
    const ENABLE_TARGET_FEATURES: &'static str;
    const DISABLE_TARGET_FEATURES: &'static str;

    // Required methods
    fn compiled_with() -> Option<bool>;
    fn summon() -> Option<Self>;
    unsafe fn forge_token_dangerously() -> Self;

    // Provided methods
    fn guaranteed() -> Option<bool> { ... }
    fn attempt() -> Option<Self> { ... }
}
Expand description

Marker trait for SIMD capability tokens.

All tokens implement this trait, enabling generic code over different SIMD feature levels.

This trait is sealed — it cannot be implemented outside of archmage. Only tokens created by summon() or downcasting are valid.

§Token Lifecycle

  1. Optionally check compiled_with() to see if runtime check is needed
  2. Call summon() at runtime to detect CPU support
  3. Pass the token through to #[arcane] functions — don’t forge new ones

§Example

use archmage::{X64V3Token, SimdToken};

fn process(data: &[f32]) -> f32 {
    if let Some(token) = X64V3Token::summon() {
        return process_avx2(token, data);
    }
    process_scalar(data)
}

Required Associated Constants§

Source

const NAME: &'static str

Human-readable name for diagnostics and error messages.

Source

const TARGET_FEATURES: &'static str

Comma-delimited target features (e.g., "sse,sse2,avx2,fma,bmi1,bmi2,f16c,lzcnt").

All features are listed, including baseline features like SSE/SSE2 for x86 tokens. For WASM, this is "simd128".

Empty for ScalarToken.

Source

const ENABLE_TARGET_FEATURES: &'static str

RUSTFLAGS to enable these features at compile time.

Example: "-Ctarget-feature=+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt"

Empty for ScalarToken.

Source

const DISABLE_TARGET_FEATURES: &'static str

RUSTFLAGS to disable these features at compile time.

Example: "-Ctarget-feature=-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt"

Useful in CompileTimeGuaranteedError messages to tell users how to recompile so that runtime disable works.

Empty for ScalarToken.

Required Methods§

Source

fn compiled_with() -> Option<bool>

Check if this binary was compiled with the required target features enabled.

Returns:

  • Some(true) — Features are compile-time enabled (e.g., -C target-cpu=haswell)
  • Some(false) — Wrong architecture, token can never be available
  • None — Might be available, call summon() to check at runtime

When compiled_with() returns Some(true), summon().unwrap() is safe and the compiler will elide the runtime check entirely.

§Example
match X64V3Token::compiled_with() {
    Some(true) => { /* summon().unwrap() is safe, no runtime check */ }
    Some(false) => { /* use fallback, this arch can't support it */ }
    None => { /* call summon() to check at runtime */ }
}
Source

fn summon() -> Option<Self>

Attempt to create a token with runtime feature detection.

Returns Some(token) if the CPU supports this feature, None otherwise.

§Example
if let Some(token) = X64V3Token::summon() {
    // Use AVX2+FMA operations
} else {
    // Fallback path
}
Source

unsafe fn forge_token_dangerously() -> Self

👎Deprecated since 0.5.0: Pass tokens through from summon() instead of forging

Create a token without any checks.

§Safety

Caller must guarantee the CPU feature is available. Using a forged token when the feature is unavailable causes undefined behavior.

§Deprecated

Do not use in new code. Pass tokens through from summon() instead. If you’re inside a #[cfg(target_feature = "...")] block where the feature is compile-time guaranteed, use summon().unwrap().

Provided Methods§

Source

fn guaranteed() -> Option<bool>

👎Deprecated since 0.6.0: Use compiled_with() instead

Deprecated alias for compiled_with().

Source

fn attempt() -> Option<Self>

Attempt to create a token with runtime feature detection.

This is an alias for summon().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl SimdToken for Arm64V2Token

Available on non-AArch64 only.
Source§

const NAME: &'static str = "Arm64-v2"

Source§

const TARGET_FEATURES: &'static str = "neon,crc,rdm,dotprod,fp16,aes,sha2"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+neon,+crc,+rdm,+dotprod,+fp16,+aes,+sha2"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-neon,-crc,-rdm,-dotprod,-fp16,-aes,-sha2"

Source§

impl SimdToken for Arm64V3Token

Available on non-AArch64 only.
Source§

const NAME: &'static str = "Arm64-v3"

Source§

const TARGET_FEATURES: &'static str = "neon,crc,rdm,dotprod,fp16,aes,sha2,fhm,fcma,sha3,i8mm,bf16"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+neon,+crc,+rdm,+dotprod,+fp16,+aes,+sha2,+fhm,+fcma,+sha3,+i8mm,+bf16"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-neon,-crc,-rdm,-dotprod,-fp16,-aes,-sha2,-fhm,-fcma,-sha3,-i8mm,-bf16"

Source§

impl SimdToken for Avx512Fp16Token

Available on x86-64 or x86 only.
Source§

const NAME: &'static str = "AVX-512FP16"

Source§

const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,avx512f,avx512bw,avx512cd,avx512dq,avx512vl,avx512fp16"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+avx512f,+avx512bw,+avx512cd,+avx512dq,+avx512vl,+avx512fp16"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl,-avx512fp16"

Source§

impl SimdToken for NeonAesToken

Available on non-AArch64 only.
Source§

const NAME: &'static str = "NEON+AES"

Source§

const TARGET_FEATURES: &'static str = "neon,aes"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+neon,+aes"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-neon,-aes"

Source§

impl SimdToken for NeonCrcToken

Available on non-AArch64 only.
Source§

const NAME: &'static str = "NEON+CRC"

Source§

const TARGET_FEATURES: &'static str = "neon,crc"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+neon,+crc"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-neon,-crc"

Source§

impl SimdToken for NeonSha3Token

Available on non-AArch64 only.
Source§

const NAME: &'static str = "NEON+SHA3"

Source§

const TARGET_FEATURES: &'static str = "neon,sha3"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+neon,+sha3"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-neon,-sha3"

Source§

impl SimdToken for NeonToken

Available on non-AArch64 only.
Source§

const NAME: &'static str = "NEON"

Source§

const TARGET_FEATURES: &'static str = "neon"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+neon"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-neon"

Source§

impl SimdToken for ScalarToken

Source§

const NAME: &'static str = "Scalar"

Source§

const TARGET_FEATURES: &'static str = ""

Source§

const ENABLE_TARGET_FEATURES: &'static str = ""

Source§

const DISABLE_TARGET_FEATURES: &'static str = ""

Source§

impl SimdToken for Wasm128Token

Available on non-WebAssembly only.
Source§

const NAME: &'static str = "WASM SIMD128"

Source§

const TARGET_FEATURES: &'static str = "simd128"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+simd128"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-simd128"

Source§

impl SimdToken for X64CryptoToken

Available on x86-64 or x86 only.
Source§

const NAME: &'static str = "x86-64 Crypto"

Source§

const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,pclmulqdq,aes"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+pclmulqdq,+aes"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-pclmulqdq,-aes"

Source§

impl SimdToken for X64V1Token

Available on x86-64 or x86 only.
Source§

const NAME: &'static str = "x86-64-v1"

Source§

const TARGET_FEATURES: &'static str = "sse,sse2"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2"

Source§

impl SimdToken for X64V2Token

Available on x86-64 or x86 only.
Source§

const NAME: &'static str = "x86-64-v2"

Source§

const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt"

Source§

impl SimdToken for X64V3Token

Available on x86-64 or x86 only.
Source§

const NAME: &'static str = "x86-64-v3"

Source§

const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt"

Source§

impl SimdToken for X64V4Token

Available on x86-64 or x86 only.
Source§

const NAME: &'static str = "AVX-512"

Source§

const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,avx512f,avx512bw,avx512cd,avx512dq,avx512vl"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+avx512f,+avx512bw,+avx512cd,+avx512dq,+avx512vl"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl"

Source§

impl SimdToken for X64V4xToken

Available on x86-64 or x86 only.
Source§

const NAME: &'static str = "x86-64-v4x"

Source§

const TARGET_FEATURES: &'static str = "sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,avx,avx2,fma,bmi1,bmi2,f16c,lzcnt,avx512f,avx512bw,avx512cd,avx512dq,avx512vl,avx512vpopcntdq,avx512ifma,avx512vbmi,avx512vbmi2,avx512bitalg,avx512vnni,vpclmulqdq,gfni,vaes"

Source§

const ENABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=+sse,+sse2,+sse3,+ssse3,+sse4.1,+sse4.2,+popcnt,+avx,+avx2,+fma,+bmi1,+bmi2,+f16c,+lzcnt,+avx512f,+avx512bw,+avx512cd,+avx512dq,+avx512vl,+avx512vpopcntdq,+avx512ifma,+avx512vbmi,+avx512vbmi2,+avx512bitalg,+avx512vnni,+vpclmulqdq,+gfni,+vaes"

Source§

const DISABLE_TARGET_FEATURES: &'static str = "-Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-popcnt,-avx,-avx2,-fma,-bmi1,-bmi2,-f16c,-lzcnt,-avx512f,-avx512bw,-avx512cd,-avx512dq,-avx512vl,-avx512vpopcntdq,-avx512ifma,-avx512vbmi,-avx512vbmi2,-avx512bitalg,-avx512vnni,-vpclmulqdq,-gfni,-vaes"