14 releases

0.7.4 Mar 15, 2024
0.7.3 Aug 10, 2023
0.7.2 May 10, 2023
0.7.1 Dec 23, 2022
0.2.0 Nov 11, 2019

#18 in Hardware support

Download history 27755/week @ 2024-01-24 26135/week @ 2024-01-31 27863/week @ 2024-02-07 29366/week @ 2024-02-14 27104/week @ 2024-02-21 23779/week @ 2024-02-28 25401/week @ 2024-03-06 25852/week @ 2024-03-13 31136/week @ 2024-03-20 28827/week @ 2024-03-27 29334/week @ 2024-04-03 31045/week @ 2024-04-10 33361/week @ 2024-04-17 30316/week @ 2024-04-24 30319/week @ 2024-05-01 24852/week @ 2024-05-08

124,710 downloads per month
Used in 253 crates (17 directly)

MIT/Apache

19KB
139 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

~1.5MB
~34K SLoC