Trait memchr::vector::MoveMask

source ·
pub(crate) trait MoveMask: Copy + Debug {
    // Required methods
    fn all_zeros_except_least_significant(n: usize) -> Self;
    fn has_non_zero(self) -> bool;
    fn count_ones(self) -> usize;
    fn and(self, other: Self) -> Self;
    fn or(self, other: Self) -> Self;
    fn clear_least_significant_bit(self) -> Self;
    fn first_offset(self) -> usize;
    fn last_offset(self) -> usize;
}
Expand description

A trait that abstracts over a vector-to-scalar operation called “move mask.”

On x86-64, this is _mm_movemask_epi8 for SSE2 and _mm256_movemask_epi8 for AVX2. It takes a vector of u8 lanes and returns a scalar where the ith bit is set if and only if the most significant bit in the ith lane of the vector is set. The simd128 ISA for wasm32 also supports this exact same operation natively.

… But aarch64 doesn’t. So we have to fake it with more instructions and a slightly different representation. We could do extra work to unify the representations, but then would require additional costs in the hot path for memchr and packedpair. So instead, we abstraction over the specific representation with this trait an ddefine the operations we actually need.

Required Methods§

source

fn all_zeros_except_least_significant(n: usize) -> Self

Return a mask that is all zeros except for the least significant n lanes in a corresponding vector.

source

fn has_non_zero(self) -> bool

Returns true if and only if this mask has a a non-zero bit anywhere.

source

fn count_ones(self) -> usize

Returns the number of bits set to 1 in this mask.

source

fn and(self, other: Self) -> Self

Does a bitwise and operation between self and other.

source

fn or(self, other: Self) -> Self

Does a bitwise or operation between self and other.

source

fn clear_least_significant_bit(self) -> Self

Returns a mask that is equivalent to self but with the least significant 1-bit set to 0.

source

fn first_offset(self) -> usize

Returns the offset of the first non-zero lane this mask represents.

source

fn last_offset(self) -> usize

Returns the offset of the last non-zero lane this mask represents.

Object Safety§

This trait is not object safe.

Implementors§