Skip to content

Commit 3733375

Browse files
committed
Remove bitmask vectors in favor of extracting bitmasks
1 parent 675401b commit 3733375

File tree

4 files changed

+0
-157
lines changed

4 files changed

+0
-157
lines changed

crates/core_simd/src/masks.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -308,48 +308,6 @@ where
308308
Self(mask_impl::Mask::from_bitmask_integer(bitmask))
309309
}
310310

311-
/// Create a bitmask vector from a mask.
312-
///
313-
/// Each bit is set if the corresponding element in the mask is `true`.
314-
/// The remaining bits are unset.
315-
///
316-
/// The bits are packed into the first N bits of the vector:
317-
/// ```
318-
/// # #![feature(portable_simd)]
319-
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
320-
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
321-
/// # use simd::mask32x8;
322-
/// let mask = mask32x8::from_array([true, false, true, false, false, false, true, false]);
323-
/// assert_eq!(mask.to_bitmask_vector()[0], 0b01000101);
324-
/// ```
325-
#[inline]
326-
#[must_use = "method returns a new integer and does not mutate the original value"]
327-
pub fn to_bitmask_vector(self) -> Simd<u8, N> {
328-
self.0.to_bitmask_vector()
329-
}
330-
331-
/// Create a mask from a bitmask vector.
332-
///
333-
/// For each bit, if it is set, the corresponding element in the mask is set to `true`.
334-
///
335-
/// The bits are packed into the first N bits of the vector:
336-
/// ```
337-
/// # #![feature(portable_simd)]
338-
/// # #[cfg(feature = "as_crate")] use core_simd::simd;
339-
/// # #[cfg(not(feature = "as_crate"))] use core::simd;
340-
/// # use simd::{mask32x8, u8x8};
341-
/// let bitmask = u8x8::from_array([0b01000101, 0, 0, 0, 0, 0, 0, 0]);
342-
/// assert_eq!(
343-
/// mask32x8::from_bitmask_vector(bitmask),
344-
/// mask32x8::from_array([true, false, true, false, false, false, true, false]),
345-
/// );
346-
/// ```
347-
#[inline]
348-
#[must_use = "method returns a new mask and does not mutate the original value"]
349-
pub fn from_bitmask_vector(bitmask: Simd<u8, N>) -> Self {
350-
Self(mask_impl::Mask::from_bitmask_vector(bitmask))
351-
}
352-
353311
/// Find the index of the first set element.
354312
///
355313
/// ```

crates/core_simd/src/masks/bitmask.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,6 @@ where
122122
unsafe { Self(core::intrinsics::simd::simd_bitmask(value), PhantomData) }
123123
}
124124

125-
#[inline]
126-
#[must_use = "method returns a new vector and does not mutate the original value"]
127-
pub fn to_bitmask_vector(self) -> Simd<u8, N> {
128-
let mut bitmask = Simd::splat(0);
129-
bitmask.as_mut_array()[..self.0.as_ref().len()].copy_from_slice(self.0.as_ref());
130-
bitmask
131-
}
132-
133-
#[inline]
134-
#[must_use = "method returns a new mask and does not mutate the original value"]
135-
pub fn from_bitmask_vector(bitmask: Simd<u8, N>) -> Self {
136-
let mut bytes = <LaneCount<N> as SupportedLaneCount>::BitMask::default();
137-
let len = bytes.as_ref().len();
138-
bytes.as_mut().copy_from_slice(&bitmask.as_array()[..len]);
139-
Self(bytes, PhantomData)
140-
}
141-
142125
#[inline]
143126
pub fn to_bitmask_integer(self) -> u64 {
144127
let mut bitmask = [0u8; 8];

crates/core_simd/src/masks/full_masks.rs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -140,62 +140,6 @@ where
140140
unsafe { Mask(core::intrinsics::simd::simd_cast(self.0)) }
141141
}
142142

