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 // Pull DecodeStatus and its enum values into the global namespace.
28 typedef llvm::MCDisassembler::DecodeStatus DecodeStatus;
29 #define Success llvm::MCDisassembler::Success
30 #define Unpredictable llvm::MCDisassembler::SoftFail
31 #define Fail llvm::MCDisassembler::Fail
33 // Helper macro to perform setwise reduction of the current running status
34 // and another status, and return if the new status is Fail.
35 #define CHECK(S,X) do { \
36 S = (DecodeStatus) ((int)S & (X)); \
37 if (S == Fail) return Fail; \
40 // Forward declare these because the autogenerated code will reference them.
41 // Definitions are further down.
42 static DecodeStatus DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
43 uint64_t Address, const void *Decoder);
44 static DecodeStatus DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
45 uint64_t Address, const void *Decoder);
46 static DecodeStatus DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
47 uint64_t Address, const void *Decoder);
48 static DecodeStatus DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
49 uint64_t Address, const void *Decoder);
50 static DecodeStatus DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
51 uint64_t Address, const void *Decoder);
52 static DecodeStatus DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
53 uint64_t Address, const void *Decoder);
54 static DecodeStatus DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
55 uint64_t Address, const void *Decoder);
56 static DecodeStatus DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
57 uint64_t Address, const void *Decoder);
58 static DecodeStatus DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
59 uint64_t Address, const void *Decoder);
60 static DecodeStatus DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
61 uint64_t Address, const void *Decoder);
63 static DecodeStatus DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
64 uint64_t Address, const void *Decoder);
65 static DecodeStatus DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
66 uint64_t Address, const void *Decoder);
67 static DecodeStatus DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
68 uint64_t Address, const void *Decoder);
69 static DecodeStatus DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
70 uint64_t Address, const void *Decoder);
71 static DecodeStatus DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
72 uint64_t Address, const void *Decoder);
73 static DecodeStatus DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
74 uint64_t Address, const void *Decoder);
75 static DecodeStatus DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
76 uint64_t Address, const void *Decoder);
78 static DecodeStatus DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Insn,
79 uint64_t Address, const void *Decoder);
80 static DecodeStatus DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
81 uint64_t Address, const void *Decoder);
82 static DecodeStatus DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
83 uint64_t Address, const void *Decoder);
84 static DecodeStatus DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Insn,
85 uint64_t Address, const void *Decoder);
86 static DecodeStatus DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
87 uint64_t Address, const void *Decoder);
88 static DecodeStatus DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Insn,
89 uint64_t Address, const void *Decoder);
90 static DecodeStatus DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Insn,
91 uint64_t Address, const void *Decoder);
93 static DecodeStatus DecodeMemMultipleWritebackInstruction(llvm::MCInst & Inst,
97 static DecodeStatus DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
98 uint64_t Address, const void *Decoder);
99 static DecodeStatus DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
100 uint64_t Address, const void *Decoder);
101 static DecodeStatus DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
102 uint64_t Address, const void *Decoder);
103 static DecodeStatus DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
104 uint64_t Address, const void *Decoder);
105 static DecodeStatus DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
106 uint64_t Address, const void *Decoder);
107 static DecodeStatus DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
108 uint64_t Address, const void *Decoder);
109 static DecodeStatus DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
110 uint64_t Address, const void *Decoder);
111 static DecodeStatus DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
112 uint64_t Address, const void *Decoder);
113 static DecodeStatus DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Val,
114 uint64_t Address, const void *Decoder);
115 static DecodeStatus DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Val,
116 uint64_t Address, const void *Decoder);
117 static DecodeStatus DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Val,
118 uint64_t Address, const void *Decoder);
119 static DecodeStatus DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Val,
120 uint64_t Address, const void *Decoder);
121 static DecodeStatus DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Val,
122 uint64_t Address, const void *Decoder);
123 static DecodeStatus DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Val,
124 uint64_t Address, const void *Decoder);
125 static DecodeStatus DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Val,
126 uint64_t Address, const void *Decoder);
127 static DecodeStatus DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Val,
128 uint64_t Address, const void *Decoder);
129 static DecodeStatus DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
130 uint64_t Address, const void *Decoder);
131 static DecodeStatus DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
132 uint64_t Address, const void *Decoder);
133 static DecodeStatus DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
134 uint64_t Address, const void *Decoder);
135 static DecodeStatus DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
136 uint64_t Address, const void *Decoder);
137 static DecodeStatus DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
138 uint64_t Address, const void *Decoder);
139 static DecodeStatus DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
140 uint64_t Address, const void *Decoder);
141 static DecodeStatus DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
142 uint64_t Address, const void *Decoder);
143 static DecodeStatus DecodeCoprocessor(llvm::MCInst &Inst, unsigned Insn,
144 uint64_t Address, const void *Decoder);
145 static DecodeStatus DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Insn,
146 uint64_t Address, const void *Decoder);
147 static DecodeStatus DecodeMSRMask(llvm::MCInst &Inst, unsigned Insn,
148 uint64_t Address, const void *Decoder);
149 static DecodeStatus DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
150 uint64_t Address, const void *Decoder);
151 static DecodeStatus DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
152 uint64_t Address, const void *Decoder);
153 static DecodeStatus DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
154 uint64_t Address, const void *Decoder);
155 static DecodeStatus DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
156 uint64_t Address, const void *Decoder);
157 static DecodeStatus DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
158 uint64_t Address, const void *Decoder);
159 static DecodeStatus DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
160 uint64_t Address, const void *Decoder);
161 static DecodeStatus DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
162 uint64_t Address, const void *Decoder);
163 static DecodeStatus DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
164 uint64_t Address, const void *Decoder);
165 static DecodeStatus DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
166 uint64_t Address, const void *Decoder);
167 static DecodeStatus DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
168 uint64_t Address, const void *Decoder);
169 static DecodeStatus DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
170 uint64_t Address, const void *Decoder);
171 static DecodeStatus DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
172 uint64_t Address, const void *Decoder);
175 static DecodeStatus DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
176 uint64_t Address, const void *Decoder);
177 static DecodeStatus DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
178 uint64_t Address, const void *Decoder);
179 static DecodeStatus DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
180 uint64_t Address, const void *Decoder);
181 static DecodeStatus DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
182 uint64_t Address, const void *Decoder);
183 static DecodeStatus DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
184 uint64_t Address, const void *Decoder);
185 static DecodeStatus DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
186 uint64_t Address, const void *Decoder);
187 static DecodeStatus DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
188 uint64_t Address, const void *Decoder);
189 static DecodeStatus DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
190 uint64_t Address, const void *Decoder);
191 static DecodeStatus DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
192 uint64_t Address, const void *Decoder);
193 static DecodeStatus DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
194 uint64_t Address, const void *Decoder);
195 static DecodeStatus DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
196 uint64_t Address, const void *Decoder);
197 static DecodeStatus DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
198 uint64_t Address, const void *Decoder);
199 static DecodeStatus DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
200 uint64_t Address, const void *Decoder);
201 static DecodeStatus DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
202 uint64_t Address, const void *Decoder);
203 static DecodeStatus DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
204 uint64_t Address, const void *Decoder);
205 static DecodeStatus DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
206 uint64_t Address, const void *Decoder);
207 static DecodeStatus DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
208 uint64_t Address, const void *Decoder);
209 static DecodeStatus DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
210 uint64_t Address, const void *Decoder);
211 static DecodeStatus DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
212 uint64_t Address, const void *Decoder);
213 static DecodeStatus DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
214 uint64_t Address, const void *Decoder);
215 static DecodeStatus DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
216 uint64_t Address, const void *Decoder);
217 static DecodeStatus DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
218 uint64_t Address, const void *Decoder);
219 static DecodeStatus DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
220 uint64_t Address, const void *Decoder);
221 static DecodeStatus DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
222 uint64_t Address, const void *Decoder);
224 #include "ARMGenDisassemblerTables.inc"
225 #include "ARMGenInstrInfo.inc"
226 #include "ARMGenEDInfo.inc"
228 using namespace llvm;
230 static MCDisassembler *createARMDisassembler(const Target &T) {
231 return new ARMDisassembler;
234 static MCDisassembler *createThumbDisassembler(const Target &T) {
235 return new ThumbDisassembler;
238 EDInstInfo *ARMDisassembler::getEDInfo() const {
242 EDInstInfo *ThumbDisassembler::getEDInfo() const {
246 DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
247 const MemoryObject &Region,
248 uint64_t Address,raw_ostream &os) const {
251 // We want to read exactly 4 bytes of data.
252 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
255 // Encoded as a small-endian 32-bit word in the stream.
256 uint32_t insn = (bytes[3] << 24) |
261 // Calling the auto-generated decoder function.
262 DecodeStatus result = decodeARMInstruction32(MI, insn, Address, this);
263 if (result != Fail) {
268 // Instructions that are shared between ARM and Thumb modes.
269 // FIXME: This shouldn't really exist. It's an artifact of the
270 // fact that we fail to encode a few instructions properly for Thumb.
272 result = decodeCommonInstruction32(MI, insn, Address, this);
273 if (result != Fail) {
278 // VFP and NEON instructions, similarly, are shared between ARM
281 result = decodeVFPInstruction32(MI, insn, Address, this);
282 if (result != Fail) {
288 result = decodeNEONDataInstruction32(MI, insn, Address, this);
289 if (result != Fail) {
291 // Add a fake predicate operand, because we share these instruction
292 // definitions with Thumb2 where these instructions are predicable.
293 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
298 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this);
299 if (result != Fail) {
301 // Add a fake predicate operand, because we share these instruction
302 // definitions with Thumb2 where these instructions are predicable.
303 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
308 result = decodeNEONDupInstruction32(MI, insn, Address, this);
309 if (result != Fail) {
311 // Add a fake predicate operand, because we share these instruction
312 // definitions with Thumb2 where these instructions are predicable.
313 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
323 extern MCInstrDesc ARMInsts[];
326 // Thumb1 instructions don't have explicit S bits. Rather, they
327 // implicitly set CPSR. Since it's not represented in the encoding, the
328 // auto-generated decoder won't inject the CPSR operand. We need to fix
329 // that as a post-pass.
330 static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
331 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
332 MCInst::iterator I = MI.begin();
333 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
334 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
335 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
340 if (OpInfo[MI.size()].isOptionalDef() &&
341 OpInfo[MI.size()].RegClass == ARM::CCRRegClassID)
342 MI.insert(MI.end(), MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
345 // Most Thumb instructions don't have explicit predicates in the
346 // encoding, but rather get their predicates from IT context. We need
347 // to fix up the predicate operands using this context information as a
349 void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
350 // A few instructions actually have predicates encoded in them. Don't
351 // try to overwrite it if we're seeing one of those.
352 switch (MI.getOpcode()) {
360 // If we're in an IT block, base the predicate on that. Otherwise,
361 // assume a predicate of AL.
363 if (!ITBlock.empty()) {
369 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
370 MCInst::iterator I = MI.begin();
371 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
372 if (OpInfo[i].isPredicate()) {
373 I = MI.insert(I, MCOperand::CreateImm(CC));
376 MI.insert(I, MCOperand::CreateReg(0));
378 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
383 MI.insert(MI.end(), MCOperand::CreateImm(CC));
385 MI.insert(MI.end(), MCOperand::CreateReg(0));
387 MI.insert(MI.end(), MCOperand::CreateReg(ARM::CPSR));
390 // Thumb VFP instructions are a special case. Because we share their
391 // encodings between ARM and Thumb modes, and they are predicable in ARM
392 // mode, the auto-generated decoder will give them an (incorrect)
393 // predicate operand. We need to rewrite these operands based on the IT
394 // context as a post-pass.
395 void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
397 if (!ITBlock.empty()) {
403 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
404 MCInst::iterator I = MI.begin();
405 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
406 if (OpInfo[i].isPredicate() ) {
412 I->setReg(ARM::CPSR);
418 DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
419 const MemoryObject &Region,
420 uint64_t Address,raw_ostream &os) const {
423 // We want to read exactly 2 bytes of data.
424 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
427 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
428 DecodeStatus result = decodeThumbInstruction16(MI, insn16, Address, this);
429 if (result != Fail) {
431 AddThumbPredicate(MI);
436 result = decodeThumbSBitInstruction16(MI, insn16, Address, this);
439 bool InITBlock = !ITBlock.empty();
440 AddThumbPredicate(MI);
441 AddThumb1SBit(MI, InITBlock);
446 result = decodeThumb2Instruction16(MI, insn16, Address, this);
447 if (result != Fail) {
449 AddThumbPredicate(MI);
451 // If we find an IT instruction, we need to parse its condition
452 // code and mask operands so that we can apply them correctly
453 // to the subsequent instructions.
454 if (MI.getOpcode() == ARM::t2IT) {
455 unsigned firstcond = MI.getOperand(0).getImm();
456 uint32_t mask = MI.getOperand(1).getImm();
457 unsigned zeros = CountTrailingZeros_32(mask);
460 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
461 if (firstcond ^ (mask & 1))
462 ITBlock.push_back(firstcond ^ 1);
464 ITBlock.push_back(firstcond);
467 ITBlock.push_back(firstcond);
473 // We want to read exactly 4 bytes of data.
474 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
477 uint32_t insn32 = (bytes[3] << 8) |
482 result = decodeThumbInstruction32(MI, insn32, Address, this);
483 if (result != Fail) {
485 bool InITBlock = ITBlock.size();
486 AddThumbPredicate(MI);
487 AddThumb1SBit(MI, InITBlock);
492 result = decodeThumb2Instruction32(MI, insn32, Address, this);
493 if (result != Fail) {
495 AddThumbPredicate(MI);
500 result = decodeCommonInstruction32(MI, insn32, Address, this);
501 if (result != Fail) {
503 AddThumbPredicate(MI);
508 result = decodeVFPInstruction32(MI, insn32, Address, this);
509 if (result != Fail) {
511 UpdateThumbVFPPredicate(MI);
516 result = decodeNEONDupInstruction32(MI, insn32, Address, this);
517 if (result != Fail) {
519 AddThumbPredicate(MI);
523 if (fieldFromInstruction32(insn32, 24, 8) == 0xF9) {
525 uint32_t NEONLdStInsn = insn32;
526 NEONLdStInsn &= 0xF0FFFFFF;
527 NEONLdStInsn |= 0x04000000;
528 result = decodeNEONLoadStoreInstruction32(MI, NEONLdStInsn, Address, this);
529 if (result != Fail) {
531 AddThumbPredicate(MI);
536 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
538 uint32_t NEONDataInsn = insn32;
539 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
540 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
541 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
542 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this);
543 if (result != Fail) {
545 AddThumbPredicate(MI);
554 extern "C" void LLVMInitializeARMDisassembler() {
555 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
556 createARMDisassembler);
557 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
558 createThumbDisassembler);
561 static const unsigned GPRDecoderTable[] = {
562 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
563 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
564 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
565 ARM::R12, ARM::SP, ARM::LR, ARM::PC
568 static DecodeStatus DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
569 uint64_t Address, const void *Decoder) {
573 unsigned Register = GPRDecoderTable[RegNo];
574 Inst.addOperand(MCOperand::CreateReg(Register));
578 static DecodeStatus DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
579 uint64_t Address, const void *Decoder) {
580 if (RegNo == 15) return Fail;
581 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
584 static DecodeStatus DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
585 uint64_t Address, const void *Decoder) {
588 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
591 static DecodeStatus DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
592 uint64_t Address, const void *Decoder) {
593 unsigned Register = 0;
617 Inst.addOperand(MCOperand::CreateReg(Register));
621 static DecodeStatus DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
622 uint64_t Address, const void *Decoder) {
623 if (RegNo == 13 || RegNo == 15) return Fail;
624 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
627 static const unsigned SPRDecoderTable[] = {
628 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
629 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
630 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
631 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
632 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
633 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
634 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
635 ARM::S28, ARM::S29, ARM::S30, ARM::S31
638 static DecodeStatus DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
639 uint64_t Address, const void *Decoder) {
643 unsigned Register = SPRDecoderTable[RegNo];
644 Inst.addOperand(MCOperand::CreateReg(Register));
648 static const unsigned DPRDecoderTable[] = {
649 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
650 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
651 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
652 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
653 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
654 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
655 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
656 ARM::D28, ARM::D29, ARM::D30, ARM::D31
659 static DecodeStatus DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
660 uint64_t Address, const void *Decoder) {
664 unsigned Register = DPRDecoderTable[RegNo];
665 Inst.addOperand(MCOperand::CreateReg(Register));
669 static DecodeStatus DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
670 uint64_t Address, const void *Decoder) {
673 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
676 static DecodeStatus DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
677 uint64_t Address, const void *Decoder) {
680 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
683 static const unsigned QPRDecoderTable[] = {
684 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
685 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
686 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
687 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
691 static DecodeStatus DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
692 uint64_t Address, const void *Decoder) {
697 unsigned Register = QPRDecoderTable[RegNo];
698 Inst.addOperand(MCOperand::CreateReg(Register));
702 static DecodeStatus DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
703 uint64_t Address, const void *Decoder) {
704 if (Val == 0xF) return Fail;
705 // AL predicate is not allowed on Thumb1 branches.
706 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
708 Inst.addOperand(MCOperand::CreateImm(Val));
709 if (Val == ARMCC::AL) {
710 Inst.addOperand(MCOperand::CreateReg(0));
712 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
716 static DecodeStatus DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
717 uint64_t Address, const void *Decoder) {
719 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
721 Inst.addOperand(MCOperand::CreateReg(0));
725 static DecodeStatus DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
726 uint64_t Address, const void *Decoder) {
727 uint32_t imm = Val & 0xFF;
728 uint32_t rot = (Val & 0xF00) >> 7;
729 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
730 Inst.addOperand(MCOperand::CreateImm(rot_imm));
734 static DecodeStatus DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
735 uint64_t Address, const void *Decoder) {
737 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
741 static DecodeStatus DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
742 uint64_t Address, const void *Decoder) {
743 DecodeStatus S = Success;
745 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
746 unsigned type = fieldFromInstruction32(Val, 5, 2);
747 unsigned imm = fieldFromInstruction32(Val, 7, 5);
749 // Register-immediate
750 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
752 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
768 if (Shift == ARM_AM::ror && imm == 0)
771 unsigned Op = Shift | (imm << 3);
772 Inst.addOperand(MCOperand::CreateImm(Op));
777 static DecodeStatus DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
778 uint64_t Address, const void *Decoder) {
779 DecodeStatus S = Success;
781 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
782 unsigned type = fieldFromInstruction32(Val, 5, 2);
783 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
786 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
787 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder));
789 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
805 Inst.addOperand(MCOperand::CreateImm(Shift));
810 static DecodeStatus DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
811 uint64_t Address, const void *Decoder) {
812 DecodeStatus S = Success;
814 // Empty register lists are not allowed.
815 if (CountPopulation_32(Val) == 0) return Fail;
816 for (unsigned i = 0; i < 16; ++i) {
817 if (Val & (1 << i)) {
818 CHECK(S, DecodeGPRRegisterClass(Inst, i, Address, Decoder));
825 static DecodeStatus DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
826 uint64_t Address, const void *Decoder) {
827 DecodeStatus S = Success;
829 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
830 unsigned regs = Val & 0xFF;
832 CHECK(S, DecodeSPRRegisterClass(Inst, Vd, Address, Decoder));
833 for (unsigned i = 0; i < (regs - 1); ++i) {
834 CHECK(S, DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder));
840 static DecodeStatus DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
841 uint64_t Address, const void *Decoder) {
842 DecodeStatus S = Success;
844 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
845 unsigned regs = (Val & 0xFF) / 2;
847 CHECK(S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder));
848 for (unsigned i = 0; i < (regs - 1); ++i) {
849 CHECK(S, DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder));
855 static DecodeStatus DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
856 uint64_t Address, const void *Decoder) {
857 // This operand encodes a mask of contiguous zeros between a specified MSB
858 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
859 // the mask of all bits LSB-and-lower, and then xor them to create
860 // the mask of that's all ones on [msb, lsb]. Finally we not it to
861 // create the final mask.
862 unsigned msb = fieldFromInstruction32(Val, 5, 5);
863 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
864 uint32_t msb_mask = (1 << (msb+1)) - 1;
865 uint32_t lsb_mask = (1 << lsb) - 1;
866 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
870 static DecodeStatus DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
871 uint64_t Address, const void *Decoder) {
872 DecodeStatus S = Success;
874 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
875 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
876 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
877 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
878 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
879 unsigned U = fieldFromInstruction32(Insn, 23, 1);
881 switch (Inst.getOpcode()) {
882 case ARM::LDC_OFFSET:
885 case ARM::LDC_OPTION:
886 case ARM::LDCL_OFFSET:
889 case ARM::LDCL_OPTION:
890 case ARM::STC_OFFSET:
893 case ARM::STC_OPTION:
894 case ARM::STCL_OFFSET:
897 case ARM::STCL_OPTION:
898 if (coproc == 0xA || coproc == 0xB)
905 Inst.addOperand(MCOperand::CreateImm(coproc));
906 Inst.addOperand(MCOperand::CreateImm(CRd));
907 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
908 switch (Inst.getOpcode()) {
909 case ARM::LDC_OPTION:
910 case ARM::LDCL_OPTION:
911 case ARM::LDC2_OPTION:
912 case ARM::LDC2L_OPTION:
913 case ARM::STC_OPTION:
914 case ARM::STCL_OPTION:
915 case ARM::STC2_OPTION:
916 case ARM::STC2L_OPTION:
921 Inst.addOperand(MCOperand::CreateReg(0));
925 unsigned P = fieldFromInstruction32(Insn, 24, 1);
926 unsigned W = fieldFromInstruction32(Insn, 21, 1);
928 bool writeback = (P == 0) || (W == 1);
929 unsigned idx_mode = 0;
931 idx_mode = ARMII::IndexModePre;
932 else if (!P && writeback)
933 idx_mode = ARMII::IndexModePost;
935 switch (Inst.getOpcode()) {
939 case ARM::LDC_OPTION:
940 case ARM::LDCL_OPTION:
941 case ARM::LDC2_OPTION:
942 case ARM::LDC2L_OPTION:
943 case ARM::STC_OPTION:
944 case ARM::STCL_OPTION:
945 case ARM::STC2_OPTION:
946 case ARM::STC2L_OPTION:
947 Inst.addOperand(MCOperand::CreateImm(imm));
951 Inst.addOperand(MCOperand::CreateImm(
952 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
954 Inst.addOperand(MCOperand::CreateImm(
955 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
959 switch (Inst.getOpcode()) {
960 case ARM::LDC_OFFSET:
963 case ARM::LDC_OPTION:
964 case ARM::LDCL_OFFSET:
967 case ARM::LDCL_OPTION:
968 case ARM::STC_OFFSET:
971 case ARM::STC_OPTION:
972 case ARM::STCL_OFFSET:
975 case ARM::STCL_OPTION:
976 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
985 static DecodeStatus DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
986 uint64_t Address, const void *Decoder) {
987 DecodeStatus S = Success;
989 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
990 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
991 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
992 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
993 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
994 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
995 unsigned P = fieldFromInstruction32(Insn, 24, 1);
996 unsigned W = fieldFromInstruction32(Insn, 21, 1);
998 // On stores, the writeback operand precedes Rt.
999 switch (Inst.getOpcode()) {
1000 case ARM::STR_POST_IMM:
1001 case ARM::STR_POST_REG:
1002 case ARM::STRB_POST_IMM:
1003 case ARM::STRB_POST_REG:
1004 case ARM::STRT_POST_REG:
1005 case ARM::STRT_POST_IMM:
1006 case ARM::STRBT_POST_REG:
1007 case ARM::STRBT_POST_IMM:
1008 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1014 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
1016 // On loads, the writeback operand comes after Rt.
1017 switch (Inst.getOpcode()) {
1018 case ARM::LDR_POST_IMM:
1019 case ARM::LDR_POST_REG:
1020 case ARM::LDRB_POST_IMM:
1021 case ARM::LDRB_POST_REG:
1024 case ARM::LDRBT_POST_REG:
1025 case ARM::LDRBT_POST_IMM:
1026 case ARM::LDRT_POST_REG:
1027 case ARM::LDRT_POST_IMM:
1028 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1034 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1036 ARM_AM::AddrOpc Op = ARM_AM::add;
1037 if (!fieldFromInstruction32(Insn, 23, 1))
1040 bool writeback = (P == 0) || (W == 1);
1041 unsigned idx_mode = 0;
1043 idx_mode = ARMII::IndexModePre;
1044 else if (!P && writeback)
1045 idx_mode = ARMII::IndexModePost;
1047 if (writeback && (Rn == 15 || Rn == Rt)) S = Unpredictable; // UNPREDICTABLE
1050 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
1051 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
1052 switch( fieldFromInstruction32(Insn, 5, 2)) {
1068 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1069 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1071 Inst.addOperand(MCOperand::CreateImm(imm));
1073 Inst.addOperand(MCOperand::CreateReg(0));
1074 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1075 Inst.addOperand(MCOperand::CreateImm(tmp));
1078 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1083 static DecodeStatus DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
1084 uint64_t Address, const void *Decoder) {
1085 DecodeStatus S = Success;
1087 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1088 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1089 unsigned type = fieldFromInstruction32(Val, 5, 2);
1090 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1091 unsigned U = fieldFromInstruction32(Val, 12, 1);
1093 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
1109 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1110 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1113 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1115 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1116 Inst.addOperand(MCOperand::CreateImm(shift));
1121 static DecodeStatus DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
1122 uint64_t Address, const void *Decoder) {
1123 DecodeStatus S = Success;
1125 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1126 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1127 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1128 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1129 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1130 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1131 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1132 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1133 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1135 bool writeback = (W == 1) | (P == 0);
1137 // For {LD,ST}RD, Rt must be even, else undefined.
1138 switch (Inst.getOpcode()) {
1141 case ARM::STRD_POST:
1144 case ARM::LDRD_POST:
1145 if (Rt & 0x1) return Fail;
1151 if (writeback) { // Writeback
1153 U |= ARMII::IndexModePre << 9;
1155 U |= ARMII::IndexModePost << 9;
1157 // On stores, the writeback operand precedes Rt.
1158 switch (Inst.getOpcode()) {
1161 case ARM::STRD_POST:
1164 case ARM::STRH_POST:
1165 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1172 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
1173 switch (Inst.getOpcode()) {
1176 case ARM::STRD_POST:
1179 case ARM::LDRD_POST:
1180 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
1187 // On loads, the writeback operand comes after Rt.
1188 switch (Inst.getOpcode()) {
1191 case ARM::LDRD_POST:
1194 case ARM::LDRH_POST:
1196 case ARM::LDRSH_PRE:
1197 case ARM::LDRSH_POST:
1199 case ARM::LDRSB_PRE:
1200 case ARM::LDRSB_POST:
1203 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1210 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1213 Inst.addOperand(MCOperand::CreateReg(0));
1214 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1216 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1217 Inst.addOperand(MCOperand::CreateImm(U));
1220 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1225 static DecodeStatus DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1226 uint64_t Address, const void *Decoder) {
1227 DecodeStatus S = Success;
1229 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1230 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1247 Inst.addOperand(MCOperand::CreateImm(mode));
1248 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1253 static DecodeStatus DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1255 uint64_t Address, const void *Decoder) {
1256 DecodeStatus S = Success;
1258 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1259 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1260 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1263 switch (Inst.getOpcode()) {
1265 Inst.setOpcode(ARM::RFEDA);
1267 case ARM::STMDA_UPD:
1268 Inst.setOpcode(ARM::RFEDA_UPD);
1271 Inst.setOpcode(ARM::RFEDB);
1273 case ARM::STMDB_UPD:
1274 Inst.setOpcode(ARM::RFEDB_UPD);
1277 Inst.setOpcode(ARM::RFEIA);
1279 case ARM::STMIA_UPD:
1280 Inst.setOpcode(ARM::RFEIA_UPD);
1283 Inst.setOpcode(ARM::RFEIB);
1285 case ARM::STMIB_UPD:
1286 Inst.setOpcode(ARM::RFEIB_UPD);
1289 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1292 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1293 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)); // Tied
1294 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1295 CHECK(S, DecodeRegListOperand(Inst, reglist, Address, Decoder));
1300 static DecodeStatus DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1301 uint64_t Address, const void *Decoder) {
1302 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1303 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1304 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1305 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1307 // imod == '01' --> UNPREDICTABLE
1308 if (imod == 1) return Fail;
1310 if (M && mode && imod && iflags) {
1311 Inst.setOpcode(ARM::CPS3p);
1312 Inst.addOperand(MCOperand::CreateImm(imod));
1313 Inst.addOperand(MCOperand::CreateImm(iflags));
1314 Inst.addOperand(MCOperand::CreateImm(mode));
1316 } else if (!mode && !M) {
1317 Inst.setOpcode(ARM::CPS2p);
1318 Inst.addOperand(MCOperand::CreateImm(imod));
1319 Inst.addOperand(MCOperand::CreateImm(iflags));
1321 } else if (!imod && !iflags && M) {
1322 Inst.setOpcode(ARM::CPS1p);
1323 Inst.addOperand(MCOperand::CreateImm(mode));
1330 static DecodeStatus DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1331 uint64_t Address, const void *Decoder) {
1332 DecodeStatus S = Success;
1334 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1335 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1336 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1337 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1338 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1341 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1343 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder));
1344 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder));
1345 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
1346 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder));
1348 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1353 static DecodeStatus DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1354 uint64_t Address, const void *Decoder) {
1355 DecodeStatus S = Success;
1357 unsigned add = fieldFromInstruction32(Val, 12, 1);
1358 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1359 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1361 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1363 if (!add) imm *= -1;
1364 if (imm == 0 && !add) imm = INT32_MIN;
1365 Inst.addOperand(MCOperand::CreateImm(imm));
1370 static DecodeStatus DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1371 uint64_t Address, const void *Decoder) {
1372 DecodeStatus S = Success;
1374 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1375 unsigned U = fieldFromInstruction32(Val, 8, 1);
1376 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1378 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1381 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1383 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1388 static DecodeStatus DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1389 uint64_t Address, const void *Decoder) {
1390 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1393 static DecodeStatus DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1394 uint64_t Address, const void *Decoder) {
1395 DecodeStatus S = Success;
1397 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1398 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1401 Inst.setOpcode(ARM::BLXi);
1402 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
1403 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1407 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1408 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1414 static DecodeStatus DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1415 uint64_t Address, const void *Decoder) {
1416 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1420 static DecodeStatus DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1421 uint64_t Address, const void *Decoder) {
1422 DecodeStatus S = Success;
1424 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1425 unsigned align = fieldFromInstruction32(Val, 4, 2);
1427 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1429 Inst.addOperand(MCOperand::CreateImm(0));
1431 Inst.addOperand(MCOperand::CreateImm(4 << align));
1436 static DecodeStatus DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1437 uint64_t Address, const void *Decoder) {
1438 DecodeStatus S = Success;
1440 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1441 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1442 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1443 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1444 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1445 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1447 // First output register
1448 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1450 // Second output register
1451 switch (Inst.getOpcode()) {
1456 case ARM::VLD1q8_UPD:
1457 case ARM::VLD1q16_UPD:
1458 case ARM::VLD1q32_UPD:
1459 case ARM::VLD1q64_UPD:
1464 case ARM::VLD1d8T_UPD:
1465 case ARM::VLD1d16T_UPD:
1466 case ARM::VLD1d32T_UPD:
1467 case ARM::VLD1d64T_UPD:
1472 case ARM::VLD1d8Q_UPD:
1473 case ARM::VLD1d16Q_UPD:
1474 case ARM::VLD1d32Q_UPD:
1475 case ARM::VLD1d64Q_UPD:
1479 case ARM::VLD2d8_UPD:
1480 case ARM::VLD2d16_UPD:
1481 case ARM::VLD2d32_UPD:
1485 case ARM::VLD2q8_UPD:
1486 case ARM::VLD2q16_UPD:
1487 case ARM::VLD2q32_UPD:
1491 case ARM::VLD3d8_UPD:
1492 case ARM::VLD3d16_UPD:
1493 case ARM::VLD3d32_UPD:
1497 case ARM::VLD4d8_UPD:
1498 case ARM::VLD4d16_UPD:
1499 case ARM::VLD4d32_UPD:
1500 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1505 case ARM::VLD2b8_UPD:
1506 case ARM::VLD2b16_UPD:
1507 case ARM::VLD2b32_UPD:
1511 case ARM::VLD3q8_UPD:
1512 case ARM::VLD3q16_UPD:
1513 case ARM::VLD3q32_UPD:
1517 case ARM::VLD4q8_UPD:
1518 case ARM::VLD4q16_UPD:
1519 case ARM::VLD4q32_UPD:
1520 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1525 // Third output register
1526 switch(Inst.getOpcode()) {
1531 case ARM::VLD1d8T_UPD:
1532 case ARM::VLD1d16T_UPD:
1533 case ARM::VLD1d32T_UPD:
1534 case ARM::VLD1d64T_UPD:
1539 case ARM::VLD1d8Q_UPD:
1540 case ARM::VLD1d16Q_UPD:
1541 case ARM::VLD1d32Q_UPD:
1542 case ARM::VLD1d64Q_UPD:
1546 case ARM::VLD2q8_UPD:
1547 case ARM::VLD2q16_UPD:
1548 case ARM::VLD2q32_UPD:
1552 case ARM::VLD3d8_UPD:
1553 case ARM::VLD3d16_UPD:
1554 case ARM::VLD3d32_UPD:
1558 case ARM::VLD4d8_UPD:
1559 case ARM::VLD4d16_UPD:
1560 case ARM::VLD4d32_UPD:
1561 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1566 case ARM::VLD3q8_UPD:
1567 case ARM::VLD3q16_UPD:
1568 case ARM::VLD3q32_UPD:
1572 case ARM::VLD4q8_UPD:
1573 case ARM::VLD4q16_UPD:
1574 case ARM::VLD4q32_UPD:
1575 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder));
1581 // Fourth output register
1582 switch (Inst.getOpcode()) {
1587 case ARM::VLD1d8Q_UPD:
1588 case ARM::VLD1d16Q_UPD:
1589 case ARM::VLD1d32Q_UPD:
1590 case ARM::VLD1d64Q_UPD:
1594 case ARM::VLD2q8_UPD:
1595 case ARM::VLD2q16_UPD:
1596 case ARM::VLD2q32_UPD:
1600 case ARM::VLD4d8_UPD:
1601 case ARM::VLD4d16_UPD:
1602 case ARM::VLD4d32_UPD:
1603 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder));
1608 case ARM::VLD4q8_UPD:
1609 case ARM::VLD4q16_UPD:
1610 case ARM::VLD4q32_UPD:
1611 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder));
1617 // Writeback operand
1618 switch (Inst.getOpcode()) {
1619 case ARM::VLD1d8_UPD:
1620 case ARM::VLD1d16_UPD:
1621 case ARM::VLD1d32_UPD:
1622 case ARM::VLD1d64_UPD:
1623 case ARM::VLD1q8_UPD:
1624 case ARM::VLD1q16_UPD:
1625 case ARM::VLD1q32_UPD:
1626 case ARM::VLD1q64_UPD:
1627 case ARM::VLD1d8T_UPD:
1628 case ARM::VLD1d16T_UPD:
1629 case ARM::VLD1d32T_UPD:
1630 case ARM::VLD1d64T_UPD:
1631 case ARM::VLD1d8Q_UPD:
1632 case ARM::VLD1d16Q_UPD:
1633 case ARM::VLD1d32Q_UPD:
1634 case ARM::VLD1d64Q_UPD:
1635 case ARM::VLD2d8_UPD:
1636 case ARM::VLD2d16_UPD:
1637 case ARM::VLD2d32_UPD:
1638 case ARM::VLD2q8_UPD:
1639 case ARM::VLD2q16_UPD:
1640 case ARM::VLD2q32_UPD:
1641 case ARM::VLD2b8_UPD:
1642 case ARM::VLD2b16_UPD:
1643 case ARM::VLD2b32_UPD:
1644 case ARM::VLD3d8_UPD:
1645 case ARM::VLD3d16_UPD:
1646 case ARM::VLD3d32_UPD:
1647 case ARM::VLD3q8_UPD:
1648 case ARM::VLD3q16_UPD:
1649 case ARM::VLD3q32_UPD:
1650 case ARM::VLD4d8_UPD:
1651 case ARM::VLD4d16_UPD:
1652 case ARM::VLD4d32_UPD:
1653 case ARM::VLD4q8_UPD:
1654 case ARM::VLD4q16_UPD:
1655 case ARM::VLD4q32_UPD:
1656 CHECK(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder));
1662 // AddrMode6 Base (register+alignment)
1663 CHECK(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder));
1665 // AddrMode6 Offset (register)
1667 Inst.addOperand(MCOperand::CreateReg(0));
1668 else if (Rm != 0xF) {
1669 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1675 static DecodeStatus DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1676 uint64_t Address, const void *Decoder) {
1677 DecodeStatus S = Success;
1679 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1680 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1681 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1682 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1683 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1684 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1686 // Writeback Operand
1687 switch (Inst.getOpcode()) {
1688 case ARM::VST1d8_UPD:
1689 case ARM::VST1d16_UPD:
1690 case ARM::VST1d32_UPD:
1691 case ARM::VST1d64_UPD:
1692 case ARM::VST1q8_UPD:
1693 case ARM::VST1q16_UPD:
1694 case ARM::VST1q32_UPD:
1695 case ARM::VST1q64_UPD:
1696 case ARM::VST1d8T_UPD:
1697 case ARM::VST1d16T_UPD:
1698 case ARM::VST1d32T_UPD:
1699 case ARM::VST1d64T_UPD:
1700 case ARM::VST1d8Q_UPD:
1701 case ARM::VST1d16Q_UPD:
1702 case ARM::VST1d32Q_UPD:
1703 case ARM::VST1d64Q_UPD:
1704 case ARM::VST2d8_UPD:
1705 case ARM::VST2d16_UPD:
1706 case ARM::VST2d32_UPD:
1707 case ARM::VST2q8_UPD:
1708 case ARM::VST2q16_UPD:
1709 case ARM::VST2q32_UPD:
1710 case ARM::VST2b8_UPD:
1711 case ARM::VST2b16_UPD:
1712 case ARM::VST2b32_UPD:
1713 case ARM::VST3d8_UPD:
1714 case ARM::VST3d16_UPD:
1715 case ARM::VST3d32_UPD:
1716 case ARM::VST3q8_UPD:
1717 case ARM::VST3q16_UPD:
1718 case ARM::VST3q32_UPD:
1719 case ARM::VST4d8_UPD:
1720 case ARM::VST4d16_UPD:
1721 case ARM::VST4d32_UPD:
1722 case ARM::VST4q8_UPD:
1723 case ARM::VST4q16_UPD:
1724 case ARM::VST4q32_UPD:
1725 CHECK(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder));
1731 // AddrMode6 Base (register+alignment)
1732 CHECK(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder));
1734 // AddrMode6 Offset (register)
1736 Inst.addOperand(MCOperand::CreateReg(0));
1737 else if (Rm != 0xF) {
1738 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1741 // First input register
1742 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1744 // Second input register
1745 switch (Inst.getOpcode()) {
1750 case ARM::VST1q8_UPD:
1751 case ARM::VST1q16_UPD:
1752 case ARM::VST1q32_UPD:
1753 case ARM::VST1q64_UPD:
1758 case ARM::VST1d8T_UPD:
1759 case ARM::VST1d16T_UPD:
1760 case ARM::VST1d32T_UPD:
1761 case ARM::VST1d64T_UPD:
1766 case ARM::VST1d8Q_UPD:
1767 case ARM::VST1d16Q_UPD:
1768 case ARM::VST1d32Q_UPD:
1769 case ARM::VST1d64Q_UPD:
1773 case ARM::VST2d8_UPD:
1774 case ARM::VST2d16_UPD:
1775 case ARM::VST2d32_UPD:
1779 case ARM::VST2q8_UPD:
1780 case ARM::VST2q16_UPD:
1781 case ARM::VST2q32_UPD:
1785 case ARM::VST3d8_UPD:
1786 case ARM::VST3d16_UPD:
1787 case ARM::VST3d32_UPD:
1791 case ARM::VST4d8_UPD:
1792 case ARM::VST4d16_UPD:
1793 case ARM::VST4d32_UPD:
1794 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1799 case ARM::VST2b8_UPD:
1800 case ARM::VST2b16_UPD:
1801 case ARM::VST2b32_UPD:
1805 case ARM::VST3q8_UPD:
1806 case ARM::VST3q16_UPD:
1807 case ARM::VST3q32_UPD:
1811 case ARM::VST4q8_UPD:
1812 case ARM::VST4q16_UPD:
1813 case ARM::VST4q32_UPD:
1814 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1820 // Third input register
1821 switch (Inst.getOpcode()) {
1826 case ARM::VST1d8T_UPD:
1827 case ARM::VST1d16T_UPD:
1828 case ARM::VST1d32T_UPD:
1829 case ARM::VST1d64T_UPD:
1834 case ARM::VST1d8Q_UPD:
1835 case ARM::VST1d16Q_UPD:
1836 case ARM::VST1d32Q_UPD:
1837 case ARM::VST1d64Q_UPD:
1841 case ARM::VST2q8_UPD:
1842 case ARM::VST2q16_UPD:
1843 case ARM::VST2q32_UPD:
1847 case ARM::VST3d8_UPD:
1848 case ARM::VST3d16_UPD:
1849 case ARM::VST3d32_UPD:
1853 case ARM::VST4d8_UPD:
1854 case ARM::VST4d16_UPD:
1855 case ARM::VST4d32_UPD:
1856 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1861 case ARM::VST3q8_UPD:
1862 case ARM::VST3q16_UPD:
1863 case ARM::VST3q32_UPD:
1867 case ARM::VST4q8_UPD:
1868 case ARM::VST4q16_UPD:
1869 case ARM::VST4q32_UPD:
1870 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder));
1876 // Fourth input register
1877 switch (Inst.getOpcode()) {
1882 case ARM::VST1d8Q_UPD:
1883 case ARM::VST1d16Q_UPD:
1884 case ARM::VST1d32Q_UPD:
1885 case ARM::VST1d64Q_UPD:
1889 case ARM::VST2q8_UPD:
1890 case ARM::VST2q16_UPD:
1891 case ARM::VST2q32_UPD:
1895 case ARM::VST4d8_UPD:
1896 case ARM::VST4d16_UPD:
1897 case ARM::VST4d32_UPD:
1898 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder));
1903 case ARM::VST4q8_UPD:
1904 case ARM::VST4q16_UPD:
1905 case ARM::VST4q32_UPD:
1906 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder));
1915 static DecodeStatus DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1916 uint64_t Address, const void *Decoder) {
1917 DecodeStatus S = Success;
1919 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1920 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1921 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1922 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1923 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1924 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1925 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
1927 align *= (1 << size);
1929 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1931 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1934 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1937 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1938 Inst.addOperand(MCOperand::CreateImm(align));
1941 Inst.addOperand(MCOperand::CreateReg(0));
1942 else if (Rm != 0xF) {
1943 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1949 static DecodeStatus DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1950 uint64_t Address, const void *Decoder) {
1951 DecodeStatus S = Success;
1953 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1954 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1955 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1956 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1957 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1958 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
1959 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1962 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1963 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
1965 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1968 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1969 Inst.addOperand(MCOperand::CreateImm(align));
1972 Inst.addOperand(MCOperand::CreateReg(0));
1973 else if (Rm != 0xF) {
1974 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1980 static DecodeStatus DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1981 uint64_t Address, const void *Decoder) {
1982 DecodeStatus S = Success;
1984 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1985 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1986 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1987 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1988 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1990 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1991 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
1992 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder));
1994 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1997 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1998 Inst.addOperand(MCOperand::CreateImm(0));
2001 Inst.addOperand(MCOperand::CreateReg(0));
2002 else if (Rm != 0xF) {
2003 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2009 static DecodeStatus DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
2010 uint64_t Address, const void *Decoder) {
2011 DecodeStatus S = Success;
2013 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2014 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2015 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2016 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2017 unsigned size = fieldFromInstruction32(Insn, 6, 2);
2018 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2019 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2034 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2035 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
2036 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder));
2037 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder));
2039 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2042 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2043 Inst.addOperand(MCOperand::CreateImm(align));
2046 Inst.addOperand(MCOperand::CreateReg(0));
2047 else if (Rm != 0xF) {
2048 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2054 static DecodeStatus DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
2055 uint64_t Address, const void *Decoder) {
2056 DecodeStatus S = Success;
2058 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2059 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2060 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2061 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
2062 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
2063 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
2064 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
2065 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
2068 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2070 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2073 Inst.addOperand(MCOperand::CreateImm(imm));
2075 switch (Inst.getOpcode()) {
2076 case ARM::VORRiv4i16:
2077 case ARM::VORRiv2i32:
2078 case ARM::VBICiv4i16:
2079 case ARM::VBICiv2i32:
2080 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2082 case ARM::VORRiv8i16:
2083 case ARM::VORRiv4i32:
2084 case ARM::VBICiv8i16:
2085 case ARM::VBICiv4i32:
2086 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2095 static DecodeStatus DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
2096 uint64_t Address, const void *Decoder) {
2097 DecodeStatus S = Success;
2099 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2100 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2101 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2102 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2103 unsigned size = fieldFromInstruction32(Insn, 18, 2);
2105 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2106 CHECK(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder));
2107 Inst.addOperand(MCOperand::CreateImm(8 << size));
2112 static DecodeStatus DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
2113 uint64_t Address, const void *Decoder) {
2114 Inst.addOperand(MCOperand::CreateImm(8 - Val));
2118 static DecodeStatus DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
2119 uint64_t Address, const void *Decoder) {
2120 Inst.addOperand(MCOperand::CreateImm(16 - Val));
2124 static DecodeStatus DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
2125 uint64_t Address, const void *Decoder) {
2126 Inst.addOperand(MCOperand::CreateImm(32 - Val));
2130 static DecodeStatus DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
2131 uint64_t Address, const void *Decoder) {
2132 Inst.addOperand(MCOperand::CreateImm(64 - Val));
2136 static DecodeStatus DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
2137 uint64_t Address, const void *Decoder) {
2138 DecodeStatus S = Success;
2140 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2141 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2142 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2143 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2144 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2145 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2146 unsigned op = fieldFromInstruction32(Insn, 6, 1);
2147 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
2149 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2151 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)); // Writeback
2154 for (unsigned i = 0; i < length; ++i) {
2155 CHECK(S, DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder));
2158 CHECK(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder));
2163 static DecodeStatus DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
2164 uint64_t Address, const void *Decoder) {
2165 // The immediate needs to be a fully instantiated float. However, the
2166 // auto-generated decoder is only able to fill in some of the bits
2167 // necessary. For instance, the 'b' bit is replicated multiple times,
2168 // and is even present in inverted form in one bit. We do a little
2169 // binary parsing here to fill in those missing bits, and then
2170 // reinterpret it all as a float.
2176 fp_conv.integer = Val;
2177 uint32_t b = fieldFromInstruction32(Val, 25, 1);
2178 fp_conv.integer |= b << 26;
2179 fp_conv.integer |= b << 27;
2180 fp_conv.integer |= b << 28;
2181 fp_conv.integer |= b << 29;
2182 fp_conv.integer |= (~b & 0x1) << 30;
2184 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
2188 static DecodeStatus DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
2189 uint64_t Address, const void *Decoder) {
2190 DecodeStatus S = Success;
2192 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2193 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2195 CHECK(S, DecodetGPRRegisterClass(Inst, dst, Address, Decoder));
2197 if (Inst.getOpcode() == ARM::tADR)
2198 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2199 else if (Inst.getOpcode() == ARM::tADDrSPi)
2200 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2204 Inst.addOperand(MCOperand::CreateImm(imm));
2208 static DecodeStatus DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
2209 uint64_t Address, const void *Decoder) {
2210 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
2214 static DecodeStatus DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
2215 uint64_t Address, const void *Decoder) {
2216 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2220 static DecodeStatus DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2221 uint64_t Address, const void *Decoder) {
2222 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2226 static DecodeStatus DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2227 uint64_t Address, const void *Decoder) {
2228 DecodeStatus S = Success;
2230 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2231 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2233 CHECK(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder));
2234 CHECK(S, DecodetGPRRegisterClass(Inst, Rm, Address, Decoder));
2239 static DecodeStatus DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2240 uint64_t Address, const void *Decoder) {
2241 DecodeStatus S = Success;
2243 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2244 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2246 CHECK(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder));
2247 Inst.addOperand(MCOperand::CreateImm(imm));
2252 static DecodeStatus DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2253 uint64_t Address, const void *Decoder) {
2254 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2259 static DecodeStatus DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2260 uint64_t Address, const void *Decoder) {
2261 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2262 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2267 static DecodeStatus DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2268 uint64_t Address, const void *Decoder) {
2269 DecodeStatus S = Success;
2271 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2272 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2273 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2275 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2276 CHECK(S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder));
2277 Inst.addOperand(MCOperand::CreateImm(imm));
2282 static DecodeStatus DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2283 uint64_t Address, const void *Decoder) {
2284 DecodeStatus S = Success;
2286 if (Inst.getOpcode() != ARM::t2PLDs) {
2287 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2288 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2291 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2293 switch (Inst.getOpcode()) {
2295 Inst.setOpcode(ARM::t2LDRBpci);
2298 Inst.setOpcode(ARM::t2LDRHpci);
2301 Inst.setOpcode(ARM::t2LDRSHpci);
2304 Inst.setOpcode(ARM::t2LDRSBpci);
2307 Inst.setOpcode(ARM::t2PLDi12);
2308 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2314 int imm = fieldFromInstruction32(Insn, 0, 12);
2315 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2316 Inst.addOperand(MCOperand::CreateImm(imm));
2321 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2322 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2323 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2324 CHECK(S, DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder));
2329 static DecodeStatus DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
2330 uint64_t Address, const void *Decoder) {
2331 int imm = Val & 0xFF;
2332 if (!(Val & 0x100)) imm *= -1;
2333 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2338 static DecodeStatus DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2339 uint64_t Address, const void *Decoder) {
2340 DecodeStatus S = Success;
2342 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2343 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2345 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2346 CHECK(S, DecodeT2Imm8S4(Inst, imm, Address, Decoder));
2351 static DecodeStatus DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
2352 uint64_t Address, const void *Decoder) {
2353 int imm = Val & 0xFF;
2354 if (!(Val & 0x100)) imm *= -1;
2355 Inst.addOperand(MCOperand::CreateImm(imm));
2361 static DecodeStatus DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
2362 uint64_t Address, const void *Decoder) {
2363 DecodeStatus S = Success;
2365 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2366 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2368 // Some instructions always use an additive offset.
2369 switch (Inst.getOpcode()) {
2381 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2382 CHECK(S, DecodeT2Imm8(Inst, imm, Address, Decoder));
2388 static DecodeStatus DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
2389 uint64_t Address, const void *Decoder) {
2390 DecodeStatus S = Success;
2392 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2393 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2395 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2396 Inst.addOperand(MCOperand::CreateImm(imm));
2402 static DecodeStatus DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
2403 uint64_t Address, const void *Decoder) {
2404 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2406 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2407 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2408 Inst.addOperand(MCOperand::CreateImm(imm));
2413 static DecodeStatus DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
2414 uint64_t Address, const void *Decoder) {
2415 DecodeStatus S = Success;
2417 if (Inst.getOpcode() == ARM::tADDrSP) {
2418 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2419 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2421 CHECK(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder));
2422 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2423 CHECK(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder));
2424 } else if (Inst.getOpcode() == ARM::tADDspr) {
2425 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2427 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2428 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2429 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2435 static DecodeStatus DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
2436 uint64_t Address, const void *Decoder) {
2437 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2438 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2440 Inst.addOperand(MCOperand::CreateImm(imod));
2441 Inst.addOperand(MCOperand::CreateImm(flags));
2446 static DecodeStatus DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
2447 uint64_t Address, const void *Decoder) {
2448 DecodeStatus S = Success;
2449 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2450 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2452 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) ;
2453 Inst.addOperand(MCOperand::CreateImm(add));
2458 static DecodeStatus DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
2459 uint64_t Address, const void *Decoder) {
2460 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2464 static DecodeStatus DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2465 uint64_t Address, const void *Decoder) {
2466 if (Val == 0xA || Val == 0xB)
2469 Inst.addOperand(MCOperand::CreateImm(Val));
2473 static DecodeStatus DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
2474 uint64_t Address, const void *Decoder) {
2476 Inst.addOperand(MCOperand::CreateImm(32));
2478 Inst.addOperand(MCOperand::CreateImm(Val));
2482 static DecodeStatus DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2483 uint64_t Address, const void *Decoder) {
2484 DecodeStatus S = Success;
2486 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2487 if (pred == 0xE || pred == 0xF) {
2488 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2493 Inst.setOpcode(ARM::t2DSB);
2496 Inst.setOpcode(ARM::t2DMB);
2499 Inst.setOpcode(ARM::t2ISB);
2503 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2504 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
2507 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2508 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2509 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2510 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2511 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2513 CHECK(S, DecodeT2BROperand(Inst, brtarget, Address, Decoder));
2514 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2519 // Decode a shifted immediate operand. These basically consist
2520 // of an 8-bit value, and a 4-bit directive that specifies either
2521 // a splat operation or a rotation.
2522 static DecodeStatus DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2523 uint64_t Address, const void *Decoder) {
2524 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2526 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2527 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2530 Inst.addOperand(MCOperand::CreateImm(imm));
2533 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2536 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2539 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2544 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2545 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2546 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2547 Inst.addOperand(MCOperand::CreateImm(imm));
2553 static DecodeStatus DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2554 uint64_t Address, const void *Decoder){
2555 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2559 static DecodeStatus DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
2560 uint64_t Address, const void *Decoder){
2561 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2565 static DecodeStatus DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Val,
2566 uint64_t Address, const void *Decoder) {
2581 Inst.addOperand(MCOperand::CreateImm(Val));
2585 static DecodeStatus DecodeMSRMask(llvm::MCInst &Inst, unsigned Val,
2586 uint64_t Address, const void *Decoder) {
2587 if (!Val) return Fail;
2588 Inst.addOperand(MCOperand::CreateImm(Val));
2592 static DecodeStatus DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
2593 uint64_t Address, const void *Decoder) {
2594 DecodeStatus S = Success;
2596 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2597 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2598 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2600 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return Fail;
2602 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2603 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
2604 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2605 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2611 static DecodeStatus DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
2612 uint64_t Address, const void *Decoder) {
2613 DecodeStatus S = Success;
2615 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2616 unsigned Rt = fieldFromInstruction32(Insn, 0, 4);
2617 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2618 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2620 CHECK(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder));
2622 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return Fail;
2623 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return Fail;
2625 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2626 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
2627 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2628 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2633 static DecodeStatus DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
2634 uint64_t Address, const void *Decoder) {
2635 DecodeStatus S = Success;
2637 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2638 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2639 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2640 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2641 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2642 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2644 if (Rn == 0xF || Rn == Rt) return Unpredictable; // UNPREDICTABLE
2646 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2647 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2648 CHECK(S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder));
2649 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2654 static DecodeStatus DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
2655 uint64_t Address, const void *Decoder) {
2656 DecodeStatus S = Success;
2658 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2659 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2660 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2661 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2662 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2663 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2665 if (Rn == 0xF || Rn == Rt) return Unpredictable; // UNPREDICTABLE
2667 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2668 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2669 CHECK(S, DecodeSORegMemOperand(Inst, imm, Address, Decoder));
2670 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2675 static DecodeStatus DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
2676 uint64_t Address, const void *Decoder) {
2677 DecodeStatus S = Success;
2679 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2680 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2681 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2682 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2683 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2691 if (fieldFromInstruction32(Insn, 4, 1))
2692 return Fail; // UNDEFINED
2693 index = fieldFromInstruction32(Insn, 5, 3);
2696 if (fieldFromInstruction32(Insn, 5, 1))
2697 return Fail; // UNDEFINED
2698 index = fieldFromInstruction32(Insn, 6, 2);
2699 if (fieldFromInstruction32(Insn, 4, 1))
2703 if (fieldFromInstruction32(Insn, 6, 1))
2704 return Fail; // UNDEFINED
2705 index = fieldFromInstruction32(Insn, 7, 1);
2706 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2710 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2711 if (Rm != 0xF) { // Writeback
2712 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2714 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2715 Inst.addOperand(MCOperand::CreateImm(align));
2716 if (Rm != 0xF && Rm != 0xD) {
2717 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2720 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2721 Inst.addOperand(MCOperand::CreateImm(index));
2726 static DecodeStatus DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
2727 uint64_t Address, const void *Decoder) {
2728 DecodeStatus S = Success;
2730 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2731 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2732 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2733 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2734 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2742 if (fieldFromInstruction32(Insn, 4, 1))
2743 return Fail; // UNDEFINED
2744 index = fieldFromInstruction32(Insn, 5, 3);
2747 if (fieldFromInstruction32(Insn, 5, 1))
2748 return Fail; // UNDEFINED
2749 index = fieldFromInstruction32(Insn, 6, 2);
2750 if (fieldFromInstruction32(Insn, 4, 1))
2754 if (fieldFromInstruction32(Insn, 6, 1))
2755 return Fail; // UNDEFINED
2756 index = fieldFromInstruction32(Insn, 7, 1);
2757 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2761 if (Rm != 0xF) { // Writeback
2762 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2764 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2765 Inst.addOperand(MCOperand::CreateImm(align));
2766 if (Rm != 0xF && Rm != 0xD) {
2767 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2770 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2771 Inst.addOperand(MCOperand::CreateImm(index));
2777 static DecodeStatus DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
2778 uint64_t Address, const void *Decoder) {
2779 DecodeStatus S = Success;
2781 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2782 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2783 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2784 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2785 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2794 index = fieldFromInstruction32(Insn, 5, 3);
2795 if (fieldFromInstruction32(Insn, 4, 1))
2799 index = fieldFromInstruction32(Insn, 6, 2);
2800 if (fieldFromInstruction32(Insn, 4, 1))
2802 if (fieldFromInstruction32(Insn, 5, 1))
2806 if (fieldFromInstruction32(Insn, 5, 1))
2807 return Fail; // UNDEFINED
2808 index = fieldFromInstruction32(Insn, 7, 1);
2809 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2811 if (fieldFromInstruction32(Insn, 6, 1))
2816 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2817 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2818 if (Rm != 0xF) { // Writeback
2819 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2821 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2822 Inst.addOperand(MCOperand::CreateImm(align));
2823 if (Rm != 0xF && Rm != 0xD) {
2824 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2827 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2828 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2829 Inst.addOperand(MCOperand::CreateImm(index));
2834 static DecodeStatus DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
2835 uint64_t Address, const void *Decoder) {
2836 DecodeStatus S = Success;
2838 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2839 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2840 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2841 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2842 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2851 index = fieldFromInstruction32(Insn, 5, 3);
2852 if (fieldFromInstruction32(Insn, 4, 1))
2856 index = fieldFromInstruction32(Insn, 6, 2);
2857 if (fieldFromInstruction32(Insn, 4, 1))
2859 if (fieldFromInstruction32(Insn, 5, 1))
2863 if (fieldFromInstruction32(Insn, 5, 1))
2864 return Fail; // UNDEFINED
2865 index = fieldFromInstruction32(Insn, 7, 1);
2866 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2868 if (fieldFromInstruction32(Insn, 6, 1))
2873 if (Rm != 0xF) { // Writeback
2874 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2876 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2877 Inst.addOperand(MCOperand::CreateImm(align));
2878 if (Rm != 0xF && Rm != 0xD) {
2879 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2882 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2883 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2884 Inst.addOperand(MCOperand::CreateImm(index));
2890 static DecodeStatus DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
2891 uint64_t Address, const void *Decoder) {
2892 DecodeStatus S = Success;
2894 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2895 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2896 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2897 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2898 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2907 if (fieldFromInstruction32(Insn, 4, 1))
2908 return Fail; // UNDEFINED
2909 index = fieldFromInstruction32(Insn, 5, 3);
2912 if (fieldFromInstruction32(Insn, 4, 1))
2913 return Fail; // UNDEFINED
2914 index = fieldFromInstruction32(Insn, 6, 2);
2915 if (fieldFromInstruction32(Insn, 5, 1))
2919 if (fieldFromInstruction32(Insn, 4, 2))
2920 return Fail; // UNDEFINED
2921 index = fieldFromInstruction32(Insn, 7, 1);
2922 if (fieldFromInstruction32(Insn, 6, 1))
2927 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2928 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2929 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
2931 if (Rm != 0xF) { // Writeback
2932 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2934 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2935 Inst.addOperand(MCOperand::CreateImm(align));
2936 if (Rm != 0xF && Rm != 0xD) {
2937 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2940 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2941 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2942 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
2943 Inst.addOperand(MCOperand::CreateImm(index));
2948 static DecodeStatus DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
2949 uint64_t Address, const void *Decoder) {
2950 DecodeStatus S = Success;
2952 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2953 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2954 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2955 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2956 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2965 if (fieldFromInstruction32(Insn, 4, 1))
2966 return Fail; // UNDEFINED
2967 index = fieldFromInstruction32(Insn, 5, 3);
2970 if (fieldFromInstruction32(Insn, 4, 1))
2971 return Fail; // UNDEFINED
2972 index = fieldFromInstruction32(Insn, 6, 2);
2973 if (fieldFromInstruction32(Insn, 5, 1))
2977 if (fieldFromInstruction32(Insn, 4, 2))
2978 return Fail; // UNDEFINED
2979 index = fieldFromInstruction32(Insn, 7, 1);
2980 if (fieldFromInstruction32(Insn, 6, 1))
2985 if (Rm != 0xF) { // Writeback
2986 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2988 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2989 Inst.addOperand(MCOperand::CreateImm(align));
2990 if (Rm != 0xF && Rm != 0xD) {
2991 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2994 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2995 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2996 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
2997 Inst.addOperand(MCOperand::CreateImm(index));
3003 static DecodeStatus DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
3004 uint64_t Address, const void *Decoder) {
3005 DecodeStatus S = Success;
3007 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3008 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3009 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3010 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3011 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3020 if (fieldFromInstruction32(Insn, 4, 1))
3022 index = fieldFromInstruction32(Insn, 5, 3);
3025 if (fieldFromInstruction32(Insn, 4, 1))
3027 index = fieldFromInstruction32(Insn, 6, 2);
3028 if (fieldFromInstruction32(Insn, 5, 1))
3032 if (fieldFromInstruction32(Insn, 4, 2))
3033 align = 4 << fieldFromInstruction32(Insn, 4, 2);
3034 index = fieldFromInstruction32(Insn, 7, 1);
3035 if (fieldFromInstruction32(Insn, 6, 1))
3040 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3041 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3042 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3043 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3045 if (Rm != 0xF) { // Writeback
3046 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3048 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3049 Inst.addOperand(MCOperand::CreateImm(align));
3050 if (Rm != 0xF && Rm != 0xD) {
3051 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3054 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3055 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3056 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3057 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3058 Inst.addOperand(MCOperand::CreateImm(index));
3063 static DecodeStatus DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
3064 uint64_t Address, const void *Decoder) {
3065 DecodeStatus S = Success;
3067 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3068 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3069 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3070 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3071 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3080 if (fieldFromInstruction32(Insn, 4, 1))
3082 index = fieldFromInstruction32(Insn, 5, 3);
3085 if (fieldFromInstruction32(Insn, 4, 1))
3087 index = fieldFromInstruction32(Insn, 6, 2);
3088 if (fieldFromInstruction32(Insn, 5, 1))
3092 if (fieldFromInstruction32(Insn, 4, 2))
3093 align = 4 << fieldFromInstruction32(Insn, 4, 2);
3094 index = fieldFromInstruction32(Insn, 7, 1);
3095 if (fieldFromInstruction32(Insn, 6, 1))
3100 if (Rm != 0xF) { // Writeback
3101 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3103 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3104 Inst.addOperand(MCOperand::CreateImm(align));
3105 if (Rm != 0xF && Rm != 0xD) {
3106 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3109 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3110 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3111 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3112 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3113 Inst.addOperand(MCOperand::CreateImm(index));