Skip to main content

SIMDMask

Trait SIMDMask 

Source
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 of T and length N.

    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§

Source

const LANES: usize

The number of lanes in the bitmask.

Source

const ISBITS: bool

Whether or not this mask implementation is a bit mask.

Required Associated Types§

Source

type Arch: Sealed

The architecture type this struct belongs to.

Source

type Underlying: Copy + Debug

The type of the underlying intrinsic.

Source

type BitMask: SIMDMask<Arch = Self::Arch> + Into<Self> + From<Self>

The bitmask associated with the logical mask.

Required Methods§

Source

fn arch(self) -> Self::Arch

Return the architecture object associated with this vector.

Source

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.

Source

fn from_underlying(arch: Self::Arch, value: Self::Underlying) -> Self

Construct the mask from the underlying type.

Source

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.

Source

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§

Source

fn first(&self) -> Option<usize>

Return the first set index in the mask or None if no entries are set.

Source

fn bitmask(self) -> Self::BitMask

Return the associated BitMask for this Mask.

Source

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.

Source

fn from_fn<F>(arch: Self::Arch, f: F) -> Self
where F: FnMut(usize) -> bool,

Construct a mask based on the result of invoking f once each element in the range 0..Self::LANES in order.

In the returned mask m, m.get(0) corresponds to the value of f(0). Similarly, m.get(1) corresponds to f(1) etc.

Source

fn any(self) -> bool

Return true if any lane in the mask is set. Otherwise, return `false.

Source

fn all(self) -> bool

Return true if all lanes in the mask are set. Otherwise, return false.

Source

fn none(self) -> bool

Return true if all lanes in the mask are set. Otherwise, return false.

Source

fn count(self) -> usize

Return the number of lanes that evaluate to true.

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.

Implementors§

Source§

impl SIMDMask for mask8x16

Source§

impl SIMDMask for mask8x32

Source§

impl SIMDMask for mask32x4

Source§

impl SIMDMask for mask32x8

Source§

impl SIMDMask for mask64x2

Source§

impl SIMDMask for mask64x4

Source§

impl<A: Sealed> SIMDMask for BitMask<1, A>

Source§

impl<A: Sealed> SIMDMask for BitMask<2, A>

Source§

impl<A: Sealed> SIMDMask for BitMask<4, A>

Source§

impl<A: Sealed> SIMDMask for BitMask<8, A>

Source§

impl<A: Sealed> SIMDMask for BitMask<16, A>

Source§

impl<A: Sealed> SIMDMask for BitMask<32, A>

Source§

impl<A: Sealed> SIMDMask for BitMask<64, A>