Skip to content

Commit d411ef5

Browse files
Add bitmask i{N <8} -> u8 impls
...and copy the notes for why they're legal.
1 parent a5789d1 commit d411ef5

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

crates/core_simd/src/intrinsics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ extern "platform-intrinsic" {
130130
pub(crate) fn simd_reduce_xor<T, U>(x: T) -> U;
131131

132132
// truncate integer vector to bitmask
133+
// `fn simd_bitmask(vector) -> unsigned integer` takes a vector of integers and
134+
// returns either an unsigned integer or array of `u8`.
135+
// Every element in the vector becomes a single bit in the returned bitmask.
136+
// If the vector has less than 8 lanes, a u8 is returned with zeroed trailing bits.
137+
// The bit order of the result depends on the byte endianness. LSB-first for little
138+
// endian and MSB-first for big endian.
139+
//
140+
// UB if called on a vector with values other than 0 and -1.
133141
#[allow(unused)]
134142
pub(crate) fn simd_bitmask<T, U>(x: T) -> U;
135143

crates/core_simd/src/masks/to_bitmask.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ macro_rules! impl_integer_intrinsic {
5050
}
5151

5252
impl_integer_intrinsic! {
53+
unsafe impl ToBitMask<BitMask=u8> for Mask<_, 1>
54+
unsafe impl ToBitMask<BitMask=u8> for Mask<_, 2>
55+
unsafe impl ToBitMask<BitMask=u8> for Mask<_, 4>
5356
unsafe impl ToBitMask<BitMask=u8> for Mask<_, 8>
5457
unsafe impl ToBitMask<BitMask=u16> for Mask<_, 16>
5558
unsafe impl ToBitMask<BitMask=u32> for Mask<_, 32>

0 commit comments

Comments
 (0)