Rollup merge of #101495 - bjorn3:pause-no-sse2, r=Mark-Simulacrum

Compile spin_loop_hint as pause on x86 even without sse2 enabled

The x86 `pause` instruction was introduced with sse2, but because it is encoded as `rep nop`, it works just fine on cpu's without sse2 support. It just doesn't do anything.
This commit is contained in:
Guillaume Gomez 2022-09-09 15:36:36 +02:00 committed by GitHub
commit 3ec332fc82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -160,19 +160,16 @@ pub const unsafe fn unreachable_unchecked() -> ! {
#[inline] #[inline]
#[stable(feature = "renamed_spin_loop", since = "1.49.0")] #[stable(feature = "renamed_spin_loop", since = "1.49.0")]
pub fn spin_loop() { pub fn spin_loop() {
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2"))] #[cfg(target_arch = "x86")]
{ {
#[cfg(target_arch = "x86")] // SAFETY: the `cfg` attr ensures that we only execute this on x86 targets.
{ unsafe { crate::arch::x86::_mm_pause() };
// SAFETY: the `cfg` attr ensures that we only execute this on x86 targets. }
unsafe { crate::arch::x86::_mm_pause() };
}
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
{ {
// SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets. // SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets.
unsafe { crate::arch::x86_64::_mm_pause() }; unsafe { crate::arch::x86_64::_mm_pause() };
}
} }
// RISC-V platform spin loop hint implementation // RISC-V platform spin loop hint implementation