Crate simdeez[][src]

SIMDeez abstracts over the various sets of SIMD instructions such that you can write a single function, and use it to produce SSE2, SSE41, AVX2, or scalar versions of that function. This can be combined with cfg attributes to produce the optimum function at compile time, or with target_feature attributes for use with runtime selection, either automatically or letting users decide


Support for more instructions sets such as AVX-512, and NEON can be added as Rust adds support for those intrinsics.


SIMDeez functions follow the naming conventions of the intel intrinsics unless otherwise noted. See the Intel Intrinsics Guide for documentation.


SIMDeez is currently in an Alpha state, not all intrinsics are covered. I will be slowly adding more as time and need permits. PRs are welcome, and I would consider putting more time into the project with corporate sponsorship.

Examples

use simdeez::*;
use simdeez::avx2::*;
use simdeez::sse2::*;
use simdeez::sse41::*;
use simdeez::scalar::*;
// If using runtime feature detection, you will want to be sure this inlines
#[inline(always)]
unsafe fn sample<S: Simd>() -> f32 {
    // function names mirror the intel intrinsics, minus the _mm_ part, call them as usual 
    let a = S::set1_ps(1.5);
    let b = S::set1_ps(2.5);
    let mut c = S::add_ps(a,b);
    // Or you can use overloaded operators when applicable:
    let overloads = a*b+b-c/a;
    // If your SIMD instruction set doesn't have floor, round, gather etc,  SIMDeez handles it for you
    c = S::floor_ps(c);
    // You can get the width (as a const!)  of the instruction set you are working with
    let width = S::WIDTH_BYTES;    
    // And set or get individual lanes with ease using the index operator.
    let first = c[0];
    let last = c[(width/4)-1];
    first+last
}
 
// Make an sse2 version of sample
#[target_feature(enable = "sse2")]
unsafe fn sample_sse2() -> f32 {
    sample::<Sse2>()
}
// Make an avx2 version of sample
#[target_feature(enable = "avx2")]
unsafe fn sample_avx2() -> f32 {
    sample::<Avx2>()
}
// An SSE4.1 version
#[target_feature(enable = "sse4.1")]
unsafe fn sample_sse41() -> f32 {
    sample::<Sse41>()
}
// Or even scalar (perf may suffer here)
unsafe fn sample_scalar() -> f32 {
    sample::<Scalar>()
}

Modules

avx2
overloads
scalar
sse2
sse41

Traits

Simd