npsimd 0.3.0

An ergonomic library for architecture-specific vectorization.
Documentation
//! Generic SIMD intrinsic functions.

// SIMD intrinsics that the Rust compiler supports directly.
//
// We use these over the LLVM intrinsics whenever possible, since the Rust
// compiler frontend understands them better and can probably optimize them a
// bit.
pub use core::intrinsics::simd::*;

/// Elementwise maximum between two vectors.
pub unsafe fn simd_max<T: Copy, U>(x: T, y: T) -> T {
    simd_select(simd_gt::<T, U>(x, y), x, y)
}

/// Elementwise minimum between two vectors.
pub unsafe fn simd_min<T: Copy, U>(x: T, y: T) -> T {
    simd_select(simd_lt::<T, U>(x, y), x, y)
}

/// Indices for [`simd_shuffle`] for slicing into a vector.
pub const fn simd_slice_indices<const LEN: usize>(start: usize) -> [u32; LEN]
where [u32; LEN]: Sized {
    let mut indices = [0u32; LEN];
    let mut index = 0;
    while index < indices.len() {
        indices[index] = (start + index) as u32;
        index += 1;
    }
    indices
}