riscv-non-isa / riscv-c-api-doc

Documentation of the RISC-V C API
https://jira.riscv.org/browse/RVG-4
Creative Commons Attribution 4.0 International
75 stars 41 forks source link

Inline Asm Constraints and Modifiers - RVC, Raw Encodings, Pairs #92

Open lenary opened 1 month ago

lenary commented 1 month ago

We have customers with usecases that want more kinds of register constraints and modifiers. This change proposes support for these constraints and modifiers, and their names.

Broadly, these are intended to make it easier for users who want to manually assemble instructions inside inline assembly blocks, either using the existing instruction formats, or using the raw form of the .insn directive. This makes it easier for hardware designers to experiment on new ISA extensions, and makes it easier to support the use of proprietary extensions with unmodified open-source toolchains.

There are three groups of additions here:


There's also a commit which fixes a header for the Assembly Constraints table.

lenary commented 1 month ago

I have an LLVM implementation of the c* constraints and the N modifier here https://github.com/llvm/llvm-project/pull/112561 which has been approved.

I am still working on the implementation of the Pr constraint.

lenary commented 1 month ago

There was a question on #39 about whether the paired constraint means "an even GPR", or a "even-odd GPR pair", as both would likely print exactly the same as the even subregister.

This matters for liveness analysis as, if Pr meant "an even GPR", the odd GPR in the pair might be allocated to a different input/output for the inline assembly block, which would conflict with the use of the even/odd value for a pair.

So, to be clear, Pr means "treat this as an even-odd GPR pair for liveness" and "print this as the even subregister", so if the compiler choses a0/a1, then a0 is printed, but a1 will also be defined/used by the inline assembly block.

lenary commented 1 month ago

I just opened https://github.com/llvm/llvm-project/pull/112983 which implements the Pr constraint.

lenary commented 3 weeks ago

Gentle Ping

Is there anything missing from the textual additions that is needed to clarify the proposal?

How are people feeling about this proposal?

kito-cheng commented 3 weeks ago

The proposal look good, let me make sure it's implementable on GCC side before we moving forward...:P

cmuellner commented 1 day ago

Kito just mentioned in the Toolchain SIG that he has a PoC implementation of this for LLVM and GCC.