Crates.io | multiversion |
lib.rs | multiversion |
version | 0.7.4 |
source | src |
created_at | 2019-09-10 04:52:28.242338 |
updated_at | 2024-03-15 04:51:06.023256 |
description | Easy function multiversioning |
homepage | |
repository | https://github.com/calebzulawski/multiversion |
max_upload_size | |
id | 163709 |
size | 37,058 |
Function multiversioning attribute macros for Rust.
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.
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;
}
}
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.