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 {
    // SIMDeez names mostly follow the intel intrinsics conventions, minus the _mm_ prefix
    // Use them as normal!
    let a = S::set1_epi32(3);
    let b = S::set1_epi32(-1);
    let c = S::add_epi32(a, b);
    let f = S::set1_ps(1.5);
    // SSE2 doesn't have floor, ceil, round, or gather  operations, don't worry, SIMDeez handles it.
    let g = S::floor_ps(f);
    // The width of the lane, in bytes, is provided as a constant
    // by each impl
    let width = S::WIDTH_BYTES / 4;
    // Set or get individual lanes with ease
    S::get_lane_epi32(c, width - 1) as f32
}
// 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
scalar
sse2
sse41

Traits

Simd