aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
diff options
context:
space:
mode:
authorManolis Tsamis <manolis.tsamis@vrull.eu>2023-02-13 14:07:45 +0100
committerPhilipp Tomsich <philipp.tomsich@vrull.eu>2023-02-17 19:45:22 +0100
commitd2918544a7fc4b5443879fe12f32a712e6dfe325 (patch)
tree72e5c6e819ed970bb2517b788634733b5c4f2ae0 /llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
parent21a543656cf4840023078359a6c7e0db7d5391b2 (diff)
downloadllvm-d2918544a7fc4b5443879fe12f32a712e6dfe325.zip
llvm-d2918544a7fc4b5443879fe12f32a712e6dfe325.tar.gz
llvm-d2918544a7fc4b5443879fe12f32a712e6dfe325.tar.bz2
[RISCV] Add vendor-defined XTheadMemPair (two-GPR Memory Operations) extension
The vendor-defined XTHeadMemPair (no comparable standard extension exists at the time of writing) extension adds two-GPR load/store pair instructions. It is supported by the C9xx cores (e.g., found in the wild in the Allwinner D1) by Alibaba T-Head. The current (as of this commit) public documentation for this extension is available at: https://github.com/T-head-Semi/thead-extension-spec/releases/download/2.2.2/xthead-2023-01-30-2.2.2.pdf Support for these instructions has already landed in GNU Binutils: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6e17ae625570ff8f3c12c8765b8d45d4db8694bd Depends on D143847 Differential Revision: https://reviews.llvm.org/D144002
Diffstat (limited to 'llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp')
-rw-r--r--llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index b379976..099d755 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -369,6 +369,10 @@ static DecodeStatus decodeRVCInstrRdRs1Rs2(MCInst &Inst, uint32_t Insn,
uint64_t Address,
const MCDisassembler *Decoder);
+static DecodeStatus decodeXTHeadMemPair(MCInst &Inst, uint32_t Insn,
+ uint64_t Address,
+ const MCDisassembler *Decoder);
+
#include "RISCVGenDisassemblerTables.inc"
static DecodeStatus decodeRVCInstrRdRs1ImmZero(MCInst &Inst, uint32_t Insn,
@@ -429,6 +433,32 @@ static DecodeStatus decodeRVCInstrRdRs1Rs2(MCInst &Inst, uint32_t Insn,
return MCDisassembler::Success;
}
+static DecodeStatus decodeXTHeadMemPair(MCInst &Inst, uint32_t Insn,
+ uint64_t Address,
+ const MCDisassembler *Decoder) {
+ uint32_t Rd1 = fieldFromInstruction(Insn, 7, 5);
+ uint32_t Rs1 = fieldFromInstruction(Insn, 15, 5);
+ uint32_t Rd2 = fieldFromInstruction(Insn, 20, 5);
+ uint32_t UImm2 = fieldFromInstruction(Insn, 25, 2);
+ DecodeGPRRegisterClass(Inst, Rd1, Address, Decoder);
+ DecodeGPRRegisterClass(Inst, Rd2, Address, Decoder);
+ DecodeGPRRegisterClass(Inst, Rs1, Address, Decoder);
+ DecodeStatus Result = decodeUImmOperand<2>(Inst, UImm2, Address, Decoder);
+ (void)Result;
+ assert(Result == MCDisassembler::Success && "Invalid immediate");
+
+ // Disassemble the final operand which is implicit.
+ unsigned Opcode = Inst.getOpcode();
+ bool IsWordOp = (Opcode == RISCV::TH_LWD || Opcode == RISCV::TH_LWUD ||
+ Opcode == RISCV::TH_SWD);
+ if (IsWordOp) {
+ Inst.addOperand(MCOperand::createImm(3));
+ } else {
+ Inst.addOperand(MCOperand::createImm(4));
+ }
+ return MCDisassembler::Success;
+}
+
DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
ArrayRef<uint8_t> Bytes,
uint64_t Address,
@@ -499,6 +529,13 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
if (Result != MCDisassembler::Fail)
return Result;
}
+ if (STI.getFeatureBits()[RISCV::FeatureVendorXTHeadMemPair]) {
+ LLVM_DEBUG(dbgs() << "Trying XTHeadMemPair custom opcode table:\n");
+ Result = decodeInstruction(DecoderTableTHeadMemPair32, MI, Insn, Address,
+ this, STI);
+ if (Result != MCDisassembler::Fail)
+ return Result;
+ }
if (STI.getFeatureBits()[RISCV::FeatureVendorXTHeadVdot]) {
LLVM_DEBUG(dbgs() << "Trying XTHeadVdot custom opcode table:\n");
Result =