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§
Required Methods§
Sourcefn first_n_mask(self, n: usize) -> <Self::Simd as Simd>::Mask
fn first_n_mask(self, n: usize) -> <Self::Simd as Simd>::Mask
Return a mask with the first n lanes set to true.
Sourceunsafe fn load_ptr(self, ptr: *const T) -> Self::Simd
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.
Sourceunsafe fn load_ptr_mask(
self,
ptr: *const T,
mask: <Self::Simd as Simd>::Mask,
) -> Self::Simd
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.
Sourcefn select(
self,
x: Self::Simd,
y: Self::Simd,
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
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.
Sourceunsafe fn store_ptr(self, x: Self::Simd, ptr: *mut T)
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.
Sourceunsafe fn store_ptr_mask(
self,
x: Self::Simd,
ptr: *mut T,
mask: <Self::Simd as Simd>::Mask,
)
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§
Sourcefn from_bits(self, x: <<Self::Simd as Simd>::Isa as Isa>::Bits) -> Self::Simd
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.
Sourcefn broadcast_lane<const LANE: i32>(self, x: Self::Simd) -> Self::Simd
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.
Sourcefn fold_splat<F: Fn(T, T) -> T>(
self,
x: Self::Simd,
accum: T,
f: F,
) -> Self::Simd
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.
Sourcefn load(self, xs: &[T]) -> Self::Simd
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().
Sourcefn load_many<const N: usize>(self, xs: &[T]) -> [Self::Simd; N]
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.
Sourcefn load_pad(self, xs: &[T]) -> (Self::Simd, <Self::Simd as Simd>::Mask)
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.
Sourcefn store_uninit(self, x: Self::Simd, xs: &mut [MaybeUninit<T>]) -> &mut [T]
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.
Sourcefn store_many_uninit<const N: usize>(
self,
vecs: [Self::Simd; N],
xs: &mut [MaybeUninit<T>],
) -> &mut [T]
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.
Sourcefn prefetch_write(self, ptr: *mut T)
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".