Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calebzulawski/multiversion
Easy function multiversioning for Rust
https://github.com/calebzulawski/multiversion
cpu-features function-multiversioning macro multiversion rust simd
Last synced: 4 days ago
JSON representation
Easy function multiversioning for Rust
- Host: GitHub
- URL: https://github.com/calebzulawski/multiversion
- Owner: calebzulawski
- License: apache-2.0
- Created: 2019-09-06T05:38:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-18T19:23:29.000Z (6 months ago)
- Last Synced: 2024-10-28T13:57:16.885Z (16 days ago)
- Topics: cpu-features, function-multiversioning, macro, multiversion, rust, simd
- Language: Rust
- Homepage:
- Size: 321 KB
- Stars: 202
- Watchers: 5
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
Multiversion
============
[![Crates.io](https://img.shields.io/crates/v/multiversion)](https://crates.io/crates/multiversion)
[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/multiversion)
![Rustc Version 1.61+](https://img.shields.io/badge/rustc-1.61+-lightgray.svg)
[![License](https://img.shields.io/crates/l/multiversion)](https://crates.io/crates/multiversion)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:
```rust
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](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) for details.