Skip to content

Commit 467e5a1

Browse files
authored
[RISCV] Add Qualcomm uC Xqcisim (Simulation Hint) extension (llvm#128833)
This extension adds 10 instructions that provide hints to the interface simulation environment. The current spec can be found at: https://github.com/quic/riscv-unified-db/releases/ This patch adds assembler only support.
1 parent 4f7dc99 commit 467e5a1

File tree

11 files changed

+246
-3
lines changed

11 files changed

+246
-3
lines changed

clang/test/Driver/print-supported-extensions-riscv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
// CHECK-NEXT: xqcilia 0.2 'Xqcilia' (Qualcomm uC Large Immediate Arithmetic Extension)
208208
// CHECK-NEXT: xqcilo 0.2 'Xqcilo' (Qualcomm uC Large Offset Load Store Extension)
209209
// CHECK-NEXT: xqcilsm 0.2 'Xqcilsm' (Qualcomm uC Load Store Multiple Extension)
210+
// CHECK-NEXT: xqcisim 0.2 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
210211
// CHECK-NEXT: xqcisls 0.2 'Xqcisls' (Qualcomm uC Scaled Load Store Extension)
211212
// CHECK-NEXT: xrivosvisni 0.1 'XRivosVisni' (Rivos Vector Integer Small New)
212213
// CHECK-NEXT: xrivosvizip 0.1 'XRivosVizip' (Rivos Vector Register Zips)

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,9 @@ The current vendor extensions supported are:
471471
``experimental-Xqcilsm``
472472
LLVM implements `version 0.2 of the Qualcomm uC Load Store Multiple extension specification <https://github.com/quic/riscv-unified-db/releases/latest>`__ by Qualcomm. All instructions are prefixed with `qc.` as described in the specification. These instructions are only available for riscv32.
473473

474+
``experimental-Xqcisim``
475+
LLVM implements `version 0.2 of the Qualcomm uC Simulation Hint extension specification <https://github.com/quic/riscv-unified-db/releases/latest>`__ by Qualcomm. All instructions are prefixed with `qc.` as described in the specification. These instructions are only available for riscv32.
476+
474477
``experimental-Xqcisls``
475478
LLVM implements `version 0.2 of the Qualcomm uC Scaled Load Store extension specification <https://github.com/quic/riscv-unified-db/releases/latest>`__ by Qualcomm. All instructions are prefixed with `qc.` as described in the specification. These instructions are only available for riscv32.
476479

llvm/docs/ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ Changes to the RISC-V Backend
126126
'Xqccmp' extension, which is a frame-pointer convention compatible version of
127127
Zcmp.
128128
* Added non-quadratic ``log-vrgather`` cost model for ``vrgather.vv`` instruction
129+
* Adds experimental assembler support for the Qualcomm uC 'Xqcisim` (Simulation Hint)
130+
extension.
129131

130132
Changes to the WebAssembly Backend
131133
----------------------------------

llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,8 @@ static constexpr FeatureBitset XqciFeatureGroup = {
653653
RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
654654
RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqcili,
655655
RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
656-
RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisls,
656+
RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
657+
RISCV::FeatureVendorXqcisls,
657658
};
658659

659660
static constexpr FeatureBitset XSfVectorGroup = {

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,14 @@ def HasVendorXqccmp : Predicate<"Subtarget->hasVendorXqccmp()">,
14071407
AssemblerPredicate<(all_of FeatureVendorXqccmp),
14081408
"'Xqccmp' (Qualcomm 16-bit Push/Pop and Double Moves)">;
14091409

1410+
def FeatureVendorXqcisim
1411+
: RISCVExperimentalExtension<0, 2, "Qualcomm uC Simulation Hint Extension",
1412+
[FeatureStdExtZca]>;
1413+
def HasVendorXqcisim
1414+
: Predicate<"Subtarget->hasVendorXqcisim()">,
1415+
AssemblerPredicate<(all_of FeatureVendorXqcisim),
1416+
"'Xqcisim' (Qualcomm uC Simulation Hint Extension)">;
1417+
14101418
// Rivos Extension(s)
14111419

14121420
def FeatureVendorXRivosVisni

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ class QCIInt_IMM<bits<1> funct1, string opcodestr>
336336
let Inst{24-20} = imm10{9-5};
337337
}
338338

339+
class QCISim_NONE<bits<4> imm11_8, string opcodestr>
340+
: RVInstI<0b010, OPC_OP_IMM, (outs), (ins), opcodestr, ""> {
341+
let rs1 = 0;
342+
let rd = 0;
343+
let imm12 = {imm11_8, 0b00000000};
344+
}
345+
346+
class QCISim_RS1<bits<4> imm11_8, string opcodestr>
347+
: RVInstI<0b010, OPC_OP_IMM, (outs), (ins GPR:$rs1), opcodestr, "$rs1"> {
348+
let rd = 0;
349+
let imm12 = {imm11_8, 0b00000000};
350+
}
351+
339352
class QCIRVInstEIBase<bits<3> funct3, bits<2> funct2, dag outs,
340353
dag ins, string opcodestr, string argstr>
341354
: RVInst48<outs, ins, opcodestr, argstr, [], InstFormatOther> {
@@ -691,6 +704,41 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
691704
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
692705
} // Predicates = [HasVendorXqcilia, IsRV32]
693706

707+
let Predicates = [HasVendorXqcisim, IsRV32] in {
708+
let mayLoad = 0, mayStore = 0, hasSideEffects = 1 in {
709+
def QC_PSYSCALLI : RVInstI<0b010, OPC_OP_IMM, (outs), (ins uimm10:$imm10),
710+
"qc.psyscalli", "$imm10"> {
711+
bits<10> imm10;
712+
713+
let rs1 = 0;
714+
let rd = 0;
715+
let imm12 = {0b00, imm10};
716+
}
717+
718+
def QC_PPUTCI : RVInstI<0b010, OPC_OP_IMM, (outs), (ins uimm8:$imm8),
719+
"qc.pputci", "$imm8"> {
720+
bits<8> imm8;
721+
722+
let rs1 = 0;
723+
let rd = 0;
724+
let imm12 = {0b0100, imm8};
725+
}
726+
727+
def QC_PCOREDUMP : QCISim_NONE<0b0110, "qc.pcoredump">;
728+
def QC_PPREGS : QCISim_NONE<0b0111, "qc.ppregs">;
729+
def QC_PPREG : QCISim_RS1<0b1000, "qc.ppreg">;
730+
def QC_PPUTC : QCISim_RS1<0b1001, "qc.pputc">;
731+
def QC_PPUTS : QCISim_RS1<0b1010, "qc.pputs">;
732+
def QC_PEXIT : QCISim_RS1<0b1011, "qc.pexit">;
733+
def QC_PSYSCALL : QCISim_RS1<0b1100, "qc.psyscall">;
734+
735+
def QC_C_PTRACE : RVInst16CI<0b000, 0b10, (outs), (ins), "qc.c.ptrace", ""> {
736+
let rd = 0;
737+
let imm = 0;
738+
}
739+
} // mayLoad = 0, mayStore = 0, hasSideEffects = 1
740+
} // Predicates = [HasVendorXqcisim, IsRV32]
741+
694742
} // DecoderNamespace = "Xqci"
695743

