1 //===- ARMDisassembler.cpp - Disassembler for ARM/Thumb ISA -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "arm-disassembler"
12 #include "ARMDisassembler.h"
14 #include "ARMRegisterInfo.h"
15 #include "MCTargetDesc/ARMAddressingModes.h"
16 #include "MCTargetDesc/ARMBaseInfo.h"
17 #include "llvm/MC/EDInstInfo.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/Target/TargetRegistry.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/MemoryObject.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/raw_ostream.h"
27 // Forward declare these because the autogenerated code will reference them.
28 // Definitions are further down.
29 static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
30 uint64_t Address, const void *Decoder);
31 static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
32 uint64_t Address, const void *Decoder);
33 static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
34 uint64_t Address, const void *Decoder);
35 static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
36 uint64_t Address, const void *Decoder);
37 static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
38 uint64_t Address, const void *Decoder);
39 static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
40 uint64_t Address, const void *Decoder);
41 static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
42 uint64_t Address, const void *Decoder);
43 static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
44 uint64_t Address, const void *Decoder);
45 static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
46 uint64_t Address, const void *Decoder);
47 static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
48 uint64_t Address, const void *Decoder);
50 static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
51 uint64_t Address, const void *Decoder);
52 static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
53 uint64_t Address, const void *Decoder);
54 static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
55 uint64_t Address, const void *Decoder);
56 static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
57 uint64_t Address, const void *Decoder);
58 static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
59 uint64_t Address, const void *Decoder);
60 static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
61 uint64_t Address, const void *Decoder);
62 static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
63 uint64_t Address, const void *Decoder);
65 static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Insn,
66 uint64_t Address, const void *Decoder);
67 static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
68 uint64_t Address, const void *Decoder);
69 static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
70 uint64_t Address, const void *Decoder);
71 static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Insn,
72 uint64_t Address, const void *Decoder);
73 static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
74 uint64_t Address, const void *Decoder);
75 static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Insn,
76 uint64_t Address, const void *Decoder);
77 static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Insn,
78 uint64_t Address, const void *Decoder);
80 static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst & Inst,
84 static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
85 uint64_t Address, const void *Decoder);
86 static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
87 uint64_t Address, const void *Decoder);
88 static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
89 uint64_t Address, const void *Decoder);
90 static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
91 uint64_t Address, const void *Decoder);
92 static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
93 uint64_t Address, const void *Decoder);
94 static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
95 uint64_t Address, const void *Decoder);
96 static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
97 uint64_t Address, const void *Decoder);
98 static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
99 uint64_t Address, const void *Decoder);
100 static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Val,
101 uint64_t Address, const void *Decoder);
102 static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Val,
103 uint64_t Address, const void *Decoder);
104 static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Val,
105 uint64_t Address, const void *Decoder);
106 static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Val,
107 uint64_t Address, const void *Decoder);
108 static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Val,
109 uint64_t Address, const void *Decoder);
110 static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Val,
111 uint64_t Address, const void *Decoder);
112 static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Val,
113 uint64_t Address, const void *Decoder);
114 static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Val,
115 uint64_t Address, const void *Decoder);
116 static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
117 uint64_t Address, const void *Decoder);
118 static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
119 uint64_t Address, const void *Decoder);
120 static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
121 uint64_t Address, const void *Decoder);
122 static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
123 uint64_t Address, const void *Decoder);
124 static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
125 uint64_t Address, const void *Decoder);
126 static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
127 uint64_t Address, const void *Decoder);
128 static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
129 uint64_t Address, const void *Decoder);
130 static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Insn,
131 uint64_t Address, const void *Decoder);
132 static bool DecodeAddrMode3Offset(llvm::MCInst &Inst, unsigned Insn,
133 uint64_t Address, const void *Decoder);
134 static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Insn,
135 uint64_t Address, const void *Decoder);
136 static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Insn,
137 uint64_t Address, const void *Decoder);
138 static bool DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
139 uint64_t Address, const void *Decoder);
140 static bool DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
141 uint64_t Address, const void *Decoder);
143 static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
144 uint64_t Address, const void *Decoder);
145 static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
146 uint64_t Address, const void *Decoder);
147 static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
148 uint64_t Address, const void *Decoder);
149 static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
150 uint64_t Address, const void *Decoder);
151 static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
152 uint64_t Address, const void *Decoder);
153 static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
154 uint64_t Address, const void *Decoder);
155 static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
156 uint64_t Address, const void *Decoder);
157 static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
158 uint64_t Address, const void *Decoder);
159 static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
160 uint64_t Address, const void *Decoder);
161 static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
162 uint64_t Address, const void *Decoder);
163 static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
164 uint64_t Address, const void *Decoder);
165 static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
166 uint64_t Address, const void *Decoder);
167 static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
168 uint64_t Address, const void *Decoder);
169 static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
170 uint64_t Address, const void *Decoder);
171 static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
172 uint64_t Address, const void *Decoder);
173 static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
174 uint64_t Address, const void *Decoder);
175 static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
176 uint64_t Address, const void *Decoder);
177 static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
178 uint64_t Address, const void *Decoder);
179 static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
180 uint64_t Address, const void *Decoder);
181 static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
182 uint64_t Address, const void *Decoder);
183 static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
184 uint64_t Address, const void *Decoder);
185 static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
186 uint64_t Address, const void *Decoder);
187 static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
188 uint64_t Address, const void *Decoder);
189 static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
190 uint64_t Address, const void *Decoder);
192 #include "ARMGenDisassemblerTables.inc"
193 #include "ARMGenInstrInfo.inc"
194 #include "ARMGenEDInfo.inc"
196 using namespace llvm;
198 static MCDisassembler *createARMDisassembler(const Target &T) {
199 return new ARMDisassembler;
202 static MCDisassembler *createThumbDisassembler(const Target &T) {
203 return new ThumbDisassembler;
206 EDInstInfo *ARMDisassembler::getEDInfo() const {
210 EDInstInfo *ThumbDisassembler::getEDInfo() const {
215 bool ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
216 const MemoryObject &Region,
217 uint64_t Address,raw_ostream &os) const {
220 // We want to read exactly 4 bytes of data.
221 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
224 // Encoded as a small-endian 32-bit word in the stream.
225 uint32_t insn = (bytes[3] << 24) |
230 // Calling the auto-generated decoder function.
231 bool result = decodeARMInstruction32(MI, insn, Address, this);
237 // Instructions that are shared between ARM and Thumb modes.
238 // FIXME: This shouldn't really exist. It's an artifact of the
239 // fact that we fail to encode a few instructions properly for Thumb.
241 result = decodeCommonInstruction32(MI, insn, Address, this);
247 // VFP and NEON instructions, similarly, are shared between ARM
250 result = decodeVFPInstruction32(MI, insn, Address, this);
257 result = decodeNEONDataInstruction32(MI, insn, Address, this);
260 // Add a fake predicate operand, because we share these instruction
261 // definitions with Thumb2 where these instructions are predicable.
262 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
267 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this);
270 // Add a fake predicate operand, because we share these instruction
271 // definitions with Thumb2 where these instructions are predicable.
272 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
277 result = decodeNEONDupInstruction32(MI, insn, Address, this);
280 // Add a fake predicate operand, because we share these instruction
281 // definitions with Thumb2 where these instructions are predicable.
282 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
292 extern MCInstrDesc ARMInsts[];
295 // Thumb1 instructions don't have explicit S bits. Rather, they
296 // implicitly set CPSR. Since it's not represented in the encoding, the
297 // auto-generated decoder won't inject the CPSR operand. We need to fix
298 // that as a post-pass.
299 static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
300 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
301 MCInst::iterator I = MI.begin();
302 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
303 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
304 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
309 if (OpInfo[MI.size()].isOptionalDef() &&
310 OpInfo[MI.size()].RegClass == ARM::CCRRegClassID)
311 MI.insert(MI.end(), MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
314 // Most Thumb instructions don't have explicit predicates in the
315 // encoding, but rather get their predicates from IT context. We need
316 // to fix up the predicate operands using this context information as a
318 void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
319 // A few instructions actually have predicates encoded in them. Don't
320 // try to overwrite it if we're seeing one of those.
321 switch (MI.getOpcode()) {
329 // If we're in an IT block, base the predicate on that. Otherwise,
330 // assume a predicate of AL.
332 if (!ITBlock.empty()) {
338 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
339 MCInst::iterator I = MI.begin();
340 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
341 if (OpInfo[i].isPredicate()) {
342 I = MI.insert(I, MCOperand::CreateImm(CC));
345 MI.insert(I, MCOperand::CreateReg(0));
347 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
352 MI.insert(MI.end(), MCOperand::CreateImm(CC));
354 MI.insert(MI.end(), MCOperand::CreateReg(0));
356 MI.insert(MI.end(), MCOperand::CreateReg(ARM::CPSR));
359 // Thumb VFP instructions are a special case. Because we share their
360 // encodings between ARM and Thumb modes, and they are predicable in ARM
361 // mode, the auto-generated decoder will give them an (incorrect)
362 // predicate operand. We need to rewrite these operands based on the IT
363 // context as a post-pass.
364 void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
366 if (!ITBlock.empty()) {
372 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
373 MCInst::iterator I = MI.begin();
374 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
375 if (OpInfo[i].isPredicate() ) {
381 I->setReg(ARM::CPSR);
388 bool ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
389 const MemoryObject &Region,
390 uint64_t Address,raw_ostream &os) const {
393 // We want to read exactly 2 bytes of data.
394 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
397 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
398 bool result = decodeThumbInstruction16(MI, insn16, Address, this);
401 bool InITBlock = !ITBlock.empty();
402 AddThumbPredicate(MI);
403 AddThumb1SBit(MI, InITBlock);
408 result = decodeThumb2Instruction16(MI, insn16, Address, this);
411 AddThumbPredicate(MI);
413 // If we find an IT instruction, we need to parse its condition
414 // code and mask operands so that we can apply them correctly
415 // to the subsequent instructions.
416 if (MI.getOpcode() == ARM::t2IT) {
417 unsigned firstcond = MI.getOperand(0).getImm();
418 uint32_t mask = MI.getOperand(1).getImm();
419 unsigned zeros = CountTrailingZeros_32(mask);
422 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
423 if (firstcond ^ (mask & 1))
424 ITBlock.push_back(firstcond ^ 1);
426 ITBlock.push_back(firstcond);
429 ITBlock.push_back(firstcond);
435 // We want to read exactly 4 bytes of data.
436 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
439 uint32_t insn32 = (bytes[3] << 8) |
444 result = decodeThumbInstruction32(MI, insn32, Address, this);
447 bool InITBlock = ITBlock.size();
448 AddThumbPredicate(MI);
449 AddThumb1SBit(MI, InITBlock);
454 result = decodeThumb2Instruction32(MI, insn32, Address, this);
457 AddThumbPredicate(MI);
462 result = decodeCommonInstruction32(MI, insn32, Address, this);
465 AddThumbPredicate(MI);
470 result = decodeVFPInstruction32(MI, insn32, Address, this);
473 UpdateThumbVFPPredicate(MI);
478 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
479 uint32_t NEONDataInsn = insn32;
480 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
481 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
482 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
483 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this);
486 AddThumbPredicate(MI);
492 result = decodeNEONLoadStoreInstruction32(MI, insn32, Address, this);
495 AddThumbPredicate(MI);
500 result = decodeNEONDupInstruction32(MI, insn32, Address, this);
503 AddThumbPredicate(MI);
511 extern "C" void LLVMInitializeARMDisassembler() {
512 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
513 createARMDisassembler);
514 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
515 createThumbDisassembler);
518 static const unsigned GPRDecoderTable[] = {
519 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
520 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
521 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
522 ARM::R12, ARM::SP, ARM::LR, ARM::PC
525 static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
526 uint64_t Address, const void *Decoder) {
530 unsigned Register = GPRDecoderTable[RegNo];
531 Inst.addOperand(MCOperand::CreateReg(Register));
535 static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
536 uint64_t Address, const void *Decoder) {
537 if (RegNo == 15) return false;
538 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
541 static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
542 uint64_t Address, const void *Decoder) {
545 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
548 static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
549 uint64_t Address, const void *Decoder) {
550 unsigned Register = 0;
574 Inst.addOperand(MCOperand::CreateReg(Register));
578 static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
579 uint64_t Address, const void *Decoder) {
580 if (RegNo == 13 || RegNo == 15) return false;
581 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
584 static const unsigned SPRDecoderTable[] = {
585 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
586 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
587 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
588 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
589 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
590 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
591 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
592 ARM::S28, ARM::S29, ARM::S30, ARM::S31
595 static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
596 uint64_t Address, const void *Decoder) {
600 unsigned Register = SPRDecoderTable[RegNo];
601 Inst.addOperand(MCOperand::CreateReg(Register));
605 static const unsigned DPRDecoderTable[] = {
606 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
607 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
608 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
609 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
610 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
611 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
612 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
613 ARM::D28, ARM::D29, ARM::D30, ARM::D31
616 static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
617 uint64_t Address, const void *Decoder) {
621 unsigned Register = DPRDecoderTable[RegNo];
622 Inst.addOperand(MCOperand::CreateReg(Register));
626 static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
627 uint64_t Address, const void *Decoder) {
630 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
633 static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
634 uint64_t Address, const void *Decoder) {
637 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
640 static const unsigned QPRDecoderTable[] = {
641 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
642 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
643 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
644 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
648 static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
649 uint64_t Address, const void *Decoder) {
654 unsigned Register = QPRDecoderTable[RegNo];
655 Inst.addOperand(MCOperand::CreateReg(Register));
659 static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
660 uint64_t Address, const void *Decoder) {
661 if (Val == 0xF) return false;
662 // AL predicate is not allowed on Thumb1 branches.
663 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
665 Inst.addOperand(MCOperand::CreateImm(Val));
666 if (Val == ARMCC::AL) {
667 Inst.addOperand(MCOperand::CreateReg(0));
669 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
673 static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
674 uint64_t Address, const void *Decoder) {
676 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
678 Inst.addOperand(MCOperand::CreateReg(0));
682 static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
683 uint64_t Address, const void *Decoder) {
684 uint32_t imm = Val & 0xFF;
685 uint32_t rot = (Val & 0xF00) >> 7;
686 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
687 Inst.addOperand(MCOperand::CreateImm(rot_imm));
691 static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
692 uint64_t Address, const void *Decoder) {
694 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
698 static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
699 uint64_t Address, const void *Decoder) {
701 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
702 unsigned type = fieldFromInstruction32(Val, 5, 2);
703 unsigned imm = fieldFromInstruction32(Val, 7, 5);
705 // Register-immediate
706 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
708 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
724 if (Shift == ARM_AM::ror && imm == 0)
727 unsigned Op = Shift | (imm << 3);
728 Inst.addOperand(MCOperand::CreateImm(Op));
733 static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
734 uint64_t Address, const void *Decoder) {
736 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
737 unsigned type = fieldFromInstruction32(Val, 5, 2);
738 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
741 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
742 if (!DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder)) return false;
744 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
760 Inst.addOperand(MCOperand::CreateImm(Shift));
765 static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
766 uint64_t Address, const void *Decoder) {
767 // Empty register lists are not allowed.
768 if (CountPopulation_32(Val) == 0) return false;
769 for (unsigned i = 0; i < 16; ++i) {
770 if (Val & (1 << i)) {
771 if (!DecodeGPRRegisterClass(Inst, i, Address, Decoder)) return false;
778 static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
779 uint64_t Address, const void *Decoder) {
780 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
781 unsigned regs = Val & 0xFF;
783 if (!DecodeSPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
784 for (unsigned i = 0; i < (regs - 1); ++i) {
785 if (!DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
791 static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
792 uint64_t Address, const void *Decoder) {
793 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
794 unsigned regs = (Val & 0xFF) / 2;
796 if (!DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
797 for (unsigned i = 0; i < (regs - 1); ++i) {
798 if (!DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
804 static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
805 uint64_t Address, const void *Decoder) {
806 // This operand encodes a mask of contiguous zeros between a specified MSB
807 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
808 // the mask of all bits LSB-and-lower, and then xor them to create
809 // the mask of that's all ones on [msb, lsb]. Finally we not it to
810 // create the final mask.
811 unsigned msb = fieldFromInstruction32(Val, 5, 5);
812 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
813 uint32_t msb_mask = (1 << (msb+1)) - 1;
814 uint32_t lsb_mask = (1 << lsb) - 1;
815 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
819 static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
820 uint64_t Address, const void *Decoder) {
821 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
822 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
823 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
824 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
825 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
826 unsigned U = fieldFromInstruction32(Insn, 23, 1);
828 switch (Inst.getOpcode()) {
829 case ARM::LDC_OFFSET:
832 case ARM::LDC_OPTION:
833 case ARM::LDCL_OFFSET:
836 case ARM::LDCL_OPTION:
837 case ARM::STC_OFFSET:
840 case ARM::STC_OPTION:
841 case ARM::STCL_OFFSET:
844 case ARM::STCL_OPTION:
845 if (coproc == 0xA || coproc == 0xB)
852 Inst.addOperand(MCOperand::CreateImm(coproc));
853 Inst.addOperand(MCOperand::CreateImm(CRd));
854 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
855 switch (Inst.getOpcode()) {
856 case ARM::LDC_OPTION:
857 case ARM::LDCL_OPTION:
858 case ARM::LDC2_OPTION:
859 case ARM::LDC2L_OPTION:
860 case ARM::STC_OPTION:
861 case ARM::STCL_OPTION:
862 case ARM::STC2_OPTION:
863 case ARM::STC2L_OPTION:
868 Inst.addOperand(MCOperand::CreateReg(0));
872 unsigned P = fieldFromInstruction32(Insn, 24, 1);
873 unsigned W = fieldFromInstruction32(Insn, 21, 1);
875 bool writeback = (P == 0) || (W == 1);
876 unsigned idx_mode = 0;
878 idx_mode = ARMII::IndexModePre;
879 else if (!P && writeback)
880 idx_mode = ARMII::IndexModePost;
882 switch (Inst.getOpcode()) {
886 case ARM::LDC_OPTION:
887 case ARM::LDCL_OPTION:
888 case ARM::LDC2_OPTION:
889 case ARM::LDC2L_OPTION:
890 case ARM::STC_OPTION:
891 case ARM::STCL_OPTION:
892 case ARM::STC2_OPTION:
893 case ARM::STC2L_OPTION:
894 Inst.addOperand(MCOperand::CreateImm(imm));
898 Inst.addOperand(MCOperand::CreateImm(
899 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
901 Inst.addOperand(MCOperand::CreateImm(
902 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
906 switch (Inst.getOpcode()) {
907 case ARM::LDC_OFFSET:
910 case ARM::LDC_OPTION:
911 case ARM::LDCL_OFFSET:
914 case ARM::LDCL_OPTION:
915 case ARM::STC_OFFSET:
918 case ARM::STC_OPTION:
919 case ARM::STCL_OFFSET:
922 case ARM::STCL_OPTION:
923 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
932 static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
933 uint64_t Address, const void *Decoder) {
934 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
935 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
936 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
937 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
938 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
939 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
940 unsigned P = fieldFromInstruction32(Insn, 24, 1);
941 unsigned W = fieldFromInstruction32(Insn, 21, 1);
943 // On stores, the writeback operand precedes Rt.
944 switch (Inst.getOpcode()) {
945 case ARM::STR_POST_IMM:
946 case ARM::STR_POST_REG:
947 case ARM::STRB_POST_IMM:
948 case ARM::STRB_POST_REG:
949 case ARM::STRT_POST_REG:
950 case ARM::STRT_POST_IMM:
951 case ARM::STRBT_POST_REG:
952 case ARM::STRBT_POST_IMM:
953 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
959 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
961 // On loads, the writeback operand comes after Rt.
962 switch (Inst.getOpcode()) {
963 case ARM::LDR_POST_IMM:
964 case ARM::LDR_POST_REG:
965 case ARM::LDRB_POST_IMM:
966 case ARM::LDRB_POST_REG:
968 case ARM::LDRBT_POST_REG:
969 case ARM::LDRBT_POST_IMM:
970 case ARM::LDRT_POST_REG:
971 case ARM::LDRT_POST_IMM:
972 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
979 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
981 ARM_AM::AddrOpc Op = ARM_AM::add;
982 if (!fieldFromInstruction32(Insn, 23, 1))
985 bool writeback = (P == 0) || (W == 1);
986 unsigned idx_mode = 0;
988 idx_mode = ARMII::IndexModePre;
989 else if (!P && writeback)
990 idx_mode = ARMII::IndexModePost;
992 if (writeback && (Rn == 15 || Rn == Rt)) return false; // UNPREDICTABLE
995 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
996 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
997 switch( fieldFromInstruction32(Insn, 5, 2)) {
1013 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1014 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1016 Inst.addOperand(MCOperand::CreateImm(imm));
1018 Inst.addOperand(MCOperand::CreateReg(0));
1019 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1020 Inst.addOperand(MCOperand::CreateImm(tmp));
1023 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1028 static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
1029 uint64_t Address, const void *Decoder) {
1030 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1031 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1032 unsigned type = fieldFromInstruction32(Val, 5, 2);
1033 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1034 unsigned U = fieldFromInstruction32(Val, 12, 1);
1036 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
1052 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1053 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1056 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1058 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1059 Inst.addOperand(MCOperand::CreateImm(shift));
1064 static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
1065 uint64_t Address, const void *Decoder) {
1066 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1067 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1068 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1069 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1070 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1071 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1072 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1073 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1074 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1076 bool writeback = (W == 1) | (P == 0);
1077 if (writeback) { // Writeback
1079 U |= ARMII::IndexModePre << 9;
1081 U |= ARMII::IndexModePost << 9;
1083 // On stores, the writeback operand precedes Rt.
1084 switch (Inst.getOpcode()) {
1087 case ARM::STRD_POST:
1088 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1096 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))
1098 switch (Inst.getOpcode()) {
1101 case ARM::STRD_POST:
1104 case ARM::LDRD_POST:
1105 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder))
1113 // On loads, the writeback operand comes after Rt.
1114 switch (Inst.getOpcode()) {
1117 case ARM::LDRD_POST:
1120 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1128 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1132 Inst.addOperand(MCOperand::CreateReg(0));
1133 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1135 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1137 Inst.addOperand(MCOperand::CreateImm(U));
1140 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1145 static bool DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1146 uint64_t Address, const void *Decoder) {
1147 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1148 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1165 Inst.addOperand(MCOperand::CreateImm(mode));
1166 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1171 static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1173 uint64_t Address, const void *Decoder) {
1174 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1175 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1176 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1179 switch (Inst.getOpcode()) {
1181 Inst.setOpcode(ARM::RFEDA);
1183 case ARM::STMDA_UPD:
1184 Inst.setOpcode(ARM::RFEDA_UPD);
1187 Inst.setOpcode(ARM::RFEDB);
1189 case ARM::STMDB_UPD:
1190 Inst.setOpcode(ARM::RFEDB_UPD);
1193 Inst.setOpcode(ARM::RFEIA);
1195 case ARM::STMIA_UPD:
1196 Inst.setOpcode(ARM::RFEIA_UPD);
1199 Inst.setOpcode(ARM::RFEIB);
1201 case ARM::STMIB_UPD:
1202 Inst.setOpcode(ARM::RFEIB_UPD);
1205 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1208 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
1209 !DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) || // Tied
1210 !DecodePredicateOperand(Inst, pred, Address, Decoder) ||
1211 !DecodeRegListOperand(Inst, reglist, Address, Decoder))
1217 static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1218 uint64_t Address, const void *Decoder) {
1219 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1220 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1221 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1222 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1224 // imod == '01' --> UNPREDICTABLE
1225 if (imod == 1) return false;
1227 if (M && mode && imod && iflags) {
1228 Inst.setOpcode(ARM::CPS3p);
1229 Inst.addOperand(MCOperand::CreateImm(imod));
1230 Inst.addOperand(MCOperand::CreateImm(iflags));
1231 Inst.addOperand(MCOperand::CreateImm(mode));
1233 } else if (!mode && !M) {
1234 Inst.setOpcode(ARM::CPS2p);
1235 Inst.addOperand(MCOperand::CreateImm(imod));
1236 Inst.addOperand(MCOperand::CreateImm(iflags));
1238 } else if (!imod && !iflags && M) {
1239 Inst.setOpcode(ARM::CPS1p);
1240 Inst.addOperand(MCOperand::CreateImm(mode));
1247 static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1248 uint64_t Address, const void *Decoder) {
1249 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1250 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1251 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1252 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1253 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1256 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1258 if (!DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder) ||
1259 !DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder) ||
1260 !DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder) ||
1261 !DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder))
1264 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1269 static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1270 uint64_t Address, const void *Decoder) {
1271 unsigned add = fieldFromInstruction32(Val, 12, 1);
1272 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1273 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1275 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1278 if (!add) imm *= -1;
1279 if (imm == 0 && !add) imm = INT32_MIN;
1280 Inst.addOperand(MCOperand::CreateImm(imm));
1285 static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1286 uint64_t Address, const void *Decoder) {
1287 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1288 unsigned U = fieldFromInstruction32(Val, 8, 1);
1289 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1291 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1295 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1297 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1302 static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1303 uint64_t Address, const void *Decoder) {
1304 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1307 static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1308 uint64_t Address, const void *Decoder) {
1309 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1310 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1313 Inst.setOpcode(ARM::BLXi);
1314 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
1315 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1319 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1320 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1326 static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1327 uint64_t Address, const void *Decoder) {
1328 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1332 static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1333 uint64_t Address, const void *Decoder) {
1334 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1335 unsigned align = fieldFromInstruction32(Val, 4, 2);
1337 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1340 Inst.addOperand(MCOperand::CreateImm(0));
1342 Inst.addOperand(MCOperand::CreateImm(4 << align));
1347 static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1348 uint64_t Address, const void *Decoder) {
1349 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1350 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1351 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1352 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1353 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1354 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1356 // First output register
1357 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1359 // Second output register
1360 switch (Inst.getOpcode()) {
1365 case ARM::VLD1q8_UPD:
1366 case ARM::VLD1q16_UPD:
1367 case ARM::VLD1q32_UPD:
1368 case ARM::VLD1q64_UPD:
1373 case ARM::VLD1d8T_UPD:
1374 case ARM::VLD1d16T_UPD:
1375 case ARM::VLD1d32T_UPD:
1376 case ARM::VLD1d64T_UPD:
1381 case ARM::VLD1d8Q_UPD:
1382 case ARM::VLD1d16Q_UPD:
1383 case ARM::VLD1d32Q_UPD:
1384 case ARM::VLD1d64Q_UPD:
1388 case ARM::VLD2d8_UPD:
1389 case ARM::VLD2d16_UPD:
1390 case ARM::VLD2d32_UPD:
1394 case ARM::VLD2q8_UPD:
1395 case ARM::VLD2q16_UPD:
1396 case ARM::VLD2q32_UPD:
1400 case ARM::VLD3d8_UPD:
1401 case ARM::VLD3d16_UPD:
1402 case ARM::VLD3d32_UPD:
1406 case ARM::VLD4d8_UPD:
1407 case ARM::VLD4d16_UPD:
1408 case ARM::VLD4d32_UPD:
1409 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1414 case ARM::VLD2b8_UPD:
1415 case ARM::VLD2b16_UPD:
1416 case ARM::VLD2b32_UPD:
1420 case ARM::VLD3q8_UPD:
1421 case ARM::VLD3q16_UPD:
1422 case ARM::VLD3q32_UPD:
1426 case ARM::VLD4q8_UPD:
1427 case ARM::VLD4q16_UPD:
1428 case ARM::VLD4q32_UPD:
1429 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1434 // Third output register
1435 switch(Inst.getOpcode()) {
1440 case ARM::VLD1d8T_UPD:
1441 case ARM::VLD1d16T_UPD:
1442 case ARM::VLD1d32T_UPD:
1443 case ARM::VLD1d64T_UPD:
1448 case ARM::VLD1d8Q_UPD:
1449 case ARM::VLD1d16Q_UPD:
1450 case ARM::VLD1d32Q_UPD:
1451 case ARM::VLD1d64Q_UPD:
1455 case ARM::VLD2q8_UPD:
1456 case ARM::VLD2q16_UPD:
1457 case ARM::VLD2q32_UPD:
1461 case ARM::VLD3d8_UPD:
1462 case ARM::VLD3d16_UPD:
1463 case ARM::VLD3d32_UPD:
1467 case ARM::VLD4d8_UPD:
1468 case ARM::VLD4d16_UPD:
1469 case ARM::VLD4d32_UPD:
1470 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1475 case ARM::VLD3q8_UPD:
1476 case ARM::VLD3q16_UPD:
1477 case ARM::VLD3q32_UPD:
1481 case ARM::VLD4q8_UPD:
1482 case ARM::VLD4q16_UPD:
1483 case ARM::VLD4q32_UPD:
1484 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
1490 // Fourth output register
1491 switch (Inst.getOpcode()) {
1496 case ARM::VLD1d8Q_UPD:
1497 case ARM::VLD1d16Q_UPD:
1498 case ARM::VLD1d32Q_UPD:
1499 case ARM::VLD1d64Q_UPD:
1503 case ARM::VLD2q8_UPD:
1504 case ARM::VLD2q16_UPD:
1505 case ARM::VLD2q32_UPD:
1509 case ARM::VLD4d8_UPD:
1510 case ARM::VLD4d16_UPD:
1511 case ARM::VLD4d32_UPD:
1512 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
1517 case ARM::VLD4q8_UPD:
1518 case ARM::VLD4q16_UPD:
1519 case ARM::VLD4q32_UPD:
1520 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
1526 // Writeback operand
1527 switch (Inst.getOpcode()) {
1528 case ARM::VLD1d8_UPD:
1529 case ARM::VLD1d16_UPD:
1530 case ARM::VLD1d32_UPD:
1531 case ARM::VLD1d64_UPD:
1532 case ARM::VLD1q8_UPD:
1533 case ARM::VLD1q16_UPD:
1534 case ARM::VLD1q32_UPD:
1535 case ARM::VLD1q64_UPD:
1536 case ARM::VLD1d8T_UPD:
1537 case ARM::VLD1d16T_UPD:
1538 case ARM::VLD1d32T_UPD:
1539 case ARM::VLD1d64T_UPD:
1540 case ARM::VLD1d8Q_UPD:
1541 case ARM::VLD1d16Q_UPD:
1542 case ARM::VLD1d32Q_UPD:
1543 case ARM::VLD1d64Q_UPD:
1544 case ARM::VLD2d8_UPD:
1545 case ARM::VLD2d16_UPD:
1546 case ARM::VLD2d32_UPD:
1547 case ARM::VLD2q8_UPD:
1548 case ARM::VLD2q16_UPD:
1549 case ARM::VLD2q32_UPD:
1550 case ARM::VLD2b8_UPD:
1551 case ARM::VLD2b16_UPD:
1552 case ARM::VLD2b32_UPD:
1553 case ARM::VLD3d8_UPD:
1554 case ARM::VLD3d16_UPD:
1555 case ARM::VLD3d32_UPD:
1556 case ARM::VLD3q8_UPD:
1557 case ARM::VLD3q16_UPD:
1558 case ARM::VLD3q32_UPD:
1559 case ARM::VLD4d8_UPD:
1560 case ARM::VLD4d16_UPD:
1561 case ARM::VLD4d32_UPD:
1562 case ARM::VLD4q8_UPD:
1563 case ARM::VLD4q16_UPD:
1564 case ARM::VLD4q32_UPD:
1565 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder)) return false;
1571 // AddrMode6 Base (register+alignment)
1572 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
1574 // AddrMode6 Offset (register)
1576 Inst.addOperand(MCOperand::CreateReg(0));
1577 else if (Rm != 0xF) {
1578 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1585 static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1586 uint64_t Address, const void *Decoder) {
1587 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1588 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1589 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1590 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1591 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1592 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1594 // Writeback Operand
1595 switch (Inst.getOpcode()) {
1596 case ARM::VST1d8_UPD:
1597 case ARM::VST1d16_UPD:
1598 case ARM::VST1d32_UPD:
1599 case ARM::VST1d64_UPD:
1600 case ARM::VST1q8_UPD:
1601 case ARM::VST1q16_UPD:
1602 case ARM::VST1q32_UPD:
1603 case ARM::VST1q64_UPD:
1604 case ARM::VST1d8T_UPD:
1605 case ARM::VST1d16T_UPD:
1606 case ARM::VST1d32T_UPD:
1607 case ARM::VST1d64T_UPD:
1608 case ARM::VST1d8Q_UPD:
1609 case ARM::VST1d16Q_UPD:
1610 case ARM::VST1d32Q_UPD:
1611 case ARM::VST1d64Q_UPD:
1612 case ARM::VST2d8_UPD:
1613 case ARM::VST2d16_UPD:
1614 case ARM::VST2d32_UPD:
1615 case ARM::VST2q8_UPD:
1616 case ARM::VST2q16_UPD:
1617 case ARM::VST2q32_UPD:
1618 case ARM::VST2b8_UPD:
1619 case ARM::VST2b16_UPD:
1620 case ARM::VST2b32_UPD:
1621 case ARM::VST3d8_UPD:
1622 case ARM::VST3d16_UPD:
1623 case ARM::VST3d32_UPD:
1624 case ARM::VST3q8_UPD:
1625 case ARM::VST3q16_UPD:
1626 case ARM::VST3q32_UPD:
1627 case ARM::VST4d8_UPD:
1628 case ARM::VST4d16_UPD:
1629 case ARM::VST4d32_UPD:
1630 case ARM::VST4q8_UPD:
1631 case ARM::VST4q16_UPD:
1632 case ARM::VST4q32_UPD:
1633 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder))
1640 // AddrMode6 Base (register+alignment)
1641 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
1643 // AddrMode6 Offset (register)
1645 Inst.addOperand(MCOperand::CreateReg(0));
1646 else if (Rm != 0xF) {
1647 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1650 // First input register
1651 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1653 // Second input register
1654 switch (Inst.getOpcode()) {
1659 case ARM::VST1q8_UPD:
1660 case ARM::VST1q16_UPD:
1661 case ARM::VST1q32_UPD:
1662 case ARM::VST1q64_UPD:
1667 case ARM::VST1d8T_UPD:
1668 case ARM::VST1d16T_UPD:
1669 case ARM::VST1d32T_UPD:
1670 case ARM::VST1d64T_UPD:
1675 case ARM::VST1d8Q_UPD:
1676 case ARM::VST1d16Q_UPD:
1677 case ARM::VST1d32Q_UPD:
1678 case ARM::VST1d64Q_UPD:
1682 case ARM::VST2d8_UPD:
1683 case ARM::VST2d16_UPD:
1684 case ARM::VST2d32_UPD:
1688 case ARM::VST2q8_UPD:
1689 case ARM::VST2q16_UPD:
1690 case ARM::VST2q32_UPD:
1694 case ARM::VST3d8_UPD:
1695 case ARM::VST3d16_UPD:
1696 case ARM::VST3d32_UPD:
1700 case ARM::VST4d8_UPD:
1701 case ARM::VST4d16_UPD:
1702 case ARM::VST4d32_UPD:
1703 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1708 case ARM::VST2b8_UPD:
1709 case ARM::VST2b16_UPD:
1710 case ARM::VST2b32_UPD:
1714 case ARM::VST3q8_UPD:
1715 case ARM::VST3q16_UPD:
1716 case ARM::VST3q32_UPD:
1720 case ARM::VST4q8_UPD:
1721 case ARM::VST4q16_UPD:
1722 case ARM::VST4q32_UPD:
1723 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1729 // Third input register
1730 switch (Inst.getOpcode()) {
1735 case ARM::VST1d8T_UPD:
1736 case ARM::VST1d16T_UPD:
1737 case ARM::VST1d32T_UPD:
1738 case ARM::VST1d64T_UPD:
1743 case ARM::VST1d8Q_UPD:
1744 case ARM::VST1d16Q_UPD:
1745 case ARM::VST1d32Q_UPD:
1746 case ARM::VST1d64Q_UPD:
1750 case ARM::VST2q8_UPD:
1751 case ARM::VST2q16_UPD:
1752 case ARM::VST2q32_UPD:
1756 case ARM::VST3d8_UPD:
1757 case ARM::VST3d16_UPD:
1758 case ARM::VST3d32_UPD:
1762 case ARM::VST4d8_UPD:
1763 case ARM::VST4d16_UPD:
1764 case ARM::VST4d32_UPD:
1765 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
1770 case ARM::VST3q8_UPD:
1771 case ARM::VST3q16_UPD:
1772 case ARM::VST3q32_UPD:
1776 case ARM::VST4q8_UPD:
1777 case ARM::VST4q16_UPD:
1778 case ARM::VST4q32_UPD:
1779 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
1785 // Fourth input register
1786 switch (Inst.getOpcode()) {
1791 case ARM::VST1d8Q_UPD:
1792 case ARM::VST1d16Q_UPD:
1793 case ARM::VST1d32Q_UPD:
1794 case ARM::VST1d64Q_UPD:
1798 case ARM::VST2q8_UPD:
1799 case ARM::VST2q16_UPD:
1800 case ARM::VST2q32_UPD:
1804 case ARM::VST4d8_UPD:
1805 case ARM::VST4d16_UPD:
1806 case ARM::VST4d32_UPD:
1807 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
1812 case ARM::VST4q8_UPD:
1813 case ARM::VST4q16_UPD:
1814 case ARM::VST4q32_UPD:
1815 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
1824 static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1825 uint64_t Address, const void *Decoder) {
1826 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1827 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1828 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1829 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1830 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1831 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1832 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
1834 align *= (1 << size);
1836 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1838 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1841 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1844 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1845 Inst.addOperand(MCOperand::CreateImm(align));
1848 Inst.addOperand(MCOperand::CreateReg(0));
1849 else if (Rm != 0xF) {
1850 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1856 static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1857 uint64_t Address, const void *Decoder) {
1858 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1859 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1860 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1861 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1862 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1863 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
1864 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1867 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1868 if (!DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)) return false;
1870 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1873 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1874 Inst.addOperand(MCOperand::CreateImm(align));
1877 Inst.addOperand(MCOperand::CreateReg(0));
1878 else if (Rm != 0xF) {
1879 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1885 static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1886 uint64_t Address, const void *Decoder) {
1887 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1888 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1889 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1890 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1891 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1893 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1894 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1895 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder))
1898 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1901 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1902 Inst.addOperand(MCOperand::CreateImm(0));
1905 Inst.addOperand(MCOperand::CreateReg(0));
1906 else if (Rm != 0xF) {
1907 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1913 static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1914 uint64_t Address, const void *Decoder) {
1915 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1916 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1917 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1918 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1919 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1920 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1921 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1936 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1937 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1938 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder) ||
1939 !DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder))
1942 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1945 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1946 Inst.addOperand(MCOperand::CreateImm(align));
1949 Inst.addOperand(MCOperand::CreateReg(0));
1950 else if (Rm != 0xF) {
1951 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1957 static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1958 uint64_t Address, const void *Decoder) {
1959 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1960 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1961 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
1962 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
1963 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
1964 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
1965 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
1966 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
1969 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1971 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1974 Inst.addOperand(MCOperand::CreateImm(imm));
1976 switch (Inst.getOpcode()) {
1977 case ARM::VORRiv4i16:
1978 case ARM::VORRiv2i32:
1979 case ARM::VBICiv4i16:
1980 case ARM::VBICiv2i32:
1981 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1983 case ARM::VORRiv8i16:
1984 case ARM::VORRiv4i32:
1985 case ARM::VBICiv8i16:
1986 case ARM::VBICiv4i32:
1987 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1996 static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
1997 uint64_t Address, const void *Decoder) {
1998 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1999 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2000 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2001 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2002 unsigned size = fieldFromInstruction32(Insn, 18, 2);
2004 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2005 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2006 Inst.addOperand(MCOperand::CreateImm(8 << size));
2011 static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
2012 uint64_t Address, const void *Decoder) {
2013 Inst.addOperand(MCOperand::CreateImm(8 - Val));
2017 static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
2018 uint64_t Address, const void *Decoder) {
2019 Inst.addOperand(MCOperand::CreateImm(16 - Val));
2023 static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
2024 uint64_t Address, const void *Decoder) {
2025 Inst.addOperand(MCOperand::CreateImm(32 - Val));
2029 static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
2030 uint64_t Address, const void *Decoder) {
2031 Inst.addOperand(MCOperand::CreateImm(64 - Val));
2035 static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
2036 uint64_t Address, const void *Decoder) {
2037 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2038 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2039 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2040 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2041 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2042 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2043 unsigned op = fieldFromInstruction32(Insn, 6, 1);
2044 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
2046 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2048 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false; // Writeback
2051 for (unsigned i = 0; i < length; ++i) {
2052 if (!DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder)) return false;
2055 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2060 static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
2061 uint64_t Address, const void *Decoder) {
2062 // The immediate needs to be a fully instantiated float. However, the
2063 // auto-generated decoder is only able to fill in some of the bits
2064 // necessary. For instance, the 'b' bit is replicated multiple times,
2065 // and is even present in inverted form in one bit. We do a little
2066 // binary parsing here to fill in those missing bits, and then
2067 // reinterpret it all as a float.
2073 fp_conv.integer = Val;
2074 uint32_t b = fieldFromInstruction32(Val, 25, 1);
2075 fp_conv.integer |= b << 26;
2076 fp_conv.integer |= b << 27;
2077 fp_conv.integer |= b << 28;
2078 fp_conv.integer |= b << 29;
2079 fp_conv.integer |= (~b & 0x1) << 30;
2081 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
2085 static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
2086 uint64_t Address, const void *Decoder) {
2087 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2088 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2090 if (!DecodetGPRRegisterClass(Inst, dst, Address, Decoder)) return false;
2092 if (Inst.getOpcode() == ARM::tADR)
2093 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2094 else if (Inst.getOpcode() == ARM::tADDrSPi)
2095 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2099 Inst.addOperand(MCOperand::CreateImm(imm));
2103 static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
2104 uint64_t Address, const void *Decoder) {
2105 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
2109 static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
2110 uint64_t Address, const void *Decoder) {
2111 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2115 static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2116 uint64_t Address, const void *Decoder) {
2117 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2121 static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2122 uint64_t Address, const void *Decoder) {
2123 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2124 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2126 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2127 !DecodetGPRRegisterClass(Inst, Rm, Address, Decoder))
2133 static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2134 uint64_t Address, const void *Decoder) {
2135 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2136 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2138 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2139 Inst.addOperand(MCOperand::CreateImm(imm));
2144 static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2145 uint64_t Address, const void *Decoder) {
2146 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2151 static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2152 uint64_t Address, const void *Decoder) {
2153 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2154 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2159 static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2160 uint64_t Address, const void *Decoder) {
2161 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2162 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2163 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2165 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2166 !DecoderGPRRegisterClass(Inst, Rm, Address, Decoder))
2168 Inst.addOperand(MCOperand::CreateImm(imm));
2173 static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2174 uint64_t Address, const void *Decoder) {
2175 if (Inst.getOpcode() != ARM::t2PLDs) {
2176 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2177 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2180 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2182 switch (Inst.getOpcode()) {
2184 Inst.setOpcode(ARM::t2LDRBpci);
2187 Inst.setOpcode(ARM::t2LDRHpci);
2190 Inst.setOpcode(ARM::t2LDRSHpci);
2193 Inst.setOpcode(ARM::t2LDRSBpci);
2196 Inst.setOpcode(ARM::t2PLDi12);
2197 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2203 int imm = fieldFromInstruction32(Insn, 0, 12);
2204 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2205 Inst.addOperand(MCOperand::CreateImm(imm));
2210 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2211 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2212 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2213 DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder);
2218 static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
2219 uint64_t Address, const void *Decoder) {
2220 int imm = Val & 0xFF;
2221 if (!(Val & 0x100)) imm *= -1;
2222 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2227 static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2228 uint64_t Address, const void *Decoder) {
2229 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2230 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2232 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2233 !DecodeT2Imm8S4(Inst, imm, Address, Decoder))
2239 static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
2240 uint64_t Address, const void *Decoder) {
2241 int imm = Val & 0xFF;
2242 if (!(Val & 0x100)) imm *= -1;
2243 Inst.addOperand(MCOperand::CreateImm(imm));
2249 static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
2250 uint64_t Address, const void *Decoder) {
2251 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2252 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2254 // Some instructions always use an additive offset.
2255 switch (Inst.getOpcode()) {
2267 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2268 !DecodeT2Imm8(Inst, imm, Address, Decoder))
2275 static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
2276 uint64_t Address, const void *Decoder) {
2277 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2278 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2280 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2281 Inst.addOperand(MCOperand::CreateImm(imm));
2287 static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
2288 uint64_t Address, const void *Decoder) {
2289 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2291 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2292 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2293 Inst.addOperand(MCOperand::CreateImm(imm));
2298 static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
2299 uint64_t Address, const void *Decoder) {
2300 if (Inst.getOpcode() == ARM::tADDrSP) {
2301 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2302 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2304 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
2305 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2306 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
2307 } else if (Inst.getOpcode() == ARM::tADDspr) {
2308 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2310 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2311 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2312 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2318 static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
2319 uint64_t Address, const void *Decoder) {
2320 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2321 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2323 Inst.addOperand(MCOperand::CreateImm(imod));
2324 Inst.addOperand(MCOperand::CreateImm(flags));
2329 static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
2330 uint64_t Address, const void *Decoder) {
2331 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2332 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2334 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
2335 Inst.addOperand(MCOperand::CreateImm(add));
2340 static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
2341 uint64_t Address, const void *Decoder) {
2342 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2346 static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2347 uint64_t Address, const void *Decoder) {
2348 if (Val == 0xA || Val == 0xB)
2351 Inst.addOperand(MCOperand::CreateImm(Val));
2355 static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
2356 uint64_t Address, const void *Decoder) {
2358 Inst.addOperand(MCOperand::CreateImm(32));
2360 Inst.addOperand(MCOperand::CreateImm(Val));
2364 static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2365 uint64_t Address, const void *Decoder) {
2366 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2367 if (pred == 0xE || pred == 0xF) {
2368 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2373 Inst.setOpcode(ARM::t2DSB);
2376 Inst.setOpcode(ARM::t2DMB);
2379 Inst.setOpcode(ARM::t2ISB);
2383 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2384 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
2387 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2388 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2389 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2390 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2391 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2393 if (!DecodeT2BROperand(Inst, brtarget, Address, Decoder) ||
2394 !DecodePredicateOperand(Inst, pred, Address, Decoder))
2400 // Decode a shifted immediate operand. These basically consist
2401 // of an 8-bit value, and a 4-bit directive that specifies either
2402 // a splat operation or a rotation.
2403 static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2404 uint64_t Address, const void *Decoder) {
2405 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2407 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2408 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2411 Inst.addOperand(MCOperand::CreateImm(imm));
2414 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2417 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2420 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2425 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2426 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2427 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2428 Inst.addOperand(MCOperand::CreateImm(imm));
2434 static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2435 uint64_t Address, const void *Decoder){
2436 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2440 static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
2441 uint64_t Address, const void *Decoder){
2442 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2446 static bool DecodeAddrMode3Offset(llvm::MCInst &Inst, unsigned Val,
2447 uint64_t Address, const void *Decoder) {
2448 bool isImm = fieldFromInstruction32(Val, 9, 1);
2449 bool isAdd = fieldFromInstruction32(Val, 8, 1);
2450 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2453 if (!DecodeGPRRegisterClass(Inst, imm, Address, Decoder)) return false;
2454 Inst.addOperand(MCOperand::CreateImm(!isAdd << 8));
2456 Inst.addOperand(MCOperand::CreateReg(0));
2457 Inst.addOperand(MCOperand::CreateImm(imm | (!isAdd << 8)));
2463 static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Val,
2464 uint64_t Address, const void *Decoder) {
2479 Inst.addOperand(MCOperand::CreateImm(Val));
2483 static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Val,
2484 uint64_t Address, const void *Decoder) {
2485 if (!Val) return false;
2486 Inst.addOperand(MCOperand::CreateImm(Val));
2490 static bool DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
2491 uint64_t Address, const void *Decoder) {
2492 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2493 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2494 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2496 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return false;
2498 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2499 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)) return false;
2500 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2501 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2507 static bool DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
2508 uint64_t Address, const void *Decoder) {
2509 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2510 unsigned Rt = fieldFromInstruction32(Insn, 0, 4);
2511 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2512 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2514 if (!DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2516 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return false;
2517 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return false;
2519 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2520 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)) return false;
2521 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2522 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;