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,
45 unsigned RegNo, uint64_t Address,
47 static DecodeStatus DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
48 uint64_t Address, const void *Decoder);
49 static DecodeStatus DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
50 uint64_t Address, const void *Decoder);
51 static DecodeStatus DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
52 uint64_t Address, const void *Decoder);
53 static DecodeStatus DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
54 uint64_t Address, const void *Decoder);
55 static DecodeStatus DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
56 uint64_t Address, const void *Decoder);
57 static DecodeStatus DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
58 uint64_t Address, const void *Decoder);
59 static DecodeStatus DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst,
63 static DecodeStatus DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
64 uint64_t Address, const void *Decoder);
66 static DecodeStatus DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
67 uint64_t Address, const void *Decoder);
68 static DecodeStatus DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
69 uint64_t Address, const void *Decoder);
70 static DecodeStatus DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
71 uint64_t Address, const void *Decoder);
72 static DecodeStatus DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
73 uint64_t Address, const void *Decoder);
74 static DecodeStatus DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
75 uint64_t Address, const void *Decoder);
76 static DecodeStatus DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
77 uint64_t Address, const void *Decoder);
78 static DecodeStatus DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
79 uint64_t Address, const void *Decoder);
81 static DecodeStatus DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Insn,
82 uint64_t Address, const void *Decoder);
83 static DecodeStatus DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
84 uint64_t Address, const void *Decoder);
85 static DecodeStatus DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst,
89 static DecodeStatus DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Insn,
90 uint64_t Address, const void *Decoder);
91 static DecodeStatus DecodeAddrMode3Instruction(llvm::MCInst &Inst,unsigned Insn,
92 uint64_t Address, const void *Decoder);
93 static DecodeStatus DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Insn,
94 uint64_t Address, const void *Decoder);
95 static DecodeStatus DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Insn,
96 uint64_t Address, const void *Decoder);
98 static DecodeStatus DecodeMemMultipleWritebackInstruction(llvm::MCInst & Inst,
101 const void *Decoder);
102 static DecodeStatus DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
103 uint64_t Address, const void *Decoder);
104 static DecodeStatus DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
105 uint64_t Address, const void *Decoder);
106 static DecodeStatus DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
107 uint64_t Address, const void *Decoder);
108 static DecodeStatus DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
109 uint64_t Address, const void *Decoder);
110 static DecodeStatus DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
111 uint64_t Address, const void *Decoder);
112 static DecodeStatus DecodeBranchImmInstruction(llvm::MCInst &Inst,unsigned Insn,
113 uint64_t Address, const void *Decoder);
114 static DecodeStatus DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
115 uint64_t Address, const void *Decoder);
116 static DecodeStatus DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
117 uint64_t Address, const void *Decoder);
118 static DecodeStatus DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Val,
119 uint64_t Address, const void *Decoder);
120 static DecodeStatus DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Val,
121 uint64_t Address, const void *Decoder);
122 static DecodeStatus DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Val,
123 uint64_t Address, const void *Decoder);
124 static DecodeStatus DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Val,
125 uint64_t Address, const void *Decoder);
126 static DecodeStatus DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Val,
127 uint64_t Address, const void *Decoder);
128 static DecodeStatus DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Val,
129 uint64_t Address, const void *Decoder);
130 static DecodeStatus DecodeNEONModImmInstruction(llvm::MCInst &Inst,unsigned Val,
131 uint64_t Address, const void *Decoder);
132 static DecodeStatus DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Val,
133 uint64_t Address, const void *Decoder);
134 static DecodeStatus DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
135 uint64_t Address, const void *Decoder);
136 static DecodeStatus DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
137 uint64_t Address, const void *Decoder);
138 static DecodeStatus DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
139 uint64_t Address, const void *Decoder);
140 static DecodeStatus DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
141 uint64_t Address, const void *Decoder);
142 static DecodeStatus DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
143 uint64_t Address, const void *Decoder);
144 static DecodeStatus DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
145 uint64_t Address, const void *Decoder);
146 static DecodeStatus DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
147 uint64_t Address, const void *Decoder);
148 static DecodeStatus DecodeCoprocessor(llvm::MCInst &Inst, unsigned Insn,
149 uint64_t Address, const void *Decoder);
150 static DecodeStatus DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Insn,
151 uint64_t Address, const void *Decoder);
152 static DecodeStatus DecodeMSRMask(llvm::MCInst &Inst, unsigned Insn,
153 uint64_t Address, const void *Decoder);
154 static DecodeStatus DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
155 uint64_t Address, const void *Decoder);
156 static DecodeStatus DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
157 uint64_t Address, const void *Decoder);
158 static DecodeStatus DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
159 uint64_t Address, const void *Decoder);
160 static DecodeStatus DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
161 uint64_t Address, const void *Decoder);
162 static DecodeStatus DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
163 uint64_t Address, const void *Decoder);
164 static DecodeStatus DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
165 uint64_t Address, const void *Decoder);
166 static DecodeStatus DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
167 uint64_t Address, const void *Decoder);
168 static DecodeStatus DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
169 uint64_t Address, const void *Decoder);
170 static DecodeStatus DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
171 uint64_t Address, const void *Decoder);
172 static DecodeStatus DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
173 uint64_t Address, const void *Decoder);
174 static DecodeStatus DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
175 uint64_t Address, const void *Decoder);
176 static DecodeStatus DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
177 uint64_t Address, const void *Decoder);
180 static DecodeStatus DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
181 uint64_t Address, const void *Decoder);
182 static DecodeStatus DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
183 uint64_t Address, const void *Decoder);
184 static DecodeStatus DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
185 uint64_t Address, const void *Decoder);
186 static DecodeStatus DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
187 uint64_t Address, const void *Decoder);
188 static DecodeStatus DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
189 uint64_t Address, const void *Decoder);
190 static DecodeStatus DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
191 uint64_t Address, const void *Decoder);
192 static DecodeStatus DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
193 uint64_t Address, const void *Decoder);
194 static DecodeStatus DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
195 uint64_t Address, const void *Decoder);
196 static DecodeStatus DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
197 uint64_t Address, const void *Decoder);
198 static DecodeStatus DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
199 uint64_t Address, const void *Decoder);
200 static DecodeStatus DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
201 uint64_t Address, const void *Decoder);
202 static DecodeStatus DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
203 uint64_t Address, const void *Decoder);
204 static DecodeStatus DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
205 uint64_t Address, const void *Decoder);
206 static DecodeStatus DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
207 uint64_t Address, const void *Decoder);
208 static DecodeStatus DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
209 uint64_t Address, const void *Decoder);
210 static DecodeStatus DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
211 uint64_t Address, const void *Decoder);
212 static DecodeStatus DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
213 uint64_t Address, const void *Decoder);
214 static DecodeStatus DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
215 uint64_t Address, const void *Decoder);
216 static DecodeStatus DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
217 uint64_t Address, const void *Decoder);
218 static DecodeStatus DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
219 uint64_t Address, const void *Decoder);
220 static DecodeStatus DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
221 uint64_t Address, const void *Decoder);
222 static DecodeStatus DecodeThumbBCCTargetOperand(llvm::MCInst &Inst,unsigned Val,
223 uint64_t Address, const void *Decoder);
224 static DecodeStatus DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
225 uint64_t Address, const void *Decoder);
227 #include "ARMGenDisassemblerTables.inc"
228 #include "ARMGenInstrInfo.inc"
229 #include "ARMGenEDInfo.inc"
231 using namespace llvm;
233 static MCDisassembler *createARMDisassembler(const Target &T) {
234 return new ARMDisassembler;
237 static MCDisassembler *createThumbDisassembler(const Target &T) {
238 return new ThumbDisassembler;
241 EDInstInfo *ARMDisassembler::getEDInfo() const {
245 EDInstInfo *ThumbDisassembler::getEDInfo() const {
249 DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
250 const MemoryObject &Region,
252 raw_ostream &os) const {
255 // We want to read exactly 4 bytes of data.
256 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
259 // Encoded as a small-endian 32-bit word in the stream.
260 uint32_t insn = (bytes[3] << 24) |
265 // Calling the auto-generated decoder function.
266 DecodeStatus result = decodeARMInstruction32(MI, insn, Address, this);
267 if (result != Fail) {
272 // Instructions that are shared between ARM and Thumb modes.
273 // FIXME: This shouldn't really exist. It's an artifact of the
274 // fact that we fail to encode a few instructions properly for Thumb.
276 result = decodeCommonInstruction32(MI, insn, Address, this);
277 if (result != Fail) {
282 // VFP and NEON instructions, similarly, are shared between ARM
285 result = decodeVFPInstruction32(MI, insn, Address, this);
286 if (result != Fail) {
292 result = decodeNEONDataInstruction32(MI, insn, Address, this);
293 if (result != Fail) {
295 // Add a fake predicate operand, because we share these instruction
296 // definitions with Thumb2 where these instructions are predicable.
297 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
302 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this);
303 if (result != Fail) {
305 // Add a fake predicate operand, because we share these instruction
306 // definitions with Thumb2 where these instructions are predicable.
307 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
312 result = decodeNEONDupInstruction32(MI, insn, Address, this);
313 if (result != Fail) {
315 // Add a fake predicate operand, because we share these instruction
316 // definitions with Thumb2 where these instructions are predicable.
317 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
327 extern MCInstrDesc ARMInsts[];
330 // Thumb1 instructions don't have explicit S bits. Rather, they
331 // implicitly set CPSR. Since it's not represented in the encoding, the
332 // auto-generated decoder won't inject the CPSR operand. We need to fix
333 // that as a post-pass.
334 static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
335 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
336 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
337 MCInst::iterator I = MI.begin();
338 for (unsigned i = 0; i < NumOps; ++i, ++I) {
339 if (I == MI.end()) break;
340 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
341 if (i > 0 && OpInfo[i-1].isPredicate()) continue;
342 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
347 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
350 // Most Thumb instructions don't have explicit predicates in the
351 // encoding, but rather get their predicates from IT context. We need
352 // to fix up the predicate operands using this context information as a
354 void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
355 // A few instructions actually have predicates encoded in them. Don't
356 // try to overwrite it if we're seeing one of those.
357 switch (MI.getOpcode()) {
365 // If we're in an IT block, base the predicate on that. Otherwise,
366 // assume a predicate of AL.
368 if (!ITBlock.empty()) {
374 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
375 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
376 MCInst::iterator I = MI.begin();
377 for (unsigned i = 0; i < NumOps; ++i, ++I) {
378 if (I == MI.end()) break;
379 if (OpInfo[i].isPredicate()) {
380 I = MI.insert(I, MCOperand::CreateImm(CC));
383 MI.insert(I, MCOperand::CreateReg(0));
385 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
390 I = MI.insert(I, MCOperand::CreateImm(CC));
393 MI.insert(I, MCOperand::CreateReg(0));
395 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
398 // Thumb VFP instructions are a special case. Because we share their
399 // encodings between ARM and Thumb modes, and they are predicable in ARM
400 // mode, the auto-generated decoder will give them an (incorrect)
401 // predicate operand. We need to rewrite these operands based on the IT
402 // context as a post-pass.
403 void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
405 if (!ITBlock.empty()) {
411 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
412 MCInst::iterator I = MI.begin();
413 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
414 if (OpInfo[i].isPredicate() ) {
420 I->setReg(ARM::CPSR);
426 DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
427 const MemoryObject &Region,
429 raw_ostream &os) const {
432 // We want to read exactly 2 bytes of data.
433 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
436 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
437 DecodeStatus result = decodeThumbInstruction16(MI, insn16, Address, this);
438 if (result != Fail) {
440 AddThumbPredicate(MI);
445 result = decodeThumbSBitInstruction16(MI, insn16, Address, this);
448 bool InITBlock = !ITBlock.empty();
449 AddThumbPredicate(MI);
450 AddThumb1SBit(MI, InITBlock);
455 result = decodeThumb2Instruction16(MI, insn16, Address, this);
456 if (result != Fail) {
458 AddThumbPredicate(MI);
460 // If we find an IT instruction, we need to parse its condition
461 // code and mask operands so that we can apply them correctly
462 // to the subsequent instructions.
463 if (MI.getOpcode() == ARM::t2IT) {
464 unsigned firstcond = MI.getOperand(0).getImm();
465 uint32_t mask = MI.getOperand(1).getImm();
466 unsigned zeros = CountTrailingZeros_32(mask);
469 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
470 if (firstcond ^ (mask & 1))
471 ITBlock.push_back(firstcond ^ 1);
473 ITBlock.push_back(firstcond);
476 ITBlock.push_back(firstcond);
482 // We want to read exactly 4 bytes of data.
483 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
486 uint32_t insn32 = (bytes[3] << 8) |
491 result = decodeThumbInstruction32(MI, insn32, Address, this);
492 if (result != Fail) {
494 bool InITBlock = ITBlock.size();
495 AddThumbPredicate(MI);
496 AddThumb1SBit(MI, InITBlock);
501 result = decodeThumb2Instruction32(MI, insn32, Address, this);
502 if (result != Fail) {
504 AddThumbPredicate(MI);
509 result = decodeCommonInstruction32(MI, insn32, Address, this);
510 if (result != Fail) {
512 AddThumbPredicate(MI);
517 result = decodeVFPInstruction32(MI, insn32, Address, this);
518 if (result != Fail) {
520 UpdateThumbVFPPredicate(MI);
525 result = decodeNEONDupInstruction32(MI, insn32, Address, this);
526 if (result != Fail) {
528 AddThumbPredicate(MI);
532 if (fieldFromInstruction32(insn32, 24, 8) == 0xF9) {
534 uint32_t NEONLdStInsn = insn32;
535 NEONLdStInsn &= 0xF0FFFFFF;
536 NEONLdStInsn |= 0x04000000;
537 result = decodeNEONLoadStoreInstruction32(MI, NEONLdStInsn, Address, this);
538 if (result != Fail) {
540 AddThumbPredicate(MI);
545 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
547 uint32_t NEONDataInsn = insn32;
548 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
549 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
550 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
551 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this);
552 if (result != Fail) {
554 AddThumbPredicate(MI);
563 extern "C" void LLVMInitializeARMDisassembler() {
564 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
565 createARMDisassembler);
566 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
567 createThumbDisassembler);
570 static const unsigned GPRDecoderTable[] = {
571 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
572 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
573 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
574 ARM::R12, ARM::SP, ARM::LR, ARM::PC
577 static DecodeStatus DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
578 uint64_t Address, const void *Decoder) {
582 unsigned Register = GPRDecoderTable[RegNo];
583 Inst.addOperand(MCOperand::CreateReg(Register));
588 DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
589 uint64_t Address, const void *Decoder) {
590 if (RegNo == 15) return Fail;
591 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
594 static DecodeStatus DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
595 uint64_t Address, const void *Decoder) {
598 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
601 static DecodeStatus DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
602 uint64_t Address, const void *Decoder) {
603 unsigned Register = 0;
627 Inst.addOperand(MCOperand::CreateReg(Register));
631 static DecodeStatus DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
632 uint64_t Address, const void *Decoder) {
633 if (RegNo == 13 || RegNo == 15) return Fail;
634 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
637 static const unsigned SPRDecoderTable[] = {
638 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
639 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
640 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
641 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
642 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
643 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
644 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
645 ARM::S28, ARM::S29, ARM::S30, ARM::S31
648 static DecodeStatus DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
649 uint64_t Address, const void *Decoder) {
653 unsigned Register = SPRDecoderTable[RegNo];
654 Inst.addOperand(MCOperand::CreateReg(Register));
658 static const unsigned DPRDecoderTable[] = {
659 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
660 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
661 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
662 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
663 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
664 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
665 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
666 ARM::D28, ARM::D29, ARM::D30, ARM::D31
669 static DecodeStatus DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
670 uint64_t Address, const void *Decoder) {
674 unsigned Register = DPRDecoderTable[RegNo];
675 Inst.addOperand(MCOperand::CreateReg(Register));
679 static DecodeStatus DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
680 uint64_t Address, const void *Decoder) {
683 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
687 DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
688 uint64_t Address, const void *Decoder) {
691 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
694 static const unsigned QPRDecoderTable[] = {
695 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
696 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
697 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
698 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
702 static DecodeStatus DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
703 uint64_t Address, const void *Decoder) {
708 unsigned Register = QPRDecoderTable[RegNo];
709 Inst.addOperand(MCOperand::CreateReg(Register));
713 static DecodeStatus DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
714 uint64_t Address, const void *Decoder) {
715 if (Val == 0xF) return Fail;
716 // AL predicate is not allowed on Thumb1 branches.
717 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
719 Inst.addOperand(MCOperand::CreateImm(Val));
720 if (Val == ARMCC::AL) {
721 Inst.addOperand(MCOperand::CreateReg(0));
723 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
727 static DecodeStatus DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
728 uint64_t Address, const void *Decoder) {
730 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
732 Inst.addOperand(MCOperand::CreateReg(0));
736 static DecodeStatus DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
737 uint64_t Address, const void *Decoder) {
738 uint32_t imm = Val & 0xFF;
739 uint32_t rot = (Val & 0xF00) >> 7;
740 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
741 Inst.addOperand(MCOperand::CreateImm(rot_imm));
745 static DecodeStatus DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
746 uint64_t Address, const void *Decoder) {
748 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
752 static DecodeStatus DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
753 uint64_t Address, const void *Decoder) {
754 DecodeStatus S = Success;
756 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
757 unsigned type = fieldFromInstruction32(Val, 5, 2);
758 unsigned imm = fieldFromInstruction32(Val, 7, 5);
760 // Register-immediate
761 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
763 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
779 if (Shift == ARM_AM::ror && imm == 0)
782 unsigned Op = Shift | (imm << 3);
783 Inst.addOperand(MCOperand::CreateImm(Op));
788 static DecodeStatus DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
789 uint64_t Address, const void *Decoder) {
790 DecodeStatus S = Success;
792 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
793 unsigned type = fieldFromInstruction32(Val, 5, 2);
794 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
797 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
798 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder));
800 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
816 Inst.addOperand(MCOperand::CreateImm(Shift));
821 static DecodeStatus DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
822 uint64_t Address, const void *Decoder) {
823 DecodeStatus S = Success;
825 // Empty register lists are not allowed.
826 if (CountPopulation_32(Val) == 0) return Fail;
827 for (unsigned i = 0; i < 16; ++i) {
828 if (Val & (1 << i)) {
829 CHECK(S, DecodeGPRRegisterClass(Inst, i, Address, Decoder));
836 static DecodeStatus DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
837 uint64_t Address, const void *Decoder) {
838 DecodeStatus S = Success;
840 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
841 unsigned regs = Val & 0xFF;
843 CHECK(S, DecodeSPRRegisterClass(Inst, Vd, Address, Decoder));
844 for (unsigned i = 0; i < (regs - 1); ++i) {
845 CHECK(S, DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder));
851 static DecodeStatus DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
852 uint64_t Address, const void *Decoder) {
853 DecodeStatus S = Success;
855 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
856 unsigned regs = (Val & 0xFF) / 2;
858 CHECK(S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder));
859 for (unsigned i = 0; i < (regs - 1); ++i) {
860 CHECK(S, DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder));
866 static DecodeStatus DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
867 uint64_t Address, const void *Decoder) {
868 // This operand encodes a mask of contiguous zeros between a specified MSB
869 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
870 // the mask of all bits LSB-and-lower, and then xor them to create
871 // the mask of that's all ones on [msb, lsb]. Finally we not it to
872 // create the final mask.
873 unsigned msb = fieldFromInstruction32(Val, 5, 5);
874 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
875 uint32_t msb_mask = (1 << (msb+1)) - 1;
876 uint32_t lsb_mask = (1 << lsb) - 1;
877 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
881 static DecodeStatus DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
882 uint64_t Address, const void *Decoder) {
883 DecodeStatus S = Success;
885 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
886 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
887 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
888 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
889 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
890 unsigned U = fieldFromInstruction32(Insn, 23, 1);
892 switch (Inst.getOpcode()) {
893 case ARM::LDC_OFFSET:
896 case ARM::LDC_OPTION:
897 case ARM::LDCL_OFFSET:
900 case ARM::LDCL_OPTION:
901 case ARM::STC_OFFSET:
904 case ARM::STC_OPTION:
905 case ARM::STCL_OFFSET:
908 case ARM::STCL_OPTION:
909 if (coproc == 0xA || coproc == 0xB)
916 Inst.addOperand(MCOperand::CreateImm(coproc));
917 Inst.addOperand(MCOperand::CreateImm(CRd));
918 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
919 switch (Inst.getOpcode()) {
920 case ARM::LDC_OPTION:
921 case ARM::LDCL_OPTION:
922 case ARM::LDC2_OPTION:
923 case ARM::LDC2L_OPTION:
924 case ARM::STC_OPTION:
925 case ARM::STCL_OPTION:
926 case ARM::STC2_OPTION:
927 case ARM::STC2L_OPTION:
932 Inst.addOperand(MCOperand::CreateReg(0));
936 unsigned P = fieldFromInstruction32(Insn, 24, 1);
937 unsigned W = fieldFromInstruction32(Insn, 21, 1);
939 bool writeback = (P == 0) || (W == 1);
940 unsigned idx_mode = 0;
942 idx_mode = ARMII::IndexModePre;
943 else if (!P && writeback)
944 idx_mode = ARMII::IndexModePost;
946 switch (Inst.getOpcode()) {
950 case ARM::LDC_OPTION:
951 case ARM::LDCL_OPTION:
952 case ARM::LDC2_OPTION:
953 case ARM::LDC2L_OPTION:
954 case ARM::STC_OPTION:
955 case ARM::STCL_OPTION:
956 case ARM::STC2_OPTION:
957 case ARM::STC2L_OPTION:
958 Inst.addOperand(MCOperand::CreateImm(imm));
962 Inst.addOperand(MCOperand::CreateImm(
963 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
965 Inst.addOperand(MCOperand::CreateImm(
966 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
970 switch (Inst.getOpcode()) {
971 case ARM::LDC_OFFSET:
974 case ARM::LDC_OPTION:
975 case ARM::LDCL_OFFSET:
978 case ARM::LDCL_OPTION:
979 case ARM::STC_OFFSET:
982 case ARM::STC_OPTION:
983 case ARM::STCL_OFFSET:
986 case ARM::STCL_OPTION:
987 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
997 DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
998 uint64_t Address, const void *Decoder) {
999 DecodeStatus S = Success;
1001 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1002 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1003 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1004 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
1005 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1006 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
1007 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1008 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1010 // On stores, the writeback operand precedes Rt.
1011 switch (Inst.getOpcode()) {
1012 case ARM::STR_POST_IMM:
1013 case ARM::STR_POST_REG:
1014 case ARM::STRB_POST_IMM:
1015 case ARM::STRB_POST_REG:
1016 case ARM::STRT_POST_REG:
1017 case ARM::STRT_POST_IMM:
1018 case ARM::STRBT_POST_REG:
1019 case ARM::STRBT_POST_IMM:
1020 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1026 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
1028 // On loads, the writeback operand comes after Rt.
1029 switch (Inst.getOpcode()) {
1030 case ARM::LDR_POST_IMM:
1031 case ARM::LDR_POST_REG:
1032 case ARM::LDRB_POST_IMM:
1033 case ARM::LDRB_POST_REG:
1036 case ARM::LDRBT_POST_REG:
1037 case ARM::LDRBT_POST_IMM:
1038 case ARM::LDRT_POST_REG:
1039 case ARM::LDRT_POST_IMM:
1040 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1046 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1048 ARM_AM::AddrOpc Op = ARM_AM::add;
1049 if (!fieldFromInstruction32(Insn, 23, 1))
1052 bool writeback = (P == 0) || (W == 1);
1053 unsigned idx_mode = 0;
1055 idx_mode = ARMII::IndexModePre;
1056 else if (!P && writeback)
1057 idx_mode = ARMII::IndexModePost;
1059 if (writeback && (Rn == 15 || Rn == Rt)) S = Unpredictable; // UNPREDICTABLE
1062 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
1063 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
1064 switch( fieldFromInstruction32(Insn, 5, 2)) {
1080 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1081 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1083 Inst.addOperand(MCOperand::CreateImm(imm));
1085 Inst.addOperand(MCOperand::CreateReg(0));
1086 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1087 Inst.addOperand(MCOperand::CreateImm(tmp));
1090 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1095 static DecodeStatus DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
1096 uint64_t Address, const void *Decoder) {
1097 DecodeStatus S = Success;
1099 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1100 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1101 unsigned type = fieldFromInstruction32(Val, 5, 2);
1102 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1103 unsigned U = fieldFromInstruction32(Val, 12, 1);
1105 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
1121 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1122 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1125 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1127 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1128 Inst.addOperand(MCOperand::CreateImm(shift));
1134 DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
1135 uint64_t Address, const void *Decoder) {
1136 DecodeStatus S = Success;
1138 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1139 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1140 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1141 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1142 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1143 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1144 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1145 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1146 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1148 bool writeback = (W == 1) | (P == 0);
1150 // For {LD,ST}RD, Rt must be even, else undefined.
1151 switch (Inst.getOpcode()) {
1154 case ARM::STRD_POST:
1157 case ARM::LDRD_POST:
1158 if (Rt & 0x1) return Fail;
1164 if (writeback) { // Writeback
1166 U |= ARMII::IndexModePre << 9;
1168 U |= ARMII::IndexModePost << 9;
1170 // On stores, the writeback operand precedes Rt.
1171 switch (Inst.getOpcode()) {
1174 case ARM::STRD_POST:
1177 case ARM::STRH_POST:
1178 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1185 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
1186 switch (Inst.getOpcode()) {
1189 case ARM::STRD_POST:
1192 case ARM::LDRD_POST:
1193 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
1200 // On loads, the writeback operand comes after Rt.
1201 switch (Inst.getOpcode()) {
1204 case ARM::LDRD_POST:
1207 case ARM::LDRH_POST:
1209 case ARM::LDRSH_PRE:
1210 case ARM::LDRSH_POST:
1212 case ARM::LDRSB_PRE:
1213 case ARM::LDRSB_POST:
1216 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1223 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1226 Inst.addOperand(MCOperand::CreateReg(0));
1227 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1229 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1230 Inst.addOperand(MCOperand::CreateImm(U));
1233 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1238 static DecodeStatus DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1239 uint64_t Address, const void *Decoder) {
1240 DecodeStatus S = Success;
1242 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1243 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1260 Inst.addOperand(MCOperand::CreateImm(mode));
1261 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1266 static DecodeStatus DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1268 uint64_t Address, const void *Decoder) {
1269 DecodeStatus S = Success;
1271 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1272 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1273 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1276 switch (Inst.getOpcode()) {
1278 Inst.setOpcode(ARM::RFEDA);
1280 case ARM::STMDA_UPD:
1281 Inst.setOpcode(ARM::RFEDA_UPD);
1284 Inst.setOpcode(ARM::RFEDB);
1286 case ARM::STMDB_UPD:
1287 Inst.setOpcode(ARM::RFEDB_UPD);
1290 Inst.setOpcode(ARM::RFEIA);
1292 case ARM::STMIA_UPD:
1293 Inst.setOpcode(ARM::RFEIA_UPD);
1296 Inst.setOpcode(ARM::RFEIB);
1298 case ARM::STMIB_UPD:
1299 Inst.setOpcode(ARM::RFEIB_UPD);
1302 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1305 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1306 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)); // Tied
1307 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1308 CHECK(S, DecodeRegListOperand(Inst, reglist, Address, Decoder));
1313 static DecodeStatus DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1314 uint64_t Address, const void *Decoder) {
1315 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1316 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1317 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1318 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1320 DecodeStatus S = Success;
1322 // imod == '01' --> UNPREDICTABLE
1323 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1324 // return failure here. The '01' imod value is unprintable, so there's
1325 // nothing useful we could do even if we returned UNPREDICTABLE.
1327 if (imod == 1) CHECK(S, Fail);
1330 Inst.setOpcode(ARM::CPS3p);
1331 Inst.addOperand(MCOperand::CreateImm(imod));
1332 Inst.addOperand(MCOperand::CreateImm(iflags));
1333 Inst.addOperand(MCOperand::CreateImm(mode));
1334 } else if (imod && !M) {
1335 Inst.setOpcode(ARM::CPS2p);
1336 Inst.addOperand(MCOperand::CreateImm(imod));
1337 Inst.addOperand(MCOperand::CreateImm(iflags));
1338 if (mode) CHECK(S, Unpredictable);
1339 } else if (!imod && M) {
1340 Inst.setOpcode(ARM::CPS1p);
1341 Inst.addOperand(MCOperand::CreateImm(mode));
1342 if (iflags) CHECK(S, Unpredictable);
1344 // imod == '00' && M == '0' --> UNPREDICTABLE
1345 Inst.setOpcode(ARM::CPS1p);
1346 Inst.addOperand(MCOperand::CreateImm(mode));
1347 CHECK(S, Unpredictable);
1353 static DecodeStatus DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1354 uint64_t Address, const void *Decoder) {
1355 DecodeStatus S = Success;
1357 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1358 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1359 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1360 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1361 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1364 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1366 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder));
1367 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder));
1368 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
1369 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder));
1371 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1376 static DecodeStatus DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1377 uint64_t Address, const void *Decoder) {
1378 DecodeStatus S = Success;
1380 unsigned add = fieldFromInstruction32(Val, 12, 1);
1381 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1382 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1384 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1386 if (!add) imm *= -1;
1387 if (imm == 0 && !add) imm = INT32_MIN;
1388 Inst.addOperand(MCOperand::CreateImm(imm));
1393 static DecodeStatus DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1394 uint64_t Address, const void *Decoder) {
1395 DecodeStatus S = Success;
1397 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1398 unsigned U = fieldFromInstruction32(Val, 8, 1);
1399 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1401 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1404 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1406 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1411 static DecodeStatus DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1412 uint64_t Address, const void *Decoder) {
1413 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1417 DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1418 uint64_t Address, const void *Decoder) {
1419 DecodeStatus S = Success;
1421 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1422 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1425 Inst.setOpcode(ARM::BLXi);
1426 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
1427 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1431 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1432 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1438 static DecodeStatus DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1439 uint64_t Address, const void *Decoder) {
1440 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1444 static DecodeStatus DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1445 uint64_t Address, const void *Decoder) {
1446 DecodeStatus S = Success;
1448 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1449 unsigned align = fieldFromInstruction32(Val, 4, 2);
1451 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1453 Inst.addOperand(MCOperand::CreateImm(0));
1455 Inst.addOperand(MCOperand::CreateImm(4 << align));
1460 static DecodeStatus DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1461 uint64_t Address, const void *Decoder) {
1462 DecodeStatus S = Success;
1464 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1465 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1466 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1467 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1468 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1469 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1471 // First output register
1472 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1474 // Second output register
1475 switch (Inst.getOpcode()) {
1480 case ARM::VLD1q8_UPD:
1481 case ARM::VLD1q16_UPD:
1482 case ARM::VLD1q32_UPD:
1483 case ARM::VLD1q64_UPD:
1488 case ARM::VLD1d8T_UPD:
1489 case ARM::VLD1d16T_UPD:
1490 case ARM::VLD1d32T_UPD:
1491 case ARM::VLD1d64T_UPD:
1496 case ARM::VLD1d8Q_UPD:
1497 case ARM::VLD1d16Q_UPD:
1498 case ARM::VLD1d32Q_UPD:
1499 case ARM::VLD1d64Q_UPD:
1503 case ARM::VLD2d8_UPD:
1504 case ARM::VLD2d16_UPD:
1505 case ARM::VLD2d32_UPD:
1509 case ARM::VLD2q8_UPD:
1510 case ARM::VLD2q16_UPD:
1511 case ARM::VLD2q32_UPD:
1515 case ARM::VLD3d8_UPD:
1516 case ARM::VLD3d16_UPD:
1517 case ARM::VLD3d32_UPD:
1521 case ARM::VLD4d8_UPD:
1522 case ARM::VLD4d16_UPD:
1523 case ARM::VLD4d32_UPD:
1524 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1529 case ARM::VLD2b8_UPD:
1530 case ARM::VLD2b16_UPD:
1531 case ARM::VLD2b32_UPD:
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 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1549 // Third output register
1550 switch(Inst.getOpcode()) {
1555 case ARM::VLD1d8T_UPD:
1556 case ARM::VLD1d16T_UPD:
1557 case ARM::VLD1d32T_UPD:
1558 case ARM::VLD1d64T_UPD:
1563 case ARM::VLD1d8Q_UPD:
1564 case ARM::VLD1d16Q_UPD:
1565 case ARM::VLD1d32Q_UPD:
1566 case ARM::VLD1d64Q_UPD:
1570 case ARM::VLD2q8_UPD:
1571 case ARM::VLD2q16_UPD:
1572 case ARM::VLD2q32_UPD:
1576 case ARM::VLD3d8_UPD:
1577 case ARM::VLD3d16_UPD:
1578 case ARM::VLD3d32_UPD:
1582 case ARM::VLD4d8_UPD:
1583 case ARM::VLD4d16_UPD:
1584 case ARM::VLD4d32_UPD:
1585 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1590 case ARM::VLD3q8_UPD:
1591 case ARM::VLD3q16_UPD:
1592 case ARM::VLD3q32_UPD:
1596 case ARM::VLD4q8_UPD:
1597 case ARM::VLD4q16_UPD:
1598 case ARM::VLD4q32_UPD:
1599 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder));
1605 // Fourth output register
1606 switch (Inst.getOpcode()) {
1611 case ARM::VLD1d8Q_UPD:
1612 case ARM::VLD1d16Q_UPD:
1613 case ARM::VLD1d32Q_UPD:
1614 case ARM::VLD1d64Q_UPD:
1618 case ARM::VLD2q8_UPD:
1619 case ARM::VLD2q16_UPD:
1620 case ARM::VLD2q32_UPD:
1624 case ARM::VLD4d8_UPD:
1625 case ARM::VLD4d16_UPD:
1626 case ARM::VLD4d32_UPD:
1627 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder));
1632 case ARM::VLD4q8_UPD:
1633 case ARM::VLD4q16_UPD:
1634 case ARM::VLD4q32_UPD:
1635 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder));
1641 // Writeback operand
1642 switch (Inst.getOpcode()) {
1643 case ARM::VLD1d8_UPD:
1644 case ARM::VLD1d16_UPD:
1645 case ARM::VLD1d32_UPD:
1646 case ARM::VLD1d64_UPD:
1647 case ARM::VLD1q8_UPD:
1648 case ARM::VLD1q16_UPD:
1649 case ARM::VLD1q32_UPD:
1650 case ARM::VLD1q64_UPD:
1651 case ARM::VLD1d8T_UPD:
1652 case ARM::VLD1d16T_UPD:
1653 case ARM::VLD1d32T_UPD:
1654 case ARM::VLD1d64T_UPD:
1655 case ARM::VLD1d8Q_UPD:
1656 case ARM::VLD1d16Q_UPD:
1657 case ARM::VLD1d32Q_UPD:
1658 case ARM::VLD1d64Q_UPD:
1659 case ARM::VLD2d8_UPD:
1660 case ARM::VLD2d16_UPD:
1661 case ARM::VLD2d32_UPD:
1662 case ARM::VLD2q8_UPD:
1663 case ARM::VLD2q16_UPD:
1664 case ARM::VLD2q32_UPD:
1665 case ARM::VLD2b8_UPD:
1666 case ARM::VLD2b16_UPD:
1667 case ARM::VLD2b32_UPD:
1668 case ARM::VLD3d8_UPD:
1669 case ARM::VLD3d16_UPD:
1670 case ARM::VLD3d32_UPD:
1671 case ARM::VLD3q8_UPD:
1672 case ARM::VLD3q16_UPD:
1673 case ARM::VLD3q32_UPD:
1674 case ARM::VLD4d8_UPD:
1675 case ARM::VLD4d16_UPD:
1676 case ARM::VLD4d32_UPD:
1677 case ARM::VLD4q8_UPD:
1678 case ARM::VLD4q16_UPD:
1679 case ARM::VLD4q32_UPD:
1680 CHECK(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder));
1686 // AddrMode6 Base (register+alignment)
1687 CHECK(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder));
1689 // AddrMode6 Offset (register)
1691 Inst.addOperand(MCOperand::CreateReg(0));
1692 else if (Rm != 0xF) {
1693 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1699 static DecodeStatus DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1700 uint64_t Address, const void *Decoder) {
1701 DecodeStatus S = Success;
1703 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1704 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1705 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1706 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1707 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1708 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1710 // Writeback Operand
1711 switch (Inst.getOpcode()) {
1712 case ARM::VST1d8_UPD:
1713 case ARM::VST1d16_UPD:
1714 case ARM::VST1d32_UPD:
1715 case ARM::VST1d64_UPD:
1716 case ARM::VST1q8_UPD:
1717 case ARM::VST1q16_UPD:
1718 case ARM::VST1q32_UPD:
1719 case ARM::VST1q64_UPD:
1720 case ARM::VST1d8T_UPD:
1721 case ARM::VST1d16T_UPD:
1722 case ARM::VST1d32T_UPD:
1723 case ARM::VST1d64T_UPD:
1724 case ARM::VST1d8Q_UPD:
1725 case ARM::VST1d16Q_UPD:
1726 case ARM::VST1d32Q_UPD:
1727 case ARM::VST1d64Q_UPD:
1728 case ARM::VST2d8_UPD:
1729 case ARM::VST2d16_UPD:
1730 case ARM::VST2d32_UPD:
1731 case ARM::VST2q8_UPD:
1732 case ARM::VST2q16_UPD:
1733 case ARM::VST2q32_UPD:
1734 case ARM::VST2b8_UPD:
1735 case ARM::VST2b16_UPD:
1736 case ARM::VST2b32_UPD:
1737 case ARM::VST3d8_UPD:
1738 case ARM::VST3d16_UPD:
1739 case ARM::VST3d32_UPD:
1740 case ARM::VST3q8_UPD:
1741 case ARM::VST3q16_UPD:
1742 case ARM::VST3q32_UPD:
1743 case ARM::VST4d8_UPD:
1744 case ARM::VST4d16_UPD:
1745 case ARM::VST4d32_UPD:
1746 case ARM::VST4q8_UPD:
1747 case ARM::VST4q16_UPD:
1748 case ARM::VST4q32_UPD:
1749 CHECK(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder));
1755 // AddrMode6 Base (register+alignment)
1756 CHECK(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder));
1758 // AddrMode6 Offset (register)
1760 Inst.addOperand(MCOperand::CreateReg(0));
1761 else if (Rm != 0xF) {
1762 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1765 // First input register
1766 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1768 // Second input register
1769 switch (Inst.getOpcode()) {
1774 case ARM::VST1q8_UPD:
1775 case ARM::VST1q16_UPD:
1776 case ARM::VST1q32_UPD:
1777 case ARM::VST1q64_UPD:
1782 case ARM::VST1d8T_UPD:
1783 case ARM::VST1d16T_UPD:
1784 case ARM::VST1d32T_UPD:
1785 case ARM::VST1d64T_UPD:
1790 case ARM::VST1d8Q_UPD:
1791 case ARM::VST1d16Q_UPD:
1792 case ARM::VST1d32Q_UPD:
1793 case ARM::VST1d64Q_UPD:
1797 case ARM::VST2d8_UPD:
1798 case ARM::VST2d16_UPD:
1799 case ARM::VST2d32_UPD:
1803 case ARM::VST2q8_UPD:
1804 case ARM::VST2q16_UPD:
1805 case ARM::VST2q32_UPD:
1809 case ARM::VST3d8_UPD:
1810 case ARM::VST3d16_UPD:
1811 case ARM::VST3d32_UPD:
1815 case ARM::VST4d8_UPD:
1816 case ARM::VST4d16_UPD:
1817 case ARM::VST4d32_UPD:
1818 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1823 case ARM::VST2b8_UPD:
1824 case ARM::VST2b16_UPD:
1825 case ARM::VST2b32_UPD:
1829 case ARM::VST3q8_UPD:
1830 case ARM::VST3q16_UPD:
1831 case ARM::VST3q32_UPD:
1835 case ARM::VST4q8_UPD:
1836 case ARM::VST4q16_UPD:
1837 case ARM::VST4q32_UPD:
1838 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1844 // Third input register
1845 switch (Inst.getOpcode()) {
1850 case ARM::VST1d8T_UPD:
1851 case ARM::VST1d16T_UPD:
1852 case ARM::VST1d32T_UPD:
1853 case ARM::VST1d64T_UPD:
1858 case ARM::VST1d8Q_UPD:
1859 case ARM::VST1d16Q_UPD:
1860 case ARM::VST1d32Q_UPD:
1861 case ARM::VST1d64Q_UPD:
1865 case ARM::VST2q8_UPD:
1866 case ARM::VST2q16_UPD:
1867 case ARM::VST2q32_UPD:
1871 case ARM::VST3d8_UPD:
1872 case ARM::VST3d16_UPD:
1873 case ARM::VST3d32_UPD:
1877 case ARM::VST4d8_UPD:
1878 case ARM::VST4d16_UPD:
1879 case ARM::VST4d32_UPD:
1880 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1885 case ARM::VST3q8_UPD:
1886 case ARM::VST3q16_UPD:
1887 case ARM::VST3q32_UPD:
1891 case ARM::VST4q8_UPD:
1892 case ARM::VST4q16_UPD:
1893 case ARM::VST4q32_UPD:
1894 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder));
1900 // Fourth input register
1901 switch (Inst.getOpcode()) {
1906 case ARM::VST1d8Q_UPD:
1907 case ARM::VST1d16Q_UPD:
1908 case ARM::VST1d32Q_UPD:
1909 case ARM::VST1d64Q_UPD:
1913 case ARM::VST2q8_UPD:
1914 case ARM::VST2q16_UPD:
1915 case ARM::VST2q32_UPD:
1919 case ARM::VST4d8_UPD:
1920 case ARM::VST4d16_UPD:
1921 case ARM::VST4d32_UPD:
1922 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder));
1927 case ARM::VST4q8_UPD:
1928 case ARM::VST4q16_UPD:
1929 case ARM::VST4q32_UPD:
1930 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder));
1939 static DecodeStatus DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1940 uint64_t Address, const void *Decoder) {
1941 DecodeStatus S = Success;
1943 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1944 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1945 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1946 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1947 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1948 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1949 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
1951 align *= (1 << size);
1953 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1955 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1958 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1961 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1962 Inst.addOperand(MCOperand::CreateImm(align));
1965 Inst.addOperand(MCOperand::CreateReg(0));
1966 else if (Rm != 0xF) {
1967 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1973 static DecodeStatus DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1974 uint64_t Address, const void *Decoder) {
1975 DecodeStatus S = Success;
1977 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1978 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1979 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1980 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1981 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1982 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
1983 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1986 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1987 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
1989 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1992 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1993 Inst.addOperand(MCOperand::CreateImm(align));
1996 Inst.addOperand(MCOperand::CreateReg(0));
1997 else if (Rm != 0xF) {
1998 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2004 static DecodeStatus DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
2005 uint64_t Address, const void *Decoder) {
2006 DecodeStatus S = Success;
2008 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2009 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2010 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2011 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2012 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2014 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2015 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
2016 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder));
2018 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2021 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2022 Inst.addOperand(MCOperand::CreateImm(0));
2025 Inst.addOperand(MCOperand::CreateReg(0));
2026 else if (Rm != 0xF) {
2027 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2033 static DecodeStatus DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
2034 uint64_t Address, const void *Decoder) {
2035 DecodeStatus S = Success;
2037 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2038 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2039 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2040 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2041 unsigned size = fieldFromInstruction32(Insn, 6, 2);
2042 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2043 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2058 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2059 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
2060 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder));
2061 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder));
2063 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2066 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2067 Inst.addOperand(MCOperand::CreateImm(align));
2070 Inst.addOperand(MCOperand::CreateReg(0));
2071 else if (Rm != 0xF) {
2072 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2079 DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
2080 uint64_t Address, const void *Decoder) {
2081 DecodeStatus S = Success;
2083 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2084 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2085 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2086 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
2087 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
2088 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
2089 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
2090 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
2093 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2095 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2098 Inst.addOperand(MCOperand::CreateImm(imm));
2100 switch (Inst.getOpcode()) {
2101 case ARM::VORRiv4i16:
2102 case ARM::VORRiv2i32:
2103 case ARM::VBICiv4i16:
2104 case ARM::VBICiv2i32:
2105 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2107 case ARM::VORRiv8i16:
2108 case ARM::VORRiv4i32:
2109 case ARM::VBICiv8i16:
2110 case ARM::VBICiv4i32:
2111 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2120 static DecodeStatus DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
2121 uint64_t Address, const void *Decoder) {
2122 DecodeStatus S = Success;
2124 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2125 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2126 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2127 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2128 unsigned size = fieldFromInstruction32(Insn, 18, 2);
2130 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2131 CHECK(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder));
2132 Inst.addOperand(MCOperand::CreateImm(8 << size));
2137 static DecodeStatus DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
2138 uint64_t Address, const void *Decoder) {
2139 Inst.addOperand(MCOperand::CreateImm(8 - Val));
2143 static DecodeStatus DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
2144 uint64_t Address, const void *Decoder) {
2145 Inst.addOperand(MCOperand::CreateImm(16 - Val));
2149 static DecodeStatus DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
2150 uint64_t Address, const void *Decoder) {
2151 Inst.addOperand(MCOperand::CreateImm(32 - Val));
2155 static DecodeStatus DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
2156 uint64_t Address, const void *Decoder) {
2157 Inst.addOperand(MCOperand::CreateImm(64 - Val));
2161 static DecodeStatus DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
2162 uint64_t Address, const void *Decoder) {
2163 DecodeStatus S = Success;
2165 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2166 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2167 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2168 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2169 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2170 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2171 unsigned op = fieldFromInstruction32(Insn, 6, 1);
2172 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
2174 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2176 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)); // Writeback
2179 for (unsigned i = 0; i < length; ++i) {
2180 CHECK(S, DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder));
2183 CHECK(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder));
2188 static DecodeStatus DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
2189 uint64_t Address, const void *Decoder) {
2190 // The immediate needs to be a fully instantiated float. However, the
2191 // auto-generated decoder is only able to fill in some of the bits
2192 // necessary. For instance, the 'b' bit is replicated multiple times,
2193 // and is even present in inverted form in one bit. We do a little
2194 // binary parsing here to fill in those missing bits, and then
2195 // reinterpret it all as a float.
2201 fp_conv.integer = Val;
2202 uint32_t b = fieldFromInstruction32(Val, 25, 1);
2203 fp_conv.integer |= b << 26;
2204 fp_conv.integer |= b << 27;
2205 fp_conv.integer |= b << 28;
2206 fp_conv.integer |= b << 29;
2207 fp_conv.integer |= (~b & 0x1) << 30;
2209 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
2213 static DecodeStatus DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
2214 uint64_t Address, const void *Decoder) {
2215 DecodeStatus S = Success;
2217 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2218 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2220 CHECK(S, DecodetGPRRegisterClass(Inst, dst, Address, Decoder));
2222 if (Inst.getOpcode() == ARM::tADR)
2223 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2224 else if (Inst.getOpcode() == ARM::tADDrSPi)
2225 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2229 Inst.addOperand(MCOperand::CreateImm(imm));
2233 static DecodeStatus DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
2234 uint64_t Address, const void *Decoder) {
2235 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
2239 static DecodeStatus DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
2240 uint64_t Address, const void *Decoder) {
2241 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2245 static DecodeStatus DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2246 uint64_t Address, const void *Decoder) {
2247 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2251 static DecodeStatus DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2252 uint64_t Address, const void *Decoder) {
2253 DecodeStatus S = Success;
2255 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2256 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2258 CHECK(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder));
2259 CHECK(S, DecodetGPRRegisterClass(Inst, Rm, Address, Decoder));
2264 static DecodeStatus DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2265 uint64_t Address, const void *Decoder) {
2266 DecodeStatus S = Success;
2268 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2269 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2271 CHECK(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder));
2272 Inst.addOperand(MCOperand::CreateImm(imm));
2277 static DecodeStatus DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2278 uint64_t Address, const void *Decoder) {
2279 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2284 static DecodeStatus DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2285 uint64_t Address, const void *Decoder) {
2286 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2287 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2292 static DecodeStatus DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2293 uint64_t Address, const void *Decoder) {
2294 DecodeStatus S = Success;
2296 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2297 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2298 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2300 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2301 CHECK(S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder));
2302 Inst.addOperand(MCOperand::CreateImm(imm));
2307 static DecodeStatus DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2308 uint64_t Address, const void *Decoder) {
2309 DecodeStatus S = Success;
2311 if (Inst.getOpcode() != ARM::t2PLDs) {
2312 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2313 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2316 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2318 switch (Inst.getOpcode()) {
2320 Inst.setOpcode(ARM::t2LDRBpci);
2323 Inst.setOpcode(ARM::t2LDRHpci);
2326 Inst.setOpcode(ARM::t2LDRSHpci);
2329 Inst.setOpcode(ARM::t2LDRSBpci);
2332 Inst.setOpcode(ARM::t2PLDi12);
2333 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2339 int imm = fieldFromInstruction32(Insn, 0, 12);
2340 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2341 Inst.addOperand(MCOperand::CreateImm(imm));
2346 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2347 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2348 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2349 CHECK(S, DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder));
2354 static DecodeStatus DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
2355 uint64_t Address, const void *Decoder) {
2356 int imm = Val & 0xFF;
2357 if (!(Val & 0x100)) imm *= -1;
2358 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2363 static DecodeStatus DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2364 uint64_t Address, const void *Decoder) {
2365 DecodeStatus S = Success;
2367 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2368 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2370 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2371 CHECK(S, DecodeT2Imm8S4(Inst, imm, Address, Decoder));
2376 static DecodeStatus DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
2377 uint64_t Address, const void *Decoder) {
2378 int imm = Val & 0xFF;
2379 if (!(Val & 0x100)) imm *= -1;
2380 Inst.addOperand(MCOperand::CreateImm(imm));
2386 static DecodeStatus DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
2387 uint64_t Address, const void *Decoder) {
2388 DecodeStatus S = Success;
2390 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2391 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2393 // Some instructions always use an additive offset.
2394 switch (Inst.getOpcode()) {
2406 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2407 CHECK(S, DecodeT2Imm8(Inst, imm, Address, Decoder));
2413 static DecodeStatus DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
2414 uint64_t Address, const void *Decoder) {
2415 DecodeStatus S = Success;
2417 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2418 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2420 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2421 Inst.addOperand(MCOperand::CreateImm(imm));
2427 static DecodeStatus DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
2428 uint64_t Address, const void *Decoder) {
2429 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2431 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2432 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2433 Inst.addOperand(MCOperand::CreateImm(imm));
2438 static DecodeStatus DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
2439 uint64_t Address, const void *Decoder) {
2440 DecodeStatus S = Success;
2442 if (Inst.getOpcode() == ARM::tADDrSP) {
2443 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2444 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2446 CHECK(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder));
2447 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2448 CHECK(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder));
2449 } else if (Inst.getOpcode() == ARM::tADDspr) {
2450 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2452 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2453 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2454 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2460 static DecodeStatus DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
2461 uint64_t Address, const void *Decoder) {
2462 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2463 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2465 Inst.addOperand(MCOperand::CreateImm(imod));
2466 Inst.addOperand(MCOperand::CreateImm(flags));
2471 static DecodeStatus DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
2472 uint64_t Address, const void *Decoder) {
2473 DecodeStatus S = Success;
2474 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2475 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2477 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) ;
2478 Inst.addOperand(MCOperand::CreateImm(add));
2483 static DecodeStatus DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
2484 uint64_t Address, const void *Decoder) {
2485 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2489 static DecodeStatus DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2490 uint64_t Address, const void *Decoder) {
2491 if (Val == 0xA || Val == 0xB)
2494 Inst.addOperand(MCOperand::CreateImm(Val));
2499 DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2500 uint64_t Address, const void *Decoder) {
2501 DecodeStatus S = Success;
2503 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2504 if (pred == 0xE || pred == 0xF) {
2505 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2510 Inst.setOpcode(ARM::t2DSB);
2513 Inst.setOpcode(ARM::t2DMB);
2516 Inst.setOpcode(ARM::t2ISB);
2520 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2521 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
2524 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2525 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2526 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2527 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2528 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2530 CHECK(S, DecodeT2BROperand(Inst, brtarget, Address, Decoder));
2531 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2536 // Decode a shifted immediate operand. These basically consist
2537 // of an 8-bit value, and a 4-bit directive that specifies either
2538 // a splat operation or a rotation.
2539 static DecodeStatus DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2540 uint64_t Address, const void *Decoder) {
2541 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2543 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2544 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2547 Inst.addOperand(MCOperand::CreateImm(imm));
2550 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2553 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2556 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2561 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2562 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2563 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2564 Inst.addOperand(MCOperand::CreateImm(imm));
2571 DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2572 uint64_t Address, const void *Decoder){
2573 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2577 static DecodeStatus DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
2578 uint64_t Address, const void *Decoder){
2579 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2583 static DecodeStatus DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Val,
2584 uint64_t Address, const void *Decoder) {
2599 Inst.addOperand(MCOperand::CreateImm(Val));
2603 static DecodeStatus DecodeMSRMask(llvm::MCInst &Inst, unsigned Val,
2604 uint64_t Address, const void *Decoder) {
2605 if (!Val) return Fail;
2606 Inst.addOperand(MCOperand::CreateImm(Val));
2610 static DecodeStatus DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
2611 uint64_t Address, const void *Decoder) {
2612 DecodeStatus S = Success;
2614 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2615 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2616 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2618 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return Fail;
2620 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2621 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
2622 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2623 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2629 static DecodeStatus DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
2630 uint64_t Address, const void *Decoder){
2631 DecodeStatus S = Success;
2633 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2634 unsigned Rt = fieldFromInstruction32(Insn, 0, 4);
2635 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2636 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2638 CHECK(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder));
2640 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return Fail;
2641 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return Fail;
2643 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2644 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
2645 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2646 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2651 static DecodeStatus DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
2652 uint64_t Address, const void *Decoder) {
2653 DecodeStatus S = Success;
2655 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2656 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2657 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2658 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2659 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2660 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2662 if (Rn == 0xF || Rn == Rt) CHECK(S, Unpredictable);
2664 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2665 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2666 CHECK(S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder));
2667 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2672 static DecodeStatus DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
2673 uint64_t Address, const void *Decoder) {
2674 DecodeStatus S = Success;
2676 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2677 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2678 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2679 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2680 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2681 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2683 if (Rn == 0xF || Rn == Rt) CHECK(S, Unpredictable);
2685 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2686 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2687 CHECK(S, DecodeSORegMemOperand(Inst, imm, Address, Decoder));
2688 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2693 static DecodeStatus DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
2694 uint64_t Address, const void *Decoder) {
2695 DecodeStatus S = Success;
2697 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2698 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2699 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2700 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2701 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2709 if (fieldFromInstruction32(Insn, 4, 1))
2710 return Fail; // UNDEFINED
2711 index = fieldFromInstruction32(Insn, 5, 3);
2714 if (fieldFromInstruction32(Insn, 5, 1))
2715 return Fail; // UNDEFINED
2716 index = fieldFromInstruction32(Insn, 6, 2);
2717 if (fieldFromInstruction32(Insn, 4, 1))
2721 if (fieldFromInstruction32(Insn, 6, 1))
2722 return Fail; // UNDEFINED
2723 index = fieldFromInstruction32(Insn, 7, 1);
2724 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2728 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2729 if (Rm != 0xF) { // Writeback
2730 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2732 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2733 Inst.addOperand(MCOperand::CreateImm(align));
2734 if (Rm != 0xF && Rm != 0xD) {
2735 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2738 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2739 Inst.addOperand(MCOperand::CreateImm(index));
2744 static DecodeStatus DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
2745 uint64_t Address, const void *Decoder) {
2746 DecodeStatus S = Success;
2748 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2749 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2750 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2751 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2752 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2760 if (fieldFromInstruction32(Insn, 4, 1))
2761 return Fail; // UNDEFINED
2762 index = fieldFromInstruction32(Insn, 5, 3);
2765 if (fieldFromInstruction32(Insn, 5, 1))
2766 return Fail; // UNDEFINED
2767 index = fieldFromInstruction32(Insn, 6, 2);
2768 if (fieldFromInstruction32(Insn, 4, 1))
2772 if (fieldFromInstruction32(Insn, 6, 1))
2773 return Fail; // UNDEFINED
2774 index = fieldFromInstruction32(Insn, 7, 1);
2775 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2779 if (Rm != 0xF) { // Writeback
2780 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2782 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2783 Inst.addOperand(MCOperand::CreateImm(align));
2784 if (Rm != 0xF && Rm != 0xD) {
2785 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2788 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2789 Inst.addOperand(MCOperand::CreateImm(index));
2795 static DecodeStatus DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
2796 uint64_t Address, const void *Decoder) {
2797 DecodeStatus S = Success;
2799 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2800 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2801 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2802 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2803 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2812 index = fieldFromInstruction32(Insn, 5, 3);
2813 if (fieldFromInstruction32(Insn, 4, 1))
2817 index = fieldFromInstruction32(Insn, 6, 2);
2818 if (fieldFromInstruction32(Insn, 4, 1))
2820 if (fieldFromInstruction32(Insn, 5, 1))
2824 if (fieldFromInstruction32(Insn, 5, 1))
2825 return Fail; // UNDEFINED
2826 index = fieldFromInstruction32(Insn, 7, 1);
2827 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2829 if (fieldFromInstruction32(Insn, 6, 1))
2834 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2835 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2836 if (Rm != 0xF) { // Writeback
2837 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2839 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2840 Inst.addOperand(MCOperand::CreateImm(align));
2841 if (Rm != 0xF && Rm != 0xD) {
2842 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2845 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2846 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2847 Inst.addOperand(MCOperand::CreateImm(index));
2852 static DecodeStatus DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
2853 uint64_t Address, const void *Decoder) {
2854 DecodeStatus S = Success;
2856 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2857 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2858 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2859 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2860 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2869 index = fieldFromInstruction32(Insn, 5, 3);
2870 if (fieldFromInstruction32(Insn, 4, 1))
2874 index = fieldFromInstruction32(Insn, 6, 2);
2875 if (fieldFromInstruction32(Insn, 4, 1))
2877 if (fieldFromInstruction32(Insn, 5, 1))
2881 if (fieldFromInstruction32(Insn, 5, 1))
2882 return Fail; // UNDEFINED
2883 index = fieldFromInstruction32(Insn, 7, 1);
2884 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2886 if (fieldFromInstruction32(Insn, 6, 1))
2891 if (Rm != 0xF) { // Writeback
2892 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2894 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2895 Inst.addOperand(MCOperand::CreateImm(align));
2896 if (Rm != 0xF && Rm != 0xD) {
2897 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2900 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2901 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2902 Inst.addOperand(MCOperand::CreateImm(index));
2908 static DecodeStatus DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
2909 uint64_t Address, const void *Decoder) {
2910 DecodeStatus S = Success;
2912 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2913 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2914 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2915 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2916 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2925 if (fieldFromInstruction32(Insn, 4, 1))
2926 return Fail; // UNDEFINED
2927 index = fieldFromInstruction32(Insn, 5, 3);
2930 if (fieldFromInstruction32(Insn, 4, 1))
2931 return Fail; // UNDEFINED
2932 index = fieldFromInstruction32(Insn, 6, 2);
2933 if (fieldFromInstruction32(Insn, 5, 1))
2937 if (fieldFromInstruction32(Insn, 4, 2))
2938 return Fail; // UNDEFINED
2939 index = fieldFromInstruction32(Insn, 7, 1);
2940 if (fieldFromInstruction32(Insn, 6, 1))
2945 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2946 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2947 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
2949 if (Rm != 0xF) { // Writeback
2950 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2952 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2953 Inst.addOperand(MCOperand::CreateImm(align));
2954 if (Rm != 0xF && Rm != 0xD) {
2955 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2958 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2959 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2960 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
2961 Inst.addOperand(MCOperand::CreateImm(index));
2966 static DecodeStatus DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
2967 uint64_t Address, const void *Decoder) {
2968 DecodeStatus S = Success;
2970 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2971 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2972 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2973 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2974 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2983 if (fieldFromInstruction32(Insn, 4, 1))
2984 return Fail; // UNDEFINED
2985 index = fieldFromInstruction32(Insn, 5, 3);
2988 if (fieldFromInstruction32(Insn, 4, 1))
2989 return Fail; // UNDEFINED
2990 index = fieldFromInstruction32(Insn, 6, 2);
2991 if (fieldFromInstruction32(Insn, 5, 1))
2995 if (fieldFromInstruction32(Insn, 4, 2))
2996 return Fail; // UNDEFINED
2997 index = fieldFromInstruction32(Insn, 7, 1);
2998 if (fieldFromInstruction32(Insn, 6, 1))
3003 if (Rm != 0xF) { // Writeback
3004 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3006 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3007 Inst.addOperand(MCOperand::CreateImm(align));
3008 if (Rm != 0xF && Rm != 0xD) {
3009 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3012 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3013 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3014 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3015 Inst.addOperand(MCOperand::CreateImm(index));
3021 static DecodeStatus DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
3022 uint64_t Address, const void *Decoder) {
3023 DecodeStatus S = Success;
3025 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3026 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3027 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3028 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3029 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3038 if (fieldFromInstruction32(Insn, 4, 1))
3040 index = fieldFromInstruction32(Insn, 5, 3);
3043 if (fieldFromInstruction32(Insn, 4, 1))
3045 index = fieldFromInstruction32(Insn, 6, 2);
3046 if (fieldFromInstruction32(Insn, 5, 1))
3050 if (fieldFromInstruction32(Insn, 4, 2))
3051 align = 4 << fieldFromInstruction32(Insn, 4, 2);
3052 index = fieldFromInstruction32(Insn, 7, 1);
3053 if (fieldFromInstruction32(Insn, 6, 1))
3058 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3059 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3060 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3061 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3063 if (Rm != 0xF) { // Writeback
3064 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3066 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3067 Inst.addOperand(MCOperand::CreateImm(align));
3068 if (Rm != 0xF && Rm != 0xD) {
3069 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3072 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3073 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3074 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3075 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3076 Inst.addOperand(MCOperand::CreateImm(index));
3081 static DecodeStatus DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
3082 uint64_t Address, const void *Decoder) {
3083 DecodeStatus S = Success;
3085 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3086 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3087 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3088 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3089 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3098 if (fieldFromInstruction32(Insn, 4, 1))
3100 index = fieldFromInstruction32(Insn, 5, 3);
3103 if (fieldFromInstruction32(Insn, 4, 1))
3105 index = fieldFromInstruction32(Insn, 6, 2);
3106 if (fieldFromInstruction32(Insn, 5, 1))
3110 if (fieldFromInstruction32(Insn, 4, 2))
3111 align = 4 << fieldFromInstruction32(Insn, 4, 2);
3112 index = fieldFromInstruction32(Insn, 7, 1);
3113 if (fieldFromInstruction32(Insn, 6, 1))
3118 if (Rm != 0xF) { // Writeback
3119 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3121 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3122 Inst.addOperand(MCOperand::CreateImm(align));
3123 if (Rm != 0xF && Rm != 0xD) {
3124 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3127 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3128 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3129 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3130 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3131 Inst.addOperand(MCOperand::CreateImm(index));