Skip to main content

BitOps

Trait BitOps 

Source
pub unsafe trait BitOps<T: Elem>: Copy {
    type Simd: Simd<Elem = T>;

Show 24 methods // Required methods fn len(self) -> usize; fn and(self, x: Self::Simd, y: Self::Simd) -> Self::Simd; fn not(self, x: Self::Simd) -> Self::Simd; fn or(self, x: Self::Simd, y: Self::Simd) -> Self::Simd; fn xor(self, x: Self::Simd, y: Self::Simd) -> Self::Simd; fn splat(self, x: T) -> Self::Simd; fn first_n_mask(self, n: usize) -> <Self::Simd as Simd>::Mask; unsafe fn load_ptr(self, ptr: *const T) -> Self::Simd; unsafe fn load_ptr_mask( self, ptr: *const T, mask: <Self::Simd as Simd>::Mask, ) -> Self::Simd; fn select( self, x: Self::Simd, y: Self::Simd, mask: <Self::Simd as Simd>::Mask, ) -> Self::Simd; unsafe fn store_ptr(self, x: Self::Simd, ptr: *mut T); unsafe fn store_ptr_mask( self, x: Self::Simd, ptr: *mut T, mask: <Self::Simd as Simd>::Mask, ); // Provided methods fn from_bits( self, x: <<Self::Simd as Simd>::Isa as Isa>::Bits, ) -> Self::Simd { ... } fn zero(self) -> Self::Simd { ... } fn broadcast_lane<const LANE: i32>(self, x: Self::Simd) -> Self::Simd { ... } fn fold_splat<F: Fn(T, T) -> T>( self, x: Self::Simd, accum: T, f: F, ) -> Self::Simd { ... } fn load(self, xs: &[T]) -> Self::Simd { ... } fn load_many<const N: usize>(self, xs: &[T]) -> [Self::Simd; N] { ... } fn load_pad(self, xs: &[T]) -> (Self::Simd, <Self::Simd as Simd>::Mask) { ... } fn store(self, x: Self::Simd, xs: &mut [T]) { ... } fn store_uninit(self, x: Self::Simd, xs: &mut [MaybeUninit<T>]) -> &mut [T] { ... } fn store_many_uninit<const N: usize>( self, vecs: [Self::Simd; N], xs: &mut [MaybeUninit<T>], ) -> &mut [T] { ... } fn prefetch(self, ptr: *const T) { ... } fn prefetch_write(self, ptr: *mut T) { ... }
}
Expand description

Bit-level operations available on all SIMD vector types.

This trait provides operations which treat a SIMD vector as a sequence of bits, without interpreting those bits as numbers of a particular type:

  • Load from and store into memory
  • Creating a new vector filled with zeros or a specific value
  • Combining elements from two vectors according to a mask
  • Bitwise operations (and, or, xor, not)

Arithmetic operations which require interpreting the bits as numbers are provided by the NumOps sub-trait. Splitting these operations allows supporting data types for which only bit-level operations are available. For example many x86 and Arm CPUs support loading, storing and shuffling f16 vectors, but not arithmetic on them.

§Safety

Implementations must ensure they can only be constructed if the instruction set is supported on the current system.

Required Associated Types§

Source

type Simd: Simd<Elem = T>

SIMD vector containing lanes of type T.

Required Methods§

Source

fn len(self) -> usize

Return the number of elements in the vector.

Source

fn and(self, x: Self::Simd, y: Self::Simd) -> Self::Simd

Return the bitwise AND of x and y.

Source

fn not(self, x: Self::Simd) -> Self::Simd

Return the bitwise NOT of x.

Source

fn or(self, x: Self::Simd, y: Self::Simd) -> Self::Simd

Return the bitwise OR of x and y.

Source

fn xor(self, x: Self::Simd, y: Self::Simd) -> Self::Simd

Return the bitwise XOR of x and y.

Source

fn splat(self, x: T) -> Self::Simd

Create a new vector with all lanes set to x.

Source

fn first_n_mask(self, n: usize) -> <Self::Simd as Simd>::Mask

Return a mask with the first n lanes set to true.

Source

unsafe fn load_ptr(self, ptr: *const T) -> Self::Simd

Load vector of elements from ptr.

ptr is not required to have any particular alignment.

§Safety

ptr must point to self.len() initialized elements of type T.

Source

unsafe fn load_ptr_mask( self, ptr: *const T, mask: <Self::Simd as Simd>::Mask, ) -> Self::Simd

Load vector elements from ptr using a mask.

ptr is not required to have any particular alignment.

§Safety

For each mask position i which is true, ptr.add(i) must point to an initialized element of type T.

Source

fn select( self, x: Self::Simd, y: Self::Simd, mask: <Self::Simd as Simd>::Mask, ) -> Self::Simd

