1*0a6a1f1dSLionel Sambuc //===- AArch64Disassembler.cpp - Disassembler for AArch64 -------*- C++ -*-===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc //
11f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
12f4a2713aSLionel Sambuc 
13*0a6a1f1dSLionel Sambuc #include "AArch64Disassembler.h"
14*0a6a1f1dSLionel Sambuc #include "AArch64ExternalSymbolizer.h"
15f4a2713aSLionel Sambuc #include "AArch64Subtarget.h"
16*0a6a1f1dSLionel Sambuc #include "MCTargetDesc/AArch64AddressingModes.h"
17f4a2713aSLionel Sambuc #include "Utils/AArch64BaseInfo.h"
18f4a2713aSLionel Sambuc #include "llvm/MC/MCFixedLenDisassembler.h"
19*0a6a1f1dSLionel Sambuc #include "llvm/MC/MCInst.h"
20f4a2713aSLionel Sambuc #include "llvm/Support/Debug.h"
21f4a2713aSLionel Sambuc #include "llvm/Support/ErrorHandling.h"
22f4a2713aSLionel Sambuc #include "llvm/Support/TargetRegistry.h"
23f4a2713aSLionel Sambuc 
24f4a2713aSLionel Sambuc using namespace llvm;
25f4a2713aSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc #define DEBUG_TYPE "aarch64-disassembler"
27f4a2713aSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc // Pull DecodeStatus and its enum values into the global namespace.
29*0a6a1f1dSLionel Sambuc typedef llvm::MCDisassembler::DecodeStatus DecodeStatus;
30f4a2713aSLionel Sambuc 
31*0a6a1f1dSLionel Sambuc // Forward declare these because the autogenerated code will reference them.
32*0a6a1f1dSLionel Sambuc // Definitions are further down.
33f4a2713aSLionel Sambuc static DecodeStatus DecodeFPR128RegisterClass(llvm::MCInst &Inst,
34f4a2713aSLionel Sambuc                                               unsigned RegNo, uint64_t Address,
35f4a2713aSLionel Sambuc                                               const void *Decoder);
36*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR128_loRegisterClass(llvm::MCInst &Inst,
37f4a2713aSLionel Sambuc                                                  unsigned RegNo,
38f4a2713aSLionel Sambuc                                                  uint64_t Address,
39f4a2713aSLionel Sambuc                                                  const void *Decoder);
40*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
41f4a2713aSLionel Sambuc                                              uint64_t Address,
42f4a2713aSLionel Sambuc                                              const void *Decoder);
43*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
44f4a2713aSLionel Sambuc                                              uint64_t Address,
45f4a2713aSLionel Sambuc                                              const void *Decoder);
46*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR16RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
47*0a6a1f1dSLionel Sambuc                                              uint64_t Address,
48*0a6a1f1dSLionel Sambuc                                              const void *Decoder);
49*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
50*0a6a1f1dSLionel Sambuc                                             uint64_t Address,
51*0a6a1f1dSLionel Sambuc                                             const void *Decoder);
52*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
53*0a6a1f1dSLionel Sambuc                                              uint64_t Address,
54*0a6a1f1dSLionel Sambuc                                              const void *Decoder);
55*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR64spRegisterClass(llvm::MCInst &Inst,
56f4a2713aSLionel Sambuc                                                unsigned RegNo, uint64_t Address,
57f4a2713aSLionel Sambuc                                                const void *Decoder);
58*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
59*0a6a1f1dSLionel Sambuc                                              uint64_t Address,
60*0a6a1f1dSLionel Sambuc                                              const void *Decoder);
61*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR32spRegisterClass(llvm::MCInst &Inst,
62f4a2713aSLionel Sambuc                                                unsigned RegNo, uint64_t Address,
63f4a2713aSLionel Sambuc                                                const void *Decoder);
64*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeQQRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
65f4a2713aSLionel Sambuc                                           uint64_t Address,
66f4a2713aSLionel Sambuc                                           const void *Decoder);
67*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeQQQRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
68*0a6a1f1dSLionel Sambuc                                            uint64_t Address,
69*0a6a1f1dSLionel Sambuc                                            const void *Decoder);
70*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeQQQQRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
71*0a6a1f1dSLionel Sambuc                                             uint64_t Address,
72*0a6a1f1dSLionel Sambuc                                             const void *Decoder);
73*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeDDRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
74*0a6a1f1dSLionel Sambuc                                           uint64_t Address,
75*0a6a1f1dSLionel Sambuc                                           const void *Decoder);
76*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeDDDRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
77*0a6a1f1dSLionel Sambuc                                            uint64_t Address,
78*0a6a1f1dSLionel Sambuc                                            const void *Decoder);
79*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeDDDDRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
80f4a2713aSLionel Sambuc                                             uint64_t Address,
81f4a2713aSLionel Sambuc                                             const void *Decoder);
82f4a2713aSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFixedPointScaleImm32(llvm::MCInst &Inst, unsigned Imm,
84f4a2713aSLionel Sambuc                                                uint64_t Address,
85f4a2713aSLionel Sambuc                                                const void *Decoder);
86*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFixedPointScaleImm64(llvm::MCInst &Inst, unsigned Imm,
87f4a2713aSLionel Sambuc                                                uint64_t Address,
88f4a2713aSLionel Sambuc                                                const void *Decoder);
89*0a6a1f1dSLionel Sambuc static DecodeStatus DecodePCRelLabel19(llvm::MCInst &Inst, unsigned Imm,
90f4a2713aSLionel Sambuc                                        uint64_t Address, const void *Decoder);
91*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMemExtend(llvm::MCInst &Inst, unsigned Imm,
92f4a2713aSLionel Sambuc                                     uint64_t Address, const void *Decoder);
93*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMRSSystemRegister(llvm::MCInst &Inst, unsigned Imm,
94f4a2713aSLionel Sambuc                                             uint64_t Address, const void *Decoder);
95*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMSRSystemRegister(llvm::MCInst &Inst, unsigned Imm,
96*0a6a1f1dSLionel Sambuc                                             uint64_t Address, const void *Decoder);
97*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeThreeAddrSRegInstruction(llvm::MCInst &Inst,
98*0a6a1f1dSLionel Sambuc                                                    uint32_t insn,
99f4a2713aSLionel Sambuc                                                    uint64_t Address,
100f4a2713aSLionel Sambuc                                                    const void *Decoder);
101*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMoveImmInstruction(llvm::MCInst &Inst, uint32_t insn,
102f4a2713aSLionel Sambuc                                              uint64_t Address,
103f4a2713aSLionel Sambuc                                              const void *Decoder);
104*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeUnsignedLdStInstruction(llvm::MCInst &Inst,
105*0a6a1f1dSLionel Sambuc                                                   uint32_t insn,
106*0a6a1f1dSLionel Sambuc                                                   uint64_t Address,
107*0a6a1f1dSLionel Sambuc                                                   const void *Decoder);
108*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeSignedLdStInstruction(llvm::MCInst &Inst,
109*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Address,
110*0a6a1f1dSLionel Sambuc                                                 const void *Decoder);
111*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeExclusiveLdStInstruction(llvm::MCInst &Inst,
112*0a6a1f1dSLionel Sambuc                                                    uint32_t insn,
113*0a6a1f1dSLionel Sambuc                                                    uint64_t Address,
114*0a6a1f1dSLionel Sambuc                                                    const void *Decoder);
115*0a6a1f1dSLionel Sambuc static DecodeStatus DecodePairLdStInstruction(llvm::MCInst &Inst, uint32_t insn,
116*0a6a1f1dSLionel Sambuc                                               uint64_t Address,
117*0a6a1f1dSLionel Sambuc                                               const void *Decoder);
118*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeAddSubERegInstruction(llvm::MCInst &Inst,
119*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Address,
120*0a6a1f1dSLionel Sambuc                                                 const void *Decoder);
121*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeLogicalImmInstruction(llvm::MCInst &Inst,
122*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Address,
123*0a6a1f1dSLionel Sambuc                                                 const void *Decoder);
124*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeModImmInstruction(llvm::MCInst &Inst, uint32_t insn,
125*0a6a1f1dSLionel Sambuc                                             uint64_t Address,
126*0a6a1f1dSLionel Sambuc                                             const void *Decoder);
127*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeModImmTiedInstruction(llvm::MCInst &Inst,
128*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Address,
129*0a6a1f1dSLionel Sambuc                                                 const void *Decoder);
130*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeAdrInstruction(llvm::MCInst &Inst, uint32_t insn,
131*0a6a1f1dSLionel Sambuc                                          uint64_t Address, const void *Decoder);
132*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeBaseAddSubImm(llvm::MCInst &Inst, uint32_t insn,
133*0a6a1f1dSLionel Sambuc                                         uint64_t Address, const void *Decoder);
134*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeUnconditionalBranch(llvm::MCInst &Inst, uint32_t insn,
135*0a6a1f1dSLionel Sambuc                                               uint64_t Address,
136*0a6a1f1dSLionel Sambuc                                               const void *Decoder);
137*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeSystemPStateInstruction(llvm::MCInst &Inst,
138*0a6a1f1dSLionel Sambuc                                                   uint32_t insn,
139*0a6a1f1dSLionel Sambuc                                                   uint64_t Address,
140*0a6a1f1dSLionel Sambuc                                                   const void *Decoder);
141*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeTestAndBranch(llvm::MCInst &Inst, uint32_t insn,
142*0a6a1f1dSLionel Sambuc                                         uint64_t Address, const void *Decoder);
143f4a2713aSLionel Sambuc 
144f4a2713aSLionel Sambuc static DecodeStatus DecodeFMOVLaneInstruction(llvm::MCInst &Inst, unsigned Insn,
145f4a2713aSLionel Sambuc                                               uint64_t Address,
146f4a2713aSLionel Sambuc                                               const void *Decoder);
147*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR64Imm(llvm::MCInst &Inst, unsigned Imm,
148*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder);
149*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR64ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
150*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
151f4a2713aSLionel Sambuc                                                const void *Decoder);
152*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR32Imm(llvm::MCInst &Inst, unsigned Imm,
153*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder);
154*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR32ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
155*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
156f4a2713aSLionel Sambuc                                                const void *Decoder);
157*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR16Imm(llvm::MCInst &Inst, unsigned Imm,
158*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder);
159*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR16ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
160*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
161f4a2713aSLionel Sambuc                                                const void *Decoder);
162*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR8Imm(llvm::MCInst &Inst, unsigned Imm,
163*0a6a1f1dSLionel Sambuc                                         uint64_t Addr, const void *Decoder);
164*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL64Imm(llvm::MCInst &Inst, unsigned Imm,
165*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder);
166*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL32Imm(llvm::MCInst &Inst, unsigned Imm,
167*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder);
168*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL16Imm(llvm::MCInst &Inst, unsigned Imm,
169*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder);
170*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL8Imm(llvm::MCInst &Inst, unsigned Imm,
171*0a6a1f1dSLionel Sambuc                                         uint64_t Addr, const void *Decoder);
172f4a2713aSLionel Sambuc 
Check(DecodeStatus & Out,DecodeStatus In)173f4a2713aSLionel Sambuc static bool Check(DecodeStatus &Out, DecodeStatus In) {
174f4a2713aSLionel Sambuc   switch (In) {
175f4a2713aSLionel Sambuc     case MCDisassembler::Success:
176f4a2713aSLionel Sambuc       // Out stays the same.
177f4a2713aSLionel Sambuc       return true;
178f4a2713aSLionel Sambuc     case MCDisassembler::SoftFail:
179f4a2713aSLionel Sambuc       Out = In;
180f4a2713aSLionel Sambuc       return true;
181f4a2713aSLionel Sambuc     case MCDisassembler::Fail:
182f4a2713aSLionel Sambuc       Out = In;
183f4a2713aSLionel Sambuc       return false;
184f4a2713aSLionel Sambuc   }
185f4a2713aSLionel Sambuc   llvm_unreachable("Invalid DecodeStatus!");
186f4a2713aSLionel Sambuc }
187f4a2713aSLionel Sambuc 
188*0a6a1f1dSLionel Sambuc #include "AArch64GenDisassemblerTables.inc"
189*0a6a1f1dSLionel Sambuc #include "AArch64GenInstrInfo.inc"
190f4a2713aSLionel Sambuc 
191*0a6a1f1dSLionel Sambuc #define Success llvm::MCDisassembler::Success
192*0a6a1f1dSLionel Sambuc #define Fail llvm::MCDisassembler::Fail
193*0a6a1f1dSLionel Sambuc #define SoftFail llvm::MCDisassembler::SoftFail
194f4a2713aSLionel Sambuc 
createAArch64Disassembler(const Target & T,const MCSubtargetInfo & STI,MCContext & Ctx)195*0a6a1f1dSLionel Sambuc static MCDisassembler *createAArch64Disassembler(const Target &T,
196*0a6a1f1dSLionel Sambuc                                                const MCSubtargetInfo &STI,
197*0a6a1f1dSLionel Sambuc                                                MCContext &Ctx) {
198*0a6a1f1dSLionel Sambuc   return new AArch64Disassembler(STI, Ctx);
199f4a2713aSLionel Sambuc }
200f4a2713aSLionel Sambuc 
getInstruction(MCInst & MI,uint64_t & Size,ArrayRef<uint8_t> Bytes,uint64_t Address,raw_ostream & OS,raw_ostream & CS) const201*0a6a1f1dSLionel Sambuc DecodeStatus AArch64Disassembler::getInstruction(MCInst &MI, uint64_t &Size,
202*0a6a1f1dSLionel Sambuc                                                  ArrayRef<uint8_t> Bytes,
203*0a6a1f1dSLionel Sambuc                                                  uint64_t Address,
204*0a6a1f1dSLionel Sambuc                                                  raw_ostream &OS,
205*0a6a1f1dSLionel Sambuc                                                  raw_ostream &CS) const {
206*0a6a1f1dSLionel Sambuc   CommentStream = &CS;
207*0a6a1f1dSLionel Sambuc 
208*0a6a1f1dSLionel Sambuc   Size = 0;
209*0a6a1f1dSLionel Sambuc   // We want to read exactly 4 bytes of data.
210*0a6a1f1dSLionel Sambuc   if (Bytes.size() < 4)
211*0a6a1f1dSLionel Sambuc     return Fail;
212*0a6a1f1dSLionel Sambuc   Size = 4;
213*0a6a1f1dSLionel Sambuc 
214f4a2713aSLionel Sambuc   // Encoded as a small-endian 32-bit word in the stream.
215*0a6a1f1dSLionel Sambuc   uint32_t Insn =
216*0a6a1f1dSLionel Sambuc       (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0);
217f4a2713aSLionel Sambuc 
218f4a2713aSLionel Sambuc   // Calling the auto-generated decoder function.
219*0a6a1f1dSLionel Sambuc   return decodeInstruction(DecoderTable32, MI, Insn, Address, this, STI);
220f4a2713aSLionel Sambuc }
221f4a2713aSLionel Sambuc 
222*0a6a1f1dSLionel Sambuc static MCSymbolizer *
createAArch64ExternalSymbolizer(StringRef TT,LLVMOpInfoCallback GetOpInfo,LLVMSymbolLookupCallback SymbolLookUp,void * DisInfo,MCContext * Ctx,MCRelocationInfo * RelInfo)223*0a6a1f1dSLionel Sambuc createAArch64ExternalSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
224*0a6a1f1dSLionel Sambuc                               LLVMSymbolLookupCallback SymbolLookUp,
225*0a6a1f1dSLionel Sambuc                               void *DisInfo, MCContext *Ctx,
226*0a6a1f1dSLionel Sambuc                               MCRelocationInfo *RelInfo) {
227*0a6a1f1dSLionel Sambuc   return new llvm::AArch64ExternalSymbolizer(
228*0a6a1f1dSLionel Sambuc                                      *Ctx,
229*0a6a1f1dSLionel Sambuc                                      std::unique_ptr<MCRelocationInfo>(RelInfo),
230*0a6a1f1dSLionel Sambuc                                      GetOpInfo, SymbolLookUp, DisInfo);
231f4a2713aSLionel Sambuc }
232f4a2713aSLionel Sambuc 
LLVMInitializeAArch64Disassembler()233*0a6a1f1dSLionel Sambuc extern "C" void LLVMInitializeAArch64Disassembler() {
234*0a6a1f1dSLionel Sambuc   TargetRegistry::RegisterMCDisassembler(TheAArch64leTarget,
235*0a6a1f1dSLionel Sambuc                                          createAArch64Disassembler);
236*0a6a1f1dSLionel Sambuc   TargetRegistry::RegisterMCDisassembler(TheAArch64beTarget,
237*0a6a1f1dSLionel Sambuc                                          createAArch64Disassembler);
238*0a6a1f1dSLionel Sambuc   TargetRegistry::RegisterMCSymbolizer(TheAArch64leTarget,
239*0a6a1f1dSLionel Sambuc                                        createAArch64ExternalSymbolizer);
240*0a6a1f1dSLionel Sambuc   TargetRegistry::RegisterMCSymbolizer(TheAArch64beTarget,
241*0a6a1f1dSLionel Sambuc                                        createAArch64ExternalSymbolizer);
242*0a6a1f1dSLionel Sambuc 
243*0a6a1f1dSLionel Sambuc   TargetRegistry::RegisterMCDisassembler(TheARM64Target,
244*0a6a1f1dSLionel Sambuc                                          createAArch64Disassembler);
245*0a6a1f1dSLionel Sambuc   TargetRegistry::RegisterMCSymbolizer(TheARM64Target,
246*0a6a1f1dSLionel Sambuc                                        createAArch64ExternalSymbolizer);
247f4a2713aSLionel Sambuc }
248f4a2713aSLionel Sambuc 
249*0a6a1f1dSLionel Sambuc static const unsigned FPR128DecoderTable[] = {
250*0a6a1f1dSLionel Sambuc     AArch64::Q0,  AArch64::Q1,  AArch64::Q2,  AArch64::Q3,  AArch64::Q4,
251*0a6a1f1dSLionel Sambuc     AArch64::Q5,  AArch64::Q6,  AArch64::Q7,  AArch64::Q8,  AArch64::Q9,
252*0a6a1f1dSLionel Sambuc     AArch64::Q10, AArch64::Q11, AArch64::Q12, AArch64::Q13, AArch64::Q14,
253*0a6a1f1dSLionel Sambuc     AArch64::Q15, AArch64::Q16, AArch64::Q17, AArch64::Q18, AArch64::Q19,
254*0a6a1f1dSLionel Sambuc     AArch64::Q20, AArch64::Q21, AArch64::Q22, AArch64::Q23, AArch64::Q24,
255*0a6a1f1dSLionel Sambuc     AArch64::Q25, AArch64::Q26, AArch64::Q27, AArch64::Q28, AArch64::Q29,
256*0a6a1f1dSLionel Sambuc     AArch64::Q30, AArch64::Q31
257*0a6a1f1dSLionel Sambuc };
258f4a2713aSLionel Sambuc 
DecodeFPR128RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)259*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR128RegisterClass(MCInst &Inst, unsigned RegNo,
260*0a6a1f1dSLionel Sambuc                                               uint64_t Addr,
261f4a2713aSLionel Sambuc                                               const void *Decoder) {
262f4a2713aSLionel Sambuc   if (RegNo > 31)
263*0a6a1f1dSLionel Sambuc     return Fail;
264f4a2713aSLionel Sambuc 
265*0a6a1f1dSLionel Sambuc   unsigned Register = FPR128DecoderTable[RegNo];
266f4a2713aSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
267*0a6a1f1dSLionel Sambuc   return Success;
268f4a2713aSLionel Sambuc }
269f4a2713aSLionel Sambuc 
DecodeFPR128_loRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)270*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR128_loRegisterClass(MCInst &Inst, unsigned RegNo,
271*0a6a1f1dSLionel Sambuc                                                  uint64_t Addr,
272*0a6a1f1dSLionel Sambuc                                                  const void *Decoder) {
273f4a2713aSLionel Sambuc   if (RegNo > 15)
274*0a6a1f1dSLionel Sambuc     return Fail;
275*0a6a1f1dSLionel Sambuc   return DecodeFPR128RegisterClass(Inst, RegNo, Addr, Decoder);
276f4a2713aSLionel Sambuc }
277f4a2713aSLionel Sambuc 
278*0a6a1f1dSLionel Sambuc static const unsigned FPR64DecoderTable[] = {
279*0a6a1f1dSLionel Sambuc     AArch64::D0,  AArch64::D1,  AArch64::D2,  AArch64::D3,  AArch64::D4,
280*0a6a1f1dSLionel Sambuc     AArch64::D5,  AArch64::D6,  AArch64::D7,  AArch64::D8,  AArch64::D9,
281*0a6a1f1dSLionel Sambuc     AArch64::D10, AArch64::D11, AArch64::D12, AArch64::D13, AArch64::D14,
282*0a6a1f1dSLionel Sambuc     AArch64::D15, AArch64::D16, AArch64::D17, AArch64::D18, AArch64::D19,
283*0a6a1f1dSLionel Sambuc     AArch64::D20, AArch64::D21, AArch64::D22, AArch64::D23, AArch64::D24,
284*0a6a1f1dSLionel Sambuc     AArch64::D25, AArch64::D26, AArch64::D27, AArch64::D28, AArch64::D29,
285*0a6a1f1dSLionel Sambuc     AArch64::D30, AArch64::D31
286*0a6a1f1dSLionel Sambuc };
287f4a2713aSLionel Sambuc 
DecodeFPR64RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)288*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR64RegisterClass(MCInst &Inst, unsigned RegNo,
289*0a6a1f1dSLionel Sambuc                                              uint64_t Addr,
290f4a2713aSLionel Sambuc                                              const void *Decoder) {
291f4a2713aSLionel Sambuc   if (RegNo > 31)
292*0a6a1f1dSLionel Sambuc     return Fail;
293f4a2713aSLionel Sambuc 
294*0a6a1f1dSLionel Sambuc   unsigned Register = FPR64DecoderTable[RegNo];
295f4a2713aSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
296*0a6a1f1dSLionel Sambuc   return Success;
297f4a2713aSLionel Sambuc }
298f4a2713aSLionel Sambuc 
299*0a6a1f1dSLionel Sambuc static const unsigned FPR32DecoderTable[] = {
300*0a6a1f1dSLionel Sambuc     AArch64::S0,  AArch64::S1,  AArch64::S2,  AArch64::S3,  AArch64::S4,
301*0a6a1f1dSLionel Sambuc     AArch64::S5,  AArch64::S6,  AArch64::S7,  AArch64::S8,  AArch64::S9,
302*0a6a1f1dSLionel Sambuc     AArch64::S10, AArch64::S11, AArch64::S12, AArch64::S13, AArch64::S14,
303*0a6a1f1dSLionel Sambuc     AArch64::S15, AArch64::S16, AArch64::S17, AArch64::S18, AArch64::S19,
304*0a6a1f1dSLionel Sambuc     AArch64::S20, AArch64::S21, AArch64::S22, AArch64::S23, AArch64::S24,
305*0a6a1f1dSLionel Sambuc     AArch64::S25, AArch64::S26, AArch64::S27, AArch64::S28, AArch64::S29,
306*0a6a1f1dSLionel Sambuc     AArch64::S30, AArch64::S31
307*0a6a1f1dSLionel Sambuc };
308*0a6a1f1dSLionel Sambuc 
DecodeFPR32RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)309*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR32RegisterClass(MCInst &Inst, unsigned RegNo,
310*0a6a1f1dSLionel Sambuc                                              uint64_t Addr,
311*0a6a1f1dSLionel Sambuc                                              const void *Decoder) {
312*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
313*0a6a1f1dSLionel Sambuc     return Fail;
314*0a6a1f1dSLionel Sambuc 
315*0a6a1f1dSLionel Sambuc   unsigned Register = FPR32DecoderTable[RegNo];
316*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
317*0a6a1f1dSLionel Sambuc   return Success;
318*0a6a1f1dSLionel Sambuc }
319*0a6a1f1dSLionel Sambuc 
320*0a6a1f1dSLionel Sambuc static const unsigned FPR16DecoderTable[] = {
321*0a6a1f1dSLionel Sambuc     AArch64::H0,  AArch64::H1,  AArch64::H2,  AArch64::H3,  AArch64::H4,
322*0a6a1f1dSLionel Sambuc     AArch64::H5,  AArch64::H6,  AArch64::H7,  AArch64::H8,  AArch64::H9,
323*0a6a1f1dSLionel Sambuc     AArch64::H10, AArch64::H11, AArch64::H12, AArch64::H13, AArch64::H14,
324*0a6a1f1dSLionel Sambuc     AArch64::H15, AArch64::H16, AArch64::H17, AArch64::H18, AArch64::H19,
325*0a6a1f1dSLionel Sambuc     AArch64::H20, AArch64::H21, AArch64::H22, AArch64::H23, AArch64::H24,
326*0a6a1f1dSLionel Sambuc     AArch64::H25, AArch64::H26, AArch64::H27, AArch64::H28, AArch64::H29,
327*0a6a1f1dSLionel Sambuc     AArch64::H30, AArch64::H31
328*0a6a1f1dSLionel Sambuc };
329*0a6a1f1dSLionel Sambuc 
DecodeFPR16RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)330*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR16RegisterClass(MCInst &Inst, unsigned RegNo,
331*0a6a1f1dSLionel Sambuc                                              uint64_t Addr,
332*0a6a1f1dSLionel Sambuc                                              const void *Decoder) {
333*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
334*0a6a1f1dSLionel Sambuc     return Fail;
335*0a6a1f1dSLionel Sambuc 
336*0a6a1f1dSLionel Sambuc   unsigned Register = FPR16DecoderTable[RegNo];
337*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
338*0a6a1f1dSLionel Sambuc   return Success;
339*0a6a1f1dSLionel Sambuc }
340*0a6a1f1dSLionel Sambuc 
341*0a6a1f1dSLionel Sambuc static const unsigned FPR8DecoderTable[] = {
342*0a6a1f1dSLionel Sambuc     AArch64::B0,  AArch64::B1,  AArch64::B2,  AArch64::B3,  AArch64::B4,
343*0a6a1f1dSLionel Sambuc     AArch64::B5,  AArch64::B6,  AArch64::B7,  AArch64::B8,  AArch64::B9,
344*0a6a1f1dSLionel Sambuc     AArch64::B10, AArch64::B11, AArch64::B12, AArch64::B13, AArch64::B14,
345*0a6a1f1dSLionel Sambuc     AArch64::B15, AArch64::B16, AArch64::B17, AArch64::B18, AArch64::B19,
346*0a6a1f1dSLionel Sambuc     AArch64::B20, AArch64::B21, AArch64::B22, AArch64::B23, AArch64::B24,
347*0a6a1f1dSLionel Sambuc     AArch64::B25, AArch64::B26, AArch64::B27, AArch64::B28, AArch64::B29,
348*0a6a1f1dSLionel Sambuc     AArch64::B30, AArch64::B31
349*0a6a1f1dSLionel Sambuc };
350*0a6a1f1dSLionel Sambuc 
DecodeFPR8RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)351*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFPR8RegisterClass(MCInst &Inst, unsigned RegNo,
352*0a6a1f1dSLionel Sambuc                                             uint64_t Addr,
353*0a6a1f1dSLionel Sambuc                                             const void *Decoder) {
354*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
355*0a6a1f1dSLionel Sambuc     return Fail;
356*0a6a1f1dSLionel Sambuc 
357*0a6a1f1dSLionel Sambuc   unsigned Register = FPR8DecoderTable[RegNo];
358*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
359*0a6a1f1dSLionel Sambuc   return Success;
360*0a6a1f1dSLionel Sambuc }
361*0a6a1f1dSLionel Sambuc 
362*0a6a1f1dSLionel Sambuc static const unsigned GPR64DecoderTable[] = {
363*0a6a1f1dSLionel Sambuc     AArch64::X0,  AArch64::X1,  AArch64::X2,  AArch64::X3,  AArch64::X4,
364*0a6a1f1dSLionel Sambuc     AArch64::X5,  AArch64::X6,  AArch64::X7,  AArch64::X8,  AArch64::X9,
365*0a6a1f1dSLionel Sambuc     AArch64::X10, AArch64::X11, AArch64::X12, AArch64::X13, AArch64::X14,
366*0a6a1f1dSLionel Sambuc     AArch64::X15, AArch64::X16, AArch64::X17, AArch64::X18, AArch64::X19,
367*0a6a1f1dSLionel Sambuc     AArch64::X20, AArch64::X21, AArch64::X22, AArch64::X23, AArch64::X24,
368*0a6a1f1dSLionel Sambuc     AArch64::X25, AArch64::X26, AArch64::X27, AArch64::X28, AArch64::FP,
369*0a6a1f1dSLionel Sambuc     AArch64::LR,  AArch64::XZR
370*0a6a1f1dSLionel Sambuc };
371*0a6a1f1dSLionel Sambuc 
DecodeGPR64RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)372*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, unsigned RegNo,
373*0a6a1f1dSLionel Sambuc                                              uint64_t Addr,
374*0a6a1f1dSLionel Sambuc                                              const void *Decoder) {
375*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
376*0a6a1f1dSLionel Sambuc     return Fail;
377*0a6a1f1dSLionel Sambuc 
378*0a6a1f1dSLionel Sambuc   unsigned Register = GPR64DecoderTable[RegNo];
379*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
380*0a6a1f1dSLionel Sambuc   return Success;
381*0a6a1f1dSLionel Sambuc }
382*0a6a1f1dSLionel Sambuc 
DecodeGPR64spRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)383*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR64spRegisterClass(MCInst &Inst, unsigned RegNo,
384*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
385*0a6a1f1dSLionel Sambuc                                                const void *Decoder) {
386*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
387*0a6a1f1dSLionel Sambuc     return Fail;
388*0a6a1f1dSLionel Sambuc   unsigned Register = GPR64DecoderTable[RegNo];
389*0a6a1f1dSLionel Sambuc   if (Register == AArch64::XZR)
390*0a6a1f1dSLionel Sambuc     Register = AArch64::SP;
391*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
392*0a6a1f1dSLionel Sambuc   return Success;
393*0a6a1f1dSLionel Sambuc }
394*0a6a1f1dSLionel Sambuc 
395*0a6a1f1dSLionel Sambuc static const unsigned GPR32DecoderTable[] = {
396*0a6a1f1dSLionel Sambuc     AArch64::W0,  AArch64::W1,  AArch64::W2,  AArch64::W3,  AArch64::W4,
397*0a6a1f1dSLionel Sambuc     AArch64::W5,  AArch64::W6,  AArch64::W7,  AArch64::W8,  AArch64::W9,
398*0a6a1f1dSLionel Sambuc     AArch64::W10, AArch64::W11, AArch64::W12, AArch64::W13, AArch64::W14,
399*0a6a1f1dSLionel Sambuc     AArch64::W15, AArch64::W16, AArch64::W17, AArch64::W18, AArch64::W19,
400*0a6a1f1dSLionel Sambuc     AArch64::W20, AArch64::W21, AArch64::W22, AArch64::W23, AArch64::W24,
401*0a6a1f1dSLionel Sambuc     AArch64::W25, AArch64::W26, AArch64::W27, AArch64::W28, AArch64::W29,
402*0a6a1f1dSLionel Sambuc     AArch64::W30, AArch64::WZR
403*0a6a1f1dSLionel Sambuc };
404*0a6a1f1dSLionel Sambuc 
DecodeGPR32RegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)405*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo,
406*0a6a1f1dSLionel Sambuc                                              uint64_t Addr,
407*0a6a1f1dSLionel Sambuc                                              const void *Decoder) {
408*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
409*0a6a1f1dSLionel Sambuc     return Fail;
410*0a6a1f1dSLionel Sambuc 
411*0a6a1f1dSLionel Sambuc   unsigned Register = GPR32DecoderTable[RegNo];
412*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
413*0a6a1f1dSLionel Sambuc   return Success;
414*0a6a1f1dSLionel Sambuc }
415*0a6a1f1dSLionel Sambuc 
DecodeGPR32spRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)416*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeGPR32spRegisterClass(MCInst &Inst, unsigned RegNo,
417*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
418*0a6a1f1dSLionel Sambuc                                                const void *Decoder) {
419*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
420*0a6a1f1dSLionel Sambuc     return Fail;
421*0a6a1f1dSLionel Sambuc 
422*0a6a1f1dSLionel Sambuc   unsigned Register = GPR32DecoderTable[RegNo];
423*0a6a1f1dSLionel Sambuc   if (Register == AArch64::WZR)
424*0a6a1f1dSLionel Sambuc     Register = AArch64::WSP;
425*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
426*0a6a1f1dSLionel Sambuc   return Success;
427*0a6a1f1dSLionel Sambuc }
428*0a6a1f1dSLionel Sambuc 
429*0a6a1f1dSLionel Sambuc static const unsigned VectorDecoderTable[] = {
430*0a6a1f1dSLionel Sambuc     AArch64::Q0,  AArch64::Q1,  AArch64::Q2,  AArch64::Q3,  AArch64::Q4,
431*0a6a1f1dSLionel Sambuc     AArch64::Q5,  AArch64::Q6,  AArch64::Q7,  AArch64::Q8,  AArch64::Q9,
432*0a6a1f1dSLionel Sambuc     AArch64::Q10, AArch64::Q11, AArch64::Q12, AArch64::Q13, AArch64::Q14,
433*0a6a1f1dSLionel Sambuc     AArch64::Q15, AArch64::Q16, AArch64::Q17, AArch64::Q18, AArch64::Q19,
434*0a6a1f1dSLionel Sambuc     AArch64::Q20, AArch64::Q21, AArch64::Q22, AArch64::Q23, AArch64::Q24,
435*0a6a1f1dSLionel Sambuc     AArch64::Q25, AArch64::Q26, AArch64::Q27, AArch64::Q28, AArch64::Q29,
436*0a6a1f1dSLionel Sambuc     AArch64::Q30, AArch64::Q31
437*0a6a1f1dSLionel Sambuc };
438*0a6a1f1dSLionel Sambuc 
DecodeVectorRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)439*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVectorRegisterClass(MCInst &Inst, unsigned RegNo,
440*0a6a1f1dSLionel Sambuc                                               uint64_t Addr,
441*0a6a1f1dSLionel Sambuc                                               const void *Decoder) {
442*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
443*0a6a1f1dSLionel Sambuc     return Fail;
444*0a6a1f1dSLionel Sambuc 
445*0a6a1f1dSLionel Sambuc   unsigned Register = VectorDecoderTable[RegNo];
446*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
447*0a6a1f1dSLionel Sambuc   return Success;
448*0a6a1f1dSLionel Sambuc }
449*0a6a1f1dSLionel Sambuc 
450*0a6a1f1dSLionel Sambuc static const unsigned QQDecoderTable[] = {
451*0a6a1f1dSLionel Sambuc   AArch64::Q0_Q1,   AArch64::Q1_Q2,   AArch64::Q2_Q3,   AArch64::Q3_Q4,
452*0a6a1f1dSLionel Sambuc   AArch64::Q4_Q5,   AArch64::Q5_Q6,   AArch64::Q6_Q7,   AArch64::Q7_Q8,
453*0a6a1f1dSLionel Sambuc   AArch64::Q8_Q9,   AArch64::Q9_Q10,  AArch64::Q10_Q11, AArch64::Q11_Q12,
454*0a6a1f1dSLionel Sambuc   AArch64::Q12_Q13, AArch64::Q13_Q14, AArch64::Q14_Q15, AArch64::Q15_Q16,
455*0a6a1f1dSLionel Sambuc   AArch64::Q16_Q17, AArch64::Q17_Q18, AArch64::Q18_Q19, AArch64::Q19_Q20,
456*0a6a1f1dSLionel Sambuc   AArch64::Q20_Q21, AArch64::Q21_Q22, AArch64::Q22_Q23, AArch64::Q23_Q24,
457*0a6a1f1dSLionel Sambuc   AArch64::Q24_Q25, AArch64::Q25_Q26, AArch64::Q26_Q27, AArch64::Q27_Q28,
458*0a6a1f1dSLionel Sambuc   AArch64::Q28_Q29, AArch64::Q29_Q30, AArch64::Q30_Q31, AArch64::Q31_Q0
459*0a6a1f1dSLionel Sambuc };
460*0a6a1f1dSLionel Sambuc 
DecodeQQRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)461*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeQQRegisterClass(MCInst &Inst, unsigned RegNo,
462*0a6a1f1dSLionel Sambuc                                           uint64_t Addr, const void *Decoder) {
463*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
464*0a6a1f1dSLionel Sambuc     return Fail;
465*0a6a1f1dSLionel Sambuc   unsigned Register = QQDecoderTable[RegNo];
466*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
467*0a6a1f1dSLionel Sambuc   return Success;
468*0a6a1f1dSLionel Sambuc }
469*0a6a1f1dSLionel Sambuc 
470*0a6a1f1dSLionel Sambuc static const unsigned QQQDecoderTable[] = {
471*0a6a1f1dSLionel Sambuc   AArch64::Q0_Q1_Q2,    AArch64::Q1_Q2_Q3,    AArch64::Q2_Q3_Q4,
472*0a6a1f1dSLionel Sambuc   AArch64::Q3_Q4_Q5,    AArch64::Q4_Q5_Q6,    AArch64::Q5_Q6_Q7,
473*0a6a1f1dSLionel Sambuc   AArch64::Q6_Q7_Q8,    AArch64::Q7_Q8_Q9,    AArch64::Q8_Q9_Q10,
474*0a6a1f1dSLionel Sambuc   AArch64::Q9_Q10_Q11,  AArch64::Q10_Q11_Q12, AArch64::Q11_Q12_Q13,
475*0a6a1f1dSLionel Sambuc   AArch64::Q12_Q13_Q14, AArch64::Q13_Q14_Q15, AArch64::Q14_Q15_Q16,
476*0a6a1f1dSLionel Sambuc   AArch64::Q15_Q16_Q17, AArch64::Q16_Q17_Q18, AArch64::Q17_Q18_Q19,
477*0a6a1f1dSLionel Sambuc   AArch64::Q18_Q19_Q20, AArch64::Q19_Q20_Q21, AArch64::Q20_Q21_Q22,
478*0a6a1f1dSLionel Sambuc   AArch64::Q21_Q22_Q23, AArch64::Q22_Q23_Q24, AArch64::Q23_Q24_Q25,
479*0a6a1f1dSLionel Sambuc   AArch64::Q24_Q25_Q26, AArch64::Q25_Q26_Q27, AArch64::Q26_Q27_Q28,
480*0a6a1f1dSLionel Sambuc   AArch64::Q27_Q28_Q29, AArch64::Q28_Q29_Q30, AArch64::Q29_Q30_Q31,
481*0a6a1f1dSLionel Sambuc   AArch64::Q30_Q31_Q0,  AArch64::Q31_Q0_Q1
482*0a6a1f1dSLionel Sambuc };
483*0a6a1f1dSLionel Sambuc 
DecodeQQQRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)484*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeQQQRegisterClass(MCInst &Inst, unsigned RegNo,
485*0a6a1f1dSLionel Sambuc                                            uint64_t Addr, const void *Decoder) {
486*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
487*0a6a1f1dSLionel Sambuc     return Fail;
488*0a6a1f1dSLionel Sambuc   unsigned Register = QQQDecoderTable[RegNo];
489*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
490*0a6a1f1dSLionel Sambuc   return Success;
491*0a6a1f1dSLionel Sambuc }
492*0a6a1f1dSLionel Sambuc 
493*0a6a1f1dSLionel Sambuc static const unsigned QQQQDecoderTable[] = {
494*0a6a1f1dSLionel Sambuc   AArch64::Q0_Q1_Q2_Q3,     AArch64::Q1_Q2_Q3_Q4,     AArch64::Q2_Q3_Q4_Q5,
495*0a6a1f1dSLionel Sambuc   AArch64::Q3_Q4_Q5_Q6,     AArch64::Q4_Q5_Q6_Q7,     AArch64::Q5_Q6_Q7_Q8,
496*0a6a1f1dSLionel Sambuc   AArch64::Q6_Q7_Q8_Q9,     AArch64::Q7_Q8_Q9_Q10,    AArch64::Q8_Q9_Q10_Q11,
497*0a6a1f1dSLionel Sambuc   AArch64::Q9_Q10_Q11_Q12,  AArch64::Q10_Q11_Q12_Q13, AArch64::Q11_Q12_Q13_Q14,
498*0a6a1f1dSLionel Sambuc   AArch64::Q12_Q13_Q14_Q15, AArch64::Q13_Q14_Q15_Q16, AArch64::Q14_Q15_Q16_Q17,
499*0a6a1f1dSLionel Sambuc   AArch64::Q15_Q16_Q17_Q18, AArch64::Q16_Q17_Q18_Q19, AArch64::Q17_Q18_Q19_Q20,
500*0a6a1f1dSLionel Sambuc   AArch64::Q18_Q19_Q20_Q21, AArch64::Q19_Q20_Q21_Q22, AArch64::Q20_Q21_Q22_Q23,
501*0a6a1f1dSLionel Sambuc   AArch64::Q21_Q22_Q23_Q24, AArch64::Q22_Q23_Q24_Q25, AArch64::Q23_Q24_Q25_Q26,
502*0a6a1f1dSLionel Sambuc   AArch64::Q24_Q25_Q26_Q27, AArch64::Q25_Q26_Q27_Q28, AArch64::Q26_Q27_Q28_Q29,
503*0a6a1f1dSLionel Sambuc   AArch64::Q27_Q28_Q29_Q30, AArch64::Q28_Q29_Q30_Q31, AArch64::Q29_Q30_Q31_Q0,
504*0a6a1f1dSLionel Sambuc   AArch64::Q30_Q31_Q0_Q1,   AArch64::Q31_Q0_Q1_Q2
505*0a6a1f1dSLionel Sambuc };
506*0a6a1f1dSLionel Sambuc 
DecodeQQQQRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)507*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeQQQQRegisterClass(MCInst &Inst, unsigned RegNo,
508*0a6a1f1dSLionel Sambuc                                             uint64_t Addr,
509*0a6a1f1dSLionel Sambuc                                             const void *Decoder) {
510*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
511*0a6a1f1dSLionel Sambuc     return Fail;
512*0a6a1f1dSLionel Sambuc   unsigned Register = QQQQDecoderTable[RegNo];
513*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
514*0a6a1f1dSLionel Sambuc   return Success;
515*0a6a1f1dSLionel Sambuc }
516*0a6a1f1dSLionel Sambuc 
517*0a6a1f1dSLionel Sambuc static const unsigned DDDecoderTable[] = {
518*0a6a1f1dSLionel Sambuc   AArch64::D0_D1,   AArch64::D1_D2,   AArch64::D2_D3,   AArch64::D3_D4,
519*0a6a1f1dSLionel Sambuc   AArch64::D4_D5,   AArch64::D5_D6,   AArch64::D6_D7,   AArch64::D7_D8,
520*0a6a1f1dSLionel Sambuc   AArch64::D8_D9,   AArch64::D9_D10,  AArch64::D10_D11, AArch64::D11_D12,
521*0a6a1f1dSLionel Sambuc   AArch64::D12_D13, AArch64::D13_D14, AArch64::D14_D15, AArch64::D15_D16,
522*0a6a1f1dSLionel Sambuc   AArch64::D16_D17, AArch64::D17_D18, AArch64::D18_D19, AArch64::D19_D20,
523*0a6a1f1dSLionel Sambuc   AArch64::D20_D21, AArch64::D21_D22, AArch64::D22_D23, AArch64::D23_D24,
524*0a6a1f1dSLionel Sambuc   AArch64::D24_D25, AArch64::D25_D26, AArch64::D26_D27, AArch64::D27_D28,
525*0a6a1f1dSLionel Sambuc   AArch64::D28_D29, AArch64::D29_D30, AArch64::D30_D31, AArch64::D31_D0
526*0a6a1f1dSLionel Sambuc };
527*0a6a1f1dSLionel Sambuc 
DecodeDDRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)528*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeDDRegisterClass(MCInst &Inst, unsigned RegNo,
529*0a6a1f1dSLionel Sambuc                                           uint64_t Addr, const void *Decoder) {
530*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
531*0a6a1f1dSLionel Sambuc     return Fail;
532*0a6a1f1dSLionel Sambuc   unsigned Register = DDDecoderTable[RegNo];
533*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
534*0a6a1f1dSLionel Sambuc   return Success;
535*0a6a1f1dSLionel Sambuc }
536*0a6a1f1dSLionel Sambuc 
537*0a6a1f1dSLionel Sambuc static const unsigned DDDDecoderTable[] = {
538*0a6a1f1dSLionel Sambuc   AArch64::D0_D1_D2,    AArch64::D1_D2_D3,    AArch64::D2_D3_D4,
539*0a6a1f1dSLionel Sambuc   AArch64::D3_D4_D5,    AArch64::D4_D5_D6,    AArch64::D5_D6_D7,
540*0a6a1f1dSLionel Sambuc   AArch64::D6_D7_D8,    AArch64::D7_D8_D9,    AArch64::D8_D9_D10,
541*0a6a1f1dSLionel Sambuc   AArch64::D9_D10_D11,  AArch64::D10_D11_D12, AArch64::D11_D12_D13,
542*0a6a1f1dSLionel Sambuc   AArch64::D12_D13_D14, AArch64::D13_D14_D15, AArch64::D14_D15_D16,
543*0a6a1f1dSLionel Sambuc   AArch64::D15_D16_D17, AArch64::D16_D17_D18, AArch64::D17_D18_D19,
544*0a6a1f1dSLionel Sambuc   AArch64::D18_D19_D20, AArch64::D19_D20_D21, AArch64::D20_D21_D22,
545*0a6a1f1dSLionel Sambuc   AArch64::D21_D22_D23, AArch64::D22_D23_D24, AArch64::D23_D24_D25,
546*0a6a1f1dSLionel Sambuc   AArch64::D24_D25_D26, AArch64::D25_D26_D27, AArch64::D26_D27_D28,
547*0a6a1f1dSLionel Sambuc   AArch64::D27_D28_D29, AArch64::D28_D29_D30, AArch64::D29_D30_D31,
548*0a6a1f1dSLionel Sambuc   AArch64::D30_D31_D0,  AArch64::D31_D0_D1
549*0a6a1f1dSLionel Sambuc };
550*0a6a1f1dSLionel Sambuc 
DecodeDDDRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)551*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeDDDRegisterClass(MCInst &Inst, unsigned RegNo,
552*0a6a1f1dSLionel Sambuc                                            uint64_t Addr, const void *Decoder) {
553*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
554*0a6a1f1dSLionel Sambuc     return Fail;
555*0a6a1f1dSLionel Sambuc   unsigned Register = DDDDecoderTable[RegNo];
556*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
557*0a6a1f1dSLionel Sambuc   return Success;
558*0a6a1f1dSLionel Sambuc }
559*0a6a1f1dSLionel Sambuc 
560*0a6a1f1dSLionel Sambuc static const unsigned DDDDDecoderTable[] = {
561*0a6a1f1dSLionel Sambuc   AArch64::D0_D1_D2_D3,     AArch64::D1_D2_D3_D4,     AArch64::D2_D3_D4_D5,
562*0a6a1f1dSLionel Sambuc   AArch64::D3_D4_D5_D6,     AArch64::D4_D5_D6_D7,     AArch64::D5_D6_D7_D8,
563*0a6a1f1dSLionel Sambuc   AArch64::D6_D7_D8_D9,     AArch64::D7_D8_D9_D10,    AArch64::D8_D9_D10_D11,
564*0a6a1f1dSLionel Sambuc   AArch64::D9_D10_D11_D12,  AArch64::D10_D11_D12_D13, AArch64::D11_D12_D13_D14,
565*0a6a1f1dSLionel Sambuc   AArch64::D12_D13_D14_D15, AArch64::D13_D14_D15_D16, AArch64::D14_D15_D16_D17,
566*0a6a1f1dSLionel Sambuc   AArch64::D15_D16_D17_D18, AArch64::D16_D17_D18_D19, AArch64::D17_D18_D19_D20,
567*0a6a1f1dSLionel Sambuc   AArch64::D18_D19_D20_D21, AArch64::D19_D20_D21_D22, AArch64::D20_D21_D22_D23,
568*0a6a1f1dSLionel Sambuc   AArch64::D21_D22_D23_D24, AArch64::D22_D23_D24_D25, AArch64::D23_D24_D25_D26,
569*0a6a1f1dSLionel Sambuc   AArch64::D24_D25_D26_D27, AArch64::D25_D26_D27_D28, AArch64::D26_D27_D28_D29,
570*0a6a1f1dSLionel Sambuc   AArch64::D27_D28_D29_D30, AArch64::D28_D29_D30_D31, AArch64::D29_D30_D31_D0,
571*0a6a1f1dSLionel Sambuc   AArch64::D30_D31_D0_D1,   AArch64::D31_D0_D1_D2
572*0a6a1f1dSLionel Sambuc };
573*0a6a1f1dSLionel Sambuc 
DecodeDDDDRegisterClass(MCInst & Inst,unsigned RegNo,uint64_t Addr,const void * Decoder)574*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeDDDDRegisterClass(MCInst &Inst, unsigned RegNo,
575*0a6a1f1dSLionel Sambuc                                             uint64_t Addr,
576*0a6a1f1dSLionel Sambuc                                             const void *Decoder) {
577*0a6a1f1dSLionel Sambuc   if (RegNo > 31)
578*0a6a1f1dSLionel Sambuc     return Fail;
579*0a6a1f1dSLionel Sambuc   unsigned Register = DDDDDecoderTable[RegNo];
580*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateReg(Register));
581*0a6a1f1dSLionel Sambuc   return Success;
582*0a6a1f1dSLionel Sambuc }
583*0a6a1f1dSLionel Sambuc 
DecodeFixedPointScaleImm32(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)584*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFixedPointScaleImm32(llvm::MCInst &Inst, unsigned Imm,
585*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
586*0a6a1f1dSLionel Sambuc                                                const void *Decoder) {
587*0a6a1f1dSLionel Sambuc   // scale{5} is asserted as 1 in tblgen.
588*0a6a1f1dSLionel Sambuc   Imm |= 0x20;
589*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(64 - Imm));
590*0a6a1f1dSLionel Sambuc   return Success;
591*0a6a1f1dSLionel Sambuc }
592*0a6a1f1dSLionel Sambuc 
DecodeFixedPointScaleImm64(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)593*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeFixedPointScaleImm64(llvm::MCInst &Inst, unsigned Imm,
594*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
595*0a6a1f1dSLionel Sambuc                                                const void *Decoder) {
596*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(64 - Imm));
597*0a6a1f1dSLionel Sambuc   return Success;
598*0a6a1f1dSLionel Sambuc }
599*0a6a1f1dSLionel Sambuc 
DecodePCRelLabel19(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)600*0a6a1f1dSLionel Sambuc static DecodeStatus DecodePCRelLabel19(llvm::MCInst &Inst, unsigned Imm,
601*0a6a1f1dSLionel Sambuc                                        uint64_t Addr, const void *Decoder) {
602*0a6a1f1dSLionel Sambuc   int64_t ImmVal = Imm;
603*0a6a1f1dSLionel Sambuc   const AArch64Disassembler *Dis =
604*0a6a1f1dSLionel Sambuc       static_cast<const AArch64Disassembler *>(Decoder);
605*0a6a1f1dSLionel Sambuc 
606*0a6a1f1dSLionel Sambuc   // Sign-extend 19-bit immediate.
607*0a6a1f1dSLionel Sambuc   if (ImmVal & (1 << (19 - 1)))
608*0a6a1f1dSLionel Sambuc     ImmVal |= ~((1LL << 19) - 1);
609*0a6a1f1dSLionel Sambuc 
610*0a6a1f1dSLionel Sambuc   if (!Dis->tryAddingSymbolicOperand(Inst, ImmVal *  4, Addr,
611*0a6a1f1dSLionel Sambuc                                      Inst.getOpcode() != AArch64::LDRXl, 0, 4))
612*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(ImmVal));
613*0a6a1f1dSLionel Sambuc   return Success;
614*0a6a1f1dSLionel Sambuc }
615*0a6a1f1dSLionel Sambuc 
DecodeMemExtend(llvm::MCInst & Inst,unsigned Imm,uint64_t Address,const void * Decoder)616*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMemExtend(llvm::MCInst &Inst, unsigned Imm,
617*0a6a1f1dSLionel Sambuc                                     uint64_t Address, const void *Decoder) {
618*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm((Imm  >> 1) & 1));
619*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(Imm & 1));
620*0a6a1f1dSLionel Sambuc   return Success;
621*0a6a1f1dSLionel Sambuc }
622*0a6a1f1dSLionel Sambuc 
DecodeMRSSystemRegister(llvm::MCInst & Inst,unsigned Imm,uint64_t Address,const void * Decoder)623*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMRSSystemRegister(llvm::MCInst &Inst, unsigned Imm,
624f4a2713aSLionel Sambuc                                             uint64_t Address,
625f4a2713aSLionel Sambuc                                             const void *Decoder) {
626*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(Imm));
627*0a6a1f1dSLionel Sambuc 
628*0a6a1f1dSLionel Sambuc   // Every system register in the encoding space is valid with the syntax
629*0a6a1f1dSLionel Sambuc   // S<op0>_<op1>_<Cn>_<Cm>_<op2>, so decoding system registers always succeeds.
630*0a6a1f1dSLionel Sambuc   return Success;
631f4a2713aSLionel Sambuc }
632f4a2713aSLionel Sambuc 
DecodeMSRSystemRegister(llvm::MCInst & Inst,unsigned Imm,uint64_t Address,const void * Decoder)633*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMSRSystemRegister(llvm::MCInst &Inst, unsigned Imm,
634f4a2713aSLionel Sambuc                                             uint64_t Address,
635f4a2713aSLionel Sambuc                                             const void *Decoder) {
636*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(Imm));
637f4a2713aSLionel Sambuc 
638*0a6a1f1dSLionel Sambuc   return Success;
639f4a2713aSLionel Sambuc }
640f4a2713aSLionel Sambuc 
DecodeFMOVLaneInstruction(llvm::MCInst & Inst,unsigned Insn,uint64_t Address,const void * Decoder)641f4a2713aSLionel Sambuc static DecodeStatus DecodeFMOVLaneInstruction(llvm::MCInst &Inst, unsigned Insn,
642f4a2713aSLionel Sambuc                                               uint64_t Address,
643f4a2713aSLionel Sambuc                                               const void *Decoder) {
644f4a2713aSLionel Sambuc   // This decoder exists to add the dummy Lane operand to the MCInst, which must
645f4a2713aSLionel Sambuc   // be 1 in assembly but has no other real manifestation.
646f4a2713aSLionel Sambuc   unsigned Rd = fieldFromInstruction(Insn, 0, 5);
647f4a2713aSLionel Sambuc   unsigned Rn = fieldFromInstruction(Insn, 5, 5);
648f4a2713aSLionel Sambuc   unsigned IsToVec = fieldFromInstruction(Insn, 16, 1);
649f4a2713aSLionel Sambuc 
650f4a2713aSLionel Sambuc   if (IsToVec) {
651f4a2713aSLionel Sambuc     DecodeFPR128RegisterClass(Inst, Rd, Address, Decoder);
652f4a2713aSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rn, Address, Decoder);
653f4a2713aSLionel Sambuc   } else {
654f4a2713aSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder);
655f4a2713aSLionel Sambuc     DecodeFPR128RegisterClass(Inst, Rn, Address, Decoder);
656f4a2713aSLionel Sambuc   }
657f4a2713aSLionel Sambuc 
658f4a2713aSLionel Sambuc   // Add the lane
659f4a2713aSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(1));
660f4a2713aSLionel Sambuc 
661*0a6a1f1dSLionel Sambuc   return Success;
662f4a2713aSLionel Sambuc }
663f4a2713aSLionel Sambuc 
DecodeVecShiftRImm(llvm::MCInst & Inst,unsigned Imm,unsigned Add)664*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftRImm(llvm::MCInst &Inst, unsigned Imm,
665*0a6a1f1dSLionel Sambuc                                        unsigned Add) {
666*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(Add - Imm));
667*0a6a1f1dSLionel Sambuc   return Success;
668*0a6a1f1dSLionel Sambuc }
669f4a2713aSLionel Sambuc 
DecodeVecShiftLImm(llvm::MCInst & Inst,unsigned Imm,unsigned Add)670*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftLImm(llvm::MCInst &Inst, unsigned Imm,
671*0a6a1f1dSLionel Sambuc                                        unsigned Add) {
672*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm((Imm + Add) & (Add - 1)));
673*0a6a1f1dSLionel Sambuc   return Success;
674*0a6a1f1dSLionel Sambuc }
675*0a6a1f1dSLionel Sambuc 
DecodeVecShiftR64Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)676*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR64Imm(llvm::MCInst &Inst, unsigned Imm,
677*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder) {
678*0a6a1f1dSLionel Sambuc   return DecodeVecShiftRImm(Inst, Imm, 64);
679*0a6a1f1dSLionel Sambuc }
680*0a6a1f1dSLionel Sambuc 
DecodeVecShiftR64ImmNarrow(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)681*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR64ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
682*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
683f4a2713aSLionel Sambuc                                                const void *Decoder) {
684*0a6a1f1dSLionel Sambuc   return DecodeVecShiftRImm(Inst, Imm | 0x20, 64);
685f4a2713aSLionel Sambuc }
686f4a2713aSLionel Sambuc 
DecodeVecShiftR32Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)687*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR32Imm(llvm::MCInst &Inst, unsigned Imm,
688*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder) {
689*0a6a1f1dSLionel Sambuc   return DecodeVecShiftRImm(Inst, Imm, 32);
690*0a6a1f1dSLionel Sambuc }
691*0a6a1f1dSLionel Sambuc 
DecodeVecShiftR32ImmNarrow(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)692*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR32ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
693*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
694*0a6a1f1dSLionel Sambuc                                                const void *Decoder) {
695*0a6a1f1dSLionel Sambuc   return DecodeVecShiftRImm(Inst, Imm | 0x10, 32);
696*0a6a1f1dSLionel Sambuc }
697*0a6a1f1dSLionel Sambuc 
DecodeVecShiftR16Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)698*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR16Imm(llvm::MCInst &Inst, unsigned Imm,
699*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder) {
700*0a6a1f1dSLionel Sambuc   return DecodeVecShiftRImm(Inst, Imm, 16);
701*0a6a1f1dSLionel Sambuc }
702*0a6a1f1dSLionel Sambuc 
DecodeVecShiftR16ImmNarrow(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)703*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR16ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
704*0a6a1f1dSLionel Sambuc                                                uint64_t Addr,
705*0a6a1f1dSLionel Sambuc                                                const void *Decoder) {
706*0a6a1f1dSLionel Sambuc   return DecodeVecShiftRImm(Inst, Imm | 0x8, 16);
707*0a6a1f1dSLionel Sambuc }
708*0a6a1f1dSLionel Sambuc 
DecodeVecShiftR8Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)709*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftR8Imm(llvm::MCInst &Inst, unsigned Imm,
710*0a6a1f1dSLionel Sambuc                                         uint64_t Addr, const void *Decoder) {
711*0a6a1f1dSLionel Sambuc   return DecodeVecShiftRImm(Inst, Imm, 8);
712*0a6a1f1dSLionel Sambuc }
713*0a6a1f1dSLionel Sambuc 
DecodeVecShiftL64Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)714*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL64Imm(llvm::MCInst &Inst, unsigned Imm,
715*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder) {
716*0a6a1f1dSLionel Sambuc   return DecodeVecShiftLImm(Inst, Imm, 64);
717*0a6a1f1dSLionel Sambuc }
718*0a6a1f1dSLionel Sambuc 
DecodeVecShiftL32Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)719*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL32Imm(llvm::MCInst &Inst, unsigned Imm,
720*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder) {
721*0a6a1f1dSLionel Sambuc   return DecodeVecShiftLImm(Inst, Imm, 32);
722*0a6a1f1dSLionel Sambuc }
723*0a6a1f1dSLionel Sambuc 
DecodeVecShiftL16Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)724*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL16Imm(llvm::MCInst &Inst, unsigned Imm,
725*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder) {
726*0a6a1f1dSLionel Sambuc   return DecodeVecShiftLImm(Inst, Imm, 16);
727*0a6a1f1dSLionel Sambuc }
728*0a6a1f1dSLionel Sambuc 
DecodeVecShiftL8Imm(llvm::MCInst & Inst,unsigned Imm,uint64_t Addr,const void * Decoder)729*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeVecShiftL8Imm(llvm::MCInst &Inst, unsigned Imm,
730*0a6a1f1dSLionel Sambuc                                         uint64_t Addr, const void *Decoder) {
731*0a6a1f1dSLionel Sambuc   return DecodeVecShiftLImm(Inst, Imm, 8);
732*0a6a1f1dSLionel Sambuc }
733*0a6a1f1dSLionel Sambuc 
DecodeThreeAddrSRegInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)734*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeThreeAddrSRegInstruction(llvm::MCInst &Inst,
735*0a6a1f1dSLionel Sambuc                                                    uint32_t insn, uint64_t Addr,
736*0a6a1f1dSLionel Sambuc                                                    const void *Decoder) {
737*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
738*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
739*0a6a1f1dSLionel Sambuc   unsigned Rm = fieldFromInstruction(insn, 16, 5);
740*0a6a1f1dSLionel Sambuc   unsigned shiftHi = fieldFromInstruction(insn, 22, 2);
741*0a6a1f1dSLionel Sambuc   unsigned shiftLo = fieldFromInstruction(insn, 10, 6);
742*0a6a1f1dSLionel Sambuc   unsigned shift = (shiftHi << 6) | shiftLo;
743*0a6a1f1dSLionel Sambuc   switch (Inst.getOpcode()) {
744*0a6a1f1dSLionel Sambuc   default:
745*0a6a1f1dSLionel Sambuc     return Fail;
746*0a6a1f1dSLionel Sambuc   case AArch64::ADDWrs:
747*0a6a1f1dSLionel Sambuc   case AArch64::ADDSWrs:
748*0a6a1f1dSLionel Sambuc   case AArch64::SUBWrs:
749*0a6a1f1dSLionel Sambuc   case AArch64::SUBSWrs:
750*0a6a1f1dSLionel Sambuc     // if shift == '11' then ReservedValue()
751*0a6a1f1dSLionel Sambuc     if (shiftHi == 0x3)
752*0a6a1f1dSLionel Sambuc       return Fail;
753*0a6a1f1dSLionel Sambuc     // Deliberate fallthrough
754*0a6a1f1dSLionel Sambuc   case AArch64::ANDWrs:
755*0a6a1f1dSLionel Sambuc   case AArch64::ANDSWrs:
756*0a6a1f1dSLionel Sambuc   case AArch64::BICWrs:
757*0a6a1f1dSLionel Sambuc   case AArch64::BICSWrs:
758*0a6a1f1dSLionel Sambuc   case AArch64::ORRWrs:
759*0a6a1f1dSLionel Sambuc   case AArch64::ORNWrs:
760*0a6a1f1dSLionel Sambuc   case AArch64::EORWrs:
761*0a6a1f1dSLionel Sambuc   case AArch64::EONWrs: {
762*0a6a1f1dSLionel Sambuc     // if sf == '0' and imm6<5> == '1' then ReservedValue()
763*0a6a1f1dSLionel Sambuc     if (shiftLo >> 5 == 1)
764*0a6a1f1dSLionel Sambuc       return Fail;
765*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
766*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rn, Addr, Decoder);
767*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
768*0a6a1f1dSLionel Sambuc     break;
769*0a6a1f1dSLionel Sambuc   }
770*0a6a1f1dSLionel Sambuc   case AArch64::ADDXrs:
771*0a6a1f1dSLionel Sambuc   case AArch64::ADDSXrs:
772*0a6a1f1dSLionel Sambuc   case AArch64::SUBXrs:
773*0a6a1f1dSLionel Sambuc   case AArch64::SUBSXrs:
774*0a6a1f1dSLionel Sambuc     // if shift == '11' then ReservedValue()
775*0a6a1f1dSLionel Sambuc     if (shiftHi == 0x3)
776*0a6a1f1dSLionel Sambuc       return Fail;
777*0a6a1f1dSLionel Sambuc     // Deliberate fallthrough
778*0a6a1f1dSLionel Sambuc   case AArch64::ANDXrs:
779*0a6a1f1dSLionel Sambuc   case AArch64::ANDSXrs:
780*0a6a1f1dSLionel Sambuc   case AArch64::BICXrs:
781*0a6a1f1dSLionel Sambuc   case AArch64::BICSXrs:
782*0a6a1f1dSLionel Sambuc   case AArch64::ORRXrs:
783*0a6a1f1dSLionel Sambuc   case AArch64::ORNXrs:
784*0a6a1f1dSLionel Sambuc   case AArch64::EORXrs:
785*0a6a1f1dSLionel Sambuc   case AArch64::EONXrs:
786*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
787*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder);
788*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
789*0a6a1f1dSLionel Sambuc     break;
790*0a6a1f1dSLionel Sambuc   }
791*0a6a1f1dSLionel Sambuc 
792*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(shift));
793*0a6a1f1dSLionel Sambuc   return Success;
794*0a6a1f1dSLionel Sambuc }
795*0a6a1f1dSLionel Sambuc 
DecodeMoveImmInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)796*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeMoveImmInstruction(llvm::MCInst &Inst, uint32_t insn,
797*0a6a1f1dSLionel Sambuc                                              uint64_t Addr,
798*0a6a1f1dSLionel Sambuc                                              const void *Decoder) {
799*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
800*0a6a1f1dSLionel Sambuc   unsigned imm = fieldFromInstruction(insn, 5, 16);
801*0a6a1f1dSLionel Sambuc   unsigned shift = fieldFromInstruction(insn, 21, 2);
802*0a6a1f1dSLionel Sambuc   shift <<= 4;
803*0a6a1f1dSLionel Sambuc   switch (Inst.getOpcode()) {
804*0a6a1f1dSLionel Sambuc   default:
805*0a6a1f1dSLionel Sambuc     return Fail;
806*0a6a1f1dSLionel Sambuc   case AArch64::MOVZWi:
807*0a6a1f1dSLionel Sambuc   case AArch64::MOVNWi:
808*0a6a1f1dSLionel Sambuc   case AArch64::MOVKWi:
809*0a6a1f1dSLionel Sambuc     if (shift & (1U << 5))
810*0a6a1f1dSLionel Sambuc       return Fail;
811*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
812*0a6a1f1dSLionel Sambuc     break;
813*0a6a1f1dSLionel Sambuc   case AArch64::MOVZXi:
814*0a6a1f1dSLionel Sambuc   case AArch64::MOVNXi:
815*0a6a1f1dSLionel Sambuc   case AArch64::MOVKXi:
816*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
817*0a6a1f1dSLionel Sambuc     break;
818*0a6a1f1dSLionel Sambuc   }
819*0a6a1f1dSLionel Sambuc 
820*0a6a1f1dSLionel Sambuc   if (Inst.getOpcode() == AArch64::MOVKWi ||
821*0a6a1f1dSLionel Sambuc       Inst.getOpcode() == AArch64::MOVKXi)
822*0a6a1f1dSLionel Sambuc     Inst.addOperand(Inst.getOperand(0));
823*0a6a1f1dSLionel Sambuc 
824*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(imm));
825*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(shift));
826*0a6a1f1dSLionel Sambuc   return Success;
827*0a6a1f1dSLionel Sambuc }
828*0a6a1f1dSLionel Sambuc 
DecodeUnsignedLdStInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)829*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeUnsignedLdStInstruction(llvm::MCInst &Inst,
830*0a6a1f1dSLionel Sambuc                                                   uint32_t insn, uint64_t Addr,
831*0a6a1f1dSLionel Sambuc                                                   const void *Decoder) {
832*0a6a1f1dSLionel Sambuc   unsigned Rt = fieldFromInstruction(insn, 0, 5);
833*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
834*0a6a1f1dSLionel Sambuc   unsigned offset = fieldFromInstruction(insn, 10, 12);
835*0a6a1f1dSLionel Sambuc   const AArch64Disassembler *Dis =
836*0a6a1f1dSLionel Sambuc       static_cast<const AArch64Disassembler *>(Decoder);
837*0a6a1f1dSLionel Sambuc 
838*0a6a1f1dSLionel Sambuc   switch (Inst.getOpcode()) {
839*0a6a1f1dSLionel Sambuc   default:
840*0a6a1f1dSLionel Sambuc     return Fail;
841*0a6a1f1dSLionel Sambuc   case AArch64::PRFMui:
842*0a6a1f1dSLionel Sambuc     // Rt is an immediate in prefetch.
843*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(Rt));
844*0a6a1f1dSLionel Sambuc     break;
845*0a6a1f1dSLionel Sambuc   case AArch64::STRBBui:
846*0a6a1f1dSLionel Sambuc   case AArch64::LDRBBui:
847*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBWui:
848*0a6a1f1dSLionel Sambuc   case AArch64::STRHHui:
849*0a6a1f1dSLionel Sambuc   case AArch64::LDRHHui:
850*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHWui:
851*0a6a1f1dSLionel Sambuc   case AArch64::STRWui:
852*0a6a1f1dSLionel Sambuc   case AArch64::LDRWui:
853*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
854*0a6a1f1dSLionel Sambuc     break;
855*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBXui:
856*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHXui:
857*0a6a1f1dSLionel Sambuc   case AArch64::LDRSWui:
858*0a6a1f1dSLionel Sambuc   case AArch64::STRXui:
859*0a6a1f1dSLionel Sambuc   case AArch64::LDRXui:
860*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
861*0a6a1f1dSLionel Sambuc     break;
862*0a6a1f1dSLionel Sambuc   case AArch64::LDRQui:
863*0a6a1f1dSLionel Sambuc   case AArch64::STRQui:
864*0a6a1f1dSLionel Sambuc     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
865*0a6a1f1dSLionel Sambuc     break;
866*0a6a1f1dSLionel Sambuc   case AArch64::LDRDui:
867*0a6a1f1dSLionel Sambuc   case AArch64::STRDui:
868*0a6a1f1dSLionel Sambuc     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
869*0a6a1f1dSLionel Sambuc     break;
870*0a6a1f1dSLionel Sambuc   case AArch64::LDRSui:
871*0a6a1f1dSLionel Sambuc   case AArch64::STRSui:
872*0a6a1f1dSLionel Sambuc     DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder);
873*0a6a1f1dSLionel Sambuc     break;
874*0a6a1f1dSLionel Sambuc   case AArch64::LDRHui:
875*0a6a1f1dSLionel Sambuc   case AArch64::STRHui:
876*0a6a1f1dSLionel Sambuc     DecodeFPR16RegisterClass(Inst, Rt, Addr, Decoder);
877*0a6a1f1dSLionel Sambuc     break;
878*0a6a1f1dSLionel Sambuc   case AArch64::LDRBui:
879*0a6a1f1dSLionel Sambuc   case AArch64::STRBui:
880*0a6a1f1dSLionel Sambuc     DecodeFPR8RegisterClass(Inst, Rt, Addr, Decoder);
881*0a6a1f1dSLionel Sambuc     break;
882*0a6a1f1dSLionel Sambuc   }
883*0a6a1f1dSLionel Sambuc 
884*0a6a1f1dSLionel Sambuc   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
885*0a6a1f1dSLionel Sambuc   if (!Dis->tryAddingSymbolicOperand(Inst, offset, Addr, Fail, 0, 4))
886*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(offset));
887*0a6a1f1dSLionel Sambuc   return Success;
888*0a6a1f1dSLionel Sambuc }
889*0a6a1f1dSLionel Sambuc 
DecodeSignedLdStInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)890*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeSignedLdStInstruction(llvm::MCInst &Inst,
891*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Addr,
892*0a6a1f1dSLionel Sambuc                                                 const void *Decoder) {
893*0a6a1f1dSLionel Sambuc   unsigned Rt = fieldFromInstruction(insn, 0, 5);
894*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
895*0a6a1f1dSLionel Sambuc   int64_t offset = fieldFromInstruction(insn, 12, 9);
896*0a6a1f1dSLionel Sambuc 
897*0a6a1f1dSLionel Sambuc   // offset is a 9-bit signed immediate, so sign extend it to
898*0a6a1f1dSLionel Sambuc   // fill the unsigned.
899*0a6a1f1dSLionel Sambuc   if (offset & (1 << (9 - 1)))
900*0a6a1f1dSLionel Sambuc     offset |= ~((1LL << 9) - 1);
901*0a6a1f1dSLionel Sambuc 
902*0a6a1f1dSLionel Sambuc   // First operand is always the writeback to the address register, if needed.
903*0a6a1f1dSLionel Sambuc   switch (Inst.getOpcode()) {
904*0a6a1f1dSLionel Sambuc   default:
905*0a6a1f1dSLionel Sambuc     break;
906*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBWpre:
907*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHWpre:
908*0a6a1f1dSLionel Sambuc   case AArch64::STRBBpre:
909*0a6a1f1dSLionel Sambuc   case AArch64::LDRBBpre:
910*0a6a1f1dSLionel Sambuc   case AArch64::STRHHpre:
911*0a6a1f1dSLionel Sambuc   case AArch64::LDRHHpre:
912*0a6a1f1dSLionel Sambuc   case AArch64::STRWpre:
913*0a6a1f1dSLionel Sambuc   case AArch64::LDRWpre:
914*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBWpost:
915*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHWpost:
916*0a6a1f1dSLionel Sambuc   case AArch64::STRBBpost:
917*0a6a1f1dSLionel Sambuc   case AArch64::LDRBBpost:
918*0a6a1f1dSLionel Sambuc   case AArch64::STRHHpost:
919*0a6a1f1dSLionel Sambuc   case AArch64::LDRHHpost:
920*0a6a1f1dSLionel Sambuc   case AArch64::STRWpost:
921*0a6a1f1dSLionel Sambuc   case AArch64::LDRWpost:
922*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBXpre:
923*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHXpre:
924*0a6a1f1dSLionel Sambuc   case AArch64::STRXpre:
925*0a6a1f1dSLionel Sambuc   case AArch64::LDRSWpre:
926*0a6a1f1dSLionel Sambuc   case AArch64::LDRXpre:
927*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBXpost:
928*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHXpost:
929*0a6a1f1dSLionel Sambuc   case AArch64::STRXpost:
930*0a6a1f1dSLionel Sambuc   case AArch64::LDRSWpost:
931*0a6a1f1dSLionel Sambuc   case AArch64::LDRXpost:
932*0a6a1f1dSLionel Sambuc   case AArch64::LDRQpre:
933*0a6a1f1dSLionel Sambuc   case AArch64::STRQpre:
934*0a6a1f1dSLionel Sambuc   case AArch64::LDRQpost:
935*0a6a1f1dSLionel Sambuc   case AArch64::STRQpost:
936*0a6a1f1dSLionel Sambuc   case AArch64::LDRDpre:
937*0a6a1f1dSLionel Sambuc   case AArch64::STRDpre:
938*0a6a1f1dSLionel Sambuc   case AArch64::LDRDpost:
939*0a6a1f1dSLionel Sambuc   case AArch64::STRDpost:
940*0a6a1f1dSLionel Sambuc   case AArch64::LDRSpre:
941*0a6a1f1dSLionel Sambuc   case AArch64::STRSpre:
942*0a6a1f1dSLionel Sambuc   case AArch64::LDRSpost:
943*0a6a1f1dSLionel Sambuc   case AArch64::STRSpost:
944*0a6a1f1dSLionel Sambuc   case AArch64::LDRHpre:
945*0a6a1f1dSLionel Sambuc   case AArch64::STRHpre:
946*0a6a1f1dSLionel Sambuc   case AArch64::LDRHpost:
947*0a6a1f1dSLionel Sambuc   case AArch64::STRHpost:
948*0a6a1f1dSLionel Sambuc   case AArch64::LDRBpre:
949*0a6a1f1dSLionel Sambuc   case AArch64::STRBpre:
950*0a6a1f1dSLionel Sambuc   case AArch64::LDRBpost:
951*0a6a1f1dSLionel Sambuc   case AArch64::STRBpost:
952*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
953*0a6a1f1dSLionel Sambuc     break;
954*0a6a1f1dSLionel Sambuc   }
955*0a6a1f1dSLionel Sambuc 
956*0a6a1f1dSLionel Sambuc   switch (Inst.getOpcode()) {
957*0a6a1f1dSLionel Sambuc   default:
958*0a6a1f1dSLionel Sambuc     return Fail;
959*0a6a1f1dSLionel Sambuc   case AArch64::PRFUMi:
960*0a6a1f1dSLionel Sambuc     // Rt is an immediate in prefetch.
961*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(Rt));
962*0a6a1f1dSLionel Sambuc     break;
963*0a6a1f1dSLionel Sambuc   case AArch64::STURBBi:
964*0a6a1f1dSLionel Sambuc   case AArch64::LDURBBi:
965*0a6a1f1dSLionel Sambuc   case AArch64::LDURSBWi:
966*0a6a1f1dSLionel Sambuc   case AArch64::STURHHi:
967*0a6a1f1dSLionel Sambuc   case AArch64::LDURHHi:
968*0a6a1f1dSLionel Sambuc   case AArch64::LDURSHWi:
969*0a6a1f1dSLionel Sambuc   case AArch64::STURWi:
970*0a6a1f1dSLionel Sambuc   case AArch64::LDURWi:
971*0a6a1f1dSLionel Sambuc   case AArch64::LDTRSBWi:
972*0a6a1f1dSLionel Sambuc   case AArch64::LDTRSHWi:
973*0a6a1f1dSLionel Sambuc   case AArch64::STTRWi:
974*0a6a1f1dSLionel Sambuc   case AArch64::LDTRWi:
975*0a6a1f1dSLionel Sambuc   case AArch64::STTRHi:
976*0a6a1f1dSLionel Sambuc   case AArch64::LDTRHi:
977*0a6a1f1dSLionel Sambuc   case AArch64::LDTRBi:
978*0a6a1f1dSLionel Sambuc   case AArch64::STTRBi:
979*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBWpre:
980*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHWpre:
981*0a6a1f1dSLionel Sambuc   case AArch64::STRBBpre:
982*0a6a1f1dSLionel Sambuc   case AArch64::LDRBBpre:
983*0a6a1f1dSLionel Sambuc   case AArch64::STRHHpre:
984*0a6a1f1dSLionel Sambuc   case AArch64::LDRHHpre:
985*0a6a1f1dSLionel Sambuc   case AArch64::STRWpre:
986*0a6a1f1dSLionel Sambuc   case AArch64::LDRWpre:
987*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBWpost:
988*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHWpost:
989*0a6a1f1dSLionel Sambuc   case AArch64::STRBBpost:
990*0a6a1f1dSLionel Sambuc   case AArch64::LDRBBpost:
991*0a6a1f1dSLionel Sambuc   case AArch64::STRHHpost:
992*0a6a1f1dSLionel Sambuc   case AArch64::LDRHHpost:
993*0a6a1f1dSLionel Sambuc   case AArch64::STRWpost:
994*0a6a1f1dSLionel Sambuc   case AArch64::LDRWpost:
995*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
996*0a6a1f1dSLionel Sambuc     break;
997*0a6a1f1dSLionel Sambuc   case AArch64::LDURSBXi:
998*0a6a1f1dSLionel Sambuc   case AArch64::LDURSHXi:
999*0a6a1f1dSLionel Sambuc   case AArch64::LDURSWi:
1000*0a6a1f1dSLionel Sambuc   case AArch64::STURXi:
1001*0a6a1f1dSLionel Sambuc   case AArch64::LDURXi:
1002*0a6a1f1dSLionel Sambuc   case AArch64::LDTRSBXi:
1003*0a6a1f1dSLionel Sambuc   case AArch64::LDTRSHXi:
1004*0a6a1f1dSLionel Sambuc   case AArch64::LDTRSWi:
1005*0a6a1f1dSLionel Sambuc   case AArch64::STTRXi:
1006*0a6a1f1dSLionel Sambuc   case AArch64::LDTRXi:
1007*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBXpre:
1008*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHXpre:
1009*0a6a1f1dSLionel Sambuc   case AArch64::STRXpre:
1010*0a6a1f1dSLionel Sambuc   case AArch64::LDRSWpre:
1011*0a6a1f1dSLionel Sambuc   case AArch64::LDRXpre:
1012*0a6a1f1dSLionel Sambuc   case AArch64::LDRSBXpost:
1013*0a6a1f1dSLionel Sambuc   case AArch64::LDRSHXpost:
1014*0a6a1f1dSLionel Sambuc   case AArch64::STRXpost:
1015*0a6a1f1dSLionel Sambuc   case AArch64::LDRSWpost:
1016*0a6a1f1dSLionel Sambuc   case AArch64::LDRXpost:
1017*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1018*0a6a1f1dSLionel Sambuc     break;
1019*0a6a1f1dSLionel Sambuc   case AArch64::LDURQi:
1020*0a6a1f1dSLionel Sambuc   case AArch64::STURQi:
1021*0a6a1f1dSLionel Sambuc   case AArch64::LDRQpre:
1022*0a6a1f1dSLionel Sambuc   case AArch64::STRQpre:
1023*0a6a1f1dSLionel Sambuc   case AArch64::LDRQpost:
1024*0a6a1f1dSLionel Sambuc   case AArch64::STRQpost:
1025*0a6a1f1dSLionel Sambuc     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
1026*0a6a1f1dSLionel Sambuc     break;
1027*0a6a1f1dSLionel Sambuc   case AArch64::LDURDi:
1028*0a6a1f1dSLionel Sambuc   case AArch64::STURDi:
1029*0a6a1f1dSLionel Sambuc   case AArch64::LDRDpre:
1030*0a6a1f1dSLionel Sambuc   case AArch64::STRDpre:
1031*0a6a1f1dSLionel Sambuc   case AArch64::LDRDpost:
1032*0a6a1f1dSLionel Sambuc   case AArch64::STRDpost:
1033*0a6a1f1dSLionel Sambuc     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
1034*0a6a1f1dSLionel Sambuc     break;
1035*0a6a1f1dSLionel Sambuc   case AArch64::LDURSi:
1036*0a6a1f1dSLionel Sambuc   case AArch64::STURSi:
1037*0a6a1f1dSLionel Sambuc   case AArch64::LDRSpre:
1038*0a6a1f1dSLionel Sambuc   case AArch64::STRSpre:
1039*0a6a1f1dSLionel Sambuc   case AArch64::LDRSpost:
1040*0a6a1f1dSLionel Sambuc   case AArch64::STRSpost:
1041*0a6a1f1dSLionel Sambuc     DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder);
1042*0a6a1f1dSLionel Sambuc     break;
1043*0a6a1f1dSLionel Sambuc   case AArch64::LDURHi:
1044*0a6a1f1dSLionel Sambuc   case AArch64::STURHi:
1045*0a6a1f1dSLionel Sambuc   case AArch64::LDRHpre:
1046*0a6a1f1dSLionel Sambuc   case AArch64::STRHpre:
1047*0a6a1f1dSLionel Sambuc   case AArch64::LDRHpost:
1048*0a6a1f1dSLionel Sambuc   case AArch64::STRHpost:
1049*0a6a1f1dSLionel Sambuc     DecodeFPR16RegisterClass(Inst, Rt, Addr, Decoder);
1050*0a6a1f1dSLionel Sambuc     break;
1051*0a6a1f1dSLionel Sambuc   case AArch64::LDURBi:
1052*0a6a1f1dSLionel Sambuc   case AArch64::STURBi:
1053*0a6a1f1dSLionel Sambuc   case AArch64::LDRBpre:
1054*0a6a1f1dSLionel Sambuc   case AArch64::STRBpre:
1055*0a6a1f1dSLionel Sambuc   case AArch64::LDRBpost:
1056*0a6a1f1dSLionel Sambuc   case AArch64::STRBpost:
1057*0a6a1f1dSLionel Sambuc     DecodeFPR8RegisterClass(Inst, Rt, Addr, Decoder);
1058*0a6a1f1dSLionel Sambuc     break;
1059*0a6a1f1dSLionel Sambuc   }
1060*0a6a1f1dSLionel Sambuc 
1061*0a6a1f1dSLionel Sambuc   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1062*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(offset));
1063*0a6a1f1dSLionel Sambuc 
1064*0a6a1f1dSLionel Sambuc   bool IsLoad = fieldFromInstruction(insn, 22, 1);
1065*0a6a1f1dSLionel Sambuc   bool IsIndexed = fieldFromInstruction(insn, 10, 2) != 0;
1066*0a6a1f1dSLionel Sambuc   bool IsFP = fieldFromInstruction(insn, 26, 1);
1067*0a6a1f1dSLionel Sambuc 
1068*0a6a1f1dSLionel Sambuc   // Cannot write back to a transfer register (but xzr != sp).
1069*0a6a1f1dSLionel Sambuc   if (IsLoad && IsIndexed && !IsFP && Rn != 31 && Rt == Rn)
1070*0a6a1f1dSLionel Sambuc     return SoftFail;
1071*0a6a1f1dSLionel Sambuc 
1072*0a6a1f1dSLionel Sambuc   return Success;
1073*0a6a1f1dSLionel Sambuc }
1074*0a6a1f1dSLionel Sambuc 
DecodeExclusiveLdStInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1075*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeExclusiveLdStInstruction(llvm::MCInst &Inst,
1076*0a6a1f1dSLionel Sambuc                                                    uint32_t insn, uint64_t Addr,
1077*0a6a1f1dSLionel Sambuc                                                    const void *Decoder) {
1078*0a6a1f1dSLionel Sambuc   unsigned Rt = fieldFromInstruction(insn, 0, 5);
1079*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1080*0a6a1f1dSLionel Sambuc   unsigned Rt2 = fieldFromInstruction(insn, 10, 5);
1081*0a6a1f1dSLionel Sambuc   unsigned Rs = fieldFromInstruction(insn, 16, 5);
1082*0a6a1f1dSLionel Sambuc 
1083*0a6a1f1dSLionel Sambuc   unsigned Opcode = Inst.getOpcode();
1084*0a6a1f1dSLionel Sambuc   switch (Opcode) {
1085*0a6a1f1dSLionel Sambuc   default:
1086*0a6a1f1dSLionel Sambuc     return Fail;
1087*0a6a1f1dSLionel Sambuc   case AArch64::STLXRW:
1088*0a6a1f1dSLionel Sambuc   case AArch64::STLXRB:
1089*0a6a1f1dSLionel Sambuc   case AArch64::STLXRH:
1090*0a6a1f1dSLionel Sambuc   case AArch64::STXRW:
1091*0a6a1f1dSLionel Sambuc   case AArch64::STXRB:
1092*0a6a1f1dSLionel Sambuc   case AArch64::STXRH:
1093*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
1094*0a6a1f1dSLionel Sambuc   // FALLTHROUGH
1095*0a6a1f1dSLionel Sambuc   case AArch64::LDARW:
1096*0a6a1f1dSLionel Sambuc   case AArch64::LDARB:
1097*0a6a1f1dSLionel Sambuc   case AArch64::LDARH:
1098*0a6a1f1dSLionel Sambuc   case AArch64::LDAXRW:
1099*0a6a1f1dSLionel Sambuc   case AArch64::LDAXRB:
1100*0a6a1f1dSLionel Sambuc   case AArch64::LDAXRH:
1101*0a6a1f1dSLionel Sambuc   case AArch64::LDXRW:
1102*0a6a1f1dSLionel Sambuc   case AArch64::LDXRB:
1103*0a6a1f1dSLionel Sambuc   case AArch64::LDXRH:
1104*0a6a1f1dSLionel Sambuc   case AArch64::STLRW:
1105*0a6a1f1dSLionel Sambuc   case AArch64::STLRB:
1106*0a6a1f1dSLionel Sambuc   case AArch64::STLRH:
1107*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1108*0a6a1f1dSLionel Sambuc     break;
1109*0a6a1f1dSLionel Sambuc   case AArch64::STLXRX:
1110*0a6a1f1dSLionel Sambuc   case AArch64::STXRX:
1111*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
1112*0a6a1f1dSLionel Sambuc   // FALLTHROUGH
1113*0a6a1f1dSLionel Sambuc   case AArch64::LDARX:
1114*0a6a1f1dSLionel Sambuc   case AArch64::LDAXRX:
1115*0a6a1f1dSLionel Sambuc   case AArch64::LDXRX:
1116*0a6a1f1dSLionel Sambuc   case AArch64::STLRX:
1117*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1118*0a6a1f1dSLionel Sambuc     break;
1119*0a6a1f1dSLionel Sambuc   case AArch64::STLXPW:
1120*0a6a1f1dSLionel Sambuc   case AArch64::STXPW:
1121*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
1122*0a6a1f1dSLionel Sambuc   // FALLTHROUGH
1123*0a6a1f1dSLionel Sambuc   case AArch64::LDAXPW:
1124*0a6a1f1dSLionel Sambuc   case AArch64::LDXPW:
1125*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1126*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt2, Addr, Decoder);
1127*0a6a1f1dSLionel Sambuc     break;
1128*0a6a1f1dSLionel Sambuc   case AArch64::STLXPX:
1129*0a6a1f1dSLionel Sambuc   case AArch64::STXPX:
1130*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
1131*0a6a1f1dSLionel Sambuc   // FALLTHROUGH
1132*0a6a1f1dSLionel Sambuc   case AArch64::LDAXPX:
1133*0a6a1f1dSLionel Sambuc   case AArch64::LDXPX:
1134*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1135*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt2, Addr, Decoder);
1136*0a6a1f1dSLionel Sambuc     break;
1137*0a6a1f1dSLionel Sambuc   }
1138*0a6a1f1dSLionel Sambuc 
1139*0a6a1f1dSLionel Sambuc   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1140*0a6a1f1dSLionel Sambuc 
1141f4a2713aSLionel Sambuc   // You shouldn't load to the same register twice in an instruction...
1142*0a6a1f1dSLionel Sambuc   if ((Opcode == AArch64::LDAXPW || Opcode == AArch64::LDXPW ||
1143*0a6a1f1dSLionel Sambuc        Opcode == AArch64::LDAXPX || Opcode == AArch64::LDXPX) &&
1144*0a6a1f1dSLionel Sambuc       Rt == Rt2)
1145*0a6a1f1dSLionel Sambuc     return SoftFail;
1146*0a6a1f1dSLionel Sambuc 
1147*0a6a1f1dSLionel Sambuc   return Success;
1148*0a6a1f1dSLionel Sambuc }
1149*0a6a1f1dSLionel Sambuc 
DecodePairLdStInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1150*0a6a1f1dSLionel Sambuc static DecodeStatus DecodePairLdStInstruction(llvm::MCInst &Inst, uint32_t insn,
1151*0a6a1f1dSLionel Sambuc                                               uint64_t Addr,
1152*0a6a1f1dSLionel Sambuc                                               const void *Decoder) {
1153*0a6a1f1dSLionel Sambuc   unsigned Rt = fieldFromInstruction(insn, 0, 5);
1154*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1155*0a6a1f1dSLionel Sambuc   unsigned Rt2 = fieldFromInstruction(insn, 10, 5);
1156*0a6a1f1dSLionel Sambuc   int64_t offset = fieldFromInstruction(insn, 15, 7);
1157*0a6a1f1dSLionel Sambuc   bool IsLoad = fieldFromInstruction(insn, 22, 1);
1158*0a6a1f1dSLionel Sambuc 
1159*0a6a1f1dSLionel Sambuc   // offset is a 7-bit signed immediate, so sign extend it to
1160*0a6a1f1dSLionel Sambuc   // fill the unsigned.
1161*0a6a1f1dSLionel Sambuc   if (offset & (1 << (7 - 1)))
1162*0a6a1f1dSLionel Sambuc     offset |= ~((1LL << 7) - 1);
1163*0a6a1f1dSLionel Sambuc 
1164*0a6a1f1dSLionel Sambuc   unsigned Opcode = Inst.getOpcode();
1165*0a6a1f1dSLionel Sambuc   bool NeedsDisjointWritebackTransfer = false;
1166*0a6a1f1dSLionel Sambuc 
1167*0a6a1f1dSLionel Sambuc   // First operand is always writeback of base register.
1168*0a6a1f1dSLionel Sambuc   switch (Opcode) {
1169*0a6a1f1dSLionel Sambuc   default:
1170*0a6a1f1dSLionel Sambuc     break;
1171*0a6a1f1dSLionel Sambuc   case AArch64::LDPXpost:
1172*0a6a1f1dSLionel Sambuc   case AArch64::STPXpost:
1173*0a6a1f1dSLionel Sambuc   case AArch64::LDPSWpost:
1174*0a6a1f1dSLionel Sambuc   case AArch64::LDPXpre:
1175*0a6a1f1dSLionel Sambuc   case AArch64::STPXpre:
1176*0a6a1f1dSLionel Sambuc   case AArch64::LDPSWpre:
1177*0a6a1f1dSLionel Sambuc   case AArch64::LDPWpost:
1178*0a6a1f1dSLionel Sambuc   case AArch64::STPWpost:
1179*0a6a1f1dSLionel Sambuc   case AArch64::LDPWpre:
1180*0a6a1f1dSLionel Sambuc   case AArch64::STPWpre:
1181*0a6a1f1dSLionel Sambuc   case AArch64::LDPQpost:
1182*0a6a1f1dSLionel Sambuc   case AArch64::STPQpost:
1183*0a6a1f1dSLionel Sambuc   case AArch64::LDPQpre:
1184*0a6a1f1dSLionel Sambuc   case AArch64::STPQpre:
1185*0a6a1f1dSLionel Sambuc   case AArch64::LDPDpost:
1186*0a6a1f1dSLionel Sambuc   case AArch64::STPDpost:
1187*0a6a1f1dSLionel Sambuc   case AArch64::LDPDpre:
1188*0a6a1f1dSLionel Sambuc   case AArch64::STPDpre:
1189*0a6a1f1dSLionel Sambuc   case AArch64::LDPSpost:
1190*0a6a1f1dSLionel Sambuc   case AArch64::STPSpost:
1191*0a6a1f1dSLionel Sambuc   case AArch64::LDPSpre:
1192*0a6a1f1dSLionel Sambuc   case AArch64::STPSpre:
1193*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1194*0a6a1f1dSLionel Sambuc     break;
1195*0a6a1f1dSLionel Sambuc   }
1196*0a6a1f1dSLionel Sambuc 
1197*0a6a1f1dSLionel Sambuc   switch (Opcode) {
1198*0a6a1f1dSLionel Sambuc   default:
1199*0a6a1f1dSLionel Sambuc     return Fail;
1200*0a6a1f1dSLionel Sambuc   case AArch64::LDPXpost:
1201*0a6a1f1dSLionel Sambuc   case AArch64::STPXpost:
1202*0a6a1f1dSLionel Sambuc   case AArch64::LDPSWpost:
1203*0a6a1f1dSLionel Sambuc   case AArch64::LDPXpre:
1204*0a6a1f1dSLionel Sambuc   case AArch64::STPXpre:
1205*0a6a1f1dSLionel Sambuc   case AArch64::LDPSWpre:
1206*0a6a1f1dSLionel Sambuc     NeedsDisjointWritebackTransfer = true;
1207*0a6a1f1dSLionel Sambuc     // Fallthrough
1208*0a6a1f1dSLionel Sambuc   case AArch64::LDNPXi:
1209*0a6a1f1dSLionel Sambuc   case AArch64::STNPXi:
1210*0a6a1f1dSLionel Sambuc   case AArch64::LDPXi:
1211*0a6a1f1dSLionel Sambuc   case AArch64::STPXi:
1212*0a6a1f1dSLionel Sambuc   case AArch64::LDPSWi:
1213*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1214*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt2, Addr, Decoder);
1215*0a6a1f1dSLionel Sambuc     break;
1216*0a6a1f1dSLionel Sambuc   case AArch64::LDPWpost:
1217*0a6a1f1dSLionel Sambuc   case AArch64::STPWpost:
1218*0a6a1f1dSLionel Sambuc   case AArch64::LDPWpre:
1219*0a6a1f1dSLionel Sambuc   case AArch64::STPWpre:
1220*0a6a1f1dSLionel Sambuc     NeedsDisjointWritebackTransfer = true;
1221*0a6a1f1dSLionel Sambuc     // Fallthrough
1222*0a6a1f1dSLionel Sambuc   case AArch64::LDNPWi:
1223*0a6a1f1dSLionel Sambuc   case AArch64::STNPWi:
1224*0a6a1f1dSLionel Sambuc   case AArch64::LDPWi:
1225*0a6a1f1dSLionel Sambuc   case AArch64::STPWi:
1226*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1227*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt2, Addr, Decoder);
1228*0a6a1f1dSLionel Sambuc     break;
1229*0a6a1f1dSLionel Sambuc   case AArch64::LDNPQi:
1230*0a6a1f1dSLionel Sambuc   case AArch64::STNPQi:
1231*0a6a1f1dSLionel Sambuc   case AArch64::LDPQpost:
1232*0a6a1f1dSLionel Sambuc   case AArch64::STPQpost:
1233*0a6a1f1dSLionel Sambuc   case AArch64::LDPQi:
1234*0a6a1f1dSLionel Sambuc   case AArch64::STPQi:
1235*0a6a1f1dSLionel Sambuc   case AArch64::LDPQpre:
1236*0a6a1f1dSLionel Sambuc   case AArch64::STPQpre:
1237*0a6a1f1dSLionel Sambuc     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
1238*0a6a1f1dSLionel Sambuc     DecodeFPR128RegisterClass(Inst, Rt2, Addr, Decoder);
1239*0a6a1f1dSLionel Sambuc     break;
1240*0a6a1f1dSLionel Sambuc   case AArch64::LDNPDi:
1241*0a6a1f1dSLionel Sambuc   case AArch64::STNPDi:
1242*0a6a1f1dSLionel Sambuc   case AArch64::LDPDpost:
1243*0a6a1f1dSLionel Sambuc   case AArch64::STPDpost:
1244*0a6a1f1dSLionel Sambuc   case AArch64::LDPDi:
1245*0a6a1f1dSLionel Sambuc   case AArch64::STPDi:
1246*0a6a1f1dSLionel Sambuc   case AArch64::LDPDpre:
1247*0a6a1f1dSLionel Sambuc   case AArch64::STPDpre:
1248*0a6a1f1dSLionel Sambuc     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
1249*0a6a1f1dSLionel Sambuc     DecodeFPR64RegisterClass(Inst, Rt2, Addr, Decoder);
1250*0a6a1f1dSLionel Sambuc     break;
1251*0a6a1f1dSLionel Sambuc   case AArch64::LDNPSi:
1252*0a6a1f1dSLionel Sambuc   case AArch64::STNPSi:
1253*0a6a1f1dSLionel Sambuc   case AArch64::LDPSpost:
1254*0a6a1f1dSLionel Sambuc   case AArch64::STPSpost:
1255*0a6a1f1dSLionel Sambuc   case AArch64::LDPSi:
1256*0a6a1f1dSLionel Sambuc   case AArch64::STPSi:
1257*0a6a1f1dSLionel Sambuc   case AArch64::LDPSpre:
1258*0a6a1f1dSLionel Sambuc   case AArch64::STPSpre:
1259*0a6a1f1dSLionel Sambuc     DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder);
1260*0a6a1f1dSLionel Sambuc     DecodeFPR32RegisterClass(Inst, Rt2, Addr, Decoder);
1261*0a6a1f1dSLionel Sambuc     break;
1262*0a6a1f1dSLionel Sambuc   }
1263*0a6a1f1dSLionel Sambuc 
1264*0a6a1f1dSLionel Sambuc   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1265*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(offset));
1266*0a6a1f1dSLionel Sambuc 
1267*0a6a1f1dSLionel Sambuc   // You shouldn't load to the same register twice in an instruction...
1268*0a6a1f1dSLionel Sambuc   if (IsLoad && Rt == Rt2)
1269*0a6a1f1dSLionel Sambuc     return SoftFail;
1270f4a2713aSLionel Sambuc 
1271f4a2713aSLionel Sambuc   // ... or do any operation that writes-back to a transfer register. But note
1272f4a2713aSLionel Sambuc   // that "stp xzr, xzr, [sp], #4" is fine because xzr and sp are different.
1273*0a6a1f1dSLionel Sambuc   if (NeedsDisjointWritebackTransfer && Rn != 31 && (Rt == Rn || Rt2 == Rn))
1274*0a6a1f1dSLionel Sambuc     return SoftFail;
1275f4a2713aSLionel Sambuc 
1276*0a6a1f1dSLionel Sambuc   return Success;
1277f4a2713aSLionel Sambuc }
1278f4a2713aSLionel Sambuc 
DecodeAddSubERegInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1279*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeAddSubERegInstruction(llvm::MCInst &Inst,
1280*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Addr,
1281f4a2713aSLionel Sambuc                                                 const void *Decoder) {
1282*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1283*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1284*0a6a1f1dSLionel Sambuc   unsigned Rm = fieldFromInstruction(insn, 16, 5);
1285*0a6a1f1dSLionel Sambuc   unsigned extend = fieldFromInstruction(insn, 10, 6);
1286f4a2713aSLionel Sambuc 
1287*0a6a1f1dSLionel Sambuc   unsigned shift = extend & 0x7;
1288*0a6a1f1dSLionel Sambuc   if (shift > 4)
1289*0a6a1f1dSLionel Sambuc     return Fail;
1290f4a2713aSLionel Sambuc 
1291*0a6a1f1dSLionel Sambuc   switch (Inst.getOpcode()) {
1292f4a2713aSLionel Sambuc   default:
1293*0a6a1f1dSLionel Sambuc     return Fail;
1294*0a6a1f1dSLionel Sambuc   case AArch64::ADDWrx:
1295*0a6a1f1dSLionel Sambuc   case AArch64::SUBWrx:
1296*0a6a1f1dSLionel Sambuc     DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder);
1297*0a6a1f1dSLionel Sambuc     DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder);
1298*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1299f4a2713aSLionel Sambuc     break;
1300*0a6a1f1dSLionel Sambuc   case AArch64::ADDSWrx:
1301*0a6a1f1dSLionel Sambuc   case AArch64::SUBSWrx:
1302*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
1303*0a6a1f1dSLionel Sambuc     DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder);
1304*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1305f4a2713aSLionel Sambuc     break;
1306*0a6a1f1dSLionel Sambuc   case AArch64::ADDXrx:
1307*0a6a1f1dSLionel Sambuc   case AArch64::SUBXrx:
1308*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1309*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1310*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1311f4a2713aSLionel Sambuc     break;
1312*0a6a1f1dSLionel Sambuc   case AArch64::ADDSXrx:
1313*0a6a1f1dSLionel Sambuc   case AArch64::SUBSXrx:
1314*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1315*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1316*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1317*0a6a1f1dSLionel Sambuc     break;
1318*0a6a1f1dSLionel Sambuc   case AArch64::ADDXrx64:
1319*0a6a1f1dSLionel Sambuc   case AArch64::SUBXrx64:
1320*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1321*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1322*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
1323*0a6a1f1dSLionel Sambuc     break;
1324*0a6a1f1dSLionel Sambuc   case AArch64::SUBSXrx64:
1325*0a6a1f1dSLionel Sambuc   case AArch64::ADDSXrx64:
1326*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1327*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1328*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
1329f4a2713aSLionel Sambuc     break;
1330f4a2713aSLionel Sambuc   }
1331*0a6a1f1dSLionel Sambuc 
1332*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(extend));
1333*0a6a1f1dSLionel Sambuc   return Success;
1334f4a2713aSLionel Sambuc }
1335f4a2713aSLionel Sambuc 
DecodeLogicalImmInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1336*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeLogicalImmInstruction(llvm::MCInst &Inst,
1337*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Addr,
1338*0a6a1f1dSLionel Sambuc                                                 const void *Decoder) {
1339*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1340*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1341*0a6a1f1dSLionel Sambuc   unsigned Datasize = fieldFromInstruction(insn, 31, 1);
1342*0a6a1f1dSLionel Sambuc   unsigned imm;
1343f4a2713aSLionel Sambuc 
1344*0a6a1f1dSLionel Sambuc   if (Datasize) {
1345*0a6a1f1dSLionel Sambuc     if (Inst.getOpcode() == AArch64::ANDSXri)
1346*0a6a1f1dSLionel Sambuc       DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1347f4a2713aSLionel Sambuc     else
1348*0a6a1f1dSLionel Sambuc       DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1349*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder);
1350*0a6a1f1dSLionel Sambuc     imm = fieldFromInstruction(insn, 10, 13);
1351*0a6a1f1dSLionel Sambuc     if (!AArch64_AM::isValidDecodeLogicalImmediate(imm, 64))
1352*0a6a1f1dSLionel Sambuc       return Fail;
1353*0a6a1f1dSLionel Sambuc   } else {
1354*0a6a1f1dSLionel Sambuc     if (Inst.getOpcode() == AArch64::ANDSWri)
1355*0a6a1f1dSLionel Sambuc       DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
1356*0a6a1f1dSLionel Sambuc     else
1357*0a6a1f1dSLionel Sambuc       DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder);
1358*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rn, Addr, Decoder);
1359*0a6a1f1dSLionel Sambuc     imm = fieldFromInstruction(insn, 10, 12);
1360*0a6a1f1dSLionel Sambuc     if (!AArch64_AM::isValidDecodeLogicalImmediate(imm, 32))
1361*0a6a1f1dSLionel Sambuc       return Fail;
1362*0a6a1f1dSLionel Sambuc   }
1363*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(imm));
1364*0a6a1f1dSLionel Sambuc   return Success;
1365f4a2713aSLionel Sambuc }
1366f4a2713aSLionel Sambuc 
DecodeModImmInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1367*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeModImmInstruction(llvm::MCInst &Inst, uint32_t insn,
1368*0a6a1f1dSLionel Sambuc                                             uint64_t Addr,
1369f4a2713aSLionel Sambuc                                             const void *Decoder) {
1370*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1371*0a6a1f1dSLionel Sambuc   unsigned cmode = fieldFromInstruction(insn, 12, 4);
1372*0a6a1f1dSLionel Sambuc   unsigned imm = fieldFromInstruction(insn, 16, 3) << 5;
1373*0a6a1f1dSLionel Sambuc   imm |= fieldFromInstruction(insn, 5, 5);
1374f4a2713aSLionel Sambuc 
1375*0a6a1f1dSLionel Sambuc   if (Inst.getOpcode() == AArch64::MOVID)
1376*0a6a1f1dSLionel Sambuc     DecodeFPR64RegisterClass(Inst, Rd, Addr, Decoder);
1377*0a6a1f1dSLionel Sambuc   else
1378*0a6a1f1dSLionel Sambuc     DecodeVectorRegisterClass(Inst, Rd, Addr, Decoder);
1379*0a6a1f1dSLionel Sambuc 
1380*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(imm));
1381*0a6a1f1dSLionel Sambuc 
1382*0a6a1f1dSLionel Sambuc   switch (Inst.getOpcode()) {
1383f4a2713aSLionel Sambuc   default:
1384f4a2713aSLionel Sambuc     break;
1385*0a6a1f1dSLionel Sambuc   case AArch64::MOVIv4i16:
1386*0a6a1f1dSLionel Sambuc   case AArch64::MOVIv8i16:
1387*0a6a1f1dSLionel Sambuc   case AArch64::MVNIv4i16:
1388*0a6a1f1dSLionel Sambuc   case AArch64::MVNIv8i16:
1389*0a6a1f1dSLionel Sambuc   case AArch64::MOVIv2i32:
1390*0a6a1f1dSLionel Sambuc   case AArch64::MOVIv4i32:
1391*0a6a1f1dSLionel Sambuc   case AArch64::MVNIv2i32:
1392*0a6a1f1dSLionel Sambuc   case AArch64::MVNIv4i32:
1393*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm((cmode & 6) << 2));
1394f4a2713aSLionel Sambuc     break;
1395*0a6a1f1dSLionel Sambuc   case AArch64::MOVIv2s_msl:
1396*0a6a1f1dSLionel Sambuc   case AArch64::MOVIv4s_msl:
1397*0a6a1f1dSLionel Sambuc   case AArch64::MVNIv2s_msl:
1398*0a6a1f1dSLionel Sambuc   case AArch64::MVNIv4s_msl:
1399*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(cmode & 1 ? 0x110 : 0x108));
1400f4a2713aSLionel Sambuc     break;
1401f4a2713aSLionel Sambuc   }
1402*0a6a1f1dSLionel Sambuc 
1403*0a6a1f1dSLionel Sambuc   return Success;
1404f4a2713aSLionel Sambuc }
1405f4a2713aSLionel Sambuc 
DecodeModImmTiedInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1406*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeModImmTiedInstruction(llvm::MCInst &Inst,
1407*0a6a1f1dSLionel Sambuc                                                 uint32_t insn, uint64_t Addr,
1408f4a2713aSLionel Sambuc                                                 const void *Decoder) {
1409*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1410*0a6a1f1dSLionel Sambuc   unsigned cmode = fieldFromInstruction(insn, 12, 4);
1411*0a6a1f1dSLionel Sambuc   unsigned imm = fieldFromInstruction(insn, 16, 3) << 5;
1412*0a6a1f1dSLionel Sambuc   imm |= fieldFromInstruction(insn, 5, 5);
1413*0a6a1f1dSLionel Sambuc 
1414*0a6a1f1dSLionel Sambuc   // Tied operands added twice.
1415*0a6a1f1dSLionel Sambuc   DecodeVectorRegisterClass(Inst, Rd, Addr, Decoder);
1416*0a6a1f1dSLionel Sambuc   DecodeVectorRegisterClass(Inst, Rd, Addr, Decoder);
1417*0a6a1f1dSLionel Sambuc 
1418*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(imm));
1419*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm((cmode & 6) << 2));
1420*0a6a1f1dSLionel Sambuc 
1421*0a6a1f1dSLionel Sambuc   return Success;
1422f4a2713aSLionel Sambuc }
1423f4a2713aSLionel Sambuc 
DecodeAdrInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1424*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeAdrInstruction(llvm::MCInst &Inst, uint32_t insn,
1425*0a6a1f1dSLionel Sambuc                                          uint64_t Addr, const void *Decoder) {
1426*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1427*0a6a1f1dSLionel Sambuc   int64_t imm = fieldFromInstruction(insn, 5, 19) << 2;
1428*0a6a1f1dSLionel Sambuc   imm |= fieldFromInstruction(insn, 29, 2);
1429*0a6a1f1dSLionel Sambuc   const AArch64Disassembler *Dis =
1430*0a6a1f1dSLionel Sambuc       static_cast<const AArch64Disassembler *>(Decoder);
1431*0a6a1f1dSLionel Sambuc 
1432*0a6a1f1dSLionel Sambuc   // Sign-extend the 21-bit immediate.
1433*0a6a1f1dSLionel Sambuc   if (imm & (1 << (21 - 1)))
1434*0a6a1f1dSLionel Sambuc     imm |= ~((1LL << 21) - 1);
1435*0a6a1f1dSLionel Sambuc 
1436*0a6a1f1dSLionel Sambuc   DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1437*0a6a1f1dSLionel Sambuc   if (!Dis->tryAddingSymbolicOperand(Inst, imm, Addr, Fail, 0, 4))
1438*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(imm));
1439*0a6a1f1dSLionel Sambuc 
1440*0a6a1f1dSLionel Sambuc   return Success;
1441f4a2713aSLionel Sambuc }
1442f4a2713aSLionel Sambuc 
DecodeBaseAddSubImm(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1443*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeBaseAddSubImm(llvm::MCInst &Inst, uint32_t insn,
1444*0a6a1f1dSLionel Sambuc                                         uint64_t Addr, const void *Decoder) {
1445*0a6a1f1dSLionel Sambuc   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1446*0a6a1f1dSLionel Sambuc   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1447*0a6a1f1dSLionel Sambuc   unsigned Imm = fieldFromInstruction(insn, 10, 14);
1448*0a6a1f1dSLionel Sambuc   unsigned S = fieldFromInstruction(insn, 29, 1);
1449*0a6a1f1dSLionel Sambuc   unsigned Datasize = fieldFromInstruction(insn, 31, 1);
1450*0a6a1f1dSLionel Sambuc 
1451*0a6a1f1dSLionel Sambuc   unsigned ShifterVal = (Imm >> 12) & 3;
1452*0a6a1f1dSLionel Sambuc   unsigned ImmVal = Imm & 0xFFF;
1453*0a6a1f1dSLionel Sambuc   const AArch64Disassembler *Dis =
1454*0a6a1f1dSLionel Sambuc       static_cast<const AArch64Disassembler *>(Decoder);
1455*0a6a1f1dSLionel Sambuc 
1456*0a6a1f1dSLionel Sambuc   if (ShifterVal != 0 && ShifterVal != 1)
1457*0a6a1f1dSLionel Sambuc     return Fail;
1458*0a6a1f1dSLionel Sambuc 
1459*0a6a1f1dSLionel Sambuc   if (Datasize) {
1460*0a6a1f1dSLionel Sambuc     if (Rd == 31 && !S)
1461*0a6a1f1dSLionel Sambuc       DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1462*0a6a1f1dSLionel Sambuc     else
1463*0a6a1f1dSLionel Sambuc       DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1464*0a6a1f1dSLionel Sambuc     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1465*0a6a1f1dSLionel Sambuc   } else {
1466*0a6a1f1dSLionel Sambuc     if (Rd == 31 && !S)
1467*0a6a1f1dSLionel Sambuc       DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder);
1468*0a6a1f1dSLionel Sambuc     else
1469*0a6a1f1dSLionel Sambuc       DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
1470*0a6a1f1dSLionel Sambuc     DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder);
1471f4a2713aSLionel Sambuc   }
1472f4a2713aSLionel Sambuc 
1473*0a6a1f1dSLionel Sambuc   if (!Dis->tryAddingSymbolicOperand(Inst, Imm, Addr, Fail, 0, 4))
1474*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(ImmVal));
1475*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(12 * ShifterVal));
1476*0a6a1f1dSLionel Sambuc   return Success;
1477f4a2713aSLionel Sambuc }
1478f4a2713aSLionel Sambuc 
DecodeUnconditionalBranch(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1479*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeUnconditionalBranch(llvm::MCInst &Inst, uint32_t insn,
1480*0a6a1f1dSLionel Sambuc                                               uint64_t Addr,
1481*0a6a1f1dSLionel Sambuc                                               const void *Decoder) {
1482*0a6a1f1dSLionel Sambuc   int64_t imm = fieldFromInstruction(insn, 0, 26);
1483*0a6a1f1dSLionel Sambuc   const AArch64Disassembler *Dis =
1484*0a6a1f1dSLionel Sambuc       static_cast<const AArch64Disassembler *>(Decoder);
1485*0a6a1f1dSLionel Sambuc 
1486*0a6a1f1dSLionel Sambuc   // Sign-extend the 26-bit immediate.
1487*0a6a1f1dSLionel Sambuc   if (imm & (1 << (26 - 1)))
1488*0a6a1f1dSLionel Sambuc     imm |= ~((1LL << 26) - 1);
1489*0a6a1f1dSLionel Sambuc 
1490*0a6a1f1dSLionel Sambuc   if (!Dis->tryAddingSymbolicOperand(Inst, imm * 4, Addr, true, 0, 4))
1491*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(imm));
1492*0a6a1f1dSLionel Sambuc 
1493*0a6a1f1dSLionel Sambuc   return Success;
1494f4a2713aSLionel Sambuc }
1495f4a2713aSLionel Sambuc 
DecodeSystemPStateInstruction(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1496*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeSystemPStateInstruction(llvm::MCInst &Inst,
1497*0a6a1f1dSLionel Sambuc                                                   uint32_t insn, uint64_t Addr,
1498*0a6a1f1dSLionel Sambuc                                                   const void *Decoder) {
1499*0a6a1f1dSLionel Sambuc   uint64_t op1 = fieldFromInstruction(insn, 16, 3);
1500*0a6a1f1dSLionel Sambuc   uint64_t op2 = fieldFromInstruction(insn, 5, 3);
1501*0a6a1f1dSLionel Sambuc   uint64_t crm = fieldFromInstruction(insn, 8, 4);
1502*0a6a1f1dSLionel Sambuc 
1503*0a6a1f1dSLionel Sambuc   uint64_t pstate_field = (op1 << 3) | op2;
1504*0a6a1f1dSLionel Sambuc 
1505*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(pstate_field));
1506*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(crm));
1507*0a6a1f1dSLionel Sambuc 
1508*0a6a1f1dSLionel Sambuc   bool ValidNamed;
1509*0a6a1f1dSLionel Sambuc   (void)AArch64PState::PStateMapper().toString(pstate_field, ValidNamed);
1510*0a6a1f1dSLionel Sambuc 
1511*0a6a1f1dSLionel Sambuc   return ValidNamed ? Success : Fail;
1512f4a2713aSLionel Sambuc }
1513f4a2713aSLionel Sambuc 
DecodeTestAndBranch(llvm::MCInst & Inst,uint32_t insn,uint64_t Addr,const void * Decoder)1514*0a6a1f1dSLionel Sambuc static DecodeStatus DecodeTestAndBranch(llvm::MCInst &Inst, uint32_t insn,
1515*0a6a1f1dSLionel Sambuc                                         uint64_t Addr, const void *Decoder) {
1516*0a6a1f1dSLionel Sambuc   uint64_t Rt = fieldFromInstruction(insn, 0, 5);
1517*0a6a1f1dSLionel Sambuc   uint64_t bit = fieldFromInstruction(insn, 31, 1) << 5;
1518*0a6a1f1dSLionel Sambuc   bit |= fieldFromInstruction(insn, 19, 5);
1519*0a6a1f1dSLionel Sambuc   int64_t dst = fieldFromInstruction(insn, 5, 14);
1520*0a6a1f1dSLionel Sambuc   const AArch64Disassembler *Dis =
1521*0a6a1f1dSLionel Sambuc       static_cast<const AArch64Disassembler *>(Decoder);
1522f4a2713aSLionel Sambuc 
1523*0a6a1f1dSLionel Sambuc   // Sign-extend 14-bit immediate.
1524*0a6a1f1dSLionel Sambuc   if (dst & (1 << (14 - 1)))
1525*0a6a1f1dSLionel Sambuc     dst |= ~((1LL << 14) - 1);
1526f4a2713aSLionel Sambuc 
1527*0a6a1f1dSLionel Sambuc   if (fieldFromInstruction(insn, 31, 1) == 0)
1528*0a6a1f1dSLionel Sambuc     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1529*0a6a1f1dSLionel Sambuc   else
1530*0a6a1f1dSLionel Sambuc     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1531*0a6a1f1dSLionel Sambuc   Inst.addOperand(MCOperand::CreateImm(bit));
1532*0a6a1f1dSLionel Sambuc   if (!Dis->tryAddingSymbolicOperand(Inst, dst * 4, Addr, true, 0, 4))
1533*0a6a1f1dSLionel Sambuc     Inst.addOperand(MCOperand::CreateImm(dst));
1534f4a2713aSLionel Sambuc 
1535*0a6a1f1dSLionel Sambuc   return Success;
1536f4a2713aSLionel Sambuc }
1537