-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hint::spin_loop invokes undefined behavior on targets without SSE2 #59237
Comments
The pause instruction requires SSE2 but was being unconditionally used on targets without it, resulting in undefined behavior. This PR fixes that by only using the pause intrinsic if SSE2 is available. It also 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. Closes rust-lang#59237 .
This is incorrect:
|
@Fanael indeed. Is there an advantage to emitting pause in earlier processors with respect to emitting nothing ? |
Not that I know, there is no advantage on any of Intel's old microarchitectures, they just interpret it as a nop and have no special way of handling spin loops. It might be different on AMD's K7 or VIA Nehemiah, but I don't have that hardware to test, and I doubt it makes any difference anyway. It lets you avoid an ugly compile time conditional and that's it I think. |
This bug report is invalid, thanks @Fanael . |
The pause instruction requires SSE2 but was being unconditionally used on targets without it, resulting in undefined behavior. This PR fixes that by only using the pause intrinsic if SSE2 is available. It also 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. Closes rust-lang#59237 .
Currently
hint::spin_loop
is implemented with thepause
instruction on all x86 / x86_64 targets, but this instruction is only available on CPUs with SSE2. The behavior ofpause
on CPUs without SSE2 is undefined.This hint should not be implemented with inline assembly, but should call the appropriate
core::arch
intrinsics instead. Those explicitly state which features are required for each operation on each target.The text was updated successfully, but these errors were encountered: