Skip to content

Commit 50416fc

Browse files
Merge pull request #345 from Sp00ph/from_to_slice
Use the new `load`/`store` functions in `{from,to}_slice`
2 parents 45413e4 + 4967f25 commit 50416fc

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

crates/core_simd/src/vector.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,9 @@ where
263263
slice.len() >= Self::N,
264264
"slice length must be at least the number of elements"
265265
);
266-
assert!(core::mem::size_of::<Self>() == Self::N * core::mem::size_of::<T>());
267-
// Safety:
268-
// - We've checked the length is sufficient.
269-
// - `T` and `Simd<T, N>` are Copy types.
270-
unsafe { slice.as_ptr().cast::<Self>().read_unaligned() }
266+
// SAFETY: We just checked that the slice contains
267+
// at least `N` elements.
268+
unsafe { Self::load(slice.as_ptr().cast()) }
271269
}
272270

273271
/// Writes a SIMD vector to the first `N` elements of a slice.
@@ -293,11 +291,9 @@ where
293291
slice.len() >= Self::N,
294292
"slice length must be at least the number of elements"
295293
);
296-
assert!(core::mem::size_of::<Self>() == Self::N * core::mem::size_of::<T>());
297-
// Safety:
298-
// - We've checked the length is sufficient
299-
// - `T` and `Simd<T, N>` are Copy types.
300-
unsafe { slice.as_mut_ptr().cast::<Self>().write_unaligned(self) }
294+
// SAFETY: We just checked that the slice contains
295+
// at least `N` elements.
296+
unsafe { self.store(slice.as_mut_ptr().cast()) }
301297
}
302298

303299
/// Performs elementwise conversion of a SIMD vector's elements to another SIMD-valid type.

0 commit comments

Comments
 (0)