[−][src]Attribute Macro multiversion::target_clones
#[target_clones]
Provides automatic function multiversioning by compiling clones of the function for each target.
The proper function clone is invoked depending on runtime CPU feature detection. Priority is evaluated left-to-right, selecting the first matching target. If no matching target is found, a clone with no required features is called.
This attribute is useful when relying on the compiler to make optimizations, such as automatic
vectorization. If you would like to dispatch hand-written optimized code, try the
multiversion
attribute instead.
Example
The function square
runs with AVX or SSE compiler optimizations when detected on the CPU at
runtime.
use multiversion::target_clones; #[target_clones("[x86|x86_64]+avx", "x86+sse")] fn square(x: &mut [f32]) { for v in x { *v *= *v; } }
Static dispatching
The target_clones
attribute provides a function that can be statically dispatched.
Additionally, functions called inside the function may be statically dispatched. See
static dispatching for more information.