Merge pull request #345 from Sp00ph/from_to_slice

Use the new `load`/`store` functions in `{from,to}_slice`
This commit is contained in:
Caleb Zulawski 2023-05-07 08:16:26 -04:00 committed by GitHub
commit 50416fcc2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -263,11 +263,9 @@ where
slice.len() >= Self::N, slice.len() >= Self::N,
"slice length must be at least the number of elements" "slice length must be at least the number of elements"
); );
assert!(core::mem::size_of::<Self>() == Self::N * core::mem::size_of::<T>()); // SAFETY: We just checked that the slice contains
// Safety: // at least `N` elements.
// - We've checked the length is sufficient. unsafe { Self::load(slice.as_ptr().cast()) }
// - `T` and `Simd<T, N>` are Copy types.
unsafe { slice.as_ptr().cast::<Self>().read_unaligned() }
} }
/// Writes a SIMD vector to the first `N` elements of a slice. /// Writes a SIMD vector to the first `N` elements of a slice.
@ -293,11 +291,9 @@ where
slice.len() >= Self::N, slice.len() >= Self::N,
"slice length must be at least the number of elements" "slice length must be at least the number of elements"
); );
assert!(core::mem::size_of::<Self>() == Self::N * core::mem::size_of::<T>()); // SAFETY: We just checked that the slice contains
// Safety: // at least `N` elements.
// - We've checked the length is sufficient unsafe { self.store(slice.as_mut_ptr().cast()) }
// - `T` and `Simd<T, N>` are Copy types.
unsafe { slice.as_mut_ptr().cast::<Self>().write_unaligned(self) }
} }
/// Performs elementwise conversion of a SIMD vector's elements to another SIMD-valid type. /// Performs elementwise conversion of a SIMD vector's elements to another SIMD-valid type.