[][src]Attribute Macro generic_simd::dispatch

#[dispatch]

Multiversions a function over all supported instruction sets.

Tagging a function with #[dispatch(token)] creates a version of the function for each supported instruction set and provides its token as token. The best supported function variant is selected at runtime.

Implementation

This attribute is a wrapper for multiversion and supports all of its conditional compilation and static dispatch features.

Example

use generic_simd::slice::SliceExt;

#[generic_simd::dispatch(token)]
pub fn add_one(x: &mut [f32]) {
    let (start, vecs, end) = x.align_native_mut(token);
    for s in start.iter_mut().chain(end.iter_mut()) {
        *s += 1.;
    }

    for v in vecs {
        *v += 1.;
    }
}

#[generic_simd::dispatch(_token)]
pub fn add_two(x: &mut [f32]) {
    // Static dispatching provided by `multiversion`.
    // This does not perform runtime feature selection and allows inlining.
    dispatch!(add_one(x));
    dispatch!(add_one(x));
}