pub trait SIMDMask: Copy + Debug {
type Arch: Sealed;
type Underlying: Copy + Debug;
type BitMask: SIMDMask<Arch = Self::Arch> + Into<Self> + From<Self>;
const LANES: usize;
const ISBITS: bool;
Show 13 methods
// Required methods
fn arch(self) -> Self::Arch;
fn to_underlying(self) -> Self::Underlying;
fn from_underlying(arch: Self::Arch, value: Self::Underlying) -> Self;
fn get_unchecked(&self, i: usize) -> bool;
fn keep_first(arch: Self::Arch, i: usize) -> Self;
// Provided methods
fn first(&self) -> Option<usize> { ... }
fn bitmask(self) -> Self::BitMask { ... }
fn get(&self, i: usize) -> Option<bool> { ... }
fn from_fn<F>(arch: Self::Arch, f: F) -> Self
where F: FnMut(usize) -> bool { ... }
fn any(self) -> bool { ... }
fn all(self) -> bool { ... }
fn none(self) -> bool { ... }
fn count(self) -> usize { ... }
}Expand description
A logical mask for SIMD operations.
The representation of this type varies between architectures and micro-architectures. For example:
-
On AVX 2 systems, a SIMD mask for type/length pairs
(T, N)consists of a SIMD register of an unsigned integer with the same size ofTand lengthN.The semantics of such registers are to allow operations in lanes where the top-most bit is set to 1.
-
On AVX-512 systems, the story is much simpler as the masks used in that instruction set are simply the correponsing bit mask.
So a mask for 8-wide operations is simply an 8-bit unsigned integer.
-
Emulated systems should use a bit-mask for the most compact representation.
Required Associated Constants§
Required Associated Types§
Sourcetype Underlying: Copy + Debug
type Underlying: Copy + Debug
The type of the underlying intrinsic.
Required Methods§
Sourcefn to_underlying(self) -> Self::Underlying
fn to_underlying(self) -> Self::Underlying
Retrieve the underlying type.
This will always be an unsigned integer of the minimum width required to contain
LANES bits.
Sourcefn from_underlying(arch: Self::Arch, value: Self::Underlying) -> Self
fn from_underlying(arch: Self::Arch, value: Self::Underlying) -> Self
Construct the mask from the underlying type.
Sourcefn get_unchecked(&self, i: usize) -> bool
fn get_unchecked(&self, i: usize) -> bool
Return true if lane i is set and false otherwise.
This method is unchecked, but safe in the sense that if i >= LANES false will
always be returned. No out of bounds access will be made, but no error indication
will be provided.
Sourcefn keep_first(arch: Self::Arch, i: usize) -> Self
fn keep_first(arch: Self::Arch, i: usize) -> Self
Efficiently construct a new mask with the first i bits set and the remainder
set to zero.
If i >= LANES then all bits will be set.
Provided Methods§
Sourcefn first(&self) -> Option<usize>
fn first(&self) -> Option<usize>
Return the first set index in the mask or None if no entries are set.
Sourcefn get(&self, i: usize) -> Option<bool>
fn get(&self, i: usize) -> Option<bool>
Return true if lane i is set and false otherwise. Returns an empty Option
if the index i is out-of-bounds.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.