From e0187f17dbcbf9dc026d379b2af8d866300596a5 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Wed, 24 Nov 2021 21:51:50 -0500 Subject: [PATCH 1/2] Do not use atomic reads on platforms without atomic support in LLVM. --- src/mem/impls.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mem/impls.rs b/src/mem/impls.rs index 65887a338..815132425 100644 --- a/src/mem/impls.rs +++ b/src/mem/impls.rs @@ -62,7 +62,12 @@ 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; // This will read (but won't use) bytes out of bound. + // cfg needed because not all targets will have atomic loads that can be lowered + // (e.g. BPF, MSP430), or provided by an external library (e.g. RV32I) + #[cfg(target_has_atomic_load_store = "ptr")] let mut prev_word = core::intrinsics::atomic_load_unordered(src_aligned); + #[cfg(not(target_has_atomic_load_store = "ptr"))] + let mut prev_word = core::ptr::read_volatile(src_aligned); while dest_usize < dest_end { src_aligned = src_aligned.add(1); @@ -155,7 +160,12 @@ 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; // This will read (but won't use) bytes out of bound. + // cfg needed because not all targets will have atomic loads that can be lowered + // (e.g. BPF, MSP430), or provided by an external library (e.g. RV32I) + #[cfg(target_has_atomic_load_store = "ptr")] let mut prev_word = core::intrinsics::atomic_load_unordered(src_aligned); + #[cfg(not(target_has_atomic_load_store = "ptr"))] + let mut prev_word = core::ptr::read_volatile(src_aligned); while dest_start < dest_usize { src_aligned = src_aligned.sub(1); From ba870b2568547470dab3a0dbf9fc8a19417cc069 Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Sat, 27 Nov 2021 19:38:43 -0500 Subject: [PATCH 2/2] Use fully-qualified syntax for abs_diff to avoid warning, which can trigger a compiler error. --- src/float/pow.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/float/pow.rs b/src/float/pow.rs index 5ab5e4201..a75340c30 100644 --- a/src/float/pow.rs +++ b/src/float/pow.rs @@ -5,7 +5,7 @@ use int::Int; fn pow(a: F, b: i32) -> F { let mut a = a; let recip = b < 0; - let mut pow = i32::abs_diff(b, 0); + let mut pow = Int::abs_diff(b, 0); let mut mul = F::ONE; loop { if (pow & 1) != 0 {