pub struct Simd<T, const N: usize>(pub [T; N]);Expand description
A fixed-length vector of N lanes of element type T.
All operations are lane-wise and implemented as plain loops over the
underlying [T; N], so the compiler can auto-vectorize them for any
element type and lane count. The lane count N is arbitrary (powers of two
that fill whole SIMD registers are the sweet spot, but not required).
The type carries no enforced alignment beyond the element’s natural
alignment; for enforced alignment use the aligned sibling types, which
share this type’s full operation surface. The field is public for
zero-friction interoperability with array code.
Tuple Fields§
§0: [T; N]Implementations§
Source§impl<T: Copy, const N: usize> Simd<T, N>
impl<T: Copy, const N: usize> Simd<T, N>
Sourcepub fn from_slice(src: &[T]) -> Self
pub fn from_slice(src: &[T]) -> Self
Sourcepub fn store_slice(&self, dst: &mut [T])
pub fn store_slice(&self, dst: &mut [T])
Sourcepub fn store_slice_partial(&self, dst: &mut [T])
pub fn store_slice_partial(&self, dst: &mut [T])
Stores at most the first min(dst.len(), N) lanes to dst.
Source§impl<T: Zero + Copy, const N: usize> Simd<T, N>
impl<T: Zero + Copy, const N: usize> Simd<T, N>
Sourcepub fn from_slice_pad(src: &[T]) -> Self
pub fn from_slice_pad(src: &[T]) -> Self
Loads a vector from src, zero-filling lanes past src.len().
Source§impl<T, const N: usize> Simd<T, N>
impl<T, const N: usize> Simd<T, N>
Sourcepub fn mul_add(self, b: Self, c: Self) -> Self
pub fn mul_add(self, b: Self, c: Self) -> Self
Lane-wise multiply-add: self * b + c, evaluated as a separate
multiply and add (two roundings per lane).
This is the fallback on targets without hardware FMA (generic
x86-64, x86-64-v2), where it avoids the slow software-fused
libm fma calls; it also fuses into a single hardware FMA
instruction when compiled with -C llvm-args=-fp-contract=fast.
Enable the use_libm_fma feature to get the single-rounding
fused form on such targets instead.
Source§impl<T, const N: usize> Simd<T, N>
impl<T, const N: usize> Simd<T, N>
Sourcepub fn abs(self) -> Self
pub fn abs(self) -> Self
Lane-wise Float::abs.
Sourcepub fn sqrt(self) -> Self
pub fn sqrt(self) -> Self
Lane-wise Float::sqrt.
Sourcepub fn recip(self) -> Self
pub fn recip(self) -> Self
Lane-wise Float::recip.
Sourcepub fn floor(self) -> Self
pub fn floor(self) -> Self
Lane-wise Float::floor.
Sourcepub fn ceil(self) -> Self
pub fn ceil(self) -> Self
Lane-wise Float::ceil.
Sourcepub fn round(self) -> Self
pub fn round(self) -> Self
Lane-wise Float::round.
Sourcepub fn trunc(self) -> Self
pub fn trunc(self) -> Self
Lane-wise Float::trunc.
Sourcepub fn fract(self) -> Self
pub fn fract(self) -> Self
Lane-wise Float::fract.
Sourcepub fn min(self, other: Self) -> Self
pub fn min(self, other: Self) -> Self
Lane-wise minimum; NaN handling follows the element’s scalar
Float::min.
Sourcepub fn max(self, other: Self) -> Self
pub fn max(self, other: Self) -> Self
Lane-wise maximum; NaN handling follows the element’s scalar
Float::max.
Sourcepub fn copysign(self, sign: Self) -> Self
pub fn copysign(self, sign: Self) -> Self
Lane-wise Float::copysign.
Source§impl<const N: usize> Simd<f32, N>
impl<const N: usize> Simd<f32, N>
Sourcepub fn round_ties_even(self) -> Self
pub fn round_ties_even(self) -> Self
Lane-wise f32::round_ties_even.
Not available generically through num_traits::Float, so this is
implemented only for the builtin float types.
Source§impl<const N: usize> Simd<f64, N>
impl<const N: usize> Simd<f64, N>
Sourcepub fn round_ties_even(self) -> Self
pub fn round_ties_even(self) -> Self
Lane-wise f64::round_ties_even.
Not available generically through num_traits::Float, so this is
implemented only for the builtin float types.
Source§impl<const N: usize> Simd<bool, N>
impl<const N: usize> Simd<bool, N>
Source§impl<T, const N: usize> Simd<T, N>
impl<T, const N: usize> Simd<T, N>
Sourcepub fn reduce_sum(self) -> T
pub fn reduce_sum(self) -> T
Sums all lanes, accumulating in lane order.
Sourcepub fn reduce_sum_n(self, n: usize) -> T
pub fn reduce_sum_n(self, n: usize) -> T
Source§impl<T, const N: usize> Simd<T, N>
impl<T, const N: usize> Simd<T, N>
Sourcepub fn reduce_product(self) -> T
pub fn reduce_product(self) -> T
Multiplies all lanes, accumulating in lane order.
Sourcepub fn reduce_product_n(self, n: usize) -> T
pub fn reduce_product_n(self, n: usize) -> T
Source§impl<T, const N: usize> Simd<T, N>
impl<T, const N: usize> Simd<T, N>
Sourcepub fn map<F>(self, f: F) -> Selfwhere
F: FnMut(T) -> T,
pub fn map<F>(self, f: F) -> Selfwhere
F: FnMut(T) -> T,
Applies f to each lane, returning a new vector.
This is the generic escape hatch for operations the crate does not
provide (e.g. transcendental functions: v.map(f64::exp)).
Sourcepub fn as_array_mut(&mut self) -> &mut [T; N]
pub fn as_array_mut(&mut self) -> &mut [T; N]
Returns the underlying array by mutable reference.
Source§impl<T: Copy, const N: usize> Simd<T, N>
impl<T: Copy, const N: usize> Simd<T, N>
Sourcepub fn mask_select(self, mask: Simd<bool, N>, other: Self) -> Self
pub fn mask_select(self, mask: Simd<bool, N>, other: Self) -> Self
Per-lane select: keeps lanes of self where mask is true and
lanes of other where it is false. This value-side form is
available on every vector type; the mask-side
select applies to plain vectors.
Sourcepub unsafe fn uninit() -> Self
pub unsafe fn uninit() -> Self
Returns an uninitialized vector, intended for scratch buffers whose lanes are fully written before being read.
§Safety
The caller must initialize all lanes before any read. The element type must additionally admit arbitrary bit patterns (true for floats and integers; not for types with niches such as references).
Trait Implementations§
Source§impl<T, const N: usize> AddAssign for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> AddAssign for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<T, const N: usize> AddAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> AddAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreSource§impl<T, const N: usize> BitAndAssign for Simd<T, N>where
T: BitAndAssign + Copy,
impl<T, const N: usize> BitAndAssign for Simd<T, N>where
T: BitAndAssign + Copy,
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&= operation. Read moreSource§impl<T, const N: usize> BitOrAssign for Simd<T, N>where
T: BitOrAssign + Copy,
impl<T, const N: usize> BitOrAssign for Simd<T, N>where
T: BitOrAssign + Copy,
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|= operation. Read moreSource§impl<T, const N: usize> BitXorAssign for Simd<T, N>where
T: BitXorAssign + Copy,
impl<T, const N: usize> BitXorAssign for Simd<T, N>where
T: BitXorAssign + Copy,
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^= operation. Read moreimpl<T: Copy, const N: usize> Copy for Simd<T, N>
Source§impl<T, const N: usize> DivAssign for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> DivAssign for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl<T, const N: usize> DivAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> DivAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreimpl<T: Eq, const N: usize> Eq for Simd<T, N>
Source§impl<T, const N: usize> MulAssign for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> MulAssign for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl<T, const N: usize> MulAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> MulAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreimpl<T: PartialEq, const N: usize> StructuralPartialEq for Simd<T, N>
Source§impl<T, const N: usize> SubAssign for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> SubAssign for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl<T, const N: usize> SubAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
impl<T, const N: usize> SubAssign<T> for Simd<T, N>where
T: NumAssignOps + Copy,
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more