Skip to content

Commit 30e85c8

Browse files
committed
Generically implement ToBitMaskArray
1 parent 29087c6 commit 30e85c8

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

crates/core_simd/src/masks/to_bitmask.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,17 @@ pub const fn bitmask_len(lanes: usize) -> usize {
7979
(lanes + 7) / 8
8080
}
8181

82-
macro_rules! impl_array_bitmask {
83-
{ $(impl ToBitMaskArray<[u8; _]> for Mask<_, $lanes:literal>)* } => {
84-
$(
85-
unsafe impl<T: MaskElement> ToBitMaskArray for Mask<T, $lanes>
86-
{
87-
const BYTES: usize = bitmask_len($lanes);
88-
89-
fn to_bitmask_array(self) -> [u8; Self::BYTES] {
90-
self.0.to_bitmask_array()
91-
}
82+
unsafe impl<T: MaskElement, const LANES: usize> ToBitMaskArray for Mask<T, LANES>
83+
where
84+
LaneCount<LANES>: SupportedLaneCount,
85+
{
86+
const BYTES: usize = bitmask_len(LANES);
9287

93-
fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self {
94-
Mask(mask_impl::Mask::from_bitmask_array(bitmask))
95-
}
96-
}
97-
)*
88+
fn to_bitmask_array(self) -> [u8; Self::BYTES] {
89+
self.0.to_bitmask_array()
9890
}
99-
}
10091

101-
// FIXME this should be specified generically, but it doesn't seem to work with rustc, yet
102-
impl_array_bitmask! {
103-
impl ToBitMaskArray<[u8; _]> for Mask<_, 1>
104-
impl ToBitMaskArray<[u8; _]> for Mask<_, 2>
105-
impl ToBitMaskArray<[u8; _]> for Mask<_, 4>
106-
impl ToBitMaskArray<[u8; _]> for Mask<_, 8>
107-
impl ToBitMaskArray<[u8; _]> for Mask<_, 16>
108-
impl ToBitMaskArray<[u8; _]> for Mask<_, 32>
109-
impl ToBitMaskArray<[u8; _]> for Mask<_, 64>
92+
fn from_bitmask_array(bitmask: [u8; Self::BYTES]) -> Self {
93+
Mask(mask_impl::Mask::from_bitmask_array(bitmask))
94+
}
11095
}

0 commit comments

Comments
 (0)