Struct Mask
#[repr(transparent)]
pub struct Mask<T, const N: usize>(pub(in ::core_simd::masks) Simd<T, N>)
where
T: MaskElement,;
A SIMD vector mask for N elements of width specified by Element.
Masks represent boolean inclusion/exclusion on a per-element basis.
The layout of this type is unspecified, and may change between platforms
and/or Rust versions, and code should not assume that it is equivalent to
[T; N].
N cannot be 0 and may be at most 64. This limit may be increased in
the future.
Fields
0: Simd<T, N>
Implementations
impl<T, const N: usize> Mask<T, N>
where
T: MaskElement,
const fn splat(value: bool) -> SelfConstructs a mask by setting all elements to the given value.
fn from_array(array: [bool; N]) -> SelfConverts an array of bools to a SIMD mask.
fn to_array(self) -> [bool; N]Converts a SIMD mask to an array of bools.
unsafe fn from_simd_unchecked(value: Simd<T, N>) -> SelfConverts a vector of integers to a mask, where 0 represents
falseand -1 representstrue.Safety
All elements must be either 0 or -1.
fn from_simd(value: Simd<T, N>) -> SelfConverts a vector of integers to a mask, where 0 represents
falseand -1 representstrue.Panics
Panics if any element is not 0 or -1.
fn to_simd(self) -> Simd<T, N>Converts the mask to a vector of integers, where 0 represents
falseand -1 representstrue.fn cast<U: MaskElement>(self) -> Mask<U, N>Converts the mask to a mask of any other element size.
unsafe fn test_unchecked(&self, index: usize) -> boolTests the value of the specified element.
Safety
indexmust be less thanself.len().fn test(&self, index: usize) -> boolTests the value of the specified element.
Panics
Panics if
indexis greater than or equal to the number of elements in the vector.unsafe fn set_unchecked(&mut self, index: usize, value: bool)Sets the value of the specified element.
Safety
indexmust be less thanself.len().fn set(&mut self, index: usize, value: bool)Sets the value of the specified element.
Panics
Panics if
indexis greater than or equal to the number of elements in the vector.fn any(self) -> boolReturns true if any element is set, or false otherwise.
fn all(self) -> boolReturns true if all elements are set, or false otherwise.
fn to_bitmask(self) -> u64Creates a bitmask from a mask.
Each bit is set if the corresponding element in the mask is
true.fn from_bitmask(bitmask: u64) -> SelfCreates a mask from a bitmask.
For each bit, if it is set, the corresponding element in the mask is set to
true. If the mask contains more than 64 elements, the remainder are set tofalse.fn first_set(self) -> Option<usize>Finds the index of the first set element.
# # use simd; # use simd; # use mask32x8; assert_eq!; assert_eq!; let mask = from_array; assert_eq!;fn last_set(self) -> Option<usize>Finds the index of the last set element.
# # use simd; # use simd; # use mask32x8; assert_eq!; assert_eq!; let mask = from_array; assert_eq!;
impl<T, const N: usize> Mask<T, N>
where
T: MaskElement,
fn reverse(self) -> SelfReverse the order of the elements in the mask.
fn rotate_elements_left<const OFFSET: usize>(self) -> SelfRotates the mask such that the first
OFFSETelements of the slice move to the end while the lastself.len() - OFFSETelements move to the front. After callingrotate_elements_left, the element previously at indexOFFSETwill become the first element in the slice.fn rotate_elements_right<const OFFSET: usize>(self) -> SelfRotates the mask such that the first
self.len() - OFFSETelements of the mask move to the end while the lastOFFSETelements move to the front. After callingrotate_elements_right, the element previously at indexself.len() - OFFSETwill become the first element in the slice.fn shift_elements_left<const OFFSET: usize>(self, padding: bool) -> SelfShifts the mask elements to the left by
OFFSET, filling in withpaddingfrom the right.fn shift_elements_right<const OFFSET: usize>(self, padding: bool) -> SelfShifts the mask elements to the right by
OFFSET, filling in withpaddingfrom the left.fn interleave(self, other: Self) -> (Self, Self)Interleave two masks.
The resulting masks contain elements taken alternatively from
selfandother, first filling the first result, and then the second.The reverse of this operation is
Mask::deinterleave.# # use simd; # use simd; # use mask32x4; let a = from_array; let b = from_array; let = a.interleave; assert_eq!; assert_eq!;fn deinterleave(self, other: Self) -> (Self, Self)Deinterleave two masks.
The first result takes every other element of
selfand thenother, starting with the first element.The second result takes every other element of
selfand thenother, starting with the second element.The reverse of this operation is
Mask::interleave.# # use simd; # use simd; # use mask32x4; let a = from_array; let b = from_array; let = a.deinterleave; assert_eq!; assert_eq!;fn resize<const M: usize>(self, value: bool) -> Mask<T, M>Resize a mask.
If
M>N, extends the length of a mask, setting the new elements tovalue. IfM<N, truncates the mask to the firstMelements.# # use simd; # use simd; # use mask32x4; let x = from_array; assert_eq!; assert_eq!;fn extract<const START: usize, const LEN: usize>(self) -> Mask<T, LEN>Extract a vector from another vector.
# # use simd; # use simd; # use mask32x4; let x = from_array; assert_eq!;
Trait Implementations
impl<T, U, const N: usize> Select<Mask<T, N>> for Mask<U, N>
where
T: MaskElement,
U: MaskElement,
fn select(self, true_values: Mask<T, N>, false_values: Mask<T, N>) -> Mask<T, N>
impl<T, U, const N: usize> Select<Simd<T, N>> for Mask<U, N>
where
T: SimdElement,
U: MaskElement,
fn select(self, true_values: Simd<T, N>, false_values: Simd<T, N>) -> Simd<T, N>
impl<T, const N: usize> BitAnd for Mask<T, N>
where
T: MaskElement,
type Output = Mask<T, N>;fn bitand(self, rhs: Self) -> Self
impl<T, const N: usize> BitAnd<bool> for Mask<T, N>
where
T: MaskElement,
type Output = Mask<T, N>;fn bitand(self, rhs: bool) -> Self
impl<T, const N: usize> BitAndAssign for Mask<T, N>
where
T: MaskElement,
fn bitand_assign(&mut self, rhs: Self)
impl<T, const N: usize> BitAndAssign<bool> for Mask<T, N>
where
T: MaskElement,
fn bitand_assign(&mut self, rhs: bool)
impl<T, const N: usize> BitOr for Mask<T, N>
where
T: MaskElement,
type Output = Mask<T, N>;fn bitor(self, rhs: Self) -> Self
impl<T, const N: usize> BitOr<bool> for Mask<T, N>
where
T: MaskElement,
type Output = Mask<T, N>;fn bitor(self, rhs: bool) -> Self
impl<T, const N: usize> BitOrAssign for Mask<T, N>
where
T: MaskElement,
fn bitor_assign(&mut self, rhs: Self)
impl<T, const N: usize> BitOrAssign<bool> for Mask<T, N>
where
T: MaskElement,
fn bitor_assign(&mut self, rhs: bool)
impl<T, const N: usize> BitXor for Mask<T, N>
where
T: MaskElement,
type Output = Mask<T, N>;fn bitxor(self, rhs: Self) -> Self::Output
impl<T, const N: usize> BitXor<bool> for Mask<T, N>
where
T: MaskElement,
type Output = Mask<T, N>;fn bitxor(self, rhs: bool) -> Self::Output
impl<T, const N: usize> BitXorAssign for Mask<T, N>
where
T: MaskElement,
fn bitxor_assign(&mut self, rhs: Self)
impl<T, const N: usize> BitXorAssign<bool> for Mask<T, N>
where
T: MaskElement,
fn bitxor_assign(&mut self, rhs: bool)
impl<T, const N: usize> Clone for Mask<T, N>
where
T: MaskElement,
fn clone(&self) -> Self
impl<T, const N: usize> Copy for Mask<T, N>
where
T: MaskElement,
impl<T, const N: usize> Debug for Mask<T, N>
where
T: MaskElement + Debug,
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T, const N: usize> Default for Mask<T, N>
where
T: MaskElement,
fn default() -> Self
impl<T, const N: usize> From<[bool; N]> for Mask<T, N>
where
T: MaskElement,
fn from(array: [bool; N]) -> Self
impl<T, const N: usize> Not for Mask<T, N>
where
T: MaskElement,
type Output = Mask<T, N>;fn not(self) -> Self::Output
impl<T, const N: usize> PartialEq for Mask<T, N>
where
T: MaskElement + PartialEq,
fn eq(&self, other: &Self) -> bool
impl<T, const N: usize> PartialOrd for Mask<T, N>
where
T: MaskElement + PartialOrd,
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl<const N: usize> From<Mask<i16, N>> for Mask<i32, N>
fn from(value: Mask<i16, N>) -> Self
impl<const N: usize> From<Mask<i16, N>> for Mask<i64, N>
fn from(value: Mask<i16, N>) -> Self
impl<const N: usize> From<Mask<i16, N>> for Mask<i8, N>
fn from(value: Mask<i16, N>) -> Self
impl<const N: usize> From<Mask<i16, N>> for Mask<isize, N>
fn from(value: Mask<i16, N>) -> Self
impl<const N: usize> From<Mask<i32, N>> for Mask<i16, N>
fn from(value: Mask<i32, N>) -> Self
impl<const N: usize> From<Mask<i32, N>> for Mask<i64, N>
fn from(value: Mask<i32, N>) -> Self
impl<const N: usize> From<Mask<i32, N>> for Mask<i8, N>
fn from(value: Mask<i32, N>) -> Self
impl<const N: usize> From<Mask<i32, N>> for Mask<isize, N>
fn from(value: Mask<i32, N>) -> Self
impl<const N: usize> From<Mask<i64, N>> for Mask<i16, N>
fn from(value: Mask<i64, N>) -> Self
impl<const N: usize> From<Mask<i64, N>> for Mask<i32, N>
fn from(value: Mask<i64, N>) -> Self
impl<const N: usize> From<Mask<i64, N>> for Mask<i8, N>
fn from(value: Mask<i64, N>) -> Self
impl<const N: usize> From<Mask<i64, N>> for Mask<isize, N>
fn from(value: Mask<i64, N>) -> Self
impl<const N: usize> From<Mask<i8, N>> for Mask<i16, N>
fn from(value: Mask<i8, N>) -> Self
impl<const N: usize> From<Mask<i8, N>> for Mask<i32, N>
fn from(value: Mask<i8, N>) -> Self
impl<const N: usize> From<Mask<i8, N>> for Mask<i64, N>
fn from(value: Mask<i8, N>) -> Self
impl<const N: usize> From<Mask<i8, N>> for Mask<isize, N>
fn from(value: Mask<i8, N>) -> Self
impl<const N: usize> From<Mask<isize, N>> for Mask<i16, N>
fn from(value: Mask<isize, N>) -> Self
impl<const N: usize> From<Mask<isize, N>> for Mask<i32, N>
fn from(value: Mask<isize, N>) -> Self
impl<const N: usize> From<Mask<isize, N>> for Mask<i64, N>
fn from(value: Mask<isize, N>) -> Self
impl<const N: usize> From<Mask<isize, N>> for Mask<i8, N>
fn from(value: Mask<isize, N>) -> Self
impl<const N: usize> SimdOrd for Mask<i16, N>
fn simd_max(self, other: Self) -> Selffn simd_min(self, other: Self) -> Selffn simd_clamp(self, min: Self, max: Self) -> Self
impl<const N: usize> SimdOrd for Mask<i32, N>
fn simd_max(self, other: Self) -> Selffn simd_min(self, other: Self) -> Selffn simd_clamp(self, min: Self, max: Self) -> Self
impl<const N: usize> SimdOrd for Mask<i64, N>
fn simd_max(self, other: Self) -> Selffn simd_min(self, other: Self) -> Selffn simd_clamp(self, min: Self, max: Self) -> Self
impl<const N: usize> SimdOrd for Mask<i8, N>
fn simd_max(self, other: Self) -> Selffn simd_min(self, other: Self) -> Selffn simd_clamp(self, min: Self, max: Self) -> Self
impl<const N: usize> SimdOrd for Mask<isize, N>
fn simd_max(self, other: Self) -> Selffn simd_min(self, other: Self) -> Selffn simd_clamp(self, min: Self, max: Self) -> Self
impl<const N: usize> SimdPartialEq for Mask<i16, N>
type Mask = Mask<i16, N>;fn simd_eq(self, other: Self) -> Self::Maskfn simd_ne(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialEq for Mask<i32, N>
type Mask = Mask<i32, N>;fn simd_eq(self, other: Self) -> Self::Maskfn simd_ne(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialEq for Mask<i64, N>
type Mask = Mask<i64, N>;fn simd_eq(self, other: Self) -> Self::Maskfn simd_ne(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialEq for Mask<i8, N>
type Mask = Mask<i8, N>;fn simd_eq(self, other: Self) -> Self::Maskfn simd_ne(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialEq for Mask<isize, N>
type Mask = Mask<isize, N>;fn simd_eq(self, other: Self) -> Self::Maskfn simd_ne(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialOrd for Mask<i16, N>
fn simd_lt(self, other: Self) -> Self::Maskfn simd_le(self, other: Self) -> Self::Maskfn simd_gt(self, other: Self) -> Self::Maskfn simd_ge(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialOrd for Mask<i32, N>
fn simd_lt(self, other: Self) -> Self::Maskfn simd_le(self, other: Self) -> Self::Maskfn simd_gt(self, other: Self) -> Self::Maskfn simd_ge(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialOrd for Mask<i64, N>
fn simd_lt(self, other: Self) -> Self::Maskfn simd_le(self, other: Self) -> Self::Maskfn simd_gt(self, other: Self) -> Self::Maskfn simd_ge(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialOrd for Mask<i8, N>
fn simd_lt(self, other: Self) -> Self::Maskfn simd_le(self, other: Self) -> Self::Maskfn simd_gt(self, other: Self) -> Self::Maskfn simd_ge(self, other: Self) -> Self::Mask
impl<const N: usize> SimdPartialOrd for Mask<isize, N>
fn simd_lt(self, other: Self) -> Self::Maskfn simd_le(self, other: Self) -> Self::Maskfn simd_gt(self, other: Self) -> Self::Maskfn simd_ge(self, other: Self) -> Self::Mask
Auto Trait Implementations
impl<T, const N: usize> Freeze for Mask<T, N>
where
Simd<T, N>: Freeze,
impl<T, const N: usize> RefUnwindSafe for Mask<T, N>
where
Simd<T, N>: RefUnwindSafe,
impl<T, const N: usize> Send for Mask<T, N>
where
Simd<T, N>: Send,
impl<T, const N: usize> Sync for Mask<T, N>
where
Simd<T, N>: Sync,
impl<T, const N: usize> Unpin for Mask<T, N>
where
Simd<T, N>: Unpin,
impl<T, const N: usize> UnsafeUnpin for Mask<T, N>
where
Simd<T, N>: UnsafeUnpin,
impl<T, const N: usize> UnwindSafe for Mask<T, N>
where
Simd<T, N>: UnwindSafe,
Blanket Implementations
impl<T> Any for Mask<T, N>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Mask<T, N>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Mask<T, N>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Mask<T, N>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Mask<T, N>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for Mask<T, N>
where
T: Copy + Debug,
impl<T> SizeHint for Mask<T, N>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for Mask<T, N>
impl<T, U> Into<U> for Mask<T, N>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Mask<T, N>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for Mask<T, N>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>