696744
//===----------------------------------------------------------------------===//

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ Error RISCVISAInfo::checkDependency() {
746746
static constexpr StringLiteral XqciExts[] = {
747747
{"xqcia"}, {"xqciac"}, {"xqcibi"}, {"xqcibm"}, {"xqcicli"},
748748
{"xqcicm"}, {"xqcics"}, {"xqcicsr"}, {"xqciint"}, {"xqcili"},
749-
{"xqcilia"}, {"xqcilo"}, {"xqcilsm"}, {"xqcisls"}};
749+
{"xqcilia"}, {"xqcilo"}, {"xqcilsm"}, {"xqcisim"}, {"xqcisls"}};
750750
static constexpr StringLiteral ZcdOverlaps[] = {
751751
{"zcmt"}, {"zcmp"}, {"xqccmp"}, {"xqciac"}, {"xqcicm"}};
752752

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilia %s -o - | FileCheck --check-prefix=RV32XQCILIA %s
9696
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilo %s -o - | FileCheck --check-prefix=RV32XQCILO %s
9797
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilsm %s -o - | FileCheck --check-prefix=RV32XQCILSM %s
98+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcisim %s -o - | FileCheck --check-prefix=RV32XQCISIM %s
9899
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcisls %s -o - | FileCheck --check-prefix=RV32XQCISLS %s
99100
; RUN: llc -mtriple=riscv32 -mattr=+zaamo %s -o - | FileCheck --check-prefix=RV32ZAAMO %s
100101
; RUN: llc -mtriple=riscv32 -mattr=+zalrsc %s -o - | FileCheck --check-prefix=RV32ZALRSC %s
@@ -419,6 +420,7 @@
419420
; RV32XQCILIA: .attribute 5, "rv32i2p1_zca1p0_xqcilia0p2"
420421
; RV32XQCILO: .attribute 5, "rv32i2p1_zca1p0_xqcilo0p2"
421422
; RV32XQCILSM: .attribute 5, "rv32i2p1_xqcilsm0p2"
423+
; RV32XQCISIM: attribute 5, "rv32i2p1_zca1p0_xqcisim0p2"
422424
; RV32XQCISLS: .attribute 5, "rv32i2p1_xqcisls0p2"
423425
; RV32ZAAMO: .attribute 5, "rv32i2p1_zaamo1p0"
424426
; RV32ZALRSC: .attribute 5, "rv32i2p1_zalrsc1p0"

