Skip to content

[RISCV] Add Qualcomm uC Xqcicm (Conditional Move) extension #121752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/test/Driver/print-supported-extensions-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
// CHECK-NEXT: xqcia 0.2 'Xqcia' (Qualcomm uC Arithmetic Extension)
// CHECK-NEXT: xqciac 0.2 'Xqciac' (Qualcomm uC Load-Store Address Calculation Extension)
// CHECK-NEXT: xqcicli 0.2 'Xqcicli' (Qualcomm uC Conditional Load Immediate Extension)
// CHECK-NEXT: xqcicm 0.2 'Xqcicm' (Qualcomm uC Conditional Move Extension)
// CHECK-NEXT: xqcics 0.2 'Xqcics' (Qualcomm uC Conditional Select Extension)
// CHECK-NEXT: xqcicsr 0.2 'Xqcicsr' (Qualcomm uC CSR Extension)
// CHECK-NEXT: xqcilsm 0.2 'Xqcilsm' (Qualcomm uC Load Store Multiple Extension)
Expand Down
3 changes: 3 additions & 0 deletions llvm/docs/RISCVUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ The current vendor extensions supported are:
``experimental-Xqcicli``
LLVM implements `version 0.2 of the Qualcomm uC Conditional Load Immediate 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.

``experimental-Xqcicm``
LLVM implements `version 0.2 of the Qualcomm uC Conditional Move 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.

``experimental-Xqcics``
LLVM implements `version 0.2 of the Qualcomm uC Conditional Select 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.

Expand Down
2 changes: 2 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ Changes to the RISC-V Backend
extension.
* Adds experimental assembler support for the Qualcomm uC 'Xqcicli` (Conditional Load Immediate)
extension.
* Adds experimental assembler support for the Qualcomm uC 'Xqcicm` (Conditonal Move)
extension.
* Added ``Sdext`` and ``Sdtrig`` extensions.

Changes to the WebAssembly Backend
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
TRY_TO_DECODE_FEATURE(
RISCV::FeatureVendorXqcicli, DecoderTableXqcicli32,
"Qualcomm uC Conditional Load Immediate custom opcode table");
TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXqcicm, DecoderTableXqcicm32,
"Qualcomm uC Conditional Move custom opcode table");
TRY_TO_DECODE(true, DecoderTable32, "RISCV32 table");

return MCDisassembler::Fail;
Expand Down Expand Up @@ -727,6 +729,9 @@ DecodeStatus RISCVDisassembler::getInstruction16(MCInst &MI, uint64_t &Size,
TRY_TO_DECODE_FEATURE(
RISCV::FeatureVendorXqciac, DecoderTableXqciac16,
"Qualcomm uC Load-Store Address Calculation custom 16bit opcode table");
TRY_TO_DECODE_FEATURE(
RISCV::FeatureVendorXqcicm, DecoderTableXqcicm16,
"Qualcomm uC Conditional Move custom 16bit opcode table");
TRY_TO_DECODE_AND_ADD_SP(STI.hasFeature(RISCV::FeatureVendorXwchc),
DecoderTableXwchc16,
"WCH QingKe XW custom opcode table");
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/Target/RISCV/RISCVFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,14 @@ def HasVendorXqcicli
AssemblerPredicate<(all_of FeatureVendorXqcicli),
"'Xqcicli' (Qualcomm uC Conditional Load Immediate Extension)">;

def FeatureVendorXqcicm
: RISCVExperimentalExtension<0, 2, "Qualcomm uC Conditional Move Extension",
[FeatureStdExtZca]>;
def HasVendorXqcicm
: Predicate<"Subtarget->hasVendorXqcicm()">,
AssemblerPredicate<(all_of FeatureVendorXqcicm),
"'Xqcicm' (Qualcomm uC Conditional Move Extension)">;

//===----------------------------------------------------------------------===//
// LLVM specific features and extensions
//===----------------------------------------------------------------------===//
Expand Down
42 changes: 42 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ class QCILICC<bits<3> funct3, bits<2> funct2, DAGOperand InTyRs2, string opcodes
let Inst{31-25} = {simm, funct2};
}

