1 //===- ARMDisassembler.cpp - Disassembler for ARM/Thumb ISA -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "arm-disassembler"
12 #include "ARMDisassembler.h"
14 #include "ARMRegisterInfo.h"
15 #include "MCTargetDesc/ARMAddressingModes.h"
16 #include "MCTargetDesc/ARMBaseInfo.h"
17 #include "llvm/MC/EDInstInfo.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/Target/TargetRegistry.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/MemoryObject.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/raw_ostream.h"
27 // Forward declare these because the autogenerated code will reference them.
28 // Definitions are further down.
29 static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
30 uint64_t Address, const void *Decoder);
31 static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
32 uint64_t Address, const void *Decoder);
33 static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
34 uint64_t Address, const void *Decoder);
35 static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
36 uint64_t Address, const void *Decoder);
37 static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
38 uint64_t Address, const void *Decoder);
39 static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
40 uint64_t Address, const void *Decoder);
41 static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
42 uint64_t Address, const void *Decoder);
43 static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
44 uint64_t Address, const void *Decoder);
45 static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
46 uint64_t Address, const void *Decoder);
47 static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
48 uint64_t Address, const void *Decoder);
50 static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
51 uint64_t Address, const void *Decoder);
52 static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
53 uint64_t Address, const void *Decoder);
54 static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
55 uint64_t Address, const void *Decoder);
56 static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
57 uint64_t Address, const void *Decoder);
58 static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
59 uint64_t Address, const void *Decoder);
60 static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
61 uint64_t Address, const void *Decoder);
62 static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
63 uint64_t Address, const void *Decoder);
65 static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Insn,
66 uint64_t Address, const void *Decoder);
67 static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
68 uint64_t Address, const void *Decoder);
69 static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
70 uint64_t Address, const void *Decoder);
71 static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Insn,
72 uint64_t Address, const void *Decoder);
73 static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
74 uint64_t Address, const void *Decoder);
75 static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Insn,
76 uint64_t Address, const void *Decoder);
77 static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Insn,
78 uint64_t Address, const void *Decoder);
80 static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst & Inst,
84 static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
85 uint64_t Address, const void *Decoder);
86 static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
87 uint64_t Address, const void *Decoder);
88 static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
89 uint64_t Address, const void *Decoder);
90 static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
91 uint64_t Address, const void *Decoder);
92 static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
93 uint64_t Address, const void *Decoder);
94 static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
95 uint64_t Address, const void *Decoder);
96 static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
97 uint64_t Address, const void *Decoder);
98 static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
99 uint64_t Address, const void *Decoder);
100 static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Val,
101 uint64_t Address, const void *Decoder);
102 static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Val,
103 uint64_t Address, const void *Decoder);
104 static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Val,
105 uint64_t Address, const void *Decoder);
106 static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Val,
107 uint64_t Address, const void *Decoder);
108 static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Val,
109 uint64_t Address, const void *Decoder);
110 static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Val,
111 uint64_t Address, const void *Decoder);
112 static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Val,
113 uint64_t Address, const void *Decoder);
114 static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Val,
115 uint64_t Address, const void *Decoder);
116 static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
117 uint64_t Address, const void *Decoder);
118 static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
119 uint64_t Address, const void *Decoder);
120 static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
121 uint64_t Address, const void *Decoder);
122 static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
123 uint64_t Address, const void *Decoder);
124 static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
125 uint64_t Address, const void *Decoder);
126 static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
127 uint64_t Address, const void *Decoder);
128 static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
129 uint64_t Address, const void *Decoder);
130 static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Insn,
131 uint64_t Address, const void *Decoder);
132 static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Insn,
133 uint64_t Address, const void *Decoder);
134 static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Insn,
135 uint64_t Address, const void *Decoder);
136 static bool DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
137 uint64_t Address, const void *Decoder);
138 static bool DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
139 uint64_t Address, const void *Decoder);
140 static bool DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
141 uint64_t Address, const void *Decoder);
142 static bool DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
143 uint64_t Address, const void *Decoder);
144 static bool DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
145 uint64_t Address, const void *Decoder);
146 static bool DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
147 uint64_t Address, const void *Decoder);
148 static bool DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
149 uint64_t Address, const void *Decoder);
150 static bool DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
151 uint64_t Address, const void *Decoder);
152 static bool DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
153 uint64_t Address, const void *Decoder);
154 static bool DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
155 uint64_t Address, const void *Decoder);
156 static bool DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
157 uint64_t Address, const void *Decoder);
158 static bool DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
159 uint64_t Address, const void *Decoder);
162 static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
163 uint64_t Address, const void *Decoder);
164 static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
165 uint64_t Address, const void *Decoder);
166 static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
167 uint64_t Address, const void *Decoder);
168 static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
169 uint64_t Address, const void *Decoder);
170 static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
171 uint64_t Address, const void *Decoder);
172 static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
173 uint64_t Address, const void *Decoder);
174 static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
175 uint64_t Address, const void *Decoder);
176 static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
177 uint64_t Address, const void *Decoder);
178 static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
179 uint64_t Address, const void *Decoder);
180 static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
181 uint64_t Address, const void *Decoder);
182 static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
183 uint64_t Address, const void *Decoder);
184 static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
185 uint64_t Address, const void *Decoder);
186 static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
187 uint64_t Address, const void *Decoder);
188 static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
189 uint64_t Address, const void *Decoder);
190 static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
191 uint64_t Address, const void *Decoder);
192 static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
193 uint64_t Address, const void *Decoder);
194 static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
195 uint64_t Address, const void *Decoder);
196 static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
197 uint64_t Address, const void *Decoder);
198 static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
199 uint64_t Address, const void *Decoder);
200 static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
201 uint64_t Address, const void *Decoder);
202 static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
203 uint64_t Address, const void *Decoder);
204 static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
205 uint64_t Address, const void *Decoder);
206 static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
207 uint64_t Address, const void *Decoder);
208 static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
209 uint64_t Address, const void *Decoder);
211 #include "ARMGenDisassemblerTables.inc"
212 #include "ARMGenInstrInfo.inc"
213 #include "ARMGenEDInfo.inc"
215 using namespace llvm;
217 static MCDisassembler *createARMDisassembler(const Target &T) {
218 return new ARMDisassembler;
221 static MCDisassembler *createThumbDisassembler(const Target &T) {
222 return new ThumbDisassembler;
225 EDInstInfo *ARMDisassembler::getEDInfo() const {
229 EDInstInfo *ThumbDisassembler::getEDInfo() const {
234 bool ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
235 const MemoryObject &Region,
236 uint64_t Address,raw_ostream &os) const {
239 // We want to read exactly 4 bytes of data.
240 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
243 // Encoded as a small-endian 32-bit word in the stream.
244 uint32_t insn = (bytes[3] << 24) |
249 // Calling the auto-generated decoder function.
250 bool result = decodeARMInstruction32(MI, insn, Address, this);
256 // Instructions that are shared between ARM and Thumb modes.
257 // FIXME: This shouldn't really exist. It's an artifact of the
258 // fact that we fail to encode a few instructions properly for Thumb.
260 result = decodeCommonInstruction32(MI, insn, Address, this);
266 // VFP and NEON instructions, similarly, are shared between ARM
269 result = decodeVFPInstruction32(MI, insn, Address, this);
276 result = decodeNEONDataInstruction32(MI, insn, Address, this);
279 // Add a fake predicate operand, because we share these instruction
280 // definitions with Thumb2 where these instructions are predicable.
281 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
286 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this);
289 // Add a fake predicate operand, because we share these instruction
290 // definitions with Thumb2 where these instructions are predicable.
291 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
296 result = decodeNEONDupInstruction32(MI, insn, Address, this);
299 // Add a fake predicate operand, because we share these instruction
300 // definitions with Thumb2 where these instructions are predicable.
301 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
311 extern MCInstrDesc ARMInsts[];
314 // Thumb1 instructions don't have explicit S bits. Rather, they
315 // implicitly set CPSR. Since it's not represented in the encoding, the
316 // auto-generated decoder won't inject the CPSR operand. We need to fix
317 // that as a post-pass.
318 static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
319 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
320 MCInst::iterator I = MI.begin();
321 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
322 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
323 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
328 if (OpInfo[MI.size()].isOptionalDef() &&
329 OpInfo[MI.size()].RegClass == ARM::CCRRegClassID)
330 MI.insert(MI.end(), MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
333 // Most Thumb instructions don't have explicit predicates in the
334 // encoding, but rather get their predicates from IT context. We need
335 // to fix up the predicate operands using this context information as a
337 void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
338 // A few instructions actually have predicates encoded in them. Don't
339 // try to overwrite it if we're seeing one of those.
340 switch (MI.getOpcode()) {
348 // If we're in an IT block, base the predicate on that. Otherwise,
349 // assume a predicate of AL.
351 if (!ITBlock.empty()) {
357 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
358 MCInst::iterator I = MI.begin();
359 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
360 if (OpInfo[i].isPredicate()) {
361 I = MI.insert(I, MCOperand::CreateImm(CC));
364 MI.insert(I, MCOperand::CreateReg(0));
366 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
371 MI.insert(MI.end(), MCOperand::CreateImm(CC));
373 MI.insert(MI.end(), MCOperand::CreateReg(0));
375 MI.insert(MI.end(), MCOperand::CreateReg(ARM::CPSR));
378 // Thumb VFP instructions are a special case. Because we share their
379 // encodings between ARM and Thumb modes, and they are predicable in ARM
380 // mode, the auto-generated decoder will give them an (incorrect)
381 // predicate operand. We need to rewrite these operands based on the IT
382 // context as a post-pass.
383 void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
385 if (!ITBlock.empty()) {
391 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
392 MCInst::iterator I = MI.begin();
393 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
394 if (OpInfo[i].isPredicate() ) {
400 I->setReg(ARM::CPSR);
407 bool ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
408 const MemoryObject &Region,
409 uint64_t Address,raw_ostream &os) const {
412 // We want to read exactly 2 bytes of data.
413 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
416 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
417 bool result = decodeThumbInstruction16(MI, insn16, Address, this);
420 AddThumbPredicate(MI);
425 result = decodeThumbSBitInstruction16(MI, insn16, Address, this);
428 bool InITBlock = !ITBlock.empty();
429 AddThumbPredicate(MI);
430 AddThumb1SBit(MI, InITBlock);
435 result = decodeThumb2Instruction16(MI, insn16, Address, this);
438 AddThumbPredicate(MI);
440 // If we find an IT instruction, we need to parse its condition
441 // code and mask operands so that we can apply them correctly
442 // to the subsequent instructions.
443 if (MI.getOpcode() == ARM::t2IT) {
444 unsigned firstcond = MI.getOperand(0).getImm();
445 uint32_t mask = MI.getOperand(1).getImm();
446 unsigned zeros = CountTrailingZeros_32(mask);
449 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
450 if (firstcond ^ (mask & 1))
451 ITBlock.push_back(firstcond ^ 1);
453 ITBlock.push_back(firstcond);
456 ITBlock.push_back(firstcond);
462 // We want to read exactly 4 bytes of data.
463 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
466 uint32_t insn32 = (bytes[3] << 8) |
471 result = decodeThumbInstruction32(MI, insn32, Address, this);
474 bool InITBlock = ITBlock.size();
475 AddThumbPredicate(MI);
476 AddThumb1SBit(MI, InITBlock);
481 result = decodeThumb2Instruction32(MI, insn32, Address, this);
484 AddThumbPredicate(MI);
489 result = decodeCommonInstruction32(MI, insn32, Address, this);
492 AddThumbPredicate(MI);
497 result = decodeVFPInstruction32(MI, insn32, Address, this);
500 UpdateThumbVFPPredicate(MI);
505 result = decodeNEONDupInstruction32(MI, insn32, Address, this);
508 AddThumbPredicate(MI);
512 if (fieldFromInstruction32(insn32, 24, 8) == 0xF9) {
514 uint32_t NEONLdStInsn = insn32;
515 NEONLdStInsn &= 0xF0FFFFFF;
516 NEONLdStInsn |= 0x04000000;
517 result = decodeNEONLoadStoreInstruction32(MI, NEONLdStInsn, Address, this);
520 AddThumbPredicate(MI);
525 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
527 uint32_t NEONDataInsn = insn32;
528 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
529 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
530 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
531 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this);
534 AddThumbPredicate(MI);
543 extern "C" void LLVMInitializeARMDisassembler() {
544 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
545 createARMDisassembler);
546 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
547 createThumbDisassembler);
550 static const unsigned GPRDecoderTable[] = {
551 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
552 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
553 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
554 ARM::R12, ARM::SP, ARM::LR, ARM::PC
557 static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
558 uint64_t Address, const void *Decoder) {
562 unsigned Register = GPRDecoderTable[RegNo];
563 Inst.addOperand(MCOperand::CreateReg(Register));
567 static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
568 uint64_t Address, const void *Decoder) {
569 if (RegNo == 15) return false;
570 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
573 static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
574 uint64_t Address, const void *Decoder) {
577 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
580 static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
581 uint64_t Address, const void *Decoder) {
582 unsigned Register = 0;
606 Inst.addOperand(MCOperand::CreateReg(Register));
610 static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
611 uint64_t Address, const void *Decoder) {
612 if (RegNo == 13 || RegNo == 15) return false;
613 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
616 static const unsigned SPRDecoderTable[] = {
617 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
618 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
619 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
620 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
621 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
622 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
623 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
624 ARM::S28, ARM::S29, ARM::S30, ARM::S31
627 static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
628 uint64_t Address, const void *Decoder) {
632 unsigned Register = SPRDecoderTable[RegNo];
633 Inst.addOperand(MCOperand::CreateReg(Register));
637 static const unsigned DPRDecoderTable[] = {
638 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
639 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
640 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
641 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
642 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
643 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
644 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
645 ARM::D28, ARM::D29, ARM::D30, ARM::D31
648 static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
649 uint64_t Address, const void *Decoder) {
653 unsigned Register = DPRDecoderTable[RegNo];
654 Inst.addOperand(MCOperand::CreateReg(Register));
658 static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
659 uint64_t Address, const void *Decoder) {
662 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
665 static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
666 uint64_t Address, const void *Decoder) {
669 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
672 static const unsigned QPRDecoderTable[] = {
673 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
674 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
675 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
676 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
680 static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
681 uint64_t Address, const void *Decoder) {
686 unsigned Register = QPRDecoderTable[RegNo];
687 Inst.addOperand(MCOperand::CreateReg(Register));
691 static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
692 uint64_t Address, const void *Decoder) {
693 if (Val == 0xF) return false;
694 // AL predicate is not allowed on Thumb1 branches.
695 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
697 Inst.addOperand(MCOperand::CreateImm(Val));
698 if (Val == ARMCC::AL) {
699 Inst.addOperand(MCOperand::CreateReg(0));
701 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
705 static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
706 uint64_t Address, const void *Decoder) {
708 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
710 Inst.addOperand(MCOperand::CreateReg(0));
714 static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
715 uint64_t Address, const void *Decoder) {
716 uint32_t imm = Val & 0xFF;
717 uint32_t rot = (Val & 0xF00) >> 7;
718 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
719 Inst.addOperand(MCOperand::CreateImm(rot_imm));
723 static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
724 uint64_t Address, const void *Decoder) {
726 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
730 static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
731 uint64_t Address, const void *Decoder) {
733 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
734 unsigned type = fieldFromInstruction32(Val, 5, 2);
735 unsigned imm = fieldFromInstruction32(Val, 7, 5);
737 // Register-immediate
738 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
740 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
756 if (Shift == ARM_AM::ror && imm == 0)
759 unsigned Op = Shift | (imm << 3);
760 Inst.addOperand(MCOperand::CreateImm(Op));
765 static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
766 uint64_t Address, const void *Decoder) {
768 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
769 unsigned type = fieldFromInstruction32(Val, 5, 2);
770 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
773 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
774 if (!DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder)) return false;
776 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
792 Inst.addOperand(MCOperand::CreateImm(Shift));
797 static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
798 uint64_t Address, const void *Decoder) {
799 // Empty register lists are not allowed.
800 if (CountPopulation_32(Val) == 0) return false;
801 for (unsigned i = 0; i < 16; ++i) {
802 if (Val & (1 << i)) {
803 if (!DecodeGPRRegisterClass(Inst, i, Address, Decoder)) return false;
810 static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
811 uint64_t Address, const void *Decoder) {
812 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
813 unsigned regs = Val & 0xFF;
815 if (!DecodeSPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
816 for (unsigned i = 0; i < (regs - 1); ++i) {
817 if (!DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
823 static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
824 uint64_t Address, const void *Decoder) {
825 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
826 unsigned regs = (Val & 0xFF) / 2;
828 if (!DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
829 for (unsigned i = 0; i < (regs - 1); ++i) {
830 if (!DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
836 static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
837 uint64_t Address, const void *Decoder) {
838 // This operand encodes a mask of contiguous zeros between a specified MSB
839 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
840 // the mask of all bits LSB-and-lower, and then xor them to create
841 // the mask of that's all ones on [msb, lsb]. Finally we not it to
842 // create the final mask.
843 unsigned msb = fieldFromInstruction32(Val, 5, 5);
844 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
845 uint32_t msb_mask = (1 << (msb+1)) - 1;
846 uint32_t lsb_mask = (1 << lsb) - 1;
847 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
851 static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
852 uint64_t Address, const void *Decoder) {
853 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
854 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
855 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
856 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
857 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
858 unsigned U = fieldFromInstruction32(Insn, 23, 1);
860 switch (Inst.getOpcode()) {
861 case ARM::LDC_OFFSET:
864 case ARM::LDC_OPTION:
865 case ARM::LDCL_OFFSET:
868 case ARM::LDCL_OPTION:
869 case ARM::STC_OFFSET:
872 case ARM::STC_OPTION:
873 case ARM::STCL_OFFSET:
876 case ARM::STCL_OPTION:
877 if (coproc == 0xA || coproc == 0xB)
884 Inst.addOperand(MCOperand::CreateImm(coproc));
885 Inst.addOperand(MCOperand::CreateImm(CRd));
886 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
887 switch (Inst.getOpcode()) {
888 case ARM::LDC_OPTION:
889 case ARM::LDCL_OPTION:
890 case ARM::LDC2_OPTION:
891 case ARM::LDC2L_OPTION:
892 case ARM::STC_OPTION:
893 case ARM::STCL_OPTION:
894 case ARM::STC2_OPTION:
895 case ARM::STC2L_OPTION:
900 Inst.addOperand(MCOperand::CreateReg(0));
904 unsigned P = fieldFromInstruction32(Insn, 24, 1);
905 unsigned W = fieldFromInstruction32(Insn, 21, 1);
907 bool writeback = (P == 0) || (W == 1);
908 unsigned idx_mode = 0;
910 idx_mode = ARMII::IndexModePre;
911 else if (!P && writeback)
912 idx_mode = ARMII::IndexModePost;
914 switch (Inst.getOpcode()) {
918 case ARM::LDC_OPTION:
919 case ARM::LDCL_OPTION:
920 case ARM::LDC2_OPTION:
921 case ARM::LDC2L_OPTION:
922 case ARM::STC_OPTION:
923 case ARM::STCL_OPTION:
924 case ARM::STC2_OPTION:
925 case ARM::STC2L_OPTION:
926 Inst.addOperand(MCOperand::CreateImm(imm));
930 Inst.addOperand(MCOperand::CreateImm(
931 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
933 Inst.addOperand(MCOperand::CreateImm(
934 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
938 switch (Inst.getOpcode()) {
939 case ARM::LDC_OFFSET:
942 case ARM::LDC_OPTION:
943 case ARM::LDCL_OFFSET:
946 case ARM::LDCL_OPTION:
947 case ARM::STC_OFFSET:
950 case ARM::STC_OPTION:
951 case ARM::STCL_OFFSET:
954 case ARM::STCL_OPTION:
955 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
964 static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
965 uint64_t Address, const void *Decoder) {
966 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
967 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
968 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
969 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
970 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
971 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
972 unsigned P = fieldFromInstruction32(Insn, 24, 1);
973 unsigned W = fieldFromInstruction32(Insn, 21, 1);
975 // On stores, the writeback operand precedes Rt.
976 switch (Inst.getOpcode()) {
977 case ARM::STR_POST_IMM:
978 case ARM::STR_POST_REG:
979 case ARM::STRB_POST_IMM:
980 case ARM::STRB_POST_REG:
981 case ARM::STRT_POST_REG:
982 case ARM::STRT_POST_IMM:
983 case ARM::STRBT_POST_REG:
984 case ARM::STRBT_POST_IMM:
985 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
991 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
993 // On loads, the writeback operand comes after Rt.
994 switch (Inst.getOpcode()) {
995 case ARM::LDR_POST_IMM:
996 case ARM::LDR_POST_REG:
997 case ARM::LDRB_POST_IMM:
998 case ARM::LDRB_POST_REG:
1001 case ARM::LDRBT_POST_REG:
1002 case ARM::LDRBT_POST_IMM:
1003 case ARM::LDRT_POST_REG:
1004 case ARM::LDRT_POST_IMM:
1005 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1012 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1014 ARM_AM::AddrOpc Op = ARM_AM::add;
1015 if (!fieldFromInstruction32(Insn, 23, 1))
1018 bool writeback = (P == 0) || (W == 1);
1019 unsigned idx_mode = 0;
1021 idx_mode = ARMII::IndexModePre;
1022 else if (!P && writeback)
1023 idx_mode = ARMII::IndexModePost;
1025 if (writeback && (Rn == 15 || Rn == Rt)) return false; // UNPREDICTABLE
1028 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
1029 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
1030 switch( fieldFromInstruction32(Insn, 5, 2)) {
1046 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1047 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1049 Inst.addOperand(MCOperand::CreateImm(imm));
1051 Inst.addOperand(MCOperand::CreateReg(0));
1052 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1053 Inst.addOperand(MCOperand::CreateImm(tmp));
1056 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1061 static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
1062 uint64_t Address, const void *Decoder) {
1063 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1064 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1065 unsigned type = fieldFromInstruction32(Val, 5, 2);
1066 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1067 unsigned U = fieldFromInstruction32(Val, 12, 1);
1069 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
1085 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1086 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1089 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1091 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1092 Inst.addOperand(MCOperand::CreateImm(shift));
1097 static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
1098 uint64_t Address, const void *Decoder) {
1099 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1100 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1101 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1102 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1103 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1104 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1105 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1106 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1107 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1109 bool writeback = (W == 1) | (P == 0);
1111 // For {LD,ST}RD, Rt must be even, else undefined.
1112 switch (Inst.getOpcode()) {
1115 case ARM::STRD_POST:
1118 case ARM::LDRD_POST:
1119 if (Rt & 0x1) return false;
1125 if (writeback) { // Writeback
1127 U |= ARMII::IndexModePre << 9;
1129 U |= ARMII::IndexModePost << 9;
1131 // On stores, the writeback operand precedes Rt.
1132 switch (Inst.getOpcode()) {
1135 case ARM::STRD_POST:
1138 case ARM::STRH_POST:
1139 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1147 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))
1149 switch (Inst.getOpcode()) {
1152 case ARM::STRD_POST:
1155 case ARM::LDRD_POST:
1156 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder))
1164 // On loads, the writeback operand comes after Rt.
1165 switch (Inst.getOpcode()) {
1168 case ARM::LDRD_POST:
1171 case ARM::LDRH_POST:
1173 case ARM::LDRSH_PRE:
1174 case ARM::LDRSH_POST:
1176 case ARM::LDRSB_PRE:
1177 case ARM::LDRSB_POST:
1180 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1188 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1192 Inst.addOperand(MCOperand::CreateReg(0));
1193 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1195 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1197 Inst.addOperand(MCOperand::CreateImm(U));
1200 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1205 static bool DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1206 uint64_t Address, const void *Decoder) {
1207 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1208 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1225 Inst.addOperand(MCOperand::CreateImm(mode));
1226 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1231 static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1233 uint64_t Address, const void *Decoder) {
1234 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1235 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1236 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1239 switch (Inst.getOpcode()) {
1241 Inst.setOpcode(ARM::RFEDA);
1243 case ARM::STMDA_UPD:
1244 Inst.setOpcode(ARM::RFEDA_UPD);
1247 Inst.setOpcode(ARM::RFEDB);
1249 case ARM::STMDB_UPD:
1250 Inst.setOpcode(ARM::RFEDB_UPD);
1253 Inst.setOpcode(ARM::RFEIA);
1255 case ARM::STMIA_UPD:
1256 Inst.setOpcode(ARM::RFEIA_UPD);
1259 Inst.setOpcode(ARM::RFEIB);
1261 case ARM::STMIB_UPD:
1262 Inst.setOpcode(ARM::RFEIB_UPD);
1265 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1268 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
1269 !DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) || // Tied
1270 !DecodePredicateOperand(Inst, pred, Address, Decoder) ||
1271 !DecodeRegListOperand(Inst, reglist, Address, Decoder))
1277 static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1278 uint64_t Address, const void *Decoder) {
1279 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1280 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1281 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1282 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1284 // imod == '01' --> UNPREDICTABLE
1285 if (imod == 1) return false;
1287 if (M && mode && imod && iflags) {
1288 Inst.setOpcode(ARM::CPS3p);
1289 Inst.addOperand(MCOperand::CreateImm(imod));
1290 Inst.addOperand(MCOperand::CreateImm(iflags));
1291 Inst.addOperand(MCOperand::CreateImm(mode));
1293 } else if (!mode && !M) {
1294 Inst.setOpcode(ARM::CPS2p);
1295 Inst.addOperand(MCOperand::CreateImm(imod));
1296 Inst.addOperand(MCOperand::CreateImm(iflags));
1298 } else if (!imod && !iflags && M) {
1299 Inst.setOpcode(ARM::CPS1p);
1300 Inst.addOperand(MCOperand::CreateImm(mode));
1307 static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1308 uint64_t Address, const void *Decoder) {
1309 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1310 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1311 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1312 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1313 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1316 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1318 if (!DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder) ||
1319 !DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder) ||
1320 !DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder) ||
1321 !DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder))
1324 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1329 static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1330 uint64_t Address, const void *Decoder) {
1331 unsigned add = fieldFromInstruction32(Val, 12, 1);
1332 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1333 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1335 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1338 if (!add) imm *= -1;
1339 if (imm == 0 && !add) imm = INT32_MIN;
1340 Inst.addOperand(MCOperand::CreateImm(imm));
1345 static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1346 uint64_t Address, const void *Decoder) {
1347 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1348 unsigned U = fieldFromInstruction32(Val, 8, 1);
1349 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1351 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1355 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1357 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1362 static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1363 uint64_t Address, const void *Decoder) {
1364 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1367 static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1368 uint64_t Address, const void *Decoder) {
1369 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1370 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1373 Inst.setOpcode(ARM::BLXi);
1374 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
1375 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1379 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1380 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1386 static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1387 uint64_t Address, const void *Decoder) {
1388 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1392 static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1393 uint64_t Address, const void *Decoder) {
1394 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1395 unsigned align = fieldFromInstruction32(Val, 4, 2);
1397 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1400 Inst.addOperand(MCOperand::CreateImm(0));
1402 Inst.addOperand(MCOperand::CreateImm(4 << align));
1407 static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1408 uint64_t Address, const void *Decoder) {
1409 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1410 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1411 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1412 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1413 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1414 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1416 // First output register
1417 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1419 // Second output register
1420 switch (Inst.getOpcode()) {
1425 case ARM::VLD1q8_UPD:
1426 case ARM::VLD1q16_UPD:
1427 case ARM::VLD1q32_UPD:
1428 case ARM::VLD1q64_UPD:
1433 case ARM::VLD1d8T_UPD:
1434 case ARM::VLD1d16T_UPD:
1435 case ARM::VLD1d32T_UPD:
1436 case ARM::VLD1d64T_UPD:
1441 case ARM::VLD1d8Q_UPD:
1442 case ARM::VLD1d16Q_UPD:
1443 case ARM::VLD1d32Q_UPD:
1444 case ARM::VLD1d64Q_UPD:
1448 case ARM::VLD2d8_UPD:
1449 case ARM::VLD2d16_UPD:
1450 case ARM::VLD2d32_UPD:
1454 case ARM::VLD2q8_UPD:
1455 case ARM::VLD2q16_UPD:
1456 case ARM::VLD2q32_UPD:
1460 case ARM::VLD3d8_UPD:
1461 case ARM::VLD3d16_UPD:
1462 case ARM::VLD3d32_UPD:
1466 case ARM::VLD4d8_UPD:
1467 case ARM::VLD4d16_UPD:
1468 case ARM::VLD4d32_UPD:
1469 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1474 case ARM::VLD2b8_UPD:
1475 case ARM::VLD2b16_UPD:
1476 case ARM::VLD2b32_UPD:
1480 case ARM::VLD3q8_UPD:
1481 case ARM::VLD3q16_UPD:
1482 case ARM::VLD3q32_UPD:
1486 case ARM::VLD4q8_UPD:
1487 case ARM::VLD4q16_UPD:
1488 case ARM::VLD4q32_UPD:
1489 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1494 // Third output register
1495 switch(Inst.getOpcode()) {
1500 case ARM::VLD1d8T_UPD:
1501 case ARM::VLD1d16T_UPD:
1502 case ARM::VLD1d32T_UPD:
1503 case ARM::VLD1d64T_UPD:
1508 case ARM::VLD1d8Q_UPD:
1509 case ARM::VLD1d16Q_UPD:
1510 case ARM::VLD1d32Q_UPD:
1511 case ARM::VLD1d64Q_UPD:
1515 case ARM::VLD2q8_UPD:
1516 case ARM::VLD2q16_UPD:
1517 case ARM::VLD2q32_UPD:
1521 case ARM::VLD3d8_UPD:
1522 case ARM::VLD3d16_UPD:
1523 case ARM::VLD3d32_UPD:
1527 case ARM::VLD4d8_UPD:
1528 case ARM::VLD4d16_UPD:
1529 case ARM::VLD4d32_UPD:
1530 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1535 case ARM::VLD3q8_UPD:
1536 case ARM::VLD3q16_UPD:
1537 case ARM::VLD3q32_UPD:
1541 case ARM::VLD4q8_UPD:
1542 case ARM::VLD4q16_UPD:
1543 case ARM::VLD4q32_UPD:
1544 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
1550 // Fourth output register
1551 switch (Inst.getOpcode()) {
1556 case ARM::VLD1d8Q_UPD:
1557 case ARM::VLD1d16Q_UPD:
1558 case ARM::VLD1d32Q_UPD:
1559 case ARM::VLD1d64Q_UPD:
1563 case ARM::VLD2q8_UPD:
1564 case ARM::VLD2q16_UPD:
1565 case ARM::VLD2q32_UPD:
1569 case ARM::VLD4d8_UPD:
1570 case ARM::VLD4d16_UPD:
1571 case ARM::VLD4d32_UPD:
1572 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
1577 case ARM::VLD4q8_UPD:
1578 case ARM::VLD4q16_UPD:
1579 case ARM::VLD4q32_UPD:
1580 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
1586 // Writeback operand
1587 switch (Inst.getOpcode()) {
1588 case ARM::VLD1d8_UPD:
1589 case ARM::VLD1d16_UPD:
1590 case ARM::VLD1d32_UPD:
1591 case ARM::VLD1d64_UPD:
1592 case ARM::VLD1q8_UPD:
1593 case ARM::VLD1q16_UPD:
1594 case ARM::VLD1q32_UPD:
1595 case ARM::VLD1q64_UPD:
1596 case ARM::VLD1d8T_UPD:
1597 case ARM::VLD1d16T_UPD:
1598 case ARM::VLD1d32T_UPD:
1599 case ARM::VLD1d64T_UPD:
1600 case ARM::VLD1d8Q_UPD:
1601 case ARM::VLD1d16Q_UPD:
1602 case ARM::VLD1d32Q_UPD:
1603 case ARM::VLD1d64Q_UPD:
1604 case ARM::VLD2d8_UPD:
1605 case ARM::VLD2d16_UPD:
1606 case ARM::VLD2d32_UPD:
1607 case ARM::VLD2q8_UPD:
1608 case ARM::VLD2q16_UPD:
1609 case ARM::VLD2q32_UPD:
1610 case ARM::VLD2b8_UPD:
1611 case ARM::VLD2b16_UPD:
1612 case ARM::VLD2b32_UPD:
1613 case ARM::VLD3d8_UPD:
1614 case ARM::VLD3d16_UPD:
1615 case ARM::VLD3d32_UPD:
1616 case ARM::VLD3q8_UPD:
1617 case ARM::VLD3q16_UPD:
1618 case ARM::VLD3q32_UPD:
1619 case ARM::VLD4d8_UPD:
1620 case ARM::VLD4d16_UPD:
1621 case ARM::VLD4d32_UPD:
1622 case ARM::VLD4q8_UPD:
1623 case ARM::VLD4q16_UPD:
1624 case ARM::VLD4q32_UPD:
1625 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder)) return false;
1631 // AddrMode6 Base (register+alignment)
1632 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
1634 // AddrMode6 Offset (register)
1636 Inst.addOperand(MCOperand::CreateReg(0));
1637 else if (Rm != 0xF) {
1638 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1645 static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1646 uint64_t Address, const void *Decoder) {
1647 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1648 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1649 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1650 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1651 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1652 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1654 // Writeback Operand
1655 switch (Inst.getOpcode()) {
1656 case ARM::VST1d8_UPD:
1657 case ARM::VST1d16_UPD:
1658 case ARM::VST1d32_UPD:
1659 case ARM::VST1d64_UPD:
1660 case ARM::VST1q8_UPD:
1661 case ARM::VST1q16_UPD:
1662 case ARM::VST1q32_UPD:
1663 case ARM::VST1q64_UPD:
1664 case ARM::VST1d8T_UPD:
1665 case ARM::VST1d16T_UPD:
1666 case ARM::VST1d32T_UPD:
1667 case ARM::VST1d64T_UPD:
1668 case ARM::VST1d8Q_UPD:
1669 case ARM::VST1d16Q_UPD:
1670 case ARM::VST1d32Q_UPD:
1671 case ARM::VST1d64Q_UPD:
1672 case ARM::VST2d8_UPD:
1673 case ARM::VST2d16_UPD:
1674 case ARM::VST2d32_UPD:
1675 case ARM::VST2q8_UPD:
1676 case ARM::VST2q16_UPD:
1677 case ARM::VST2q32_UPD:
1678 case ARM::VST2b8_UPD:
1679 case ARM::VST2b16_UPD:
1680 case ARM::VST2b32_UPD:
1681 case ARM::VST3d8_UPD:
1682 case ARM::VST3d16_UPD:
1683 case ARM::VST3d32_UPD:
1684 case ARM::VST3q8_UPD:
1685 case ARM::VST3q16_UPD:
1686 case ARM::VST3q32_UPD:
1687 case ARM::VST4d8_UPD:
1688 case ARM::VST4d16_UPD:
1689 case ARM::VST4d32_UPD:
1690 case ARM::VST4q8_UPD:
1691 case ARM::VST4q16_UPD:
1692 case ARM::VST4q32_UPD:
1693 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder))
1700 // AddrMode6 Base (register+alignment)
1701 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
1703 // AddrMode6 Offset (register)
1705 Inst.addOperand(MCOperand::CreateReg(0));
1706 else if (Rm != 0xF) {
1707 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1710 // First input register
1711 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1713 // Second input register
1714 switch (Inst.getOpcode()) {
1719 case ARM::VST1q8_UPD:
1720 case ARM::VST1q16_UPD:
1721 case ARM::VST1q32_UPD:
1722 case ARM::VST1q64_UPD:
1727 case ARM::VST1d8T_UPD:
1728 case ARM::VST1d16T_UPD:
1729 case ARM::VST1d32T_UPD:
1730 case ARM::VST1d64T_UPD:
1735 case ARM::VST1d8Q_UPD:
1736 case ARM::VST1d16Q_UPD:
1737 case ARM::VST1d32Q_UPD:
1738 case ARM::VST1d64Q_UPD:
1742 case ARM::VST2d8_UPD:
1743 case ARM::VST2d16_UPD:
1744 case ARM::VST2d32_UPD:
1748 case ARM::VST2q8_UPD:
1749 case ARM::VST2q16_UPD:
1750 case ARM::VST2q32_UPD:
1754 case ARM::VST3d8_UPD:
1755 case ARM::VST3d16_UPD:
1756 case ARM::VST3d32_UPD:
1760 case ARM::VST4d8_UPD:
1761 case ARM::VST4d16_UPD:
1762 case ARM::VST4d32_UPD:
1763 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1768 case ARM::VST2b8_UPD:
1769 case ARM::VST2b16_UPD:
1770 case ARM::VST2b32_UPD:
1774 case ARM::VST3q8_UPD:
1775 case ARM::VST3q16_UPD:
1776 case ARM::VST3q32_UPD:
1780 case ARM::VST4q8_UPD:
1781 case ARM::VST4q16_UPD:
1782 case ARM::VST4q32_UPD:
1783 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1789 // Third input register
1790 switch (Inst.getOpcode()) {
1795 case ARM::VST1d8T_UPD:
1796 case ARM::VST1d16T_UPD:
1797 case ARM::VST1d32T_UPD:
1798 case ARM::VST1d64T_UPD:
1803 case ARM::VST1d8Q_UPD:
1804 case ARM::VST1d16Q_UPD:
1805 case ARM::VST1d32Q_UPD:
1806 case ARM::VST1d64Q_UPD:
1810 case ARM::VST2q8_UPD:
1811 case ARM::VST2q16_UPD:
1812 case ARM::VST2q32_UPD:
1816 case ARM::VST3d8_UPD:
1817 case ARM::VST3d16_UPD:
1818 case ARM::VST3d32_UPD:
1822 case ARM::VST4d8_UPD:
1823 case ARM::VST4d16_UPD:
1824 case ARM::VST4d32_UPD:
1825 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1830 case ARM::VST3q8_UPD:
1831 case ARM::VST3q16_UPD:
1832 case ARM::VST3q32_UPD:
1836 case ARM::VST4q8_UPD:
1837 case ARM::VST4q16_UPD:
1838 case ARM::VST4q32_UPD:
1839 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
1845 // Fourth input register
1846 switch (Inst.getOpcode()) {
1851 case ARM::VST1d8Q_UPD:
1852 case ARM::VST1d16Q_UPD:
1853 case ARM::VST1d32Q_UPD:
1854 case ARM::VST1d64Q_UPD:
1858 case ARM::VST2q8_UPD:
1859 case ARM::VST2q16_UPD:
1860 case ARM::VST2q32_UPD:
1864 case ARM::VST4d8_UPD:
1865 case ARM::VST4d16_UPD:
1866 case ARM::VST4d32_UPD:
1867 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
1872 case ARM::VST4q8_UPD:
1873 case ARM::VST4q16_UPD:
1874 case ARM::VST4q32_UPD:
1875 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
1884 static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1885 uint64_t Address, const void *Decoder) {
1886 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1887 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1888 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1889 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1890 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1891 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1892 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
1894 align *= (1 << size);
1896 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1898 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1901 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1904 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1905 Inst.addOperand(MCOperand::CreateImm(align));
1908 Inst.addOperand(MCOperand::CreateReg(0));
1909 else if (Rm != 0xF) {
1910 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1916 static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1917 uint64_t Address, const void *Decoder) {
1918 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1919 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1920 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1921 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1922 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1923 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
1924 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1927 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1928 if (!DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)) return false;
1930 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1933 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1934 Inst.addOperand(MCOperand::CreateImm(align));
1937 Inst.addOperand(MCOperand::CreateReg(0));
1938 else if (Rm != 0xF) {
1939 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1945 static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1946 uint64_t Address, const void *Decoder) {
1947 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1948 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1949 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1950 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1951 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1953 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1954 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1955 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder))
1958 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1961 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1962 Inst.addOperand(MCOperand::CreateImm(0));
1965 Inst.addOperand(MCOperand::CreateReg(0));
1966 else if (Rm != 0xF) {
1967 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1973 static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1974 uint64_t Address, const void *Decoder) {
1975 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1976 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1977 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1978 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1979 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1980 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1981 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1996 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1997 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1998 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder) ||
1999 !DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder))
2002 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2005 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2006 Inst.addOperand(MCOperand::CreateImm(align));
2009 Inst.addOperand(MCOperand::CreateReg(0));
2010 else if (Rm != 0xF) {
2011 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2017 static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
2018 uint64_t Address, const void *Decoder) {
2019 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2020 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2021 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2022 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
2023 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
2024 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
2025 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
2026 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
2029 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2031 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2034 Inst.addOperand(MCOperand::CreateImm(imm));
2036 switch (Inst.getOpcode()) {
2037 case ARM::VORRiv4i16:
2038 case ARM::VORRiv2i32:
2039 case ARM::VBICiv4i16:
2040 case ARM::VBICiv2i32:
2041 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2043 case ARM::VORRiv8i16:
2044 case ARM::VORRiv4i32:
2045 case ARM::VBICiv8i16:
2046 case ARM::VBICiv4i32:
2047 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2056 static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
2057 uint64_t Address, const void *Decoder) {
2058 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2059 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2060 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2061 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2062 unsigned size = fieldFromInstruction32(Insn, 18, 2);
2064 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2065 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2066 Inst.addOperand(MCOperand::CreateImm(8 << size));
2071 static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
2072 uint64_t Address, const void *Decoder) {
2073 Inst.addOperand(MCOperand::CreateImm(8 - Val));
2077 static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
2078 uint64_t Address, const void *Decoder) {
2079 Inst.addOperand(MCOperand::CreateImm(16 - Val));
2083 static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
2084 uint64_t Address, const void *Decoder) {
2085 Inst.addOperand(MCOperand::CreateImm(32 - Val));
2089 static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
2090 uint64_t Address, const void *Decoder) {
2091 Inst.addOperand(MCOperand::CreateImm(64 - Val));
2095 static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
2096 uint64_t Address, const void *Decoder) {
2097 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2098 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2099 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2100 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2101 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2102 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2103 unsigned op = fieldFromInstruction32(Insn, 6, 1);
2104 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
2106 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2108 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false; // Writeback
2111 for (unsigned i = 0; i < length; ++i) {
2112 if (!DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder)) return false;
2115 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2120 static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
2121 uint64_t Address, const void *Decoder) {
2122 // The immediate needs to be a fully instantiated float. However, the
2123 // auto-generated decoder is only able to fill in some of the bits
2124 // necessary. For instance, the 'b' bit is replicated multiple times,
2125 // and is even present in inverted form in one bit. We do a little
2126 // binary parsing here to fill in those missing bits, and then
2127 // reinterpret it all as a float.
2133 fp_conv.integer = Val;
2134 uint32_t b = fieldFromInstruction32(Val, 25, 1);
2135 fp_conv.integer |= b << 26;
2136 fp_conv.integer |= b << 27;
2137 fp_conv.integer |= b << 28;
2138 fp_conv.integer |= b << 29;
2139 fp_conv.integer |= (~b & 0x1) << 30;
2141 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
2145 static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
2146 uint64_t Address, const void *Decoder) {
2147 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2148 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2150 if (!DecodetGPRRegisterClass(Inst, dst, Address, Decoder)) return false;
2152 if (Inst.getOpcode() == ARM::tADR)
2153 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2154 else if (Inst.getOpcode() == ARM::tADDrSPi)
2155 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2159 Inst.addOperand(MCOperand::CreateImm(imm));
2163 static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
2164 uint64_t Address, const void *Decoder) {
2165 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
2169 static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
2170 uint64_t Address, const void *Decoder) {
2171 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2175 static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2176 uint64_t Address, const void *Decoder) {
2177 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2181 static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2182 uint64_t Address, const void *Decoder) {
2183 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2184 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2186 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2187 !DecodetGPRRegisterClass(Inst, Rm, Address, Decoder))
2193 static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2194 uint64_t Address, const void *Decoder) {
2195 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2196 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2198 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2199 Inst.addOperand(MCOperand::CreateImm(imm));
2204 static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2205 uint64_t Address, const void *Decoder) {
2206 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2211 static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2212 uint64_t Address, const void *Decoder) {
2213 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2214 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2219 static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2220 uint64_t Address, const void *Decoder) {
2221 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2222 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2223 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2225 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2226 !DecoderGPRRegisterClass(Inst, Rm, Address, Decoder))
2228 Inst.addOperand(MCOperand::CreateImm(imm));
2233 static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2234 uint64_t Address, const void *Decoder) {
2235 if (Inst.getOpcode() != ARM::t2PLDs) {
2236 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2237 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2240 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2242 switch (Inst.getOpcode()) {
2244 Inst.setOpcode(ARM::t2LDRBpci);
2247 Inst.setOpcode(ARM::t2LDRHpci);
2250 Inst.setOpcode(ARM::t2LDRSHpci);
2253 Inst.setOpcode(ARM::t2LDRSBpci);
2256 Inst.setOpcode(ARM::t2PLDi12);
2257 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2263 int imm = fieldFromInstruction32(Insn, 0, 12);
2264 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2265 Inst.addOperand(MCOperand::CreateImm(imm));
2270 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2271 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2272 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2273 DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder);
2278 static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
2279 uint64_t Address, const void *Decoder) {
2280 int imm = Val & 0xFF;
2281 if (!(Val & 0x100)) imm *= -1;
2282 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2287 static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2288 uint64_t Address, const void *Decoder) {
2289 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2290 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2292 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2293 !DecodeT2Imm8S4(Inst, imm, Address, Decoder))
2299 static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
2300 uint64_t Address, const void *Decoder) {
2301 int imm = Val & 0xFF;
2302 if (!(Val & 0x100)) imm *= -1;
2303 Inst.addOperand(MCOperand::CreateImm(imm));
2309 static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
2310 uint64_t Address, const void *Decoder) {
2311 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2312 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2314 // Some instructions always use an additive offset.
2315 switch (Inst.getOpcode()) {
2327 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2328 !DecodeT2Imm8(Inst, imm, Address, Decoder))
2335 static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
2336 uint64_t Address, const void *Decoder) {
2337 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2338 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2340 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2341 Inst.addOperand(MCOperand::CreateImm(imm));
2347 static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
2348 uint64_t Address, const void *Decoder) {
2349 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2351 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2352 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2353 Inst.addOperand(MCOperand::CreateImm(imm));
2358 static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
2359 uint64_t Address, const void *Decoder) {
2360 if (Inst.getOpcode() == ARM::tADDrSP) {
2361 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2362 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2364 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
2365 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2366 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
2367 } else if (Inst.getOpcode() == ARM::tADDspr) {
2368 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2370 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2371 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2372 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2378 static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
2379 uint64_t Address, const void *Decoder) {
2380 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2381 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2383 Inst.addOperand(MCOperand::CreateImm(imod));
2384 Inst.addOperand(MCOperand::CreateImm(flags));
2389 static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
2390 uint64_t Address, const void *Decoder) {
2391 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2392 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2394 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2395 Inst.addOperand(MCOperand::CreateImm(add));
2400 static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
2401 uint64_t Address, const void *Decoder) {
2402 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2406 static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2407 uint64_t Address, const void *Decoder) {
2408 if (Val == 0xA || Val == 0xB)
2411 Inst.addOperand(MCOperand::CreateImm(Val));
2415 static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
2416 uint64_t Address, const void *Decoder) {
2418 Inst.addOperand(MCOperand::CreateImm(32));
2420 Inst.addOperand(MCOperand::CreateImm(Val));
2424 static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2425 uint64_t Address, const void *Decoder) {
2426 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2427 if (pred == 0xE || pred == 0xF) {
2428 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2433 Inst.setOpcode(ARM::t2DSB);
2436 Inst.setOpcode(ARM::t2DMB);
2439 Inst.setOpcode(ARM::t2ISB);
2443 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2444 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
2447 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2448 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2449 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2450 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2451 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2453 if (!DecodeT2BROperand(Inst, brtarget, Address, Decoder) ||
2454 !DecodePredicateOperand(Inst, pred, Address, Decoder))
2460 // Decode a shifted immediate operand. These basically consist
2461 // of an 8-bit value, and a 4-bit directive that specifies either
2462 // a splat operation or a rotation.
2463 static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2464 uint64_t Address, const void *Decoder) {
2465 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2467 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2468 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2471 Inst.addOperand(MCOperand::CreateImm(imm));
2474 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2477 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2480 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2485 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2486 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2487 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2488 Inst.addOperand(MCOperand::CreateImm(imm));
2494 static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2495 uint64_t Address, const void *Decoder){
2496 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2500 static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
2501 uint64_t Address, const void *Decoder){
2502 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2506 static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Val,
2507 uint64_t Address, const void *Decoder) {
2522 Inst.addOperand(MCOperand::CreateImm(Val));
2526 static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Val,
2527 uint64_t Address, const void *Decoder) {
2528 if (!Val) return false;
2529 Inst.addOperand(MCOperand::CreateImm(Val));
2533 static bool DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
2534 uint64_t Address, const void *Decoder) {
2535 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2536 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2537 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2539 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return false;
2541 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2542 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)) return false;
2543 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2544 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2550 static bool DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
2551 uint64_t Address, const void *Decoder) {
2552 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2553 unsigned Rt = fieldFromInstruction32(Insn, 0, 4);
2554 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2555 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2557 if (!DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2559 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return false;
2560 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return false;
2562 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2563 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)) return false;
2564 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2565 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2570 static bool DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
2571 uint64_t Address, const void *Decoder) {
2572 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2573 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2574 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2575 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2576 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2577 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2579 if (Rn == 0xF || Rn == Rt) return false; // UNPREDICTABLE
2581 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2582 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2583 if (!DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder)) return false;
2584 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2589 static bool DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
2590 uint64_t Address, const void *Decoder) {
2591 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2592 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2593 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2594 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2595 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2596 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2598 if (Rn == 0xF || Rn == Rt) return false; // UNPREDICTABLE
2600 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2601 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2602 if (!DecodeSORegMemOperand(Inst, imm, Address, Decoder)) return false;
2603 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2608 static bool DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
2609 uint64_t Address, const void *Decoder) {
2610 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2611 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2612 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2613 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2614 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2622 if (fieldFromInstruction32(Insn, 4, 1))
2623 return false; // UNDEFINED
2624 index = fieldFromInstruction32(Insn, 5, 3);
2627 if (fieldFromInstruction32(Insn, 5, 1))
2628 return false; // UNDEFINED
2629 index = fieldFromInstruction32(Insn, 6, 2);
2630 if (fieldFromInstruction32(Insn, 4, 1))
2634 if (fieldFromInstruction32(Insn, 6, 1))
2635 return false; // UNDEFINED
2636 index = fieldFromInstruction32(Insn, 7, 1);
2637 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2641 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2642 if (Rm != 0xF) { // Writeback
2643 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2646 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2647 Inst.addOperand(MCOperand::CreateImm(align));
2648 if (Rm != 0xF && Rm != 0xD) {
2649 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2653 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2654 Inst.addOperand(MCOperand::CreateImm(index));
2659 static bool DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
2660 uint64_t Address, const void *Decoder) {
2661 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2662 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2663 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2664 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2665 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2673 if (fieldFromInstruction32(Insn, 4, 1))
2674 return false; // UNDEFINED
2675 index = fieldFromInstruction32(Insn, 5, 3);
2678 if (fieldFromInstruction32(Insn, 5, 1))
2679 return false; // UNDEFINED
2680 index = fieldFromInstruction32(Insn, 6, 2);
2681 if (fieldFromInstruction32(Insn, 4, 1))
2685 if (fieldFromInstruction32(Insn, 6, 1))
2686 return false; // UNDEFINED
2687 index = fieldFromInstruction32(Insn, 7, 1);
2688 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2692 if (Rm != 0xF) { // Writeback
2693 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2696 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2697 Inst.addOperand(MCOperand::CreateImm(align));
2698 if (Rm != 0xF && Rm != 0xD) {
2699 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2703 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2704 Inst.addOperand(MCOperand::CreateImm(index));
2710 static bool DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
2711 uint64_t Address, const void *Decoder) {
2712 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2713 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2714 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2715 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2716 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2725 index = fieldFromInstruction32(Insn, 5, 3);
2726 if (fieldFromInstruction32(Insn, 4, 1))
2730 index = fieldFromInstruction32(Insn, 6, 2);
2731 if (fieldFromInstruction32(Insn, 4, 1))
2733 if (fieldFromInstruction32(Insn, 5, 1))
2737 if (fieldFromInstruction32(Insn, 5, 1))
2738 return false; // UNDEFINED
2739 index = fieldFromInstruction32(Insn, 7, 1);
2740 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2742 if (fieldFromInstruction32(Insn, 6, 1))
2747 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2748 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2749 if (Rm != 0xF) { // Writeback
2750 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2753 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2754 Inst.addOperand(MCOperand::CreateImm(align));
2755 if (Rm != 0xF && Rm != 0xD) {
2756 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2760 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2761 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2762 Inst.addOperand(MCOperand::CreateImm(index));
2767 static bool DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
2768 uint64_t Address, const void *Decoder) {
2769 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2770 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2771 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2772 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2773 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2782 index = fieldFromInstruction32(Insn, 5, 3);
2783 if (fieldFromInstruction32(Insn, 4, 1))
2787 index = fieldFromInstruction32(Insn, 6, 2);
2788 if (fieldFromInstruction32(Insn, 4, 1))
2790 if (fieldFromInstruction32(Insn, 5, 1))
2794 if (fieldFromInstruction32(Insn, 5, 1))
2795 return false; // UNDEFINED
2796 index = fieldFromInstruction32(Insn, 7, 1);
2797 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2799 if (fieldFromInstruction32(Insn, 6, 1))
2804 if (Rm != 0xF) { // Writeback
2805 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2808 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2809 Inst.addOperand(MCOperand::CreateImm(align));
2810 if (Rm != 0xF && Rm != 0xD) {
2811 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2815 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2816 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2817 Inst.addOperand(MCOperand::CreateImm(index));
2823 static bool DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
2824 uint64_t Address, const void *Decoder) {
2825 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2826 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2827 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2828 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2829 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2838 if (fieldFromInstruction32(Insn, 4, 1))
2839 return false; // UNDEFINED
2840 index = fieldFromInstruction32(Insn, 5, 3);
2843 if (fieldFromInstruction32(Insn, 4, 1))
2844 return false; // UNDEFINED
2845 index = fieldFromInstruction32(Insn, 6, 2);
2846 if (fieldFromInstruction32(Insn, 5, 1))
2850 if (fieldFromInstruction32(Insn, 4, 2))
2851 return false; // UNDEFINED
2852 index = fieldFromInstruction32(Insn, 7, 1);
2853 if (fieldFromInstruction32(Insn, 6, 1))
2858 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2859 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2860 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2862 if (Rm != 0xF) { // Writeback
2863 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2866 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2867 Inst.addOperand(MCOperand::CreateImm(align));
2868 if (Rm != 0xF && Rm != 0xD) {
2869 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2873 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2874 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2875 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2876 Inst.addOperand(MCOperand::CreateImm(index));
2881 static bool DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
2882 uint64_t Address, const void *Decoder) {
2883 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2884 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2885 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2886 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2887 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2896 if (fieldFromInstruction32(Insn, 4, 1))
2897 return false; // UNDEFINED
2898 index = fieldFromInstruction32(Insn, 5, 3);
2901 if (fieldFromInstruction32(Insn, 4, 1))
2902 return false; // UNDEFINED
2903 index = fieldFromInstruction32(Insn, 6, 2);
2904 if (fieldFromInstruction32(Insn, 5, 1))
2908 if (fieldFromInstruction32(Insn, 4, 2))
2909 return false; // UNDEFINED
2910 index = fieldFromInstruction32(Insn, 7, 1);
2911 if (fieldFromInstruction32(Insn, 6, 1))
2916 if (Rm != 0xF) { // Writeback
2917 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2920 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2921 Inst.addOperand(MCOperand::CreateImm(align));
2922 if (Rm != 0xF && Rm != 0xD) {
2923 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2927 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2928 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2929 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2930 Inst.addOperand(MCOperand::CreateImm(index));
2936 static bool DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
2937 uint64_t Address, const void *Decoder) {
2938 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2939 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2940 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2941 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2942 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2951 if (fieldFromInstruction32(Insn, 4, 1))
2953 index = fieldFromInstruction32(Insn, 5, 3);
2956 if (fieldFromInstruction32(Insn, 4, 1))
2958 index = fieldFromInstruction32(Insn, 6, 2);
2959 if (fieldFromInstruction32(Insn, 5, 1))
2963 if (fieldFromInstruction32(Insn, 4, 2))
2964 align = 4 << fieldFromInstruction32(Insn, 4, 2);
2965 index = fieldFromInstruction32(Insn, 7, 1);
2966 if (fieldFromInstruction32(Insn, 6, 1))
2971 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2972 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2973 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2974 if (!DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)) return false;
2976 if (Rm != 0xF) { // Writeback
2977 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2980 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2981 Inst.addOperand(MCOperand::CreateImm(align));
2982 if (Rm != 0xF && Rm != 0xD) {
2983 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2987 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2988 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2989 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2990 if (!DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)) return false;
2991 Inst.addOperand(MCOperand::CreateImm(index));
2996 static bool DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
2997 uint64_t Address, const void *Decoder) {
2998 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2999 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3000 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3001 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3002 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3011 if (fieldFromInstruction32(Insn, 4, 1))
3013 index = fieldFromInstruction32(Insn, 5, 3);
3016 if (fieldFromInstruction32(Insn, 4, 1))
3018 index = fieldFromInstruction32(Insn, 6, 2);
3019 if (fieldFromInstruction32(Insn, 5, 1))
3023 if (fieldFromInstruction32(Insn, 4, 2))
3024 align = 4 << fieldFromInstruction32(Insn, 4, 2);
3025 index = fieldFromInstruction32(Insn, 7, 1);
3026 if (fieldFromInstruction32(Insn, 6, 1))
3031 if (Rm != 0xF) { // Writeback
3032 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
3035 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
3036 Inst.addOperand(MCOperand::CreateImm(align));
3037 if (Rm != 0xF && Rm != 0xD) {
3038 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
3042 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
3043 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
3044 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
3045 if (!DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)) return false;
3046 Inst.addOperand(MCOperand::CreateImm(index));