Closed
Description
Clobbered registers are currently represented as an output to _
. However there are several limitations to this approach:
- It is impossible for registers that are not supported as inputs/outputs (e.g. x87 float registers, MMX registers, RISC-V vector registers, etc) to be marked as clobbered.
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.- Lack of forwards compatibility with new registers that could be introduced with future ISA extensions. Consider the AVX-512 mark registers (
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.- Adding some sort of wildcard clobber. For example
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. - Adding ABI-based clobbers such as
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.