Skip to content

Commit 9464fe5

Browse files
committed
Manually implement for supported lanes
1 parent be13985 commit 9464fe5

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

crates/core_simd/src/masks/full_masks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ where
114114
#[must_use = "method returns a new array and does not mutate the original value"]
115115
pub fn to_bitmask(self) -> [u8; super::bitmask_len(LANES)] {
116116
unsafe {
117-
let mut bitmask: [u8; super::bitmask_len(LANES)] =
118-
intrinsics::simd_bitmask(self.0);
117+
let mut bitmask: [u8; super::bitmask_len(LANES)] = intrinsics::simd_bitmask(self.0);
119118

120119
// There is a bug where LLVM appears to implement this operation with the wrong
121120
// bit order.

crates/core_simd/src/masks/to_bitmask.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,31 @@ pub const fn bitmask_len(lanes: usize) -> usize {
8585
}
8686

8787
#[cfg(feature = "generic_const_exprs")]
88-
impl<T: MaskElement, const LANES: usize> ToBitMask<[u8; bitmask_len(LANES)]> for Mask<T, LANES>
89-
where
90-
LaneCount<LANES>: SupportedLaneCount,
91-
{
92-
fn to_bitmask(self) -> [u8; bitmask_len(LANES)] {
93-
self.0.to_bitmask()
94-
}
88+
macro_rules! impl_array_bitmask {
89+
{ $(impl ToBitMask<[u8; _]> for Mask<_, $lanes:literal>)* } => {
90+
$(
91+
impl<T: MaskElement> ToBitMask<[u8; bitmask_len($lanes)]> for Mask<T, $lanes>
92+
{
93+
fn to_bitmask(self) -> [u8; bitmask_len($lanes)] {
94+
self.0.to_bitmask()
95+
}
9596

96-
fn from_bitmask(bitmask: [u8; bitmask_len(LANES)]) -> Self {
97-
Mask(mask_impl::Mask::from_bitmask(bitmask))
97+
fn from_bitmask(bitmask: [u8; bitmask_len($lanes)]) -> Self {
98+
Mask(mask_impl::Mask::from_bitmask(bitmask))
99+
}
100+
}
101+
)*
98102
}
99103
}
104+
105+
// FIXME this should be specified generically, but it doesn't seem to work with rustc, yet
106+
#[cfg(feature = "generic_const_exprs")]
107+
impl_array_bitmask! {
108+
impl ToBitMask<[u8; _]> for Mask<_, 1>
109+
impl ToBitMask<[u8; _]> for Mask<_, 2>
110+
impl ToBitMask<[u8; _]> for Mask<_, 4>
111+
impl ToBitMask<[u8; _]> for Mask<_, 8>
112+
impl ToBitMask<[u8; _]> for Mask<_, 16>
113+
impl ToBitMask<[u8; _]> for Mask<_, 32>
114+
impl ToBitMask<[u8; _]> for Mask<_, 64>
115+
}

crates/core_simd/tests/masks.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ macro_rules! test_mask_api {
8181
assert_eq!(core_simd::Mask::<$type, 16>::from_bitmask(bitmask), mask);
8282
}
8383

84-
/*
8584
#[cfg(feature = "generic_const_exprs")]
8685
#[test]
8786
fn roundtrip_bitmask_array_conversion() {
@@ -95,7 +94,6 @@ macro_rules! test_mask_api {
9594
assert_eq!(bitmask, [0b01001001, 0b10000011]);
9695
assert_eq!(core_simd::Mask::<$type, 16>::from_bitmask(bitmask), mask);
9796
}
98-
*/
9997
}
10098
}
10199
}

0 commit comments

Comments
 (0)