From f3208a6b86b3b84fd0dc9b8ba064b1bf547e7f8e Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Sat, 5 Feb 2022 08:02:00 +0000 Subject: [PATCH 1/2] Removed need for generic_const_expr in bitmask --- crates/core_simd/src/masks.rs | 6 ++---- crates/core_simd/src/masks/bitmask.rs | 6 ++---- crates/core_simd/src/masks/full_masks.rs | 8 +++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/crates/core_simd/src/masks.rs b/crates/core_simd/src/masks.rs index ae1fef53da8..f0f631287c1 100644 --- a/crates/core_simd/src/masks.rs +++ b/crates/core_simd/src/masks.rs @@ -217,18 +217,16 @@ where } /// Convert this mask to a bitmask, with one bit set per lane. - #[cfg(feature = "generic_const_exprs")] #[inline] #[must_use = "method returns a new array and does not mutate the original value"] - pub fn to_bitmask(self) -> [u8; LaneCount::::BITMASK_LEN] { + pub fn to_bitmask(self) -> as SupportedLaneCount>::BitMask { self.0.to_bitmask() } /// Convert a bitmask to a mask. - #[cfg(feature = "generic_const_exprs")] #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] - pub fn from_bitmask(bitmask: [u8; LaneCount::::BITMASK_LEN]) -> Self { + pub fn from_bitmask(bitmask: as SupportedLaneCount>::BitMask) -> Self { Self(mask_impl::Mask::from_bitmask(bitmask)) } diff --git a/crates/core_simd/src/masks/bitmask.rs b/crates/core_simd/src/masks/bitmask.rs index b4217dc87ba..8a5c905d0d2 100644 --- a/crates/core_simd/src/masks/bitmask.rs +++ b/crates/core_simd/src/masks/bitmask.rs @@ -115,18 +115,16 @@ where unsafe { Self(intrinsics::simd_bitmask(value), PhantomData) } } - #[cfg(feature = "generic_const_exprs")] #[inline] #[must_use = "method returns a new array and does not mutate the original value"] - pub fn to_bitmask(self) -> [u8; LaneCount::::BITMASK_LEN] { + pub fn to_bitmask(self) -> as SupportedLaneCount>::BitMask { // Safety: these are the same type and we are laundering the generic unsafe { core::mem::transmute_copy(&self.0) } } - #[cfg(feature = "generic_const_exprs")] #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] - pub fn from_bitmask(bitmask: [u8; LaneCount::::BITMASK_LEN]) -> Self { + pub fn from_bitmask(bitmask: as SupportedLaneCount>::BitMask) -> Self { // Safety: these are the same type and we are laundering the generic Self(unsafe { core::mem::transmute_copy(&bitmask) }, PhantomData) } diff --git a/crates/core_simd/src/masks/full_masks.rs b/crates/core_simd/src/masks/full_masks.rs index e5bb784bb91..6298b87985f 100644 --- a/crates/core_simd/src/masks/full_masks.rs +++ b/crates/core_simd/src/masks/full_masks.rs @@ -109,12 +109,11 @@ where unsafe { Mask(intrinsics::simd_cast(self.0)) } } - #[cfg(feature = "generic_const_exprs")] #[inline] #[must_use = "method returns a new array and does not mutate the original value"] - pub fn to_bitmask(self) -> [u8; LaneCount::::BITMASK_LEN] { + pub fn to_bitmask(self) -> as SupportedLaneCount>::BitMask { unsafe { - let mut bitmask: [u8; LaneCount::::BITMASK_LEN] = + let mut bitmask: as SupportedLaneCount>::BitMask = intrinsics::simd_bitmask(self.0); // There is a bug where LLVM appears to implement this operation with the wrong @@ -130,10 +129,9 @@ where } } - #[cfg(feature = "generic_const_exprs")] #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] - pub fn from_bitmask(mut bitmask: [u8; LaneCount::::BITMASK_LEN]) -> Self { + pub fn from_bitmask(mut bitmask: as SupportedLaneCount>::BitMask) -> Self { unsafe { // There is a bug where LLVM appears to implement this operation with the wrong // bit order. From bb3ee2bc61b33cfb309e668e1bc8887504d1a000 Mon Sep 17 00:00:00 2001 From: "Jorge C. Leitao" Date: Sat, 5 Feb 2022 23:20:32 +0000 Subject: [PATCH 2/2] Activated test for bitmask --- crates/core_simd/tests/masks.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/core_simd/tests/masks.rs b/crates/core_simd/tests/masks.rs index 6a8ecd33a73..ebafb191b9a 100644 --- a/crates/core_simd/tests/masks.rs +++ b/crates/core_simd/tests/masks.rs @@ -68,7 +68,6 @@ macro_rules! test_mask_api { assert_eq!(core_simd::Mask::<$type, 8>::from_int(int), mask); } - #[cfg(feature = "generic_const_exprs")] #[test] fn roundtrip_bitmask_conversion() { let values = [