Skip to content

Commit 171d3ed

Browse files
hchandelHarsh Chandel
andauthored
[RISCV] Add Qualcomm uC Xqciint (Interrupts) extension (#122256)
This extension adds eleven instructions to accelerate interrupt servicing. The current spec can be found at: https://github.com/quic/riscv-unified-db/releases/latest This patch adds assembler only support. --------- Co-authored-by: Harsh Chandel <[email protected]>
1 parent d7e7966 commit 171d3ed

File tree

14 files changed

+279
-3
lines changed

14 files changed

+279
-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
@@ -196,6 +196,7 @@
196196
// CHECK-NEXT: xqcicm 0.2 'Xqcicm' (Qualcomm uC Conditional Move Extension)
197197
// CHECK-NEXT: xqcics 0.2 'Xqcics' (Qualcomm uC Conditional Select Extension)
198198
// CHECK-NEXT: xqcicsr 0.2 'Xqcicsr' (Qualcomm uC CSR Extension)
199+
// CHECK-NEXT: xqciint 0.2 'Xqciint' (Qualcomm uC Interrupts Extension)
199200
// CHECK-NEXT: xqcilsm 0.2 'Xqcilsm' (Qualcomm uC Load Store Multiple Extension)
200201
// CHECK-NEXT: xqcisls 0.2 'Xqcisls' (Qualcomm uC Scaled Load Store Extension)
201202
// CHECK-EMPTY:

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ The current vendor extensions supported are:
447447
``experimental-Xqcicsr``
448448
LLVM implements `version 0.2 of the Qualcomm uC CSR 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.
449449

450+
``experimental-Xqciint``
451+
LLVM implements `version 0.2 of the Qualcomm uC Interrupts 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.
452+
450453
``experimental-Xqcilsm``
451454
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.
452455

llvm/docs/ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ Changes to the RISC-V Backend
235235
extension.
236236
* Adds experimental assembler support for the Qualcomm uC 'Xqcicm` (Conditonal Move)
237237
extension.
238+
* Adds experimental assembler support for the Qualcomm uC 'Xqciint` (Interrupts)
239+
extension.
238240
* Added ``Sdext`` and ``Sdtrig`` extensions.
239241

240242
Changes to the WebAssembly Backend

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ struct RISCVOperand final : public MCParsedAsmOperand {
717717
bool isUImm6() const { return IsUImm<6>(); }
718718
bool isUImm7() const { return IsUImm<7>(); }
719719
bool isUImm8() const { return IsUImm<8>(); }
720+
bool isUImm10() const { return IsUImm<10>(); }
720721
bool isUImm11() const { return IsUImm<11>(); }
721722
bool isUImm16() const { return IsUImm<16>(); }
722723
bool isUImm20() const { return IsUImm<20>(); }
@@ -1590,6 +1591,8 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
15901591
return generateImmOutOfRangeError(
15911592
Operands, ErrorInfo, -(1 << 9), (1 << 9) - 16,
15921593
"immediate must be a multiple of 16 bytes and non-zero in the range");
1594+
case Match_InvalidUImm10:
1595+
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 10) - 1);
15931596
case Match_InvalidUImm11:
15941597
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, (1 << 11) - 1);
15951598
case Match_InvalidSImm12:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
700700
"Qualcomm uC Conditional Load Immediate custom opcode table");
701701
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicm, DecoderTableXqcicm32,
702702
"Qualcomm uC Conditional Move custom opcode table");
703+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqciint, DecoderTableXqciint32,
704+
"Qualcomm uC Interrupts custom opcode table");
703705
TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");
704706

705707
return MCDisassembler::Fail;
@@ -732,6 +734,8 @@ DecodeStatus RISCVDisassembler::getInstruction16(MCInst &MI, uint64_t &Size,
732734
TRY_TO_DECODE_FEATURE(
733735
RISCV::FeatureVendorXqcicm, DecoderTableXqcicm16,
734736
"Qualcomm uC Conditional Move custom 16bit opcode table");
737+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqciint, DecoderTableXqciint16,
738+
"Qualcomm uC Interrupts custom 16bit opcode table");
735739
TRY_TO_DECODE_AND_ADD_SP(STI.hasFeature(RISCV::FeatureVendorXwchc),
736740
DecoderTableXwchc16,
737741
"WCH QingKe XW custom opcode table");

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ enum OperandType : unsigned {
313313
OPERAND_UIMM8_LSB000,
314314
OPERAND_UIMM8_GE32,
315315
OPERAND_UIMM9_LSB000,
316+
OPERAND_UIMM10,
316317
OPERAND_UIMM10_LSB00_NONZERO,
317318
OPERAND_UIMM11,
318319
OPERAND_UIMM12,

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,14 @@ def HasVendorXqcicm
13021302
AssemblerPredicate<(all_of FeatureVendorXqcicm),
13031303
"'Xqcicm' (Qualcomm uC Conditional Move Extension)">;
13041304

1305+
def FeatureVendorXqciint
1306+
: RISCVExperimentalExtension<0, 2, "Qualcomm uC Interrupts Extension",
1307+
[FeatureStdExtZca]>;
1308+
def HasVendorXqciint
1309+
: Predicate<"Subtarget->hasVendorXqciint()">,
1310+
AssemblerPredicate<(all_of FeatureVendorXqciint),
1311+
"'Xqciint' (Qualcomm uC Interrupts Extension)">;
1312+
13051313
//===----------------------------------------------------------------------===//
13061314
// LLVM specific features and extensions
13071315
//===----------------------------------------------------------------------===//

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,6 +2473,7 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
24732473
CASE_OPERAND_UIMM(6)
24742474
CASE_OPERAND_UIMM(7)
24752475
CASE_OPERAND_UIMM(8)
2476+
CASE_OPERAND_UIMM(10)
24762477
CASE_OPERAND_UIMM(12)
24772478
CASE_OPERAND_UIMM(20)
24782479
// clang-format on

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def uimm5gt3 : RISCVOp<XLenVT>, ImmLeaf<XLenVT,
2828
let OperandType = "OPERAND_UIMM5_GT3";
2929
}
3030

