Skip to content

Commit fc7a454

Browse files
committed
Removes alignment requirement in st3
1 parent 3fdc05a commit fc7a454

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

crates/core_arch/src/macros.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,10 @@ macro_rules! deinterleaving_load {
277277

278278
// NOTE: copy_nonoverlapping requires both pointers to be aligned to at least align_of::<$elem>(),
279279
// passing a pointer that is not sufficiently aligned is an UB.
280-
let arr: Arr = std::array::from_fn(|x| $crate::ptr::read_unaligned(($ptr as *const $elem).add(x)));
280+
let arr: Arr = $crate::ptr::read_unaligned($ptr as *const [$elem; { $lanes * 3 }]);
281281
// NOTE: repr(simd) adds padding to make the total size a power of two.
282-
// Hence writing W to ptr might write out of bounds.
282+
// Hence reading a W from ptr might read out of bounds.
283+
type W = Simd<$elem, { $lanes * 3 }>;
283284
let w: W = W::from_array(arr);
284285

285286
let v0: V = simd_shuffle!(w, w, deinterleave_mask::<$lanes, 3, 0>());
@@ -354,11 +355,7 @@ macro_rules! interleaving_store {
354355

355356
// NOTE: copy_nonoverlapping requires both pointers to be aligned to at least align_of::<$elem>(),
356357
// passing a pointer that is not sufficiently aligned is an UB.
357-
let mut i = 0;
358-
while i < $lanes * 3 {
359-
$crate::ptr::write_unaligned(($ptr as *mut $elem).add(i), arr[i]);
360-
i += 1;
361-
}
358+
$ptr.cast::<[$elem; { $lanes * 3 }]>().write_unaligned(arr);
362359
}};
363360

364361
// N = 4

0 commit comments

Comments
 (0)