Skip to content

Commit c9eb473

Browse files
committed
RISC-V: Add new operand constraint: cR
This commit introduces a new operand constraint `cR` for the RISC-V architecture, which allows the use of an even-odd RVC general purpose register (x8-x15) in inline asm. Ref: riscv-non-isa/riscv-c-api-doc#102 gcc/ChangeLog: * config/riscv/constraints.md (cR): New constraint. * doc/md.texi (Machine Constraints::RISC-V): Document the new cR constraint. gcc/testsuite/ChangeLog: * gcc.target/riscv/constraint-cR-pair.c: New test case.
1 parent 3fc902e commit c9eb473

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

gcc/config/riscv/constraints.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
(define_register_constraint "cf" "TARGET_HARD_FLOAT ? RVC_FP_REGS : (TARGET_ZFINX ? RVC_GR_REGS : NO_REGS)"
4444
"RVC floating-point registers (f8-f15), if available, reuse GPR as FPR when use zfinx.")
4545

46+
(define_register_constraint "cR" "RVC_GR_REGS"
47+
"Even-odd RVC general purpose register (x8-x15)."
48+
"regno % 2 == 0")
49+
4650
;; General constraints
4751

4852
(define_constraint "I"

gcc/doc/md.texi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,9 @@ RVC general purpose register (x8-x15).
36943694
RVC floating-point registers (f8-f15), if available, reuse GPR as FPR when use
36953695
zfinx.
36963696

3697+
@item cR
3698+
Even-odd RVC general purpose register pair.
3699+
36973700
@item R
36983701
Even-odd general purpose register pair.
36993702

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* { dg-do compile } */
2+
/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */
3+
/* { dg-final { check-function-bodies "**" "" } } */
4+
5+
void foo(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int m0, int m1) {
6+
/*
7+
** foo:
8+
** ...
9+
** addi\s*t0,\s*(a[024]|s0),\s*(a[024]|s0)
10+
** ...
11+
*/
12+
__asm__ volatile("addi t0, %0, %0" : : "cR" (m0) : "memory");
13+
}

0 commit comments

Comments
 (0)