31+
def uimm10 : RISCVUImmLeafOp<10>;
32+
3133
def uimm11 : RISCVUImmLeafOp<11>;
3234

3335
//===----------------------------------------------------------------------===//
@@ -166,6 +168,36 @@ class QCIMVCCI<bits<3> funct3, string opcodestr, DAGOperand immType>
166168
let rs2 = imm;
167169
}
168170

171+
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
172+
class QCIRVInst16CI_RS1<bits<5> funct5, string OpcodeStr>
173+
: RVInst16CI<0b000, 0b10, (outs), (ins GPRNoX0:$rs1), OpcodeStr, "$rs1"> {
174+
bits<5> rs1;
175+
176+
let Inst{12} = 0b1;
177+
let Inst{11-7} = rs1;
178+
let Inst{6-2} = funct5{4-0};
179+
}
180+
181+
let hasSideEffects = 1 in
182+
class QCIRVInst16CI_NONE<bits<5> funct5, string OpcodeStr>
183+
: RVInst16CI<0b000, 0b10, (outs), (ins), OpcodeStr, ""> {
184+
let Inst{12} = 0b1;
185+
let Inst{11-7} = funct5;
186+
let Inst{6-2} = 0b00100;
187+
}
188+
189+
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
190+
class QCIInt_IMM<bits<1> funct1, string opcodestr>
191+
: RVInstIBase<0b000, OPC_SYSTEM, (outs), (ins uimm10:$imm10), opcodestr,
192+
"$imm10"> {
193+
bits<10> imm10;
194+
195+
let rd = 0;
196+
let rs1 = imm10{4-0};
197+
let Inst{31-25} = {0b110011, funct1};
198+
let Inst{24-20} = imm10{9-5};
199+
}
200+
169201
//===----------------------------------------------------------------------===//
170202
// Instructions
171203
//===----------------------------------------------------------------------===//
@@ -312,6 +344,38 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
312344
def QC_MVGEUI : QCIMVCCI<0b111, "qc.mvgeui", uimm5>;
313345
} // Predicates = [HasVendorXqcicm, IsRV32], DecoderNamespace = "Xqcicm"
314346

347+
let Predicates = [HasVendorXqciint, IsRV32], DecoderNamespace = "Xqciint" in {
348+
let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in
349+
def QC_C_DIR : RVInst16CI<0b000, 0b10, (outs GPRNoX0:$rd), (ins),
350+
"qc.c.dir", "$rd"> {
351+
bits<5> rd;
352+
353+
let Inst{12} = 0b1;
354+
let Inst{11-7} = rd;
355+
let Inst{6-2} = 0b00000;
356+
}
357+
358+
def QC_SETINTI : QCIInt_IMM<0b0, "qc.setinti">;
359+
def QC_CLRINTI : QCIInt_IMM<0b1, "qc.clrinti">;
360+
361+
def QC_C_EIR : QCIRVInst16CI_RS1<0b00001, "qc.c.eir">;
362+
def QC_C_SETINT : QCIRVInst16CI_RS1<0b00010, "qc.c.setint">;
363+
def QC_C_CLRINT : QCIRVInst16CI_RS1<0b00011, "qc.c.clrint">;
364+
365+
let mayLoad = 0, mayStore = 0 in {
366+
def QC_C_DI : QCIRVInst16CI_NONE<0b10110, "qc.c.di">;
367+
def QC_C_EI : QCIRVInst16CI_NONE<0b10111, "qc.c.ei">;
368+
} // mayLoad =0, mayStore = 0
369+
370+
let mayLoad = 1, mayStore = 1 in {
371+
def QC_C_MIENTER : QCIRVInst16CI_NONE<0b10000, "qc.c.mienter">;
372+
def QC_C_MIENTER_NEST : QCIRVInst16CI_NONE<0b10001, "qc.c.mienter.nest">;
373+
} // mayLoad = 1, mayStore = 1
374+
375+
let mayLoad = 1, mayStore = 1, isReturn = 1, isTerminator = 1 in
376+
def QC_C_MILEAVERET : QCIRVInst16CI_NONE<0b10100, "qc.c.mileaveret">;
377+
} // Predicates = [HasVendorXqciint, IsRV32], DecoderNamespace = "Xqciint"
378+
315379
//===----------------------------------------------------------------------===//
316380
// Aliases
317381
//===----------------------------------------------------------------------===//

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ Error RISCVISAInfo::checkDependency() {
742742
bool HasZvl = MinVLen != 0;
743743
bool HasZcmt = Exts.count("zcmt") != 0;
744744
static constexpr StringLiteral XqciExts[] = {
745-
{"xqcia"}, {"xqciac"}, {"xqcicli"}, {"xqcicm"},
746-
{"xqcics"}, {"xqcicsr"}, {"xqcilsm"}, {"xqcisls"}};
745+
{"xqcia"}, {"xqciac"}, {"xqcicli"}, {"xqcicm"}, {"xqcics"},
746+
{"xqcicsr"}, {"xqciint"}, {"xqcilsm"}, {"xqcisls"}};
747747

748748
if (HasI && HasE)
749749
return getIncompatibleError("i", "e");

0 commit comments

Comments
 (0)