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

#17 in Hardware support

Download history 26651/week @ 2024-03-14 31082/week @ 2024-03-21 29691/week @ 2024-03-28 28626/week @ 2024-04-04 31275/week @ 2024-04-11 33320/week @ 2024-04-18 29204/week @ 2024-04-25 31220/week @ 2024-05-02 32105/week @ 2024-05-09 28895/week @ 2024-05-16 34817/week @ 2024-05-23 34204/week @ 2024-05-30 33495/week @ 2024-06-06 36542/week @ 2024-06-13 39515/week @ 2024-06-20 36876/week @ 2024-06-27

152,675 downloads per month
Used in 270 crates (16 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
~35K SLoC