-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
asm! needs a better way of specifying clobbers #81092
Comments
The |
All three of these approaches seem useful. We may or may not need all of them before we can stabilize asm, though.
@bkolobara Do you specifically need Could we separate this into a few orthogonal items, and determine which ones block stabilization of |
There's also some considerations from LLVM to take into account based on how it handles clobbers:
|
@joshtriplett We specifically need |
Is
|
That's a bug, rustc should be passing If you want to submit a PR, the fix is fairly straightforward: you just need to do the same thing that is done for AArch64's rust/compiler/rustc_codegen_llvm/src/asm.rs Lines 487 to 490 in 21cbbdc
|
Thank you! It sounds like my problem is separate from this issue, so I opened a #82052. |
On a similar note, is
A similar error is produced if you attempt to mark |
No, that's intentional. LLVM will sometimes use |
Does that mean it is invalid for inline assembly to trigger a context switch to a userspace that will modify I have struggled to find any reference about when LLVM will modify/use |
It means that the programmer is responsible for saving and restoring |
Allow clobbering unsupported registers in asm! Previously registers could only be marked as clobbered if the target feature for that register was enabled. This restriction is now removed. cc rust-lang#81092 r? `@nagisa`
Allow clobbering unsupported registers in asm! Previously registers could only be marked as clobbered if the target feature for that register was enabled. This restriction is now removed. cc rust-lang#81092 r? ``@nagisa``
One significant issue that was discussed in Zulip is how wildcard clobbers should handle registers that are reserved by LLVM. |
I think the best way forward is to add a
|
Clobbered registers are currently represented as an output to
_
. However there are several limitations to this approach:The set of registers available for clobbering is limited by the currently enabled target features. For example, it is desirable to mark SSE registers as clobbered even if SSE instructions are disabled (e.g. for a kernel). Having to wrap everything inFixed by Allow clobbering unsupported registers in asm! #83841#[cfg(target_feature = "sse")]
is very inconvenient.k0
-k7
): if anasm!
block calls a Rust function, that function may write to the mask registers. However the mask registers may not have been clobbered if the author of theasm!
was not aware of AVX-512 when it was written.Some potential solutions include:
Adding a separateFixed by Allow clobbering unsupported registers in asm! #83841clobber("reg")
operand which is similar to the existing ones but doesn't require that the target feature for the register be enabled.clobber("all")
would clobber all registers known to the compiler. This would be incompatible with register class specifiers: you would need to explicitly specify registers for all input/output operands.clobber("C")
which clobbers all registers that would be clobbered by a call to anextern "C" fn
.It is not yet clear what the best solution is here. Discussion is welcome.
The text was updated successfully, but these errors were encountered: