Multiversion

Build Status Build Status Rustc Version 1.31+ License Crates.io Rust Documentation

Function multiversioning macro/attribute for Rust.

Usage

Add the following to your dependencies in Cargo.toml: toml [dependencies] multiversion = "0.1"

Example

Automatic function multiversioning with the target_clones attribute, similar to GCC's target_clones attribute: ```rust use multiversion::target_clones;

[targetclones("[x86|x8664]+avx", "x86+sse")]

fn square(x: &mut [f32]) { for v in x { *v *= *v; } } ```

Manual function multiversioning with the multiversion! macro: ```rust use multiversion::multiversion;

multiversion!{ fn square(x: &mut [f32]) "[x86|x8664]+avx" => squareavx, "x86+sse" => squaresse, default => squaregeneric, }

[cfg(any(targetarch = "x86", targetarch = "x86_64"))]

[target_feature(enable = "avx")]

unsafe fn square_avx(x: &mut [f32]) { for v in x { *v *= *v; } }

[cfg(target_arch = "x86")]

[target_feature(enable = "sse")]

unsafe fn square_sse(x: &mut [f32]) { for v in x { *v *= *v; } }

fn square_generic(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.