Trait SimdMask
pub trait SimdMask<S: Simd>: ExtractToken<S = S> + Copy + Sync + Send + 'static + Seal + Select<Self> + BitAnd<Output = Self> + BitAndAssign + BitOr<Output = Self> + BitOrAssign + BitXor<Output = Self> + BitXorAssign + Not<Output = Self>
Functionality implemented by SIMD masks.
A mask has one logical boolean lane per SIMD lane. Its storage is intentionally opaque: current backends may use all-zero/all-one integer vectors internally, while future predicate-register backends may use a compact representation.
Associated Types
type Element: SimdIntElement<Mask = Self::Element> + Neg<Output = Self::Element>;The signed integer type used when converting this mask to and from lane values.
False lanes are encoded as all zeroes (integer value 0), and true lanes are encoded as all ones (integer value -1).
type Ints: SimdInt<S, Element = Self::Element, Mask = Self> + Neg<Output = Self::Ints>;This mask's corresponding integer vector type.
Associated Constants
const LEN: usize;This mask type's lane count.
Required Methods
fn splat(simd: S, val: bool) -> SelfCreate a SIMD mask with all lanes set to the given boolean value.
fn from_bitmask(simd: S, bits: u64) -> SelfCreate a mask from a compact bitmask.
Bit
imaps to lanei, with lane 0 in the least significant bit. Bits aboveSelf::LENare ignored.fn to_bitmask(self) -> u64Convert this mask to a compact bitmask.
Bit
imaps to lanei, with lane 0 in the least significant bit. Bits aboveSelf::LENare cleared.fn from_vector(v: Self::Ints) -> SelfCreate a SIMD mask from signed integer mask lanes.
fn to_vector(self) -> Self::IntsConvert this SIMD mask to signed integer mask lanes.
fn set(&mut self, index: usize, value: bool)Sets the value of one logical lane.
Panics if
indexis greater than or equal to the number of lanes in the mask.fn from_slice(simd: S, slice: &[Self::Element]) -> SelfCreate a SIMD mask from signed integer mask lanes.
The slice must be exactly the size of the SIMD mask.
fn store_slice(&self, slice: &mut [Self::Element])Store this SIMD mask as signed integer mask lanes.
The slice must be exactly the size of the SIMD mask.
fn rotate_elements_left<const OFFSET: usize>(self) -> SelfRotate the mask elements to the left by
OFFSET.If
OFFSETis greater than or equal toSelf::LEN, it wraps moduloSelf::LEN.fn rotate_elements_right<const OFFSET: usize>(self) -> SelfRotate the mask elements to the right by
OFFSET.If
OFFSETis greater than or equal toSelf::LEN, it wraps moduloSelf::LEN.fn reverse(self) -> SelfReverse the order of the mask's logical lanes.
fn simd_eq(self, rhs: impl SimdInto<Self, S>) -> SelfCompare two vectors element-wise for equality.
Returns a mask where each logical lane is true if the corresponding elements are equal, and false if not.
fn simd_ne(self, rhs: impl SimdInto<Self, S>) -> SelfCompare two masks element-wise for inequality.
Returns a mask where each logical lane is true if the corresponding elements are unequal, and false if equal.
This is equivalent to negating the mask returned by
simd_eq.fn any_true(self) -> boolReturns true if any logical lanes in this mask are true.
Masks may be converted to and from signed integer lane arrays for compatibility with older APIs. For those conversions, false is encoded as all zeroes (integer value 0) and true is encoded as all ones (integer value -1).
Behavior on masks constructed from any other integer bit pattern is unspecified. It may vary depending on architecture, feature level, the mask elements' width, the mask vector's width, or library version.
The behavior is also not guaranteed to be logically consistent for such non-canonical masks.
any_truemay not return the same result as!all_false, andall_truemay not return the same result as!any_false.The
selectoperation also has unspecified behavior for non-canonical masks. That behavior may not match the behavior of this operation.fn all_true(self) -> boolReturns true if all logical lanes in this mask are true.
Masks may be converted to and from signed integer lane arrays for compatibility with older APIs. For those conversions, false is encoded as all zeroes (integer value 0) and true is encoded as all ones (integer value -1).
Behavior on masks constructed from any other integer bit pattern is unspecified. It may vary depending on architecture, feature level, the mask elements' width, the mask vector's width, or library version.
The behavior is also not guaranteed to be logically consistent for such non-canonical masks.
any_truemay not return the same result as!all_false, andall_truemay not return the same result as!any_false.The
selectoperation also has unspecified behavior for non-canonical masks. That behavior may not match the behavior of this operation.fn any_false(self) -> boolReturns true if any logical lanes in this mask are false.
This is logically equivalent to
!all_true, but may be faster.Masks may be converted to and from signed integer lane arrays for compatibility with older APIs. For those conversions, false is encoded as all zeroes (integer value 0) and true is encoded as all ones (integer value -1).
Behavior on masks constructed from any other integer bit pattern is unspecified. It may vary depending on architecture, feature level, the mask elements' width, the mask vector's width, or library version.
The behavior is also not guaranteed to be logically consistent for such non-canonical masks.
any_truemay not return the same result as!all_false, andall_truemay not return the same result as!any_false.The
selectoperation also has unspecified behavior for non-canonical masks. That behavior may not match the behavior of this operation.fn all_false(self) -> boolReturns true if all logical lanes in this mask are false.
This is logically equivalent to
!any_true, but may be faster.Masks may be converted to and from signed integer lane arrays for compatibility with older APIs. For those conversions, false is encoded as all zeroes (integer value 0) and true is encoded as all ones (integer value -1).
Behavior on masks constructed from any other integer bit pattern is unspecified. It may vary depending on architecture, feature level, the mask elements' width, the mask vector's width, or library version.
The behavior is also not guaranteed to be logically consistent for such non-canonical masks.
any_truemay not return the same result as!all_false, andall_truemay not return the same result as!any_false.The
selectoperation also has unspecified behavior for non-canonical masks. That behavior may not match the behavior of this operation.
Provided Methods
fn test(&self, index: usize) -> boolTest whether one logical lane is set.
Panics if
indexis greater than or equal to the number of lanes in the mask.
Implementors
impl<S: Simd> SimdMask<S> for mask16x16<S>impl<S: Simd> SimdMask<S> for mask16x32<S>impl<S: Simd> SimdMask<S> for mask16x8<S>impl<S: Simd> SimdMask<S> for mask32x16<S>impl<S: Simd> SimdMask<S> for mask32x4<S>impl<S: Simd> SimdMask<S> for mask32x8<S>impl<S: Simd> SimdMask<S> for mask64x2<S>impl<S: Simd> SimdMask<S> for mask64x4<S>impl<S: Simd> SimdMask<S> for mask64x8<S>impl<S: Simd> SimdMask<S> for mask8x16<S>impl<S: Simd> SimdMask<S> for mask8x32<S>impl<S: Simd> SimdMask<S> for mask8x64<S>