12cab237bSDimitry Andric //===-- RISCVDisassembler.cpp - Disassembler for RISCV --------------------===//
22cab237bSDimitry Andric //
32cab237bSDimitry Andric // The LLVM Compiler Infrastructure
42cab237bSDimitry Andric //
52cab237bSDimitry Andric // This file is distributed under the University of Illinois Open Source
62cab237bSDimitry Andric // License. See LICENSE.TXT for details.
72cab237bSDimitry Andric //
82cab237bSDimitry Andric //===----------------------------------------------------------------------===//
92cab237bSDimitry Andric //
102cab237bSDimitry Andric // This file implements the RISCVDisassembler class.
112cab237bSDimitry Andric //
122cab237bSDimitry Andric //===----------------------------------------------------------------------===//
132cab237bSDimitry Andric
142cab237bSDimitry Andric #include "MCTargetDesc/RISCVMCTargetDesc.h"
15*b5893f02SDimitry Andric #include "Utils/RISCVBaseInfo.h"
162cab237bSDimitry Andric #include "llvm/MC/MCContext.h"
172cab237bSDimitry Andric #include "llvm/MC/MCDisassembler/MCDisassembler.h"
182cab237bSDimitry Andric #include "llvm/MC/MCFixedLenDisassembler.h"
192cab237bSDimitry Andric #include "llvm/MC/MCInst.h"
202cab237bSDimitry Andric #include "llvm/MC/MCRegisterInfo.h"
212cab237bSDimitry Andric #include "llvm/MC/MCSubtargetInfo.h"
222cab237bSDimitry Andric #include "llvm/Support/Endian.h"
232cab237bSDimitry Andric #include "llvm/Support/TargetRegistry.h"
242cab237bSDimitry Andric
252cab237bSDimitry Andric using namespace llvm;
262cab237bSDimitry Andric
272cab237bSDimitry Andric #define DEBUG_TYPE "riscv-disassembler"
282cab237bSDimitry Andric
292cab237bSDimitry Andric typedef MCDisassembler::DecodeStatus DecodeStatus;
302cab237bSDimitry Andric
312cab237bSDimitry Andric namespace {
322cab237bSDimitry Andric class RISCVDisassembler : public MCDisassembler {
332cab237bSDimitry Andric
342cab237bSDimitry Andric public:
RISCVDisassembler(const MCSubtargetInfo & STI,MCContext & Ctx)352cab237bSDimitry Andric RISCVDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx)
362cab237bSDimitry Andric : MCDisassembler(STI, Ctx) {}
372cab237bSDimitry Andric
382cab237bSDimitry Andric DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
392cab237bSDimitry Andric ArrayRef<uint8_t> Bytes, uint64_t Address,
402cab237bSDimitry Andric raw_ostream &VStream,
412cab237bSDimitry Andric raw_ostream &CStream) const override;
422cab237bSDimitry Andric };
432cab237bSDimitry Andric } // end anonymous namespace
442cab237bSDimitry Andric
createRISCVDisassembler(const Target & T,const MCSubtargetInfo & STI,MCContext & Ctx)452cab237bSDimitry Andric static MCDisassembler *createRISCVDisassembler(const Target &T,
462cab237bSDimitry Andric const MCSubtargetInfo &STI,
472cab237bSDimitry Andric MCContext &Ctx) {
482cab237bSDimitry Andric return new RISCVDisassembler(STI, Ctx);
492cab237bSDimitry Andric }
502cab237bSDimitry Andric
LLVMInitializeRISCVDisassembler()512cab237bSDimitry Andric extern "C" void LLVMInitializeRISCVDisassembler() {
522cab237bSDimitry Andric // Register the disassembler for each target.
532cab237bSDimitry Andric TargetRegistry::RegisterMCDisassembler(getTheRISCV32Target(),
542cab237bSDimitry Andric createRISCVDisassembler);
552cab237bSDimitry Andric TargetRegistry::RegisterMCDisassembler(getTheRISCV64Target(),
562cab237bSDimitry Andric createRISCVDisassembler);
572cab237bSDimitry Andric }
582cab237bSDimitry Andric
592cab237bSDimitry Andric static const unsigned GPRDecoderTable[] = {
602cab237bSDimitry Andric RISCV::X0, RISCV::X1, RISCV::X2, RISCV::X3,
612cab237bSDimitry Andric RISCV::X4, RISCV::X5, RISCV::X6, RISCV::X7,
622cab237bSDimitry Andric RISCV::X8, RISCV::X9, RISCV::X10, RISCV::X11,
632cab237bSDimitry Andric RISCV::X12, RISCV::X13, RISCV::X14, RISCV::X15,
642cab237bSDimitry Andric RISCV::X16, RISCV::X17, RISCV::X18, RISCV::X19,
652cab237bSDimitry Andric RISCV::X20, RISCV::X21, RISCV::X22, RISCV::X23,
662cab237bSDimitry Andric RISCV::X24, RISCV::X25, RISCV::X26, RISCV::X27,
672cab237bSDimitry Andric RISCV::X28, RISCV::X29, RISCV::X30, RISCV::X31
682cab237bSDimitry Andric };
692cab237bSDimitry Andric
DecodeGPRRegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)702cab237bSDimitry Andric static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, uint64_t RegNo,
712cab237bSDimitry Andric uint64_t Address,
722cab237bSDimitry Andric const void *Decoder) {
732cab237bSDimitry Andric if (RegNo > sizeof(GPRDecoderTable))
742cab237bSDimitry Andric return MCDisassembler::Fail;
752cab237bSDimitry Andric
762cab237bSDimitry Andric // We must define our own mapping from RegNo to register identifier.
772cab237bSDimitry Andric // Accessing index RegNo in the register class will work in the case that
782cab237bSDimitry Andric // registers were added in ascending order, but not in general.
792cab237bSDimitry Andric unsigned Reg = GPRDecoderTable[RegNo];
802cab237bSDimitry Andric Inst.addOperand(MCOperand::createReg(Reg));
812cab237bSDimitry Andric return MCDisassembler::Success;
822cab237bSDimitry Andric }
832cab237bSDimitry Andric
842cab237bSDimitry Andric static const unsigned FPR32DecoderTable[] = {
852cab237bSDimitry Andric RISCV::F0_32, RISCV::F1_32, RISCV::F2_32, RISCV::F3_32,
862cab237bSDimitry Andric RISCV::F4_32, RISCV::F5_32, RISCV::F6_32, RISCV::F7_32,
872cab237bSDimitry Andric RISCV::F8_32, RISCV::F9_32, RISCV::F10_32, RISCV::F11_32,
882cab237bSDimitry Andric RISCV::F12_32, RISCV::F13_32, RISCV::F14_32, RISCV::F15_32,
892cab237bSDimitry Andric RISCV::F16_32, RISCV::F17_32, RISCV::F18_32, RISCV::F19_32,
902cab237bSDimitry Andric RISCV::F20_32, RISCV::F21_32, RISCV::F22_32, RISCV::F23_32,
912cab237bSDimitry Andric RISCV::F24_32, RISCV::F25_32, RISCV::F26_32, RISCV::F27_32,
922cab237bSDimitry Andric RISCV::F28_32, RISCV::F29_32, RISCV::F30_32, RISCV::F31_32
932cab237bSDimitry Andric };
942cab237bSDimitry Andric
DecodeFPR32RegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)952cab237bSDimitry Andric static DecodeStatus DecodeFPR32RegisterClass(MCInst &Inst, uint64_t RegNo,
962cab237bSDimitry Andric uint64_t Address,
972cab237bSDimitry Andric const void *Decoder) {
982cab237bSDimitry Andric if (RegNo > sizeof(FPR32DecoderTable))
992cab237bSDimitry Andric return MCDisassembler::Fail;
1002cab237bSDimitry Andric
1012cab237bSDimitry Andric // We must define our own mapping from RegNo to register identifier.
1022cab237bSDimitry Andric // Accessing index RegNo in the register class will work in the case that
1032cab237bSDimitry Andric // registers were added in ascending order, but not in general.
1042cab237bSDimitry Andric unsigned Reg = FPR32DecoderTable[RegNo];
1052cab237bSDimitry Andric Inst.addOperand(MCOperand::createReg(Reg));
1062cab237bSDimitry Andric return MCDisassembler::Success;
1072cab237bSDimitry Andric }
1082cab237bSDimitry Andric
DecodeFPR32CRegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)1092cab237bSDimitry Andric static DecodeStatus DecodeFPR32CRegisterClass(MCInst &Inst, uint64_t RegNo,
1102cab237bSDimitry Andric uint64_t Address,
1112cab237bSDimitry Andric const void *Decoder) {
1122cab237bSDimitry Andric if (RegNo > 8) {
1132cab237bSDimitry Andric return MCDisassembler::Fail;
1142cab237bSDimitry Andric }
1152cab237bSDimitry Andric unsigned Reg = FPR32DecoderTable[RegNo + 8];
1162cab237bSDimitry Andric Inst.addOperand(MCOperand::createReg(Reg));
1172cab237bSDimitry Andric return MCDisassembler::Success;
1182cab237bSDimitry Andric }
1192cab237bSDimitry Andric
1202cab237bSDimitry Andric static const unsigned FPR64DecoderTable[] = {
1212cab237bSDimitry Andric RISCV::F0_64, RISCV::F1_64, RISCV::F2_64, RISCV::F3_64,
1222cab237bSDimitry Andric RISCV::F4_64, RISCV::F5_64, RISCV::F6_64, RISCV::F7_64,
1232cab237bSDimitry Andric RISCV::F8_64, RISCV::F9_64, RISCV::F10_64, RISCV::F11_64,
1242cab237bSDimitry Andric RISCV::F12_64, RISCV::F13_64, RISCV::F14_64, RISCV::F15_64,
1252cab237bSDimitry Andric RISCV::F16_64, RISCV::F17_64, RISCV::F18_64, RISCV::F19_64,
1262cab237bSDimitry Andric RISCV::F20_64, RISCV::F21_64, RISCV::F22_64, RISCV::F23_64,
1272cab237bSDimitry Andric RISCV::F24_64, RISCV::F25_64, RISCV::F26_64, RISCV::F27_64,
1282cab237bSDimitry Andric RISCV::F28_64, RISCV::F29_64, RISCV::F30_64, RISCV::F31_64
1292cab237bSDimitry Andric };
1302cab237bSDimitry Andric
DecodeFPR64RegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)1312cab237bSDimitry Andric static DecodeStatus DecodeFPR64RegisterClass(MCInst &Inst, uint64_t RegNo,
1322cab237bSDimitry Andric uint64_t Address,
1332cab237bSDimitry Andric const void *Decoder) {
1342cab237bSDimitry Andric if (RegNo > sizeof(FPR64DecoderTable))
1352cab237bSDimitry Andric return MCDisassembler::Fail;
1362cab237bSDimitry Andric
1372cab237bSDimitry Andric // We must define our own mapping from RegNo to register identifier.
1382cab237bSDimitry Andric // Accessing index RegNo in the register class will work in the case that
1392cab237bSDimitry Andric // registers were added in ascending order, but not in general.
1402cab237bSDimitry Andric unsigned Reg = FPR64DecoderTable[RegNo];
1412cab237bSDimitry Andric Inst.addOperand(MCOperand::createReg(Reg));
1422cab237bSDimitry Andric return MCDisassembler::Success;
1432cab237bSDimitry Andric }
1442cab237bSDimitry Andric
DecodeFPR64CRegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)1452cab237bSDimitry Andric static DecodeStatus DecodeFPR64CRegisterClass(MCInst &Inst, uint64_t RegNo,
1462cab237bSDimitry Andric uint64_t Address,
1472cab237bSDimitry Andric const void *Decoder) {
1482cab237bSDimitry Andric if (RegNo > 8) {
1492cab237bSDimitry Andric return MCDisassembler::Fail;
1502cab237bSDimitry Andric }
1512cab237bSDimitry Andric unsigned Reg = FPR64DecoderTable[RegNo + 8];
1522cab237bSDimitry Andric Inst.addOperand(MCOperand::createReg(Reg));
1532cab237bSDimitry Andric return MCDisassembler::Success;
1542cab237bSDimitry Andric }
1552cab237bSDimitry Andric
DecodeGPRNoX0RegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)1562cab237bSDimitry Andric static DecodeStatus DecodeGPRNoX0RegisterClass(MCInst &Inst, uint64_t RegNo,
1572cab237bSDimitry Andric uint64_t Address,
1582cab237bSDimitry Andric const void *Decoder) {
1592cab237bSDimitry Andric if (RegNo == 0) {
1602cab237bSDimitry Andric return MCDisassembler::Fail;
1612cab237bSDimitry Andric }
1622cab237bSDimitry Andric
1632cab237bSDimitry Andric return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
1642cab237bSDimitry Andric }
1652cab237bSDimitry Andric
DecodeGPRNoX0X2RegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)1662cab237bSDimitry Andric static DecodeStatus DecodeGPRNoX0X2RegisterClass(MCInst &Inst, uint64_t RegNo,
1672cab237bSDimitry Andric uint64_t Address,
1682cab237bSDimitry Andric const void *Decoder) {
1692cab237bSDimitry Andric if (RegNo == 2) {
1702cab237bSDimitry Andric return MCDisassembler::Fail;
1712cab237bSDimitry Andric }
1722cab237bSDimitry Andric
1732cab237bSDimitry Andric return DecodeGPRNoX0RegisterClass(Inst, RegNo, Address, Decoder);
1742cab237bSDimitry Andric }
1752cab237bSDimitry Andric
DecodeGPRCRegisterClass(MCInst & Inst,uint64_t RegNo,uint64_t Address,const void * Decoder)1762cab237bSDimitry Andric static DecodeStatus DecodeGPRCRegisterClass(MCInst &Inst, uint64_t RegNo,
1772cab237bSDimitry Andric uint64_t Address,
1782cab237bSDimitry Andric const void *Decoder) {
1792cab237bSDimitry Andric if (RegNo > 8)
1802cab237bSDimitry Andric return MCDisassembler::Fail;
1812cab237bSDimitry Andric
1822cab237bSDimitry Andric unsigned Reg = GPRDecoderTable[RegNo + 8];
1832cab237bSDimitry Andric Inst.addOperand(MCOperand::createReg(Reg));
1842cab237bSDimitry Andric return MCDisassembler::Success;
1852cab237bSDimitry Andric }
1862cab237bSDimitry Andric
1872cab237bSDimitry Andric // Add implied SP operand for instructions *SP compressed instructions. The SP
1882cab237bSDimitry Andric // operand isn't explicitly encoded in the instruction.
addImplySP(MCInst & Inst,int64_t Address,const void * Decoder)1892cab237bSDimitry Andric static void addImplySP(MCInst &Inst, int64_t Address, const void *Decoder) {
1902cab237bSDimitry Andric if (Inst.getOpcode() == RISCV::C_LWSP || Inst.getOpcode() == RISCV::C_SWSP ||
1912cab237bSDimitry Andric Inst.getOpcode() == RISCV::C_LDSP || Inst.getOpcode() == RISCV::C_SDSP ||
1922cab237bSDimitry Andric Inst.getOpcode() == RISCV::C_FLWSP ||
1932cab237bSDimitry Andric Inst.getOpcode() == RISCV::C_FSWSP ||
1942cab237bSDimitry Andric Inst.getOpcode() == RISCV::C_FLDSP ||
1952cab237bSDimitry Andric Inst.getOpcode() == RISCV::C_FSDSP ||
1962cab237bSDimitry Andric Inst.getOpcode() == RISCV::C_ADDI4SPN) {
1972cab237bSDimitry Andric DecodeGPRRegisterClass(Inst, 2, Address, Decoder);
1982cab237bSDimitry Andric }
1992cab237bSDimitry Andric if (Inst.getOpcode() == RISCV::C_ADDI16SP) {
2002cab237bSDimitry Andric DecodeGPRRegisterClass(Inst, 2, Address, Decoder);
2012cab237bSDimitry Andric DecodeGPRRegisterClass(Inst, 2, Address, Decoder);
2022cab237bSDimitry Andric }
2032cab237bSDimitry Andric }
2042cab237bSDimitry Andric
2052cab237bSDimitry Andric template <unsigned N>
decodeUImmOperand(MCInst & Inst,uint64_t Imm,int64_t Address,const void * Decoder)2062cab237bSDimitry Andric static DecodeStatus decodeUImmOperand(MCInst &Inst, uint64_t Imm,
2072cab237bSDimitry Andric int64_t Address, const void *Decoder) {
2082cab237bSDimitry Andric assert(isUInt<N>(Imm) && "Invalid immediate");
2092cab237bSDimitry Andric addImplySP(Inst, Address, Decoder);
2102cab237bSDimitry Andric Inst.addOperand(MCOperand::createImm(Imm));
2112cab237bSDimitry Andric return MCDisassembler::Success;
2122cab237bSDimitry Andric }
2132cab237bSDimitry Andric
2142cab237bSDimitry Andric template <unsigned N>
decodeUImmNonZeroOperand(MCInst & Inst,uint64_t Imm,int64_t Address,const void * Decoder)215*b5893f02SDimitry Andric static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint64_t Imm,
216*b5893f02SDimitry Andric int64_t Address,
217*b5893f02SDimitry Andric const void *Decoder) {
218*b5893f02SDimitry Andric if (Imm == 0)
219*b5893f02SDimitry Andric return MCDisassembler::Fail;
220*b5893f02SDimitry Andric return decodeUImmOperand<N>(Inst, Imm, Address, Decoder);
221*b5893f02SDimitry Andric }
222*b5893f02SDimitry Andric
223*b5893f02SDimitry Andric template <unsigned N>
decodeSImmOperand(MCInst & Inst,uint64_t Imm,int64_t Address,const void * Decoder)2242cab237bSDimitry Andric static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm,
2252cab237bSDimitry Andric int64_t Address, const void *Decoder) {
2262cab237bSDimitry Andric assert(isUInt<N>(Imm) && "Invalid immediate");
2272cab237bSDimitry Andric addImplySP(Inst, Address, Decoder);
2282cab237bSDimitry Andric // Sign-extend the number in the bottom N bits of Imm
2292cab237bSDimitry Andric Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm)));
2302cab237bSDimitry Andric return MCDisassembler::Success;
2312cab237bSDimitry Andric }
2322cab237bSDimitry Andric
2332cab237bSDimitry Andric template <unsigned N>
decodeSImmNonZeroOperand(MCInst & Inst,uint64_t Imm,int64_t Address,const void * Decoder)234*b5893f02SDimitry Andric static DecodeStatus decodeSImmNonZeroOperand(MCInst &Inst, uint64_t Imm,
235*b5893f02SDimitry Andric int64_t Address,
236*b5893f02SDimitry Andric const void *Decoder) {
237*b5893f02SDimitry Andric if (Imm == 0)
238*b5893f02SDimitry Andric return MCDisassembler::Fail;
239*b5893f02SDimitry Andric return decodeSImmOperand<N>(Inst, Imm, Address, Decoder);
240*b5893f02SDimitry Andric }
241*b5893f02SDimitry Andric
242*b5893f02SDimitry Andric template <unsigned N>
decodeSImmOperandAndLsl1(MCInst & Inst,uint64_t Imm,int64_t Address,const void * Decoder)2432cab237bSDimitry Andric static DecodeStatus decodeSImmOperandAndLsl1(MCInst &Inst, uint64_t Imm,
2442cab237bSDimitry Andric int64_t Address,
2452cab237bSDimitry Andric const void *Decoder) {
2462cab237bSDimitry Andric assert(isUInt<N>(Imm) && "Invalid immediate");
2472cab237bSDimitry Andric // Sign-extend the number in the bottom N bits of Imm after accounting for
2482cab237bSDimitry Andric // the fact that the N bit immediate is stored in N-1 bits (the LSB is
2492cab237bSDimitry Andric // always zero)
2502cab237bSDimitry Andric Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm << 1)));
2512cab237bSDimitry Andric return MCDisassembler::Success;
2522cab237bSDimitry Andric }
2532cab237bSDimitry Andric
decodeCLUIImmOperand(MCInst & Inst,uint64_t Imm,int64_t Address,const void * Decoder)2544ba319b5SDimitry Andric static DecodeStatus decodeCLUIImmOperand(MCInst &Inst, uint64_t Imm,
2554ba319b5SDimitry Andric int64_t Address,
2564ba319b5SDimitry Andric const void *Decoder) {
2574ba319b5SDimitry Andric assert(isUInt<6>(Imm) && "Invalid immediate");
2584ba319b5SDimitry Andric if (Imm > 31) {
2594ba319b5SDimitry Andric Imm = (SignExtend64<6>(Imm) & 0xfffff);
2604ba319b5SDimitry Andric }
2614ba319b5SDimitry Andric Inst.addOperand(MCOperand::createImm(Imm));
2624ba319b5SDimitry Andric return MCDisassembler::Success;
2634ba319b5SDimitry Andric }
2644ba319b5SDimitry Andric
decodeFRMArg(MCInst & Inst,uint64_t Imm,int64_t Address,const void * Decoder)265*b5893f02SDimitry Andric static DecodeStatus decodeFRMArg(MCInst &Inst, uint64_t Imm,
266*b5893f02SDimitry Andric int64_t Address,
267*b5893f02SDimitry Andric const void *Decoder) {
268*b5893f02SDimitry Andric assert(isUInt<3>(Imm) && "Invalid immediate");
269*b5893f02SDimitry Andric if (!llvm::RISCVFPRndMode::isValidRoundingMode(Imm))
270*b5893f02SDimitry Andric return MCDisassembler::Fail;
271*b5893f02SDimitry Andric
272*b5893f02SDimitry Andric Inst.addOperand(MCOperand::createImm(Imm));
273*b5893f02SDimitry Andric return MCDisassembler::Success;
274*b5893f02SDimitry Andric }
275*b5893f02SDimitry Andric
2762cab237bSDimitry Andric #include "RISCVGenDisassemblerTables.inc"
2772cab237bSDimitry Andric
getInstruction(MCInst & MI,uint64_t & Size,ArrayRef<uint8_t> Bytes,uint64_t Address,raw_ostream & OS,raw_ostream & CS) const2782cab237bSDimitry Andric DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
2792cab237bSDimitry Andric ArrayRef<uint8_t> Bytes,
2802cab237bSDimitry Andric uint64_t Address,
2812cab237bSDimitry Andric raw_ostream &OS,
2822cab237bSDimitry Andric raw_ostream &CS) const {
2832cab237bSDimitry Andric // TODO: This will need modification when supporting instruction set
2842cab237bSDimitry Andric // extensions with instructions > 32-bits (up to 176 bits wide).
2852cab237bSDimitry Andric uint32_t Insn;
2862cab237bSDimitry Andric DecodeStatus Result;
2872cab237bSDimitry Andric
2882cab237bSDimitry Andric // It's a 32 bit instruction if bit 0 and 1 are 1.
2892cab237bSDimitry Andric if ((Bytes[0] & 0x3) == 0x3) {
290*b5893f02SDimitry Andric if (Bytes.size() < 4) {
291*b5893f02SDimitry Andric Size = 0;
292*b5893f02SDimitry Andric return MCDisassembler::Fail;
293*b5893f02SDimitry Andric }
2942cab237bSDimitry Andric Insn = support::endian::read32le(Bytes.data());
2954ba319b5SDimitry Andric LLVM_DEBUG(dbgs() << "Trying RISCV32 table :\n");
2962cab237bSDimitry Andric Result = decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI);
2972cab237bSDimitry Andric Size = 4;
2982cab237bSDimitry Andric } else {
299*b5893f02SDimitry Andric if (Bytes.size() < 2) {
300*b5893f02SDimitry Andric Size = 0;
301*b5893f02SDimitry Andric return MCDisassembler::Fail;
302*b5893f02SDimitry Andric }
3032cab237bSDimitry Andric Insn = support::endian::read16le(Bytes.data());
3042cab237bSDimitry Andric
3052cab237bSDimitry Andric if (!STI.getFeatureBits()[RISCV::Feature64Bit]) {
3064ba319b5SDimitry Andric LLVM_DEBUG(
3074ba319b5SDimitry Andric dbgs() << "Trying RISCV32Only_16 table (16-bit Instruction):\n");
3082cab237bSDimitry Andric // Calling the auto-generated decoder function.
3092cab237bSDimitry Andric Result = decodeInstruction(DecoderTableRISCV32Only_16, MI, Insn, Address,
3102cab237bSDimitry Andric this, STI);
3112cab237bSDimitry Andric if (Result != MCDisassembler::Fail) {
3122cab237bSDimitry Andric Size = 2;
3132cab237bSDimitry Andric return Result;
3142cab237bSDimitry Andric }
3152cab237bSDimitry Andric }
3162cab237bSDimitry Andric
3174ba319b5SDimitry Andric LLVM_DEBUG(dbgs() << "Trying RISCV_C table (16-bit Instruction):\n");
3182cab237bSDimitry Andric // Calling the auto-generated decoder function.
3192cab237bSDimitry Andric Result = decodeInstruction(DecoderTable16, MI, Insn, Address, this, STI);
3202cab237bSDimitry Andric Size = 2;
3212cab237bSDimitry Andric }
3222cab237bSDimitry Andric
3232cab237bSDimitry Andric return Result;
3242cab237bSDimitry Andric }
325