143-
#[inline]
144-
#[must_use = "method returns a new vector and does not mutate the original value"]
145-
pub fn to_bitmask_vector(self) -> Simd<u8, N> {
146-
let mut bitmask = Simd::splat(0);
147-
148-
// Safety: Bytes is the right size array
149-
unsafe {
150-
// Compute the bitmask
151-
let mut bytes: <LaneCount<N> as SupportedLaneCount>::BitMask =
152-
core::intrinsics::simd::simd_bitmask(self.0);
153-
154-
// LLVM assumes bit order should match endianness
155-
if cfg!(target_endian = "big") {
156-
for x in bytes.as_mut() {
157-
*x = x.reverse_bits()
158-
}
159-
if N % 8 > 0 {
160-
bytes.as_mut()[N / 8] >>= 8 - N % 8;
161-
}
162-
}
163-
164-
bitmask.as_mut_array()[..bytes.as_ref().len()].copy_from_slice(bytes.as_ref());
165-
}
166-
167-
bitmask
168-
}
169-
170-
#[inline]
171-
#[must_use = "method returns a new mask and does not mutate the original value"]
172-
pub fn from_bitmask_vector(bitmask: Simd<u8, N>) -> Self {
173-
let mut bytes = <LaneCount<N> as SupportedLaneCount>::BitMask::default();
174-
175-
// Safety: Bytes is the right size array
176-
unsafe {
177-
let len = bytes.as_ref().len();
178-
bytes.as_mut().copy_from_slice(&bitmask.as_array()[..len]);
179-
180-
// LLVM assumes bit order should match endianness
181-
if cfg!(target_endian = "big") {
182-
for x in bytes.as_mut() {
183-
*x = x.reverse_bits();
184-
}
185-
if N % 8 > 0 {
186-
bytes.as_mut()[N / 8] >>= 8 - N % 8;
187-
}
188-
}
189-
190-
// Compute the regular mask
191-
Self::from_int_unchecked(core::intrinsics::simd::simd_select_bitmask(
192-
bytes,
193-
Self::splat(true).to_int(),
194-
Self::splat(false).to_int(),
195-
))
196-
}
197-
}
198-
199143
#[inline]
200144
unsafe fn to_bitmask_impl<U: ReverseBits, const M: usize>(self) -> U
201145
where

crates/core_simd/tests/masks.rs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -134,48 +134,6 @@ macro_rules! test_mask_api {
134134
cast_impl::<i64>();
135135
cast_impl::<isize>();
136136
}
137-
138-
#[test]
139-
fn roundtrip_bitmask_vector_conversion() {
140-
use core_simd::simd::ToBytes;
141-
let values = [
142-
true, false, false, true, false, false, true, false,
143-
true, true, false, false, false, false, false, true,
144-
];
145-
let mask = Mask::<$type, 16>::from_array(values);
146-
let bitmask = mask.to_bitmask_vector();
147-
assert_eq!(bitmask.resize::<2>(0).to_ne_bytes()[..2], [0b01001001, 0b10000011]);
148-
assert_eq!(Mask::<$type, 16>::from_bitmask_vector(bitmask), mask);
149-
}
150-
151-
// rust-lang/portable-simd#379
152-
#[test]
153-
fn roundtrip_bitmask_vector_conversion_small() {
154-
use core_simd::simd::ToBytes;
155-
let values = [
156-
true, false, true, true
157-
];
158-
let mask = Mask::<$type, 4>::from_array(values);
159-
let bitmask = mask.to_bitmask_vector();
160-
assert_eq!(bitmask.resize::<1>(0).to_ne_bytes()[0], 0b00001101);
161-
assert_eq!(Mask::<$type, 4>::from_bitmask_vector(bitmask), mask);
162-
}
163-
164-
/* FIXME doesn't work with non-powers-of-two, yet
165-
// rust-lang/portable-simd#379
166-
#[cfg(feature = "all_lane_counts")]
167-
#[test]
168-
fn roundtrip_bitmask_vector_conversion_odd() {
169-
use core_simd::simd::ToBytes;
170-
let values = [
171-
true, false, true, false, true, true, false, false, false, true, true,
172-
];
173-
let mask = Mask::<$type, 11>::from_array(values);
174-
let bitmask = mask.to_bitmask_vector();
175-
assert_eq!(bitmask.resize::<2>(0).to_ne_bytes()[..2], [0b00110101, 0b00000110]);
176-
assert_eq!(Mask::<$type, 11>::from_bitmask_vector(bitmask), mask);
177-
}
178-
*/
179137
}
180138
}
181139
}

0 commit comments

Comments
 (0)