Skip to content

Commit 538b898

Browse files
authored
[RISCV] Add Qualcomm uC Xqcilia (Large Immediate Arithmetic) extension (#124706)
This extension adds eight 48 bit large arithmetic instructions. The current spec can be found at: https://github.com/quic/riscv-unified-db/releases/latest This patch adds assembler only support.
1 parent b66ec64 commit 538b898

File tree

13 files changed

+286
-3
lines changed

13 files changed

+286
-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
@@ -200,6 +200,7 @@
200200
// CHECK-NEXT: xqcics 0.2 'Xqcics' (Qualcomm uC Conditional Select Extension)
201201
// CHECK-NEXT: xqcicsr 0.2 'Xqcicsr' (Qualcomm uC CSR Extension)
202202
// CHECK-NEXT: xqciint 0.2 'Xqciint' (Qualcomm uC Interrupts Extension)
203+
// CHECK-NEXT: xqcilia 0.2 'Xqcilia' (Qualcomm uC Large Immediate Arithmetic Extension)
203204
// CHECK-NEXT: xqcilo 0.2 'Xqcilo' (Qualcomm uC Large Offset Load Store Extension)
204205
// CHECK-NEXT: xqcilsm 0.2 'Xqcilsm' (Qualcomm uC Load Store Multiple Extension)
205206
// CHECK-NEXT: xqcisls 0.2 'Xqcisls' (Qualcomm uC Scaled Load Store Extension)

llvm/docs/RISCVUsage.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,9 @@ The current vendor extensions supported are:
450450
``experimental-Xqciint``
451451
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.
452452

453+
``experimental-Xqcilia``
454+
LLVM implements `version 0.2 of the Qualcomm uC Large Immediate Arithmetic 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.
455+
453456
``experimental-Xqcilo``
454457
LLVM implements `version 0.2 of the Qualcomm uC Large Offset 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.
455458

llvm/docs/ReleaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ Changes to the PowerPC Backend
107107
Changes to the RISC-V Backend
108108
-----------------------------
109109

110+
* Adds experimental assembler support for the Qualcomm uC 'Xqcilia` (Large Immediate Arithmetic)
111+
extension.
112+
110113
Changes to the WebAssembly Backend
111114
----------------------------------
112115

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,16 @@ struct RISCVOperand final : public MCParsedAsmOperand {
10561056
isInt<26>(fixImmediateForRV32(Imm, isRV64Imm()));
10571057
}
10581058

1059+
bool isSImm32() const {
1060+
int64_t Imm;
1061+
RISCVMCExpr::VariantKind VK = RISCVMCExpr::VK_RISCV_None;
1062+
if (!isImm())
1063+
return false;
1064+
bool IsConstantImm = evaluateConstantImm(getImm(), Imm, VK);
1065+
return IsConstantImm && isInt<32>(fixImmediateForRV32(Imm, isRV64Imm())) &&
1066+
VK == RISCVMCExpr::VK_RISCV_None;
1067+
}
1068+
10591069
/// getStartLoc - Gets location of the first token of this operand
10601070
SMLoc getStartLoc() const override { return StartLoc; }
10611071
/// getEndLoc - Gets location of the last token of this operand
@@ -1665,6 +1675,10 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
16651675
case Match_InvalidSImm26:
16661676
return generateImmOutOfRangeError(Operands, ErrorInfo, -(1 << 25),
16671677
(1 << 25) - 1);
1678+
case Match_InvalidSImm32:
1679+
return generateImmOutOfRangeError(Operands, ErrorInfo,
1680+
std::numeric_limits<int32_t>::min(),
1681+
std::numeric_limits<uint32_t>::max());
16681682
case Match_InvalidRnumArg: {
16691683
return generateImmOutOfRangeError(Operands, ErrorInfo, 0, 10);
16701684
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ DecodeStatus RISCVDisassembler::getInstruction48(MCInst &MI, uint64_t &Size,
767767
for (size_t i = Size; i-- != 0;) {
768768
Insn += (static_cast<uint64_t>(Bytes[i]) << 8 * i);
769769
}
770+
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcilia, DecoderTableXqcilia48,
771+
"Qualcomm uC Large Immediate Arithmetic 48bit");
770772
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcilo, DecoderTableXqcilo48,
771773
"Qualcomm uC Large Offset Load Store 48bit");
772774

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ enum OperandType : unsigned {
327327
OPERAND_SIMM12,
328328
OPERAND_SIMM12_LSB00000,
329329
OPERAND_SIMM26,
330+
OPERAND_SIMM32,
330331
OPERAND_CLUI_IMM,
331332
OPERAND_VTYPEI10,
332333
OPERAND_VTYPEI11,

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,14 @@ def HasVendorXqciint
13581358
AssemblerPredicate<(all_of FeatureVendorXqciint),
13591359
"'Xqciint' (Qualcomm uC Interrupts Extension)">;
13601360

1361+
def FeatureVendorXqcilia
1362+
: RISCVExperimentalExtension<0, 2, "Qualcomm uC Large Immediate Arithmetic Extension",
1363+
[FeatureStdExtZca]>;
1364+
def HasVendorXqcilia
1365+
: Predicate<"Subtarget->hasVendorXqcilia()">,
1366+
AssemblerPredicate<(all_of FeatureVendorXqcilia),
1367+
"'Xqcilia' (Qualcomm uC Large Immediate Arithmetic Extension)">;
1368+
13611369
def FeatureVendorXqcilo
13621370
: RISCVExperimentalExtension<0, 2, "Qualcomm uC Large Offset Load Store Extension",
13631371
[FeatureStdExtZca]>;

llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ def uimm11 : RISCVUImmLeafOp<11>;
3434

3535
def simm26 : RISCVSImmLeafOp<26>;
3636

37+
// 32-bit Immediate, used by RV32 Instructions in 32-bit operations, so no
38+
// sign-/zero-extension. This is represented internally as a signed 32-bit value.
39+
def simm32 : RISCVOp<XLenVT> {
40+
let ParserMatchClass = SImmAsmOperand<32, "">;
41+
let EncoderMethod = "getImmOpValue";
42+
let DecoderMethod = "decodeSImmOperand<32>";
43+
let OperandType = "OPERAND_SIMM32";
44+
let MCOperandPredicate = [{
45+
int64_t Imm;
46+
if (MCOp.evaluateAsConstantImm(Imm))
47+
return isInt<32>(Imm);
48+
return false;
49+
}];
50+
}
51+
3752
//===----------------------------------------------------------------------===//
3853
// Instruction Formats
3954
//===----------------------------------------------------------------------===//
@@ -245,6 +260,25 @@ class QCIRVInstESStore<bits<3> funct3, bits<2> funct2, string opcodestr>
245260
(ins GPRMem:$rs2, GPR:$rs1, simm26:$imm),
246261
opcodestr, "$rs2, ${imm}(${rs1})">;
247262

263+
class QCIRVInstEAI<bits<3> funct3, bits<1> funct1, string opcodestr>
264+
: RVInst48<(outs GPRNoX0:$rd_wb), (ins GPRNoX0:$rd, simm32:$imm),
265+
opcodestr, "$rd, $imm", [], InstFormatOther> {
266+
bits<5> rd;
267+
bits<32> imm;
268+
269+
let Constraints = "$rd = $rd_wb";
270+
let Inst{47-16} = imm{31-0};
271+
let Inst{15} = funct1;
272+
let Inst{14-12} = funct3;
273+
let Inst{11-7} = rd;
274+
let Inst{6-0} = 0b0011111;
275+
}
276+
277+
class QCIRVInstEI<bits<3> funct3, bits<2> funct2, string opcodestr>
278+
: QCIRVInstEIBase<funct3, funct2, (outs GPRNoX0:$rd),
279+
(ins GPRNoX0:$rs1, simm26:$imm), opcodestr,
280+
"$rd, $rs1, $imm">;
281+
248282
//===----------------------------------------------------------------------===//
249283
// Instructions
250284
//===----------------------------------------------------------------------===//
@@ -435,6 +469,20 @@ let Predicates = [HasVendorXqcilo, IsRV32], DecoderNamespace = "Xqcilo" in {
435469
def QC_E_SW : QCIRVInstESStore<0b110, 0b11, "qc.e.sw">;
436470
} // Predicates = [HasVendorXqcilo, IsRV32], DecoderNamespace = "Xqcilo"
437471

472+
let Predicates = [HasVendorXqcilia, IsRV32], DecoderNamespace = "Xqcilia" in {
473+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
474+
def QC_E_XORAI : QCIRVInstEAI<0b001, 0b0, "qc.e.xorai">;
475+
def QC_E_ORAI : QCIRVInstEAI<0b001, 0b1, "qc.e.orai" >;
476+
def QC_E_ADDAI : QCIRVInstEAI<0b010, 0b0, "qc.e.addai">;
477+
def QC_E_ANDAI : QCIRVInstEAI<0b010, 0b1, "qc.e.andai">;
478+
479+
def QC_E_XORI : QCIRVInstEI<0b011, 0b00, "qc.e.xori">;
480+
def QC_E_ORI : QCIRVInstEI<0b011, 0b01, "qc.e.ori" >;
481+
def QC_E_ADDI : QCIRVInstEI<0b011, 0b10, "qc.e.addi">;
482+
def QC_E_ANDI : QCIRVInstEI<0b011, 0b11, "qc.e.andi">;
483+
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
484+
} // Predicates = [HasVendorXqcilia, IsRV32], DecoderNamespace = "Xqcilia"
485+
438486
//===----------------------------------------------------------------------===//
439487
// Aliases
440488
//===----------------------------------------------------------------------===//

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,9 @@ 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"}, {"xqcics"},
746-
{"xqcicsr"}, {"xqciint"}, {"xqcilo"}, {"xqcilsm"}, {"xqcisls"}};
745+
{"xqcia"}, {"xqciac"}, {"xqcicli"}, {"xqcicm"},
746+
{"xqcics"}, {"xqcicsr"}, {"xqciint"}, {"xqcilia"},
747+
{"xqcilo"}, {"xqcilsm"}, {"xqcisls"}};
747748