let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
class QCIMVCC<bits<3> funct3, string opcodestr>
: RVInstR4<0b00, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd),
(ins GPRNoX0:$rs1, GPRNoX0:$rs2, GPRNoX0:$rs3),
opcodestr, "$rd, $rs1, $rs2, $rs3">;

let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
class QCIMVCCI<bits<3> funct3, string opcodestr, DAGOperand immType>
: RVInstR4<0b10, funct3, OPC_CUSTOM_2, (outs GPRNoX0:$rd),
(ins GPRNoX0:$rs1, immType:$imm, GPRNoX0:$rs3),
opcodestr, "$rd, $rs1, $imm, $rs3"> {
bits<5> imm;

let rs2 = imm;
}

//===----------------------------------------------------------------------===//
// Instructions
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -270,6 +286,32 @@ let Predicates = [HasVendorXqcicli, IsRV32], DecoderNamespace = "Xqcicli" in {
def QC_LIGEUI : QCILICC<0b111, 0b11, uimm5, "qc.ligeui">;
} // Predicates = [HasVendorXqcicli, IsRV32], DecoderNamespace = "Xqcicli"

let Predicates = [HasVendorXqcicm, IsRV32], DecoderNamespace = "Xqcicm" in {
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
def QC_C_MVEQZ : RVInst16CL<0b101, 0b10, (outs GPRC:$rd_wb),
(ins GPRC:$rd, GPRC:$rs1),
"qc.c.mveqz", "$rd, $rs1"> {
let Constraints = "$rd = $rd_wb";

let Inst{12-10} = 0b011;
let Inst{6-5} = 0b00;
}

def QC_MVEQ : QCIMVCC<0b000, "qc.mveq">;
def QC_MVNE : QCIMVCC<0b001, "qc.mvne">;
def QC_MVLT : QCIMVCC<0b100, "qc.mvlt">;
def QC_MVGE : QCIMVCC<0b101, "qc.mvge">;
def QC_MVLTU : QCIMVCC<0b110, "qc.mvltu">;
def QC_MVGEU : QCIMVCC<0b111, "qc.mvgeu">;

def QC_MVEQI : QCIMVCCI<0b000, "qc.mveqi", simm5>;
def QC_MVNEI : QCIMVCCI<0b001, "qc.mvnei", simm5>;
def QC_MVLTI : QCIMVCCI<0b100, "qc.mvlti", simm5>;
def QC_MVGEI : QCIMVCCI<0b101, "qc.mvgei", simm5>;
def QC_MVLTUI : QCIMVCCI<0b110, "qc.mvltui", uimm5>;
def QC_MVGEUI : QCIMVCCI<0b111, "qc.mvgeui", uimm5>;
} // Predicates = [HasVendorXqcicm, IsRV32], DecoderNamespace = "Xqcicm"

//===----------------------------------------------------------------------===//
// Aliases
//===----------------------------------------------------------------------===//
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/TargetParser/RISCVISAInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ Error RISCVISAInfo::checkDependency() {
bool HasZvl = MinVLen != 0;
bool HasZcmt = Exts.count("zcmt") != 0;
static constexpr StringLiteral XqciExts[] = {
{"xqcia"}, {"xqciac"}, {"xqcicli"}, {"xqcics"},
{"xqcicsr"}, {"xqcilsm"}, {"xqcisls"}};
{"xqcia"}, {"xqciac"}, {"xqcicli"}, {"xqcicm"},
{"xqcics"}, {"xqcicsr"}, {"xqcilsm"}, {"xqcisls"}};