llvm/test/MC/RISCV/xqcisim-invalid.s

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Xqcisim - Simulaton Hint Instructions
2+
# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-xqcisim < %s 2>&1 \
3+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-PLUS %s
4+
# RUN: not llvm-mc -triple riscv32 -mattr=-experimental-xqcisim < %s 2>&1 \
5+
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-MINUS %s
6+
7+
# CHECK-PLUS: :[[@LINE+1]]:14: error: immediate must be an integer in the range [0, 1023]
8+
qc.psyscalli 1024
9+
10+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
11+
qc.psyscalli
12+
13+
# CHECK: :[[@LINE+1]]:18: error: invalid operand for instruction
14+
qc.psyscalli 23, x0
15+
16+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
17+
qc.psyscalli 1023
18+
19+
20+
# CHECK-PLUS: :[[@LINE+1]]:11: error: immediate must be an integer in the range [0, 255]
21+
qc.pputci 256
22+
23+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
24+
qc.pputci
25+
26+
# CHECK: :[[@LINE+1]]:16: error: invalid operand for instruction
27+
qc.pputci 200, x8
28+
29+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
30+
qc.pputci 255
31+
32+
33+
# CHECK: :[[@LINE+1]]:13: error: invalid operand for instruction
34+
qc.c.ptrace x0
35+
36+
# CHECK: :[[@LINE+1]]:13: error: invalid operand for instruction
37+
qc.c.ptrace 1
38+
39+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
40+
qc.c.ptrace
41+
42+
43+
# CHECK: :[[@LINE+1]]:14: error: invalid operand for instruction
44+
qc.pcoredump 12
45+
46+
# CHECK: :[[@LINE+1]]:14: error: invalid operand for instruction
47+
qc.pcoredump x4
48+
49+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
50+
qc.pcoredump
51+
52+
53+
# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
54+
qc.ppregs x1
55+
56+
# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
57+
qc.ppregs 23
58+
59+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
60+
qc.ppregs
61+
62+
63+
# CHECK: :[[@LINE+1]]:15: error: invalid operand for instruction
64+
qc.ppreg x10, x2
65+
66+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
67+
qc.ppreg
68+
69+
# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
70+
qc.ppreg 23
71+
72+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
73+
qc.ppreg a0
74+
75+
76+
# CHECK: :[[@LINE+1]]:14: error: invalid operand for instruction
77+
qc.pputc x7, x3
78+
79+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
80+
qc.pputc
81+
82+
# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
83+
qc.pputc 34
84+
85+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
86+
qc.pputc t2
87+
88+
89+
# CHECK: :[[@LINE+1]]:15: error: invalid operand for instruction
90+
qc.pputs x15, x18
91+
92+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
93+
qc.pputs
94+
95+
# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
96+
qc.pputs 45
97+
98+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
99+
qc.pputs a5
100+
101+
102+
# CHECK: :[[@LINE+1]]:15: error: invalid operand for instruction
103+
qc.pexit x26, x23
104+
105+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
106+
qc.pexit
107+
108+
# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
109+
qc.pexit 78
110+
111+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
112+
qc.pexit s10
113+
114+
115+
# CHECK: :[[@LINE+1]]:18: error: invalid operand for instruction
116+
qc.psyscall x11, x5
117+
118+
# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
119+
qc.psyscall
120+
121+
# CHECK: :[[@LINE+1]]:13: error: invalid operand for instruction
122+
qc.psyscall 98
123+
124+
# CHECK-MINUS: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcisim' (Qualcomm uC Simulation Hint Extension)
125+
qc.psyscall a1

