[cleanup] Lift using directives, DEBUG_TYPE definitions, and even some
[oota-llvm.git] / lib / Target / ARM64 / Disassembler / ARM64Disassembler.cpp
1 //===- ARM64Disassembler.cpp - Disassembler for ARM64 -----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 #define DEBUG_TYPE "arm64-disassembler"
14
15 #include "ARM64Disassembler.h"
16 #include "ARM64ExternalSymbolizer.h"
17 #include "ARM64Subtarget.h"
18 #include "MCTargetDesc/ARM64AddressingModes.h"
19 #include "Utils/ARM64BaseInfo.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCFixedLenDisassembler.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/MemoryObject.h"
24 #include "llvm/Support/TargetRegistry.h"
25 #include "llvm/Support/ErrorHandling.h"
26
27 using namespace llvm;
28
29 // Pull DecodeStatus and its enum values into the global namespace.
30 typedef llvm::MCDisassembler::DecodeStatus DecodeStatus;
31
32 // Forward declare these because the autogenerated code will reference them.
33 // Definitions are further down.
34 static DecodeStatus DecodeFPR128RegisterClass(llvm::MCInst &Inst,
35                                               unsigned RegNo, uint64_t Address,
36                                               const void *Decoder);
37 static DecodeStatus DecodeFPR128_loRegisterClass(llvm::MCInst &Inst,
38                                                  unsigned RegNo,
39                                                  uint64_t Address,
40                                                  const void *Decoder);
41 static DecodeStatus DecodeFPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
42                                              uint64_t Address,
43                                              const void *Decoder);
44 static DecodeStatus DecodeFPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
45                                              uint64_t Address,
46                                              const void *Decoder);
47 static DecodeStatus DecodeFPR16RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
48                                              uint64_t Address,
49                                              const void *Decoder);
50 static DecodeStatus DecodeFPR8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
51                                             uint64_t Address,
52                                             const void *Decoder);
53 static DecodeStatus DecodeGPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
54                                              uint64_t Address,
55                                              const void *Decoder);
56 static DecodeStatus DecodeGPR64spRegisterClass(llvm::MCInst &Inst,
57                                                unsigned RegNo, uint64_t Address,
58                                                const void *Decoder);
59 static DecodeStatus DecodeGPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
60                                              uint64_t Address,
61                                              const void *Decoder);
62 static DecodeStatus DecodeGPR32spRegisterClass(llvm::MCInst &Inst,
63                                                unsigned RegNo, uint64_t Address,
64                                                const void *Decoder);
65 static DecodeStatus DecodeQQRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
66                                           uint64_t Address,
67                                           const void *Decoder);
68 static DecodeStatus DecodeQQQRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
69                                            uint64_t Address,
70                                            const void *Decoder);
71 static DecodeStatus DecodeQQQQRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
72                                             uint64_t Address,
73                                             const void *Decoder);
74 static DecodeStatus DecodeDDRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
75                                           uint64_t Address,
76                                           const void *Decoder);
77 static DecodeStatus DecodeDDDRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
78                                            uint64_t Address,
79                                            const void *Decoder);
80 static DecodeStatus DecodeDDDDRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
81                                             uint64_t Address,
82                                             const void *Decoder);
83
84 static DecodeStatus DecodeFixedPointScaleImm32(llvm::MCInst &Inst, unsigned Imm,
85                                                uint64_t Address,
86                                                const void *Decoder);
87 static DecodeStatus DecodeFixedPointScaleImm64(llvm::MCInst &Inst, unsigned Imm,
88                                                uint64_t Address,
89                                                const void *Decoder);
90 static DecodeStatus DecodeCondBranchTarget(llvm::MCInst &Inst, unsigned Imm,
91                                            uint64_t Address,
92                                            const void *Decoder);
93 static DecodeStatus DecodeMRSSystemRegister(llvm::MCInst &Inst, unsigned Imm,
94                                             uint64_t Address, const void *Decoder);
95 static DecodeStatus DecodeMSRSystemRegister(llvm::MCInst &Inst, unsigned Imm,
96                                             uint64_t Address, const void *Decoder);
97 static DecodeStatus DecodeThreeAddrSRegInstruction(llvm::MCInst &Inst,
98                                                    uint32_t insn,
99                                                    uint64_t Address,
100                                                    const void *Decoder);
101 static DecodeStatus DecodeMoveImmInstruction(llvm::MCInst &Inst, uint32_t insn,
102                                              uint64_t Address,
103                                              const void *Decoder);
104 static DecodeStatus DecodeUnsignedLdStInstruction(llvm::MCInst &Inst,
105                                                   uint32_t insn,
106                                                   uint64_t Address,
107                                                   const void *Decoder);
108 static DecodeStatus DecodeSignedLdStInstruction(llvm::MCInst &Inst,
109                                                 uint32_t insn, uint64_t Address,
110                                                 const void *Decoder);
111 static DecodeStatus DecodeExclusiveLdStInstruction(llvm::MCInst &Inst,
112                                                    uint32_t insn,
113                                                    uint64_t Address,
114                                                    const void *Decoder);
115 static DecodeStatus DecodePairLdStInstruction(llvm::MCInst &Inst, uint32_t insn,
116                                               uint64_t Address,
117                                               const void *Decoder);
118 static DecodeStatus DecodeRegOffsetLdStInstruction(llvm::MCInst &Inst,
119                                                    uint32_t insn,
120                                                    uint64_t Address,
121                                                    const void *Decoder);
122 static DecodeStatus DecodeAddSubERegInstruction(llvm::MCInst &Inst,
123                                                 uint32_t insn, uint64_t Address,
124                                                 const void *Decoder);
125 static DecodeStatus DecodeLogicalImmInstruction(llvm::MCInst &Inst,
126                                                 uint32_t insn, uint64_t Address,
127                                                 const void *Decoder);
128 static DecodeStatus DecodeModImmInstruction(llvm::MCInst &Inst, uint32_t insn,
129                                             uint64_t Address,
130                                             const void *Decoder);
131 static DecodeStatus DecodeModImmTiedInstruction(llvm::MCInst &Inst,
132                                                 uint32_t insn, uint64_t Address,
133                                                 const void *Decoder);
134 static DecodeStatus DecodeAdrInstruction(llvm::MCInst &Inst, uint32_t insn,
135                                          uint64_t Address, const void *Decoder);
136 static DecodeStatus DecodeBaseAddSubImm(llvm::MCInst &Inst, uint32_t insn,
137                                         uint64_t Address, const void *Decoder);
138 static DecodeStatus DecodeUnconditionalBranch(llvm::MCInst &Inst, uint32_t insn,
139                                               uint64_t Address,
140                                               const void *Decoder);
141 static DecodeStatus DecodeSystemCPSRInstruction(llvm::MCInst &Inst,
142                                                 uint32_t insn, uint64_t Address,
143                                                 const void *Decoder);
144 static DecodeStatus DecodeTestAndBranch(llvm::MCInst &Inst, uint32_t insn,
145                                         uint64_t Address, const void *Decoder);
146 static DecodeStatus DecodeSIMDLdStPost(llvm::MCInst &Inst, uint32_t insn,
147                                        uint64_t Addr, const void *Decoder);
148 static DecodeStatus DecodeSIMDLdStSingle(llvm::MCInst &Inst, uint32_t insn,
149                                          uint64_t Addr, const void *Decoder);
150 static DecodeStatus DecodeSIMDLdStSingleTied(llvm::MCInst &Inst, uint32_t insn,
151                                              uint64_t Addr,
152                                              const void *Decoder);
153
154 static DecodeStatus DecodeVecShiftR64Imm(llvm::MCInst &Inst, unsigned Imm,
155                                          uint64_t Addr, const void *Decoder);
156 static DecodeStatus DecodeVecShiftR64ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
157                                                uint64_t Addr,
158                                                const void *Decoder);
159 static DecodeStatus DecodeVecShiftR32Imm(llvm::MCInst &Inst, unsigned Imm,
160                                          uint64_t Addr, const void *Decoder);
161 static DecodeStatus DecodeVecShiftR32ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
162                                                uint64_t Addr,
163                                                const void *Decoder);
164 static DecodeStatus DecodeVecShiftR16Imm(llvm::MCInst &Inst, unsigned Imm,
165                                          uint64_t Addr, const void *Decoder);
166 static DecodeStatus DecodeVecShiftR16ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
167                                                uint64_t Addr,
168                                                const void *Decoder);
169 static DecodeStatus DecodeVecShiftR8Imm(llvm::MCInst &Inst, unsigned Imm,
170                                         uint64_t Addr, const void *Decoder);
171 static DecodeStatus DecodeVecShiftL64Imm(llvm::MCInst &Inst, unsigned Imm,
172                                          uint64_t Addr, const void *Decoder);
173 static DecodeStatus DecodeVecShiftL32Imm(llvm::MCInst &Inst, unsigned Imm,
174                                          uint64_t Addr, const void *Decoder);
175 static DecodeStatus DecodeVecShiftL16Imm(llvm::MCInst &Inst, unsigned Imm,
176                                          uint64_t Addr, const void *Decoder);
177 static DecodeStatus DecodeVecShiftL8Imm(llvm::MCInst &Inst, unsigned Imm,
178                                         uint64_t Addr, const void *Decoder);
179
180 #include "ARM64GenDisassemblerTables.inc"
181 #include "ARM64GenInstrInfo.inc"
182
183 #define Success llvm::MCDisassembler::Success
184 #define Fail llvm::MCDisassembler::Fail
185
186 static MCDisassembler *createARM64Disassembler(const Target &T,
187                                                const MCSubtargetInfo &STI,
188                                                MCContext &Ctx) {
189   return new ARM64Disassembler(STI, Ctx);
190 }
191
192 DecodeStatus ARM64Disassembler::getInstruction(MCInst &MI, uint64_t &Size,
193                                                const MemoryObject &Region,
194                                                uint64_t Address,
195                                                raw_ostream &os,
196                                                raw_ostream &cs) const {
197   CommentStream = &cs;
198
199   uint8_t bytes[4];
200
201   Size = 0;
202   // We want to read exactly 4 bytes of data.
203   if (Region.readBytes(Address, 4, (uint8_t *)bytes) == -1)
204     return Fail;
205   Size = 4;
206
207   // Encoded as a small-endian 32-bit word in the stream.
208   uint32_t insn =
209       (bytes[3] << 24) | (bytes[2] << 16) | (bytes[1] << 8) | (bytes[0] << 0);
210
211   // Calling the auto-generated decoder function.
212   DecodeStatus result =
213       decodeInstruction(DecoderTable32, MI, insn, Address, this, STI);
214   if (!result)
215     return Fail;
216
217   return Success;
218 }
219
220 static MCSymbolizer *
221 createARM64ExternalSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
222                               LLVMSymbolLookupCallback SymbolLookUp,
223                               void *DisInfo, MCContext *Ctx,
224                               MCRelocationInfo *RelInfo) {
225   return new llvm::ARM64ExternalSymbolizer(
226                                      *Ctx,
227                                      std::unique_ptr<MCRelocationInfo>(RelInfo),
228                                      GetOpInfo, SymbolLookUp, DisInfo);
229 }
230
231 extern "C" void LLVMInitializeARM64Disassembler() {
232   TargetRegistry::RegisterMCDisassembler(TheARM64Target,
233                                          createARM64Disassembler);
234   TargetRegistry::RegisterMCSymbolizer(TheARM64Target,
235                                        createARM64ExternalSymbolizer);
236 }
237
238 static const unsigned FPR128DecoderTable[] = {
239   ARM64::Q0,  ARM64::Q1,  ARM64::Q2,  ARM64::Q3,  ARM64::Q4,  ARM64::Q5,
240   ARM64::Q6,  ARM64::Q7,  ARM64::Q8,  ARM64::Q9,  ARM64::Q10, ARM64::Q11,
241   ARM64::Q12, ARM64::Q13, ARM64::Q14, ARM64::Q15, ARM64::Q16, ARM64::Q17,
242   ARM64::Q18, ARM64::Q19, ARM64::Q20, ARM64::Q21, ARM64::Q22, ARM64::Q23,
243   ARM64::Q24, ARM64::Q25, ARM64::Q26, ARM64::Q27, ARM64::Q28, ARM64::Q29,
244   ARM64::Q30, ARM64::Q31
245 };
246
247 static DecodeStatus DecodeFPR128RegisterClass(MCInst &Inst, unsigned RegNo,
248                                               uint64_t Addr,
249                                               const void *Decoder) {
250   if (RegNo > 31)
251     return Fail;
252
253   unsigned Register = FPR128DecoderTable[RegNo];
254   Inst.addOperand(MCOperand::CreateReg(Register));
255   return Success;
256 }
257
258 static DecodeStatus DecodeFPR128_loRegisterClass(MCInst &Inst, unsigned RegNo,
259                                                  uint64_t Addr,
260                                                  const void *Decoder) {
261   if (RegNo > 15)
262     return Fail;
263   return DecodeFPR128RegisterClass(Inst, RegNo, Addr, Decoder);
264 }
265
266 static const unsigned FPR64DecoderTable[] = {
267   ARM64::D0,  ARM64::D1,  ARM64::D2,  ARM64::D3,  ARM64::D4,  ARM64::D5,
268   ARM64::D6,  ARM64::D7,  ARM64::D8,  ARM64::D9,  ARM64::D10, ARM64::D11,
269   ARM64::D12, ARM64::D13, ARM64::D14, ARM64::D15, ARM64::D16, ARM64::D17,
270   ARM64::D18, ARM64::D19, ARM64::D20, ARM64::D21, ARM64::D22, ARM64::D23,
271   ARM64::D24, ARM64::D25, ARM64::D26, ARM64::D27, ARM64::D28, ARM64::D29,
272   ARM64::D30, ARM64::D31
273 };
274
275 static DecodeStatus DecodeFPR64RegisterClass(MCInst &Inst, unsigned RegNo,
276                                              uint64_t Addr,
277                                              const void *Decoder) {
278   if (RegNo > 31)
279     return Fail;
280
281   unsigned Register = FPR64DecoderTable[RegNo];
282   Inst.addOperand(MCOperand::CreateReg(Register));
283   return Success;
284 }
285
286 static const unsigned FPR32DecoderTable[] = {
287   ARM64::S0,  ARM64::S1,  ARM64::S2,  ARM64::S3,  ARM64::S4,  ARM64::S5,
288   ARM64::S6,  ARM64::S7,  ARM64::S8,  ARM64::S9,  ARM64::S10, ARM64::S11,
289   ARM64::S12, ARM64::S13, ARM64::S14, ARM64::S15, ARM64::S16, ARM64::S17,
290   ARM64::S18, ARM64::S19, ARM64::S20, ARM64::S21, ARM64::S22, ARM64::S23,
291   ARM64::S24, ARM64::S25, ARM64::S26, ARM64::S27, ARM64::S28, ARM64::S29,
292   ARM64::S30, ARM64::S31
293 };
294
295 static DecodeStatus DecodeFPR32RegisterClass(MCInst &Inst, unsigned RegNo,
296                                              uint64_t Addr,
297                                              const void *Decoder) {
298   if (RegNo > 31)
299     return Fail;
300
301   unsigned Register = FPR32DecoderTable[RegNo];
302   Inst.addOperand(MCOperand::CreateReg(Register));
303   return Success;
304 }
305
306 static const unsigned FPR16DecoderTable[] = {
307   ARM64::H0,  ARM64::H1,  ARM64::H2,  ARM64::H3,  ARM64::H4,  ARM64::H5,
308   ARM64::H6,  ARM64::H7,  ARM64::H8,  ARM64::H9,  ARM64::H10, ARM64::H11,
309   ARM64::H12, ARM64::H13, ARM64::H14, ARM64::H15, ARM64::H16, ARM64::H17,
310   ARM64::H18, ARM64::H19, ARM64::H20, ARM64::H21, ARM64::H22, ARM64::H23,
311   ARM64::H24, ARM64::H25, ARM64::H26, ARM64::H27, ARM64::H28, ARM64::H29,
312   ARM64::H30, ARM64::H31
313 };
314
315 static DecodeStatus DecodeFPR16RegisterClass(MCInst &Inst, unsigned RegNo,
316                                              uint64_t Addr,
317                                              const void *Decoder) {
318   if (RegNo > 31)
319     return Fail;
320
321   unsigned Register = FPR16DecoderTable[RegNo];
322   Inst.addOperand(MCOperand::CreateReg(Register));
323   return Success;
324 }
325
326 static const unsigned FPR8DecoderTable[] = {
327   ARM64::B0,  ARM64::B1,  ARM64::B2,  ARM64::B3,  ARM64::B4,  ARM64::B5,
328   ARM64::B6,  ARM64::B7,  ARM64::B8,  ARM64::B9,  ARM64::B10, ARM64::B11,
329   ARM64::B12, ARM64::B13, ARM64::B14, ARM64::B15, ARM64::B16, ARM64::B17,
330   ARM64::B18, ARM64::B19, ARM64::B20, ARM64::B21, ARM64::B22, ARM64::B23,
331   ARM64::B24, ARM64::B25, ARM64::B26, ARM64::B27, ARM64::B28, ARM64::B29,
332   ARM64::B30, ARM64::B31
333 };
334
335 static DecodeStatus DecodeFPR8RegisterClass(MCInst &Inst, unsigned RegNo,
336                                             uint64_t Addr,
337                                             const void *Decoder) {
338   if (RegNo > 31)
339     return Fail;
340
341   unsigned Register = FPR8DecoderTable[RegNo];
342   Inst.addOperand(MCOperand::CreateReg(Register));
343   return Success;
344 }
345
346 static const unsigned GPR64DecoderTable[] = {
347   ARM64::X0,  ARM64::X1,  ARM64::X2,  ARM64::X3,  ARM64::X4,  ARM64::X5,
348   ARM64::X6,  ARM64::X7,  ARM64::X8,  ARM64::X9,  ARM64::X10, ARM64::X11,
349   ARM64::X12, ARM64::X13, ARM64::X14, ARM64::X15, ARM64::X16, ARM64::X17,
350   ARM64::X18, ARM64::X19, ARM64::X20, ARM64::X21, ARM64::X22, ARM64::X23,
351   ARM64::X24, ARM64::X25, ARM64::X26, ARM64::X27, ARM64::X28, ARM64::FP,
352   ARM64::LR,  ARM64::XZR
353 };
354
355 static DecodeStatus DecodeGPR64RegisterClass(MCInst &Inst, unsigned RegNo,
356                                              uint64_t Addr,
357                                              const void *Decoder) {
358   if (RegNo > 31)
359     return Fail;
360
361   unsigned Register = GPR64DecoderTable[RegNo];
362   Inst.addOperand(MCOperand::CreateReg(Register));
363   return Success;
364 }
365
366 static DecodeStatus DecodeGPR64spRegisterClass(MCInst &Inst, unsigned RegNo,
367                                                uint64_t Addr,
368                                                const void *Decoder) {
369   if (RegNo > 31)
370     return Fail;
371   unsigned Register = GPR64DecoderTable[RegNo];
372   if (Register == ARM64::XZR)
373     Register = ARM64::SP;
374   Inst.addOperand(MCOperand::CreateReg(Register));
375   return Success;
376 }
377
378 static const unsigned GPR32DecoderTable[] = {
379   ARM64::W0,  ARM64::W1,  ARM64::W2,  ARM64::W3,  ARM64::W4,  ARM64::W5,
380   ARM64::W6,  ARM64::W7,  ARM64::W8,  ARM64::W9,  ARM64::W10, ARM64::W11,
381   ARM64::W12, ARM64::W13, ARM64::W14, ARM64::W15, ARM64::W16, ARM64::W17,
382   ARM64::W18, ARM64::W19, ARM64::W20, ARM64::W21, ARM64::W22, ARM64::W23,
383   ARM64::W24, ARM64::W25, ARM64::W26, ARM64::W27, ARM64::W28, ARM64::W29,
384   ARM64::W30, ARM64::WZR
385 };
386
387 static DecodeStatus DecodeGPR32RegisterClass(MCInst &Inst, unsigned RegNo,
388                                              uint64_t Addr,
389                                              const void *Decoder) {
390   if (RegNo > 31)
391     return Fail;
392
393   unsigned Register = GPR32DecoderTable[RegNo];
394   Inst.addOperand(MCOperand::CreateReg(Register));
395   return Success;
396 }
397
398 static DecodeStatus DecodeGPR32spRegisterClass(MCInst &Inst, unsigned RegNo,
399                                                uint64_t Addr,
400                                                const void *Decoder) {
401   if (RegNo > 31)
402     return Fail;
403
404   unsigned Register = GPR32DecoderTable[RegNo];
405   if (Register == ARM64::WZR)
406     Register = ARM64::WSP;
407   Inst.addOperand(MCOperand::CreateReg(Register));
408   return Success;
409 }
410
411 static const unsigned VectorDecoderTable[] = {
412   ARM64::Q0,  ARM64::Q1,  ARM64::Q2,  ARM64::Q3,  ARM64::Q4,  ARM64::Q5,
413   ARM64::Q6,  ARM64::Q7,  ARM64::Q8,  ARM64::Q9,  ARM64::Q10, ARM64::Q11,
414   ARM64::Q12, ARM64::Q13, ARM64::Q14, ARM64::Q15, ARM64::Q16, ARM64::Q17,
415   ARM64::Q18, ARM64::Q19, ARM64::Q20, ARM64::Q21, ARM64::Q22, ARM64::Q23,
416   ARM64::Q24, ARM64::Q25, ARM64::Q26, ARM64::Q27, ARM64::Q28, ARM64::Q29,
417   ARM64::Q30, ARM64::Q31
418 };
419
420 static DecodeStatus DecodeVectorRegisterClass(MCInst &Inst, unsigned RegNo,
421                                               uint64_t Addr,
422                                               const void *Decoder) {
423   if (RegNo > 31)
424     return Fail;
425
426   unsigned Register = VectorDecoderTable[RegNo];
427   Inst.addOperand(MCOperand::CreateReg(Register));
428   return Success;
429 }
430
431 static const unsigned QQDecoderTable[] = {
432   ARM64::Q0_Q1,   ARM64::Q1_Q2,   ARM64::Q2_Q3,   ARM64::Q3_Q4,
433   ARM64::Q4_Q5,   ARM64::Q5_Q6,   ARM64::Q6_Q7,   ARM64::Q7_Q8,
434   ARM64::Q8_Q9,   ARM64::Q9_Q10,  ARM64::Q10_Q11, ARM64::Q11_Q12,
435   ARM64::Q12_Q13, ARM64::Q13_Q14, ARM64::Q14_Q15, ARM64::Q15_Q16,
436   ARM64::Q16_Q17, ARM64::Q17_Q18, ARM64::Q18_Q19, ARM64::Q19_Q20,
437   ARM64::Q20_Q21, ARM64::Q21_Q22, ARM64::Q22_Q23, ARM64::Q23_Q24,
438   ARM64::Q24_Q25, ARM64::Q25_Q26, ARM64::Q26_Q27, ARM64::Q27_Q28,
439   ARM64::Q28_Q29, ARM64::Q29_Q30, ARM64::Q30_Q31, ARM64::Q31_Q0
440 };
441
442 static DecodeStatus DecodeQQRegisterClass(MCInst &Inst, unsigned RegNo,
443                                           uint64_t Addr, const void *Decoder) {
444   if (RegNo > 31)
445     return Fail;
446   unsigned Register = QQDecoderTable[RegNo];
447   Inst.addOperand(MCOperand::CreateReg(Register));
448   return Success;
449 }
450
451 static const unsigned QQQDecoderTable[] = {
452   ARM64::Q0_Q1_Q2,    ARM64::Q1_Q2_Q3,    ARM64::Q2_Q3_Q4,
453   ARM64::Q3_Q4_Q5,    ARM64::Q4_Q5_Q6,    ARM64::Q5_Q6_Q7,
454   ARM64::Q6_Q7_Q8,    ARM64::Q7_Q8_Q9,    ARM64::Q8_Q9_Q10,
455   ARM64::Q9_Q10_Q11,  ARM64::Q10_Q11_Q12, ARM64::Q11_Q12_Q13,
456   ARM64::Q12_Q13_Q14, ARM64::Q13_Q14_Q15, ARM64::Q14_Q15_Q16,
457   ARM64::Q15_Q16_Q17, ARM64::Q16_Q17_Q18, ARM64::Q17_Q18_Q19,
458   ARM64::Q18_Q19_Q20, ARM64::Q19_Q20_Q21, ARM64::Q20_Q21_Q22,
459   ARM64::Q21_Q22_Q23, ARM64::Q22_Q23_Q24, ARM64::Q23_Q24_Q25,
460   ARM64::Q24_Q25_Q26, ARM64::Q25_Q26_Q27, ARM64::Q26_Q27_Q28,
461   ARM64::Q27_Q28_Q29, ARM64::Q28_Q29_Q30, ARM64::Q29_Q30_Q31,
462   ARM64::Q30_Q31_Q0,  ARM64::Q31_Q0_Q1
463 };
464
465 static DecodeStatus DecodeQQQRegisterClass(MCInst &Inst, unsigned RegNo,
466                                            uint64_t Addr, const void *Decoder) {
467   if (RegNo > 31)
468     return Fail;
469   unsigned Register = QQQDecoderTable[RegNo];
470   Inst.addOperand(MCOperand::CreateReg(Register));
471   return Success;
472 }
473
474 static const unsigned QQQQDecoderTable[] = {
475   ARM64::Q0_Q1_Q2_Q3,     ARM64::Q1_Q2_Q3_Q4,     ARM64::Q2_Q3_Q4_Q5,
476   ARM64::Q3_Q4_Q5_Q6,     ARM64::Q4_Q5_Q6_Q7,     ARM64::Q5_Q6_Q7_Q8,
477   ARM64::Q6_Q7_Q8_Q9,     ARM64::Q7_Q8_Q9_Q10,    ARM64::Q8_Q9_Q10_Q11,
478   ARM64::Q9_Q10_Q11_Q12,  ARM64::Q10_Q11_Q12_Q13, ARM64::Q11_Q12_Q13_Q14,
479   ARM64::Q12_Q13_Q14_Q15, ARM64::Q13_Q14_Q15_Q16, ARM64::Q14_Q15_Q16_Q17,
480   ARM64::Q15_Q16_Q17_Q18, ARM64::Q16_Q17_Q18_Q19, ARM64::Q17_Q18_Q19_Q20,
481   ARM64::Q18_Q19_Q20_Q21, ARM64::Q19_Q20_Q21_Q22, ARM64::Q20_Q21_Q22_Q23,
482   ARM64::Q21_Q22_Q23_Q24, ARM64::Q22_Q23_Q24_Q25, ARM64::Q23_Q24_Q25_Q26,
483   ARM64::Q24_Q25_Q26_Q27, ARM64::Q25_Q26_Q27_Q28, ARM64::Q26_Q27_Q28_Q29,
484   ARM64::Q27_Q28_Q29_Q30, ARM64::Q28_Q29_Q30_Q31, ARM64::Q29_Q30_Q31_Q0,
485   ARM64::Q30_Q31_Q0_Q1,   ARM64::Q31_Q0_Q1_Q2
486 };
487
488 static DecodeStatus DecodeQQQQRegisterClass(MCInst &Inst, unsigned RegNo,
489                                             uint64_t Addr,
490                                             const void *Decoder) {
491   if (RegNo > 31)
492     return Fail;
493   unsigned Register = QQQQDecoderTable[RegNo];
494   Inst.addOperand(MCOperand::CreateReg(Register));
495   return Success;
496 }
497
498 static const unsigned DDDecoderTable[] = {
499   ARM64::D0_D1,   ARM64::D1_D2,   ARM64::D2_D3,   ARM64::D3_D4,
500   ARM64::D4_D5,   ARM64::D5_D6,   ARM64::D6_D7,   ARM64::D7_D8,
501   ARM64::D8_D9,   ARM64::D9_D10,  ARM64::D10_D11, ARM64::D11_D12,
502   ARM64::D12_D13, ARM64::D13_D14, ARM64::D14_D15, ARM64::D15_D16,
503   ARM64::D16_D17, ARM64::D17_D18, ARM64::D18_D19, ARM64::D19_D20,
504   ARM64::D20_D21, ARM64::D21_D22, ARM64::D22_D23, ARM64::D23_D24,
505   ARM64::D24_D25, ARM64::D25_D26, ARM64::D26_D27, ARM64::D27_D28,
506   ARM64::D28_D29, ARM64::D29_D30, ARM64::D30_D31, ARM64::D31_D0
507 };
508
509 static DecodeStatus DecodeDDRegisterClass(MCInst &Inst, unsigned RegNo,
510                                           uint64_t Addr, const void *Decoder) {
511   if (RegNo > 31)
512     return Fail;
513   unsigned Register = DDDecoderTable[RegNo];
514   Inst.addOperand(MCOperand::CreateReg(Register));
515   return Success;
516 }
517
518 static const unsigned DDDDecoderTable[] = {
519   ARM64::D0_D1_D2,    ARM64::D1_D2_D3,    ARM64::D2_D3_D4,
520   ARM64::D3_D4_D5,    ARM64::D4_D5_D6,    ARM64::D5_D6_D7,
521   ARM64::D6_D7_D8,    ARM64::D7_D8_D9,    ARM64::D8_D9_D10,
522   ARM64::D9_D10_D11,  ARM64::D10_D11_D12, ARM64::D11_D12_D13,
523   ARM64::D12_D13_D14, ARM64::D13_D14_D15, ARM64::D14_D15_D16,
524   ARM64::D15_D16_D17, ARM64::D16_D17_D18, ARM64::D17_D18_D19,
525   ARM64::D18_D19_D20, ARM64::D19_D20_D21, ARM64::D20_D21_D22,
526   ARM64::D21_D22_D23, ARM64::D22_D23_D24, ARM64::D23_D24_D25,
527   ARM64::D24_D25_D26, ARM64::D25_D26_D27, ARM64::D26_D27_D28,
528   ARM64::D27_D28_D29, ARM64::D28_D29_D30, ARM64::D29_D30_D31,
529   ARM64::D30_D31_D0,  ARM64::D31_D0_D1
530 };
531
532 static DecodeStatus DecodeDDDRegisterClass(MCInst &Inst, unsigned RegNo,
533                                            uint64_t Addr, const void *Decoder) {
534   if (RegNo > 31)
535     return Fail;
536   unsigned Register = DDDDecoderTable[RegNo];
537   Inst.addOperand(MCOperand::CreateReg(Register));
538   return Success;
539 }
540
541 static const unsigned DDDDDecoderTable[] = {
542   ARM64::D0_D1_D2_D3,     ARM64::D1_D2_D3_D4,     ARM64::D2_D3_D4_D5,
543   ARM64::D3_D4_D5_D6,     ARM64::D4_D5_D6_D7,     ARM64::D5_D6_D7_D8,
544   ARM64::D6_D7_D8_D9,     ARM64::D7_D8_D9_D10,    ARM64::D8_D9_D10_D11,
545   ARM64::D9_D10_D11_D12,  ARM64::D10_D11_D12_D13, ARM64::D11_D12_D13_D14,
546   ARM64::D12_D13_D14_D15, ARM64::D13_D14_D15_D16, ARM64::D14_D15_D16_D17,
547   ARM64::D15_D16_D17_D18, ARM64::D16_D17_D18_D19, ARM64::D17_D18_D19_D20,
548   ARM64::D18_D19_D20_D21, ARM64::D19_D20_D21_D22, ARM64::D20_D21_D22_D23,
549   ARM64::D21_D22_D23_D24, ARM64::D22_D23_D24_D25, ARM64::D23_D24_D25_D26,
550   ARM64::D24_D25_D26_D27, ARM64::D25_D26_D27_D28, ARM64::D26_D27_D28_D29,
551   ARM64::D27_D28_D29_D30, ARM64::D28_D29_D30_D31, ARM64::D29_D30_D31_D0,
552   ARM64::D30_D31_D0_D1,   ARM64::D31_D0_D1_D2
553 };
554
555 static DecodeStatus DecodeDDDDRegisterClass(MCInst &Inst, unsigned RegNo,
556                                             uint64_t Addr,
557                                             const void *Decoder) {
558   if (RegNo > 31)
559     return Fail;
560   unsigned Register = DDDDDecoderTable[RegNo];
561   Inst.addOperand(MCOperand::CreateReg(Register));
562   return Success;
563 }
564
565 static DecodeStatus DecodeFixedPointScaleImm32(llvm::MCInst &Inst, unsigned Imm,
566                                                uint64_t Addr,
567                                                const void *Decoder) {
568   // scale{5} is asserted as 1 in tblgen.
569   Imm |= 0x20;  
570   Inst.addOperand(MCOperand::CreateImm(64 - Imm));
571   return Success;
572 }
573
574 static DecodeStatus DecodeFixedPointScaleImm64(llvm::MCInst &Inst, unsigned Imm,
575                                                uint64_t Addr,
576                                                const void *Decoder) {
577   Inst.addOperand(MCOperand::CreateImm(64 - Imm));
578   return Success;
579 }
580
581 static DecodeStatus DecodeCondBranchTarget(llvm::MCInst &Inst, unsigned Imm,
582                                            uint64_t Addr, const void *Decoder) {
583   int64_t ImmVal = Imm;
584   const ARM64Disassembler *Dis =
585       static_cast<const ARM64Disassembler *>(Decoder);
586
587   // Sign-extend 19-bit immediate.
588   if (ImmVal & (1 << (19 - 1)))
589     ImmVal |= ~((1LL << 19) - 1);
590
591   if (!Dis->tryAddingSymbolicOperand(Inst, ImmVal << 2, Addr,
592                                      Inst.getOpcode() != ARM64::LDRXl, 0, 4))
593     Inst.addOperand(MCOperand::CreateImm(ImmVal));
594   return Success;
595 }
596
597 static DecodeStatus DecodeMRSSystemRegister(llvm::MCInst &Inst, unsigned Imm,
598                                             uint64_t Address,
599                                             const void *Decoder) {
600   Imm |= 0x8000;
601   Inst.addOperand(MCOperand::CreateImm(Imm));
602
603   bool ValidNamed;
604   (void)ARM64SysReg::MRSMapper().toString(Imm, ValidNamed);
605
606   return ValidNamed ? Success : Fail;
607 }
608
609 static DecodeStatus DecodeMSRSystemRegister(llvm::MCInst &Inst, unsigned Imm,
610                                             uint64_t Address,
611                                             const void *Decoder) {
612   Imm |= 0x8000;
613   Inst.addOperand(MCOperand::CreateImm(Imm));
614
615   bool ValidNamed;
616   (void)ARM64SysReg::MSRMapper().toString(Imm, ValidNamed);
617
618   return ValidNamed ? Success : Fail;
619 }
620
621 static DecodeStatus DecodeVecShiftRImm(llvm::MCInst &Inst, unsigned Imm,
622                                        unsigned Add) {
623   Inst.addOperand(MCOperand::CreateImm(Add - Imm));
624   return Success;
625 }
626
627 static DecodeStatus DecodeVecShiftLImm(llvm::MCInst &Inst, unsigned Imm,
628                                        unsigned Add) {
629   Inst.addOperand(MCOperand::CreateImm((Imm + Add) & (Add - 1)));
630   return Success;
631 }
632
633 static DecodeStatus DecodeVecShiftR64Imm(llvm::MCInst &Inst, unsigned Imm,
634                                          uint64_t Addr, const void *Decoder) {
635   return DecodeVecShiftRImm(Inst, Imm, 64);
636 }
637
638 static DecodeStatus DecodeVecShiftR64ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
639                                                uint64_t Addr,
640                                                const void *Decoder) {
641   return DecodeVecShiftRImm(Inst, Imm | 0x20, 64);
642 }
643
644 static DecodeStatus DecodeVecShiftR32Imm(llvm::MCInst &Inst, unsigned Imm,
645                                          uint64_t Addr, const void *Decoder) {
646   return DecodeVecShiftRImm(Inst, Imm, 32);
647 }
648
649 static DecodeStatus DecodeVecShiftR32ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
650                                                uint64_t Addr,
651                                                const void *Decoder) {
652   return DecodeVecShiftRImm(Inst, Imm | 0x10, 32);
653 }
654
655 static DecodeStatus DecodeVecShiftR16Imm(llvm::MCInst &Inst, unsigned Imm,
656                                          uint64_t Addr, const void *Decoder) {
657   return DecodeVecShiftRImm(Inst, Imm, 16);
658 }
659
660 static DecodeStatus DecodeVecShiftR16ImmNarrow(llvm::MCInst &Inst, unsigned Imm,
661                                                uint64_t Addr,
662                                                const void *Decoder) {
663   return DecodeVecShiftRImm(Inst, Imm | 0x8, 16);
664 }
665
666 static DecodeStatus DecodeVecShiftR8Imm(llvm::MCInst &Inst, unsigned Imm,
667                                         uint64_t Addr, const void *Decoder) {
668   return DecodeVecShiftRImm(Inst, Imm, 8);
669 }
670
671 static DecodeStatus DecodeVecShiftL64Imm(llvm::MCInst &Inst, unsigned Imm,
672                                          uint64_t Addr, const void *Decoder) {
673   return DecodeVecShiftLImm(Inst, Imm, 64);
674 }
675
676 static DecodeStatus DecodeVecShiftL32Imm(llvm::MCInst &Inst, unsigned Imm,
677                                          uint64_t Addr, const void *Decoder) {
678   return DecodeVecShiftLImm(Inst, Imm, 32);
679 }
680
681 static DecodeStatus DecodeVecShiftL16Imm(llvm::MCInst &Inst, unsigned Imm,
682                                          uint64_t Addr, const void *Decoder) {
683   return DecodeVecShiftLImm(Inst, Imm, 16);
684 }
685
686 static DecodeStatus DecodeVecShiftL8Imm(llvm::MCInst &Inst, unsigned Imm,
687                                         uint64_t Addr, const void *Decoder) {
688   return DecodeVecShiftLImm(Inst, Imm, 8);
689 }
690
691 static DecodeStatus DecodeThreeAddrSRegInstruction(llvm::MCInst &Inst,
692                                                    uint32_t insn, uint64_t Addr,
693                                                    const void *Decoder) {
694   unsigned Rd = fieldFromInstruction(insn, 0, 5);
695   unsigned Rn = fieldFromInstruction(insn, 5, 5);
696   unsigned Rm = fieldFromInstruction(insn, 16, 5);
697   unsigned shiftHi = fieldFromInstruction(insn, 22, 2);
698   unsigned shiftLo = fieldFromInstruction(insn, 10, 6);
699   unsigned shift = (shiftHi << 6) | shiftLo;
700   switch (Inst.getOpcode()) {
701   default:
702     return Fail;
703   case ARM64::ADDWrs:
704   case ARM64::ADDSWrs:
705   case ARM64::SUBWrs:
706   case ARM64::SUBSWrs:
707     // if shift == '11' then ReservedValue()
708     if (shiftHi == 0x3)
709       return Fail;
710     // Deliberate fallthrough
711   case ARM64::ANDWrs:
712   case ARM64::ANDSWrs:
713   case ARM64::BICWrs:
714   case ARM64::BICSWrs:
715   case ARM64::ORRWrs:
716   case ARM64::ORNWrs:
717   case ARM64::EORWrs:
718   case ARM64::EONWrs: {
719     // if sf == '0' and imm6<5> == '1' then ReservedValue()
720     if (shiftLo >> 5 == 1)
721       return Fail;
722     DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
723     DecodeGPR32RegisterClass(Inst, Rn, Addr, Decoder);
724     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
725     break;
726   }
727   case ARM64::ADDXrs:
728   case ARM64::ADDSXrs:
729   case ARM64::SUBXrs:
730   case ARM64::SUBSXrs:
731     // if shift == '11' then ReservedValue()
732     if (shiftHi == 0x3)
733       return Fail;
734     // Deliberate fallthrough
735   case ARM64::ANDXrs:
736   case ARM64::ANDSXrs:
737   case ARM64::BICXrs:
738   case ARM64::BICSXrs:
739   case ARM64::ORRXrs:
740   case ARM64::ORNXrs:
741   case ARM64::EORXrs:
742   case ARM64::EONXrs:
743     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
744     DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder);
745     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
746     break;
747   }
748
749   Inst.addOperand(MCOperand::CreateImm(shift));
750   return Success;
751 }
752
753 static DecodeStatus DecodeMoveImmInstruction(llvm::MCInst &Inst, uint32_t insn,
754                                              uint64_t Addr,
755                                              const void *Decoder) {
756   unsigned Rd = fieldFromInstruction(insn, 0, 5);
757   unsigned imm = fieldFromInstruction(insn, 5, 16);
758   unsigned shift = fieldFromInstruction(insn, 21, 2);
759   shift <<= 4;
760   switch (Inst.getOpcode()) {
761   default:
762     return Fail;
763   case ARM64::MOVZWi:
764   case ARM64::MOVNWi:
765   case ARM64::MOVKWi:
766     if (shift & (1U << 5))
767       return Fail;
768     DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
769     break;
770   case ARM64::MOVZXi:
771   case ARM64::MOVNXi:
772   case ARM64::MOVKXi:
773     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
774     break;
775   }
776
777   if (Inst.getOpcode() == ARM64::MOVKWi || Inst.getOpcode() == ARM64::MOVKXi)
778     Inst.addOperand(Inst.getOperand(0));
779
780   Inst.addOperand(MCOperand::CreateImm(imm));
781   Inst.addOperand(MCOperand::CreateImm(shift));
782   return Success;
783 }
784
785 static DecodeStatus DecodeUnsignedLdStInstruction(llvm::MCInst &Inst,
786                                                   uint32_t insn, uint64_t Addr,
787                                                   const void *Decoder) {
788   unsigned Rt = fieldFromInstruction(insn, 0, 5);
789   unsigned Rn = fieldFromInstruction(insn, 5, 5);
790   unsigned offset = fieldFromInstruction(insn, 10, 12);
791   const ARM64Disassembler *Dis =
792       static_cast<const ARM64Disassembler *>(Decoder);
793
794   switch (Inst.getOpcode()) {
795   default:
796     return Fail;
797   case ARM64::PRFMui:
798     // Rt is an immediate in prefetch.
799     Inst.addOperand(MCOperand::CreateImm(Rt));
800     break;
801   case ARM64::STRBBui:
802   case ARM64::LDRBBui:
803   case ARM64::LDRSBWui:
804   case ARM64::STRHHui:
805   case ARM64::LDRHHui:
806   case ARM64::LDRSHWui:
807   case ARM64::STRWui:
808   case ARM64::LDRWui:
809     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
810     break;
811   case ARM64::LDRSBXui:
812   case ARM64::LDRSHXui:
813   case ARM64::LDRSWui:
814   case ARM64::STRXui:
815   case ARM64::LDRXui:
816     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
817     break;
818   case ARM64::LDRQui:
819   case ARM64::STRQui:
820     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
821     break;
822   case ARM64::LDRDui:
823   case ARM64::STRDui:
824     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
825     break;
826   case ARM64::LDRSui:
827   case ARM64::STRSui:
828     DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder);
829     break;
830   case ARM64::LDRHui:
831   case ARM64::STRHui:
832     DecodeFPR16RegisterClass(Inst, Rt, Addr, Decoder);
833     break;
834   case ARM64::LDRBui:
835   case ARM64::STRBui:
836     DecodeFPR8RegisterClass(Inst, Rt, Addr, Decoder);
837     break;
838   }
839
840   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
841   if (!Dis->tryAddingSymbolicOperand(Inst, offset, Addr, Fail, 0, 4))
842     Inst.addOperand(MCOperand::CreateImm(offset));
843   return Success;
844 }
845
846 static DecodeStatus DecodeSignedLdStInstruction(llvm::MCInst &Inst,
847                                                 uint32_t insn, uint64_t Addr,
848                                                 const void *Decoder) {
849   unsigned Rt = fieldFromInstruction(insn, 0, 5);
850   unsigned Rn = fieldFromInstruction(insn, 5, 5);
851   int64_t offset = fieldFromInstruction(insn, 12, 9);
852
853   // offset is a 9-bit signed immediate, so sign extend it to
854   // fill the unsigned.
855   if (offset & (1 << (9 - 1)))
856     offset |= ~((1LL << 9) - 1);
857
858   switch (Inst.getOpcode()) {
859   default:
860     return Fail;
861   case ARM64::PRFUMi:
862     // Rt is an immediate in prefetch.
863     Inst.addOperand(MCOperand::CreateImm(Rt));
864     break;
865   case ARM64::STURBBi:
866   case ARM64::LDURBBi:
867   case ARM64::LDURSBWi:
868   case ARM64::STURHHi:
869   case ARM64::LDURHHi:
870   case ARM64::LDURSHWi:
871   case ARM64::STURWi:
872   case ARM64::LDURWi:
873   case ARM64::LDTRSBWi:
874   case ARM64::LDTRSHWi:
875   case ARM64::STTRWi:
876   case ARM64::LDTRWi:
877   case ARM64::STTRHi:
878   case ARM64::LDTRHi:
879   case ARM64::LDTRBi:
880   case ARM64::STTRBi:
881   case ARM64::LDRSBWpre:
882   case ARM64::LDRSHWpre:
883   case ARM64::STRBBpre:
884   case ARM64::LDRBBpre:
885   case ARM64::STRHHpre:
886   case ARM64::LDRHHpre:
887   case ARM64::STRWpre:
888   case ARM64::LDRWpre:
889   case ARM64::LDRSBWpost:
890   case ARM64::LDRSHWpost:
891   case ARM64::STRBBpost:
892   case ARM64::LDRBBpost:
893   case ARM64::STRHHpost:
894   case ARM64::LDRHHpost:
895   case ARM64::STRWpost:
896   case ARM64::LDRWpost:
897     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
898     break;
899   case ARM64::LDURSBXi:
900   case ARM64::LDURSHXi:
901   case ARM64::LDURSWi:
902   case ARM64::STURXi:
903   case ARM64::LDURXi:
904   case ARM64::LDTRSBXi:
905   case ARM64::LDTRSHXi:
906   case ARM64::LDTRSWi:
907   case ARM64::STTRXi:
908   case ARM64::LDTRXi:
909   case ARM64::LDRSBXpre:
910   case ARM64::LDRSHXpre:
911   case ARM64::STRXpre:
912   case ARM64::LDRSWpre:
913   case ARM64::LDRXpre:
914   case ARM64::LDRSBXpost:
915   case ARM64::LDRSHXpost:
916   case ARM64::STRXpost:
917   case ARM64::LDRSWpost:
918   case ARM64::LDRXpost:
919     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
920     break;
921   case ARM64::LDURQi:
922   case ARM64::STURQi:
923   case ARM64::LDRQpre:
924   case ARM64::STRQpre:
925   case ARM64::LDRQpost:
926   case ARM64::STRQpost:
927     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
928     break;
929   case ARM64::LDURDi:
930   case ARM64::STURDi:
931   case ARM64::LDRDpre:
932   case ARM64::STRDpre:
933   case ARM64::LDRDpost:
934   case ARM64::STRDpost:
935     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
936     break;
937   case ARM64::LDURSi:
938   case ARM64::STURSi:
939   case ARM64::LDRSpre:
940   case ARM64::STRSpre:
941   case ARM64::LDRSpost:
942   case ARM64::STRSpost:
943     DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder);
944     break;
945   case ARM64::LDURHi:
946   case ARM64::STURHi:
947   case ARM64::LDRHpre:
948   case ARM64::STRHpre:
949   case ARM64::LDRHpost:
950   case ARM64::STRHpost:
951     DecodeFPR16RegisterClass(Inst, Rt, Addr, Decoder);
952     break;
953   case ARM64::LDURBi:
954   case ARM64::STURBi:
955   case ARM64::LDRBpre:
956   case ARM64::STRBpre:
957   case ARM64::LDRBpost:
958   case ARM64::STRBpost:
959     DecodeFPR8RegisterClass(Inst, Rt, Addr, Decoder);
960     break;
961   }
962
963   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
964   Inst.addOperand(MCOperand::CreateImm(offset));
965   return Success;
966 }
967
968 static DecodeStatus DecodeExclusiveLdStInstruction(llvm::MCInst &Inst,
969                                                    uint32_t insn, uint64_t Addr,
970                                                    const void *Decoder) {
971   unsigned Rt = fieldFromInstruction(insn, 0, 5);
972   unsigned Rn = fieldFromInstruction(insn, 5, 5);
973   unsigned Rt2 = fieldFromInstruction(insn, 10, 5);
974   unsigned Rs = fieldFromInstruction(insn, 16, 5);
975
976   switch (Inst.getOpcode()) {
977   default:
978     return Fail;
979   case ARM64::STLXRW:
980   case ARM64::STLXRB:
981   case ARM64::STLXRH:
982   case ARM64::STXRW:
983   case ARM64::STXRB:
984   case ARM64::STXRH:
985     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
986   // FALLTHROUGH
987   case ARM64::LDARW:
988   case ARM64::LDARB:
989   case ARM64::LDARH:
990   case ARM64::LDAXRW:
991   case ARM64::LDAXRB:
992   case ARM64::LDAXRH:
993   case ARM64::LDXRW:
994   case ARM64::LDXRB:
995   case ARM64::LDXRH:
996   case ARM64::STLRW:
997   case ARM64::STLRB:
998   case ARM64::STLRH:
999     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1000     break;
1001   case ARM64::STLXRX:
1002   case ARM64::STXRX:
1003     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
1004   // FALLTHROUGH
1005   case ARM64::LDARX:
1006   case ARM64::LDAXRX:
1007   case ARM64::LDXRX:
1008   case ARM64::STLRX:
1009     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1010     break;
1011   case ARM64::STLXPW:
1012   case ARM64::STXPW:
1013     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
1014   // FALLTHROUGH
1015   case ARM64::LDAXPW:
1016   case ARM64::LDXPW:
1017     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1018     DecodeGPR32RegisterClass(Inst, Rt2, Addr, Decoder);
1019     break;
1020   case ARM64::STLXPX:
1021   case ARM64::STXPX:
1022     DecodeGPR32RegisterClass(Inst, Rs, Addr, Decoder);
1023   // FALLTHROUGH
1024   case ARM64::LDAXPX:
1025   case ARM64::LDXPX:
1026     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1027     DecodeGPR64RegisterClass(Inst, Rt2, Addr, Decoder);
1028     break;
1029   }
1030
1031   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1032   return Success;
1033 }
1034
1035 static DecodeStatus DecodePairLdStInstruction(llvm::MCInst &Inst, uint32_t insn,
1036                                               uint64_t Addr,
1037                                               const void *Decoder) {
1038   unsigned Rt = fieldFromInstruction(insn, 0, 5);
1039   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1040   unsigned Rt2 = fieldFromInstruction(insn, 10, 5);
1041   int64_t offset = fieldFromInstruction(insn, 15, 7);
1042
1043   // offset is a 7-bit signed immediate, so sign extend it to
1044   // fill the unsigned.
1045   if (offset & (1 << (7 - 1)))
1046     offset |= ~((1LL << 7) - 1);
1047
1048   switch (Inst.getOpcode()) {
1049   default:
1050     return Fail;
1051   case ARM64::LDNPXi:
1052   case ARM64::STNPXi:
1053   case ARM64::LDPXpost:
1054   case ARM64::STPXpost:
1055   case ARM64::LDPSWpost:
1056   case ARM64::LDPXi:
1057   case ARM64::STPXi:
1058   case ARM64::LDPSWi:
1059   case ARM64::LDPXpre:
1060   case ARM64::STPXpre:
1061   case ARM64::LDPSWpre:
1062     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1063     DecodeGPR64RegisterClass(Inst, Rt2, Addr, Decoder);
1064     break;
1065   case ARM64::LDNPWi:
1066   case ARM64::STNPWi:
1067   case ARM64::LDPWpost:
1068   case ARM64::STPWpost:
1069   case ARM64::LDPWi:
1070   case ARM64::STPWi:
1071   case ARM64::LDPWpre:
1072   case ARM64::STPWpre:
1073     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1074     DecodeGPR32RegisterClass(Inst, Rt2, Addr, Decoder);
1075     break;
1076   case ARM64::LDNPQi:
1077   case ARM64::STNPQi:
1078   case ARM64::LDPQpost:
1079   case ARM64::STPQpost:
1080   case ARM64::LDPQi:
1081   case ARM64::STPQi:
1082   case ARM64::LDPQpre:
1083   case ARM64::STPQpre:
1084     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
1085     DecodeFPR128RegisterClass(Inst, Rt2, Addr, Decoder);
1086     break;
1087   case ARM64::LDNPDi:
1088   case ARM64::STNPDi:
1089   case ARM64::LDPDpost:
1090   case ARM64::STPDpost:
1091   case ARM64::LDPDi:
1092   case ARM64::STPDi:
1093   case ARM64::LDPDpre:
1094   case ARM64::STPDpre:
1095     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
1096     DecodeFPR64RegisterClass(Inst, Rt2, Addr, Decoder);
1097     break;
1098   case ARM64::LDNPSi:
1099   case ARM64::STNPSi:
1100   case ARM64::LDPSpost:
1101   case ARM64::STPSpost:
1102   case ARM64::LDPSi:
1103   case ARM64::STPSi:
1104   case ARM64::LDPSpre:
1105   case ARM64::STPSpre:
1106     DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder);
1107     DecodeFPR32RegisterClass(Inst, Rt2, Addr, Decoder);
1108     break;
1109   }
1110
1111   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1112   Inst.addOperand(MCOperand::CreateImm(offset));
1113   return Success;
1114 }
1115
1116 static DecodeStatus DecodeRegOffsetLdStInstruction(llvm::MCInst &Inst,
1117                                                    uint32_t insn, uint64_t Addr,
1118                                                    const void *Decoder) {
1119   unsigned Rt = fieldFromInstruction(insn, 0, 5);
1120   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1121   unsigned Rm = fieldFromInstruction(insn, 16, 5);
1122   unsigned extendHi = fieldFromInstruction(insn, 13, 3);
1123   unsigned extendLo = fieldFromInstruction(insn, 12, 1);
1124   unsigned extend = (extendHi << 1) | extendLo;
1125
1126   // All RO load-store instructions are undefined if option == 00x or 10x.
1127   if (extend >> 2 == 0x0 || extend >> 2 == 0x2)
1128     return Fail;
1129
1130   switch (Inst.getOpcode()) {
1131   default:
1132     return Fail;
1133   case ARM64::LDRSWro:
1134     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1135     break;
1136   case ARM64::LDRXro:
1137   case ARM64::STRXro:
1138     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1139     break;
1140   case ARM64::LDRWro:
1141   case ARM64::STRWro:
1142     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1143     break;
1144   case ARM64::LDRQro:
1145   case ARM64::STRQro:
1146     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
1147     break;
1148   case ARM64::LDRDro:
1149   case ARM64::STRDro:
1150     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
1151     break;
1152   case ARM64::LDRSro:
1153   case ARM64::STRSro:
1154     DecodeFPR32RegisterClass(Inst, Rt, Addr, Decoder);
1155     break;
1156   case ARM64::LDRHro:
1157   case ARM64::STRHro:
1158     DecodeFPR16RegisterClass(Inst, Rt, Addr, Decoder);
1159     break;
1160   case ARM64::LDRBro:
1161   case ARM64::STRBro:
1162     DecodeFPR8RegisterClass(Inst, Rt, Addr, Decoder);
1163     break;
1164   case ARM64::LDRBBro:
1165   case ARM64::STRBBro:
1166   case ARM64::LDRSBWro:
1167     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1168     break;
1169   case ARM64::LDRHHro:
1170   case ARM64::STRHHro:
1171   case ARM64::LDRSHWro:
1172     DecodeGPR32RegisterClass(Inst, Rt, Addr, Decoder);
1173     break;
1174   case ARM64::LDRSHXro:
1175     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1176     break;
1177   case ARM64::LDRSBXro:
1178     DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1179     break;
1180   case ARM64::PRFMro:
1181     Inst.addOperand(MCOperand::CreateImm(Rt));
1182   }
1183
1184   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1185   DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
1186
1187   Inst.addOperand(MCOperand::CreateImm(extend));
1188   return Success;
1189 }
1190
1191 static DecodeStatus DecodeAddSubERegInstruction(llvm::MCInst &Inst,
1192                                                 uint32_t insn, uint64_t Addr,
1193                                                 const void *Decoder) {
1194   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1195   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1196   unsigned Rm = fieldFromInstruction(insn, 16, 5);
1197   unsigned extend = fieldFromInstruction(insn, 10, 6);
1198
1199   unsigned shift = extend & 0x7;
1200   if (shift > 4)
1201     return Fail;
1202
1203   switch (Inst.getOpcode()) {
1204   default:
1205     return Fail;
1206   case ARM64::ADDWrx:
1207   case ARM64::SUBWrx:
1208     DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder);
1209     DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder);
1210     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1211     break;
1212   case ARM64::ADDSWrx:
1213   case ARM64::SUBSWrx:
1214     DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
1215     DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder);
1216     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1217     break;
1218   case ARM64::ADDXrx:
1219   case ARM64::SUBXrx:
1220     DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1221     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1222     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1223     break;
1224   case ARM64::ADDSXrx:
1225   case ARM64::SUBSXrx:
1226     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1227     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1228     DecodeGPR32RegisterClass(Inst, Rm, Addr, Decoder);
1229     break;
1230   case ARM64::ADDXrx64:
1231   case ARM64::SUBXrx64:
1232     DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1233     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1234     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
1235     break;
1236   case ARM64::SUBSXrx64:
1237   case ARM64::ADDSXrx64:
1238     DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1239     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1240     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
1241     break;
1242   }
1243
1244   Inst.addOperand(MCOperand::CreateImm(extend));
1245   return Success;
1246 }
1247
1248 static DecodeStatus DecodeLogicalImmInstruction(llvm::MCInst &Inst,
1249                                                 uint32_t insn, uint64_t Addr,
1250                                                 const void *Decoder) {
1251   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1252   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1253   unsigned Datasize = fieldFromInstruction(insn, 31, 1);
1254   unsigned imm;
1255
1256   if (Datasize) {
1257     if (Inst.getOpcode() == ARM64::ANDSXri)
1258       DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1259     else
1260       DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1261     DecodeGPR64RegisterClass(Inst, Rn, Addr, Decoder);
1262     imm = fieldFromInstruction(insn, 10, 13);
1263     if (!ARM64_AM::isValidDecodeLogicalImmediate(imm, 64))
1264       return Fail;
1265   } else {
1266     if (Inst.getOpcode() == ARM64::ANDSWri)
1267       DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
1268     else
1269       DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder);
1270     DecodeGPR32RegisterClass(Inst, Rn, Addr, Decoder);
1271     imm = fieldFromInstruction(insn, 10, 12);
1272     if (!ARM64_AM::isValidDecodeLogicalImmediate(imm, 32))
1273       return Fail;
1274   }
1275   Inst.addOperand(MCOperand::CreateImm(imm));
1276   return Success;
1277 }
1278
1279 static DecodeStatus DecodeModImmInstruction(llvm::MCInst &Inst, uint32_t insn,
1280                                             uint64_t Addr,
1281                                             const void *Decoder) {
1282   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1283   unsigned cmode = fieldFromInstruction(insn, 12, 4);
1284   unsigned imm = fieldFromInstruction(insn, 16, 3) << 5;
1285   imm |= fieldFromInstruction(insn, 5, 5);
1286
1287   if (Inst.getOpcode() == ARM64::MOVID)
1288     DecodeFPR64RegisterClass(Inst, Rd, Addr, Decoder);
1289   else
1290     DecodeVectorRegisterClass(Inst, Rd, Addr, Decoder);
1291
1292   Inst.addOperand(MCOperand::CreateImm(imm));
1293
1294   switch (Inst.getOpcode()) {
1295   default:
1296     break;
1297   case ARM64::MOVIv4i16:
1298   case ARM64::MOVIv8i16:
1299   case ARM64::MVNIv4i16:
1300   case ARM64::MVNIv8i16:
1301   case ARM64::MOVIv2i32:
1302   case ARM64::MOVIv4i32:
1303   case ARM64::MVNIv2i32:
1304   case ARM64::MVNIv4i32:
1305     Inst.addOperand(MCOperand::CreateImm((cmode & 6) << 2));
1306     break;
1307   case ARM64::MOVIv2s_msl:
1308   case ARM64::MOVIv4s_msl:
1309   case ARM64::MVNIv2s_msl:
1310   case ARM64::MVNIv4s_msl:
1311     Inst.addOperand(MCOperand::CreateImm(cmode & 1 ? 0x110 : 0x108));
1312     break;
1313   }
1314
1315   return Success;
1316 }
1317
1318 static DecodeStatus DecodeModImmTiedInstruction(llvm::MCInst &Inst,
1319                                                 uint32_t insn, uint64_t Addr,
1320                                                 const void *Decoder) {
1321   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1322   unsigned cmode = fieldFromInstruction(insn, 12, 4);
1323   unsigned imm = fieldFromInstruction(insn, 16, 3) << 5;
1324   imm |= fieldFromInstruction(insn, 5, 5);
1325
1326   // Tied operands added twice.
1327   DecodeVectorRegisterClass(Inst, Rd, Addr, Decoder);
1328   DecodeVectorRegisterClass(Inst, Rd, Addr, Decoder);
1329
1330   Inst.addOperand(MCOperand::CreateImm(imm));
1331   Inst.addOperand(MCOperand::CreateImm((cmode & 6) << 2));
1332
1333   return Success;
1334 }
1335
1336 static DecodeStatus DecodeAdrInstruction(llvm::MCInst &Inst, uint32_t insn,
1337                                          uint64_t Addr, const void *Decoder) {
1338   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1339   int64_t imm = fieldFromInstruction(insn, 5, 19) << 2;
1340   imm |= fieldFromInstruction(insn, 29, 2);
1341   const ARM64Disassembler *Dis =
1342       static_cast<const ARM64Disassembler *>(Decoder);
1343
1344   // Sign-extend the 21-bit immediate.
1345   if (imm & (1 << (21 - 1)))
1346     imm |= ~((1LL << 21) - 1);
1347
1348   DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1349   if (!Dis->tryAddingSymbolicOperand(Inst, imm, Addr, Fail, 0, 4))
1350     Inst.addOperand(MCOperand::CreateImm(imm));
1351
1352   return Success;
1353 }
1354
1355 static DecodeStatus DecodeBaseAddSubImm(llvm::MCInst &Inst, uint32_t insn,
1356                                         uint64_t Addr, const void *Decoder) {
1357   unsigned Rd = fieldFromInstruction(insn, 0, 5);
1358   unsigned Rn = fieldFromInstruction(insn, 5, 5);
1359   unsigned Imm = fieldFromInstruction(insn, 10, 14);
1360   unsigned S = fieldFromInstruction(insn, 29, 1);
1361   unsigned Datasize = fieldFromInstruction(insn, 31, 1);
1362
1363   unsigned ShifterVal = (Imm >> 12) & 3;
1364   unsigned ImmVal = Imm & 0xFFF;
1365   const ARM64Disassembler *Dis =
1366       static_cast<const ARM64Disassembler *>(Decoder);
1367
1368   if (ShifterVal != 0 && ShifterVal != 1)
1369     return Fail;
1370
1371   if (Datasize) {
1372     if (Rd == 31 && !S)
1373       DecodeGPR64spRegisterClass(Inst, Rd, Addr, Decoder);
1374     else
1375       DecodeGPR64RegisterClass(Inst, Rd, Addr, Decoder);
1376     DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1377   } else {
1378     if (Rd == 31 && !S)
1379       DecodeGPR32spRegisterClass(Inst, Rd, Addr, Decoder);
1380     else
1381       DecodeGPR32RegisterClass(Inst, Rd, Addr, Decoder);
1382     DecodeGPR32spRegisterClass(Inst, Rn, Addr, Decoder);
1383   }
1384
1385   if (!Dis->tryAddingSymbolicOperand(Inst, Imm, Addr, Fail, 0, 4))
1386     Inst.addOperand(MCOperand::CreateImm(ImmVal));
1387   Inst.addOperand(MCOperand::CreateImm(12 * ShifterVal));
1388   return Success;
1389 }
1390
1391 static DecodeStatus DecodeUnconditionalBranch(llvm::MCInst &Inst, uint32_t insn,
1392                                               uint64_t Addr,
1393                                               const void *Decoder) {
1394   int64_t imm = fieldFromInstruction(insn, 0, 26);
1395   const ARM64Disassembler *Dis =
1396       static_cast<const ARM64Disassembler *>(Decoder);
1397
1398   // Sign-extend the 26-bit immediate.
1399   if (imm & (1 << (26 - 1)))
1400     imm |= ~((1LL << 26) - 1);
1401
1402   if (!Dis->tryAddingSymbolicOperand(Inst, imm << 2, Addr, true, 0, 4))
1403     Inst.addOperand(MCOperand::CreateImm(imm));
1404
1405   return Success;
1406 }
1407
1408 static DecodeStatus DecodeSystemCPSRInstruction(llvm::MCInst &Inst,
1409                                                 uint32_t insn, uint64_t Addr,
1410                                                 const void *Decoder) {
1411   uint64_t op1 = fieldFromInstruction(insn, 16, 3);
1412   uint64_t op2 = fieldFromInstruction(insn, 5, 3);
1413   uint64_t crm = fieldFromInstruction(insn, 8, 4);
1414
1415   uint64_t cpsr_field = (op1 << 3) | op2;
1416
1417   Inst.addOperand(MCOperand::CreateImm(cpsr_field));
1418   Inst.addOperand(MCOperand::CreateImm(crm));
1419
1420   bool ValidNamed;
1421   (void)ARM64PState::PStateMapper().toString(cpsr_field, ValidNamed);
1422   
1423   return ValidNamed ? Success : Fail;
1424 }
1425
1426 static DecodeStatus DecodeTestAndBranch(llvm::MCInst &Inst, uint32_t insn,
1427                                         uint64_t Addr, const void *Decoder) {
1428   uint64_t Rt = fieldFromInstruction(insn, 0, 5);
1429   uint64_t bit = fieldFromInstruction(insn, 31, 1) << 5;
1430   bit |= fieldFromInstruction(insn, 19, 5);
1431   int64_t dst = fieldFromInstruction(insn, 5, 14);
1432   const ARM64Disassembler *Dis =
1433       static_cast<const ARM64Disassembler *>(Decoder);
1434
1435   // Sign-extend 14-bit immediate.
1436   if (dst & (1 << (14 - 1)))
1437     dst |= ~((1LL << 14) - 1);
1438
1439   DecodeGPR64RegisterClass(Inst, Rt, Addr, Decoder);
1440   Inst.addOperand(MCOperand::CreateImm(bit));
1441   if (!Dis->tryAddingSymbolicOperand(Inst, dst << 2, Addr, true, 0, 4))
1442     Inst.addOperand(MCOperand::CreateImm(dst));
1443
1444   return Success;
1445 }
1446
1447 static DecodeStatus DecodeSIMDLdStPost(llvm::MCInst &Inst, uint32_t insn,
1448                                        uint64_t Addr, const void *Decoder) {
1449   uint64_t Rd = fieldFromInstruction(insn, 0, 5);
1450   uint64_t Rn = fieldFromInstruction(insn, 5, 5);
1451   uint64_t Rm = fieldFromInstruction(insn, 16, 5);
1452
1453   switch (Inst.getOpcode()) {
1454   default:
1455     return Fail;
1456   case ARM64::ST1Onev8b_POST:
1457   case ARM64::ST1Onev4h_POST:
1458   case ARM64::ST1Onev2s_POST:
1459   case ARM64::ST1Onev1d_POST:
1460   case ARM64::LD1Onev8b_POST:
1461   case ARM64::LD1Onev4h_POST:
1462   case ARM64::LD1Onev2s_POST:
1463   case ARM64::LD1Onev1d_POST:
1464     DecodeFPR64RegisterClass(Inst, Rd, Addr, Decoder);
1465     break;
1466   case ARM64::ST1Onev16b_POST:
1467   case ARM64::ST1Onev8h_POST:
1468   case ARM64::ST1Onev4s_POST:
1469   case ARM64::ST1Onev2d_POST:
1470   case ARM64::LD1Onev16b_POST:
1471   case ARM64::LD1Onev8h_POST:
1472   case ARM64::LD1Onev4s_POST:
1473   case ARM64::LD1Onev2d_POST:
1474     DecodeFPR128RegisterClass(Inst, Rd, Addr, Decoder);
1475     break;
1476   case ARM64::ST1Twov8b_POST:
1477   case ARM64::ST1Twov4h_POST:
1478   case ARM64::ST1Twov2s_POST:
1479   case ARM64::ST1Twov1d_POST:
1480   case ARM64::ST2Twov8b_POST:
1481   case ARM64::ST2Twov4h_POST:
1482   case ARM64::ST2Twov2s_POST:
1483   case ARM64::LD1Twov8b_POST:
1484   case ARM64::LD1Twov4h_POST:
1485   case ARM64::LD1Twov2s_POST:
1486   case ARM64::LD1Twov1d_POST:
1487   case ARM64::LD2Twov8b_POST:
1488   case ARM64::LD2Twov4h_POST:
1489   case ARM64::LD2Twov2s_POST:
1490     DecodeDDRegisterClass(Inst, Rd, Addr, Decoder);
1491     break;
1492   case ARM64::ST1Threev8b_POST:
1493   case ARM64::ST1Threev4h_POST:
1494   case ARM64::ST1Threev2s_POST:
1495   case ARM64::ST1Threev1d_POST:
1496   case ARM64::ST3Threev8b_POST:
1497   case ARM64::ST3Threev4h_POST:
1498   case ARM64::ST3Threev2s_POST:
1499   case ARM64::LD1Threev8b_POST:
1500   case ARM64::LD1Threev4h_POST:
1501   case ARM64::LD1Threev2s_POST:
1502   case ARM64::LD1Threev1d_POST:
1503   case ARM64::LD3Threev8b_POST:
1504   case ARM64::LD3Threev4h_POST:
1505   case ARM64::LD3Threev2s_POST:
1506     DecodeDDDRegisterClass(Inst, Rd, Addr, Decoder);
1507     break;
1508   case ARM64::ST1Fourv8b_POST:
1509   case ARM64::ST1Fourv4h_POST:
1510   case ARM64::ST1Fourv2s_POST:
1511   case ARM64::ST1Fourv1d_POST:
1512   case ARM64::ST4Fourv8b_POST:
1513   case ARM64::ST4Fourv4h_POST:
1514   case ARM64::ST4Fourv2s_POST:
1515   case ARM64::LD1Fourv8b_POST:
1516   case ARM64::LD1Fourv4h_POST:
1517   case ARM64::LD1Fourv2s_POST:
1518   case ARM64::LD1Fourv1d_POST:
1519   case ARM64::LD4Fourv8b_POST:
1520   case ARM64::LD4Fourv4h_POST:
1521   case ARM64::LD4Fourv2s_POST:
1522     DecodeDDDDRegisterClass(Inst, Rd, Addr, Decoder);
1523     break;
1524   case ARM64::ST1Twov16b_POST:
1525   case ARM64::ST1Twov8h_POST:
1526   case ARM64::ST1Twov4s_POST:
1527   case ARM64::ST1Twov2d_POST:
1528   case ARM64::ST2Twov16b_POST:
1529   case ARM64::ST2Twov8h_POST:
1530   case ARM64::ST2Twov4s_POST:
1531   case ARM64::ST2Twov2d_POST:
1532   case ARM64::LD1Twov16b_POST:
1533   case ARM64::LD1Twov8h_POST:
1534   case ARM64::LD1Twov4s_POST:
1535   case ARM64::LD1Twov2d_POST:
1536   case ARM64::LD2Twov16b_POST:
1537   case ARM64::LD2Twov8h_POST:
1538   case ARM64::LD2Twov4s_POST:
1539   case ARM64::LD2Twov2d_POST:
1540     DecodeQQRegisterClass(Inst, Rd, Addr, Decoder);
1541     break;
1542   case ARM64::ST1Threev16b_POST:
1543   case ARM64::ST1Threev8h_POST:
1544   case ARM64::ST1Threev4s_POST:
1545   case ARM64::ST1Threev2d_POST:
1546   case ARM64::ST3Threev16b_POST:
1547   case ARM64::ST3Threev8h_POST:
1548   case ARM64::ST3Threev4s_POST:
1549   case ARM64::ST3Threev2d_POST:
1550   case ARM64::LD1Threev16b_POST:
1551   case ARM64::LD1Threev8h_POST:
1552   case ARM64::LD1Threev4s_POST:
1553   case ARM64::LD1Threev2d_POST:
1554   case ARM64::LD3Threev16b_POST:
1555   case ARM64::LD3Threev8h_POST:
1556   case ARM64::LD3Threev4s_POST:
1557   case ARM64::LD3Threev2d_POST:
1558     DecodeQQQRegisterClass(Inst, Rd, Addr, Decoder);
1559     break;
1560   case ARM64::ST1Fourv16b_POST:
1561   case ARM64::ST1Fourv8h_POST:
1562   case ARM64::ST1Fourv4s_POST:
1563   case ARM64::ST1Fourv2d_POST:
1564   case ARM64::ST4Fourv16b_POST:
1565   case ARM64::ST4Fourv8h_POST:
1566   case ARM64::ST4Fourv4s_POST:
1567   case ARM64::ST4Fourv2d_POST:
1568   case ARM64::LD1Fourv16b_POST:
1569   case ARM64::LD1Fourv8h_POST:
1570   case ARM64::LD1Fourv4s_POST:
1571   case ARM64::LD1Fourv2d_POST:
1572   case ARM64::LD4Fourv16b_POST:
1573   case ARM64::LD4Fourv8h_POST:
1574   case ARM64::LD4Fourv4s_POST:
1575   case ARM64::LD4Fourv2d_POST:
1576     DecodeQQQQRegisterClass(Inst, Rd, Addr, Decoder);
1577     break;
1578   }
1579
1580   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1581   DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
1582   return Success;
1583 }
1584
1585 static DecodeStatus DecodeSIMDLdStSingle(llvm::MCInst &Inst, uint32_t insn,
1586                                          uint64_t Addr, const void *Decoder) {
1587   uint64_t Rt = fieldFromInstruction(insn, 0, 5);
1588   uint64_t Rn = fieldFromInstruction(insn, 5, 5);
1589   uint64_t Rm = fieldFromInstruction(insn, 16, 5);
1590   uint64_t size = fieldFromInstruction(insn, 10, 2);
1591   uint64_t S = fieldFromInstruction(insn, 12, 1);
1592   uint64_t Q = fieldFromInstruction(insn, 30, 1);
1593   uint64_t index = 0;
1594
1595   switch (Inst.getOpcode()) {
1596   case ARM64::ST1i8:
1597   case ARM64::ST1i8_POST:
1598   case ARM64::ST2i8:
1599   case ARM64::ST2i8_POST:
1600   case ARM64::ST3i8_POST:
1601   case ARM64::ST3i8:
1602   case ARM64::ST4i8_POST:
1603   case ARM64::ST4i8:
1604     index = (Q << 3) | (S << 2) | size;
1605     break;
1606   case ARM64::ST1i16:
1607   case ARM64::ST1i16_POST:
1608   case ARM64::ST2i16:
1609   case ARM64::ST2i16_POST:
1610   case ARM64::ST3i16_POST:
1611   case ARM64::ST3i16:
1612   case ARM64::ST4i16_POST:
1613   case ARM64::ST4i16:
1614     index = (Q << 2) | (S << 1) | (size >> 1);
1615     break;
1616   case ARM64::ST1i32:
1617   case ARM64::ST1i32_POST:
1618   case ARM64::ST2i32:
1619   case ARM64::ST2i32_POST:
1620   case ARM64::ST3i32_POST:
1621   case ARM64::ST3i32:
1622   case ARM64::ST4i32_POST:
1623   case ARM64::ST4i32:
1624     index = (Q << 1) | S;
1625     break;
1626   case ARM64::ST1i64:
1627   case ARM64::ST1i64_POST:
1628   case ARM64::ST2i64:
1629   case ARM64::ST2i64_POST:
1630   case ARM64::ST3i64_POST:
1631   case ARM64::ST3i64:
1632   case ARM64::ST4i64_POST:
1633   case ARM64::ST4i64:
1634     index = Q;
1635     break;
1636   }
1637
1638   switch (Inst.getOpcode()) {
1639   default:
1640     return Fail;
1641   case ARM64::LD1Rv8b:
1642   case ARM64::LD1Rv8b_POST:
1643   case ARM64::LD1Rv4h:
1644   case ARM64::LD1Rv4h_POST:
1645   case ARM64::LD1Rv2s:
1646   case ARM64::LD1Rv2s_POST:
1647   case ARM64::LD1Rv1d:
1648   case ARM64::LD1Rv1d_POST:
1649     DecodeFPR64RegisterClass(Inst, Rt, Addr, Decoder);
1650     break;
1651   case ARM64::LD1Rv16b:
1652   case ARM64::LD1Rv16b_POST:
1653   case ARM64::LD1Rv8h:
1654   case ARM64::LD1Rv8h_POST:
1655   case ARM64::LD1Rv4s:
1656   case ARM64::LD1Rv4s_POST:
1657   case ARM64::LD1Rv2d:
1658   case ARM64::LD1Rv2d_POST:
1659   case ARM64::ST1i8:
1660   case ARM64::ST1i8_POST:
1661   case ARM64::ST1i16:
1662   case ARM64::ST1i16_POST:
1663   case ARM64::ST1i32:
1664   case ARM64::ST1i32_POST:
1665   case ARM64::ST1i64:
1666   case ARM64::ST1i64_POST:
1667     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
1668     break;
1669   case ARM64::LD2Rv16b:
1670   case ARM64::LD2Rv16b_POST:
1671   case ARM64::LD2Rv8h:
1672   case ARM64::LD2Rv8h_POST:
1673   case ARM64::LD2Rv4s:
1674   case ARM64::LD2Rv4s_POST:
1675   case ARM64::LD2Rv2d:
1676   case ARM64::LD2Rv2d_POST:
1677   case ARM64::ST2i8:
1678   case ARM64::ST2i8_POST:
1679   case ARM64::ST2i16:
1680   case ARM64::ST2i16_POST:
1681   case ARM64::ST2i32:
1682   case ARM64::ST2i32_POST:
1683   case ARM64::ST2i64:
1684   case ARM64::ST2i64_POST:
1685     DecodeQQRegisterClass(Inst, Rt, Addr, Decoder);
1686     break;
1687   case ARM64::LD2Rv8b:
1688   case ARM64::LD2Rv8b_POST:
1689   case ARM64::LD2Rv4h:
1690   case ARM64::LD2Rv4h_POST:
1691   case ARM64::LD2Rv2s:
1692   case ARM64::LD2Rv2s_POST:
1693   case ARM64::LD2Rv1d:
1694   case ARM64::LD2Rv1d_POST:
1695     DecodeDDRegisterClass(Inst, Rt, Addr, Decoder);
1696     break;
1697   case ARM64::LD3Rv8b:
1698   case ARM64::LD3Rv8b_POST:
1699   case ARM64::LD3Rv4h:
1700   case ARM64::LD3Rv4h_POST:
1701   case ARM64::LD3Rv2s:
1702   case ARM64::LD3Rv2s_POST:
1703   case ARM64::LD3Rv1d:
1704   case ARM64::LD3Rv1d_POST:
1705     DecodeDDDRegisterClass(Inst, Rt, Addr, Decoder);
1706     break;
1707   case ARM64::LD3Rv16b:
1708   case ARM64::LD3Rv16b_POST:
1709   case ARM64::LD3Rv8h:
1710   case ARM64::LD3Rv8h_POST:
1711   case ARM64::LD3Rv4s:
1712   case ARM64::LD3Rv4s_POST:
1713   case ARM64::LD3Rv2d:
1714   case ARM64::LD3Rv2d_POST:
1715   case ARM64::ST3i8:
1716   case ARM64::ST3i8_POST:
1717   case ARM64::ST3i16:
1718   case ARM64::ST3i16_POST:
1719   case ARM64::ST3i32:
1720   case ARM64::ST3i32_POST:
1721   case ARM64::ST3i64:
1722   case ARM64::ST3i64_POST:
1723     DecodeQQQRegisterClass(Inst, Rt, Addr, Decoder);
1724     break;
1725   case ARM64::LD4Rv8b:
1726   case ARM64::LD4Rv8b_POST:
1727   case ARM64::LD4Rv4h:
1728   case ARM64::LD4Rv4h_POST:
1729   case ARM64::LD4Rv2s:
1730   case ARM64::LD4Rv2s_POST:
1731   case ARM64::LD4Rv1d:
1732   case ARM64::LD4Rv1d_POST:
1733     DecodeDDDDRegisterClass(Inst, Rt, Addr, Decoder);
1734     break;
1735   case ARM64::LD4Rv16b:
1736   case ARM64::LD4Rv16b_POST:
1737   case ARM64::LD4Rv8h:
1738   case ARM64::LD4Rv8h_POST:
1739   case ARM64::LD4Rv4s:
1740   case ARM64::LD4Rv4s_POST:
1741   case ARM64::LD4Rv2d:
1742   case ARM64::LD4Rv2d_POST:
1743   case ARM64::ST4i8:
1744   case ARM64::ST4i8_POST:
1745   case ARM64::ST4i16:
1746   case ARM64::ST4i16_POST:
1747   case ARM64::ST4i32:
1748   case ARM64::ST4i32_POST:
1749   case ARM64::ST4i64:
1750   case ARM64::ST4i64_POST:
1751     DecodeQQQQRegisterClass(Inst, Rt, Addr, Decoder);
1752     break;
1753   }
1754
1755   switch (Inst.getOpcode()) {
1756   case ARM64::LD1Rv8b:
1757   case ARM64::LD1Rv8b_POST:
1758   case ARM64::LD1Rv16b:
1759   case ARM64::LD1Rv16b_POST:
1760   case ARM64::LD1Rv4h:
1761   case ARM64::LD1Rv4h_POST:
1762   case ARM64::LD1Rv8h:
1763   case ARM64::LD1Rv8h_POST:
1764   case ARM64::LD1Rv4s:
1765   case ARM64::LD1Rv4s_POST:
1766   case ARM64::LD1Rv2s:
1767   case ARM64::LD1Rv2s_POST:
1768   case ARM64::LD1Rv1d:
1769   case ARM64::LD1Rv1d_POST:
1770   case ARM64::LD1Rv2d:
1771   case ARM64::LD1Rv2d_POST:
1772   case ARM64::LD2Rv8b:
1773   case ARM64::LD2Rv8b_POST:
1774   case ARM64::LD2Rv16b:
1775   case ARM64::LD2Rv16b_POST:
1776   case ARM64::LD2Rv4h:
1777   case ARM64::LD2Rv4h_POST:
1778   case ARM64::LD2Rv8h:
1779   case ARM64::LD2Rv8h_POST:
1780   case ARM64::LD2Rv2s:
1781   case ARM64::LD2Rv2s_POST:
1782   case ARM64::LD2Rv4s:
1783   case ARM64::LD2Rv4s_POST:
1784   case ARM64::LD2Rv2d:
1785   case ARM64::LD2Rv2d_POST:
1786   case ARM64::LD2Rv1d:
1787   case ARM64::LD2Rv1d_POST:
1788   case ARM64::LD3Rv8b:
1789   case ARM64::LD3Rv8b_POST:
1790   case ARM64::LD3Rv16b:
1791   case ARM64::LD3Rv16b_POST:
1792   case ARM64::LD3Rv4h:
1793   case ARM64::LD3Rv4h_POST:
1794   case ARM64::LD3Rv8h:
1795   case ARM64::LD3Rv8h_POST:
1796   case ARM64::LD3Rv2s:
1797   case ARM64::LD3Rv2s_POST:
1798   case ARM64::LD3Rv4s:
1799   case ARM64::LD3Rv4s_POST:
1800   case ARM64::LD3Rv2d:
1801   case ARM64::LD3Rv2d_POST:
1802   case ARM64::LD3Rv1d:
1803   case ARM64::LD3Rv1d_POST:
1804   case ARM64::LD4Rv8b:
1805   case ARM64::LD4Rv8b_POST:
1806   case ARM64::LD4Rv16b:
1807   case ARM64::LD4Rv16b_POST:
1808   case ARM64::LD4Rv4h:
1809   case ARM64::LD4Rv4h_POST:
1810   case ARM64::LD4Rv8h:
1811   case ARM64::LD4Rv8h_POST:
1812   case ARM64::LD4Rv2s:
1813   case ARM64::LD4Rv2s_POST:
1814   case ARM64::LD4Rv4s:
1815   case ARM64::LD4Rv4s_POST:
1816   case ARM64::LD4Rv2d:
1817   case ARM64::LD4Rv2d_POST:
1818   case ARM64::LD4Rv1d:
1819   case ARM64::LD4Rv1d_POST:
1820     break;
1821   default:
1822     Inst.addOperand(MCOperand::CreateImm(index));
1823   }
1824
1825   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1826
1827   switch (Inst.getOpcode()) {
1828   case ARM64::ST1i8_POST:
1829   case ARM64::ST1i16_POST:
1830   case ARM64::ST1i32_POST:
1831   case ARM64::ST1i64_POST:
1832   case ARM64::LD1Rv8b_POST:
1833   case ARM64::LD1Rv16b_POST:
1834   case ARM64::LD1Rv4h_POST:
1835   case ARM64::LD1Rv8h_POST:
1836   case ARM64::LD1Rv2s_POST:
1837   case ARM64::LD1Rv4s_POST:
1838   case ARM64::LD1Rv1d_POST:
1839   case ARM64::LD1Rv2d_POST:
1840   case ARM64::ST2i8_POST:
1841   case ARM64::ST2i16_POST:
1842   case ARM64::ST2i32_POST:
1843   case ARM64::ST2i64_POST:
1844   case ARM64::LD2Rv8b_POST:
1845   case ARM64::LD2Rv16b_POST:
1846   case ARM64::LD2Rv4h_POST:
1847   case ARM64::LD2Rv8h_POST:
1848   case ARM64::LD2Rv2s_POST:
1849   case ARM64::LD2Rv4s_POST:
1850   case ARM64::LD2Rv2d_POST:
1851   case ARM64::LD2Rv1d_POST:
1852   case ARM64::ST3i8_POST:
1853   case ARM64::ST3i16_POST:
1854   case ARM64::ST3i32_POST:
1855   case ARM64::ST3i64_POST:
1856   case ARM64::LD3Rv8b_POST:
1857   case ARM64::LD3Rv16b_POST:
1858   case ARM64::LD3Rv4h_POST:
1859   case ARM64::LD3Rv8h_POST:
1860   case ARM64::LD3Rv2s_POST:
1861   case ARM64::LD3Rv4s_POST:
1862   case ARM64::LD3Rv2d_POST:
1863   case ARM64::LD3Rv1d_POST:
1864   case ARM64::ST4i8_POST:
1865   case ARM64::ST4i16_POST:
1866   case ARM64::ST4i32_POST:
1867   case ARM64::ST4i64_POST:
1868   case ARM64::LD4Rv8b_POST:
1869   case ARM64::LD4Rv16b_POST:
1870   case ARM64::LD4Rv4h_POST:
1871   case ARM64::LD4Rv8h_POST:
1872   case ARM64::LD4Rv2s_POST:
1873   case ARM64::LD4Rv4s_POST:
1874   case ARM64::LD4Rv2d_POST:
1875   case ARM64::LD4Rv1d_POST:
1876     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
1877     break;
1878   }
1879   return Success;
1880 }
1881
1882 static DecodeStatus DecodeSIMDLdStSingleTied(llvm::MCInst &Inst, uint32_t insn,
1883                                              uint64_t Addr,
1884                                              const void *Decoder) {
1885   uint64_t Rt = fieldFromInstruction(insn, 0, 5);
1886   uint64_t Rn = fieldFromInstruction(insn, 5, 5);
1887   uint64_t Rm = fieldFromInstruction(insn, 16, 5);
1888   uint64_t size = fieldFromInstruction(insn, 10, 2);
1889   uint64_t S = fieldFromInstruction(insn, 12, 1);
1890   uint64_t Q = fieldFromInstruction(insn, 30, 1);
1891   uint64_t index = 0;
1892
1893   switch (Inst.getOpcode()) {
1894   case ARM64::LD1i8:
1895   case ARM64::LD1i8_POST:
1896   case ARM64::LD2i8:
1897   case ARM64::LD2i8_POST:
1898   case ARM64::LD3i8_POST:
1899   case ARM64::LD3i8:
1900   case ARM64::LD4i8_POST:
1901   case ARM64::LD4i8:
1902     index = (Q << 3) | (S << 2) | size;
1903     break;
1904   case ARM64::LD1i16:
1905   case ARM64::LD1i16_POST:
1906   case ARM64::LD2i16:
1907   case ARM64::LD2i16_POST:
1908   case ARM64::LD3i16_POST:
1909   case ARM64::LD3i16:
1910   case ARM64::LD4i16_POST:
1911   case ARM64::LD4i16:
1912     index = (Q << 2) | (S << 1) | (size >> 1);
1913     break;
1914   case ARM64::LD1i32:
1915   case ARM64::LD1i32_POST:
1916   case ARM64::LD2i32:
1917   case ARM64::LD2i32_POST:
1918   case ARM64::LD3i32_POST:
1919   case ARM64::LD3i32:
1920   case ARM64::LD4i32_POST:
1921   case ARM64::LD4i32:
1922     index = (Q << 1) | S;
1923     break;
1924   case ARM64::LD1i64:
1925   case ARM64::LD1i64_POST:
1926   case ARM64::LD2i64:
1927   case ARM64::LD2i64_POST:
1928   case ARM64::LD3i64_POST:
1929   case ARM64::LD3i64:
1930   case ARM64::LD4i64_POST:
1931   case ARM64::LD4i64:
1932     index = Q;
1933     break;
1934   }
1935
1936   switch (Inst.getOpcode()) {
1937   default:
1938     return Fail;
1939   case ARM64::LD1i8:
1940   case ARM64::LD1i8_POST:
1941   case ARM64::LD1i16:
1942   case ARM64::LD1i16_POST:
1943   case ARM64::LD1i32:
1944   case ARM64::LD1i32_POST:
1945   case ARM64::LD1i64:
1946   case ARM64::LD1i64_POST:
1947     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
1948     DecodeFPR128RegisterClass(Inst, Rt, Addr, Decoder);
1949     break;
1950   case ARM64::LD2i8:
1951   case ARM64::LD2i8_POST:
1952   case ARM64::LD2i16:
1953   case ARM64::LD2i16_POST:
1954   case ARM64::LD2i32:
1955   case ARM64::LD2i32_POST:
1956   case ARM64::LD2i64:
1957   case ARM64::LD2i64_POST:
1958     DecodeQQRegisterClass(Inst, Rt, Addr, Decoder);
1959     DecodeQQRegisterClass(Inst, Rt, Addr, Decoder);
1960     break;
1961   case ARM64::LD3i8:
1962   case ARM64::LD3i8_POST:
1963   case ARM64::LD3i16:
1964   case ARM64::LD3i16_POST:
1965   case ARM64::LD3i32:
1966   case ARM64::LD3i32_POST:
1967   case ARM64::LD3i64:
1968   case ARM64::LD3i64_POST:
1969     DecodeQQQRegisterClass(Inst, Rt, Addr, Decoder);
1970     DecodeQQQRegisterClass(Inst, Rt, Addr, Decoder);
1971     break;
1972   case ARM64::LD4i8:
1973   case ARM64::LD4i8_POST:
1974   case ARM64::LD4i16:
1975   case ARM64::LD4i16_POST:
1976   case ARM64::LD4i32:
1977   case ARM64::LD4i32_POST:
1978   case ARM64::LD4i64:
1979   case ARM64::LD4i64_POST:
1980     DecodeQQQQRegisterClass(Inst, Rt, Addr, Decoder);
1981     DecodeQQQQRegisterClass(Inst, Rt, Addr, Decoder);
1982     break;
1983   }
1984
1985   Inst.addOperand(MCOperand::CreateImm(index));
1986   DecodeGPR64spRegisterClass(Inst, Rn, Addr, Decoder);
1987
1988   switch (Inst.getOpcode()) {
1989   case ARM64::LD1i8_POST:
1990   case ARM64::LD1i16_POST:
1991   case ARM64::LD1i32_POST:
1992   case ARM64::LD1i64_POST:
1993   case ARM64::LD2i8_POST:
1994   case ARM64::LD2i16_POST:
1995   case ARM64::LD2i32_POST:
1996   case ARM64::LD2i64_POST:
1997   case ARM64::LD3i8_POST:
1998   case ARM64::LD3i16_POST:
1999   case ARM64::LD3i32_POST:
2000   case ARM64::LD3i64_POST:
2001   case ARM64::LD4i8_POST:
2002   case ARM64::LD4i16_POST:
2003   case ARM64::LD4i32_POST:
2004   case ARM64::LD4i64_POST:
2005     DecodeGPR64RegisterClass(Inst, Rm, Addr, Decoder);
2006     break;
2007   }
2008   return Success;
2009 }