Skip to content

asm! needs a better way of specifying clobbers #81092

Closed
@Amanieu

Description

@Amanieu

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 in #[cfg(target_feature = "sse")] is very inconvenient. Fixed by Allow clobbering unsupported registers in asm! #83841
  • Lack of forwards compatibility with new registers that could be introduced with future ISA extensions. Consider the AVX-512 mark registers (k0-k7): if an asm! 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 the asm! was not aware of AVX-512 when it was written.

Some potential solutions include:

  • Adding a separate clobber("reg") operand which is similar to the existing ones but doesn't require that the target feature for the register be enabled. Fixed by Allow clobbering unsupported registers in asm! #83841
  • 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 an extern "C" fn.

It is not yet clear what the best solution is here. Discussion is welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-enhancementCategory: An issue proposing an enhancement or a PR with one.F-asm`#![feature(asm)]` (not `llvm_asm`)T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions