15 unstable releases

0.8.0 Dec 8, 2024
0.7.4 Mar 15, 2024
0.7.3 Aug 10, 2023
0.7.2 May 10, 2023
0.2.0 Nov 11, 2019

#25 in Hardware support

Download history 27964/week @ 2025-02-04 121204/week @ 2025-02-11 134530/week @ 2025-02-18 147157/week @ 2025-02-25 147720/week @ 2025-03-04 137993/week @ 2025-03-11 124068/week @ 2025-03-18 123058/week @ 2025-03-25 99844/week @ 2025-04-01 96395/week @ 2025-04-08 83544/week @ 2025-04-15 82332/week @ 2025-04-22 90988/week @ 2025-04-29 78176/week @ 2025-05-06 76920/week @ 2025-05-13 58637/week @ 2025-05-20

316,747 downloads per month
Used in 333 crates (18 directly)

MIT/Apache

19KB
134 lines

Multiversion

Crates.io Rust Documentation Rustc Version 1.61+ License

Function multiversioning attribute macros for Rust.

What is function multiversioning?

Many CPU architectures have a variety of instruction set extensions that provide additional functionality. Common examples are single instruction, multiple data (SIMD) extensions such as SSE and AVX on x86/x86-64 and NEON on ARM/AArch64. When available, these extended features can provide significant speed improvements to some functions. These optional features cannot be haphazardly compiled into programs--executing an unsupported instruction will result in a crash.

Function multiversioning is the practice of compiling multiple versions of a function with various features enabled and safely detecting which version to use at runtime.

Example

The multiversion macro compiles a function for multiple possible targets, and selects the optimal one at runtime:

use multiversion::multiversion;

#[multiversion(targets("x86_64+avx", "aarch64+neon"))]
fn square(x: &mut [f32]) {
    for v in x {
        *v *= *v;
    }
}

License

Multiversion is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies

~220–650KB
~15K SLoC