Skip to content

Commit

Permalink
hexagon: Clobber p0 and remove #[inline(never)]
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 6, 2024
1 parent 3d249c7 commit cd12f7b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
target: i686-unknown-linux-gnu
- rust: nightly
target: i686-unknown-linux-gnu
- rust: nightly-2023-08-24 # Rust 1.74, LLVM 17 (oldest version that MaybeUninit register is supported)
- rust: nightly-2024-11-29 # Rust 1.85, LLVM 19 (oldest version we can use asm_experimental_arch on this target)
target: hexagon-unknown-linux-musl
- rust: nightly
target: hexagon-unknown-linux-musl
Expand Down
13 changes: 11 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,21 @@ fn main() {
}
}
}
"avr" | "hexagon" | "m68k" | "mips" | "mips32r6" | "mips64" | "mips64r6" | "msp430"
| "powerpc" | "powerpc64" | "xtensa" => {
"avr" | "m68k" | "mips" | "mips32r6" | "mips64" | "mips64r6" | "msp430" | "powerpc"
| "powerpc64" | "xtensa" => {
if version.nightly && is_allowed_feature("asm_experimental_arch") {
println!("cargo:rustc-cfg=atomic_maybe_uninit_unstable_asm_experimental_arch");
}
}
"hexagon" => {
// https://github.com/rust-lang/rust/pull/133452 merged in Rust 1.85 (nightly-2024-11-29).
if version.nightly
&& version.probe(85, 2024, 11, 28)
&& is_allowed_feature("asm_experimental_arch")
{
println!("cargo:rustc-cfg=atomic_maybe_uninit_unstable_asm_experimental_arch");
}
}
"sparc" | "sparc64" => {
// https://github.com/rust-lang/rust/pull/132472 merged in Rust 1.84 (nightly-2024-11-08).
if version.nightly
Expand Down
30 changes: 18 additions & 12 deletions src/arch/hexagon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ macro_rules! atomic {
($ty:ident) => {
atomic_load_store!($ty, "w", "");
impl AtomicSwap for $ty {
#[inline(never)] // TODO: there is no way to mark p0 as clobbered
#[inline]
unsafe fn atomic_swap(
dst: *mut MaybeUninit<Self>,
val: MaybeUninit<Self>,
Expand All @@ -94,14 +94,15 @@ macro_rules! atomic {
dst = in(reg) dst,
val = in(reg) val,
out = out(reg) out,
options(nostack),
out("p0") _,
options(nostack, preserves_flags),
);
}
out
}
}
impl AtomicCompareExchange for $ty {
#[inline(never)] // TODO: there is no way to mark p0 as clobbered
#[inline]
unsafe fn atomic_compare_exchange(
dst: *mut MaybeUninit<Self>,
old: MaybeUninit<Self>,
Expand Down Expand Up @@ -131,7 +132,8 @@ macro_rules! atomic {
new = in(reg) new,
out = out(reg) out,
r = inout(reg) r,
options(nostack),
out("p0") _,
options(nostack, preserves_flags),
);
crate::utils::assert_unchecked(r == 0 || r == 1); // may help remove extra test
(out, r != 0)
Expand All @@ -145,7 +147,7 @@ macro_rules! atomic_sub_word {
($ty:ident, $size:tt) => {
atomic_load_store!($ty, $size, "u");
impl AtomicSwap for $ty {
#[inline(never)] // TODO: there is no way to mark p0 as clobbered
#[inline]
unsafe fn atomic_swap(
dst: *mut MaybeUninit<Self>,
val: MaybeUninit<Self>,
Expand Down Expand Up @@ -174,14 +176,15 @@ macro_rules! atomic_sub_word {
shift = in(reg) shift,
mask = in(reg) mask,
tmp = out(reg) _,
options(nostack),
out("p0") _,
options(nostack, preserves_flags),
);
}
out
}
}
impl AtomicCompareExchange for $ty {
#[inline(never)] // TODO: there is no way to mark p0 as clobbered
#[inline]
unsafe fn atomic_compare_exchange(
dst: *mut MaybeUninit<Self>,
old: MaybeUninit<Self>,
Expand Down Expand Up @@ -223,7 +226,8 @@ macro_rules! atomic_sub_word {
mask = in(reg) mask,
tmp = out(reg) _,
r = inout(reg) r,
options(nostack),
out("p0") _,
options(nostack, preserves_flags),
);
crate::utils::assert_unchecked(r == 0 || r == 1); // may help remove extra test
(out, r != 0)
Expand Down Expand Up @@ -289,7 +293,7 @@ macro_rules! atomic64 {
}
}
impl AtomicSwap for $ty {
#[inline(never)] // TODO: there is no way to mark p0 as clobbered
#[inline]
unsafe fn atomic_swap(
dst: *mut MaybeUninit<Self>,
val: MaybeUninit<Self>,
Expand All @@ -311,14 +315,15 @@ macro_rules! atomic64 {
in("r3") val.pair.hi,
out("r4") prev_lo,
out("r5") prev_hi,
options(nostack),
out("p0") _,
options(nostack, preserves_flags),
);
MaybeUninit64 { pair: Pair { lo: prev_lo, hi: prev_hi } }.$ty
}
}
}
impl AtomicCompareExchange for $ty {
#[inline(never)] // TODO: there is no way to mark p0 as clobbered
#[inline]
unsafe fn atomic_compare_exchange(
dst: *mut MaybeUninit<Self>,
old: MaybeUninit<Self>,
Expand Down Expand Up @@ -356,7 +361,8 @@ macro_rules! atomic64 {
in("r5") new.pair.hi,
out("r6") prev_lo,
out("r7") prev_hi,
options(nostack),
out("p0") _,
options(nostack, preserves_flags),
);
crate::utils::assert_unchecked(r == 0 || r == 1); // may help remove extra test
(MaybeUninit64 { pair: Pair { lo: prev_lo, hi: prev_hi } }.$ty, r != 0)
Expand Down

0 comments on commit cd12f7b

Please sign in to comment.