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