Use atomic_load_unordered for first word load in misaligned case

This commit is contained in:
Gary Guo 2021-08-31 00:22:43 +01:00
parent 709bd6e11c
commit 1f0cbb2945

View file

@ -61,8 +61,8 @@ pub unsafe fn copy_forward(mut dest: *mut u8, mut src: *const u8, mut n: usize)
// Realign src
let mut src_aligned = (src as usize & !WORD_MASK) as *mut usize;
// XXX: Could this possibly be UB?
let mut prev_word = *src_aligned;
// This will read (but won't use) bytes out of bound.
let mut prev_word = core::intrinsics::atomic_load_unordered(src_aligned);
while dest_usize < dest_end {
src_aligned = src_aligned.add(1);
@ -154,8 +154,8 @@ pub unsafe fn copy_backward(dest: *mut u8, src: *const u8, mut n: usize) {
// Realign src_aligned
let mut src_aligned = (src as usize & !WORD_MASK) as *mut usize;
// XXX: Could this possibly be UB?
let mut prev_word = *src_aligned;
// This will read (but won't use) bytes out of bound.
let mut prev_word = core::intrinsics::atomic_load_unordered(src_aligned);
while dest_start < dest_usize {
src_aligned = src_aligned.sub(1);