Skip to content

Commit

Permalink
Use atomic_load_unordered for first word load in misaligned case
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Aug 30, 2021
1 parent 2d28f4d commit ce86d41
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/mem/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ce86d41

Please sign in to comment.