15 unstable releases

new 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

#20 in Hardware support

Download history 59289/week @ 2024-08-23 64926/week @ 2024-08-30 52923/week @ 2024-09-06 44373/week @ 2024-09-13 48122/week @ 2024-09-20 44012/week @ 2024-09-27 41999/week @ 2024-10-04 42967/week @ 2024-10-11 43153/week @ 2024-10-18 51225/week @ 2024-10-25 39655/week @ 2024-11-01 37709/week @ 2024-11-08 48630/week @ 2024-11-15 34622/week @ 2024-11-22 31039/week @ 2024-11-29 27093/week @ 2024-12-06

147,440 downloads per month
Used in 362 crates (17 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

~240–680KB
~16K SLoC