if (HasI && HasE)
return getIncompatibleError("i", "e");
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/CodeGen/RISCV/attributes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcia %s -o - | FileCheck --check-prefix=RV32XQCIA %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqciac %s -o - | FileCheck --check-prefix=RV32XQCIAC %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcicli %s -o - | FileCheck --check-prefix=RV32XQCICLI %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcicm %s -o - | FileCheck --check-prefix=RV32XQCICM %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcics %s -o - | FileCheck --check-prefix=RV32XQCICS %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcicsr %s -o - | FileCheck --check-prefix=RV32XQCICSR %s
; RUN: llc -mtriple=riscv32 -mattr=+experimental-xqcilsm %s -o - | FileCheck --check-prefix=RV32XQCILSM %s
Expand Down Expand Up @@ -397,6 +398,7 @@
; RV32XQCIA: .attribute 5, "rv32i2p1_xqcia0p2"
; RV32XQCIAC: .attribute 5, "rv32i2p1_zca1p0_xqciac0p2"
; RV32XQCICLI: .attribute 5, "rv32i2p1_xqcicli0p2"
; RV32XQCICM: .attribute 5, "rv32i2p1_zca1p0_xqcicm0p2"
; RV32XQCICS: .attribute 5, "rv32i2p1_xqcics0p2"
; RV32XQCICSR: .attribute 5, "rv32i2p1_xqcicsr0p2"
; RV32XQCILSM: .attribute 5, "rv32i2p1_xqcilsm0p2"
Expand Down
152 changes: 152 additions & 0 deletions llvm/test/MC/RISCV/xqcicm-invalid.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Xqcicm - Qualcomm uC Conditional Move Extension
# RUN: not llvm-mc -triple riscv32 -mattr=+experimental-xqcicm < %s 2>&1 \
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-IMM %s
# RUN: not llvm-mc -triple riscv32 -mattr=-experimental-xqcicm < %s 2>&1 \
# RUN: | FileCheck -check-prefixes=CHECK,CHECK-EXT %s

# CHECK: :[[@LINE+1]]:12: error: invalid operand for instruction
qc.c.mveqz 9, x10

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.c.mveqz x9

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.c.mveqz x9, x10


# CHECK: :[[@LINE+1]]:9: error: invalid operand for instruction
qc.mveq 9, x10, x11, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mveq x9

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mveq x9, x10, x11, x12


# CHECK: :[[@LINE+1]]:9: error: invalid operand for instruction
qc.mvge 9, x10, x11, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvge x9

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvge x9, x10, x11, x12


# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.mvgeu 9, x10, x11, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvgeu x9

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvgeu x9, x10, x11, x12


# CHECK: :[[@LINE+1]]:9: error: invalid operand for instruction
qc.mvlt 9, x10, x11, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvlt x9

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvlt x9, x10, x11, x12


# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.mvltu 9, x10, x11, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvltu x9

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvltu x9, x10, x11, x12


# CHECK: :[[@LINE+1]]:9: error: invalid operand for instruction
qc.mvne 9, x10, x11, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvne x9

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvne x9, x10, x11, x12


# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.mveqi 9, x10, 5, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mveqi x9

# CHECK-IMM: :[[@LINE+1]]:19: error: immediate must be an integer in the range [-16, 15]
qc.mveqi x9, x10, 17, x12

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mveqi x9, x10, 5, x12


# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.mvgei 9, x10, 5, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvgei x9

# CHECK-IMM: :[[@LINE+1]]:19: error: immediate must be an integer in the range [-16, 15]
qc.mvgei x9, x10, 17, x12

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvgei x9, x10, 5, x12


# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.mvlti 9, x10, 5, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvlti x9

# CHECK-IMM: :[[@LINE+1]]:19: error: immediate must be an integer in the range [-16, 15]
qc.mvlti x9, x10, 17, x12

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvlti x9, x10, 5, x12


# CHECK: :[[@LINE+1]]:10: error: invalid operand for instruction
qc.mvnei 9, x10, 5, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvnei x9

# CHECK-IMM: :[[@LINE+1]]:19: error: immediate must be an integer in the range [-16, 15]
qc.mvnei x9, x10, 17, x12

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvnei x9, x10, 5, x12


# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.mvltui 9, x10, 5, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvltui x9

# CHECK-IMM: :[[@LINE+1]]:20: error: immediate must be an integer in the range [0, 31]
qc.mvltui x9, x10, 37, x12

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvltui x9, x10, 5, x12


# CHECK: :[[@LINE+1]]:11: error: invalid operand for instruction
qc.mvgeui 9, x10, 5, x12

# CHECK: :[[@LINE+1]]:1: error: too few operands for instruction
qc.mvgeui x9

# CHECK-IMM: :[[@LINE+1]]:20: error: immediate must be an integer in the range [0, 31]
qc.mvgeui x9, x10, 37, x12

# CHECK-EXT: :[[@LINE+1]]:1: error: instruction requires the following: 'Xqcicm' (Qualcomm uC Conditional Move Extension)
qc.mvgeui x9, x10, 5, x12
Loading
Loading