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) -> Self

Create a SIMD mask with all lanes set to the given boolean value.

fn from_bitmask(simd: S, bits: u64) -> Self

Create a mask from a compact bitmask.

Bit i maps to lane i, with lane 0 in the least significant bit. Bits above Self::LEN are ignored.

fn to_bitmask(self) -> u64

Convert this mask to a compact bitmask.

Bit i maps to lane i, with lane 0 in the least significant bit. Bits above Self::LEN are cleared.

fn from_vector(v: Self::Ints) -> Self

Create a SIMD mask from signed integer mask lanes.

fn to_vector(self) -> Self::Ints

Convert 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 index is greater than or equal to the number of lanes in the mask.

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

Create 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) -> Self

Rotate the mask elements to the left by OFFSET.

If OFFSET is greater than or equal to Self::LEN, it wraps modulo Self::LEN.

fn rotate_elements_right<const OFFSET: usize>(self) -> Self

Rotate the mask elements to the right by OFFSET.

If OFFSET is greater than or equal to Self::LEN, it wraps modulo Self::LEN.

fn reverse(self) -> Self

Reverse the order of the mask's logical lanes.

fn simd_eq(self, rhs: impl SimdInto<Self, S>) -> Self

Compare 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>) -> Self

Compare 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) -> bool

Returns 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_true may not return the same result as !all_false, and all_true may not return the same result as !any_false.

The select operation also has unspecified behavior for non-canonical masks. That behavior may not match the behavior of this operation.

fn all_true(self) -> bool

Returns 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_true may not return the same result as !all_false, and all_true may not return the same result as !any_false.

The select operation also has unspecified behavior for non-canonical masks. That behavior may not match the behavior of this operation.

fn any_false(self) -> bool

Returns 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_true may not return the same result as !all_false, and all_true may not return the same result as !any_false.

The select operation also has unspecified behavior for non-canonical masks. That behavior may not match the behavior of this operation.

fn all_false(self) -> bool

Returns 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_true may not return the same result as !all_false, and all_true may not return the same result as !any_false.

The select operation 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) -> bool

Test whether one logical lane is set.

Panics if index is greater than or equal to the number of lanes in the mask.

Implementors