748749
if (HasI && HasE)
749750
return getIncompatibleError("i", "e");

llvm/test/CodeGen/RISCV/attributes.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcics %s -o - | FileCheck --check-prefix=RV32XQCICS %s
8989
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcicsr %s -o - | FileCheck --check-prefix=RV32XQCICSR %s
9090
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqciint %s -o - | FileCheck --check-prefix=RV32XQCIINT %s
91+
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilia %s -o - | FileCheck --check-prefix=RV32XQCILIA %s
9192
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilo %s -o - | FileCheck --check-prefix=RV32XQCILO %s
9293
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilsm %s -o - | FileCheck --check-prefix=RV32XQCILSM %s
9394
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcisls %s -o - | FileCheck --check-prefix=RV32XQCISLS %s
@@ -404,6 +405,7 @@
404405
; RV32XQCICS: .attribute 5, "rv32i2p1_xqcics0p2"
405406
; RV32XQCICSR: .attribute 5, "rv32i2p1_xqcicsr0p2"
406407
; RV32XQCIINT: .attribute 5, "rv32i2p1_zca1p0_xqciint0p2"
408+
; RV32XQCILIA: .attribute 5, "rv32i2p1_zca1p0_xqcilia0p2"
407409
; RV32XQCILO: .attribute 5, "rv32i2p1_zca1p0_xqcilo0p2"
408410
; RV32XQCILSM: .attribute 5, "rv32i2p1_xqcilsm0p2"
409411
; RV32XQCISLS: .attribute 5, "rv32i2p1_xqcisls0p2"

0 commit comments

Comments
 (0)