13 unstable releases

0.7.3 Aug 10, 2023
0.7.2 May 10, 2023
0.7.1 Dec 23, 2022
0.6.1 Aug 18, 2020
0.2.0 Nov 11, 2019

#34 in Hardware support

Download history 21002/week @ 2023-06-08 21064/week @ 2023-06-15 20433/week @ 2023-06-22 24292/week @ 2023-06-29 25391/week @ 2023-07-06 23380/week @ 2023-07-13 24753/week @ 2023-07-20 25065/week @ 2023-07-27 22783/week @ 2023-08-03 24980/week @ 2023-08-10 25970/week @ 2023-08-17 26189/week @ 2023-08-24 24047/week @ 2023-08-31 24424/week @ 2023-09-07 22458/week @ 2023-09-14 23639/week @ 2023-09-21

99,508 downloads per month
Used in 174 crates (13 directly)

MIT/Apache

19KB
140 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
~32K SLoC