Skip to content

Commit 36e198b

Browse files
calebzulawskiworkingjubilee
authored andcommittedNov 13, 2021
Use new bitmask intrinsics with byte arrays
1 parent 1ce1c64 commit 36e198b

File tree

3 files changed

+9
-39
lines changed

3 files changed

+9
-39
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

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unused_imports)]
12
use super::MaskElement;
23
use crate::simd::intrinsics;
34
use crate::simd::{LaneCount, Simd, SupportedLaneCount};
@@ -101,24 +102,17 @@ where
101102
#[inline]
102103
pub fn to_int(self) -> Simd<T, LANES> {
103104
unsafe {
104-
let mask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
105-
core::mem::transmute_copy(&self);
106-
intrinsics::simd_select_bitmask(mask, Simd::splat(T::TRUE), Simd::splat(T::FALSE))
105+
crate::intrinsics::simd_select_bitmask(
106+
self.0,
107+
Simd::splat(T::TRUE),
108+
Simd::splat(T::FALSE),
109+
)
107110
}
108111
}
109112

110113
#[inline]
111114
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-
unsafe {
118-
let mask: <LaneCount<LANES> as SupportedLaneCount>::IntBitMask =
119-
intrinsics::simd_bitmask(value);
120-
Self(core::mem::transmute_copy(&mask), PhantomData)
121-
}
115+
unsafe { Self(crate::intrinsics::simd_bitmask(value), PhantomData) }
122116
}
123117

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

‎crates/core_simd/src/masks/full_masks.rs

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

119112
// There is a bug where LLVM appears to implement this operation with the wrong
120113
// bit order.
@@ -142,15 +135,7 @@ where
142135
}
143136
}
144137

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

0 commit comments

Comments
 (0)
Please sign in to comment.