1 //===- AArch64Disassembler.cpp - Disassembler for AArch64 -----------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
12 #include "AArch64Disassembler.h"
13 #include "AArch64ExternalSymbolizer.h"
14 #include "MCTargetDesc/AArch64AddressingModes.h"
15 #include "MCTargetDesc/AArch64MCTargetDesc.h"
16 #include "TargetInfo/AArch64TargetInfo.h"
17 #include "Utils/AArch64BaseInfo.h"
18 #include "llvm/MC/MCDecoderOps.h"
19 #include "llvm/MC/MCDisassembler/MCRelocationInfo.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrDesc.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/TargetRegistry.h"
25 #include "llvm/Support/Compiler.h"
26 #include "llvm/Support/Debug.h"
31 #define DEBUG_TYPE "aarch64-disassembler"
33 // Pull DecodeStatus and its enum values into the global namespace.
34 using DecodeStatus
= MCDisassembler::DecodeStatus
;
36 // Forward declare these because the autogenerated code will reference them.
37 // Definitions are further down.
38 template <unsigned RegClassID
, unsigned FirstReg
, unsigned NumRegsInClass
>
39 static DecodeStatus
DecodeSimpleRegisterClass(MCInst
&Inst
, unsigned RegNo
,
41 const MCDisassembler
*Decoder
);
43 DecodeGPR64x8ClassRegisterClass(MCInst
&Inst
, unsigned RegNo
, uint64_t Address
,
44 const MCDisassembler
*Decoder
);
45 template <unsigned Min
, unsigned Max
>
46 static DecodeStatus
DecodeZPRMul2_MinMax(MCInst
&Inst
, unsigned RegNo
,
48 const MCDisassembler
*Decoder
);
49 static DecodeStatus
DecodeZK(MCInst
&Inst
, unsigned RegNo
, uint64_t Address
,
50 const MCDisassembler
*Decoder
);
51 template <unsigned Min
, unsigned Max
>
52 static DecodeStatus
DecodeZPR2Mul2RegisterClass(MCInst
&Inst
, unsigned RegNo
,
55 static DecodeStatus
DecodeZPR4Mul4RegisterClass(MCInst
&Inst
, unsigned RegNo
,
58 template <unsigned NumBitsForTile
>
59 static DecodeStatus
DecodeMatrixTile(MCInst
&Inst
, unsigned RegNo
,
61 const MCDisassembler
*Decoder
);
63 DecodeMatrixTileListRegisterClass(MCInst
&Inst
, unsigned RegMask
,
65 const MCDisassembler
*Decoder
);
66 static DecodeStatus
DecodePPR2Mul2RegisterClass(MCInst
&Inst
, unsigned RegNo
,
70 static DecodeStatus
DecodeFixedPointScaleImm32(MCInst
&Inst
, unsigned Imm
,
72 const MCDisassembler
*Decoder
);
73 static DecodeStatus
DecodeFixedPointScaleImm64(MCInst
&Inst
, unsigned Imm
,
75 const MCDisassembler
*Decoder
);
76 static DecodeStatus
DecodePCRelLabel16(MCInst
&Inst
, unsigned Imm
,
78 const MCDisassembler
*Decoder
);
79 static DecodeStatus
DecodePCRelLabel19(MCInst
&Inst
, unsigned Imm
,
81 const MCDisassembler
*Decoder
);
82 static DecodeStatus
DecodePCRelLabel9(MCInst
&Inst
, unsigned Imm
,
84 const MCDisassembler
*Decoder
);
85 static DecodeStatus
DecodeMemExtend(MCInst
&Inst
, unsigned Imm
,
87 const MCDisassembler
*Decoder
);
88 static DecodeStatus
DecodeMRSSystemRegister(MCInst
&Inst
, unsigned Imm
,
90 const MCDisassembler
*Decoder
);
91 static DecodeStatus
DecodeMSRSystemRegister(MCInst
&Inst
, unsigned Imm
,
93 const MCDisassembler
*Decoder
);
95 DecodeThreeAddrSRegInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Address
,
96 const MCDisassembler
*Decoder
);
97 static DecodeStatus
DecodeMoveImmInstruction(MCInst
&Inst
, uint32_t insn
,
99 const MCDisassembler
*Decoder
);
101 DecodeUnsignedLdStInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Address
,
102 const MCDisassembler
*Decoder
);
103 static DecodeStatus
DecodeSignedLdStInstruction(MCInst
&Inst
, uint32_t insn
,
105 const MCDisassembler
*Decoder
);
107 DecodeExclusiveLdStInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Address
,
108 const MCDisassembler
*Decoder
);
109 static DecodeStatus
DecodePairLdStInstruction(MCInst
&Inst
, uint32_t insn
,
111 const MCDisassembler
*Decoder
);
112 static DecodeStatus
DecodeAuthLoadInstruction(MCInst
&Inst
, uint32_t insn
,
114 const MCDisassembler
*Decoder
);
115 static DecodeStatus
DecodeAddSubERegInstruction(MCInst
&Inst
, uint32_t insn
,
117 const MCDisassembler
*Decoder
);
118 static DecodeStatus
DecodeLogicalImmInstruction(MCInst
&Inst
, uint32_t insn
,
120 const MCDisassembler
*Decoder
);
121 static DecodeStatus
DecodeModImmInstruction(MCInst
&Inst
, uint32_t insn
,
123 const MCDisassembler
*Decoder
);
124 static DecodeStatus
DecodeModImmTiedInstruction(MCInst
&Inst
, uint32_t insn
,
126 const MCDisassembler
*Decoder
);
127 static DecodeStatus
DecodeAdrInstruction(MCInst
&Inst
, uint32_t insn
,
129 const MCDisassembler
*Decoder
);
130 static DecodeStatus
DecodeAddSubImmShift(MCInst
&Inst
, uint32_t insn
,
132 const MCDisassembler
*Decoder
);
133 static DecodeStatus
DecodeUnconditionalBranch(MCInst
&Inst
, uint32_t insn
,
135 const MCDisassembler
*Decoder
);
137 DecodeSystemPStateImm0_15Instruction(MCInst
&Inst
, uint32_t insn
,
139 const MCDisassembler
*Decoder
);
141 DecodeSystemPStateImm0_1Instruction(MCInst
&Inst
, uint32_t insn
,
143 const MCDisassembler
*Decoder
);
144 static DecodeStatus
DecodeTestAndBranch(MCInst
&Inst
, uint32_t insn
,
146 const MCDisassembler
*Decoder
);
148 static DecodeStatus
DecodeFMOVLaneInstruction(MCInst
&Inst
, unsigned Insn
,
150 const MCDisassembler
*Decoder
);
151 static DecodeStatus
DecodeVecShiftR64Imm(MCInst
&Inst
, unsigned Imm
,
153 const MCDisassembler
*Decoder
);
154 static DecodeStatus
DecodeVecShiftR64ImmNarrow(MCInst
&Inst
, unsigned Imm
,
156 const MCDisassembler
*Decoder
);
157 static DecodeStatus
DecodeVecShiftR32Imm(MCInst
&Inst
, unsigned Imm
,
159 const MCDisassembler
*Decoder
);
160 static DecodeStatus
DecodeVecShiftR32ImmNarrow(MCInst
&Inst
, unsigned Imm
,
162 const MCDisassembler
*Decoder
);
163 static DecodeStatus
DecodeVecShiftR16Imm(MCInst
&Inst
, unsigned Imm
,
165 const MCDisassembler
*Decoder
);
166 static DecodeStatus
DecodeVecShiftR16ImmNarrow(MCInst
&Inst
, unsigned Imm
,
168 const MCDisassembler
*Decoder
);
169 static DecodeStatus
DecodeVecShiftR8Imm(MCInst
&Inst
, unsigned Imm
,
171 const MCDisassembler
*Decoder
);
172 static DecodeStatus
DecodeVecShiftL64Imm(MCInst
&Inst
, unsigned Imm
,
174 const MCDisassembler
*Decoder
);
175 static DecodeStatus
DecodeVecShiftL32Imm(MCInst
&Inst
, unsigned Imm
,
177 const MCDisassembler
*Decoder
);
178 static DecodeStatus
DecodeVecShiftL16Imm(MCInst
&Inst
, unsigned Imm
,
180 const MCDisassembler
*Decoder
);
181 static DecodeStatus
DecodeVecShiftL8Imm(MCInst
&Inst
, unsigned Imm
,
183 const MCDisassembler
*Decoder
);
185 DecodeWSeqPairsClassRegisterClass(MCInst
&Inst
, unsigned RegNo
, uint64_t Addr
,
186 const MCDisassembler
*Decoder
);
188 DecodeXSeqPairsClassRegisterClass(MCInst
&Inst
, unsigned RegNo
, uint64_t Addr
,
189 const MCDisassembler
*Decoder
);
190 static DecodeStatus
DecodeSyspXzrInstruction(MCInst
&Inst
, uint32_t insn
,
192 const MCDisassembler
*Decoder
);
194 DecodeSVELogicalImmInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Address
,
195 const MCDisassembler
*Decoder
);
197 static DecodeStatus
DecodeSImm(MCInst
&Inst
, uint64_t Imm
, uint64_t Address
,
198 const MCDisassembler
*Decoder
);
199 template <int ElementWidth
>
200 static DecodeStatus
DecodeImm8OptLsl(MCInst
&Inst
, unsigned Imm
, uint64_t Addr
,
201 const MCDisassembler
*Decoder
);
202 static DecodeStatus
DecodeSVEIncDecImm(MCInst
&Inst
, unsigned Imm
,
204 const MCDisassembler
*Decoder
);
205 static DecodeStatus
DecodeSVCROp(MCInst
&Inst
, unsigned Imm
, uint64_t Address
,
206 const MCDisassembler
*Decoder
);
207 static DecodeStatus
DecodeCPYMemOpInstruction(MCInst
&Inst
, uint32_t insn
,
209 const MCDisassembler
*Decoder
);
210 static DecodeStatus
DecodeSETMemOpInstruction(MCInst
&Inst
, uint32_t insn
,
212 const MCDisassembler
*Decoder
);
213 static DecodeStatus
DecodePRFMRegInstruction(MCInst
&Inst
, uint32_t insn
,
215 const MCDisassembler
*Decoder
);
217 #include "AArch64GenDisassemblerTables.inc"
218 #include "AArch64GenInstrInfo.inc"
220 #define Success MCDisassembler::Success
221 #define Fail MCDisassembler::Fail
222 #define SoftFail MCDisassembler::SoftFail
224 static MCDisassembler
*createAArch64Disassembler(const Target
&T
,
225 const MCSubtargetInfo
&STI
,
228 return new AArch64Disassembler(STI
, Ctx
, T
.createMCInstrInfo());
231 DecodeStatus
AArch64Disassembler::getInstruction(MCInst
&MI
, uint64_t &Size
,
232 ArrayRef
<uint8_t> Bytes
,
234 raw_ostream
&CS
) const {
238 // We want to read exactly 4 bytes of data.
239 if (Bytes
.size() < 4)
243 // Encoded as a small-endian 32-bit word in the stream.
245 (Bytes
[3] << 24) | (Bytes
[2] << 16) | (Bytes
[1] << 8) | (Bytes
[0] << 0);
247 const uint8_t *Tables
[] = {DecoderTable32
, DecoderTableFallback32
};
249 for (const auto *Table
: Tables
) {
250 DecodeStatus Result
=
251 decodeInstruction(Table
, MI
, Insn
, Address
, this, STI
);
253 const MCInstrDesc
&Desc
= MCII
->get(MI
.getOpcode());
255 // For Scalable Matrix Extension (SME) instructions that have an implicit
256 // operand for the accumulator (ZA) or implicit immediate zero which isn't
257 // encoded, manually insert operand.
258 for (unsigned i
= 0; i
< Desc
.getNumOperands(); i
++) {
259 if (Desc
.operands()[i
].OperandType
== MCOI::OPERAND_REGISTER
) {
260 switch (Desc
.operands()[i
].RegClass
) {
263 case AArch64::MPRRegClassID
:
264 MI
.insert(MI
.begin() + i
, MCOperand::createReg(AArch64::ZA
));
266 case AArch64::MPR8RegClassID
:
267 MI
.insert(MI
.begin() + i
, MCOperand::createReg(AArch64::ZAB0
));
269 case AArch64::ZTRRegClassID
:
270 MI
.insert(MI
.begin() + i
, MCOperand::createReg(AArch64::ZT0
));
273 } else if (Desc
.operands()[i
].OperandType
==
274 AArch64::OPERAND_IMPLICIT_IMM_0
) {
275 MI
.insert(MI
.begin() + i
, MCOperand::createImm(0));
279 if (MI
.getOpcode() == AArch64::LDR_ZA
||
280 MI
.getOpcode() == AArch64::STR_ZA
) {
281 // Spill and fill instructions have a single immediate used for both
282 // the vector select offset and optional memory offset. Replicate
283 // the decoded immediate.
284 const MCOperand
&Imm4Op
= MI
.getOperand(2);
285 assert(Imm4Op
.isImm() && "Unexpected operand type!");
286 MI
.addOperand(Imm4Op
);
289 if (Result
!= MCDisassembler::Fail
)
293 return MCDisassembler::Fail
;
296 uint64_t AArch64Disassembler::suggestBytesToSkip(ArrayRef
<uint8_t> Bytes
,
297 uint64_t Address
) const {
298 // AArch64 instructions are always 4 bytes wide, so there's no point
299 // in skipping any smaller number of bytes if an instruction can't
304 static MCSymbolizer
*
305 createAArch64ExternalSymbolizer(const Triple
&TT
, LLVMOpInfoCallback GetOpInfo
,
306 LLVMSymbolLookupCallback SymbolLookUp
,
307 void *DisInfo
, MCContext
*Ctx
,
308 std::unique_ptr
<MCRelocationInfo
> &&RelInfo
) {
309 return new AArch64ExternalSymbolizer(*Ctx
, std::move(RelInfo
), GetOpInfo
,
310 SymbolLookUp
, DisInfo
);
313 extern "C" LLVM_EXTERNAL_VISIBILITY
void LLVMInitializeAArch64Disassembler() {
314 TargetRegistry::RegisterMCDisassembler(getTheAArch64leTarget(),
315 createAArch64Disassembler
);
316 TargetRegistry::RegisterMCDisassembler(getTheAArch64beTarget(),
317 createAArch64Disassembler
);
318 TargetRegistry::RegisterMCSymbolizer(getTheAArch64leTarget(),
319 createAArch64ExternalSymbolizer
);
320 TargetRegistry::RegisterMCSymbolizer(getTheAArch64beTarget(),
321 createAArch64ExternalSymbolizer
);
322 TargetRegistry::RegisterMCDisassembler(getTheAArch64_32Target(),
323 createAArch64Disassembler
);
324 TargetRegistry::RegisterMCSymbolizer(getTheAArch64_32Target(),
325 createAArch64ExternalSymbolizer
);
327 TargetRegistry::RegisterMCDisassembler(getTheARM64Target(),
328 createAArch64Disassembler
);
329 TargetRegistry::RegisterMCSymbolizer(getTheARM64Target(),
330 createAArch64ExternalSymbolizer
);
331 TargetRegistry::RegisterMCDisassembler(getTheARM64_32Target(),
332 createAArch64Disassembler
);
333 TargetRegistry::RegisterMCSymbolizer(getTheARM64_32Target(),
334 createAArch64ExternalSymbolizer
);
337 template <unsigned RegClassID
, unsigned FirstReg
, unsigned NumRegsInClass
>
338 static DecodeStatus
DecodeSimpleRegisterClass(MCInst
&Inst
, unsigned RegNo
,
340 const MCDisassembler
*Decoder
) {
341 if (RegNo
> NumRegsInClass
- 1)
345 AArch64MCRegisterClasses
[RegClassID
].getRegister(RegNo
+ FirstReg
);
346 Inst
.addOperand(MCOperand::createReg(Register
));
351 DecodeGPR64x8ClassRegisterClass(MCInst
&Inst
, unsigned RegNo
, uint64_t Address
,
352 const MCDisassembler
*Decoder
) {
359 AArch64MCRegisterClasses
[AArch64::GPR64x8ClassRegClassID
].getRegister(
361 Inst
.addOperand(MCOperand::createReg(Register
));
365 template <unsigned Min
, unsigned Max
>
366 static DecodeStatus
DecodeZPRMul2_MinMax(MCInst
&Inst
, unsigned RegNo
,
368 const MCDisassembler
*Decoder
) {
369 unsigned Reg
= (RegNo
* 2) + Min
;
370 if (Reg
< Min
|| Reg
> Max
|| (Reg
& 1))
373 AArch64MCRegisterClasses
[AArch64::ZPRRegClassID
].getRegister(Reg
);
374 Inst
.addOperand(MCOperand::createReg(Register
));
378 template <unsigned Min
, unsigned Max
>
379 static DecodeStatus
DecodeZPR2Mul2RegisterClass(MCInst
&Inst
, unsigned RegNo
,
381 const void *Decoder
) {
382 unsigned Reg
= (RegNo
* 2) + Min
;
383 if (Reg
< Min
|| Reg
> Max
|| (Reg
& 1))
387 AArch64MCRegisterClasses
[AArch64::ZPR2RegClassID
].getRegister(Reg
);
388 Inst
.addOperand(MCOperand::createReg(Register
));
392 static DecodeStatus
DecodeZK(MCInst
&Inst
, unsigned RegNo
, uint64_t Address
,
393 const MCDisassembler
*Decoder
) {
398 AArch64MCRegisterClasses
[AArch64::ZPR_KRegClassID
].getRegister(RegNo
);
399 Inst
.addOperand(MCOperand::createReg(Register
));
403 static DecodeStatus
DecodeZPR4Mul4RegisterClass(MCInst
&Inst
, unsigned RegNo
,
405 const void *Decoder
) {
409 AArch64MCRegisterClasses
[AArch64::ZPR4RegClassID
].getRegister(RegNo
* 4);
410 Inst
.addOperand(MCOperand::createReg(Register
));
415 DecodeMatrixTileListRegisterClass(MCInst
&Inst
, unsigned RegMask
,
417 const MCDisassembler
*Decoder
) {
420 Inst
.addOperand(MCOperand::createImm(RegMask
));
424 static const MCPhysReg MatrixZATileDecoderTable
[5][16] = {
426 {AArch64::ZAH0
, AArch64::ZAH1
},
427 {AArch64::ZAS0
, AArch64::ZAS1
, AArch64::ZAS2
, AArch64::ZAS3
},
428 {AArch64::ZAD0
, AArch64::ZAD1
, AArch64::ZAD2
, AArch64::ZAD3
, AArch64::ZAD4
,
429 AArch64::ZAD5
, AArch64::ZAD6
, AArch64::ZAD7
},
430 {AArch64::ZAQ0
, AArch64::ZAQ1
, AArch64::ZAQ2
, AArch64::ZAQ3
, AArch64::ZAQ4
,
431 AArch64::ZAQ5
, AArch64::ZAQ6
, AArch64::ZAQ7
, AArch64::ZAQ8
, AArch64::ZAQ9
,
432 AArch64::ZAQ10
, AArch64::ZAQ11
, AArch64::ZAQ12
, AArch64::ZAQ13
,
433 AArch64::ZAQ14
, AArch64::ZAQ15
}};
435 template <unsigned NumBitsForTile
>
436 static DecodeStatus
DecodeMatrixTile(MCInst
&Inst
, unsigned RegNo
,
438 const MCDisassembler
*Decoder
) {
439 unsigned LastReg
= (1 << NumBitsForTile
) - 1;
443 MCOperand::createReg(MatrixZATileDecoderTable
[NumBitsForTile
][RegNo
]));
447 static DecodeStatus
DecodePPR2Mul2RegisterClass(MCInst
&Inst
, unsigned RegNo
,
449 const void *Decoder
) {
450 if ((RegNo
* 2) > 14)
453 AArch64MCRegisterClasses
[AArch64::PPR2RegClassID
].getRegister(RegNo
* 2);
454 Inst
.addOperand(MCOperand::createReg(Register
));
458 static DecodeStatus
DecodeFixedPointScaleImm32(MCInst
&Inst
, unsigned Imm
,
460 const MCDisassembler
*Decoder
) {
461 // scale{5} is asserted as 1 in tblgen.
463 Inst
.addOperand(MCOperand::createImm(64 - Imm
));
467 static DecodeStatus
DecodeFixedPointScaleImm64(MCInst
&Inst
, unsigned Imm
,
469 const MCDisassembler
*Decoder
) {
470 Inst
.addOperand(MCOperand::createImm(64 - Imm
));
474 static DecodeStatus
DecodePCRelLabel16(MCInst
&Inst
, unsigned Imm
,
476 const MCDisassembler
*Decoder
) {
477 // Immediate is encoded as the top 16-bits of an unsigned 18-bit negative
478 // PC-relative offset.
479 uint64_t ImmVal
= Imm
;
480 if (ImmVal
> (1 << 16))
483 if (!Decoder
->tryAddingSymbolicOperand(Inst
, (ImmVal
<< 2), Addr
,
484 /*IsBranch=*/false, 0, 0, 4))
485 Inst
.addOperand(MCOperand::createImm(ImmVal
));
489 static DecodeStatus
DecodePCRelLabel19(MCInst
&Inst
, unsigned Imm
,
491 const MCDisassembler
*Decoder
) {
492 int64_t ImmVal
= Imm
;
494 // Sign-extend 19-bit immediate.
495 if (ImmVal
& (1 << (19 - 1)))
496 ImmVal
|= ~((1LL << 19) - 1);
498 if (!Decoder
->tryAddingSymbolicOperand(
499 Inst
, ImmVal
* 4, Addr
, Inst
.getOpcode() != AArch64::LDRXl
, 0, 0, 4))
500 Inst
.addOperand(MCOperand::createImm(ImmVal
));
504 static DecodeStatus
DecodePCRelLabel9(MCInst
&Inst
, unsigned Imm
, uint64_t Addr
,
505 const MCDisassembler
*Decoder
) {
506 int64_t ImmVal
= Imm
;
508 // Sign-extend 9-bit immediate.
509 if (ImmVal
& (1 << (9 - 1)))
510 ImmVal
|= ~((1LL << 9) - 1);
512 if (!Decoder
->tryAddingSymbolicOperand(Inst
, (ImmVal
* 4), Addr
,
513 /*IsBranch=*/true, 0, 0, 4))
514 Inst
.addOperand(MCOperand::createImm(ImmVal
));
518 static DecodeStatus
DecodeMemExtend(MCInst
&Inst
, unsigned Imm
,
520 const MCDisassembler
*Decoder
) {
521 Inst
.addOperand(MCOperand::createImm((Imm
>> 1) & 1));
522 Inst
.addOperand(MCOperand::createImm(Imm
& 1));
526 static DecodeStatus
DecodeMRSSystemRegister(MCInst
&Inst
, unsigned Imm
,
528 const MCDisassembler
*Decoder
) {
529 Inst
.addOperand(MCOperand::createImm(Imm
));
531 // Every system register in the encoding space is valid with the syntax
532 // S<op0>_<op1>_<Cn>_<Cm>_<op2>, so decoding system registers always succeeds.
536 static DecodeStatus
DecodeMSRSystemRegister(MCInst
&Inst
, unsigned Imm
,
538 const MCDisassembler
*Decoder
) {
539 Inst
.addOperand(MCOperand::createImm(Imm
));
544 static DecodeStatus
DecodeFMOVLaneInstruction(MCInst
&Inst
, unsigned Insn
,
546 const MCDisassembler
*Decoder
) {
547 // This decoder exists to add the dummy Lane operand to the MCInst, which must
548 // be 1 in assembly but has no other real manifestation.
549 unsigned Rd
= fieldFromInstruction(Insn
, 0, 5);
550 unsigned Rn
= fieldFromInstruction(Insn
, 5, 5);
551 unsigned IsToVec
= fieldFromInstruction(Insn
, 16, 1);
554 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(
555 Inst
, Rd
, Address
, Decoder
);
556 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(
557 Inst
, Rn
, Address
, Decoder
);
559 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(
560 Inst
, Rd
, Address
, Decoder
);
561 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(
562 Inst
, Rn
, Address
, Decoder
);
566 Inst
.addOperand(MCOperand::createImm(1));
571 static DecodeStatus
DecodeVecShiftRImm(MCInst
&Inst
, unsigned Imm
,
573 Inst
.addOperand(MCOperand::createImm(Add
- Imm
));
577 static DecodeStatus
DecodeVecShiftLImm(MCInst
&Inst
, unsigned Imm
,
579 Inst
.addOperand(MCOperand::createImm((Imm
+ Add
) & (Add
- 1)));
583 static DecodeStatus
DecodeVecShiftR64Imm(MCInst
&Inst
, unsigned Imm
,
585 const MCDisassembler
*Decoder
) {
586 return DecodeVecShiftRImm(Inst
, Imm
, 64);
589 static DecodeStatus
DecodeVecShiftR64ImmNarrow(MCInst
&Inst
, unsigned Imm
,
591 const MCDisassembler
*Decoder
) {
592 return DecodeVecShiftRImm(Inst
, Imm
| 0x20, 64);
595 static DecodeStatus
DecodeVecShiftR32Imm(MCInst
&Inst
, unsigned Imm
,
597 const MCDisassembler
*Decoder
) {
598 return DecodeVecShiftRImm(Inst
, Imm
, 32);
601 static DecodeStatus
DecodeVecShiftR32ImmNarrow(MCInst
&Inst
, unsigned Imm
,
603 const MCDisassembler
*Decoder
) {
604 return DecodeVecShiftRImm(Inst
, Imm
| 0x10, 32);
607 static DecodeStatus
DecodeVecShiftR16Imm(MCInst
&Inst
, unsigned Imm
,
609 const MCDisassembler
*Decoder
) {
610 return DecodeVecShiftRImm(Inst
, Imm
, 16);
613 static DecodeStatus
DecodeVecShiftR16ImmNarrow(MCInst
&Inst
, unsigned Imm
,
615 const MCDisassembler
*Decoder
) {
616 return DecodeVecShiftRImm(Inst
, Imm
| 0x8, 16);
619 static DecodeStatus
DecodeVecShiftR8Imm(MCInst
&Inst
, unsigned Imm
,
621 const MCDisassembler
*Decoder
) {
622 return DecodeVecShiftRImm(Inst
, Imm
, 8);
625 static DecodeStatus
DecodeVecShiftL64Imm(MCInst
&Inst
, unsigned Imm
,
627 const MCDisassembler
*Decoder
) {
628 return DecodeVecShiftLImm(Inst
, Imm
, 64);
631 static DecodeStatus
DecodeVecShiftL32Imm(MCInst
&Inst
, unsigned Imm
,
633 const MCDisassembler
*Decoder
) {
634 return DecodeVecShiftLImm(Inst
, Imm
, 32);
637 static DecodeStatus
DecodeVecShiftL16Imm(MCInst
&Inst
, unsigned Imm
,
639 const MCDisassembler
*Decoder
) {
640 return DecodeVecShiftLImm(Inst
, Imm
, 16);
643 static DecodeStatus
DecodeVecShiftL8Imm(MCInst
&Inst
, unsigned Imm
,
645 const MCDisassembler
*Decoder
) {
646 return DecodeVecShiftLImm(Inst
, Imm
, 8);
650 DecodeThreeAddrSRegInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Addr
,
651 const MCDisassembler
*Decoder
) {
652 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
653 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
654 unsigned Rm
= fieldFromInstruction(insn
, 16, 5);
655 unsigned shiftHi
= fieldFromInstruction(insn
, 22, 2);
656 unsigned shiftLo
= fieldFromInstruction(insn
, 10, 6);
657 unsigned shift
= (shiftHi
<< 6) | shiftLo
;
658 switch (Inst
.getOpcode()) {
661 case AArch64::ADDWrs
:
662 case AArch64::ADDSWrs
:
663 case AArch64::SUBWrs
:
664 case AArch64::SUBSWrs
:
665 // if shift == '11' then ReservedValue()
669 case AArch64::ANDWrs
:
670 case AArch64::ANDSWrs
:
671 case AArch64::BICWrs
:
672 case AArch64::BICSWrs
:
673 case AArch64::ORRWrs
:
674 case AArch64::ORNWrs
:
675 case AArch64::EORWrs
:
676 case AArch64::EONWrs
: {
677 // if sf == '0' and imm6<5> == '1' then ReservedValue()
678 if (shiftLo
>> 5 == 1)
680 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
682 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rn
, Addr
,
684 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
688 case AArch64::ADDXrs
:
689 case AArch64::ADDSXrs
:
690 case AArch64::SUBXrs
:
691 case AArch64::SUBSXrs
:
692 // if shift == '11' then ReservedValue()
696 case AArch64::ANDXrs
:
697 case AArch64::ANDSXrs
:
698 case AArch64::BICXrs
:
699 case AArch64::BICSXrs
:
700 case AArch64::ORRXrs
:
701 case AArch64::ORNXrs
:
702 case AArch64::EORXrs
:
703 case AArch64::EONXrs
:
704 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
706 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rn
, Addr
,
708 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
713 Inst
.addOperand(MCOperand::createImm(shift
));
717 static DecodeStatus
DecodeMoveImmInstruction(MCInst
&Inst
, uint32_t insn
,
719 const MCDisassembler
*Decoder
) {
720 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
721 unsigned imm
= fieldFromInstruction(insn
, 5, 16);
722 unsigned shift
= fieldFromInstruction(insn
, 21, 2);
724 switch (Inst
.getOpcode()) {
727 case AArch64::MOVZWi
:
728 case AArch64::MOVNWi
:
729 case AArch64::MOVKWi
:
730 if (shift
& (1U << 5))
732 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
735 case AArch64::MOVZXi
:
736 case AArch64::MOVNXi
:
737 case AArch64::MOVKXi
:
738 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
743 if (Inst
.getOpcode() == AArch64::MOVKWi
||
744 Inst
.getOpcode() == AArch64::MOVKXi
)
745 Inst
.addOperand(Inst
.getOperand(0));
747 Inst
.addOperand(MCOperand::createImm(imm
));
748 Inst
.addOperand(MCOperand::createImm(shift
));
753 DecodeUnsignedLdStInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Addr
,
754 const MCDisassembler
*Decoder
) {
755 unsigned Rt
= fieldFromInstruction(insn
, 0, 5);
756 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
757 unsigned offset
= fieldFromInstruction(insn
, 10, 12);
759 switch (Inst
.getOpcode()) {
762 case AArch64::PRFMui
:
763 // Rt is an immediate in prefetch.
764 Inst
.addOperand(MCOperand::createImm(Rt
));
766 case AArch64::STRBBui
:
767 case AArch64::LDRBBui
:
768 case AArch64::LDRSBWui
:
769 case AArch64::STRHHui
:
770 case AArch64::LDRHHui
:
771 case AArch64::LDRSHWui
:
772 case AArch64::STRWui
:
773 case AArch64::LDRWui
:
774 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
777 case AArch64::LDRSBXui
:
778 case AArch64::LDRSHXui
:
779 case AArch64::LDRSWui
:
780 case AArch64::STRXui
:
781 case AArch64::LDRXui
:
782 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
785 case AArch64::LDRQui
:
786 case AArch64::STRQui
:
787 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
790 case AArch64::LDRDui
:
791 case AArch64::STRDui
:
792 DecodeSimpleRegisterClass
<AArch64::FPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
795 case AArch64::LDRSui
:
796 case AArch64::STRSui
:
797 DecodeSimpleRegisterClass
<AArch64::FPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
800 case AArch64::LDRHui
:
801 case AArch64::STRHui
:
802 DecodeSimpleRegisterClass
<AArch64::FPR16RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
805 case AArch64::LDRBui
:
806 case AArch64::STRBui
:
807 DecodeSimpleRegisterClass
<AArch64::FPR8RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
812 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
814 if (!Decoder
->tryAddingSymbolicOperand(Inst
, offset
, Addr
, Fail
, 0, 0, 4))
815 Inst
.addOperand(MCOperand::createImm(offset
));
819 static DecodeStatus
DecodeSignedLdStInstruction(MCInst
&Inst
, uint32_t insn
,
821 const MCDisassembler
*Decoder
) {
822 unsigned Rt
= fieldFromInstruction(insn
, 0, 5);
823 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
824 int64_t offset
= fieldFromInstruction(insn
, 12, 9);
826 // offset is a 9-bit signed immediate, so sign extend it to
827 // fill the unsigned.
828 if (offset
& (1 << (9 - 1)))
829 offset
|= ~((1LL << 9) - 1);
831 // First operand is always the writeback to the address register, if needed.
832 switch (Inst
.getOpcode()) {
835 case AArch64::LDRSBWpre
:
836 case AArch64::LDRSHWpre
:
837 case AArch64::STRBBpre
:
838 case AArch64::LDRBBpre
:
839 case AArch64::STRHHpre
:
840 case AArch64::LDRHHpre
:
841 case AArch64::STRWpre
:
842 case AArch64::LDRWpre
:
843 case AArch64::LDRSBWpost
:
844 case AArch64::LDRSHWpost
:
845 case AArch64::STRBBpost
:
846 case AArch64::LDRBBpost
:
847 case AArch64::STRHHpost
:
848 case AArch64::LDRHHpost
:
849 case AArch64::STRWpost
:
850 case AArch64::LDRWpost
:
851 case AArch64::LDRSBXpre
:
852 case AArch64::LDRSHXpre
:
853 case AArch64::STRXpre
:
854 case AArch64::LDRSWpre
:
855 case AArch64::LDRXpre
:
856 case AArch64::LDRSBXpost
:
857 case AArch64::LDRSHXpost
:
858 case AArch64::STRXpost
:
859 case AArch64::LDRSWpost
:
860 case AArch64::LDRXpost
:
861 case AArch64::LDRQpre
:
862 case AArch64::STRQpre
:
863 case AArch64::LDRQpost
:
864 case AArch64::STRQpost
:
865 case AArch64::LDRDpre
:
866 case AArch64::STRDpre
:
867 case AArch64::LDRDpost
:
868 case AArch64::STRDpost
:
869 case AArch64::LDRSpre
:
870 case AArch64::STRSpre
:
871 case AArch64::LDRSpost
:
872 case AArch64::STRSpost
:
873 case AArch64::LDRHpre
:
874 case AArch64::STRHpre
:
875 case AArch64::LDRHpost
:
876 case AArch64::STRHpost
:
877 case AArch64::LDRBpre
:
878 case AArch64::STRBpre
:
879 case AArch64::LDRBpost
:
880 case AArch64::STRBpost
:
881 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
886 switch (Inst
.getOpcode()) {
889 case AArch64::PRFUMi
:
890 // Rt is an immediate in prefetch.
891 Inst
.addOperand(MCOperand::createImm(Rt
));
893 case AArch64::STURBBi
:
894 case AArch64::LDURBBi
:
895 case AArch64::LDURSBWi
:
896 case AArch64::STURHHi
:
897 case AArch64::LDURHHi
:
898 case AArch64::LDURSHWi
:
899 case AArch64::STURWi
:
900 case AArch64::LDURWi
:
901 case AArch64::LDTRSBWi
:
902 case AArch64::LDTRSHWi
:
903 case AArch64::STTRWi
:
904 case AArch64::LDTRWi
:
905 case AArch64::STTRHi
:
906 case AArch64::LDTRHi
:
907 case AArch64::LDTRBi
:
908 case AArch64::STTRBi
:
909 case AArch64::LDRSBWpre
:
910 case AArch64::LDRSHWpre
:
911 case AArch64::STRBBpre
:
912 case AArch64::LDRBBpre
:
913 case AArch64::STRHHpre
:
914 case AArch64::LDRHHpre
:
915 case AArch64::STRWpre
:
916 case AArch64::LDRWpre
:
917 case AArch64::LDRSBWpost
:
918 case AArch64::LDRSHWpost
:
919 case AArch64::STRBBpost
:
920 case AArch64::LDRBBpost
:
921 case AArch64::STRHHpost
:
922 case AArch64::LDRHHpost
:
923 case AArch64::STRWpost
:
924 case AArch64::LDRWpost
:
925 case AArch64::STLURBi
:
926 case AArch64::STLURHi
:
927 case AArch64::STLURWi
:
928 case AArch64::LDAPURBi
:
929 case AArch64::LDAPURSBWi
:
930 case AArch64::LDAPURHi
:
931 case AArch64::LDAPURSHWi
:
932 case AArch64::LDAPURi
:
933 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
936 case AArch64::LDURSBXi
:
937 case AArch64::LDURSHXi
:
938 case AArch64::LDURSWi
:
939 case AArch64::STURXi
:
940 case AArch64::LDURXi
:
941 case AArch64::LDTRSBXi
:
942 case AArch64::LDTRSHXi
:
943 case AArch64::LDTRSWi
:
944 case AArch64::STTRXi
:
945 case AArch64::LDTRXi
:
946 case AArch64::LDRSBXpre
:
947 case AArch64::LDRSHXpre
:
948 case AArch64::STRXpre
:
949 case AArch64::LDRSWpre
:
950 case AArch64::LDRXpre
:
951 case AArch64::LDRSBXpost
:
952 case AArch64::LDRSHXpost
:
953 case AArch64::STRXpost
:
954 case AArch64::LDRSWpost
:
955 case AArch64::LDRXpost
:
956 case AArch64::LDAPURSWi
:
957 case AArch64::LDAPURSHXi
:
958 case AArch64::LDAPURSBXi
:
959 case AArch64::STLURXi
:
960 case AArch64::LDAPURXi
:
961 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
964 case AArch64::LDURQi
:
965 case AArch64::STURQi
:
966 case AArch64::LDRQpre
:
967 case AArch64::STRQpre
:
968 case AArch64::LDRQpost
:
969 case AArch64::STRQpost
:
970 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
973 case AArch64::LDURDi
:
974 case AArch64::STURDi
:
975 case AArch64::LDRDpre
:
976 case AArch64::STRDpre
:
977 case AArch64::LDRDpost
:
978 case AArch64::STRDpost
:
979 DecodeSimpleRegisterClass
<AArch64::FPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
982 case AArch64::LDURSi
:
983 case AArch64::STURSi
:
984 case AArch64::LDRSpre
:
985 case AArch64::STRSpre
:
986 case AArch64::LDRSpost
:
987 case AArch64::STRSpost
:
988 DecodeSimpleRegisterClass
<AArch64::FPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
991 case AArch64::LDURHi
:
992 case AArch64::STURHi
:
993 case AArch64::LDRHpre
:
994 case AArch64::STRHpre
:
995 case AArch64::LDRHpost
:
996 case AArch64::STRHpost
:
997 DecodeSimpleRegisterClass
<AArch64::FPR16RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1000 case AArch64::LDURBi
:
1001 case AArch64::STURBi
:
1002 case AArch64::LDRBpre
:
1003 case AArch64::STRBpre
:
1004 case AArch64::LDRBpost
:
1005 case AArch64::STRBpost
:
1006 DecodeSimpleRegisterClass
<AArch64::FPR8RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1011 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1013 Inst
.addOperand(MCOperand::createImm(offset
));
1015 bool IsLoad
= fieldFromInstruction(insn
, 22, 1);
1016 bool IsIndexed
= fieldFromInstruction(insn
, 10, 2) != 0;
1017 bool IsFP
= fieldFromInstruction(insn
, 26, 1);
1019 // Cannot write back to a transfer register (but xzr != sp).
1020 if (IsLoad
&& IsIndexed
&& !IsFP
&& Rn
!= 31 && Rt
== Rn
)
1027 DecodeExclusiveLdStInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Addr
,
1028 const MCDisassembler
*Decoder
) {
1029 unsigned Rt
= fieldFromInstruction(insn
, 0, 5);
1030 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1031 unsigned Rt2
= fieldFromInstruction(insn
, 10, 5);
1032 unsigned Rs
= fieldFromInstruction(insn
, 16, 5);
1034 unsigned Opcode
= Inst
.getOpcode();
1038 case AArch64::STLXRW
:
1039 case AArch64::STLXRB
:
1040 case AArch64::STLXRH
:
1041 case AArch64::STXRW
:
1042 case AArch64::STXRB
:
1043 case AArch64::STXRH
:
1044 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rs
, Addr
,
1047 case AArch64::LDARW
:
1048 case AArch64::LDARB
:
1049 case AArch64::LDARH
:
1050 case AArch64::LDAXRW
:
1051 case AArch64::LDAXRB
:
1052 case AArch64::LDAXRH
:
1053 case AArch64::LDXRW
:
1054 case AArch64::LDXRB
:
1055 case AArch64::LDXRH
:
1056 case AArch64::STLRW
:
1057 case AArch64::STLRB
:
1058 case AArch64::STLRH
:
1059 case AArch64::STLLRW
:
1060 case AArch64::STLLRB
:
1061 case AArch64::STLLRH
:
1062 case AArch64::LDLARW
:
1063 case AArch64::LDLARB
:
1064 case AArch64::LDLARH
:
1065 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1068 case AArch64::STLXRX
:
1069 case AArch64::STXRX
:
1070 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rs
, Addr
,
1073 case AArch64::LDARX
:
1074 case AArch64::LDAXRX
:
1075 case AArch64::LDXRX
:
1076 case AArch64::STLRX
:
1077 case AArch64::LDLARX
:
1078 case AArch64::STLLRX
:
1079 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1082 case AArch64::STLXPW
:
1083 case AArch64::STXPW
:
1084 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rs
, Addr
,
1087 case AArch64::LDAXPW
:
1088 case AArch64::LDXPW
:
1089 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1091 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt2
, Addr
,
1094 case AArch64::STLXPX
:
1095 case AArch64::STXPX
:
1096 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rs
, Addr
,
1099 case AArch64::LDAXPX
:
1100 case AArch64::LDXPX
:
1101 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1103 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt2
, Addr
,
1108 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1111 // You shouldn't load to the same register twice in an instruction...
1112 if ((Opcode
== AArch64::LDAXPW
|| Opcode
== AArch64::LDXPW
||
1113 Opcode
== AArch64::LDAXPX
|| Opcode
== AArch64::LDXPX
) &&
1120 static DecodeStatus
DecodePairLdStInstruction(MCInst
&Inst
, uint32_t insn
,
1122 const MCDisassembler
*Decoder
) {
1123 unsigned Rt
= fieldFromInstruction(insn
, 0, 5);
1124 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1125 unsigned Rt2
= fieldFromInstruction(insn
, 10, 5);
1126 int64_t offset
= fieldFromInstruction(insn
, 15, 7);
1127 bool IsLoad
= fieldFromInstruction(insn
, 22, 1);
1129 // offset is a 7-bit signed immediate, so sign extend it to
1130 // fill the unsigned.
1131 if (offset
& (1 << (7 - 1)))
1132 offset
|= ~((1LL << 7) - 1);
1134 unsigned Opcode
= Inst
.getOpcode();
1135 bool NeedsDisjointWritebackTransfer
= false;
1137 // First operand is always writeback of base register.
1141 case AArch64::LDPXpost
:
1142 case AArch64::STPXpost
:
1143 case AArch64::LDPSWpost
:
1144 case AArch64::LDPXpre
:
1145 case AArch64::STPXpre
:
1146 case AArch64::LDPSWpre
:
1147 case AArch64::LDPWpost
:
1148 case AArch64::STPWpost
:
1149 case AArch64::LDPWpre
:
1150 case AArch64::STPWpre
:
1151 case AArch64::LDPQpost
:
1152 case AArch64::STPQpost
:
1153 case AArch64::LDPQpre
:
1154 case AArch64::STPQpre
:
1155 case AArch64::LDPDpost
:
1156 case AArch64::STPDpost
:
1157 case AArch64::LDPDpre
:
1158 case AArch64::STPDpre
:
1159 case AArch64::LDPSpost
:
1160 case AArch64::STPSpost
:
1161 case AArch64::LDPSpre
:
1162 case AArch64::STPSpre
:
1163 case AArch64::STGPpre
:
1164 case AArch64::STGPpost
:
1165 case AArch64::LDTPpre
:
1166 case AArch64::LDTPpost
:
1167 case AArch64::LDTPQpost
:
1168 case AArch64::LDTPQpre
:
1169 case AArch64::STTPpost
:
1170 case AArch64::STTPpre
:
1171 case AArch64::STTPQpost
:
1172 case AArch64::STTPQpre
:
1173 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1181 case AArch64::LDPXpost
:
1182 case AArch64::STPXpost
:
1183 case AArch64::LDPSWpost
:
1184 case AArch64::LDPXpre
:
1185 case AArch64::STPXpre
:
1186 case AArch64::LDPSWpre
:
1187 case AArch64::STGPpre
:
1188 case AArch64::STGPpost
:
1189 case AArch64::LDTPpost
:
1190 case AArch64::LDTPpre
:
1191 case AArch64::STTPpost
:
1192 case AArch64::STTPpre
:
1193 NeedsDisjointWritebackTransfer
= true;
1195 case AArch64::LDNPXi
:
1196 case AArch64::STNPXi
:
1197 case AArch64::LDPXi
:
1198 case AArch64::STPXi
:
1199 case AArch64::LDPSWi
:
1200 case AArch64::STGPi
:
1201 case AArch64::LDTPi
:
1202 case AArch64::STTPi
:
1203 case AArch64::STTNPXi
:
1204 case AArch64::LDTNPXi
:
1205 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1207 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt2
, Addr
,
1210 case AArch64::LDPWpost
:
1211 case AArch64::STPWpost
:
1212 case AArch64::LDPWpre
:
1213 case AArch64::STPWpre
:
1214 NeedsDisjointWritebackTransfer
= true;
1216 case AArch64::LDNPWi
:
1217 case AArch64::STNPWi
:
1218 case AArch64::LDPWi
:
1219 case AArch64::STPWi
:
1220 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1222 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt2
, Addr
,
1225 case AArch64::LDNPQi
:
1226 case AArch64::STNPQi
:
1227 case AArch64::LDPQpost
:
1228 case AArch64::STPQpost
:
1229 case AArch64::LDPQi
:
1230 case AArch64::STPQi
:
1231 case AArch64::LDPQpre
:
1232 case AArch64::STPQpre
:
1233 case AArch64::LDTPQi
:
1234 case AArch64::LDTPQpost
:
1235 case AArch64::LDTPQpre
:
1236 case AArch64::LDTNPQi
:
1237 case AArch64::STTPQi
:
1238 case AArch64::STTPQpost
:
1239 case AArch64::STTPQpre
:
1240 case AArch64::STTNPQi
:
1241 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1243 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(Inst
, Rt2
, Addr
,
1246 case AArch64::LDNPDi
:
1247 case AArch64::STNPDi
:
1248 case AArch64::LDPDpost
:
1249 case AArch64::STPDpost
:
1250 case AArch64::LDPDi
:
1251 case AArch64::STPDi
:
1252 case AArch64::LDPDpre
:
1253 case AArch64::STPDpre
:
1254 DecodeSimpleRegisterClass
<AArch64::FPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1256 DecodeSimpleRegisterClass
<AArch64::FPR64RegClassID
, 0, 32>(Inst
, Rt2
, Addr
,
1259 case AArch64::LDNPSi
:
1260 case AArch64::STNPSi
:
1261 case AArch64::LDPSpost
:
1262 case AArch64::STPSpost
:
1263 case AArch64::LDPSi
:
1264 case AArch64::STPSi
:
1265 case AArch64::LDPSpre
:
1266 case AArch64::STPSpre
:
1267 DecodeSimpleRegisterClass
<AArch64::FPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1269 DecodeSimpleRegisterClass
<AArch64::FPR32RegClassID
, 0, 32>(Inst
, Rt2
, Addr
,
1274 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1276 Inst
.addOperand(MCOperand::createImm(offset
));
1278 // You shouldn't load to the same register twice in an instruction...
1279 if (IsLoad
&& Rt
== Rt2
)
1282 // ... or do any operation that writes-back to a transfer register. But note
1283 // that "stp xzr, xzr, [sp], #4" is fine because xzr and sp are different.
1284 if (NeedsDisjointWritebackTransfer
&& Rn
!= 31 && (Rt
== Rn
|| Rt2
== Rn
))
1290 static DecodeStatus
DecodeAuthLoadInstruction(MCInst
&Inst
, uint32_t insn
,
1292 const MCDisassembler
*Decoder
) {
1293 unsigned Rt
= fieldFromInstruction(insn
, 0, 5);
1294 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1295 uint64_t offset
= fieldFromInstruction(insn
, 22, 1) << 9 |
1296 fieldFromInstruction(insn
, 12, 9);
1297 unsigned writeback
= fieldFromInstruction(insn
, 11, 1);
1299 switch (Inst
.getOpcode()) {
1302 case AArch64::LDRAAwriteback
:
1303 case AArch64::LDRABwriteback
:
1304 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(
1305 Inst
, Rn
/* writeback register */, Addr
, Decoder
);
1307 case AArch64::LDRAAindexed
:
1308 case AArch64::LDRABindexed
:
1312 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1314 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1316 DecodeSImm
<10>(Inst
, offset
, Addr
, Decoder
);
1318 if (writeback
&& Rt
== Rn
&& Rn
!= 31) {
1325 static DecodeStatus
DecodeAddSubERegInstruction(MCInst
&Inst
, uint32_t insn
,
1327 const MCDisassembler
*Decoder
) {
1328 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1329 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1330 unsigned Rm
= fieldFromInstruction(insn
, 16, 5);
1331 unsigned extend
= fieldFromInstruction(insn
, 10, 6);
1333 unsigned shift
= extend
& 0x7;
1337 switch (Inst
.getOpcode()) {
1340 case AArch64::ADDWrx
:
1341 case AArch64::SUBWrx
:
1342 DecodeSimpleRegisterClass
<AArch64::GPR32spRegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1344 DecodeSimpleRegisterClass
<AArch64::GPR32spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1346 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1349 case AArch64::ADDSWrx
:
1350 case AArch64::SUBSWrx
:
1351 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1353 DecodeSimpleRegisterClass
<AArch64::GPR32spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1355 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1358 case AArch64::ADDXrx
:
1359 case AArch64::SUBXrx
:
1360 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1362 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1364 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1367 case AArch64::ADDSXrx
:
1368 case AArch64::SUBSXrx
:
1369 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1371 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1373 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1376 case AArch64::ADDXrx64
:
1377 case AArch64::SUBXrx64
:
1378 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1380 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1382 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1385 case AArch64::SUBSXrx64
:
1386 case AArch64::ADDSXrx64
:
1387 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1389 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1391 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1396 Inst
.addOperand(MCOperand::createImm(extend
));
1400 static DecodeStatus
DecodeLogicalImmInstruction(MCInst
&Inst
, uint32_t insn
,
1402 const MCDisassembler
*Decoder
) {
1403 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1404 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1405 unsigned Datasize
= fieldFromInstruction(insn
, 31, 1);
1409 if (Inst
.getOpcode() == AArch64::ANDSXri
)
1410 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1413 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(
1414 Inst
, Rd
, Addr
, Decoder
);
1415 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1417 imm
= fieldFromInstruction(insn
, 10, 13);
1418 if (!AArch64_AM::isValidDecodeLogicalImmediate(imm
, 64))
1421 if (Inst
.getOpcode() == AArch64::ANDSWri
)
1422 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1425 DecodeSimpleRegisterClass
<AArch64::GPR32spRegClassID
, 0, 32>(
1426 Inst
, Rd
, Addr
, Decoder
);
1427 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1429 imm
= fieldFromInstruction(insn
, 10, 12);
1430 if (!AArch64_AM::isValidDecodeLogicalImmediate(imm
, 32))
1433 Inst
.addOperand(MCOperand::createImm(imm
));
1437 static DecodeStatus
DecodeModImmInstruction(MCInst
&Inst
, uint32_t insn
,
1439 const MCDisassembler
*Decoder
) {
1440 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1441 unsigned cmode
= fieldFromInstruction(insn
, 12, 4);
1442 unsigned imm
= fieldFromInstruction(insn
, 16, 3) << 5;
1443 imm
|= fieldFromInstruction(insn
, 5, 5);
1445 if (Inst
.getOpcode() == AArch64::MOVID
)
1446 DecodeSimpleRegisterClass
<AArch64::FPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1449 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1452 Inst
.addOperand(MCOperand::createImm(imm
));
1454 switch (Inst
.getOpcode()) {
1457 case AArch64::MOVIv4i16
:
1458 case AArch64::MOVIv8i16
:
1459 case AArch64::MVNIv4i16
:
1460 case AArch64::MVNIv8i16
:
1461 case AArch64::MOVIv2i32
:
1462 case AArch64::MOVIv4i32
:
1463 case AArch64::MVNIv2i32
:
1464 case AArch64::MVNIv4i32
:
1465 Inst
.addOperand(MCOperand::createImm((cmode
& 6) << 2));
1467 case AArch64::MOVIv2s_msl
:
1468 case AArch64::MOVIv4s_msl
:
1469 case AArch64::MVNIv2s_msl
:
1470 case AArch64::MVNIv4s_msl
:
1471 Inst
.addOperand(MCOperand::createImm((cmode
& 1) ? 0x110 : 0x108));
1478 static DecodeStatus
DecodeModImmTiedInstruction(MCInst
&Inst
, uint32_t insn
,
1480 const MCDisassembler
*Decoder
) {
1481 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1482 unsigned cmode
= fieldFromInstruction(insn
, 12, 4);
1483 unsigned imm
= fieldFromInstruction(insn
, 16, 3) << 5;
1484 imm
|= fieldFromInstruction(insn
, 5, 5);
1486 // Tied operands added twice.
1487 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1489 DecodeSimpleRegisterClass
<AArch64::FPR128RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1492 Inst
.addOperand(MCOperand::createImm(imm
));
1493 Inst
.addOperand(MCOperand::createImm((cmode
& 6) << 2));
1498 static DecodeStatus
DecodeAdrInstruction(MCInst
&Inst
, uint32_t insn
,
1500 const MCDisassembler
*Decoder
) {
1501 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1502 int64_t imm
= fieldFromInstruction(insn
, 5, 19) << 2;
1503 imm
|= fieldFromInstruction(insn
, 29, 2);
1505 // Sign-extend the 21-bit immediate.
1506 if (imm
& (1 << (21 - 1)))
1507 imm
|= ~((1LL << 21) - 1);
1509 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1511 if (!Decoder
->tryAddingSymbolicOperand(Inst
, imm
, Addr
, Fail
, 0, 0, 4))
1512 Inst
.addOperand(MCOperand::createImm(imm
));
1517 static DecodeStatus
DecodeAddSubImmShift(MCInst
&Inst
, uint32_t insn
,
1519 const MCDisassembler
*Decoder
) {
1520 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1521 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1522 unsigned Imm
= fieldFromInstruction(insn
, 10, 14);
1523 unsigned S
= fieldFromInstruction(insn
, 29, 1);
1524 unsigned Datasize
= fieldFromInstruction(insn
, 31, 1);
1526 unsigned ShifterVal
= (Imm
>> 12) & 3;
1527 unsigned ImmVal
= Imm
& 0xFFF;
1529 if (ShifterVal
!= 0 && ShifterVal
!= 1)
1534 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(
1535 Inst
, Rd
, Addr
, Decoder
);
1537 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1539 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1543 DecodeSimpleRegisterClass
<AArch64::GPR32spRegClassID
, 0, 32>(
1544 Inst
, Rd
, Addr
, Decoder
);
1546 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rd
, Addr
,
1548 DecodeSimpleRegisterClass
<AArch64::GPR32spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1552 if (!Decoder
->tryAddingSymbolicOperand(Inst
, Imm
, Addr
, Fail
, 0, 0, 4))
1553 Inst
.addOperand(MCOperand::createImm(ImmVal
));
1554 Inst
.addOperand(MCOperand::createImm(12 * ShifterVal
));
1558 static DecodeStatus
DecodeUnconditionalBranch(MCInst
&Inst
, uint32_t insn
,
1560 const MCDisassembler
*Decoder
) {
1561 int64_t imm
= fieldFromInstruction(insn
, 0, 26);
1563 // Sign-extend the 26-bit immediate.
1564 if (imm
& (1 << (26 - 1)))
1565 imm
|= ~((1LL << 26) - 1);
1567 if (!Decoder
->tryAddingSymbolicOperand(Inst
, imm
* 4, Addr
, true, 0, 0, 4))
1568 Inst
.addOperand(MCOperand::createImm(imm
));
1573 static bool isInvalidPState(uint64_t Op1
, uint64_t Op2
) {
1574 return Op1
== 0b000 && (Op2
== 0b000 || // CFINV
1575 Op2
== 0b001 || // XAFlag
1576 Op2
== 0b010); // AXFlag
1580 DecodeSystemPStateImm0_15Instruction(MCInst
&Inst
, uint32_t insn
, uint64_t Addr
,
1581 const MCDisassembler
*Decoder
) {
1582 uint64_t op1
= fieldFromInstruction(insn
, 16, 3);
1583 uint64_t op2
= fieldFromInstruction(insn
, 5, 3);
1584 uint64_t imm
= fieldFromInstruction(insn
, 8, 4);
1585 uint64_t pstate_field
= (op1
<< 3) | op2
;
1587 if (isInvalidPState(op1
, op2
))
1590 Inst
.addOperand(MCOperand::createImm(pstate_field
));
1591 Inst
.addOperand(MCOperand::createImm(imm
));
1593 auto PState
= AArch64PState::lookupPStateImm0_15ByEncoding(pstate_field
);
1595 PState
->haveFeatures(Decoder
->getSubtargetInfo().getFeatureBits()))
1601 DecodeSystemPStateImm0_1Instruction(MCInst
&Inst
, uint32_t insn
, uint64_t Addr
,
1602 const MCDisassembler
*Decoder
) {
1603 uint64_t op1
= fieldFromInstruction(insn
, 16, 3);
1604 uint64_t op2
= fieldFromInstruction(insn
, 5, 3);
1605 uint64_t crm_high
= fieldFromInstruction(insn
, 9, 3);
1606 uint64_t imm
= fieldFromInstruction(insn
, 8, 1);
1607 uint64_t pstate_field
= (crm_high
<< 6) | (op1
<< 3) | op2
;
1609 if (isInvalidPState(op1
, op2
))
1612 Inst
.addOperand(MCOperand::createImm(pstate_field
));
1613 Inst
.addOperand(MCOperand::createImm(imm
));
1615 auto PState
= AArch64PState::lookupPStateImm0_1ByEncoding(pstate_field
);
1617 PState
->haveFeatures(Decoder
->getSubtargetInfo().getFeatureBits()))
1622 static DecodeStatus
DecodeTestAndBranch(MCInst
&Inst
, uint32_t insn
,
1624 const MCDisassembler
*Decoder
) {
1625 uint64_t Rt
= fieldFromInstruction(insn
, 0, 5);
1626 uint64_t bit
= fieldFromInstruction(insn
, 31, 1) << 5;
1627 bit
|= fieldFromInstruction(insn
, 19, 5);
1628 int64_t dst
= fieldFromInstruction(insn
, 5, 14);
1630 // Sign-extend 14-bit immediate.
1631 if (dst
& (1 << (14 - 1)))
1632 dst
|= ~((1LL << 14) - 1);
1634 if (fieldFromInstruction(insn
, 31, 1) == 0)
1635 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1638 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1640 Inst
.addOperand(MCOperand::createImm(bit
));
1641 if (!Decoder
->tryAddingSymbolicOperand(Inst
, dst
* 4, Addr
, true, 0, 0, 4))
1642 Inst
.addOperand(MCOperand::createImm(dst
));
1648 DecodeGPRSeqPairsClassRegisterClass(MCInst
&Inst
, unsigned RegClassID
,
1649 unsigned RegNo
, uint64_t Addr
,
1650 const MCDisassembler
*Decoder
) {
1651 // Register number must be even (see CASP instruction)
1655 unsigned Reg
= AArch64MCRegisterClasses
[RegClassID
].getRegister(RegNo
/ 2);
1656 Inst
.addOperand(MCOperand::createReg(Reg
));
1661 DecodeWSeqPairsClassRegisterClass(MCInst
&Inst
, unsigned RegNo
, uint64_t Addr
,
1662 const MCDisassembler
*Decoder
) {
1663 return DecodeGPRSeqPairsClassRegisterClass(
1664 Inst
, AArch64::WSeqPairsClassRegClassID
, RegNo
, Addr
, Decoder
);
1668 DecodeXSeqPairsClassRegisterClass(MCInst
&Inst
, unsigned RegNo
, uint64_t Addr
,
1669 const MCDisassembler
*Decoder
) {
1670 return DecodeGPRSeqPairsClassRegisterClass(
1671 Inst
, AArch64::XSeqPairsClassRegClassID
, RegNo
, Addr
, Decoder
);
1674 static DecodeStatus
DecodeSyspXzrInstruction(MCInst
&Inst
, uint32_t insn
,
1676 const MCDisassembler
*Decoder
) {
1677 unsigned op1
= fieldFromInstruction(insn
, 16, 3);
1678 unsigned CRn
= fieldFromInstruction(insn
, 12, 4);
1679 unsigned CRm
= fieldFromInstruction(insn
, 8, 4);
1680 unsigned op2
= fieldFromInstruction(insn
, 5, 3);
1681 unsigned Rt
= fieldFromInstruction(insn
, 0, 5);
1685 Inst
.addOperand(MCOperand::createImm(op1
));
1686 Inst
.addOperand(MCOperand::createImm(CRn
));
1687 Inst
.addOperand(MCOperand::createImm(CRm
));
1688 Inst
.addOperand(MCOperand::createImm(op2
));
1689 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rt
, Addr
,
1696 DecodeSVELogicalImmInstruction(MCInst
&Inst
, uint32_t insn
, uint64_t Addr
,
1697 const MCDisassembler
*Decoder
) {
1698 unsigned Zdn
= fieldFromInstruction(insn
, 0, 5);
1699 unsigned imm
= fieldFromInstruction(insn
, 5, 13);
1700 if (!AArch64_AM::isValidDecodeLogicalImmediate(imm
, 64))
1703 // The same (tied) operand is added twice to the instruction.
1704 DecodeSimpleRegisterClass
<AArch64::ZPRRegClassID
, 0, 32>(Inst
, Zdn
, Addr
,
1706 if (Inst
.getOpcode() != AArch64::DUPM_ZI
)
1707 DecodeSimpleRegisterClass
<AArch64::ZPRRegClassID
, 0, 32>(Inst
, Zdn
, Addr
,
1709 Inst
.addOperand(MCOperand::createImm(imm
));
1714 static DecodeStatus
DecodeSImm(MCInst
&Inst
, uint64_t Imm
, uint64_t Address
,
1715 const MCDisassembler
*Decoder
) {
1716 if (Imm
& ~((1LL << Bits
) - 1))
1719 // Imm is a signed immediate, so sign extend it.
1720 if (Imm
& (1 << (Bits
- 1)))
1721 Imm
|= ~((1LL << Bits
) - 1);
1723 Inst
.addOperand(MCOperand::createImm(Imm
));
1727 // Decode 8-bit signed/unsigned immediate for a given element width.
1728 template <int ElementWidth
>
1729 static DecodeStatus
DecodeImm8OptLsl(MCInst
&Inst
, unsigned Imm
, uint64_t Addr
,
1730 const MCDisassembler
*Decoder
) {
1731 unsigned Val
= (uint8_t)Imm
;
1732 unsigned Shift
= (Imm
& 0x100) ? 8 : 0;
1733 if (ElementWidth
== 8 && Shift
)
1735 Inst
.addOperand(MCOperand::createImm(Val
));
1736 Inst
.addOperand(MCOperand::createImm(Shift
));
1740 // Decode uimm4 ranged from 1-16.
1741 static DecodeStatus
DecodeSVEIncDecImm(MCInst
&Inst
, unsigned Imm
,
1743 const MCDisassembler
*Decoder
) {
1744 Inst
.addOperand(MCOperand::createImm(Imm
+ 1));
1748 static DecodeStatus
DecodeSVCROp(MCInst
&Inst
, unsigned Imm
, uint64_t Address
,
1749 const MCDisassembler
*Decoder
) {
1750 if (AArch64SVCR::lookupSVCRByEncoding(Imm
)) {
1751 Inst
.addOperand(MCOperand::createImm(Imm
));
1757 static DecodeStatus
DecodeCPYMemOpInstruction(MCInst
&Inst
, uint32_t insn
,
1759 const MCDisassembler
*Decoder
) {
1760 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1761 unsigned Rs
= fieldFromInstruction(insn
, 16, 5);
1762 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1764 // None of the registers may alias: if they do, then the instruction is not
1765 // merely unpredictable but actually entirely unallocated.
1766 if (Rd
== Rs
|| Rs
== Rn
|| Rd
== Rn
)
1767 return MCDisassembler::Fail
;
1769 // All three register operands are written back, so they all appear
1770 // twice in the operand list, once as outputs and once as inputs.
1771 if (!DecodeSimpleRegisterClass
<AArch64::GPR64commonRegClassID
, 0, 31>(
1772 Inst
, Rd
, Addr
, Decoder
) ||
1773 !DecodeSimpleRegisterClass
<AArch64::GPR64commonRegClassID
, 0, 31>(
1774 Inst
, Rs
, Addr
, Decoder
) ||
1775 !DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(
1776 Inst
, Rn
, Addr
, Decoder
) ||
1777 !DecodeSimpleRegisterClass
<AArch64::GPR64commonRegClassID
, 0, 31>(
1778 Inst
, Rd
, Addr
, Decoder
) ||
1779 !DecodeSimpleRegisterClass
<AArch64::GPR64commonRegClassID
, 0, 31>(
1780 Inst
, Rs
, Addr
, Decoder
) ||
1781 !DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(
1782 Inst
, Rn
, Addr
, Decoder
))
1783 return MCDisassembler::Fail
;
1785 return MCDisassembler::Success
;
1788 static DecodeStatus
DecodeSETMemOpInstruction(MCInst
&Inst
, uint32_t insn
,
1790 const MCDisassembler
*Decoder
) {
1791 unsigned Rd
= fieldFromInstruction(insn
, 0, 5);
1792 unsigned Rm
= fieldFromInstruction(insn
, 16, 5);
1793 unsigned Rn
= fieldFromInstruction(insn
, 5, 5);
1795 // None of the registers may alias: if they do, then the instruction is not
1796 // merely unpredictable but actually entirely unallocated.
1797 if (Rd
== Rm
|| Rm
== Rn
|| Rd
== Rn
)
1798 return MCDisassembler::Fail
;
1800 // Rd and Rn (not Rm) register operands are written back, so they appear
1801 // twice in the operand list, once as outputs and once as inputs.
1802 if (!DecodeSimpleRegisterClass
<AArch64::GPR64commonRegClassID
, 0, 31>(
1803 Inst
, Rd
, Addr
, Decoder
) ||
1804 !DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(
1805 Inst
, Rn
, Addr
, Decoder
) ||
1806 !DecodeSimpleRegisterClass
<AArch64::GPR64commonRegClassID
, 0, 31>(
1807 Inst
, Rd
, Addr
, Decoder
) ||
1808 !DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(
1809 Inst
, Rn
, Addr
, Decoder
) ||
1810 !DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(
1811 Inst
, Rm
, Addr
, Decoder
))
1812 return MCDisassembler::Fail
;
1814 return MCDisassembler::Success
;
1817 static DecodeStatus
DecodePRFMRegInstruction(MCInst
&Inst
, uint32_t insn
,
1819 const MCDisassembler
*Decoder
) {
1820 // PRFM with Rt = '11xxx' should be decoded as RPRFM.
1821 // Fail to decode and defer to fallback decoder table to decode RPRFM.
1822 unsigned Mask
= 0x18;
1823 uint64_t Rt
= fieldFromInstruction(insn
, 0, 5);
1824 if ((Rt
& Mask
) == Mask
)
1827 uint64_t Rn
= fieldFromInstruction(insn
, 5, 5);
1828 uint64_t Shift
= fieldFromInstruction(insn
, 12, 1);
1829 uint64_t Extend
= fieldFromInstruction(insn
, 15, 1);
1830 uint64_t Rm
= fieldFromInstruction(insn
, 16, 5);
1832 Inst
.addOperand(MCOperand::createImm(Rt
));
1833 DecodeSimpleRegisterClass
<AArch64::GPR64spRegClassID
, 0, 32>(Inst
, Rn
, Addr
,
1836 switch (Inst
.getOpcode()) {
1839 case AArch64::PRFMroW
:
1840 DecodeSimpleRegisterClass
<AArch64::GPR32RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1843 case AArch64::PRFMroX
:
1844 DecodeSimpleRegisterClass
<AArch64::GPR64RegClassID
, 0, 32>(Inst
, Rm
, Addr
,
1849 DecodeMemExtend(Inst
, (Extend
<< 1) | Shift
, Addr
, Decoder
);