Skip to content

SpinHint: use ISB on AArch64, like Rust's spin_loop - #9

Merged
eyalamirmusic merged 1 commit into
mainfrom
spinhint-arm64-isb
Dec 2, 2026
Merged

eyalamirmusic merged 1 commit into
mainfrom
spinhint-arm64-isb

Conversation

@eyalamirmusic

Copy link
Copy Markdown
Owner

Summary

On AArch64, EA::spinHint() now emits isb sy instead of yield, matching Rust's core::hint::spin_loop(). YIELD is a NOP on non-SMT AArch64 cores (Apple M-series, most Cortex-A/Neoverse), so spin loops didn't back off at all. ISB stalls briefly, the way x86 PAUSE does (OpenJDK's OnSpinWaitInst=isb and MySQL use it too).

x86/x64 (PAUSE) and 32-bit ARM (YIELD) are unchanged.

ARM64EC fix

MSVC defines _M_X64 under ARM64EC, so the old code took the x86 _mm_pause() branch. The AArch64 branch, which now includes _M_ARM64EC, is checked first.

Testing

Platform Compiler Tests Asm
macOS arm64 AppleClang 563/563
Linux aarch64 GCC 16 563/563 isb
Linux aarch64 Clang 23 563/563 isb
Windows x64 MSVC 564/564 pause
Windows x64 clang-cl 564/564 pause

Not verified: compiling with MSVC for ARM64 / ARM64EC (the Windows box has no ARM64 toolset).

YIELD is a NOP on non-SMT AArch64 cores (Apple M-series, most
Cortex-A/Neoverse), so spin loops did not back off at all. ISB stalls
briefly the way x86 PAUSE does; Rust's core::hint::spin_loop, OpenJDK
and MySQL use it for the same reason.

Check the AArch64 branch first and include _M_ARM64EC: MSVC also
defines _M_X64 under ARM64EC, so it previously took the _mm_pause path.

x86/x64 (PAUSE) and 32-bit ARM (YIELD) are unchanged.
@eyalamirmusic
eyalamirmusic merged commit 312c21a into main Dec 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant