easy simd
A library that abstracts over SIMD instruction sets, including ones with differing widths. SIMDeez is designed to allow you to write a function one time and produce SSE2, SSE41, AVX2, AVX-512, Neon and WebAssembly SIMD versions of the function. You can either have the version you want chosen at compile time or automatically at runtime.
Originally developed by @jackmott. Active maintenance and releases now happen from this repository.
If there are intrinsics you need that are not currently implemented, create an issue and I'll add them. PRs to add more intrinsics are welcome. Currently things are well fleshed out for i32, i64, f32, and f64 types.
AVX-512 support is now included for x86/x86_64 targets with avx512f, avx512bw, and avx512dq. Runtime dispatch will select it ahead of AVX2 when those features are available.
Refer to the excellent Intel Intrinsics Guide for documentation on these functions:
_mm_add_ps(a,b) becomes add_ps(a,b)#[no_std] projectslet sum = va + vb or s *= slet v1 = v[1];SIMDeez includes a native, pure-Rust SIMD math surface exposed through simdeez::math and re-exported in simdeez::prelude.
Covered families include:
log2_u35, exp2_u35, ln_u35, exp_u35sin_u35, cos_u35, tan_u35, asin_u35, acos_u35, atan_u35, atan2_u35sinh_u35, cosh_u35, tanh_u35, asinh_u35, acosh_u35, atanh_u35log10_u35, hypot_u35, fmodFor implementation notes and benchmark guidance, see SIMD_MATH.md.
Example:
use simdeez::prelude::*;
fn apply_math(x: S::Vf32) -> S::Vf32 {
let y = x.log2_u35();
y.exp2_u35() + x.ln_u35() + x.exp_u35() + x.sin_u35() + x.cos_u35() + x.tan_u35()
}All of the above could change! Faster seems to generally have the same performance as long as you don't run into some of the slower fallback functions.
…This will generate the following functions for you:
distance the generic version of your functiondistance_scalar a scalar fallbackdistance_sse2 SSE2 versiondistance_sse41 SSE41 versiondistance_avx2 AVX2 versiondistance_avx512 AVX-512 versiondistance_neon Neon versiondistance_wasm WebAssembly SIMD versiondistance_runtime_select // picks the fastest of the above at runtimeYou can use any of these you wish, though typically you would use the runtime_select version
unless you want to force an older instruction set to avoid throttling or for other arcane
reasons.
Optionally you can use the simd_compiletime_generate! macro in the same way. This will
produce 2 active functions via the cfg attribute feature:
distance the generic version of your functiondistance_compiletime the fastest instruction set availble for the given compile time
feature setYou may also forgo the macros if you know what you are doing, just keep in mind there are lots of arcane subtleties with inlining and target_features that must be managed. See how the macros expand for more detail.
No open issues yet, or sync has not completed.