Repository navigation
SpinHint: use ISB on AArch64, like Rust's spin_loop - #9
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On AArch64,
EA::spinHint()now emitsisb syinstead ofyield, matching Rust'score::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'sOnSpinWaitInst=isband MySQL use it too).x86/x64 (PAUSE) and 32-bit ARM (YIELD) are unchanged.
ARM64EC fix
MSVC defines
_M_X64under ARM64EC, so the old code took the x86_mm_pause()branch. The AArch64 branch, which now includes_M_ARM64EC, is checked first.Testing
isbisbpausepauseNot verified: compiling with MSVC for ARM64 / ARM64EC (the Windows box has no ARM64 toolset).