llvm/test/MC/RISCV/xqcisim-valid.s

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Xqcisim - Simulation Hint Instructions
2+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcisim -riscv-no-aliases -show-encoding \
3+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
4+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcisim < %s \
5+
# RUN: | llvm-objdump --mattr=+experimental-xqcisim -M no-aliases --no-print-imm-hex -d - \
6+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
7+
# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-xqcisim -show-encoding \
8+
# RUN: | FileCheck -check-prefixes=CHECK-ENC,CHECK-INST %s
9+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-xqcisim < %s \
10+
# RUN: | llvm-objdump --mattr=+experimental-xqcisim --no-print-imm-hex -d - \
11+
# RUN: | FileCheck -check-prefix=CHECK-INST %s
12+
13+
14+
# CHECK-INST: qc.psyscalli 1023
15+
# CHECK-ENC: encoding: [0x13,0x20,0xf0,0x3f]
16+
qc.psyscalli 1023
17+
18+
# CHECK-INST: qc.pputci 255
19+
# CHECK-ENC: encoding: [0x13,0x20,0xf0,0x4f]
20+
qc.pputci 255
21+
22+
# CHECK-INST: qc.c.ptrace
23+
# CHECK-ENC: encoding: [0x02,0x00]
24+
qc.c.ptrace
25+
26+
# CHECK-INST: qc.pcoredump
27+
# CHECK-ENC: encoding: [0x13,0x20,0x00,0x60]
28+
qc.pcoredump
29+
30+
# CHECK-INST: qc.ppregs
31+
# CHECK-ENC: encoding: [0x13,0x20,0x00,0x70]
32+
qc.ppregs
33+
34+
# CHECK-INST: qc.ppreg a0
35+
# CHECK-ENC: encoding: [0x13,0x20,0x05,0x80]
36+
qc.ppreg x10
37+
38+
# CHECK-INST: qc.pputc t2
39+
# CHECK-ENC: encoding: [0x13,0xa0,0x03,0x90]
40+
qc.pputc x7
41+
42+
# CHECK-INST: qc.pputs a5
43+
# CHECK-ENC: encoding: [0x13,0xa0,0x07,0xa0]
44+
qc.pputs x15
45+
46+
# CHECK-INST: qc.pexit s10
47+
# CHECK-ENC: encoding: [0x13,0x20,0x0d,0xb0]
48+
qc.pexit x26
49+
50+
# CHECK-INST: qc.psyscall a1
51+
# CHECK-ENC: encoding: [0x13,0xa0,0x05,0xc0]
52+
qc.psyscall x11

llvm/unittests/TargetParser/RISCVISAInfoTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ TEST(ParseArchString, RejectsConflictingExtensions) {
658658
"rv64i_xqcicsr0p2", "rv64i_xqcilsm0p2", "rv64i_xqcicm0p2",
659659
"rv64i_xqcics0p2", "rv64i_xqcicli0p2", "rv64i_xqciint0p4",
660660
"rv64i_xqcilo0p2", "rv64i_xqcilia0p2", "rv64i_xqcibm0p4",
661-
"rv64i_xqcibi0p2", "rv64i_xqcili0p2"}) {
661+
"rv64i_xqcibi0p2", "rv64i_xqcili0p2", "rv64i_xqcisim0p2"}) {
662662
EXPECT_THAT(
663663
toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
664664
::testing::EndsWith(" is only supported for 'rv32'"));
@@ -1147,6 +1147,7 @@ Experimental extensions
11471147
xqcilia 0.2
11481148
xqcilo 0.2
11491149
xqcilsm 0.2
1150+
xqcisim 0.2
11501151
xqcisls 0.2
11511152
xrivosvisni 0.1
11521153
xrivosvizip 0.1

0 commit comments

Comments
 (0)