Skip to content

Commit 6910d0f

Browse files
committed
Add thumb asm volatile writes
1 parent e55c95b commit 6910d0f

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

library/core/src/ptr/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ pub use non_null::NonNull;
425425
mod unique;
426426
#[unstable(feature = "ptr_internals", issue = "none")]
427427
pub use unique::Unique;
428-
429428
#[stable(feature = "volatile", since = "1.9.0")]
430429
pub use volatile::{read_volatile, write_volatile};
431430

library/core/src/ptr/volatile.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::{mem::SizedTypeProperties, cfg_match, intrinsics};
1+
use crate::mem::SizedTypeProperties;
2+
use crate::{cfg_match, intrinsics};
23

34
/// Performs a volatile read of the value from `src` without moving it. This
45
/// leaves the memory in `src` unchanged.
@@ -203,6 +204,33 @@ pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
203204
) => crate::ub_checks::maybe_is_aligned_and_not_null(addr, align, is_zst)
204205
);
205206
cfg_match! {
207+
all(target_arch = "arm", target_feature = "thumb-mode", target_pointer_width = "32") => {
208+
{
209+
use crate::arch::asm;
210+
use crate::mem::MaybeUninit;
211+
212+
match size_of::<T>() {
213+
1 =>
214+
asm!(
215+
"strb {val}, [{dest}]",
216+
val = in(reg) intrinsics::transmute_unchecked::<T, MaybeUninit<u8>>(src),
217+
dest = in(reg) dst
218+
),
219+
220+
2 => asm!(
221+
"strh {val}, [{dest}]",
222+
val = in(reg) intrinsics::transmute_unchecked::<T, MaybeUninit<u16>>(src),
223+
dest = in(reg) dst,
224+
),
225+
4 => asm!(
226+
"str {val}, [{dest}]",
227+
val = in(reg) intrinsics::transmute_unchecked::<T, MaybeUninit<u32>>(src),
228+
dest = in(reg) dst
229+
),
230+
_ => intrinsics::volatile_store(dst, src)
231+
}
232+
}
233+
}
206234
_ => {
207235
intrinsics::volatile_store(dst, src);
208236
}

0 commit comments

Comments
 (0)