Skip to main content

SimdBase

Trait SimdBase 

Source
pub trait SimdBase<S: Simd>:
    Copy
    + Sync
    + Send
    + 'static
    + Seal
    + Bytes
    + SimdFrom<Self::Element, S>
    + Index<usize, Output = Self::Element>
    + IndexMut<usize, Output = Self::Element>
    + Deref<Target = Self::Array>
    + DerefMut<Target = Self::Array> {
    type Element: SimdElement;
    type Mask: SimdMask<S, Element = <Self::Element as SimdElement>::Mask>;
    type Block: SimdBase<S, Element = Self::Element>;
    type Array;

    const N: usize;

    // Required methods
    fn witness(&self) -> S;
    fn as_slice(&self) -> &[Self::Element];
    fn as_mut_slice(&mut self) -> &mut [Self::Element];
    fn from_slice(simd: S, slice: &[Self::Element]) -> Self;
    fn store_slice(&self, slice: &mut [Self::Element]);
    fn block_splat(block: Self::Block) -> Self;
    fn from_fn(simd: S, f: impl FnMut(usize) -> Self::Element) -> Self;
    fn splat(simd: S, val: Self::Element) -> Self;
    fn slide<const SHIFT: usize>(self, rhs: impl SimdInto<Self, S>) -> Self;
    fn slide_within_blocks<const SHIFT: usize>(
        self,
        rhs: impl SimdInto<Self, S>,
    ) -> Self;
    fn swizzle_dyn_within_blocks(
        self,
        indices: impl SimdInto<Self::Bytes, S>,
    ) -> Self;
}
Expand description

Base functionality implemented by all SIMD vectors.

Required Associated Constants§

Source

const N: usize

This vector type’s lane count. This is useful when you’re working with a native-width vector (e.g. Simd::f32s) and want to process data in native-width chunks.

Required Associated Types§

Source

type Element: SimdElement

The type of this vector’s elements.

Source

type Mask: SimdMask<S, Element = <Self::Element as SimdElement>::Mask>

A SIMD vector mask with the same number of logical lanes.

Masks intentionally do not implement SimdBase. SSE, NEON, WASM, and the fallback backend currently store masks as all-zero/all-one integer vectors, but AVX-512/RVV/SVE-style targets use compact predicate registers instead.

Source

type Block: SimdBase<S, Element = Self::Element>

A 128-bit SIMD vector of the same scalar type.

Source

type Array

The array type that this vector type corresponds to, which will always be [Self::Element; Self::N]. It has the same layout as this vector type, but likely has a lower alignment.

Required Methods§

Source

fn witness(&self) -> S

Get the Simd implementation associated with this type.

Source

fn as_slice(&self) -> &[Self::Element]

Source

fn as_mut_slice(&mut self) -> &mut [Self::Element]

Source

fn from_slice(simd: S, slice: &[Self::Element]) -> Self

Create a SIMD vector from a slice.

The slice must be exactly the size of the SIMD vector.

Source

fn store_slice(&self, slice: &mut [Self::Element])

Store a SIMD vector into a slice.

The slice must be exactly the size of the SIMD vector.

Source

fn block_splat(block: Self::Block) -> Self

Create a SIMD vector from a 128-bit vector of the same scalar type, repeated.

Source

fn from_fn(simd: S, f: impl FnMut(usize) -> Self::Element) -> Self

Create a SIMD vector where each element is produced by calling f with that element’s lane index (from 0 to SimdBase::N - 1).

Source

fn splat(simd: S, val: Self::Element) -> Self

Create a SIMD vector with all elements set to the given value.

Source

fn slide<const SHIFT: usize>(self, rhs: impl SimdInto<Self, S>) -> Self

Concatenate [self, rhs] and extract Self::N elements starting at index SHIFT.

SHIFT must be within [0, Self::N].

This can be used to implement a “shift items” operation by providing all zeroes as one operand. For a left shift, the right-hand side should be all zeroes. For a right shift by M items, the left-hand side should be all zeroes, and the shift amount will be Self::N - M.

This can also be used to rotate items within a vector by providing the same vector as both operands.


slide::<1>([a b c d], [e f g h]) == [b c d e]
Source

fn slide_within_blocks<const SHIFT: usize>( self, rhs: impl SimdInto<Self, S>, ) -> Self

Like slide, but operates independently on each 128-bit block.

Source

fn swizzle_dyn_within_blocks( self, indices: impl SimdInto<Self::Bytes, S>, ) -> Self

Dynamically swizzle this vector’s bytes independently within each 128-bit block.

The indices operand is a same-width byte vector. For each output byte, index values 0..=15 select the corresponding byte from the same 128-bit input block.

Out-of-range index behavior varies by platform.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<S: Simd> SimdBase<S> for f32x4<S>

Source§

impl<S: Simd> SimdBase<S> for f32x8<S>

Source§

impl<S: Simd> SimdBase<S> for f32x16<S>

Source§

impl<S: Simd> SimdBase<S> for f64x2<S>

Source§

impl<S: Simd> SimdBase<S> for f64x4<S>

Source§

impl<S: Simd> SimdBase<S> for f64x8<S>

Source§

impl<S: Simd> SimdBase<S> for i8x16<S>

Source§

impl<S: Simd> SimdBase<S> for i8x32<S>

Source§

impl<S: Simd> SimdBase<S> for i8x64<S>

Source§

impl<S: Simd> SimdBase<S> for i16x8<S>

Source§

impl<S: Simd> SimdBase<S> for i16x16<S>

Source§

impl<S: Simd> SimdBase<S> for i16x32<S>

Source§

impl<S: Simd> SimdBase<S> for i32x4<S>

Source§

impl<S: Simd> SimdBase<S> for i32x8<S>

Source§

impl<S: Simd> SimdBase<S> for i32x16<S>

Source§

impl<S: Simd> SimdBase<S> for u8x16<S>

Source§

impl<S: Simd> SimdBase<S> for u8x32<S>

Source§

impl<S: Simd> SimdBase<S> for u8x64<S>

Source§

impl<S: Simd> SimdBase<S> for u16x8<S>

Source§

impl<S: Simd> SimdBase<S> for u16x16<S>

Source§

impl<S: Simd> SimdBase<S> for u16x32<S>

Source§

impl<S: Simd> SimdBase<S> for u32x4<S>

Source§

impl<S: Simd> SimdBase<S> for u32x8<S>

Source§

impl<S: Simd> SimdBase<S> for u32x16<S>