https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90181
Bug ID: 90181 Summary: Feature request: provide a way to explicitly select specific named registers in constraints Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: inline-asm Assignee: unassigned at gcc dot gnu.org Reporter: nfxjfg at googlemail dot com Target Milestone: --- Currently, inline assembler constraints have no way to select an explicitly named register. Apparently you're supposed to use register variables. There is even text that register variables exist only for this use case. For example, suppose you want to pass something through the register a7 on the RISC-V platform. You need to do: void call_ecall(size_t num) { register size_t r_a7 __asm("a7") = num; __asm volatile("ecall" : : "r" (r_a7) : "memory"); } This gets awkward fast. It adds a lot of extra noise if you have many registers to pass (the ecall instruction provides an example where this may be needed). The semantics are also not entirely clear: will r_a7 occupy the a7 register for the entire function (suppose there is more C code around it)? What if call_ecall gets inlined into a larger function? I think the intended (and actual) semantics are that it's effective only at the points where it's passed with register inline asm constraints. Why can't this just be: void call_ecall(size_t num) { __asm volatile("ecall" : : "a7" (num) : "memory"); } Some architectures do support this (like x86), but not all. If this is not possible, I'd be nice if the gcc developers could establish why not, and in particular why a new architecture/backend like RISC-V does not.