Skip to content

Commit 8f170fe

Browse files
Rollup merge of rust-lang#59239 - gnzlbg:fix_spin_loop, r=nagisa
Remove inline assembly from hint::spin_loop This PR removes the inline assembly which was not required since these instructions are available in core::arch, and extends support of the spin_loop hint to arm targets with the v6 feature which also support the yield instruction.
2 parents c9f6316 + 830c98d commit 8f170fe

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/libcore/hint.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,32 @@ pub unsafe fn unreachable_unchecked() -> ! {
6262
#[inline]
6363
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
6464
pub fn spin_loop() {
65-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
66-
unsafe {
67-
asm!("pause" ::: "memory" : "volatile");
65+
#[cfg(
66+
all(
67+
any(target_arch = "x86", target_arch = "x86_64"),
68+
target_feature = "sse2"
69+
)
70+
)] {
71+
#[cfg(target_arch = "x86")] {
72+
unsafe { crate::arch::x86::_mm_pause() };
73+
}
74+
75+
#[cfg(target_arch = "x86_64")] {
76+
unsafe { crate::arch::x86_64::_mm_pause() };
77+
}
6878
}
6979

70-
#[cfg(target_arch = "aarch64")]
71-
unsafe {
72-
asm!("yield" ::: "memory" : "volatile");
80+
#[cfg(
81+
any(
82+
target_arch = "aarch64",
83+
all(target_arch = "arm", target_feature = "v6")
84+
)
85+
)] {
86+
#[cfg(target_arch = "aarch64")] {
87+
unsafe { crate::arch::aarch64::__yield() };
88+
}
89+
#[cfg(target_arch = "arm")] {
90+
unsafe { crate::arch::arm::__yield() };
91+
}
7392
}
7493
}

0 commit comments

Comments
 (0)