Skip to content

Commit d8b3821

Browse files
authored
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.
1 parent 3c72788 commit d8b3821

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

library/core/src/hint.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,16 @@ pub const unsafe fn unreachable_unchecked() -> ! {
160160
#[inline]
161161
#[stable(feature = "renamed_spin_loop", since = "1.49.0")]
162162
pub fn spin_loop() {
163-
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), target_feature = "sse2"))]
163+
#[cfg(target_arch = "x86")]
164164
{
165-
#[cfg(target_arch = "x86")]
166-
{
167-
// SAFETY: the `cfg` attr ensures that we only execute this on x86 targets.
168-
unsafe { crate::arch::x86::_mm_pause() };
169-
}
165+
// SAFETY: the `cfg` attr ensures that we only execute this on x86 targets.
166+
unsafe { crate::arch::x86::_mm_pause() };
167+
}
170168

171-
#[cfg(target_arch = "x86_64")]
172-
{
173-
// SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets.
174-
unsafe { crate::arch::x86_64::_mm_pause() };
175-
}
169+
#[cfg(target_arch = "x86_64")]
170+
{
171+
// SAFETY: the `cfg` attr ensures that we only execute this on x86_64 targets.
172+
unsafe { crate::arch::x86_64::_mm_pause() };
176173
}
177174

178175
// RISC-V platform spin loop hint implementation

0 commit comments

Comments
 (0)