Select elements from x or y according to a mask.

Elements are selected from x where the corresponding mask element is one or y if zero.

Source

unsafe fn store_ptr(self, x: Self::Simd, ptr: *mut T)

Store the values in this vector to a memory location.

§Safety

ptr must point to self.len() elements.

Source

unsafe fn store_ptr_mask( self, x: Self::Simd, ptr: *mut T, mask: <Self::Simd as Simd>::Mask, )

Store the values in this vector to a memory location, where the corresponding mask element is set.

§Safety

For each position i in the mask which is true, ptr.add(i) must point to a valid element of type Self::Elem.

Provided Methods§

Source

fn from_bits(self, x: <<Self::Simd as Simd>::Isa as Isa>::Bits) -> Self::Simd

Convert x to an untyped vector of the same width.

Source

fn zero(self) -> Self::Simd

Create a new vector with all lanes set to zero.

Source

fn broadcast_lane<const LANE: i32>(self, x: Self::Simd) -> Self::Simd

Broadcast the element from one lane of a vector to all lanes of a new vector.

Source

fn fold_splat<F: Fn(T, T) -> T>( self, x: Self::Simd, accum: T, f: F, ) -> Self::Simd

Reduce the elements in x to a single value using f, then return a new vector with the accumulated value broadcast to each lane.

Source

fn load(self, xs: &[T]) -> Self::Simd

Load the first self.len() elements from a slice into a vector.

Panics if xs.len() < self.len().

Source

fn load_many<const N: usize>(self, xs: &[T]) -> [Self::Simd; N]

Load N vectors from consecutive sub-slices of xs.

Panics if xs.len() < self.len() * N.

Source

fn load_pad(self, xs: &[T]) -> (Self::Simd, <Self::Simd as Simd>::Mask)

Load elements from xs into a vector.

If the vector length exceeds xs.len(), the tail is padded with zeros.

Returns the padded vector and a mask of the lanes which were set.

Source

fn store(self, x: Self::Simd, xs: &mut [T])

Store x into the first self.len() elements of xs.

Source

fn store_uninit(self, x: Self::Simd, xs: &mut [MaybeUninit<T>]) -> &mut [T]

Store x into the first self.len() elements of xs.

This is a variant of store which takes an uninitialized slice as input and returns the initialized portion of the slice.

Source

fn store_many_uninit<const N: usize>( self, vecs: [Self::Simd; N], xs: &mut [MaybeUninit<T>], ) -> &mut [T]

Store N vectors into consecutive sub-slices of xs, returning the initialized portion.

This can be faster than store_uninit when storing several vectors as it only performs a single bounds check.

Panics if xs.len() < self.len() * N.

Source

fn prefetch(self, ptr: *const T)

Pre-fetch the cache line containing ptr for reading.

Source

fn prefetch_write(self, ptr: *mut T)

Pre-fetch the cache line containing ptr for writing.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl BitOps<f16> for Avx2Isa

Source§

type Simd = F16x16

Source§

impl BitOps<f16> for Avx512Isa

Source§

type Simd = F16x32

Source§

impl BitOps<f16> for GenericIsa

Source§

type Simd = F16x8

Source§

impl BitOps<f32> for Avx2Isa

Source§

type Simd = F32x8

Source§

impl BitOps<f32> for Avx512Isa

Source§

type Simd = F32x16

Source§

impl BitOps<f32> for GenericIsa

Source§

type Simd = F32x4

Source§

impl BitOps<i8> for Avx2Isa

Source§

type Simd = I8x32

Source§

impl BitOps<i8> for Avx512Isa

Source§

type Simd = I8x64

Source§

impl BitOps<i8> for GenericIsa

Source§

type Simd = I8x16

Source§

impl BitOps<i16> for Avx2Isa

Source§

type Simd = I16x16

Source§

impl BitOps<i16> for Avx512Isa

Source§

type Simd = I16x32

Source§

impl BitOps<i16> for GenericIsa

Source§

type Simd = I16x8

Source§

impl BitOps<i32> for Avx2Isa

Source§

type Simd = I32x8

Source§

impl BitOps<i32> for Avx512Isa

Source§

type Simd = I32x16

Source§

impl BitOps<i32> for GenericIsa

Source§

type Simd = I32x4

Source§

impl BitOps<u8> for Avx2Isa

Source§

type Simd = U8x32

Source§

impl BitOps<u8> for Avx512Isa

Source§

type Simd = U8x64

Source§

impl BitOps<u8> for GenericIsa

Source§

type Simd = U8x16

Source§

impl BitOps<u16> for Avx2Isa

Source§

type Simd = U16x16

Source§

impl BitOps<u16> for Avx512Isa

Source§

type Simd = U16x32

Source§

impl BitOps<u16> for GenericIsa

Source§

type Simd = U16x8