Skip to content

Commit

Permalink
Rollup merge of rust-lang#59239 - gnzlbg:fix_spin_loop, r=nagisa
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mark-Simulacrum authored Mar 23, 2019
2 parents 7ec44cb + 830c98d commit d1344b3
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/libcore/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,32 @@ pub unsafe fn unreachable_unchecked() -> ! {
#[inline]
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
pub fn spin_loop() {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
unsafe {
asm!("pause" ::: "memory" : "volatile");
#[cfg(
all(
any(target_arch = "x86", target_arch = "x86_64"),
target_feature = "sse2"
)
)] {
#[cfg(target_arch = "x86")] {
unsafe { crate::arch::x86::_mm_pause() };
}

#[cfg(target_arch = "x86_64")] {
unsafe { crate::arch::x86_64::_mm_pause() };
}
}

#[cfg(target_arch = "aarch64")]
unsafe {
asm!("yield" ::: "memory" : "volatile");
#[cfg(
any(
target_arch = "aarch64",
all(target_arch = "arm", target_feature = "v6")
)
)] {
#[cfg(target_arch = "aarch64")] {
unsafe { crate::arch::aarch64::__yield() };
}
#[cfg(target_arch = "arm")] {
unsafe { crate::arch::arm::__yield() };
}
}
}

0 comments on commit d1344b3

Please sign in to comment.