diff --git a/crates/core_simd/src/masks.rs b/crates/core_simd/src/masks.rs index 5c0ae303162d..637313424239 100644 --- a/crates/core_simd/src/masks.rs +++ b/crates/core_simd/src/masks.rs @@ -286,7 +286,7 @@ where /// The remaining bits are unset. #[inline] #[must_use = "method returns a new integer and does not mutate the original value"] - pub fn to_bitmask_vector(self) -> Simd { + pub fn to_bitmask_vector(self) -> Simd { self.0.to_bitmask_vector() } @@ -295,7 +295,7 @@ where /// For each bit, if it is set, the corresponding element in the mask is set to `true`. #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] - pub fn from_bitmask_vector(bitmask: Simd) -> Self { + pub fn from_bitmask_vector(bitmask: Simd) -> Self { Self(mask_impl::Mask::from_bitmask_vector(bitmask)) } } diff --git a/crates/core_simd/src/masks/bitmask.rs b/crates/core_simd/src/masks/bitmask.rs index 21d9e49a1b57..6ddff07fea25 100644 --- a/crates/core_simd/src/masks/bitmask.rs +++ b/crates/core_simd/src/masks/bitmask.rs @@ -121,45 +121,18 @@ where #[inline] #[must_use = "method returns a new vector and does not mutate the original value"] - pub fn to_bitmask_vector(self) -> Simd { - let mut bitmask = Self::splat(false).to_int(); - - assert!( - core::mem::size_of::>() - >= core::mem::size_of::< as SupportedLaneCount>::BitMask>() - ); - - // Safety: the bitmask vector is big enough to hold the bitmask - unsafe { - core::ptr::copy_nonoverlapping( - self.0.as_ref().as_ptr(), - bitmask.as_mut_array().as_mut_ptr() as _, - self.0.as_ref().len(), - ); - } - + pub fn to_bitmask_vector(self) -> Simd { + let mut bitmask = Simd::splat(0); + bitmask.as_mut_array()[..self.0.as_ref().len()].copy_from_slice(self.0.as_ref()); bitmask } #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] - pub fn from_bitmask_vector(bitmask: Simd) -> Self { + pub fn from_bitmask_vector(bitmask: Simd) -> Self { let mut bytes = as SupportedLaneCount>::BitMask::default(); - - assert!( - core::mem::size_of::>() - >= core::mem::size_of::< as SupportedLaneCount>::BitMask>() - ); - - // Safety: the bitmask vector is big enough to hold the bitmask - unsafe { - core::ptr::copy_nonoverlapping( - bitmask.as_array().as_ptr() as _, - bytes.as_mut().as_mut_ptr(), - bytes.as_ref().len(), - ); - } - + let len = bytes.as_ref().len(); + bytes.as_mut().copy_from_slice(&bitmask.as_array()[..len]); Self(bytes, PhantomData) } diff --git a/crates/core_simd/src/masks/full_masks.rs b/crates/core_simd/src/masks/full_masks.rs index a529490f3a21..0d17e90c1289 100644 --- a/crates/core_simd/src/masks/full_masks.rs +++ b/crates/core_simd/src/masks/full_masks.rs @@ -143,8 +143,8 @@ where #[inline] #[must_use = "method returns a new vector and does not mutate the original value"] - pub fn to_bitmask_vector(self) -> Simd { - let mut bitmask = Self::splat(false).to_int(); + pub fn to_bitmask_vector(self) -> Simd { + let mut bitmask = Simd::splat(0); // Safety: Bytes is the right size array unsafe { @@ -159,15 +159,7 @@ where } } - assert!( - core::mem::size_of::>() - >= core::mem::size_of::< as SupportedLaneCount>::BitMask>() - ); - core::ptr::copy_nonoverlapping( - bytes.as_ref().as_ptr(), - bitmask.as_mut_array().as_mut_ptr() as _, - bytes.as_ref().len(), - ); + bitmask.as_mut_array()[..bytes.as_ref().len()].copy_from_slice(bytes.as_ref()); } bitmask @@ -175,20 +167,13 @@ where #[inline] #[must_use = "method returns a new mask and does not mutate the original value"] - pub fn from_bitmask_vector(bitmask: Simd) -> Self { + pub fn from_bitmask_vector(bitmask: Simd) -> Self { let mut bytes = as SupportedLaneCount>::BitMask::default(); // Safety: Bytes is the right size array unsafe { - assert!( - core::mem::size_of::>() - >= core::mem::size_of::< as SupportedLaneCount>::BitMask>() - ); - core::ptr::copy_nonoverlapping( - bitmask.as_array().as_ptr() as _, - bytes.as_mut().as_mut_ptr(), - bytes.as_mut().len(), - ); + let len = bytes.as_ref().len(); + bytes.as_mut().copy_from_slice(&bitmask.as_array()[..len]); // LLVM assumes bit order should match endianness if cfg!(target_endian = "big") {