https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105048
Bug ID: 105048
Summary: [enhancement] Allow specific register constraints
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: inline-asm
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ehem+gccbugs at m5p dot com
Target Milestone: ---
Using local register variables to constrain assembly-language inputs and
outputs to particular registers is really ugly. Better to have explicit syntax
for this. I would suggesting using "R<register>" for this.
Using "R" conflicts with x86, but x86 effectively already has this since "a",
"b", "c", "d", "S", "D" covers most of the registers used for calling
conventions. I though also note Clang doesn't appear to have implemented "R"
which suggests this has rarely, if ever, been used. (another letter could be
used on x86, or it might be possible to repurpose)
This is particularly valuable for interfacing with systems using foreign
calling conventions.
The example is how one might interface with a hypervisor on ARM64. This seems
valuable as the register specification is a feature of the
inline-assembly-language, not a feature of the variable.
This could result in superior output, by avoiding copies. In particular
`hypercall_inline()` might well end up with 5 extra `mov` instructions (plus a
call and return) which are never optimized out, whereas `hypercall_macro()` is
rather likely to produce a single instruction.