Thanks to visit codestin.com
Credit goes to docs.rs

Crate multiversed

Crate multiversed 

Source
Expand description

Attribute macros wrapping multiversion with predefined SIMD target presets.

This crate provides the #[multiversed] attribute that wraps #[multiversion::multiversion] with carefully curated target sets for each architecture.

§Usage

use multiversed::multiversed;

// Use targets from enabled cargo features (default: x86-64-v3, x86-64-v4-modern, arm64)
#[multiversed]
pub fn dot_product(a: &[f32], b: &[f32]) -> f32 {
    a.iter().zip(b).map(|(x, y)| x * y).sum()
}

// Explicit presets
#[multiversed("x86-64-v4", "arm64")]
pub fn optimized_sum(data: &[f32]) -> f32 {
    data.iter().sum()
}

// Mix presets with custom raw target strings
#[multiversed("x86-64-v3", "aarch64+neon+dotprod")]
pub fn custom_targets(data: &[f32]) -> f32 {
    data.iter().sum()
}

§Cargo Features (Presets)

Each feature is a complete, non-cumulative preset based on the x86-64 psABI microarchitecture levels and ARM architecture versions.

§x86/x86_64

FeatureKey FeaturesHardware
x86-64-v2SSE4.2, POPCNTNehalem 2008+, Bulldozer 2011+
x86-64-v3AVX2, FMA, BMI1/2Haswell 2013+, Zen 1 2017+
x86-64-v4AVX-512 (F/BW/DQ/VL/CD)Skylake-X 2017+, Zen 4 2022+
x86-64-v4-modern+ VNNI, VBMI2, BF16, GFNI, VAESIce Lake 2019+, Zen 4 2022+

Note: Intel consumer CPUs (Alder Lake 12th gen through Arrow Lake) do NOT have AVX-512 due to E-core limitations. Only Xeon server, i9-X workstation, and AMD Zen 4+ have AVX-512.

§aarch64 (above baseline - NEON is always present)

FeatureKey FeaturesHardware
arm64NEON, FP16Cortex-A75+, Apple M1+, Neoverse N1+, Snapdragon X

Note: Only the minimal NEON+FP16 baseline is provided. Use raw target strings for additional features like dotprod, sha3, or SVE.

§Attribute Arguments

The #[multiversed] attribute accepts:

  • No arguments: Uses targets from enabled cargo features
  • Preset names: "x86-64-v3", "arm64", etc.
  • Raw target strings: Any string containing + is passed through as-is

Multiple arguments are comma-separated and all are included in the target list.

Attribute Macros§

multiversed
Apply multiversion with SIMD target presets.