xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/VE/Disassembler/VEDisassembler.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
15ffd83dbSDimitry Andric //===- VEDisassembler.cpp - Disassembler for VE -----------------*- C++ -*-===//
25ffd83dbSDimitry Andric //
35ffd83dbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45ffd83dbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55ffd83dbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65ffd83dbSDimitry Andric //
75ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
85ffd83dbSDimitry Andric //
95ffd83dbSDimitry Andric // This file is part of the VE Disassembler.
105ffd83dbSDimitry Andric //
115ffd83dbSDimitry Andric //===----------------------------------------------------------------------===//
125ffd83dbSDimitry Andric 
135ffd83dbSDimitry Andric #include "MCTargetDesc/VEMCTargetDesc.h"
145ffd83dbSDimitry Andric #include "TargetInfo/VETargetInfo.h"
155ffd83dbSDimitry Andric #include "VE.h"
165ffd83dbSDimitry Andric #include "llvm/MC/MCAsmInfo.h"
175ffd83dbSDimitry Andric #include "llvm/MC/MCContext.h"
18*81ad6265SDimitry Andric #include "llvm/MC/MCDecoderOps.h"
195ffd83dbSDimitry Andric #include "llvm/MC/MCDisassembler/MCDisassembler.h"
205ffd83dbSDimitry Andric #include "llvm/MC/MCInst.h"
21349cc55cSDimitry Andric #include "llvm/MC/TargetRegistry.h"
225ffd83dbSDimitry Andric 
235ffd83dbSDimitry Andric using namespace llvm;
245ffd83dbSDimitry Andric 
255ffd83dbSDimitry Andric #define DEBUG_TYPE "ve-disassembler"
265ffd83dbSDimitry Andric 
275ffd83dbSDimitry Andric typedef MCDisassembler::DecodeStatus DecodeStatus;
285ffd83dbSDimitry Andric 
295ffd83dbSDimitry Andric namespace {
305ffd83dbSDimitry Andric 
315ffd83dbSDimitry Andric /// A disassembler class for VE.
325ffd83dbSDimitry Andric class VEDisassembler : public MCDisassembler {
335ffd83dbSDimitry Andric public:
VEDisassembler(const MCSubtargetInfo & STI,MCContext & Ctx)345ffd83dbSDimitry Andric   VEDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx)
355ffd83dbSDimitry Andric       : MCDisassembler(STI, Ctx) {}
36*81ad6265SDimitry Andric   virtual ~VEDisassembler() = default;
375ffd83dbSDimitry Andric 
385ffd83dbSDimitry Andric   DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
395ffd83dbSDimitry Andric                               ArrayRef<uint8_t> Bytes, uint64_t Address,
405ffd83dbSDimitry Andric                               raw_ostream &CStream) const override;
415ffd83dbSDimitry Andric };
425ffd83dbSDimitry Andric } // namespace
435ffd83dbSDimitry Andric 
createVEDisassembler(const Target & T,const MCSubtargetInfo & STI,MCContext & Ctx)445ffd83dbSDimitry Andric static MCDisassembler *createVEDisassembler(const Target &T,
455ffd83dbSDimitry Andric                                             const MCSubtargetInfo &STI,
465ffd83dbSDimitry Andric                                             MCContext &Ctx) {
475ffd83dbSDimitry Andric   return new VEDisassembler(STI, Ctx);
485ffd83dbSDimitry Andric }
495ffd83dbSDimitry Andric 
LLVMInitializeVEDisassembler()50e8d8bef9SDimitry Andric extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeVEDisassembler() {
515ffd83dbSDimitry Andric   // Register the disassembler.
525ffd83dbSDimitry Andric   TargetRegistry::RegisterMCDisassembler(getTheVETarget(),
535ffd83dbSDimitry Andric                                          createVEDisassembler);
545ffd83dbSDimitry Andric }
555ffd83dbSDimitry Andric 
565ffd83dbSDimitry Andric static const unsigned I32RegDecoderTable[] = {
575ffd83dbSDimitry Andric     VE::SW0,  VE::SW1,  VE::SW2,  VE::SW3,  VE::SW4,  VE::SW5,  VE::SW6,
585ffd83dbSDimitry Andric     VE::SW7,  VE::SW8,  VE::SW9,  VE::SW10, VE::SW11, VE::SW12, VE::SW13,
595ffd83dbSDimitry Andric     VE::SW14, VE::SW15, VE::SW16, VE::SW17, VE::SW18, VE::SW19, VE::SW20,
605ffd83dbSDimitry Andric     VE::SW21, VE::SW22, VE::SW23, VE::SW24, VE::SW25, VE::SW26, VE::SW27,
615ffd83dbSDimitry Andric     VE::SW28, VE::SW29, VE::SW30, VE::SW31, VE::SW32, VE::SW33, VE::SW34,
625ffd83dbSDimitry Andric     VE::SW35, VE::SW36, VE::SW37, VE::SW38, VE::SW39, VE::SW40, VE::SW41,
635ffd83dbSDimitry Andric     VE::SW42, VE::SW43, VE::SW44, VE::SW45, VE::SW46, VE::SW47, VE::SW48,
645ffd83dbSDimitry Andric     VE::SW49, VE::SW50, VE::SW51, VE::SW52, VE::SW53, VE::SW54, VE::SW55,
655ffd83dbSDimitry Andric     VE::SW56, VE::SW57, VE::SW58, VE::SW59, VE::SW60, VE::SW61, VE::SW62,
665ffd83dbSDimitry Andric     VE::SW63};
675ffd83dbSDimitry Andric 
685ffd83dbSDimitry Andric static const unsigned I64RegDecoderTable[] = {
695ffd83dbSDimitry Andric     VE::SX0,  VE::SX1,  VE::SX2,  VE::SX3,  VE::SX4,  VE::SX5,  VE::SX6,
705ffd83dbSDimitry Andric     VE::SX7,  VE::SX8,  VE::SX9,  VE::SX10, VE::SX11, VE::SX12, VE::SX13,
715ffd83dbSDimitry Andric     VE::SX14, VE::SX15, VE::SX16, VE::SX17, VE::SX18, VE::SX19, VE::SX20,
725ffd83dbSDimitry Andric     VE::SX21, VE::SX22, VE::SX23, VE::SX24, VE::SX25, VE::SX26, VE::SX27,
735ffd83dbSDimitry Andric     VE::SX28, VE::SX29, VE::SX30, VE::SX31, VE::SX32, VE::SX33, VE::SX34,
745ffd83dbSDimitry Andric     VE::SX35, VE::SX36, VE::SX37, VE::SX38, VE::SX39, VE::SX40, VE::SX41,
755ffd83dbSDimitry Andric     VE::SX42, VE::SX43, VE::SX44, VE::SX45, VE::SX46, VE::SX47, VE::SX48,
765ffd83dbSDimitry Andric     VE::SX49, VE::SX50, VE::SX51, VE::SX52, VE::SX53, VE::SX54, VE::SX55,
775ffd83dbSDimitry Andric     VE::SX56, VE::SX57, VE::SX58, VE::SX59, VE::SX60, VE::SX61, VE::SX62,
785ffd83dbSDimitry Andric     VE::SX63};
795ffd83dbSDimitry Andric 
805ffd83dbSDimitry Andric static const unsigned F32RegDecoderTable[] = {
815ffd83dbSDimitry Andric     VE::SF0,  VE::SF1,  VE::SF2,  VE::SF3,  VE::SF4,  VE::SF5,  VE::SF6,
825ffd83dbSDimitry Andric     VE::SF7,  VE::SF8,  VE::SF9,  VE::SF10, VE::SF11, VE::SF12, VE::SF13,
835ffd83dbSDimitry Andric     VE::SF14, VE::SF15, VE::SF16, VE::SF17, VE::SF18, VE::SF19, VE::SF20,
845ffd83dbSDimitry Andric     VE::SF21, VE::SF22, VE::SF23, VE::SF24, VE::SF25, VE::SF26, VE::SF27,
855ffd83dbSDimitry Andric     VE::SF28, VE::SF29, VE::SF30, VE::SF31, VE::SF32, VE::SF33, VE::SF34,
865ffd83dbSDimitry Andric     VE::SF35, VE::SF36, VE::SF37, VE::SF38, VE::SF39, VE::SF40, VE::SF41,
875ffd83dbSDimitry Andric     VE::SF42, VE::SF43, VE::SF44, VE::SF45, VE::SF46, VE::SF47, VE::SF48,
885ffd83dbSDimitry Andric     VE::SF49, VE::SF50, VE::SF51, VE::SF52, VE::SF53, VE::SF54, VE::SF55,
895ffd83dbSDimitry Andric     VE::SF56, VE::SF57, VE::SF58, VE::SF59, VE::SF60, VE::SF61, VE::SF62,
905ffd83dbSDimitry Andric     VE::SF63};
915ffd83dbSDimitry Andric 
925ffd83dbSDimitry Andric static const unsigned F128RegDecoderTable[] = {
935ffd83dbSDimitry Andric     VE::Q0,  VE::Q1,  VE::Q2,  VE::Q3,  VE::Q4,  VE::Q5,  VE::Q6,  VE::Q7,
945ffd83dbSDimitry Andric     VE::Q8,  VE::Q9,  VE::Q10, VE::Q11, VE::Q12, VE::Q13, VE::Q14, VE::Q15,
955ffd83dbSDimitry Andric     VE::Q16, VE::Q17, VE::Q18, VE::Q19, VE::Q20, VE::Q21, VE::Q22, VE::Q23,
965ffd83dbSDimitry Andric     VE::Q24, VE::Q25, VE::Q26, VE::Q27, VE::Q28, VE::Q29, VE::Q30, VE::Q31};
975ffd83dbSDimitry Andric 
98e8d8bef9SDimitry Andric static const unsigned V64RegDecoderTable[] = {
99e8d8bef9SDimitry Andric     VE::V0,  VE::V1,  VE::V2,  VE::V3,  VE::V4,  VE::V5,  VE::V6,  VE::V7,
100e8d8bef9SDimitry Andric     VE::V8,  VE::V9,  VE::V10, VE::V11, VE::V12, VE::V13, VE::V14, VE::V15,
101e8d8bef9SDimitry Andric     VE::V16, VE::V17, VE::V18, VE::V19, VE::V20, VE::V21, VE::V22, VE::V23,
102e8d8bef9SDimitry Andric     VE::V24, VE::V25, VE::V26, VE::V27, VE::V28, VE::V29, VE::V30, VE::V31,
103e8d8bef9SDimitry Andric     VE::V32, VE::V33, VE::V34, VE::V35, VE::V36, VE::V37, VE::V38, VE::V39,
104e8d8bef9SDimitry Andric     VE::V40, VE::V41, VE::V42, VE::V43, VE::V44, VE::V45, VE::V46, VE::V47,
105e8d8bef9SDimitry Andric     VE::V48, VE::V49, VE::V50, VE::V51, VE::V52, VE::V53, VE::V54, VE::V55,
106e8d8bef9SDimitry Andric     VE::V56, VE::V57, VE::V58, VE::V59, VE::V60, VE::V61, VE::V62, VE::V63};
107e8d8bef9SDimitry Andric 
108e8d8bef9SDimitry Andric static const unsigned VMRegDecoderTable[] = {
109e8d8bef9SDimitry Andric     VE::VM0,  VE::VM1,  VE::VM2,  VE::VM3, VE::VM4,  VE::VM5,
110e8d8bef9SDimitry Andric     VE::VM6,  VE::VM7,  VE::VM8,  VE::VM9, VE::VM10, VE::VM11,
111e8d8bef9SDimitry Andric     VE::VM12, VE::VM13, VE::VM14, VE::VM15};
112e8d8bef9SDimitry Andric 
113e8d8bef9SDimitry Andric static const unsigned VM512RegDecoderTable[] = {VE::VMP0, VE::VMP1, VE::VMP2,
114e8d8bef9SDimitry Andric                                                 VE::VMP3, VE::VMP4, VE::VMP5,
115e8d8bef9SDimitry Andric                                                 VE::VMP6, VE::VMP7};
116e8d8bef9SDimitry Andric 
1175ffd83dbSDimitry Andric static const unsigned MiscRegDecoderTable[] = {
1185ffd83dbSDimitry Andric     VE::USRCC,      VE::PSW,        VE::SAR,        VE::NoRegister,
1195ffd83dbSDimitry Andric     VE::NoRegister, VE::NoRegister, VE::NoRegister, VE::PMMR,
1205ffd83dbSDimitry Andric     VE::PMCR0,      VE::PMCR1,      VE::PMCR2,      VE::PMCR3,
1215ffd83dbSDimitry Andric     VE::NoRegister, VE::NoRegister, VE::NoRegister, VE::NoRegister,
1225ffd83dbSDimitry Andric     VE::PMC0,       VE::PMC1,       VE::PMC2,       VE::PMC3,
1235ffd83dbSDimitry Andric     VE::PMC4,       VE::PMC5,       VE::PMC6,       VE::PMC7,
1245ffd83dbSDimitry Andric     VE::PMC8,       VE::PMC9,       VE::PMC10,      VE::PMC11,
1255ffd83dbSDimitry Andric     VE::PMC12,      VE::PMC13,      VE::PMC14};
1265ffd83dbSDimitry Andric 
DecodeI32RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)1275ffd83dbSDimitry Andric static DecodeStatus DecodeI32RegisterClass(MCInst &Inst, unsigned RegNo,
1285ffd83dbSDimitry Andric                                            uint64_t Address,
129*81ad6265SDimitry Andric                                            const MCDisassembler *Decoder) {
1305ffd83dbSDimitry Andric   if (RegNo > 63)
1315ffd83dbSDimitry Andric     return MCDisassembler::Fail;
1325ffd83dbSDimitry Andric   unsigned Reg = I32RegDecoderTable[RegNo];
1335ffd83dbSDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
1345ffd83dbSDimitry Andric   return MCDisassembler::Success;
1355ffd83dbSDimitry Andric }
1365ffd83dbSDimitry Andric 
DecodeI64RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)1375ffd83dbSDimitry Andric static DecodeStatus DecodeI64RegisterClass(MCInst &Inst, unsigned RegNo,
1385ffd83dbSDimitry Andric                                            uint64_t Address,
139*81ad6265SDimitry Andric                                            const MCDisassembler *Decoder) {
1405ffd83dbSDimitry Andric   if (RegNo > 63)
1415ffd83dbSDimitry Andric     return MCDisassembler::Fail;
1425ffd83dbSDimitry Andric   unsigned Reg = I64RegDecoderTable[RegNo];
1435ffd83dbSDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
1445ffd83dbSDimitry Andric   return MCDisassembler::Success;
1455ffd83dbSDimitry Andric }
1465ffd83dbSDimitry Andric 
DecodeF32RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)1475ffd83dbSDimitry Andric static DecodeStatus DecodeF32RegisterClass(MCInst &Inst, unsigned RegNo,
1485ffd83dbSDimitry Andric                                            uint64_t Address,
149*81ad6265SDimitry Andric                                            const MCDisassembler *Decoder) {
1505ffd83dbSDimitry Andric   if (RegNo > 63)
1515ffd83dbSDimitry Andric     return MCDisassembler::Fail;
1525ffd83dbSDimitry Andric   unsigned Reg = F32RegDecoderTable[RegNo];
1535ffd83dbSDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
1545ffd83dbSDimitry Andric   return MCDisassembler::Success;
1555ffd83dbSDimitry Andric }
1565ffd83dbSDimitry Andric 
DecodeF128RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)1575ffd83dbSDimitry Andric static DecodeStatus DecodeF128RegisterClass(MCInst &Inst, unsigned RegNo,
1585ffd83dbSDimitry Andric                                             uint64_t Address,
159*81ad6265SDimitry Andric                                             const MCDisassembler *Decoder) {
1605ffd83dbSDimitry Andric   if (RegNo % 2 || RegNo > 63)
1615ffd83dbSDimitry Andric     return MCDisassembler::Fail;
1625ffd83dbSDimitry Andric   unsigned Reg = F128RegDecoderTable[RegNo / 2];
1635ffd83dbSDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
1645ffd83dbSDimitry Andric   return MCDisassembler::Success;
1655ffd83dbSDimitry Andric }
1665ffd83dbSDimitry Andric 
DecodeV64RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)167e8d8bef9SDimitry Andric static DecodeStatus DecodeV64RegisterClass(MCInst &Inst, unsigned RegNo,
168e8d8bef9SDimitry Andric                                            uint64_t Address,
169*81ad6265SDimitry Andric                                            const MCDisassembler *Decoder) {
170e8d8bef9SDimitry Andric   unsigned Reg = VE::NoRegister;
171e8d8bef9SDimitry Andric   if (RegNo == 255)
172e8d8bef9SDimitry Andric     Reg = VE::VIX;
173e8d8bef9SDimitry Andric   else if (RegNo > 63)
174e8d8bef9SDimitry Andric     return MCDisassembler::Fail;
175e8d8bef9SDimitry Andric   else
176e8d8bef9SDimitry Andric     Reg = V64RegDecoderTable[RegNo];
177e8d8bef9SDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
178e8d8bef9SDimitry Andric   return MCDisassembler::Success;
179e8d8bef9SDimitry Andric }
180e8d8bef9SDimitry Andric 
DecodeVMRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)181e8d8bef9SDimitry Andric static DecodeStatus DecodeVMRegisterClass(MCInst &Inst, unsigned RegNo,
182e8d8bef9SDimitry Andric                                           uint64_t Address,
183*81ad6265SDimitry Andric                                           const MCDisassembler *Decoder) {
184e8d8bef9SDimitry Andric   if (RegNo > 15)
185e8d8bef9SDimitry Andric     return MCDisassembler::Fail;
186e8d8bef9SDimitry Andric   unsigned Reg = VMRegDecoderTable[RegNo];
187e8d8bef9SDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
188e8d8bef9SDimitry Andric   return MCDisassembler::Success;
189e8d8bef9SDimitry Andric }
190e8d8bef9SDimitry Andric 
DecodeVM512RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)191e8d8bef9SDimitry Andric static DecodeStatus DecodeVM512RegisterClass(MCInst &Inst, unsigned RegNo,
192e8d8bef9SDimitry Andric                                              uint64_t Address,
193*81ad6265SDimitry Andric                                              const MCDisassembler *Decoder) {
194e8d8bef9SDimitry Andric   if (RegNo % 2 || RegNo > 15)
195e8d8bef9SDimitry Andric     return MCDisassembler::Fail;
196e8d8bef9SDimitry Andric   unsigned Reg = VM512RegDecoderTable[RegNo / 2];
197e8d8bef9SDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
198e8d8bef9SDimitry Andric   return MCDisassembler::Success;
199e8d8bef9SDimitry Andric }
200e8d8bef9SDimitry Andric 
DecodeMISCRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Address,const MCDisassembler * Decoder)2015ffd83dbSDimitry Andric static DecodeStatus DecodeMISCRegisterClass(MCInst &Inst, unsigned RegNo,
2025ffd83dbSDimitry Andric                                             uint64_t Address,
203*81ad6265SDimitry Andric                                             const MCDisassembler *Decoder) {
2045ffd83dbSDimitry Andric   if (RegNo > 30)
2055ffd83dbSDimitry Andric     return MCDisassembler::Fail;
2065ffd83dbSDimitry Andric   unsigned Reg = MiscRegDecoderTable[RegNo];
2075ffd83dbSDimitry Andric   if (Reg == VE::NoRegister)
2085ffd83dbSDimitry Andric     return MCDisassembler::Fail;
2095ffd83dbSDimitry Andric   Inst.addOperand(MCOperand::createReg(Reg));
2105ffd83dbSDimitry Andric   return MCDisassembler::Success;
2115ffd83dbSDimitry Andric }
2125ffd83dbSDimitry Andric 
2135ffd83dbSDimitry Andric static DecodeStatus DecodeASX(MCInst &Inst, uint64_t insn, uint64_t Address,
214*81ad6265SDimitry Andric                               const MCDisassembler *Decoder);
2155ffd83dbSDimitry Andric static DecodeStatus DecodeLoadI32(MCInst &Inst, uint64_t insn, uint64_t Address,
216*81ad6265SDimitry Andric                                   const MCDisassembler *Decoder);
2175ffd83dbSDimitry Andric static DecodeStatus DecodeStoreI32(MCInst &Inst, uint64_t insn,
218*81ad6265SDimitry Andric                                    uint64_t Address,
219*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder);
2205ffd83dbSDimitry Andric static DecodeStatus DecodeLoadI64(MCInst &Inst, uint64_t insn, uint64_t Address,
221*81ad6265SDimitry Andric                                   const MCDisassembler *Decoder);
2225ffd83dbSDimitry Andric static DecodeStatus DecodeStoreI64(MCInst &Inst, uint64_t insn,
223*81ad6265SDimitry Andric                                    uint64_t Address,
224*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder);
2255ffd83dbSDimitry Andric static DecodeStatus DecodeLoadF32(MCInst &Inst, uint64_t insn, uint64_t Address,
226*81ad6265SDimitry Andric                                   const MCDisassembler *Decoder);
2275ffd83dbSDimitry Andric static DecodeStatus DecodeStoreF32(MCInst &Inst, uint64_t insn,
228*81ad6265SDimitry Andric                                    uint64_t Address,
229*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder);
2305ffd83dbSDimitry Andric static DecodeStatus DecodeLoadASI64(MCInst &Inst, uint64_t insn,
231*81ad6265SDimitry Andric                                     uint64_t Address,
232*81ad6265SDimitry Andric                                     const MCDisassembler *Decoder);
2335ffd83dbSDimitry Andric static DecodeStatus DecodeStoreASI64(MCInst &Inst, uint64_t insn,
234*81ad6265SDimitry Andric                                      uint64_t Address,
235*81ad6265SDimitry Andric                                      const MCDisassembler *Decoder);
2365ffd83dbSDimitry Andric static DecodeStatus DecodeTS1AMI64(MCInst &Inst, uint64_t insn,
237*81ad6265SDimitry Andric                                    uint64_t Address,
238*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder);
2395ffd83dbSDimitry Andric static DecodeStatus DecodeTS1AMI32(MCInst &Inst, uint64_t insn,
240*81ad6265SDimitry Andric                                    uint64_t Address,
241*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder);
2425ffd83dbSDimitry Andric static DecodeStatus DecodeCASI64(MCInst &Inst, uint64_t insn, uint64_t Address,
243*81ad6265SDimitry Andric                                  const MCDisassembler *Decoder);
2445ffd83dbSDimitry Andric static DecodeStatus DecodeCASI32(MCInst &Inst, uint64_t insn, uint64_t Address,
245*81ad6265SDimitry Andric                                  const MCDisassembler *Decoder);
2465ffd83dbSDimitry Andric static DecodeStatus DecodeCall(MCInst &Inst, uint64_t insn, uint64_t Address,
247*81ad6265SDimitry Andric                                const MCDisassembler *Decoder);
2485ffd83dbSDimitry Andric static DecodeStatus DecodeSIMM7(MCInst &Inst, uint64_t insn, uint64_t Address,
249*81ad6265SDimitry Andric                                 const MCDisassembler *Decoder);
2505ffd83dbSDimitry Andric static DecodeStatus DecodeSIMM32(MCInst &Inst, uint64_t insn, uint64_t Address,
251*81ad6265SDimitry Andric                                  const MCDisassembler *Decoder);
2525ffd83dbSDimitry Andric static DecodeStatus DecodeCCOperand(MCInst &Inst, uint64_t insn,
253*81ad6265SDimitry Andric                                     uint64_t Address,
254*81ad6265SDimitry Andric                                     const MCDisassembler *Decoder);
2555ffd83dbSDimitry Andric static DecodeStatus DecodeRDOperand(MCInst &Inst, uint64_t insn,
256*81ad6265SDimitry Andric                                     uint64_t Address,
257*81ad6265SDimitry Andric                                     const MCDisassembler *Decoder);
2585ffd83dbSDimitry Andric static DecodeStatus DecodeBranchCondition(MCInst &Inst, uint64_t insn,
2595ffd83dbSDimitry Andric                                           uint64_t Address,
260*81ad6265SDimitry Andric                                           const MCDisassembler *Decoder);
2615ffd83dbSDimitry Andric static DecodeStatus DecodeBranchConditionAlways(MCInst &Inst, uint64_t insn,
2625ffd83dbSDimitry Andric                                                 uint64_t Address,
263*81ad6265SDimitry Andric                                                 const MCDisassembler *Decoder);
2645ffd83dbSDimitry Andric 
2655ffd83dbSDimitry Andric #include "VEGenDisassemblerTables.inc"
2665ffd83dbSDimitry Andric 
2675ffd83dbSDimitry Andric /// Read four bytes from the ArrayRef and return 32 bit word.
readInstruction64(ArrayRef<uint8_t> Bytes,uint64_t Address,uint64_t & Size,uint64_t & Insn,bool IsLittleEndian)2685ffd83dbSDimitry Andric static DecodeStatus readInstruction64(ArrayRef<uint8_t> Bytes, uint64_t Address,
2695ffd83dbSDimitry Andric                                       uint64_t &Size, uint64_t &Insn,
2705ffd83dbSDimitry Andric                                       bool IsLittleEndian) {
2715ffd83dbSDimitry Andric   // We want to read exactly 8 Bytes of data.
2725ffd83dbSDimitry Andric   if (Bytes.size() < 8) {
2735ffd83dbSDimitry Andric     Size = 0;
2745ffd83dbSDimitry Andric     return MCDisassembler::Fail;
2755ffd83dbSDimitry Andric   }
2765ffd83dbSDimitry Andric 
2775ffd83dbSDimitry Andric   Insn = IsLittleEndian
2785ffd83dbSDimitry Andric              ? ((uint64_t)Bytes[0] << 0) | ((uint64_t)Bytes[1] << 8) |
2795ffd83dbSDimitry Andric                    ((uint64_t)Bytes[2] << 16) | ((uint64_t)Bytes[3] << 24) |
2805ffd83dbSDimitry Andric                    ((uint64_t)Bytes[4] << 32) | ((uint64_t)Bytes[5] << 40) |
2815ffd83dbSDimitry Andric                    ((uint64_t)Bytes[6] << 48) | ((uint64_t)Bytes[7] << 56)
2825ffd83dbSDimitry Andric              : ((uint64_t)Bytes[7] << 0) | ((uint64_t)Bytes[6] << 8) |
2835ffd83dbSDimitry Andric                    ((uint64_t)Bytes[5] << 16) | ((uint64_t)Bytes[4] << 24) |
2845ffd83dbSDimitry Andric                    ((uint64_t)Bytes[3] << 32) | ((uint64_t)Bytes[2] << 40) |
2855ffd83dbSDimitry Andric                    ((uint64_t)Bytes[1] << 48) | ((uint64_t)Bytes[0] << 56);
2865ffd83dbSDimitry Andric 
2875ffd83dbSDimitry Andric   return MCDisassembler::Success;
2885ffd83dbSDimitry Andric }
2895ffd83dbSDimitry Andric 
getInstruction(MCInst & Instr,uint64_t & Size,ArrayRef<uint8_t> Bytes,uint64_t Address,raw_ostream & CStream) const2905ffd83dbSDimitry Andric DecodeStatus VEDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
2915ffd83dbSDimitry Andric                                             ArrayRef<uint8_t> Bytes,
2925ffd83dbSDimitry Andric                                             uint64_t Address,
2935ffd83dbSDimitry Andric                                             raw_ostream &CStream) const {
2945ffd83dbSDimitry Andric   uint64_t Insn;
2955ffd83dbSDimitry Andric   bool isLittleEndian = getContext().getAsmInfo()->isLittleEndian();
2965ffd83dbSDimitry Andric   DecodeStatus Result =
2975ffd83dbSDimitry Andric       readInstruction64(Bytes, Address, Size, Insn, isLittleEndian);
2985ffd83dbSDimitry Andric   if (Result == MCDisassembler::Fail)
2995ffd83dbSDimitry Andric     return MCDisassembler::Fail;
3005ffd83dbSDimitry Andric 
3015ffd83dbSDimitry Andric   // Calling the auto-generated decoder function.
3025ffd83dbSDimitry Andric 
3035ffd83dbSDimitry Andric   Result = decodeInstruction(DecoderTableVE64, Instr, Insn, Address, this, STI);
3045ffd83dbSDimitry Andric 
3055ffd83dbSDimitry Andric   if (Result != MCDisassembler::Fail) {
3065ffd83dbSDimitry Andric     Size = 8;
3075ffd83dbSDimitry Andric     return Result;
3085ffd83dbSDimitry Andric   }
3095ffd83dbSDimitry Andric 
3105ffd83dbSDimitry Andric   return MCDisassembler::Fail;
3115ffd83dbSDimitry Andric }
3125ffd83dbSDimitry Andric 
3135ffd83dbSDimitry Andric typedef DecodeStatus (*DecodeFunc)(MCInst &MI, unsigned RegNo, uint64_t Address,
314*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder);
3155ffd83dbSDimitry Andric 
DecodeASX(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)3165ffd83dbSDimitry Andric static DecodeStatus DecodeASX(MCInst &MI, uint64_t insn, uint64_t Address,
317*81ad6265SDimitry Andric                               const MCDisassembler *Decoder) {
3185ffd83dbSDimitry Andric   unsigned sy = fieldFromInstruction(insn, 40, 7);
3195ffd83dbSDimitry Andric   bool cy = fieldFromInstruction(insn, 47, 1);
3205ffd83dbSDimitry Andric   unsigned sz = fieldFromInstruction(insn, 32, 7);
3215ffd83dbSDimitry Andric   bool cz = fieldFromInstruction(insn, 39, 1);
3225ffd83dbSDimitry Andric   uint64_t simm32 = SignExtend64<32>(fieldFromInstruction(insn, 0, 32));
3235ffd83dbSDimitry Andric   DecodeStatus status;
3245ffd83dbSDimitry Andric 
3255ffd83dbSDimitry Andric   // Decode sz.
3265ffd83dbSDimitry Andric   if (cz) {
3275ffd83dbSDimitry Andric     status = DecodeI64RegisterClass(MI, sz, Address, Decoder);
3285ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
3295ffd83dbSDimitry Andric       return status;
3305ffd83dbSDimitry Andric   } else {
3315ffd83dbSDimitry Andric     MI.addOperand(MCOperand::createImm(0));
3325ffd83dbSDimitry Andric   }
3335ffd83dbSDimitry Andric 
3345ffd83dbSDimitry Andric   // Decode sy.
3355ffd83dbSDimitry Andric   if (cy) {
3365ffd83dbSDimitry Andric     status = DecodeI64RegisterClass(MI, sy, Address, Decoder);
3375ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
3385ffd83dbSDimitry Andric       return status;
3395ffd83dbSDimitry Andric   } else {
3405ffd83dbSDimitry Andric     MI.addOperand(MCOperand::createImm(SignExtend32<7>(sy)));
3415ffd83dbSDimitry Andric   }
3425ffd83dbSDimitry Andric 
3435ffd83dbSDimitry Andric   // Decode simm32.
3445ffd83dbSDimitry Andric   MI.addOperand(MCOperand::createImm(simm32));
3455ffd83dbSDimitry Andric 
3465ffd83dbSDimitry Andric   return MCDisassembler::Success;
3475ffd83dbSDimitry Andric }
3485ffd83dbSDimitry Andric 
DecodeAS(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)3495ffd83dbSDimitry Andric static DecodeStatus DecodeAS(MCInst &MI, uint64_t insn, uint64_t Address,
350*81ad6265SDimitry Andric                              const MCDisassembler *Decoder) {
3515ffd83dbSDimitry Andric   unsigned sz = fieldFromInstruction(insn, 32, 7);
3525ffd83dbSDimitry Andric   bool cz = fieldFromInstruction(insn, 39, 1);
3535ffd83dbSDimitry Andric   uint64_t simm32 = SignExtend64<32>(fieldFromInstruction(insn, 0, 32));
3545ffd83dbSDimitry Andric   DecodeStatus status;
3555ffd83dbSDimitry Andric 
3565ffd83dbSDimitry Andric   // Decode sz.
3575ffd83dbSDimitry Andric   if (cz) {
3585ffd83dbSDimitry Andric     status = DecodeI64RegisterClass(MI, sz, Address, Decoder);
3595ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
3605ffd83dbSDimitry Andric       return status;
3615ffd83dbSDimitry Andric   } else {
3625ffd83dbSDimitry Andric     MI.addOperand(MCOperand::createImm(0));
3635ffd83dbSDimitry Andric   }
3645ffd83dbSDimitry Andric 
3655ffd83dbSDimitry Andric   // Decode simm32.
3665ffd83dbSDimitry Andric   MI.addOperand(MCOperand::createImm(simm32));
3675ffd83dbSDimitry Andric 
3685ffd83dbSDimitry Andric   return MCDisassembler::Success;
3695ffd83dbSDimitry Andric }
3705ffd83dbSDimitry Andric 
DecodeMem(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder,bool isLoad,DecodeFunc DecodeSX)3715ffd83dbSDimitry Andric static DecodeStatus DecodeMem(MCInst &MI, uint64_t insn, uint64_t Address,
372*81ad6265SDimitry Andric                               const MCDisassembler *Decoder, bool isLoad,
3735ffd83dbSDimitry Andric                               DecodeFunc DecodeSX) {
3745ffd83dbSDimitry Andric   unsigned sx = fieldFromInstruction(insn, 48, 7);
3755ffd83dbSDimitry Andric 
3765ffd83dbSDimitry Andric   DecodeStatus status;
3775ffd83dbSDimitry Andric   if (isLoad) {
3785ffd83dbSDimitry Andric     status = DecodeSX(MI, sx, Address, Decoder);
3795ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
3805ffd83dbSDimitry Andric       return status;
3815ffd83dbSDimitry Andric   }
3825ffd83dbSDimitry Andric 
3835ffd83dbSDimitry Andric   status = DecodeASX(MI, insn, Address, Decoder);
3845ffd83dbSDimitry Andric   if (status != MCDisassembler::Success)
3855ffd83dbSDimitry Andric     return status;
3865ffd83dbSDimitry Andric 
3875ffd83dbSDimitry Andric   if (!isLoad) {
3885ffd83dbSDimitry Andric     status = DecodeSX(MI, sx, Address, Decoder);
3895ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
3905ffd83dbSDimitry Andric       return status;
3915ffd83dbSDimitry Andric   }
3925ffd83dbSDimitry Andric   return MCDisassembler::Success;
3935ffd83dbSDimitry Andric }
3945ffd83dbSDimitry Andric 
DecodeMemAS(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder,bool isLoad,DecodeFunc DecodeSX)3955ffd83dbSDimitry Andric static DecodeStatus DecodeMemAS(MCInst &MI, uint64_t insn, uint64_t Address,
396*81ad6265SDimitry Andric                                 const MCDisassembler *Decoder, bool isLoad,
3975ffd83dbSDimitry Andric                                 DecodeFunc DecodeSX) {
3985ffd83dbSDimitry Andric   unsigned sx = fieldFromInstruction(insn, 48, 7);
3995ffd83dbSDimitry Andric 
4005ffd83dbSDimitry Andric   DecodeStatus status;
4015ffd83dbSDimitry Andric   if (isLoad) {
4025ffd83dbSDimitry Andric     status = DecodeSX(MI, sx, Address, Decoder);
4035ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
4045ffd83dbSDimitry Andric       return status;
4055ffd83dbSDimitry Andric   }
4065ffd83dbSDimitry Andric 
4075ffd83dbSDimitry Andric   status = DecodeAS(MI, insn, Address, Decoder);
4085ffd83dbSDimitry Andric   if (status != MCDisassembler::Success)
4095ffd83dbSDimitry Andric     return status;
4105ffd83dbSDimitry Andric 
4115ffd83dbSDimitry Andric   if (!isLoad) {
4125ffd83dbSDimitry Andric     status = DecodeSX(MI, sx, Address, Decoder);
4135ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
4145ffd83dbSDimitry Andric       return status;
4155ffd83dbSDimitry Andric   }
4165ffd83dbSDimitry Andric   return MCDisassembler::Success;
4175ffd83dbSDimitry Andric }
4185ffd83dbSDimitry Andric 
DecodeLoadI32(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4195ffd83dbSDimitry Andric static DecodeStatus DecodeLoadI32(MCInst &Inst, uint64_t insn, uint64_t Address,
420*81ad6265SDimitry Andric                                   const MCDisassembler *Decoder) {
4215ffd83dbSDimitry Andric   return DecodeMem(Inst, insn, Address, Decoder, true, DecodeI32RegisterClass);
4225ffd83dbSDimitry Andric }
4235ffd83dbSDimitry Andric 
DecodeStoreI32(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4245ffd83dbSDimitry Andric static DecodeStatus DecodeStoreI32(MCInst &Inst, uint64_t insn,
425*81ad6265SDimitry Andric                                    uint64_t Address,
426*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder) {
4275ffd83dbSDimitry Andric   return DecodeMem(Inst, insn, Address, Decoder, false, DecodeI32RegisterClass);
4285ffd83dbSDimitry Andric }
4295ffd83dbSDimitry Andric 
DecodeLoadI64(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4305ffd83dbSDimitry Andric static DecodeStatus DecodeLoadI64(MCInst &Inst, uint64_t insn, uint64_t Address,
431*81ad6265SDimitry Andric                                   const MCDisassembler *Decoder) {
4325ffd83dbSDimitry Andric   return DecodeMem(Inst, insn, Address, Decoder, true, DecodeI64RegisterClass);
4335ffd83dbSDimitry Andric }
4345ffd83dbSDimitry Andric 
DecodeStoreI64(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4355ffd83dbSDimitry Andric static DecodeStatus DecodeStoreI64(MCInst &Inst, uint64_t insn,
436*81ad6265SDimitry Andric                                    uint64_t Address,
437*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder) {
4385ffd83dbSDimitry Andric   return DecodeMem(Inst, insn, Address, Decoder, false, DecodeI64RegisterClass);
4395ffd83dbSDimitry Andric }
4405ffd83dbSDimitry Andric 
DecodeLoadF32(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4415ffd83dbSDimitry Andric static DecodeStatus DecodeLoadF32(MCInst &Inst, uint64_t insn, uint64_t Address,
442*81ad6265SDimitry Andric                                   const MCDisassembler *Decoder) {
4435ffd83dbSDimitry Andric   return DecodeMem(Inst, insn, Address, Decoder, true, DecodeF32RegisterClass);
4445ffd83dbSDimitry Andric }
4455ffd83dbSDimitry Andric 
DecodeStoreF32(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4465ffd83dbSDimitry Andric static DecodeStatus DecodeStoreF32(MCInst &Inst, uint64_t insn,
447*81ad6265SDimitry Andric                                    uint64_t Address,
448*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder) {
4495ffd83dbSDimitry Andric   return DecodeMem(Inst, insn, Address, Decoder, false, DecodeF32RegisterClass);
4505ffd83dbSDimitry Andric }
4515ffd83dbSDimitry Andric 
DecodeLoadASI64(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4525ffd83dbSDimitry Andric static DecodeStatus DecodeLoadASI64(MCInst &Inst, uint64_t insn,
453*81ad6265SDimitry Andric                                     uint64_t Address,
454*81ad6265SDimitry Andric                                     const MCDisassembler *Decoder) {
4555ffd83dbSDimitry Andric   return DecodeMemAS(Inst, insn, Address, Decoder, true,
4565ffd83dbSDimitry Andric                      DecodeI64RegisterClass);
4575ffd83dbSDimitry Andric }
4585ffd83dbSDimitry Andric 
DecodeStoreASI64(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)4595ffd83dbSDimitry Andric static DecodeStatus DecodeStoreASI64(MCInst &Inst, uint64_t insn,
460*81ad6265SDimitry Andric                                      uint64_t Address,
461*81ad6265SDimitry Andric                                      const MCDisassembler *Decoder) {
4625ffd83dbSDimitry Andric   return DecodeMemAS(Inst, insn, Address, Decoder, false,
4635ffd83dbSDimitry Andric                      DecodeI64RegisterClass);
4645ffd83dbSDimitry Andric }
4655ffd83dbSDimitry Andric 
DecodeCAS(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder,bool isImmOnly,bool isUImm,DecodeFunc DecodeSX)4665ffd83dbSDimitry Andric static DecodeStatus DecodeCAS(MCInst &MI, uint64_t insn, uint64_t Address,
467*81ad6265SDimitry Andric                               const MCDisassembler *Decoder, bool isImmOnly,
468*81ad6265SDimitry Andric                               bool isUImm, DecodeFunc DecodeSX) {
4695ffd83dbSDimitry Andric   unsigned sx = fieldFromInstruction(insn, 48, 7);
4705ffd83dbSDimitry Andric   bool cy = fieldFromInstruction(insn, 47, 1);
4715ffd83dbSDimitry Andric   unsigned sy = fieldFromInstruction(insn, 40, 7);
4725ffd83dbSDimitry Andric 
4735ffd83dbSDimitry Andric   // Add $sx.
4745ffd83dbSDimitry Andric   DecodeStatus status;
4755ffd83dbSDimitry Andric   status = DecodeSX(MI, sx, Address, Decoder);
4765ffd83dbSDimitry Andric   if (status != MCDisassembler::Success)
4775ffd83dbSDimitry Andric     return status;
4785ffd83dbSDimitry Andric 
4795ffd83dbSDimitry Andric   // Add $disp($sz).
4805ffd83dbSDimitry Andric   status = DecodeAS(MI, insn, Address, Decoder);
4815ffd83dbSDimitry Andric   if (status != MCDisassembler::Success)
4825ffd83dbSDimitry Andric     return status;
4835ffd83dbSDimitry Andric 
4845ffd83dbSDimitry Andric   // Add $sy.
4855ffd83dbSDimitry Andric   if (cy && !isImmOnly) {
4865ffd83dbSDimitry Andric     status = DecodeSX(MI, sy, Address, Decoder);
4875ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
4885ffd83dbSDimitry Andric       return status;
4895ffd83dbSDimitry Andric   } else {
4905ffd83dbSDimitry Andric     if (isUImm)
4915ffd83dbSDimitry Andric       MI.addOperand(MCOperand::createImm(sy));
4925ffd83dbSDimitry Andric     else
4935ffd83dbSDimitry Andric       MI.addOperand(MCOperand::createImm(SignExtend32<7>(sy)));
4945ffd83dbSDimitry Andric   }
4955ffd83dbSDimitry Andric 
4965ffd83dbSDimitry Andric   // Add $sd.
4975ffd83dbSDimitry Andric   status = DecodeSX(MI, sx, Address, Decoder);
4985ffd83dbSDimitry Andric   if (status != MCDisassembler::Success)
4995ffd83dbSDimitry Andric     return status;
5005ffd83dbSDimitry Andric 
5015ffd83dbSDimitry Andric   return MCDisassembler::Success;
5025ffd83dbSDimitry Andric }
5035ffd83dbSDimitry Andric 
DecodeTS1AMI64(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5045ffd83dbSDimitry Andric static DecodeStatus DecodeTS1AMI64(MCInst &MI, uint64_t insn, uint64_t Address,
505*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder) {
5065ffd83dbSDimitry Andric   return DecodeCAS(MI, insn, Address, Decoder, false, true,
5075ffd83dbSDimitry Andric                    DecodeI64RegisterClass);
5085ffd83dbSDimitry Andric }
5095ffd83dbSDimitry Andric 
DecodeTS1AMI32(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5105ffd83dbSDimitry Andric static DecodeStatus DecodeTS1AMI32(MCInst &MI, uint64_t insn, uint64_t Address,
511*81ad6265SDimitry Andric                                    const MCDisassembler *Decoder) {
5125ffd83dbSDimitry Andric   return DecodeCAS(MI, insn, Address, Decoder, false, true,
5135ffd83dbSDimitry Andric                    DecodeI32RegisterClass);
5145ffd83dbSDimitry Andric }
5155ffd83dbSDimitry Andric 
DecodeCASI64(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5165ffd83dbSDimitry Andric static DecodeStatus DecodeCASI64(MCInst &MI, uint64_t insn, uint64_t Address,
517*81ad6265SDimitry Andric                                  const MCDisassembler *Decoder) {
5185ffd83dbSDimitry Andric   return DecodeCAS(MI, insn, Address, Decoder, false, false,
5195ffd83dbSDimitry Andric                    DecodeI64RegisterClass);
5205ffd83dbSDimitry Andric }
5215ffd83dbSDimitry Andric 
DecodeCASI32(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5225ffd83dbSDimitry Andric static DecodeStatus DecodeCASI32(MCInst &MI, uint64_t insn, uint64_t Address,
523*81ad6265SDimitry Andric                                  const MCDisassembler *Decoder) {
5245ffd83dbSDimitry Andric   return DecodeCAS(MI, insn, Address, Decoder, false, false,
5255ffd83dbSDimitry Andric                    DecodeI32RegisterClass);
5265ffd83dbSDimitry Andric }
5275ffd83dbSDimitry Andric 
DecodeCall(MCInst & Inst,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5285ffd83dbSDimitry Andric static DecodeStatus DecodeCall(MCInst &Inst, uint64_t insn, uint64_t Address,
529*81ad6265SDimitry Andric                                const MCDisassembler *Decoder) {
5305ffd83dbSDimitry Andric   return DecodeMem(Inst, insn, Address, Decoder, true, DecodeI64RegisterClass);
5315ffd83dbSDimitry Andric }
5325ffd83dbSDimitry Andric 
DecodeSIMM7(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5335ffd83dbSDimitry Andric static DecodeStatus DecodeSIMM7(MCInst &MI, uint64_t insn, uint64_t Address,
534*81ad6265SDimitry Andric                                 const MCDisassembler *Decoder) {
5355ffd83dbSDimitry Andric   uint64_t tgt = SignExtend64<7>(insn);
5365ffd83dbSDimitry Andric   MI.addOperand(MCOperand::createImm(tgt));
5375ffd83dbSDimitry Andric   return MCDisassembler::Success;
5385ffd83dbSDimitry Andric }
5395ffd83dbSDimitry Andric 
DecodeSIMM32(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5405ffd83dbSDimitry Andric static DecodeStatus DecodeSIMM32(MCInst &MI, uint64_t insn, uint64_t Address,
541*81ad6265SDimitry Andric                                  const MCDisassembler *Decoder) {
5425ffd83dbSDimitry Andric   uint64_t tgt = SignExtend64<32>(insn);
5435ffd83dbSDimitry Andric   MI.addOperand(MCOperand::createImm(tgt));
5445ffd83dbSDimitry Andric   return MCDisassembler::Success;
5455ffd83dbSDimitry Andric }
5465ffd83dbSDimitry Andric 
isIntegerBCKind(MCInst & MI)5475ffd83dbSDimitry Andric static bool isIntegerBCKind(MCInst &MI) {
5485ffd83dbSDimitry Andric 
5495ffd83dbSDimitry Andric #define BCm_kind(NAME)                                                         \
5505ffd83dbSDimitry Andric   case NAME##rri:                                                              \
5515ffd83dbSDimitry Andric   case NAME##rzi:                                                              \
5525ffd83dbSDimitry Andric   case NAME##iri:                                                              \
5535ffd83dbSDimitry Andric   case NAME##izi:                                                              \
5545ffd83dbSDimitry Andric   case NAME##rri_nt:                                                           \
5555ffd83dbSDimitry Andric   case NAME##rzi_nt:                                                           \
5565ffd83dbSDimitry Andric   case NAME##iri_nt:                                                           \
5575ffd83dbSDimitry Andric   case NAME##izi_nt:                                                           \
5585ffd83dbSDimitry Andric   case NAME##rri_t:                                                            \
5595ffd83dbSDimitry Andric   case NAME##rzi_t:                                                            \
5605ffd83dbSDimitry Andric   case NAME##iri_t:                                                            \
5615ffd83dbSDimitry Andric   case NAME##izi_t:
5625ffd83dbSDimitry Andric 
5635ffd83dbSDimitry Andric #define BCRm_kind(NAME)                                                        \
5645ffd83dbSDimitry Andric   case NAME##rr:                                                               \
5655ffd83dbSDimitry Andric   case NAME##ir:                                                               \
5665ffd83dbSDimitry Andric   case NAME##rr_nt:                                                            \
5675ffd83dbSDimitry Andric   case NAME##ir_nt:                                                            \
5685ffd83dbSDimitry Andric   case NAME##rr_t:                                                             \
5695ffd83dbSDimitry Andric   case NAME##ir_t:
5705ffd83dbSDimitry Andric 
5715ffd83dbSDimitry Andric   {
5725ffd83dbSDimitry Andric     using namespace llvm::VE;
5735ffd83dbSDimitry Andric     switch (MI.getOpcode()) {
5745ffd83dbSDimitry Andric       BCm_kind(BCFL) BCm_kind(BCFW) BCRm_kind(BRCFL)
5755ffd83dbSDimitry Andric           BCRm_kind(BRCFW) return true;
5765ffd83dbSDimitry Andric     }
5775ffd83dbSDimitry Andric   }
5785ffd83dbSDimitry Andric #undef BCm_kind
5795ffd83dbSDimitry Andric 
5805ffd83dbSDimitry Andric   return false;
5815ffd83dbSDimitry Andric }
5825ffd83dbSDimitry Andric 
5835ffd83dbSDimitry Andric // Decode CC Operand field.
DecodeCCOperand(MCInst & MI,uint64_t cf,uint64_t Address,const MCDisassembler * Decoder)5845ffd83dbSDimitry Andric static DecodeStatus DecodeCCOperand(MCInst &MI, uint64_t cf, uint64_t Address,
585*81ad6265SDimitry Andric                                     const MCDisassembler *Decoder) {
5865ffd83dbSDimitry Andric   MI.addOperand(MCOperand::createImm(VEValToCondCode(cf, isIntegerBCKind(MI))));
5875ffd83dbSDimitry Andric   return MCDisassembler::Success;
5885ffd83dbSDimitry Andric }
5895ffd83dbSDimitry Andric 
5905ffd83dbSDimitry Andric // Decode RD Operand field.
DecodeRDOperand(MCInst & MI,uint64_t cf,uint64_t Address,const MCDisassembler * Decoder)5915ffd83dbSDimitry Andric static DecodeStatus DecodeRDOperand(MCInst &MI, uint64_t cf, uint64_t Address,
592*81ad6265SDimitry Andric                                     const MCDisassembler *Decoder) {
5935ffd83dbSDimitry Andric   MI.addOperand(MCOperand::createImm(VEValToRD(cf)));
5945ffd83dbSDimitry Andric   return MCDisassembler::Success;
5955ffd83dbSDimitry Andric }
5965ffd83dbSDimitry Andric 
5975ffd83dbSDimitry Andric // Decode branch condition instruction and CCOperand field in it.
DecodeBranchCondition(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)5985ffd83dbSDimitry Andric static DecodeStatus DecodeBranchCondition(MCInst &MI, uint64_t insn,
5995ffd83dbSDimitry Andric                                           uint64_t Address,
600*81ad6265SDimitry Andric                                           const MCDisassembler *Decoder) {
6015ffd83dbSDimitry Andric   unsigned cf = fieldFromInstruction(insn, 48, 4);
6025ffd83dbSDimitry Andric   bool cy = fieldFromInstruction(insn, 47, 1);
6035ffd83dbSDimitry Andric   unsigned sy = fieldFromInstruction(insn, 40, 7);
6045ffd83dbSDimitry Andric 
6055ffd83dbSDimitry Andric   // Decode cf.
6065ffd83dbSDimitry Andric   MI.addOperand(MCOperand::createImm(VEValToCondCode(cf, isIntegerBCKind(MI))));
6075ffd83dbSDimitry Andric 
6085ffd83dbSDimitry Andric   // Decode sy.
6095ffd83dbSDimitry Andric   DecodeStatus status;
6105ffd83dbSDimitry Andric   if (cy) {
6115ffd83dbSDimitry Andric     status = DecodeI64RegisterClass(MI, sy, Address, Decoder);
6125ffd83dbSDimitry Andric     if (status != MCDisassembler::Success)
6135ffd83dbSDimitry Andric       return status;
6145ffd83dbSDimitry Andric   } else {
6155ffd83dbSDimitry Andric     MI.addOperand(MCOperand::createImm(SignExtend32<7>(sy)));
6165ffd83dbSDimitry Andric   }
6175ffd83dbSDimitry Andric 
6185ffd83dbSDimitry Andric   // Decode MEMri.
6195ffd83dbSDimitry Andric   return DecodeAS(MI, insn, Address, Decoder);
6205ffd83dbSDimitry Andric }
6215ffd83dbSDimitry Andric 
DecodeBranchConditionAlways(MCInst & MI,uint64_t insn,uint64_t Address,const MCDisassembler * Decoder)6225ffd83dbSDimitry Andric static DecodeStatus DecodeBranchConditionAlways(MCInst &MI, uint64_t insn,
6235ffd83dbSDimitry Andric                                                 uint64_t Address,
624*81ad6265SDimitry Andric                                                 const MCDisassembler *Decoder) {
6255ffd83dbSDimitry Andric   // Decode MEMri.
6265ffd83dbSDimitry Andric   return DecodeAS(MI, insn, Address, Decoder);
6275ffd83dbSDimitry Andric }
628