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

#20 in Hardware support

Download history 47292/week @ 2024-07-30 39057/week @ 2024-08-06 47738/week @ 2024-08-13 56383/week @ 2024-08-20 62524/week @ 2024-08-27 61077/week @ 2024-09-03 49457/week @ 2024-09-10 40453/week @ 2024-09-17 47966/week @ 2024-09-24 44061/week @ 2024-10-01 41730/week @ 2024-10-08 45256/week @ 2024-10-15 43923/week @ 2024-10-22 44959/week @ 2024-10-29 40431/week @ 2024-11-05 36161/week @ 2024-11-12

174,267 downloads per month
Used in 358 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
~38K SLoC