Skip to content

Commit 0f68ecb

Browse files
committed
Use new bitmask intrinsics with byte arrays
1 parent 8cf7a62 commit 0f68ecb

File tree

3 files changed

+3
-36
lines changed

3 files changed

+3
-36
lines changed

crates/core_simd/src/lane_count.rs

-9
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,25 @@ impl<const LANES: usize> LaneCount<LANES> {
1515
pub trait SupportedLaneCount: Sealed {
1616
#[doc(hidden)]
1717
type BitMask: Copy + Default + AsRef<[u8]> + AsMut<[u8]>;
18-
19-
#[doc(hidden)]
20-
type IntBitMask;
2118
}
2219

2320
impl<const LANES: usize> Sealed for LaneCount<LANES> {}
2421

2522
impl SupportedLaneCount for LaneCount<1> {
2623
type BitMask = [u8; 1];
27-
type IntBitMask = u8;
2824
}
2925
impl SupportedLaneCount for LaneCount<2> {
3026
type BitMask = [u8; 1];
31-
type IntBitMask = u8;
3227
}
3328
impl SupportedLaneCount for LaneCount<4> {
3429
type BitMask = [u8; 1];
35-
type IntBitMask = u8;
3630
}
3731
impl SupportedLaneCount for LaneCount<8> {
3832
type BitMask = [u8; 1];
39-
type IntBitMask = u8;
4033
}
4134
impl SupportedLaneCount for LaneCount<16> {
4235
type BitMask = [u8; 2];
43-
type IntBitMask = u16;
4436
}
4537
impl SupportedLaneCount for LaneCount<32> {
4638
type BitMask = [u8; 4];
47-
type IntBitMask = u32;
4839
}

crates/core_simd/src/masks/bitmask.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ where
9797
#[inline]
9898
pub fn to_int(self) -> Simd<T, LANES> {
9999
unsafe {
100-
let mask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
101-
core::mem::transmute_copy(&self);
102100
crate::intrinsics::simd_select_bitmask(
103-
mask,
101+
self.0,
104102
Simd::splat(T::TRUE),
105103
Simd::splat(T::FALSE),
106104
)
@@ -109,14 +107,7 @@ where
109107

110108
#[inline]
111109
pub unsafe fn from_int_unchecked(value: Simd<T, LANES>) -> Self {
112-
// TODO remove the transmute when rustc is more flexible
113-
assert_eq!(
114-
core::mem::size_of::<<LaneCount::<LANES> as SupportedLaneCount>::BitMask>(),
115-
core::mem::size_of::<<LaneCount::<LANES> as SupportedLaneCount>::IntBitMask>(),
116-
);
117-
let mask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
118-
crate::intrinsics::simd_bitmask(value);
119-
Self(core::mem::transmute_copy(&mask), PhantomData)
110+
Self(crate::intrinsics::simd_bitmask(value), PhantomData)
120111
}
121112

122113
#[cfg(feature = "generic_const_exprs")]

crates/core_simd/src/masks/full_masks.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,8 @@ where
105105
#[inline]
106106
pub fn to_bitmask(self) -> [u8; LaneCount::<LANES>::BITMASK_LEN] {
107107
unsafe {
108-
// TODO remove the transmute when rustc can use arrays of u8 as bitmasks
109-
assert_eq!(
110-
core::mem::size_of::<<LaneCount::<LANES> as SupportedLaneCount>::IntBitMask>(),
111-
LaneCount::<LANES>::BITMASK_LEN,
112-
);
113-
let bitmask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
114-
crate::intrinsics::simd_bitmask(self.0);
115108
let mut bitmask: [u8; LaneCount::<LANES>::BITMASK_LEN] =
116-
core::mem::transmute_copy(&bitmask);
109+
crate::intrinsics::simd_bitmask(self.0);
117110

118111
// There is a bug where LLVM appears to implement this operation with the wrong
119112
// bit order.
@@ -141,14 +134,6 @@ where
141134
}
142135
}
143136

144-
// TODO remove the transmute when rustc can use arrays of u8 as bitmasks
145-
assert_eq!(
146-
core::mem::size_of::<<LaneCount::<LANES> as SupportedLaneCount>::IntBitMask>(),
147-
LaneCount::<LANES>::BITMASK_LEN,
148-
);
149-
let bitmask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
150-
core::mem::transmute_copy(&bitmask);
151-
152137
Self::from_int_unchecked(crate::intrinsics::simd_select_bitmask(
153138
bitmask,
154139
Self::splat(true).to_int(),

0 commit comments

Comments
 (0)