1 //===-- ARM64InstPrinter.cpp - Convert ARM64 MCInst to assembly syntax ----===//
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 // This class prints an ARM64 MCInst to a .s file.
12 //===----------------------------------------------------------------------===//
14 #include "ARM64InstPrinter.h"
15 #include "MCTargetDesc/ARM64AddressingModes.h"
16 #include "Utils/ARM64BaseInfo.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/MC/MCExpr.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/Support/Format.h"
23 #include "llvm/Support/raw_ostream.h"
26 #define DEBUG_TYPE "asm-printer"
28 #define GET_INSTRUCTION_NAME
29 #define PRINT_ALIAS_INSTR
30 #include "ARM64GenAsmWriter.inc"
31 #define GET_INSTRUCTION_NAME
32 #define PRINT_ALIAS_INSTR
33 #include "ARM64GenAsmWriter1.inc"
35 ARM64InstPrinter::ARM64InstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
36 const MCRegisterInfo &MRI,
37 const MCSubtargetInfo &STI)
38 : MCInstPrinter(MAI, MII, MRI) {
39 // Initialize the set of available features.
40 setAvailableFeatures(STI.getFeatureBits());
43 ARM64AppleInstPrinter::ARM64AppleInstPrinter(const MCAsmInfo &MAI,
44 const MCInstrInfo &MII,
45 const MCRegisterInfo &MRI,
46 const MCSubtargetInfo &STI)
47 : ARM64InstPrinter(MAI, MII, MRI, STI) {}
49 void ARM64InstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const {
50 // This is for .cfi directives.
51 OS << getRegisterName(RegNo);
54 void ARM64InstPrinter::printInst(const MCInst *MI, raw_ostream &O,
56 // Check for special encodings and print the canonical alias instead.
58 unsigned Opcode = MI->getOpcode();
60 if (Opcode == ARM64::SYSxt)
61 if (printSysAlias(MI, O)) {
62 printAnnotation(O, Annot);
66 // TBZ/TBNZ should print the register operand as a Wreg if the bit
68 if ((Opcode == ARM64::TBNZ || Opcode == ARM64::TBZ) &&
69 MI->getOperand(1).getImm() < 32) {
71 unsigned Reg = MI->getOperand(0).getReg();
72 newMI.getOperand(0).setReg(getWRegFromXReg(Reg));
73 printInstruction(&newMI, O);
74 printAnnotation(O, Annot);
78 // SBFM/UBFM should print to a nicer aliased form if possible.
79 if (Opcode == ARM64::SBFMXri || Opcode == ARM64::SBFMWri ||
80 Opcode == ARM64::UBFMXri || Opcode == ARM64::UBFMWri) {
81 const MCOperand &Op0 = MI->getOperand(0);
82 const MCOperand &Op1 = MI->getOperand(1);
83 const MCOperand &Op2 = MI->getOperand(2);
84 const MCOperand &Op3 = MI->getOperand(3);
86 bool IsSigned = (Opcode == ARM64::SBFMXri || Opcode == ARM64::SBFMWri);
87 bool Is64Bit = (Opcode == ARM64::SBFMXri || Opcode == ARM64::UBFMXri);
88 if (Op2.isImm() && Op2.getImm() == 0 && Op3.isImm()) {
89 const char *AsmMnemonic = nullptr;
91 switch (Op3.getImm()) {
102 AsmMnemonic = "sxth";
104 AsmMnemonic = "uxth";
107 // *xtw is only valid for signed 64-bit operations.
108 if (Is64Bit && IsSigned)
109 AsmMnemonic = "sxtw";
114 O << '\t' << AsmMnemonic << '\t' << getRegisterName(Op0.getReg())
115 << ", " << getRegisterName(getWRegFromXReg(Op1.getReg()));
116 printAnnotation(O, Annot);
121 // All immediate shifts are aliases, implemented using the Bitfield
122 // instruction. In all cases the immediate shift amount shift must be in
123 // the range 0 to (reg.size -1).
124 if (Op2.isImm() && Op3.isImm()) {
125 const char *AsmMnemonic = nullptr;
127 int64_t immr = Op2.getImm();
128 int64_t imms = Op3.getImm();
129 if (Opcode == ARM64::UBFMWri && imms != 0x1F && ((imms + 1) == immr)) {
132 } else if (Opcode == ARM64::UBFMXri && imms != 0x3f &&
133 ((imms + 1 == immr))) {
136 } else if (Opcode == ARM64::UBFMWri && imms == 0x1f) {
139 } else if (Opcode == ARM64::UBFMXri && imms == 0x3f) {
142 } else if (Opcode == ARM64::SBFMWri && imms == 0x1f) {
145 } else if (Opcode == ARM64::SBFMXri && imms == 0x3f) {
150 O << '\t' << AsmMnemonic << '\t' << getRegisterName(Op0.getReg())
151 << ", " << getRegisterName(Op1.getReg()) << ", #" << shift;
152 printAnnotation(O, Annot);
157 // SBFIZ/UBFIZ aliases
158 if (Op2.getImm() > Op3.getImm()) {
159 O << '\t' << (IsSigned ? "sbfiz" : "ubfiz") << '\t'
160 << getRegisterName(Op0.getReg()) << ", " << getRegisterName(Op1.getReg())
161 << ", #" << (Is64Bit ? 64 : 32) - Op2.getImm() << ", #" << Op3.getImm() + 1;
162 printAnnotation(O, Annot);
166 // Otherwise SBFX/UBFX is the prefered form
167 O << '\t' << (IsSigned ? "sbfx" : "ubfx") << '\t'
168 << getRegisterName(Op0.getReg()) << ", " << getRegisterName(Op1.getReg())
169 << ", #" << Op2.getImm() << ", #" << Op3.getImm() - Op2.getImm() + 1;
170 printAnnotation(O, Annot);
174 // Symbolic operands for MOVZ, MOVN and MOVK already imply a shift
175 // (e.g. :gottprel_g1: is always going to be "lsl #16") so it should not be
177 if ((Opcode == ARM64::MOVZXi || Opcode == ARM64::MOVZWi ||
178 Opcode == ARM64::MOVNXi || Opcode == ARM64::MOVNWi) &&
179 MI->getOperand(1).isExpr()) {
180 if (Opcode == ARM64::MOVZXi || Opcode == ARM64::MOVZWi)
185 O << getRegisterName(MI->getOperand(0).getReg()) << ", #"
186 << *MI->getOperand(1).getExpr();
190 if ((Opcode == ARM64::MOVKXi || Opcode == ARM64::MOVKWi) &&
191 MI->getOperand(2).isExpr()) {
192 O << "\tmovk\t" << getRegisterName(MI->getOperand(0).getReg()) << ", #"
193 << *MI->getOperand(2).getExpr();
197 // ANDS WZR, Wn, #imm ==> TST Wn, #imm
198 // ANDS XZR, Xn, #imm ==> TST Xn, #imm
199 if (Opcode == ARM64::ANDSWri && MI->getOperand(0).getReg() == ARM64::WZR) {
200 O << "\ttst\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
201 printLogicalImm32(MI, 2, O);
204 if (Opcode == ARM64::ANDSXri && MI->getOperand(0).getReg() == ARM64::XZR) {
205 O << "\ttst\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
206 printLogicalImm64(MI, 2, O);
209 // ANDS WZR, Wn, Wm{, lshift #imm} ==> TST Wn{, lshift #imm}
210 // ANDS XZR, Xn, Xm{, lshift #imm} ==> TST Xn{, lshift #imm}
211 if ((Opcode == ARM64::ANDSWrs && MI->getOperand(0).getReg() == ARM64::WZR) ||
212 (Opcode == ARM64::ANDSXrs && MI->getOperand(0).getReg() == ARM64::XZR)) {
213 O << "\ttst\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
214 printShiftedRegister(MI, 2, O);
218 // ORN Wn, WZR, Wm{, lshift #imm} ==> MVN Wn, Wm{, lshift #imm}
219 // ORN Xn, XZR, Xm{, lshift #imm} ==> MVN Xn, Xm{, lshift #imm}
220 if ((Opcode == ARM64::ORNWrs && MI->getOperand(1).getReg() == ARM64::WZR) ||
221 (Opcode == ARM64::ORNXrs && MI->getOperand(1).getReg() == ARM64::XZR)) {
222 O << "\tmvn\t" << getRegisterName(MI->getOperand(0).getReg()) << ", ";
223 printShiftedRegister(MI, 2, O);
226 // SUBS WZR, Wn, #imm ==> CMP Wn, #imm
227 // SUBS XZR, Xn, #imm ==> CMP Xn, #imm
228 if ((Opcode == ARM64::SUBSWri && MI->getOperand(0).getReg() == ARM64::WZR) ||
229 (Opcode == ARM64::SUBSXri && MI->getOperand(0).getReg() == ARM64::XZR)) {
230 O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
231 printAddSubImm(MI, 2, O);
234 // SUBS WZR, Wn, Wm{, lshift #imm} ==> CMP Wn, Wm{, lshift #imm}
235 // SUBS XZR, Xn, Xm{, lshift #imm} ==> CMP Xn, Xm{, lshift #imm}
236 if ((Opcode == ARM64::SUBSWrs && MI->getOperand(0).getReg() == ARM64::WZR) ||
237 (Opcode == ARM64::SUBSXrs && MI->getOperand(0).getReg() == ARM64::XZR)) {
238 O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
239 printShiftedRegister(MI, 2, O);
242 // SUBS XZR, Xn, Wm, uxtb #imm ==> CMP Xn, uxtb #imm
243 // SUBS WZR, Wn, Xm, uxtb #imm ==> CMP Wn, uxtb #imm
244 if ((Opcode == ARM64::SUBSXrx && MI->getOperand(0).getReg() == ARM64::XZR) ||
245 (Opcode == ARM64::SUBSWrx && MI->getOperand(0).getReg() == ARM64::WZR)) {
246 O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
247 printExtendedRegister(MI, 2, O);
250 // SUBS XZR, Xn, Xm, uxtx #imm ==> CMP Xn, uxtb #imm
251 if (Opcode == ARM64::SUBSXrx64 && MI->getOperand(0).getReg() == ARM64::XZR) {
252 O << "\tcmp\t" << getRegisterName(MI->getOperand(1).getReg()) << ", "
253 << getRegisterName(MI->getOperand(2).getReg());
254 printExtend(MI, 3, O);
258 // ADDS WZR, Wn, #imm ==> CMN Wn, #imm
259 // ADDS XZR, Xn, #imm ==> CMN Xn, #imm
260 if ((Opcode == ARM64::ADDSWri && MI->getOperand(0).getReg() == ARM64::WZR) ||
261 (Opcode == ARM64::ADDSXri && MI->getOperand(0).getReg() == ARM64::XZR)) {
262 O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
263 printAddSubImm(MI, 2, O);
266 // ADDS WZR, Wn, Wm{, lshift #imm} ==> CMN Wn, Wm{, lshift #imm}
267 // ADDS XZR, Xn, Xm{, lshift #imm} ==> CMN Xn, Xm{, lshift #imm}
268 if ((Opcode == ARM64::ADDSWrs && MI->getOperand(0).getReg() == ARM64::WZR) ||
269 (Opcode == ARM64::ADDSXrs && MI->getOperand(0).getReg() == ARM64::XZR)) {
270 O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
271 printShiftedRegister(MI, 2, O);
274 // ADDS XZR, Xn, Wm, uxtb #imm ==> CMN Xn, uxtb #imm
275 if (Opcode == ARM64::ADDSXrx && MI->getOperand(0).getReg() == ARM64::XZR) {
276 O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", ";
277 printExtendedRegister(MI, 2, O);
280 // ADDS XZR, Xn, Xm, uxtx #imm ==> CMN Xn, uxtb #imm
281 if (Opcode == ARM64::ADDSXrx64 && MI->getOperand(0).getReg() == ARM64::XZR) {
282 O << "\tcmn\t" << getRegisterName(MI->getOperand(1).getReg()) << ", "
283 << getRegisterName(MI->getOperand(2).getReg());
284 printExtend(MI, 3, O);
287 // ADD WSP, Wn, #0 ==> MOV WSP, Wn
288 if (Opcode == ARM64::ADDWri && (MI->getOperand(0).getReg() == ARM64::WSP ||
289 MI->getOperand(1).getReg() == ARM64::WSP) &&
290 MI->getOperand(2).getImm() == 0 &&
291 ARM64_AM::getShiftValue(MI->getOperand(3).getImm()) == 0) {
292 O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
293 << ", " << getRegisterName(MI->getOperand(1).getReg());
296 // ADD XSP, Wn, #0 ==> MOV XSP, Wn
297 if (Opcode == ARM64::ADDXri && (MI->getOperand(0).getReg() == ARM64::SP ||
298 MI->getOperand(1).getReg() == ARM64::SP) &&
299 MI->getOperand(2).getImm() == 0 &&
300 ARM64_AM::getShiftValue(MI->getOperand(3).getImm()) == 0) {
301 O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
302 << ", " << getRegisterName(MI->getOperand(1).getReg());
305 // ORR Wn, WZR, Wm ==> MOV Wn, Wm
306 if (Opcode == ARM64::ORRWrs && MI->getOperand(1).getReg() == ARM64::WZR &&
307 MI->getOperand(3).getImm() == 0) {
308 O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
309 << ", " << getRegisterName(MI->getOperand(2).getReg());
312 // ORR Xn, XZR, Xm ==> MOV Xn, Xm
313 if (Opcode == ARM64::ORRXrs && MI->getOperand(1).getReg() == ARM64::XZR &&
314 MI->getOperand(3).getImm() == 0) {
315 O << "\tmov\t" << getRegisterName(MI->getOperand(0).getReg())
316 << ", " << getRegisterName(MI->getOperand(2).getReg());
320 if (!printAliasInstr(MI, O))
321 printInstruction(MI, O);
323 printAnnotation(O, Annot);
326 static bool isTblTbxInstruction(unsigned Opcode, StringRef &Layout,
329 case ARM64::TBXv8i8One:
330 case ARM64::TBXv8i8Two:
331 case ARM64::TBXv8i8Three:
332 case ARM64::TBXv8i8Four:
336 case ARM64::TBLv8i8One:
337 case ARM64::TBLv8i8Two:
338 case ARM64::TBLv8i8Three:
339 case ARM64::TBLv8i8Four:
343 case ARM64::TBXv16i8One:
344 case ARM64::TBXv16i8Two:
345 case ARM64::TBXv16i8Three:
346 case ARM64::TBXv16i8Four:
350 case ARM64::TBLv16i8One:
351 case ARM64::TBLv16i8Two:
352 case ARM64::TBLv16i8Three:
353 case ARM64::TBLv16i8Four:
362 struct LdStNInstrDesc {
364 const char *Mnemonic;
370 static LdStNInstrDesc LdStNInstInfo[] = {
371 { ARM64::LD1i8, "ld1", ".b", 2, 0 },
372 { ARM64::LD1i16, "ld1", ".h", 2, 0 },
373 { ARM64::LD1i32, "ld1", ".s", 2, 0 },
374 { ARM64::LD1i64, "ld1", ".d", 2, 0 },
375 { ARM64::LD1i8_POST, "ld1", ".b", 2, 1 },
376 { ARM64::LD1i16_POST, "ld1", ".h", 2, 2 },
377 { ARM64::LD1i32_POST, "ld1", ".s", 2, 4 },
378 { ARM64::LD1i64_POST, "ld1", ".d", 2, 8 },
379 { ARM64::LD1Rv16b, "ld1r", ".16b", 0, 0 },
380 { ARM64::LD1Rv8h, "ld1r", ".8h", 0, 0 },
381 { ARM64::LD1Rv4s, "ld1r", ".4s", 0, 0 },
382 { ARM64::LD1Rv2d, "ld1r", ".2d", 0, 0 },
383 { ARM64::LD1Rv8b, "ld1r", ".8b", 0, 0 },
384 { ARM64::LD1Rv4h, "ld1r", ".4h", 0, 0 },
385 { ARM64::LD1Rv2s, "ld1r", ".2s", 0, 0 },
386 { ARM64::LD1Rv1d, "ld1r", ".1d", 0, 0 },
387 { ARM64::LD1Rv16b_POST, "ld1r", ".16b", 0, 1 },
388 { ARM64::LD1Rv8h_POST, "ld1r", ".8h", 0, 2 },
389 { ARM64::LD1Rv4s_POST, "ld1r", ".4s", 0, 4 },
390 { ARM64::LD1Rv2d_POST, "ld1r", ".2d", 0, 8 },
391 { ARM64::LD1Rv8b_POST, "ld1r", ".8b", 0, 1 },
392 { ARM64::LD1Rv4h_POST, "ld1r", ".4h", 0, 2 },
393 { ARM64::LD1Rv2s_POST, "ld1r", ".2s", 0, 4 },
394 { ARM64::LD1Rv1d_POST, "ld1r", ".1d", 0, 8 },
395 { ARM64::LD1Onev16b, "ld1", ".16b", 0, 0 },
396 { ARM64::LD1Onev8h, "ld1", ".8h", 0, 0 },
397 { ARM64::LD1Onev4s, "ld1", ".4s", 0, 0 },
398 { ARM64::LD1Onev2d, "ld1", ".2d", 0, 0 },
399 { ARM64::LD1Onev8b, "ld1", ".8b", 0, 0 },
400 { ARM64::LD1Onev4h, "ld1", ".4h", 0, 0 },
401 { ARM64::LD1Onev2s, "ld1", ".2s", 0, 0 },
402 { ARM64::LD1Onev1d, "ld1", ".1d", 0, 0 },
403 { ARM64::LD1Onev16b_POST, "ld1", ".16b", 0, 16 },
404 { ARM64::LD1Onev8h_POST, "ld1", ".8h", 0, 16 },
405 { ARM64::LD1Onev4s_POST, "ld1", ".4s", 0, 16 },
406 { ARM64::LD1Onev2d_POST, "ld1", ".2d", 0, 16 },
407 { ARM64::LD1Onev8b_POST, "ld1", ".8b", 0, 8 },
408 { ARM64::LD1Onev4h_POST, "ld1", ".4h", 0, 8 },
409 { ARM64::LD1Onev2s_POST, "ld1", ".2s", 0, 8 },
410 { ARM64::LD1Onev1d_POST, "ld1", ".1d", 0, 8 },
411 { ARM64::LD1Twov16b, "ld1", ".16b", 0, 0 },
412 { ARM64::LD1Twov8h, "ld1", ".8h", 0, 0 },
413 { ARM64::LD1Twov4s, "ld1", ".4s", 0, 0 },
414 { ARM64::LD1Twov2d, "ld1", ".2d", 0, 0 },
415 { ARM64::LD1Twov8b, "ld1", ".8b", 0, 0 },
416 { ARM64::LD1Twov4h, "ld1", ".4h", 0, 0 },
417 { ARM64::LD1Twov2s, "ld1", ".2s", 0, 0 },
418 { ARM64::LD1Twov1d, "ld1", ".1d", 0, 0 },
419 { ARM64::LD1Twov16b_POST, "ld1", ".16b", 0, 32 },
420 { ARM64::LD1Twov8h_POST, "ld1", ".8h", 0, 32 },
421 { ARM64::LD1Twov4s_POST, "ld1", ".4s", 0, 32 },
422 { ARM64::LD1Twov2d_POST, "ld1", ".2d", 0, 32 },
423 { ARM64::LD1Twov8b_POST, "ld1", ".8b", 0, 16 },
424 { ARM64::LD1Twov4h_POST, "ld1", ".4h", 0, 16 },
425 { ARM64::LD1Twov2s_POST, "ld1", ".2s", 0, 16 },
426 { ARM64::LD1Twov1d_POST, "ld1", ".1d", 0, 16 },
427 { ARM64::LD1Threev16b, "ld1", ".16b", 0, 0 },
428 { ARM64::LD1Threev8h, "ld1", ".8h", 0, 0 },
429 { ARM64::LD1Threev4s, "ld1", ".4s", 0, 0 },
430 { ARM64::LD1Threev2d, "ld1", ".2d", 0, 0 },
431 { ARM64::LD1Threev8b, "ld1", ".8b", 0, 0 },
432 { ARM64::LD1Threev4h, "ld1", ".4h", 0, 0 },
433 { ARM64::LD1Threev2s, "ld1", ".2s", 0, 0 },
434 { ARM64::LD1Threev1d, "ld1", ".1d", 0, 0 },
435 { ARM64::LD1Threev16b_POST, "ld1", ".16b", 0, 48 },
436 { ARM64::LD1Threev8h_POST, "ld1", ".8h", 0, 48 },
437 { ARM64::LD1Threev4s_POST, "ld1", ".4s", 0, 48 },
438 { ARM64::LD1Threev2d_POST, "ld1", ".2d", 0, 48 },
439 { ARM64::LD1Threev8b_POST, "ld1", ".8b", 0, 24 },
440 { ARM64::LD1Threev4h_POST, "ld1", ".4h", 0, 24 },
441 { ARM64::LD1Threev2s_POST, "ld1", ".2s", 0, 24 },
442 { ARM64::LD1Threev1d_POST, "ld1", ".1d", 0, 24 },
443 { ARM64::LD1Fourv16b, "ld1", ".16b", 0, 0 },
444 { ARM64::LD1Fourv8h, "ld1", ".8h", 0, 0 },
445 { ARM64::LD1Fourv4s, "ld1", ".4s", 0, 0 },
446 { ARM64::LD1Fourv2d, "ld1", ".2d", 0, 0 },
447 { ARM64::LD1Fourv8b, "ld1", ".8b", 0, 0 },
448 { ARM64::LD1Fourv4h, "ld1", ".4h", 0, 0 },
449 { ARM64::LD1Fourv2s, "ld1", ".2s", 0, 0 },
450 { ARM64::LD1Fourv1d, "ld1", ".1d", 0, 0 },
451 { ARM64::LD1Fourv16b_POST, "ld1", ".16b", 0, 64 },
452 { ARM64::LD1Fourv8h_POST, "ld1", ".8h", 0, 64 },
453 { ARM64::LD1Fourv4s_POST, "ld1", ".4s", 0, 64 },
454 { ARM64::LD1Fourv2d_POST, "ld1", ".2d", 0, 64 },
455 { ARM64::LD1Fourv8b_POST, "ld1", ".8b", 0, 32 },
456 { ARM64::LD1Fourv4h_POST, "ld1", ".4h", 0, 32 },
457 { ARM64::LD1Fourv2s_POST, "ld1", ".2s", 0, 32 },
458 { ARM64::LD1Fourv1d_POST, "ld1", ".1d", 0, 32 },
459 { ARM64::LD2i8, "ld2", ".b", 2, 0 },
460 { ARM64::LD2i16, "ld2", ".h", 2, 0 },
461 { ARM64::LD2i32, "ld2", ".s", 2, 0 },
462 { ARM64::LD2i64, "ld2", ".d", 2, 0 },
463 { ARM64::LD2i8_POST, "ld2", ".b", 2, 2 },
464 { ARM64::LD2i16_POST, "ld2", ".h", 2, 4 },
465 { ARM64::LD2i32_POST, "ld2", ".s", 2, 8 },
466 { ARM64::LD2i64_POST, "ld2", ".d", 2, 16 },
467 { ARM64::LD2Rv16b, "ld2r", ".16b", 0, 0 },
468 { ARM64::LD2Rv8h, "ld2r", ".8h", 0, 0 },
469 { ARM64::LD2Rv4s, "ld2r", ".4s", 0, 0 },
470 { ARM64::LD2Rv2d, "ld2r", ".2d", 0, 0 },
471 { ARM64::LD2Rv8b, "ld2r", ".8b", 0, 0 },
472 { ARM64::LD2Rv4h, "ld2r", ".4h", 0, 0 },
473 { ARM64::LD2Rv2s, "ld2r", ".2s", 0, 0 },
474 { ARM64::LD2Rv1d, "ld2r", ".1d", 0, 0 },
475 { ARM64::LD2Rv16b_POST, "ld2r", ".16b", 0, 2 },
476 { ARM64::LD2Rv8h_POST, "ld2r", ".8h", 0, 4 },
477 { ARM64::LD2Rv4s_POST, "ld2r", ".4s", 0, 8 },
478 { ARM64::LD2Rv2d_POST, "ld2r", ".2d", 0, 16 },
479 { ARM64::LD2Rv8b_POST, "ld2r", ".8b", 0, 2 },
480 { ARM64::LD2Rv4h_POST, "ld2r", ".4h", 0, 4 },
481 { ARM64::LD2Rv2s_POST, "ld2r", ".2s", 0, 8 },
482 { ARM64::LD2Rv1d_POST, "ld2r", ".1d", 0, 16 },
483 { ARM64::LD2Twov16b, "ld2", ".16b", 0, 0 },
484 { ARM64::LD2Twov8h, "ld2", ".8h", 0, 0 },
485 { ARM64::LD2Twov4s, "ld2", ".4s", 0, 0 },
486 { ARM64::LD2Twov2d, "ld2", ".2d", 0, 0 },
487 { ARM64::LD2Twov8b, "ld2", ".8b", 0, 0 },
488 { ARM64::LD2Twov4h, "ld2", ".4h", 0, 0 },
489 { ARM64::LD2Twov2s, "ld2", ".2s", 0, 0 },
490 { ARM64::LD2Twov16b_POST, "ld2", ".16b", 0, 32 },
491 { ARM64::LD2Twov8h_POST, "ld2", ".8h", 0, 32 },
492 { ARM64::LD2Twov4s_POST, "ld2", ".4s", 0, 32 },
493 { ARM64::LD2Twov2d_POST, "ld2", ".2d", 0, 32 },
494 { ARM64::LD2Twov8b_POST, "ld2", ".8b", 0, 16 },
495 { ARM64::LD2Twov4h_POST, "ld2", ".4h", 0, 16 },
496 { ARM64::LD2Twov2s_POST, "ld2", ".2s", 0, 16 },
497 { ARM64::LD3i8, "ld3", ".b", 2, 0 },
498 { ARM64::LD3i16, "ld3", ".h", 2, 0 },
499 { ARM64::LD3i32, "ld3", ".s", 2, 0 },
500 { ARM64::LD3i64, "ld3", ".d", 2, 0 },
501 { ARM64::LD3i8_POST, "ld3", ".b", 2, 3 },
502 { ARM64::LD3i16_POST, "ld3", ".h", 2, 6 },
503 { ARM64::LD3i32_POST, "ld3", ".s", 2, 12 },
504 { ARM64::LD3i64_POST, "ld3", ".d", 2, 24 },
505 { ARM64::LD3Rv16b, "ld3r", ".16b", 0, 0 },
506 { ARM64::LD3Rv8h, "ld3r", ".8h", 0, 0 },
507 { ARM64::LD3Rv4s, "ld3r", ".4s", 0, 0 },
508 { ARM64::LD3Rv2d, "ld3r", ".2d", 0, 0 },
509 { ARM64::LD3Rv8b, "ld3r", ".8b", 0, 0 },
510 { ARM64::LD3Rv4h, "ld3r", ".4h", 0, 0 },
511 { ARM64::LD3Rv2s, "ld3r", ".2s", 0, 0 },
512 { ARM64::LD3Rv1d, "ld3r", ".1d", 0, 0 },
513 { ARM64::LD3Rv16b_POST, "ld3r", ".16b", 0, 3 },
514 { ARM64::LD3Rv8h_POST, "ld3r", ".8h", 0, 6 },
515 { ARM64::LD3Rv4s_POST, "ld3r", ".4s", 0, 12 },
516 { ARM64::LD3Rv2d_POST, "ld3r", ".2d", 0, 24 },
517 { ARM64::LD3Rv8b_POST, "ld3r", ".8b", 0, 3 },
518 { ARM64::LD3Rv4h_POST, "ld3r", ".4h", 0, 6 },
519 { ARM64::LD3Rv2s_POST, "ld3r", ".2s", 0, 12 },
520 { ARM64::LD3Rv1d_POST, "ld3r", ".1d", 0, 24 },
521 { ARM64::LD3Threev16b, "ld3", ".16b", 0, 0 },
522 { ARM64::LD3Threev8h, "ld3", ".8h", 0, 0 },
523 { ARM64::LD3Threev4s, "ld3", ".4s", 0, 0 },
524 { ARM64::LD3Threev2d, "ld3", ".2d", 0, 0 },
525 { ARM64::LD3Threev8b, "ld3", ".8b", 0, 0 },
526 { ARM64::LD3Threev4h, "ld3", ".4h", 0, 0 },
527 { ARM64::LD3Threev2s, "ld3", ".2s", 0, 0 },
528 { ARM64::LD3Threev16b_POST, "ld3", ".16b", 0, 48 },
529 { ARM64::LD3Threev8h_POST, "ld3", ".8h", 0, 48 },
530 { ARM64::LD3Threev4s_POST, "ld3", ".4s", 0, 48 },
531 { ARM64::LD3Threev2d_POST, "ld3", ".2d", 0, 48 },
532 { ARM64::LD3Threev8b_POST, "ld3", ".8b", 0, 24 },
533 { ARM64::LD3Threev4h_POST, "ld3", ".4h", 0, 24 },
534 { ARM64::LD3Threev2s_POST, "ld3", ".2s", 0, 24 },
535 { ARM64::LD4i8, "ld4", ".b", 2, 0 },
536 { ARM64::LD4i16, "ld4", ".h", 2, 0 },
537 { ARM64::LD4i32, "ld4", ".s", 2, 0 },
538 { ARM64::LD4i64, "ld4", ".d", 2, 0 },
539 { ARM64::LD4i8_POST, "ld4", ".b", 2, 4 },
540 { ARM64::LD4i16_POST, "ld4", ".h", 2, 8 },
541 { ARM64::LD4i32_POST, "ld4", ".s", 2, 16 },
542 { ARM64::LD4i64_POST, "ld4", ".d", 2, 32 },
543 { ARM64::LD4Rv16b, "ld4r", ".16b", 0, 0 },
544 { ARM64::LD4Rv8h, "ld4r", ".8h", 0, 0 },
545 { ARM64::LD4Rv4s, "ld4r", ".4s", 0, 0 },
546 { ARM64::LD4Rv2d, "ld4r", ".2d", 0, 0 },
547 { ARM64::LD4Rv8b, "ld4r", ".8b", 0, 0 },
548 { ARM64::LD4Rv4h, "ld4r", ".4h", 0, 0 },
549 { ARM64::LD4Rv2s, "ld4r", ".2s", 0, 0 },
550 { ARM64::LD4Rv1d, "ld4r", ".1d", 0, 0 },
551 { ARM64::LD4Rv16b_POST, "ld4r", ".16b", 0, 4 },
552 { ARM64::LD4Rv8h_POST, "ld4r", ".8h", 0, 8 },
553 { ARM64::LD4Rv4s_POST, "ld4r", ".4s", 0, 16 },
554 { ARM64::LD4Rv2d_POST, "ld4r", ".2d", 0, 32 },
555 { ARM64::LD4Rv8b_POST, "ld4r", ".8b", 0, 4 },
556 { ARM64::LD4Rv4h_POST, "ld4r", ".4h", 0, 8 },
557 { ARM64::LD4Rv2s_POST, "ld4r", ".2s", 0, 16 },
558 { ARM64::LD4Rv1d_POST, "ld4r", ".1d", 0, 32 },
559 { ARM64::LD4Fourv16b, "ld4", ".16b", 0, 0 },
560 { ARM64::LD4Fourv8h, "ld4", ".8h", 0, 0 },
561 { ARM64::LD4Fourv4s, "ld4", ".4s", 0, 0 },
562 { ARM64::LD4Fourv2d, "ld4", ".2d", 0, 0 },
563 { ARM64::LD4Fourv8b, "ld4", ".8b", 0, 0 },
564 { ARM64::LD4Fourv4h, "ld4", ".4h", 0, 0 },
565 { ARM64::LD4Fourv2s, "ld4", ".2s", 0, 0 },
566 { ARM64::LD4Fourv16b_POST, "ld4", ".16b", 0, 64 },
567 { ARM64::LD4Fourv8h_POST, "ld4", ".8h", 0, 64 },
568 { ARM64::LD4Fourv4s_POST, "ld4", ".4s", 0, 64 },
569 { ARM64::LD4Fourv2d_POST, "ld4", ".2d", 0, 64 },
570 { ARM64::LD4Fourv8b_POST, "ld4", ".8b", 0, 32 },
571 { ARM64::LD4Fourv4h_POST, "ld4", ".4h", 0, 32 },
572 { ARM64::LD4Fourv2s_POST, "ld4", ".2s", 0, 32 },
573 { ARM64::ST1i8, "st1", ".b", 1, 0 },
574 { ARM64::ST1i16, "st1", ".h", 1, 0 },
575 { ARM64::ST1i32, "st1", ".s", 1, 0 },
576 { ARM64::ST1i64, "st1", ".d", 1, 0 },
577 { ARM64::ST1i8_POST, "st1", ".b", 1, 1 },
578 { ARM64::ST1i16_POST, "st1", ".h", 1, 2 },
579 { ARM64::ST1i32_POST, "st1", ".s", 1, 4 },
580 { ARM64::ST1i64_POST, "st1", ".d", 1, 8 },
581 { ARM64::ST1Onev16b, "st1", ".16b", 0, 0 },
582 { ARM64::ST1Onev8h, "st1", ".8h", 0, 0 },
583 { ARM64::ST1Onev4s, "st1", ".4s", 0, 0 },
584 { ARM64::ST1Onev2d, "st1", ".2d", 0, 0 },
585 { ARM64::ST1Onev8b, "st1", ".8b", 0, 0 },
586 { ARM64::ST1Onev4h, "st1", ".4h", 0, 0 },
587 { ARM64::ST1Onev2s, "st1", ".2s", 0, 0 },
588 { ARM64::ST1Onev1d, "st1", ".1d", 0, 0 },
589 { ARM64::ST1Onev16b_POST, "st1", ".16b", 0, 16 },
590 { ARM64::ST1Onev8h_POST, "st1", ".8h", 0, 16 },
591 { ARM64::ST1Onev4s_POST, "st1", ".4s", 0, 16 },
592 { ARM64::ST1Onev2d_POST, "st1", ".2d", 0, 16 },
593 { ARM64::ST1Onev8b_POST, "st1", ".8b", 0, 8 },
594 { ARM64::ST1Onev4h_POST, "st1", ".4h", 0, 8 },
595 { ARM64::ST1Onev2s_POST, "st1", ".2s", 0, 8 },
596 { ARM64::ST1Onev1d_POST, "st1", ".1d", 0, 8 },
597 { ARM64::ST1Twov16b, "st1", ".16b", 0, 0 },
598 { ARM64::ST1Twov8h, "st1", ".8h", 0, 0 },
599 { ARM64::ST1Twov4s, "st1", ".4s", 0, 0 },
600 { ARM64::ST1Twov2d, "st1", ".2d", 0, 0 },
601 { ARM64::ST1Twov8b, "st1", ".8b", 0, 0 },
602 { ARM64::ST1Twov4h, "st1", ".4h", 0, 0 },
603 { ARM64::ST1Twov2s, "st1", ".2s", 0, 0 },
604 { ARM64::ST1Twov1d, "st1", ".1d", 0, 0 },
605 { ARM64::ST1Twov16b_POST, "st1", ".16b", 0, 32 },
606 { ARM64::ST1Twov8h_POST, "st1", ".8h", 0, 32 },
607 { ARM64::ST1Twov4s_POST, "st1", ".4s", 0, 32 },
608 { ARM64::ST1Twov2d_POST, "st1", ".2d", 0, 32 },
609 { ARM64::ST1Twov8b_POST, "st1", ".8b", 0, 16 },
610 { ARM64::ST1Twov4h_POST, "st1", ".4h", 0, 16 },
611 { ARM64::ST1Twov2s_POST, "st1", ".2s", 0, 16 },
612 { ARM64::ST1Twov1d_POST, "st1", ".1d", 0, 16 },
613 { ARM64::ST1Threev16b, "st1", ".16b", 0, 0 },
614 { ARM64::ST1Threev8h, "st1", ".8h", 0, 0 },
615 { ARM64::ST1Threev4s, "st1", ".4s", 0, 0 },
616 { ARM64::ST1Threev2d, "st1", ".2d", 0, 0 },
617 { ARM64::ST1Threev8b, "st1", ".8b", 0, 0 },
618 { ARM64::ST1Threev4h, "st1", ".4h", 0, 0 },
619 { ARM64::ST1Threev2s, "st1", ".2s", 0, 0 },
620 { ARM64::ST1Threev1d, "st1", ".1d", 0, 0 },
621 { ARM64::ST1Threev16b_POST, "st1", ".16b", 0, 48 },
622 { ARM64::ST1Threev8h_POST, "st1", ".8h", 0, 48 },
623 { ARM64::ST1Threev4s_POST, "st1", ".4s", 0, 48 },
624 { ARM64::ST1Threev2d_POST, "st1", ".2d", 0, 48 },
625 { ARM64::ST1Threev8b_POST, "st1", ".8b", 0, 24 },
626 { ARM64::ST1Threev4h_POST, "st1", ".4h", 0, 24 },
627 { ARM64::ST1Threev2s_POST, "st1", ".2s", 0, 24 },
628 { ARM64::ST1Threev1d_POST, "st1", ".1d", 0, 24 },
629 { ARM64::ST1Fourv16b, "st1", ".16b", 0, 0 },
630 { ARM64::ST1Fourv8h, "st1", ".8h", 0, 0 },
631 { ARM64::ST1Fourv4s, "st1", ".4s", 0, 0 },
632 { ARM64::ST1Fourv2d, "st1", ".2d", 0, 0 },
633 { ARM64::ST1Fourv8b, "st1", ".8b", 0, 0 },
634 { ARM64::ST1Fourv4h, "st1", ".4h", 0, 0 },
635 { ARM64::ST1Fourv2s, "st1", ".2s", 0, 0 },
636 { ARM64::ST1Fourv1d, "st1", ".1d", 0, 0 },
637 { ARM64::ST1Fourv16b_POST, "st1", ".16b", 0, 64 },
638 { ARM64::ST1Fourv8h_POST, "st1", ".8h", 0, 64 },
639 { ARM64::ST1Fourv4s_POST, "st1", ".4s", 0, 64 },
640 { ARM64::ST1Fourv2d_POST, "st1", ".2d", 0, 64 },
641 { ARM64::ST1Fourv8b_POST, "st1", ".8b", 0, 32 },
642 { ARM64::ST1Fourv4h_POST, "st1", ".4h", 0, 32 },
643 { ARM64::ST1Fourv2s_POST, "st1", ".2s", 0, 32 },
644 { ARM64::ST1Fourv1d_POST, "st1", ".1d", 0, 32 },
645 { ARM64::ST2i8, "st2", ".b", 1, 0 },
646 { ARM64::ST2i16, "st2", ".h", 1, 0 },
647 { ARM64::ST2i32, "st2", ".s", 1, 0 },
648 { ARM64::ST2i64, "st2", ".d", 1, 0 },
649 { ARM64::ST2i8_POST, "st2", ".b", 1, 2 },
650 { ARM64::ST2i16_POST, "st2", ".h", 1, 4 },
651 { ARM64::ST2i32_POST, "st2", ".s", 1, 8 },
652 { ARM64::ST2i64_POST, "st2", ".d", 1, 16 },
653 { ARM64::ST2Twov16b, "st2", ".16b", 0, 0 },
654 { ARM64::ST2Twov8h, "st2", ".8h", 0, 0 },
655 { ARM64::ST2Twov4s, "st2", ".4s", 0, 0 },
656 { ARM64::ST2Twov2d, "st2", ".2d", 0, 0 },
657 { ARM64::ST2Twov8b, "st2", ".8b", 0, 0 },
658 { ARM64::ST2Twov4h, "st2", ".4h", 0, 0 },
659 { ARM64::ST2Twov2s, "st2", ".2s", 0, 0 },
660 { ARM64::ST2Twov16b_POST, "st2", ".16b", 0, 32 },
661 { ARM64::ST2Twov8h_POST, "st2", ".8h", 0, 32 },
662 { ARM64::ST2Twov4s_POST, "st2", ".4s", 0, 32 },
663 { ARM64::ST2Twov2d_POST, "st2", ".2d", 0, 32 },
664 { ARM64::ST2Twov8b_POST, "st2", ".8b", 0, 16 },
665 { ARM64::ST2Twov4h_POST, "st2", ".4h", 0, 16 },
666 { ARM64::ST2Twov2s_POST, "st2", ".2s", 0, 16 },
667 { ARM64::ST3i8, "st3", ".b", 1, 0 },
668 { ARM64::ST3i16, "st3", ".h", 1, 0 },
669 { ARM64::ST3i32, "st3", ".s", 1, 0 },
670 { ARM64::ST3i64, "st3", ".d", 1, 0 },
671 { ARM64::ST3i8_POST, "st3", ".b", 1, 3 },
672 { ARM64::ST3i16_POST, "st3", ".h", 1, 6 },
673 { ARM64::ST3i32_POST, "st3", ".s", 1, 12 },
674 { ARM64::ST3i64_POST, "st3", ".d", 1, 24 },
675 { ARM64::ST3Threev16b, "st3", ".16b", 0, 0 },
676 { ARM64::ST3Threev8h, "st3", ".8h", 0, 0 },
677 { ARM64::ST3Threev4s, "st3", ".4s", 0, 0 },
678 { ARM64::ST3Threev2d, "st3", ".2d", 0, 0 },
679 { ARM64::ST3Threev8b, "st3", ".8b", 0, 0 },
680 { ARM64::ST3Threev4h, "st3", ".4h", 0, 0 },
681 { ARM64::ST3Threev2s, "st3", ".2s", 0, 0 },
682 { ARM64::ST3Threev16b_POST, "st3", ".16b", 0, 48 },
683 { ARM64::ST3Threev8h_POST, "st3", ".8h", 0, 48 },
684 { ARM64::ST3Threev4s_POST, "st3", ".4s", 0, 48 },
685 { ARM64::ST3Threev2d_POST, "st3", ".2d", 0, 48 },
686 { ARM64::ST3Threev8b_POST, "st3", ".8b", 0, 24 },
687 { ARM64::ST3Threev4h_POST, "st3", ".4h", 0, 24 },
688 { ARM64::ST3Threev2s_POST, "st3", ".2s", 0, 24 },
689 { ARM64::ST4i8, "st4", ".b", 1, 0 },
690 { ARM64::ST4i16, "st4", ".h", 1, 0 },
691 { ARM64::ST4i32, "st4", ".s", 1, 0 },
692 { ARM64::ST4i64, "st4", ".d", 1, 0 },
693 { ARM64::ST4i8_POST, "st4", ".b", 1, 4 },
694 { ARM64::ST4i16_POST, "st4", ".h", 1, 8 },
695 { ARM64::ST4i32_POST, "st4", ".s", 1, 16 },
696 { ARM64::ST4i64_POST, "st4", ".d", 1, 32 },
697 { ARM64::ST4Fourv16b, "st4", ".16b", 0, 0 },
698 { ARM64::ST4Fourv8h, "st4", ".8h", 0, 0 },
699 { ARM64::ST4Fourv4s, "st4", ".4s", 0, 0 },
700 { ARM64::ST4Fourv2d, "st4", ".2d", 0, 0 },
701 { ARM64::ST4Fourv8b, "st4", ".8b", 0, 0 },
702 { ARM64::ST4Fourv4h, "st4", ".4h", 0, 0 },
703 { ARM64::ST4Fourv2s, "st4", ".2s", 0, 0 },
704 { ARM64::ST4Fourv16b_POST, "st4", ".16b", 0, 64 },
705 { ARM64::ST4Fourv8h_POST, "st4", ".8h", 0, 64 },
706 { ARM64::ST4Fourv4s_POST, "st4", ".4s", 0, 64 },
707 { ARM64::ST4Fourv2d_POST, "st4", ".2d", 0, 64 },
708 { ARM64::ST4Fourv8b_POST, "st4", ".8b", 0, 32 },
709 { ARM64::ST4Fourv4h_POST, "st4", ".4h", 0, 32 },
710 { ARM64::ST4Fourv2s_POST, "st4", ".2s", 0, 32 },
713 static LdStNInstrDesc *getLdStNInstrDesc(unsigned Opcode) {
715 for (Idx = 0; Idx != array_lengthof(LdStNInstInfo); ++Idx)
716 if (LdStNInstInfo[Idx].Opcode == Opcode)
717 return &LdStNInstInfo[Idx];
722 void ARM64AppleInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
724 unsigned Opcode = MI->getOpcode();
725 StringRef Layout, Mnemonic;
728 if (isTblTbxInstruction(MI->getOpcode(), Layout, IsTbx)) {
729 O << "\t" << (IsTbx ? "tbx" : "tbl") << Layout << '\t'
730 << getRegisterName(MI->getOperand(0).getReg(), ARM64::vreg) << ", ";
732 unsigned ListOpNum = IsTbx ? 2 : 1;
733 printVectorList(MI, ListOpNum, O, "");
736 << getRegisterName(MI->getOperand(ListOpNum + 1).getReg(), ARM64::vreg);
737 printAnnotation(O, Annot);
741 if (LdStNInstrDesc *LdStDesc = getLdStNInstrDesc(Opcode)) {
742 O << "\t" << LdStDesc->Mnemonic << LdStDesc->Layout << '\t';
744 // Now onto the operands: first a vector list with possible lane
745 // specifier. E.g. { v0 }[2]
746 printVectorList(MI, 0, O, "");
748 if (LdStDesc->LaneOperand != 0)
749 O << '[' << MI->getOperand(LdStDesc->LaneOperand).getImm() << ']';
751 // Next the address: [xN]
752 unsigned AddrOpNum = LdStDesc->LaneOperand + 1;
753 unsigned AddrReg = MI->getOperand(AddrOpNum).getReg();
754 O << ", [" << getRegisterName(AddrReg) << ']';
756 // Finally, there might be a post-indexed offset.
757 if (LdStDesc->NaturalOffset != 0) {
758 unsigned Reg = MI->getOperand(AddrOpNum + 1).getReg();
759 if (Reg != ARM64::XZR)
760 O << ", " << getRegisterName(Reg);
762 assert(LdStDesc->NaturalOffset && "no offset on post-inc instruction?");
763 O << ", #" << LdStDesc->NaturalOffset;
767 printAnnotation(O, Annot);
771 ARM64InstPrinter::printInst(MI, O, Annot);
774 bool ARM64InstPrinter::printSysAlias(const MCInst *MI, raw_ostream &O) {
776 unsigned Opcode = MI->getOpcode();
777 assert(Opcode == ARM64::SYSxt && "Invalid opcode for SYS alias!");
780 const char *Asm = nullptr;
781 const MCOperand &Op1 = MI->getOperand(0);
782 const MCOperand &Cn = MI->getOperand(1);
783 const MCOperand &Cm = MI->getOperand(2);
784 const MCOperand &Op2 = MI->getOperand(3);
786 unsigned Op1Val = Op1.getImm();
787 unsigned CnVal = Cn.getImm();
788 unsigned CmVal = Cm.getImm();
789 unsigned Op2Val = Op2.getImm();
798 if (Op1Val == 0 && Op2Val == 0)
802 if (Op1Val == 0 && Op2Val == 0)
804 else if (Op1Val == 3 && Op2Val == 1)
810 if (Op1Val == 3 && Op2Val == 1)
814 if (Op1Val == 0 && Op2Val == 1)
816 if (Op1Val == 0 && Op2Val == 2)
820 if (Op1Val == 3 && Op2Val == 1)
822 else if (Op1Val == 0 && Op2Val == 2)
826 if (Op1Val == 3 && Op2Val == 1)
830 if (Op1Val == 3 && Op2Val == 1)
832 else if (Op1Val == 0 && Op2Val == 2)
845 case 0: Asm = "at\ts1e1r"; break;
846 case 1: Asm = "at\ts1e1w"; break;
847 case 2: Asm = "at\ts1e0r"; break;
848 case 3: Asm = "at\ts1e0w"; break;
855 case 0: Asm = "at\ts1e2r"; break;
856 case 1: Asm = "at\ts1e2w"; break;
857 case 4: Asm = "at\ts12e1r"; break;
858 case 5: Asm = "at\ts12e1w"; break;
859 case 6: Asm = "at\ts12e0r"; break;
860 case 7: Asm = "at\ts12e0w"; break;
867 case 0: Asm = "at\ts1e3r"; break;
868 case 1: Asm = "at\ts1e3w"; break;
874 } else if (CnVal == 8) {
887 case 0: Asm = "tlbi\tvmalle1is"; break;
888 case 1: Asm = "tlbi\tvae1is"; break;
889 case 2: Asm = "tlbi\taside1is"; break;
890 case 3: Asm = "tlbi\tvaae1is"; break;
891 case 5: Asm = "tlbi\tvale1is"; break;
892 case 7: Asm = "tlbi\tvaale1is"; break;
899 case 0: Asm = "tlbi\talle2is"; break;
900 case 1: Asm = "tlbi\tvae2is"; break;
901 case 4: Asm = "tlbi\talle1is"; break;
902 case 5: Asm = "tlbi\tvale2is"; break;
903 case 6: Asm = "tlbi\tvmalls12e1is"; break;
910 case 0: Asm = "tlbi\talle3is"; break;
911 case 1: Asm = "tlbi\tvae3is"; break;
912 case 5: Asm = "tlbi\tvale3is"; break;
925 case 1: Asm = "tlbi\tipas2e1is"; break;
926 case 5: Asm = "tlbi\tipas2le1is"; break;
939 case 1: Asm = "tlbi\tipas2e1"; break;
940 case 5: Asm = "tlbi\tipas2le1"; break;
953 case 0: Asm = "tlbi\tvmalle1"; break;
954 case 1: Asm = "tlbi\tvae1"; break;
955 case 2: Asm = "tlbi\taside1"; break;
956 case 3: Asm = "tlbi\tvaae1"; break;
957 case 5: Asm = "tlbi\tvale1"; break;
958 case 7: Asm = "tlbi\tvaale1"; break;
965 case 0: Asm = "tlbi\talle2"; break;
966 case 1: Asm = "tlbi\tvae2"; break;
967 case 4: Asm = "tlbi\talle1"; break;
968 case 5: Asm = "tlbi\tvale2"; break;
969 case 6: Asm = "tlbi\tvmalls12e1"; break;
976 case 0: Asm = "tlbi\talle3"; break;
977 case 1: Asm = "tlbi\tvae3"; break;
978 case 5: Asm = "tlbi\tvale3"; break;
987 unsigned Reg = MI->getOperand(4).getReg();
990 if (StringRef(Asm).lower().find("all") == StringRef::npos)
991 O << ", " << getRegisterName(Reg);
994 return Asm != nullptr;
997 void ARM64InstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
999 const MCOperand &Op = MI->getOperand(OpNo);
1001 unsigned Reg = Op.getReg();
1002 O << getRegisterName(Reg);
1003 } else if (Op.isImm()) {
1004 O << '#' << Op.getImm();
1006 assert(Op.isExpr() && "unknown operand kind in printOperand");
1011 void ARM64InstPrinter::printHexImm(const MCInst *MI, unsigned OpNo,
1013 const MCOperand &Op = MI->getOperand(OpNo);
1014 O << format("#%#llx", Op.getImm());
1017 void ARM64InstPrinter::printPostIncOperand(const MCInst *MI, unsigned OpNo,
1018 unsigned Imm, raw_ostream &O) {
1019 const MCOperand &Op = MI->getOperand(OpNo);
1021 unsigned Reg = Op.getReg();
1022 if (Reg == ARM64::XZR)
1025 O << getRegisterName(Reg);
1027 assert(0 && "unknown operand kind in printPostIncOperand64");
1030 void ARM64InstPrinter::printPostIncOperand1(const MCInst *MI, unsigned OpNo,
1032 printPostIncOperand(MI, OpNo, 1, O);
1035 void ARM64InstPrinter::printPostIncOperand2(const MCInst *MI, unsigned OpNo,
1037 printPostIncOperand(MI, OpNo, 2, O);
1040 void ARM64InstPrinter::printPostIncOperand3(const MCInst *MI, unsigned OpNo,
1042 printPostIncOperand(MI, OpNo, 3, O);
1045 void ARM64InstPrinter::printPostIncOperand4(const MCInst *MI, unsigned OpNo,
1047 printPostIncOperand(MI, OpNo, 4, O);
1050 void ARM64InstPrinter::printPostIncOperand6(const MCInst *MI, unsigned OpNo,
1052 printPostIncOperand(MI, OpNo, 6, O);
1055 void ARM64InstPrinter::printPostIncOperand8(const MCInst *MI, unsigned OpNo,
1057 printPostIncOperand(MI, OpNo, 8, O);
1060 void ARM64InstPrinter::printPostIncOperand12(const MCInst *MI, unsigned OpNo,
1062 printPostIncOperand(MI, OpNo, 12, O);
1065 void ARM64InstPrinter::printPostIncOperand16(const MCInst *MI, unsigned OpNo,
1067 printPostIncOperand(MI, OpNo, 16, O);
1070 void ARM64InstPrinter::printPostIncOperand24(const MCInst *MI, unsigned OpNo,
1072 printPostIncOperand(MI, OpNo, 24, O);
1075 void ARM64InstPrinter::printPostIncOperand32(const MCInst *MI, unsigned OpNo,
1077 printPostIncOperand(MI, OpNo, 32, O);
1080 void ARM64InstPrinter::printPostIncOperand48(const MCInst *MI, unsigned OpNo,
1082 printPostIncOperand(MI, OpNo, 48, O);
1085 void ARM64InstPrinter::printPostIncOperand64(const MCInst *MI, unsigned OpNo,
1087 printPostIncOperand(MI, OpNo, 64, O);
1090 void ARM64InstPrinter::printVRegOperand(const MCInst *MI, unsigned OpNo,
1092 const MCOperand &Op = MI->getOperand(OpNo);
1093 assert(Op.isReg() && "Non-register vreg operand!");
1094 unsigned Reg = Op.getReg();
1095 O << getRegisterName(Reg, ARM64::vreg);
1098 void ARM64InstPrinter::printSysCROperand(const MCInst *MI, unsigned OpNo,
1100 const MCOperand &Op = MI->getOperand(OpNo);
1101 assert(Op.isImm() && "System instruction C[nm] operands must be immediates!");
1102 O << "c" << Op.getImm();
1105 void ARM64InstPrinter::printAddSubImm(const MCInst *MI, unsigned OpNum,
1107 const MCOperand &MO = MI->getOperand(OpNum);
1109 unsigned Val = (MO.getImm() & 0xfff);
1110 assert(Val == MO.getImm() && "Add/sub immediate out of range!");
1112 ARM64_AM::getShiftValue(MI->getOperand(OpNum + 1).getImm());
1115 printShifter(MI, OpNum + 1, O);
1118 *CommentStream << "=#" << (Val << Shift) << '\n';
1120 assert(MO.isExpr() && "Unexpected operand type!");
1122 printShifter(MI, OpNum + 1, O);
1126 void ARM64InstPrinter::printLogicalImm32(const MCInst *MI, unsigned OpNum,
1128 uint64_t Val = MI->getOperand(OpNum).getImm();
1130 O.write_hex(ARM64_AM::decodeLogicalImmediate(Val, 32));
1133 void ARM64InstPrinter::printLogicalImm64(const MCInst *MI, unsigned OpNum,
1135 uint64_t Val = MI->getOperand(OpNum).getImm();
1137 O.write_hex(ARM64_AM::decodeLogicalImmediate(Val, 64));
1140 void ARM64InstPrinter::printShifter(const MCInst *MI, unsigned OpNum,
1142 unsigned Val = MI->getOperand(OpNum).getImm();
1143 // LSL #0 should not be printed.
1144 if (ARM64_AM::getShiftType(Val) == ARM64_AM::LSL &&
1145 ARM64_AM::getShiftValue(Val) == 0)
1147 O << ", " << ARM64_AM::getShiftName(ARM64_AM::getShiftType(Val)) << " #"
1148 << ARM64_AM::getShiftValue(Val);
1151 void ARM64InstPrinter::printShiftedRegister(const MCInst *MI, unsigned OpNum,
1153 O << getRegisterName(MI->getOperand(OpNum).getReg());
1154 printShifter(MI, OpNum + 1, O);
1157 void ARM64InstPrinter::printExtendedRegister(const MCInst *MI, unsigned OpNum,
1159 O << getRegisterName(MI->getOperand(OpNum).getReg());
1160 printExtend(MI, OpNum + 1, O);
1163 void ARM64InstPrinter::printExtend(const MCInst *MI, unsigned OpNum,
1165 unsigned Val = MI->getOperand(OpNum).getImm();
1166 ARM64_AM::ExtendType ExtType = ARM64_AM::getArithExtendType(Val);
1167 unsigned ShiftVal = ARM64_AM::getArithShiftValue(Val);
1169 // If the destination or first source register operand is [W]SP, print
1170 // UXTW/UXTX as LSL, and if the shift amount is also zero, print nothing at
1172 if (ExtType == ARM64_AM::UXTW || ExtType == ARM64_AM::UXTX) {
1173 unsigned Dest = MI->getOperand(0).getReg();
1174 unsigned Src1 = MI->getOperand(1).getReg();
1175 if ( ((Dest == ARM64::SP || Src1 == ARM64::SP) &&
1176 ExtType == ARM64_AM::UXTX) ||
1177 ((Dest == ARM64::WSP || Src1 == ARM64::WSP) &&
1178 ExtType == ARM64_AM::UXTW) ) {
1180 O << ", lsl #" << ShiftVal;
1184 O << ", " << ARM64_AM::getExtendName(ExtType);
1186 O << " #" << ShiftVal;
1189 void ARM64InstPrinter::printDotCondCode(const MCInst *MI, unsigned OpNum,
1191 ARM64CC::CondCode CC = (ARM64CC::CondCode)MI->getOperand(OpNum).getImm();
1192 O << '.' << ARM64CC::getCondCodeName(CC);
1195 void ARM64InstPrinter::printCondCode(const MCInst *MI, unsigned OpNum,
1197 ARM64CC::CondCode CC = (ARM64CC::CondCode)MI->getOperand(OpNum).getImm();
1198 O << ARM64CC::getCondCodeName(CC);
1201 void ARM64InstPrinter::printAMNoIndex(const MCInst *MI, unsigned OpNum,
1203 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']';
1206 void ARM64InstPrinter::printImmScale4(const MCInst *MI, unsigned OpNum,
1208 O << '#' << 4 * MI->getOperand(OpNum).getImm();
1211 void ARM64InstPrinter::printImmScale8(const MCInst *MI, unsigned OpNum,
1213 O << '#' << 8 * MI->getOperand(OpNum).getImm();
1216 void ARM64InstPrinter::printImmScale16(const MCInst *MI, unsigned OpNum,
1218 O << '#' << 16 * MI->getOperand(OpNum).getImm();
1221 void ARM64InstPrinter::printAMIndexed(const MCInst *MI, unsigned OpNum,
1222 unsigned Scale, raw_ostream &O) {
1223 const MCOperand MO1 = MI->getOperand(OpNum + 1);
1224 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg());
1226 if (MO1.getImm() != 0)
1227 O << ", #" << (MO1.getImm() * Scale);
1229 assert(MO1.isExpr() && "Unexpected operand type!");
1230 O << ", " << *MO1.getExpr();
1235 void ARM64InstPrinter::printAMIndexedWB(const MCInst *MI, unsigned OpNum,
1236 unsigned Scale, raw_ostream &O) {
1237 const MCOperand MO1 = MI->getOperand(OpNum + 1);
1238 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg());
1240 O << ", #" << (MO1.getImm() * Scale);
1242 assert(MO1.isExpr() && "Unexpected operand type!");
1243 O << ", " << *MO1.getExpr();
1248 void ARM64InstPrinter::printPrefetchOp(const MCInst *MI, unsigned OpNum,
1250 unsigned prfop = MI->getOperand(OpNum).getImm();
1252 StringRef Name = ARM64PRFM::PRFMMapper().toString(prfop, Valid);
1259 void ARM64InstPrinter::printMemoryPostIndexed32(const MCInst *MI,
1262 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1263 << 4 * MI->getOperand(OpNum + 1).getImm();
1266 void ARM64InstPrinter::printMemoryPostIndexed64(const MCInst *MI,
1269 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1270 << 8 * MI->getOperand(OpNum + 1).getImm();
1273 void ARM64InstPrinter::printMemoryPostIndexed128(const MCInst *MI,
1276 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1277 << 16 * MI->getOperand(OpNum + 1).getImm();
1280 void ARM64InstPrinter::printMemoryPostIndexed(const MCInst *MI, unsigned OpNum,
1282 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ']' << ", #"
1283 << MI->getOperand(OpNum + 1).getImm();
1286 void ARM64InstPrinter::printMemoryRegOffset(const MCInst *MI, unsigned OpNum,
1287 raw_ostream &O, int LegalShiftAmt) {
1288 unsigned Val = MI->getOperand(OpNum + 2).getImm();
1289 ARM64_AM::ExtendType ExtType = ARM64_AM::getMemExtendType(Val);
1291 O << '[' << getRegisterName(MI->getOperand(OpNum).getReg()) << ", ";
1292 if (ExtType == ARM64_AM::UXTW || ExtType == ARM64_AM::SXTW)
1293 O << getRegisterName(getWRegFromXReg(MI->getOperand(OpNum + 1).getReg()));
1295 O << getRegisterName(MI->getOperand(OpNum + 1).getReg());
1297 bool DoShift = ARM64_AM::getMemDoShift(Val);
1299 if (ExtType == ARM64_AM::UXTX) {
1303 O << ", " << ARM64_AM::getExtendName(ExtType);
1306 O << " #" << LegalShiftAmt;
1311 void ARM64InstPrinter::printMemoryRegOffset8(const MCInst *MI, unsigned OpNum,
1313 printMemoryRegOffset(MI, OpNum, O, 0);
1316 void ARM64InstPrinter::printMemoryRegOffset16(const MCInst *MI, unsigned OpNum,
1318 printMemoryRegOffset(MI, OpNum, O, 1);
1321 void ARM64InstPrinter::printMemoryRegOffset32(const MCInst *MI, unsigned OpNum,
1323 printMemoryRegOffset(MI, OpNum, O, 2);
1326 void ARM64InstPrinter::printMemoryRegOffset64(const MCInst *MI, unsigned OpNum,
1328 printMemoryRegOffset(MI, OpNum, O, 3);
1331 void ARM64InstPrinter::printMemoryRegOffset128(const MCInst *MI, unsigned OpNum,
1333 printMemoryRegOffset(MI, OpNum, O, 4);
1336 void ARM64InstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNum,
1338 const MCOperand &MO = MI->getOperand(OpNum);
1341 // FIXME: Should this ever happen?
1344 O << ARM64_AM::getFPImmFloat(MO.getImm());
1347 static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride = 1) {
1351 assert(0 && "Vector register expected!");
1352 case ARM64::Q0: Reg = ARM64::Q1; break;
1353 case ARM64::Q1: Reg = ARM64::Q2; break;
1354 case ARM64::Q2: Reg = ARM64::Q3; break;
1355 case ARM64::Q3: Reg = ARM64::Q4; break;
1356 case ARM64::Q4: Reg = ARM64::Q5; break;
1357 case ARM64::Q5: Reg = ARM64::Q6; break;
1358 case ARM64::Q6: Reg = ARM64::Q7; break;
1359 case ARM64::Q7: Reg = ARM64::Q8; break;
1360 case ARM64::Q8: Reg = ARM64::Q9; break;
1361 case ARM64::Q9: Reg = ARM64::Q10; break;
1362 case ARM64::Q10: Reg = ARM64::Q11; break;
1363 case ARM64::Q11: Reg = ARM64::Q12; break;
1364 case ARM64::Q12: Reg = ARM64::Q13; break;
1365 case ARM64::Q13: Reg = ARM64::Q14; break;
1366 case ARM64::Q14: Reg = ARM64::Q15; break;
1367 case ARM64::Q15: Reg = ARM64::Q16; break;
1368 case ARM64::Q16: Reg = ARM64::Q17; break;
1369 case ARM64::Q17: Reg = ARM64::Q18; break;
1370 case ARM64::Q18: Reg = ARM64::Q19; break;
1371 case ARM64::Q19: Reg = ARM64::Q20; break;
1372 case ARM64::Q20: Reg = ARM64::Q21; break;
1373 case ARM64::Q21: Reg = ARM64::Q22; break;
1374 case ARM64::Q22: Reg = ARM64::Q23; break;
1375 case ARM64::Q23: Reg = ARM64::Q24; break;
1376 case ARM64::Q24: Reg = ARM64::Q25; break;
1377 case ARM64::Q25: Reg = ARM64::Q26; break;
1378 case ARM64::Q26: Reg = ARM64::Q27; break;
1379 case ARM64::Q27: Reg = ARM64::Q28; break;
1380 case ARM64::Q28: Reg = ARM64::Q29; break;
1381 case ARM64::Q29: Reg = ARM64::Q30; break;
1382 case ARM64::Q30: Reg = ARM64::Q31; break;
1383 // Vector lists can wrap around.
1392 void ARM64InstPrinter::printVectorList(const MCInst *MI, unsigned OpNum,
1393 raw_ostream &O, StringRef LayoutSuffix) {
1394 unsigned Reg = MI->getOperand(OpNum).getReg();
1398 // Work out how many registers there are in the list (if there is an actual
1400 unsigned NumRegs = 1;
1401 if (MRI.getRegClass(ARM64::DDRegClassID).contains(Reg) ||
1402 MRI.getRegClass(ARM64::QQRegClassID).contains(Reg))
1404 else if (MRI.getRegClass(ARM64::DDDRegClassID).contains(Reg) ||
1405 MRI.getRegClass(ARM64::QQQRegClassID).contains(Reg))
1407 else if (MRI.getRegClass(ARM64::DDDDRegClassID).contains(Reg) ||
1408 MRI.getRegClass(ARM64::QQQQRegClassID).contains(Reg))
1411 // Now forget about the list and find out what the first register is.
1412 if (unsigned FirstReg = MRI.getSubReg(Reg, ARM64::dsub0))
1414 else if (unsigned FirstReg = MRI.getSubReg(Reg, ARM64::qsub0))
1417 // If it's a D-reg, we need to promote it to the equivalent Q-reg before
1418 // printing (otherwise getRegisterName fails).
1419 if (MRI.getRegClass(ARM64::FPR64RegClassID).contains(Reg)) {
1420 const MCRegisterClass &FPR128RC = MRI.getRegClass(ARM64::FPR128RegClassID);
1421 Reg = MRI.getMatchingSuperReg(Reg, ARM64::dsub, &FPR128RC);
1424 for (unsigned i = 0; i < NumRegs; ++i, Reg = getNextVectorRegister(Reg)) {
1425 O << getRegisterName(Reg, ARM64::vreg) << LayoutSuffix;
1426 if (i + 1 != NumRegs)
1433 void ARM64InstPrinter::printImplicitlyTypedVectorList(const MCInst *MI,
1436 printVectorList(MI, OpNum, O, "");
1439 template <unsigned NumLanes, char LaneKind>
1440 void ARM64InstPrinter::printTypedVectorList(const MCInst *MI, unsigned OpNum,
1442 std::string Suffix(".");
1444 Suffix += itostr(NumLanes) + LaneKind;
1448 printVectorList(MI, OpNum, O, Suffix);
1451 void ARM64InstPrinter::printVectorIndex(const MCInst *MI, unsigned OpNum,
1453 O << "[" << MI->getOperand(OpNum).getImm() << "]";
1456 void ARM64InstPrinter::printAlignedLabel(const MCInst *MI, unsigned OpNum,
1458 const MCOperand &Op = MI->getOperand(OpNum);
1460 // If the label has already been resolved to an immediate offset (say, when
1461 // we're running the disassembler), just print the immediate.
1463 O << "#" << (Op.getImm() << 2);
1467 // If the branch target is simply an address then print it in hex.
1468 const MCConstantExpr *BranchTarget =
1469 dyn_cast<MCConstantExpr>(MI->getOperand(OpNum).getExpr());
1471 if (BranchTarget && BranchTarget->EvaluateAsAbsolute(Address)) {
1473 O.write_hex(Address);
1475 // Otherwise, just print the expression.
1476 O << *MI->getOperand(OpNum).getExpr();
1480 void ARM64InstPrinter::printAdrpLabel(const MCInst *MI, unsigned OpNum,
1482 const MCOperand &Op = MI->getOperand(OpNum);
1484 // If the label has already been resolved to an immediate offset (say, when
1485 // we're running the disassembler), just print the immediate.
1487 O << "#" << (Op.getImm() << 12);
1491 // Otherwise, just print the expression.
1492 O << *MI->getOperand(OpNum).getExpr();
1495 void ARM64InstPrinter::printBarrierOption(const MCInst *MI, unsigned OpNo,
1497 unsigned Val = MI->getOperand(OpNo).getImm();
1498 unsigned Opcode = MI->getOpcode();
1502 if (Opcode == ARM64::ISB)
1503 Name = ARM64ISB::ISBMapper().toString(Val, Valid);
1505 Name = ARM64DB::DBarrierMapper().toString(Val, Valid);
1512 void ARM64InstPrinter::printMRSSystemRegister(const MCInst *MI, unsigned OpNo,
1514 unsigned Val = MI->getOperand(OpNo).getImm();
1517 auto Mapper = ARM64SysReg::MRSMapper();
1518 std::string Name = Mapper.toString(Val, Valid);
1521 O << StringRef(Name).upper();
1524 void ARM64InstPrinter::printMSRSystemRegister(const MCInst *MI, unsigned OpNo,
1526 unsigned Val = MI->getOperand(OpNo).getImm();
1529 auto Mapper = ARM64SysReg::MSRMapper();
1530 std::string Name = Mapper.toString(Val, Valid);
1533 O << StringRef(Name).upper();
1536 void ARM64InstPrinter::printSystemCPSRField(const MCInst *MI, unsigned OpNo,
1538 unsigned Val = MI->getOperand(OpNo).getImm();
1541 StringRef Name = ARM64PState::PStateMapper().toString(Val, Valid);
1543 O << StringRef(Name.str()).upper();
1548 void ARM64InstPrinter::printSIMDType10Operand(const MCInst *MI, unsigned OpNo,
1550 unsigned RawVal = MI->getOperand(OpNo).getImm();
1551 uint64_t Val = ARM64_AM::decodeAdvSIMDModImmType10(RawVal);
1552 O << format("#%#016llx", Val);