Skip to content

Commit 4d0397d

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

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

crates/core_simd/src/intrinsics.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ 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 mask and
134+
// returns the most significant bit (MSB) of each lane in the form
135+
// of either:
136+
// * an unsigned integer
137+
// * an array of `u8`
138+
// If the vector has less than 8 lanes, a u8 is returned with zeroed trailing bits.
139+
//
140+
// The bit order of the result depends on the byte endianness, LSB-first for little
141+
// endian and MSB-first for big endian.
142+
// Not intended to be called on a vector with values other than 0 and -1.
133143
#[allow(unused)]
134144
pub(crate) fn simd_bitmask<T, U>(x: T) -> U;
135145

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)