12345347eSHal Finkel //===------ PPCDisassembler.cpp - Disassembler for PowerPC ------*- C++ -*-===//
22345347eSHal Finkel //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
62345347eSHal Finkel //
72345347eSHal Finkel //===----------------------------------------------------------------------===//
82345347eSHal Finkel 
927c769d2SBenjamin Kramer #include "MCTargetDesc/PPCMCTargetDesc.h"
10f57c1977SBenjamin Kramer #include "llvm/MC/MCDisassembler/MCDisassembler.h"
112345347eSHal Finkel #include "llvm/MC/MCFixedLenDisassembler.h"
122345347eSHal Finkel #include "llvm/MC/MCInst.h"
132345347eSHal Finkel #include "llvm/MC/MCSubtargetInfo.h"
14c11fd3e7SBenjamin Kramer #include "llvm/Support/Endian.h"
152345347eSHal Finkel #include "llvm/Support/TargetRegistry.h"
162345347eSHal Finkel 
172345347eSHal Finkel using namespace llvm;
182345347eSHal Finkel 
190dad994aSNemanja Ivanovic DEFINE_PPC_REGCLASSES;
200dad994aSNemanja Ivanovic 
21e96dd897SChandler Carruth #define DEBUG_TYPE "ppc-disassembler"
22e96dd897SChandler Carruth 
232345347eSHal Finkel typedef MCDisassembler::DecodeStatus DecodeStatus;
242345347eSHal Finkel 
252345347eSHal Finkel namespace {
262345347eSHal Finkel class PPCDisassembler : public MCDisassembler {
27c11fd3e7SBenjamin Kramer   bool IsLittleEndian;
28c11fd3e7SBenjamin Kramer 
292345347eSHal Finkel public:
30c11fd3e7SBenjamin Kramer   PPCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
31c11fd3e7SBenjamin Kramer                   bool IsLittleEndian)
32c11fd3e7SBenjamin Kramer       : MCDisassembler(STI, Ctx), IsLittleEndian(IsLittleEndian) {}
332345347eSHal Finkel 
344aa6bea7SRafael Espindola   DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
357fc5b874SRafael Espindola                               ArrayRef<uint8_t> Bytes, uint64_t Address,
364aa6bea7SRafael Espindola                               raw_ostream &VStream,
374aa6bea7SRafael Espindola                               raw_ostream &CStream) const override;
382345347eSHal Finkel };
392345347eSHal Finkel } // end anonymous namespace
402345347eSHal Finkel 
412345347eSHal Finkel static MCDisassembler *createPPCDisassembler(const Target &T,
42a1bc0f56SLang Hames                                              const MCSubtargetInfo &STI,
43a1bc0f56SLang Hames                                              MCContext &Ctx) {
44c11fd3e7SBenjamin Kramer   return new PPCDisassembler(STI, Ctx, /*IsLittleEndian=*/false);
45c11fd3e7SBenjamin Kramer }
46c11fd3e7SBenjamin Kramer 
47c11fd3e7SBenjamin Kramer static MCDisassembler *createPPCLEDisassembler(const Target &T,
48c11fd3e7SBenjamin Kramer                                                const MCSubtargetInfo &STI,
49c11fd3e7SBenjamin Kramer                                                MCContext &Ctx) {
50c11fd3e7SBenjamin Kramer   return new PPCDisassembler(STI, Ctx, /*IsLittleEndian=*/true);
512345347eSHal Finkel }
522345347eSHal Finkel 
532345347eSHal Finkel extern "C" void LLVMInitializePowerPCDisassembler() {
542345347eSHal Finkel   // Register the disassembler for each target.
55f42454b9SMehdi Amini   TargetRegistry::RegisterMCDisassembler(getThePPC32Target(),
562345347eSHal Finkel                                          createPPCDisassembler);
57f42454b9SMehdi Amini   TargetRegistry::RegisterMCDisassembler(getThePPC64Target(),
582345347eSHal Finkel                                          createPPCDisassembler);
59f42454b9SMehdi Amini   TargetRegistry::RegisterMCDisassembler(getThePPC64LETarget(),
60c11fd3e7SBenjamin Kramer                                          createPPCLEDisassembler);
612345347eSHal Finkel }
622345347eSHal Finkel 
63*c0694520SSean Fertile static DecodeStatus DecodePCRel24BranchTarget(MCInst &Inst, unsigned Imm,
64*c0694520SSean Fertile                                               uint64_t Addr,
65*c0694520SSean Fertile                                               const void *Decoder) {
66*c0694520SSean Fertile   int32_t Offset = SignExtend32<24>(Imm);
67*c0694520SSean Fertile   Inst.addOperand(MCOperand::createImm(Offset));
68*c0694520SSean Fertile   return MCDisassembler::Success;
69*c0694520SSean Fertile }
70*c0694520SSean Fertile 
712345347eSHal Finkel // FIXME: These can be generated by TableGen from the existing register
722345347eSHal Finkel // encoding values!
732345347eSHal Finkel 
742345347eSHal Finkel template <std::size_t N>
752345347eSHal Finkel static DecodeStatus decodeRegisterClass(MCInst &Inst, uint64_t RegNo,
760dad994aSNemanja Ivanovic                                         const MCPhysReg (&Regs)[N]) {
772345347eSHal Finkel   assert(RegNo < N && "Invalid register number");
78e9119e41SJim Grosbach   Inst.addOperand(MCOperand::createReg(Regs[RegNo]));
792345347eSHal Finkel   return MCDisassembler::Success;
802345347eSHal Finkel }
812345347eSHal Finkel 
822345347eSHal Finkel static DecodeStatus DecodeCRRCRegisterClass(MCInst &Inst, uint64_t RegNo,
832345347eSHal Finkel                                             uint64_t Address,
842345347eSHal Finkel                                             const void *Decoder) {
852345347eSHal Finkel   return decodeRegisterClass(Inst, RegNo, CRRegs);
862345347eSHal Finkel }
872345347eSHal Finkel 
88535e69deSKit Barton static DecodeStatus DecodeCRRC0RegisterClass(MCInst &Inst, uint64_t RegNo,
89535e69deSKit Barton                                             uint64_t Address,
90535e69deSKit Barton                                             const void *Decoder) {
91535e69deSKit Barton   return decodeRegisterClass(Inst, RegNo, CRRegs);
92535e69deSKit Barton }
93535e69deSKit Barton 
942345347eSHal Finkel static DecodeStatus DecodeCRBITRCRegisterClass(MCInst &Inst, uint64_t RegNo,
952345347eSHal Finkel                                             uint64_t Address,
962345347eSHal Finkel                                             const void *Decoder) {
972345347eSHal Finkel   return decodeRegisterClass(Inst, RegNo, CRBITRegs);
982345347eSHal Finkel }
992345347eSHal Finkel 
1002345347eSHal Finkel static DecodeStatus DecodeF4RCRegisterClass(MCInst &Inst, uint64_t RegNo,
1012345347eSHal Finkel                                             uint64_t Address,
1022345347eSHal Finkel                                             const void *Decoder) {
1032345347eSHal Finkel   return decodeRegisterClass(Inst, RegNo, FRegs);
1042345347eSHal Finkel }
1052345347eSHal Finkel 
1062345347eSHal Finkel static DecodeStatus DecodeF8RCRegisterClass(MCInst &Inst, uint64_t RegNo,
1072345347eSHal Finkel                                             uint64_t Address,
1082345347eSHal Finkel                                             const void *Decoder) {
1092345347eSHal Finkel   return decodeRegisterClass(Inst, RegNo, FRegs);
1102345347eSHal Finkel }
1112345347eSHal Finkel 
11211049f8fSNemanja Ivanovic static DecodeStatus DecodeVFRCRegisterClass(MCInst &Inst, uint64_t RegNo,
11311049f8fSNemanja Ivanovic                                             uint64_t Address,
11411049f8fSNemanja Ivanovic                                             const void *Decoder) {
11511049f8fSNemanja Ivanovic   return decodeRegisterClass(Inst, RegNo, VFRegs);
11611049f8fSNemanja Ivanovic }
11711049f8fSNemanja Ivanovic 
1182345347eSHal Finkel static DecodeStatus DecodeVRRCRegisterClass(MCInst &Inst, uint64_t RegNo,
1192345347eSHal Finkel                                             uint64_t Address,
1202345347eSHal Finkel                                             const void *Decoder) {
1212345347eSHal Finkel   return decodeRegisterClass(Inst, RegNo, VRegs);
1222345347eSHal Finkel }
1232345347eSHal Finkel 
12427774d92SHal Finkel static DecodeStatus DecodeVSRCRegisterClass(MCInst &Inst, uint64_t RegNo,
12527774d92SHal Finkel                                             uint64_t Address,
12627774d92SHal Finkel                                             const void *Decoder) {
12727774d92SHal Finkel   return decodeRegisterClass(Inst, RegNo, VSRegs);
12827774d92SHal Finkel }
12927774d92SHal Finkel 
13019be506aSHal Finkel static DecodeStatus DecodeVSFRCRegisterClass(MCInst &Inst, uint64_t RegNo,
13119be506aSHal Finkel                                             uint64_t Address,
13219be506aSHal Finkel                                             const void *Decoder) {
13319be506aSHal Finkel   return decodeRegisterClass(Inst, RegNo, VSFRegs);
13419be506aSHal Finkel }
13519be506aSHal Finkel 
136f3c94b1eSNemanja Ivanovic static DecodeStatus DecodeVSSRCRegisterClass(MCInst &Inst, uint64_t RegNo,
137f3c94b1eSNemanja Ivanovic                                             uint64_t Address,
138f3c94b1eSNemanja Ivanovic                                             const void *Decoder) {
139f3c94b1eSNemanja Ivanovic   return decodeRegisterClass(Inst, RegNo, VSSRegs);
140f3c94b1eSNemanja Ivanovic }
141f3c94b1eSNemanja Ivanovic 
1422345347eSHal Finkel static DecodeStatus DecodeGPRCRegisterClass(MCInst &Inst, uint64_t RegNo,
1432345347eSHal Finkel                                             uint64_t Address,
1442345347eSHal Finkel                                             const void *Decoder) {
1450dad994aSNemanja Ivanovic   return decodeRegisterClass(Inst, RegNo, RRegs);
1462345347eSHal Finkel }
1472345347eSHal Finkel 
1482345347eSHal Finkel static DecodeStatus DecodeGPRC_NOR0RegisterClass(MCInst &Inst, uint64_t RegNo,
1492345347eSHal Finkel                                             uint64_t Address,
1502345347eSHal Finkel                                             const void *Decoder) {
1510dad994aSNemanja Ivanovic   return decodeRegisterClass(Inst, RegNo, RRegsNoR0);
1522345347eSHal Finkel }
1532345347eSHal Finkel 
1542345347eSHal Finkel static DecodeStatus DecodeG8RCRegisterClass(MCInst &Inst, uint64_t RegNo,
1552345347eSHal Finkel                                             uint64_t Address,
1562345347eSHal Finkel                                             const void *Decoder) {
1570dad994aSNemanja Ivanovic   return decodeRegisterClass(Inst, RegNo, XRegs);
1582345347eSHal Finkel }
1592345347eSHal Finkel 
16022e7da95SGuozhi Wei static DecodeStatus DecodeG8RC_NOX0RegisterClass(MCInst &Inst, uint64_t RegNo,
16122e7da95SGuozhi Wei                                             uint64_t Address,
16222e7da95SGuozhi Wei                                             const void *Decoder) {
1630dad994aSNemanja Ivanovic   return decodeRegisterClass(Inst, RegNo, XRegsNoX0);
16422e7da95SGuozhi Wei }
16522e7da95SGuozhi Wei 
1662345347eSHal Finkel #define DecodePointerLikeRegClass0 DecodeGPRCRegisterClass
1672345347eSHal Finkel #define DecodePointerLikeRegClass1 DecodeGPRC_NOR0RegisterClass
1682345347eSHal Finkel 
169c93a9a2cSHal Finkel static DecodeStatus DecodeQFRCRegisterClass(MCInst &Inst, uint64_t RegNo,
170c93a9a2cSHal Finkel                                             uint64_t Address,
171c93a9a2cSHal Finkel                                             const void *Decoder) {
172c93a9a2cSHal Finkel   return decodeRegisterClass(Inst, RegNo, QFRegs);
173c93a9a2cSHal Finkel }
174c93a9a2cSHal Finkel 
175d52990c7SJustin Hibbits static DecodeStatus DecodeSPE4RCRegisterClass(MCInst &Inst, uint64_t RegNo,
176d52990c7SJustin Hibbits                                             uint64_t Address,
177d52990c7SJustin Hibbits                                             const void *Decoder) {
1780dad994aSNemanja Ivanovic   return decodeRegisterClass(Inst, RegNo, RRegs);
179d52990c7SJustin Hibbits }
180d52990c7SJustin Hibbits 
181d52990c7SJustin Hibbits static DecodeStatus DecodeSPERCRegisterClass(MCInst &Inst, uint64_t RegNo,
182d52990c7SJustin Hibbits                                             uint64_t Address,
183d52990c7SJustin Hibbits                                             const void *Decoder) {
184d52990c7SJustin Hibbits   return decodeRegisterClass(Inst, RegNo, SPERegs);
185d52990c7SJustin Hibbits }
186d52990c7SJustin Hibbits 
187c93a9a2cSHal Finkel #define DecodeQSRCRegisterClass DecodeQFRCRegisterClass
188c93a9a2cSHal Finkel #define DecodeQBRCRegisterClass DecodeQFRCRegisterClass
189c93a9a2cSHal Finkel 
1902345347eSHal Finkel template<unsigned N>
1912345347eSHal Finkel static DecodeStatus decodeUImmOperand(MCInst &Inst, uint64_t Imm,
1922345347eSHal Finkel                                       int64_t Address, const void *Decoder) {
1932345347eSHal Finkel   assert(isUInt<N>(Imm) && "Invalid immediate");
194e9119e41SJim Grosbach   Inst.addOperand(MCOperand::createImm(Imm));
1952345347eSHal Finkel   return MCDisassembler::Success;
1962345347eSHal Finkel }
1972345347eSHal Finkel 
1982345347eSHal Finkel template<unsigned N>
1992345347eSHal Finkel static DecodeStatus decodeSImmOperand(MCInst &Inst, uint64_t Imm,
2002345347eSHal Finkel                                       int64_t Address, const void *Decoder) {
2012345347eSHal Finkel   assert(isUInt<N>(Imm) && "Invalid immediate");
202e9119e41SJim Grosbach   Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm)));
2032345347eSHal Finkel   return MCDisassembler::Success;
2042345347eSHal Finkel }
2052345347eSHal Finkel 
2062345347eSHal Finkel static DecodeStatus decodeMemRIOperands(MCInst &Inst, uint64_t Imm,
2072345347eSHal Finkel                                         int64_t Address, const void *Decoder) {
2082345347eSHal Finkel   // Decode the memri field (imm, reg), which has the low 16-bits as the
2092345347eSHal Finkel   // displacement and the next 5 bits as the register #.
2102345347eSHal Finkel 
2112345347eSHal Finkel   uint64_t Base = Imm >> 16;
2122345347eSHal Finkel   uint64_t Disp = Imm & 0xFFFF;
2132345347eSHal Finkel 
2142345347eSHal Finkel   assert(Base < 32 && "Invalid base register");
2152345347eSHal Finkel 
2162345347eSHal Finkel   switch (Inst.getOpcode()) {
2172345347eSHal Finkel   default: break;
2182345347eSHal Finkel   case PPC::LBZU:
2192345347eSHal Finkel   case PPC::LHAU:
2202345347eSHal Finkel   case PPC::LHZU:
2212345347eSHal Finkel   case PPC::LWZU:
2222345347eSHal Finkel   case PPC::LFSU:
2232345347eSHal Finkel   case PPC::LFDU:
2242345347eSHal Finkel     // Add the tied output operand.
2250dad994aSNemanja Ivanovic     Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
2262345347eSHal Finkel     break;
2272345347eSHal Finkel   case PPC::STBU:
2282345347eSHal Finkel   case PPC::STHU:
2292345347eSHal Finkel   case PPC::STWU:
2302345347eSHal Finkel   case PPC::STFSU:
2312345347eSHal Finkel   case PPC::STFDU:
2320dad994aSNemanja Ivanovic     Inst.insert(Inst.begin(), MCOperand::createReg(RRegsNoR0[Base]));
2332345347eSHal Finkel     break;
2342345347eSHal Finkel   }
2352345347eSHal Finkel 
236e9119e41SJim Grosbach   Inst.addOperand(MCOperand::createImm(SignExtend64<16>(Disp)));
2370dad994aSNemanja Ivanovic   Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
2382345347eSHal Finkel   return MCDisassembler::Success;
2392345347eSHal Finkel }
2402345347eSHal Finkel 
2412345347eSHal Finkel static DecodeStatus decodeMemRIXOperands(MCInst &Inst, uint64_t Imm,
2422345347eSHal Finkel                                          int64_t Address, const void *Decoder) {
2432345347eSHal Finkel   // Decode the memrix field (imm, reg), which has the low 14-bits as the
2442345347eSHal Finkel   // displacement and the next 5 bits as the register #.
2452345347eSHal Finkel 
2462345347eSHal Finkel   uint64_t Base = Imm >> 14;
2472345347eSHal Finkel   uint64_t Disp = Imm & 0x3FFF;
2482345347eSHal Finkel 
2492345347eSHal Finkel   assert(Base < 32 && "Invalid base register");
2502345347eSHal Finkel 
2512345347eSHal Finkel   if (Inst.getOpcode() == PPC::LDU)
2522345347eSHal Finkel     // Add the tied output operand.
2530dad994aSNemanja Ivanovic     Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
2542345347eSHal Finkel   else if (Inst.getOpcode() == PPC::STDU)
2550dad994aSNemanja Ivanovic     Inst.insert(Inst.begin(), MCOperand::createReg(RRegsNoR0[Base]));
2562345347eSHal Finkel 
257e9119e41SJim Grosbach   Inst.addOperand(MCOperand::createImm(SignExtend64<16>(Disp << 2)));
2580dad994aSNemanja Ivanovic   Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
2592345347eSHal Finkel   return MCDisassembler::Success;
2602345347eSHal Finkel }
2612345347eSHal Finkel 
262ba532dc8SKit Barton static DecodeStatus decodeMemRIX16Operands(MCInst &Inst, uint64_t Imm,
263ba532dc8SKit Barton                                          int64_t Address, const void *Decoder) {
264ba532dc8SKit Barton   // Decode the memrix16 field (imm, reg), which has the low 12-bits as the
265ba532dc8SKit Barton   // displacement with 16-byte aligned, and the next 5 bits as the register #.
266ba532dc8SKit Barton 
267ba532dc8SKit Barton   uint64_t Base = Imm >> 12;
268ba532dc8SKit Barton   uint64_t Disp = Imm & 0xFFF;
269ba532dc8SKit Barton 
270ba532dc8SKit Barton   assert(Base < 32 && "Invalid base register");
271ba532dc8SKit Barton 
272ba532dc8SKit Barton   Inst.addOperand(MCOperand::createImm(SignExtend64<16>(Disp << 4)));
2730dad994aSNemanja Ivanovic   Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
274ba532dc8SKit Barton   return MCDisassembler::Success;
275ba532dc8SKit Barton }
276ba532dc8SKit Barton 
2774fa4fa6aSJustin Hibbits static DecodeStatus decodeSPE8Operands(MCInst &Inst, uint64_t Imm,
2784fa4fa6aSJustin Hibbits                                          int64_t Address, const void *Decoder) {
2794fa4fa6aSJustin Hibbits   // Decode the spe8disp field (imm, reg), which has the low 5-bits as the
2804fa4fa6aSJustin Hibbits   // displacement with 8-byte aligned, and the next 5 bits as the register #.
2814fa4fa6aSJustin Hibbits 
2824fa4fa6aSJustin Hibbits   uint64_t Base = Imm >> 5;
2834fa4fa6aSJustin Hibbits   uint64_t Disp = Imm & 0x1F;
2844fa4fa6aSJustin Hibbits 
2854fa4fa6aSJustin Hibbits   assert(Base < 32 && "Invalid base register");
2864fa4fa6aSJustin Hibbits 
2874fa4fa6aSJustin Hibbits   Inst.addOperand(MCOperand::createImm(Disp << 3));
2880dad994aSNemanja Ivanovic   Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
2894fa4fa6aSJustin Hibbits   return MCDisassembler::Success;
2904fa4fa6aSJustin Hibbits }
2914fa4fa6aSJustin Hibbits 
2924fa4fa6aSJustin Hibbits static DecodeStatus decodeSPE4Operands(MCInst &Inst, uint64_t Imm,
2934fa4fa6aSJustin Hibbits                                          int64_t Address, const void *Decoder) {
2944fa4fa6aSJustin Hibbits   // Decode the spe4disp field (imm, reg), which has the low 5-bits as the
2954fa4fa6aSJustin Hibbits   // displacement with 4-byte aligned, and the next 5 bits as the register #.
2964fa4fa6aSJustin Hibbits 
2974fa4fa6aSJustin Hibbits   uint64_t Base = Imm >> 5;
2984fa4fa6aSJustin Hibbits   uint64_t Disp = Imm & 0x1F;
2994fa4fa6aSJustin Hibbits 
3004fa4fa6aSJustin Hibbits   assert(Base < 32 && "Invalid base register");
3014fa4fa6aSJustin Hibbits 
3024fa4fa6aSJustin Hibbits   Inst.addOperand(MCOperand::createImm(Disp << 2));
3030dad994aSNemanja Ivanovic   Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
3044fa4fa6aSJustin Hibbits   return MCDisassembler::Success;
3054fa4fa6aSJustin Hibbits }
3064fa4fa6aSJustin Hibbits 
3074fa4fa6aSJustin Hibbits static DecodeStatus decodeSPE2Operands(MCInst &Inst, uint64_t Imm,
3084fa4fa6aSJustin Hibbits                                          int64_t Address, const void *Decoder) {
3094fa4fa6aSJustin Hibbits   // Decode the spe2disp field (imm, reg), which has the low 5-bits as the
3104fa4fa6aSJustin Hibbits   // displacement with 2-byte aligned, and the next 5 bits as the register #.
3114fa4fa6aSJustin Hibbits 
3124fa4fa6aSJustin Hibbits   uint64_t Base = Imm >> 5;
3134fa4fa6aSJustin Hibbits   uint64_t Disp = Imm & 0x1F;
3144fa4fa6aSJustin Hibbits 
3154fa4fa6aSJustin Hibbits   assert(Base < 32 && "Invalid base register");
3164fa4fa6aSJustin Hibbits 
3174fa4fa6aSJustin Hibbits   Inst.addOperand(MCOperand::createImm(Disp << 1));
3180dad994aSNemanja Ivanovic   Inst.addOperand(MCOperand::createReg(RRegsNoR0[Base]));
3194fa4fa6aSJustin Hibbits   return MCDisassembler::Success;
3204fa4fa6aSJustin Hibbits }
3214fa4fa6aSJustin Hibbits 
3222345347eSHal Finkel static DecodeStatus decodeCRBitMOperand(MCInst &Inst, uint64_t Imm,
3232345347eSHal Finkel                                         int64_t Address, const void *Decoder) {
3242345347eSHal Finkel   // The cr bit encoding is 0x80 >> cr_reg_num.
3252345347eSHal Finkel 
3262345347eSHal Finkel   unsigned Zeros = countTrailingZeros(Imm);
3272345347eSHal Finkel   assert(Zeros < 8 && "Invalid CR bit value");
3282345347eSHal Finkel 
329e9119e41SJim Grosbach   Inst.addOperand(MCOperand::createReg(CRRegs[7 - Zeros]));
3302345347eSHal Finkel   return MCDisassembler::Success;
3312345347eSHal Finkel }
3322345347eSHal Finkel 
3332345347eSHal Finkel #include "PPCGenDisassemblerTables.inc"
3342345347eSHal Finkel 
3352345347eSHal Finkel DecodeStatus PPCDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
3367fc5b874SRafael Espindola                                              ArrayRef<uint8_t> Bytes,
3374aa6bea7SRafael Espindola                                              uint64_t Address, raw_ostream &OS,
3384aa6bea7SRafael Espindola                                              raw_ostream &CS) const {
3392345347eSHal Finkel   // Get the four bytes of the instruction.
3402345347eSHal Finkel   Size = 4;
3417fc5b874SRafael Espindola   if (Bytes.size() < 4) {
3422345347eSHal Finkel     Size = 0;
3432345347eSHal Finkel     return MCDisassembler::Fail;
3442345347eSHal Finkel   }
3452345347eSHal Finkel 
346c11fd3e7SBenjamin Kramer   // Read the instruction in the proper endianness.
347c11fd3e7SBenjamin Kramer   uint32_t Inst = IsLittleEndian ? support::endian::read32le(Bytes.data())
348c11fd3e7SBenjamin Kramer                                  : support::endian::read32be(Bytes.data());
3492345347eSHal Finkel 
350db0712f9SMichael Kuperstein   if (STI.getFeatureBits()[PPC::FeatureQPX]) {
351c93a9a2cSHal Finkel     DecodeStatus result =
352c93a9a2cSHal Finkel       decodeInstruction(DecoderTableQPX32, MI, Inst, Address, this, STI);
353c93a9a2cSHal Finkel     if (result != MCDisassembler::Fail)
354c93a9a2cSHal Finkel       return result;
3554fa4fa6aSJustin Hibbits   } else if (STI.getFeatureBits()[PPC::FeatureSPE]) {
3564fa4fa6aSJustin Hibbits     DecodeStatus result =
3574fa4fa6aSJustin Hibbits       decodeInstruction(DecoderTableSPE32, MI, Inst, Address, this, STI);
3584fa4fa6aSJustin Hibbits     if (result != MCDisassembler::Fail)
3594fa4fa6aSJustin Hibbits       return result;
360c93a9a2cSHal Finkel   }
361c93a9a2cSHal Finkel 
3622345347eSHal Finkel   return decodeInstruction(DecoderTable32, MI, Inst, Address, this, STI);
3632345347eSHal Finkel }
3642345347eSHal Finkel 
365