Skip to content

Commit f504a3a

Browse files
Merge branch 'master' into attrs
2 parents 390f468 + 8527625 commit f504a3a

File tree

3 files changed

+23
-25
lines changed

3 files changed

+23
-25
lines changed

crates/core_simd/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![no_std]
22
#![feature(
3-
const_ptr_read,
43
const_refs_to_cell,
54
const_maybe_uninit_as_mut_ptr,
65
const_mut_refs,

crates/core_simd/src/swizzle_dyn.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ where
4343
32 => transize(x86::_mm256_permutexvar_epi8, self, idxs),
4444
// Notable absence: avx512bw shuffle
4545
// If avx512bw is available, odds of avx512vbmi are good
46-
#[cfg(target_feature = "avx512vbmi")]
47-
64 => transize(x86::_mm512_permutexvar_epi8, self, idxs),
46+
// FIXME: initial AVX512VBMI variant didn't actually pass muster
47+
// #[cfg(target_feature = "avx512vbmi")]
48+
// 64 => transize(x86::_mm512_permutexvar_epi8, self, idxs),
4849
_ => {
4950
let mut array = [0; N];
5051
for (i, k) in idxs.to_array().into_iter().enumerate() {
@@ -67,6 +68,7 @@ where
6768
#[target_feature(enable = "avx2")]
6869
#[allow(unused)]
6970
#[inline]
71+
#[allow(clippy::let_and_return)]
7072
unsafe fn avx2_pshufb(bytes: Simd<u8, 32>, idxs: Simd<u8, 32>) -> Simd<u8, 32> {
7173
use crate::simd::SimdPartialOrd;
7274
#[cfg(target_arch = "x86")]

crates/core_simd/src/vector.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::simd::{
22
intrinsics, LaneCount, Mask, MaskElement, SimdCast, SimdCastPtr, SimdConstPtr, SimdMutPtr,
33
SimdPartialOrd, SupportedLaneCount, Swizzle,
44
};
5+
use core::convert::{TryFrom, TryInto};
56

67
/// A SIMD vector with the shape of `[T; N]` but the operations of `T`.
78
///
@@ -109,7 +110,7 @@ where
109110
T: SimdElement,
110111
{
111112
/// Number of elements in this vector.
112-
pub const N: usize = N;
113+
pub const LANES: usize = N;
113114

114115
/// Returns the number of elements in this SIMD vector.
115116
///
@@ -123,7 +124,7 @@ where
123124
/// ```
124125
#[inline]
125126
pub const fn lanes(&self) -> usize {
126-
Self::N
127+
Self::LANES
127128
}
128129

129130
/// Constructs a new SIMD vector with all elements set to the given value.
@@ -159,9 +160,9 @@ where
159160
/// ```
160161
#[inline]
161162
pub const fn as_array(&self) -> &[T; N] {
162-
// SAFETY: Transmuting between `Simd<T, N>` and `[T; N]`
163-
// is always valid and `Simd<T, N>` never has a lower alignment
164-
// than `[T; N]`.
163+
// SAFETY: `Simd<T, N>` is just an overaligned `[T; N]` with
164+
// potential padding at the end, so pointer casting to a
165+
// `&[T; N]` is safe.
165166
//
166167
// NOTE: This deliberately doesn't just use `&self.0`, see the comment
167168
// on the struct definition for details.
@@ -171,9 +172,9 @@ where
171172
/// Returns a mutable array reference containing the entire SIMD vector.
172173
#[inline]
173174
pub fn as_mut_array(&mut self) -> &mut [T; N] {
174-
// SAFETY: Transmuting between `Simd<T, N>` and `[T; N]`
175-
// is always valid and `Simd<T, N>` never has a lower alignment
176-
// than `[T; N]`.
175+
// SAFETY: `Simd<T, N>` is just an overaligned `[T; N]` with
176+
// potential padding at the end, so pointer casting to a
177+
// `&mut [T; N]` is safe.
177178
//
178179
// NOTE: This deliberately doesn't just use `&mut self.0`, see the comment
179180
// on the struct definition for details.
@@ -269,14 +270,12 @@ where
269270
#[track_caller]
270271
pub const fn from_slice(slice: &[T]) -> Self {
271272
assert!(
272-
slice.len() >= Self::N,
273+
slice.len() >= Self::LANES,
273274
"slice length must be at least the number of elements"
274275
);
275-
assert!(core::mem::size_of::<Self>() == Self::N * core::mem::size_of::<T>());
276-
// Safety:
277-
// - We've checked the length is sufficient.
278-
// - `T` and `Simd<T, N>` are Copy types.
279-
unsafe { slice.as_ptr().cast::<Self>().read_unaligned() }
276+
// SAFETY: We just checked that the slice contains
277+
// at least `N` elements.
278+
unsafe { Self::load(slice.as_ptr().cast()) }
280279
}
281280

282281
/// Writes a SIMD vector to the first `N` elements of a slice.
@@ -301,14 +300,12 @@ where
301300
#[track_caller]
302301
pub fn copy_to_slice(self, slice: &mut [T]) {
303302
assert!(
304-
slice.len() >= Self::N,
303+
slice.len() >= Self::LANES,
305304
"slice length must be at least the number of elements"
306305
);
307-
assert!(core::mem::size_of::<Self>() == Self::N * core::mem::size_of::<T>());
308-
// Safety:
309-
// - We've checked the length is sufficient
310-
// - `T` and `Simd<T, N>` are Copy types.
311-
unsafe { slice.as_mut_ptr().cast::<Self>().write_unaligned(self) }
306+
// SAFETY: We just checked that the slice contains
307+
// at least `N` elements.
308+
unsafe { self.store(slice.as_mut_ptr().cast()) }
312309
}
313310

314311
/// Performs elementwise conversion of a SIMD vector's elements to another SIMD-valid type.
@@ -902,7 +899,7 @@ where
902899
type Error = core::array::TryFromSliceError;
903900

904901
#[inline]
905-
fn try_from(slice: &[T]) -> Result<Self, Self::Error> {
902+
fn try_from(slice: &[T]) -> Result<Self, core::array::TryFromSliceError> {
906903
Ok(Self::from_array(slice.try_into()?))
907904
}
908905
}
@@ -915,7 +912,7 @@ where
915912
type Error = core::array::TryFromSliceError;
916913

917914
#[inline]
918-
fn try_from(slice: &mut [T]) -> Result<Self, Self::Error> {
915+
fn try_from(slice: &mut [T]) -> Result<Self, core::array::TryFromSliceError> {
919916
Ok(Self::from_array(slice.try_into()?))
920917
}
921918
}

0 commit comments

Comments
 (0)