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
i
th bit is set if and only if the most significant bit in the i
th 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§
Sourcefn all_zeros_except_least_significant(n: usize) -> Self
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.
Sourcefn has_non_zero(self) -> bool
fn has_non_zero(self) -> bool
Returns true if and only if this mask has a a non-zero bit anywhere.
Sourcefn count_ones(self) -> usize
fn count_ones(self) -> usize
Returns the number of bits set to 1 in this mask.
Sourcefn clear_least_significant_bit(self) -> Self
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.
Sourcefn first_offset(self) -> usize
fn first_offset(self) -> usize
Returns the offset of the first non-zero lane this mask represents.
Sourcefn last_offset(self) -> usize
fn last_offset(self) -> usize
Returns the offset of the last non-zero lane this mask represents.
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.