Coverage Report

Created: 2026-09-01 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/AArch64/AArch64InstPrinter.c
Line
Count
Source
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//==-- AArch64InstPrinter.cpp - Convert AArch64 MCInst to assembly syntax --==//
16
//
17
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
18
// See https://llvm.org/LICENSE.txt for license information.
19
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20
//
21
//===----------------------------------------------------------------------===//
22
//
23
// This class prints an AArch64 MCInst to a .s file.
24
//
25
//===----------------------------------------------------------------------===//
26
27
#include <stdio.h>
28
#include <string.h>
29
#include <stdlib.h>
30
#include <capstone/platform.h>
31
32
#include "../../Mapping.h"
33
#include "../../MCInst.h"
34
#include "../../MCInstPrinter.h"
35
#include "../../MCRegisterInfo.h"
36
#include "../../SStream.h"
37
#include "../../utils.h"
38
#include "AArch64AddressingModes.h"
39
#include "AArch64BaseInfo.h"
40
#include "AArch64DisassemblerExtension.h"
41
#include "AArch64InstPrinter.h"
42
#include "AArch64Linkage.h"
43
#include "AArch64Mapping.h"
44
45
#define GET_BANKEDREG_IMPL
46
#include "AArch64GenSystemOperands.inc"
47
48
286k
#define CONCAT(a, b) CONCAT_(a, b)
49
286k
#define CONCAT_(a, b) a##_##b
50
51
#define CONCATs(a, b) CONCATS(a, b)
52
#define CONCATS(a, b) a##b
53
54
#define DEBUG_TYPE "asm-printer"
55
56
// BEGIN Static declarations.
57
// These functions must be declared statically here, because they
58
// are also defined in the ARM module.
59
// If they are not static, we fail during linking.
60
61
static void printCustomAliasOperand(MCInst *MI, uint64_t Address,
62
            unsigned OpIdx, unsigned PrintMethodIdx,
63
            SStream *OS);
64
65
static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O);
66
67
#define DECLARE_printComplexRotationOp(Angle, Remainder) \
68
  static void CONCAT(printComplexRotationOp, CONCAT(Angle, Remainder))( \
69
    MCInst * MI, unsigned OpNo, SStream *O);
70
DECLARE_printComplexRotationOp(180, 90);
71
DECLARE_printComplexRotationOp(90, 0);
72
73
// END Static declarations.
74
75
#define GET_INSTRUCTION_NAME
76
#define PRINT_ALIAS_INSTR
77
#include "AArch64GenAsmWriter.inc"
78
79
void printRegName(SStream *OS, unsigned Reg)
80
490k
{
81
490k
  SStream_concat(OS, "%s%s", markup("<reg:"),
82
490k
           getRegisterName(Reg, AArch64_NoRegAltName));
83
490k
  SStream_concat0(OS, markup(">"));
84
490k
}
85
86
void printRegNameAlt(SStream *OS, unsigned Reg, unsigned AltIdx)
87
121k
{
88
121k
  SStream_concat(OS, "%s%s", markup("<reg:"),
89
121k
           getRegisterName(Reg, AltIdx));
90
121k
  SStream_concat0(OS, markup(">"));
91
121k
}
92
93
const char *getRegName(unsigned Reg)
94
0
{
95
0
  return getRegisterName(Reg, AArch64_NoRegAltName);
96
0
}
97
98
void printInst(MCInst *MI, uint64_t Address, const char *Annot, SStream *O)
99
245k
{
100
245k
  bool isAlias = false;
101
245k
  bool useAliasDetails = map_use_alias_details(MI);
102
245k
  map_set_fill_detail_ops(MI, useAliasDetails);
103
104
245k
  unsigned Opcode = MCInst_getOpcode(MI);
105
106
245k
  if (Opcode == AArch64_SYSxt) {
107
3.27k
    if (printSysAlias(MI, O)) {
108
1.08k
      isAlias = true;
109
1.08k
      MCInst_setIsAlias(MI, isAlias);
110
1.08k
      if (useAliasDetails)
111
1.08k
        return;
112
1.08k
    }
113
3.27k
  }
114
115
244k
  if (Opcode == AArch64_SYSPxt || Opcode == AArch64_SYSPxt_XZR) {
116
1.48k
    if (printSyspAlias(MI, O)) {
117
676
      isAlias = true;
118
676
      MCInst_setIsAlias(MI, isAlias);
119
676
      if (useAliasDetails)
120
676
        return;
121
676
    }
122
1.48k
  }
123
124
  // RPRFM overlaps PRFM (reg), so try to print it as RPRFM here.
125
244k
  if ((Opcode == AArch64_PRFMroX) || (Opcode == AArch64_PRFMroW)) {
126
372
    if (printRangePrefetchAlias(MI, O, Annot)) {
127
0
      isAlias = true;
128
0
      MCInst_setIsAlias(MI, isAlias);
129
0
      if (useAliasDetails)
130
0
        return;
131
0
    }
132
372
  }
133
134
  // SBFM/UBFM should print to a nicer aliased form if possible.
135
244k
  if (Opcode == AArch64_SBFMXri || Opcode == AArch64_SBFMWri ||
136
242k
      Opcode == AArch64_UBFMXri || Opcode == AArch64_UBFMWri) {
137
2.98k
    MCOperand *Op0 = MCInst_getOperand(MI, (0));
138
2.98k
    MCOperand *Op1 = MCInst_getOperand(MI, (1));
139
2.98k
    MCOperand *Op2 = MCInst_getOperand(MI, (2));
140
2.98k
    MCOperand *Op3 = MCInst_getOperand(MI, (3));
141
142
2.98k
    bool IsSigned = (Opcode == AArch64_SBFMXri ||
143
2.26k
         Opcode == AArch64_SBFMWri);
144
2.98k
    bool Is64Bit = (Opcode == AArch64_SBFMXri ||
145
2.26k
        Opcode == AArch64_UBFMXri);
146
2.98k
    if (MCOperand_isImm(Op2) && MCOperand_getImm(Op2) == 0 &&
147
1.62k
        MCOperand_isImm(Op3)) {
148
1.62k
      const char *AsmMnemonic = NULL;
149
150
1.62k
      switch (MCOperand_getImm(Op3)) {
151
389
      default:
152
389
        break;
153
487
      case 7:
154
487
        if (IsSigned)
155
146
          AsmMnemonic = "sxtb";
156
341
        else if (!Is64Bit)
157
243
          AsmMnemonic = "uxtb";
158
487
        break;
159
365
      case 15:
160
365
        if (IsSigned)
161
155
          AsmMnemonic = "sxth";
162
210
        else if (!Is64Bit)
163
160
          AsmMnemonic = "uxth";
164
365
        break;
165
382
      case 31:
166
        // *xtw is only valid for signed 64-bit operations.
167
382
        if (Is64Bit && IsSigned)
168
73
          AsmMnemonic = "sxtw";
169
382
        break;
170
1.62k
      }
171
172
1.62k
      if (AsmMnemonic) {
173
777
        SStream_concat(O, "%s", AsmMnemonic);
174
777
        SStream_concat0(O, " ");
175
176
777
        printRegName(O, MCOperand_getReg(Op0));
177
777
        SStream_concat0(O, ", ");
178
777
        printRegName(O, getWRegFromXReg(
179
777
              MCOperand_getReg(Op1)));
180
777
        if (detail_is_set(MI) && useAliasDetails) {
181
777
          AArch64_set_detail_op_reg(
182
777
            MI, 0, MCOperand_getReg(Op0));
183
777
          AArch64_set_detail_op_reg(
184
777
            MI, 1,
185
777
            getWRegFromXReg(
186
777
              MCOperand_getReg(Op1)));
187
777
          if (strings_match(AsmMnemonic, "uxtb"))
188
243
            AArch64_get_detail_op(MI, -1)
189
243
              ->ext =
190
243
              AARCH64_EXT_UXTB;
191
534
          else if (strings_match(AsmMnemonic,
192
534
                     "sxtb"))
193
146
            AArch64_get_detail_op(MI, -1)
194
146
              ->ext =
195
146
              AARCH64_EXT_SXTB;
196
388
          else if (strings_match(AsmMnemonic,
197
388
                     "uxth"))
198
160
            AArch64_get_detail_op(MI, -1)
199
160
              ->ext =
200
160
              AARCH64_EXT_UXTH;
201
228
          else if (strings_match(AsmMnemonic,
202
228
                     "sxth"))
203
155
            AArch64_get_detail_op(MI, -1)
204
155
              ->ext =
205
155
              AARCH64_EXT_SXTH;
206
73
          else if (strings_match(AsmMnemonic,
207
73
                     "sxtw"))
208
73
            AArch64_get_detail_op(MI, -1)
209
73
              ->ext =
210
73
              AARCH64_EXT_SXTW;
211
0
          else
212
0
            AArch64_get_detail_op(MI, -1)
213
0
              ->ext =
214
0
              AARCH64_EXT_INVALID;
215
777
        }
216
777
        isAlias = true;
217
777
        MCInst_setIsAlias(MI, isAlias);
218
777
        if (useAliasDetails)
219
777
          return;
220
0
        else
221
0
          goto add_real_detail;
222
777
      }
223
1.62k
    }
224
225
    // All immediate shifts are aliases, implemented using the Bitfield
226
    // instruction. In all cases the immediate shift amount shift must be in
227
    // the range 0 to (reg.size -1).
228
2.20k
    if (MCOperand_isImm(Op2) && MCOperand_isImm(Op3)) {
229
2.20k
      const char *AsmMnemonic = NULL;
230
2.20k
      int shift = 0;
231
2.20k
      int64_t immr = MCOperand_getImm(Op2);
232
2.20k
      int64_t imms = MCOperand_getImm(Op3);
233
2.20k
      if (Opcode == AArch64_UBFMWri && imms != 0x1F &&
234
332
          ((imms + 1) == immr)) {
235
32
        AsmMnemonic = "lsl";
236
32
        shift = 31 - imms;
237
2.17k
      } else if (Opcode == AArch64_UBFMXri && imms != 0x3f &&
238
674
           ((imms + 1 == immr))) {
239
114
        AsmMnemonic = "lsl";
240
114
        shift = 63 - imms;
241
2.05k
      } else if (Opcode == AArch64_UBFMWri && imms == 0x1f) {
242
81
        AsmMnemonic = "lsr";
243
81
        shift = immr;
244
1.97k
      } else if (Opcode == AArch64_UBFMXri && imms == 0x3f) {
245
41
        AsmMnemonic = "lsr";
246
41
        shift = immr;
247
1.93k
      } else if (Opcode == AArch64_SBFMWri && imms == 0x1f) {
248
316
        AsmMnemonic = "asr";
249
316
        shift = immr;
250
1.62k
      } else if (Opcode == AArch64_SBFMXri && imms == 0x3f) {
251
252
        AsmMnemonic = "asr";
252
252
        shift = immr;
253
252
      }
254
2.20k
      if (AsmMnemonic) {
255
836
        SStream_concat(O, "%s", AsmMnemonic);
256
836
        SStream_concat0(O, " ");
257
258
836
        printRegName(O, MCOperand_getReg(Op0));
259
836
        SStream_concat0(O, ", ");
260
836
        printRegName(O, MCOperand_getReg(Op1));
261
836
        SStream_concat(O, "%s%s#%d", ", ",
262
836
                 markup("<imm:"), shift);
263
836
        SStream_concat0(O, markup(">"));
264
836
        if (detail_is_set(MI) && useAliasDetails) {
265
836
          AArch64_set_detail_op_reg(
266
836
            MI, 0, MCOperand_getReg(Op0));
267
836
          AArch64_set_detail_op_reg(
268
836
            MI, 1, MCOperand_getReg(Op1));
269
836
          if (strings_match(AsmMnemonic, "lsl"))
270
146
            AArch64_get_detail_op(MI, -1)
271
146
              ->shift.type =
272
146
              AARCH64_SFT_LSL;
273
690
          else if (strings_match(AsmMnemonic,
274
690
                     "lsr"))
275
122
            AArch64_get_detail_op(MI, -1)
276
122
              ->shift.type =
277
122
              AARCH64_SFT_LSR;
278
568
          else if (strings_match(AsmMnemonic,
279
568
                     "asr"))
280
568
            AArch64_get_detail_op(MI, -1)
281
568
              ->shift.type =
282
568
              AARCH64_SFT_ASR;
283
0
          else
284
0
            AArch64_get_detail_op(MI, -1)
285
0
              ->shift.type =
286
0
              AARCH64_SFT_INVALID;
287
836
          AArch64_get_detail_op(MI, -1)
288
836
            ->shift.value = shift;
289
836
        }
290
836
        isAlias = true;
291
836
        MCInst_setIsAlias(MI, isAlias);
292
836
        if (useAliasDetails)
293
836
          return;
294
0
        else
295
0
          goto add_real_detail;
296
836
      }
297
2.20k
    }
298
299
    // SBFIZ/UBFIZ aliases
300
1.36k
    if (MCOperand_getImm(Op2) > MCOperand_getImm(Op3)) {
301
430
      SStream_concat(O, "%s", (IsSigned ? "sbfiz" : "ubfiz"));
302
430
      SStream_concat0(O, " ");
303
304
430
      printRegName(O, MCOperand_getReg(Op0));
305
430
      SStream_concat0(O, ", ");
306
430
      printRegName(O, MCOperand_getReg(Op1));
307
430
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
308
430
      printUInt32Bang(O, (Is64Bit ? 64 : 32) -
309
430
               MCOperand_getImm(Op2));
310
430
      SStream_concat(O, "%s%s%s", markup(">"), ", ",
311
430
               markup("<imm:"));
312
430
      printInt64Bang(O, MCOperand_getImm(Op3) + 1);
313
430
      SStream_concat0(O, markup(">"));
314
430
      if (detail_is_set(MI) && useAliasDetails) {
315
430
        AArch64_set_detail_op_reg(
316
430
          MI, 0, MCOperand_getReg(Op0));
317
430
        AArch64_set_detail_op_reg(
318
430
          MI, 1, MCOperand_getReg(Op1));
319
430
        AArch64_set_detail_op_imm(
320
430
          MI, 2, AARCH64_OP_IMM,
321
430
          (Is64Bit ? 64 : 32) -
322
430
            MCOperand_getImm(Op2));
323
430
        AArch64_set_detail_op_imm(
324
430
          MI, 3, AARCH64_OP_IMM,
325
430
          MCOperand_getImm(Op3) + 1);
326
430
      }
327
430
      isAlias = true;
328
430
      MCInst_setIsAlias(MI, isAlias);
329
430
      if (useAliasDetails)
330
430
        return;
331
0
      else
332
0
        goto add_real_detail;
333
430
    }
334
335
    // Otherwise SBFX/UBFX is the preferred form
336
938
    SStream_concat(O, "%s", (IsSigned ? "sbfx" : "ubfx"));
337
938
    SStream_concat0(O, " ");
338
339
938
    printRegName(O, MCOperand_getReg(Op0));
340
938
    SStream_concat0(O, ", ");
341
938
    printRegName(O, MCOperand_getReg(Op1));
342
938
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
343
938
    printInt64Bang(O, MCOperand_getImm(Op2));
344
938
    SStream_concat(O, "%s%s%s", markup(">"), ", ", markup("<imm:"));
345
938
    printInt64Bang(O, MCOperand_getImm(Op3) -
346
938
            MCOperand_getImm(Op2) + 1);
347
938
    SStream_concat0(O, markup(">"));
348
938
    if (detail_is_set(MI) && useAliasDetails) {
349
938
      AArch64_set_detail_op_reg(MI, 0, MCOperand_getReg(Op0));
350
938
      AArch64_set_detail_op_reg(MI, 1, MCOperand_getReg(Op1));
351
938
      AArch64_set_detail_op_imm(MI, 2, AARCH64_OP_IMM,
352
938
              MCOperand_getImm(Op2));
353
938
      AArch64_set_detail_op_imm(
354
938
        MI, 3, AARCH64_OP_IMM,
355
938
        MCOperand_getImm(Op3) - MCOperand_getImm(Op2) +
356
938
          1);
357
938
    }
358
938
    isAlias = true;
359
938
    MCInst_setIsAlias(MI, isAlias);
360
938
    if (useAliasDetails)
361
938
      return;
362
0
    else
363
0
      goto add_real_detail;
364
938
  }
365
366
241k
  if (Opcode == AArch64_BFMXri || Opcode == AArch64_BFMWri) {
367
548
    isAlias = true;
368
548
    MCInst_setIsAlias(MI, isAlias);
369
548
    MCOperand *Op0 = MCInst_getOperand(MI, (0)); // Op1 == Op0
370
548
    MCOperand *Op2 = MCInst_getOperand(MI, (2));
371
548
    int ImmR = MCOperand_getImm(MCInst_getOperand(MI, (3)));
372
548
    int ImmS = MCOperand_getImm(MCInst_getOperand(MI, (4)));
373
374
548
    if ((MCOperand_getReg(Op2) == AArch64_WZR ||
375
517
         MCOperand_getReg(Op2) == AArch64_XZR) &&
376
277
        (ImmR == 0 || ImmS < ImmR) &&
377
68
        (AArch64_getFeatureBits(MI->csh->mode,
378
68
              AArch64_FeatureAll) ||
379
0
         AArch64_getFeatureBits(MI->csh->mode,
380
68
              AArch64_HasV8_2aOps))) {
381
      // BFC takes precedence over its entire range, sligtly differently
382
      // to BFI.
383
68
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
384
68
      int LSB = (BitWidth - ImmR) % BitWidth;
385
68
      int Width = ImmS + 1;
386
387
68
      SStream_concat0(O, "bfc ");
388
68
      printRegName(O, MCOperand_getReg(Op0));
389
68
      SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"),
390
68
               LSB);
391
68
      SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
392
68
               markup("<imm:"), Width);
393
68
      SStream_concat0(O, markup(">"));
394
68
      if (detail_is_set(MI) && useAliasDetails) {
395
68
        AArch64_set_detail_op_reg(
396
68
          MI, 0, MCOperand_getReg(Op0));
397
68
        AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM,
398
68
                LSB);
399
68
        AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM,
400
68
                Width);
401
68
      }
402
403
68
      if (useAliasDetails)
404
68
        return;
405
0
      else
406
0
        goto add_real_detail;
407
480
    } else if (ImmS < ImmR) {
408
      // BFI alias
409
204
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
410
204
      int LSB = (BitWidth - ImmR) % BitWidth;
411
204
      int Width = ImmS + 1;
412
413
204
      SStream_concat0(O, "bfi ");
414
204
      printRegName(O, MCOperand_getReg(Op0));
415
204
      SStream_concat0(O, ", ");
416
204
      printRegName(O, MCOperand_getReg(Op2));
417
204
      SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"),
418
204
               LSB);
419
204
      SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
420
204
               markup("<imm:"), Width);
421
204
      SStream_concat0(O, markup(">"));
422
204
      if (detail_is_set(MI) && useAliasDetails) {
423
204
        AArch64_set_detail_op_reg(
424
204
          MI, 0, MCOperand_getReg(Op0));
425
204
        AArch64_set_detail_op_reg(
426
204
          MI, 2, MCOperand_getReg(Op2));
427
204
        AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM,
428
204
                LSB);
429
204
        AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM,
430
204
                Width);
431
204
      }
432
204
      if (useAliasDetails)
433
204
        return;
434
0
      else
435
0
        goto add_real_detail;
436
204
    }
437
438
276
    int LSB = ImmR;
439
276
    int Width = ImmS - ImmR + 1;
440
    // Otherwise BFXIL the preferred form
441
276
    SStream_concat0(O, "bfxil ");
442
276
    printRegName(O, MCOperand_getReg(Op0));
443
276
    SStream_concat0(O, ", ");
444
276
    printRegName(O, MCOperand_getReg(Op2));
445
276
    SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"), LSB);
446
276
    SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
447
276
             markup("<imm:"), Width);
448
276
    SStream_concat0(O, markup(">"));
449
276
    if (detail_is_set(MI) && useAliasDetails) {
450
276
      AArch64_set_detail_op_reg(MI, 0, MCOperand_getReg(Op0));
451
276
      AArch64_set_detail_op_reg(MI, 2, MCOperand_getReg(Op2));
452
276
      AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM, LSB);
453
276
      AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM, Width);
454
276
    }
455
276
    if (useAliasDetails)
456
276
      return;
457
276
  }
458
459
  // Symbolic operands for MOVZ, MOVN and MOVK already imply a shift
460
  // (e.g. :gottprel_g1: is always going to be "lsl #16") so it should not be
461
  // printed.
462
240k
  if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi ||
463
240k
       Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) &&
464
1.64k
      MCOperand_isExpr(MCInst_getOperand(MI, (1)))) {
465
0
    printUInt64Bang(O, MCInst_getOpVal(MI, 1));
466
0
    if (detail_is_set(MI) && useAliasDetails) {
467
0
      AArch64_set_detail_op_imm(MI, 1, AARCH64_OP_IMM,
468
0
              MCInst_getOpVal(MI, 1));
469
0
    }
470
0
  }
471
472
240k
  if ((Opcode == AArch64_MOVKXi || Opcode == AArch64_MOVKWi) &&
473
734
      MCOperand_isExpr(MCInst_getOperand(MI, (2)))) {
474
0
    printUInt64Bang(O, MCInst_getOpVal(MI, 2));
475
0
    if (detail_is_set(MI) && useAliasDetails) {
476
0
      AArch64_set_detail_op_imm(MI, 2, AARCH64_OP_IMM,
477
0
              MCInst_getOpVal(MI, 2));
478
0
    }
479
0
  }
480
481
  // MOVZ, MOVN and "ORR wzr, #imm" instructions are aliases for MOV, but
482
  // their domains overlap so they need to be prioritized. The chain is "MOVZ
483
  // lsl #0 > MOVZ lsl #N > MOVN lsl #0 > MOVN lsl #N > ORR". The highest
484
  // instruction that can represent the move is the MOV alias, and the rest
485
  // get printed normally.
486
240k
  if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi) &&
487
635
      MCOperand_isImm(MCInst_getOperand(MI, (1))) &&
488
635
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
489
635
    int RegWidth = Opcode == AArch64_MOVZXi ? 64 : 32;
490
635
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, (2)));
491
635
    uint64_t Value =
492
635
      (uint64_t)MCOperand_getImm(MCInst_getOperand(MI, (1)))
493
635
      << Shift;
494
495
635
    bool SuppressMovAlias =
496
635
      (MI->csh->syntax &
497
635
       CS_OPT_SYNTAX_AARCH64_EXPLICIT_WIDE_IMM) &&
498
0
      Shift != 0;
499
500
635
    if (!SuppressMovAlias &&
501
635
        AArch64_AM_isMOVZMovAlias(
502
635
          Value, Shift, Opcode == AArch64_MOVZXi ? 64 : 32)) {
503
545
      isAlias = true;
504
545
      MCInst_setIsAlias(MI, isAlias);
505
545
      SStream_concat0(O, "mov ");
506
545
      printRegName(O, MCOperand_getReg(
507
545
            MCInst_getOperand(MI, (0))));
508
545
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
509
545
      printInt64Bang(O, SignExtend64(Value, RegWidth));
510
545
      SStream_concat0(O, markup(">"));
511
545
      if (detail_is_set(MI) && useAliasDetails) {
512
545
        AArch64_set_detail_op_reg(
513
545
          MI, 0, MCInst_getOpVal(MI, 0));
514
545
        AArch64_set_detail_op_imm(
515
545
          MI, 1, AARCH64_OP_IMM,
516
545
          SignExtend64(Value, RegWidth));
517
545
      }
518
545
      if (useAliasDetails)
519
545
        return;
520
545
    }
521
635
  }
522
523
240k
  if ((Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) &&
524
1.00k
      MCOperand_isImm(MCInst_getOperand(MI, (1))) &&
525
1.00k
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
526
1.00k
    int RegWidth = Opcode == AArch64_MOVNXi ? 64 : 32;
527
1.00k
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, (2)));
528
1.00k
    uint64_t Value =
529
1.00k
      ~((uint64_t)MCOperand_getImm(MCInst_getOperand(MI, (1)))
530
1.00k
        << Shift);
531
1.00k
    if (RegWidth == 32)
532
38
      Value = Value & 0xffffffff;
533
534
1.00k
    bool SuppressMovAlias =
535
1.00k
      (MI->csh->syntax &
536
1.00k
       CS_OPT_SYNTAX_AARCH64_EXPLICIT_WIDE_IMM) &&
537
0
      Shift != 0;
538
539
1.00k
    if (!SuppressMovAlias &&
540
1.00k
        AArch64_AM_isMOVNMovAlias(Value, Shift, RegWidth)) {
541
989
      isAlias = true;
542
989
      MCInst_setIsAlias(MI, isAlias);
543
989
      SStream_concat0(O, "mov ");
544
989
      printRegName(O, MCOperand_getReg(
545
989
            MCInst_getOperand(MI, (0))));
546
989
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
547
989
      printInt64Bang(O, SignExtend64(Value, RegWidth));
548
989
      SStream_concat0(O, markup(">"));
549
989
      if (detail_is_set(MI) && useAliasDetails) {
550
989
        AArch64_set_detail_op_reg(
551
989
          MI, 0, MCInst_getOpVal(MI, 0));
552
989
        AArch64_set_detail_op_imm(
553
989
          MI, 1, AARCH64_OP_IMM,
554
989
          SignExtend64(Value, RegWidth));
555
989
      }
556
989
      if (useAliasDetails)
557
989
        return;
558
989
    }
559
1.00k
  }
560
561
239k
  if ((Opcode == AArch64_ORRXri || Opcode == AArch64_ORRWri) &&
562
2.05k
      (MCOperand_getReg(MCInst_getOperand(MI, (1))) == AArch64_XZR ||
563
1.31k
       MCOperand_getReg(MCInst_getOperand(MI, (1))) == AArch64_WZR) &&
564
1.09k
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
565
1.09k
    int RegWidth = Opcode == AArch64_ORRXri ? 64 : 32;
566
1.09k
    uint64_t Value = AArch64_AM_decodeLogicalImmediate(
567
1.09k
      MCOperand_getImm(MCInst_getOperand(MI, (2))), RegWidth);
568
1.09k
    if (!AArch64_AM_isAnyMOVWMovAlias(Value, RegWidth)) {
569
572
      isAlias = true;
570
572
      MCInst_setIsAlias(MI, isAlias);
571
572
      SStream_concat0(O, "mov ");
572
572
      printRegName(O, MCOperand_getReg(
573
572
            MCInst_getOperand(MI, (0))));
574
572
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
575
572
      printInt64Bang(O, SignExtend64(Value, RegWidth));
576
572
      SStream_concat0(O, markup(">"));
577
572
      if (detail_is_set(MI) && useAliasDetails) {
578
572
        AArch64_set_detail_op_reg(
579
572
          MI, 0, MCInst_getOpVal(MI, 0));
580
572
        AArch64_set_detail_op_imm(
581
572
          MI, 2, AARCH64_OP_IMM,
582
572
          SignExtend64(Value, RegWidth));
583
572
      }
584
572
      if (useAliasDetails)
585
572
        return;
586
572
    }
587
1.09k
  }
588
589
238k
  if (Opcode == AArch64_SPACE) {
590
0
    isAlias = true;
591
0
    MCInst_setIsAlias(MI, isAlias);
592
0
    SStream_concat1(O, ' ');
593
0
    SStream_concat(O, "%s", " SPACE ");
594
0
    printInt64(O, MCOperand_getImm(MCInst_getOperand(MI, (1))));
595
0
    if (detail_is_set(MI) && useAliasDetails) {
596
0
      AArch64_set_detail_op_imm(MI, 1, AARCH64_OP_IMM,
597
0
              MCInst_getOpVal(MI, 1));
598
0
    }
599
0
    if (useAliasDetails)
600
0
      return;
601
0
  }
602
603
238k
  if (!isAlias)
604
238k
    isAlias |= printAliasInstr(MI, Address, O);
605
606
238k
add_real_detail:
607
238k
  MCInst_setIsAlias(MI, isAlias);
608
609
238k
  if (!isAlias || !useAliasDetails) {
610
216k
    map_set_fill_detail_ops(MI, !(isAlias && useAliasDetails));
611
216k
    if (isAlias)
612
0
      SStream_Close(O);
613
216k
    printInstruction(MI, Address, O);
614
216k
    if (isAlias)
615
0
      SStream_Open(O);
616
216k
  }
617
238k
}
618
619
bool printRangePrefetchAlias(MCInst *MI, SStream *O, const char *Annot)
620
372
{
621
372
  unsigned Opcode = MCInst_getOpcode(MI);
622
623
372
#ifndef NDEBUG
624
625
372
#endif
626
627
372
  unsigned PRFOp = MCOperand_getImm(MCInst_getOperand(MI, (0)));
628
372
  unsigned Mask = 0x18; // 0b11000
629
372
  if ((PRFOp & Mask) != Mask)
630
372
    return false; // Rt != '11xxx', it's a PRFM instruction.
631
632
0
  unsigned Rm = MCOperand_getReg(MCInst_getOperand(MI, (2)));
633
634
  // "Rm" must be a 64-bit GPR for RPRFM.
635
0
  if (MCRegisterInfo_getRegClass(MI->MRI, Rm))
636
0
    Rm = MCRegisterInfo_getMatchingSuperReg(
637
0
      MI->MRI, Rm, AArch64_sub_32,
638
0
      MCRegisterInfo_getRegClass(MI->MRI, Rm));
639
640
0
  unsigned SignExtend = MCOperand_getImm(
641
0
    MCInst_getOperand(MI, (3))); // encoded in "option<2>".
642
0
  unsigned Shift =
643
0
    MCOperand_getImm(MCInst_getOperand(MI, (4))); // encoded in "S".
644
645
0
  unsigned Option0 = (Opcode == AArch64_PRFMroX) ? 1 : 0;
646
647
  // encoded in "option<2>:option<0>:S:Rt<2:0>".
648
0
  unsigned RPRFOp = (SignExtend << 5) | (Option0 << 4) | (Shift << 3) |
649
0
        (PRFOp & 0x7);
650
651
0
  SStream_concat0(O, "rprfm ");
652
0
  const AArch64RPRFM_RPRFM *RPRFM =
653
0
    AArch64RPRFM_lookupRPRFMByEncoding(RPRFOp);
654
0
  if (RPRFM) {
655
0
    SStream_concat0(O, RPRFM->Name);
656
0
  } else {
657
0
    printUInt32Bang(O, RPRFOp);
658
0
    SStream_concat(O, ", ");
659
0
  }
660
0
  SStream_concat0(O, getRegisterName(Rm, AArch64_NoRegAltName));
661
0
  SStream_concat0(O, ", [");
662
0
  printOperand(MI, 1, O); // "Rn".
663
0
  SStream_concat0(O, "]");
664
665
0
  return true;
666
372
}
667
668
bool printSysAlias(MCInst *MI, SStream *O)
669
3.27k
{
670
3.27k
  MCOperand *Op1 = MCInst_getOperand(MI, (0));
671
3.27k
  MCOperand *Cn = MCInst_getOperand(MI, (1));
672
3.27k
  MCOperand *Cm = MCInst_getOperand(MI, (2));
673
3.27k
  MCOperand *Op2 = MCInst_getOperand(MI, (3));
674
675
3.27k
  unsigned Op1Val = MCOperand_getImm(Op1);
676
3.27k
  unsigned CnVal = MCOperand_getImm(Cn);
677
3.27k
  unsigned CmVal = MCOperand_getImm(Cm);
678
3.27k
  unsigned Op2Val = MCOperand_getImm(Op2);
679
680
3.27k
  uint16_t Encoding = Op2Val;
681
3.27k
  Encoding |= CmVal << 3;
682
3.27k
  Encoding |= CnVal << 7;
683
3.27k
  Encoding |= Op1Val << 11;
684
685
3.27k
  bool NeedsReg;
686
3.27k
  const char *Ins;
687
3.27k
  const char *Name;
688
689
3.27k
  if (CnVal == 7) {
690
2.38k
    switch (CmVal) {
691
49
    default:
692
49
      return false;
693
    // Maybe IC, maybe Prediction Restriction
694
294
    case 1:
695
294
      switch (Op1Val) {
696
71
      default:
697
71
        return false;
698
198
      case 0:
699
198
        goto Search_IC;
700
25
      case 3:
701
25
        goto Search_PRCTX;
702
294
      }
703
    // Prediction Restriction aliases
704
764
    case 3: {
705
789
Search_PRCTX:
706
789
      if (Op1Val != 3 || CnVal != 7 || CmVal != 3)
707
27
        return false;
708
709
762
      unsigned int Requires =
710
762
        Op2Val == 6 ? AArch64_FeatureSPECRES2 :
711
762
                AArch64_FeaturePredRes;
712
762
      if (!(AArch64_getFeatureBits(MI->csh->mode,
713
762
                 AArch64_FeatureAll) ||
714
0
            AArch64_getFeatureBits(MI->csh->mode, Requires)))
715
0
        return false;
716
717
762
      NeedsReg = true;
718
762
      switch (Op2Val) {
719
188
      default:
720
188
        return false;
721
135
      case 4:
722
135
        Ins = "cfp ";
723
135
        break;
724
343
      case 5:
725
343
        Ins = "dvp ";
726
343
        break;
727
8
      case 6:
728
8
        Ins = "cosp ";
729
8
        break;
730
88
      case 7:
731
88
        Ins = "cpp ";
732
88
        break;
733
762
      }
734
574
      Name = "RCTX";
735
574
    } break;
736
    // IC aliases
737
95
    case 5: {
738
293
Search_IC: {
739
293
  const AArch64IC_IC *IC = AArch64IC_lookupICByEncoding(Encoding);
740
293
  if (!IC ||
741
64
      !AArch64_testFeatureList(MI->csh->mode, IC->FeaturesRequired))
742
229
    return false;
743
64
  if (detail_is_set(MI)) {
744
64
    aarch64_sysop sysop = { 0 };
745
64
    sysop.reg = IC->SysReg;
746
64
    sysop.sub_type = AARCH64_OP_IC;
747
64
    AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
748
64
    AArch64_get_detail_op(MI, 0)->sysop = sysop;
749
64
    AArch64_inc_op_count(MI);
750
64
  }
751
752
64
  NeedsReg = IC->NeedsReg;
753
64
  Ins = "ic ";
754
64
  Name = IC->Name;
755
64
}
756
64
    } break;
757
    // DC aliases
758
72
    case 4:
759
153
    case 6:
760
648
    case 10:
761
693
    case 11:
762
717
    case 12:
763
808
    case 13:
764
955
    case 14: {
765
955
      const AArch64DC_DC *DC =
766
955
        AArch64DC_lookupDCByEncoding(Encoding);
767
955
      if (!DC || !AArch64_testFeatureList(
768
343
             MI->csh->mode, DC->FeaturesRequired))
769
612
        return false;
770
343
      if (detail_is_set(MI)) {
771
343
        aarch64_sysop sysop = { 0 };
772
343
        sysop.alias = DC->SysAlias;
773
343
        sysop.sub_type = AARCH64_OP_DC;
774
343
        AArch64_get_detail_op(MI, 0)->type =
775
343
          AARCH64_OP_SYSALIAS;
776
343
        AArch64_get_detail_op(MI, 0)->sysop = sysop;
777
343
        AArch64_inc_op_count(MI);
778
343
      }
779
780
343
      NeedsReg = true;
781
343
      Ins = "dc ";
782
343
      Name = DC->Name;
783
343
    } break;
784
    // AT aliases
785
66
    case 8:
786
224
    case 9: {
787
224
      const AArch64AT_AT *AT =
788
224
        AArch64AT_lookupATByEncoding(Encoding);
789
224
      if (!AT || !AArch64_testFeatureList(
790
50
             MI->csh->mode, AT->FeaturesRequired))
791
174
        return false;
792
793
50
      if (detail_is_set(MI)) {
794
50
        aarch64_sysop sysop = { 0 };
795
50
        sysop.alias = AT->SysAlias;
796
50
        sysop.sub_type = AARCH64_OP_AT;
797
50
        AArch64_get_detail_op(MI, 0)->type =
798
50
          AARCH64_OP_SYSALIAS;
799
50
        AArch64_get_detail_op(MI, 0)->sysop = sysop;
800
50
        AArch64_inc_op_count(MI);
801
50
      }
802
50
      NeedsReg = true;
803
50
      Ins = "at ";
804
50
      Name = AT->Name;
805
50
    } break;
806
2.38k
    }
807
2.38k
  } else if (CnVal == 8 || CnVal == 9) {
808
    // TLBI aliases
809
174
    const AArch64TLBI_TLBI *TLBI =
810
174
      AArch64TLBI_lookupTLBIByEncoding(Encoding);
811
174
    if (!TLBI || !AArch64_testFeatureList(MI->csh->mode,
812
53
                  TLBI->FeaturesRequired))
813
121
      return false;
814
815
53
    if (detail_is_set(MI)) {
816
53
      aarch64_sysop sysop = { 0 };
817
53
      sysop.reg = TLBI->SysReg;
818
53
      sysop.sub_type = AARCH64_OP_TLBI;
819
53
      AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
820
53
      AArch64_get_detail_op(MI, 0)->sysop = sysop;
821
53
      AArch64_inc_op_count(MI);
822
53
    }
823
53
    NeedsReg = TLBI->NeedsReg;
824
53
    Ins = "tlbi ";
825
53
    Name = TLBI->Name;
826
53
  } else
827
715
    return false;
828
829
2.16k
#define TMP_STR_LEN 32
830
1.08k
  char Str[TMP_STR_LEN] = { 0 };
831
1.08k
  append_to_str_lower(Str, TMP_STR_LEN, Ins);
832
1.08k
  append_to_str_lower(Str, TMP_STR_LEN, Name);
833
1.08k
#undef TMP_STR_LEN
834
835
1.08k
  SStream_concat1(O, ' ');
836
1.08k
  SStream_concat0(O, Str);
837
1.08k
  if (NeedsReg) {
838
1.01k
    SStream_concat0(O, ", ");
839
1.01k
    printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (4))));
840
1.01k
    AArch64_set_detail_op_reg(MI, 4, MCInst_getOpVal(MI, 4));
841
1.01k
  }
842
843
1.08k
  return true;
844
3.27k
}
845
846
bool printSyspAlias(MCInst *MI, SStream *O)
847
1.48k
{
848
1.48k
  MCOperand *Op1 = MCInst_getOperand(MI, (0));
849
1.48k
  MCOperand *Cn = MCInst_getOperand(MI, (1));
850
1.48k
  MCOperand *Cm = MCInst_getOperand(MI, (2));
851
1.48k
  MCOperand *Op2 = MCInst_getOperand(MI, (3));
852
853
1.48k
  unsigned Op1Val = MCOperand_getImm(Op1);
854
1.48k
  unsigned CnVal = MCOperand_getImm(Cn);
855
1.48k
  unsigned CmVal = MCOperand_getImm(Cm);
856
1.48k
  unsigned Op2Val = MCOperand_getImm(Op2);
857
858
1.48k
  uint16_t Encoding = Op2Val;
859
1.48k
  Encoding |= CmVal << 3;
860
1.48k
  Encoding |= CnVal << 7;
861
1.48k
  Encoding |= Op1Val << 11;
862
863
1.48k
  const char *Ins;
864
1.48k
  const char *Name;
865
866
1.48k
  if (CnVal == 8 || CnVal == 9) {
867
    // TLBIP aliases
868
869
923
    if (CnVal == 9) {
870
76
      if (!AArch64_getFeatureBits(MI->csh->mode,
871
76
                AArch64_FeatureAll) ||
872
76
          !AArch64_getFeatureBits(MI->csh->mode,
873
76
                AArch64_FeatureXS))
874
0
        return false;
875
76
      Encoding &= ~(1 << 7);
876
76
    }
877
878
923
    const AArch64TLBI_TLBI *TLBI =
879
923
      AArch64TLBI_lookupTLBIByEncoding(Encoding);
880
923
    if (!TLBI || !AArch64_testFeatureList(MI->csh->mode,
881
676
                  TLBI->FeaturesRequired))
882
247
      return false;
883
884
676
    if (detail_is_set(MI)) {
885
676
      aarch64_sysop sysop = { 0 };
886
676
      sysop.reg = TLBI->SysReg;
887
676
      sysop.sub_type = AARCH64_OP_TLBI;
888
676
      AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
889
676
      AArch64_get_detail_op(MI, 0)->sysop = sysop;
890
676
      AArch64_inc_op_count(MI);
891
676
    }
892
676
    Ins = "tlbip ";
893
676
    Name = TLBI->Name;
894
676
  } else
895
562
    return false;
896
897
1.42k
#define TMP_STR_LEN 32
898
676
  char Str[TMP_STR_LEN] = { 0 };
899
676
  append_to_str_lower(Str, TMP_STR_LEN, Ins);
900
676
  append_to_str_lower(Str, TMP_STR_LEN, Name);
901
902
676
  if (CnVal == 9) {
903
68
    append_to_str_lower(Str, TMP_STR_LEN, "nxs");
904
68
  }
905
676
#undef TMP_STR_LEN
906
907
676
  SStream_concat1(O, ' ');
908
676
  SStream_concat0(O, Str);
909
676
  SStream_concat0(O, ", ");
910
676
  if (MCOperand_getReg(MCInst_getOperand(MI, (4))) == AArch64_XZR)
911
574
    printSyspXzrPair(MI, 4, O);
912
102
  else
913
102
    CONCAT(printGPRSeqPairsClassOperand, 64)(MI, 4, O);
914
915
676
  return true;
916
1.48k
}
917
918
#define DEFINE_printMatrix(EltSize) \
919
  void CONCAT(printMatrix, EltSize)(MCInst * MI, unsigned OpNum, \
920
            SStream *O) \
921
5.53k
  { \
922
5.53k
    AArch64_add_cs_detail_1( \
923
5.53k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
5.53k
      EltSize); \
925
5.53k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
5.53k
\
927
5.53k
    printRegName(O, MCOperand_getReg(RegOp)); \
928
5.53k
    switch (EltSize) { \
929
781
    case 0: \
930
781
      break; \
931
0
    case 8: \
932
0
      SStream_concat0(O, ".b"); \
933
0
      break; \
934
732
    case 16: \
935
732
      SStream_concat0(O, ".h"); \
936
732
      break; \
937
2.93k
    case 32: \
938
2.93k
      SStream_concat0(O, ".s"); \
939
2.93k
      break; \
940
1.08k
    case 64: \
941
1.08k
      SStream_concat0(O, ".d"); \
942
1.08k
      break; \
943
0
    case 128: \
944
0
      SStream_concat0(O, ".q"); \
945
0
      break; \
946
0
    default: \
947
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
948
5.53k
    } \
949
5.53k
  }
printMatrix_64
Line
Count
Source
921
1.08k
  { \
922
1.08k
    AArch64_add_cs_detail_1( \
923
1.08k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
1.08k
      EltSize); \
925
1.08k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
1.08k
\
927
1.08k
    printRegName(O, MCOperand_getReg(RegOp)); \
928
1.08k
    switch (EltSize) { \
929
0
    case 0: \
930
0
      break; \
931
0
    case 8: \
932
0
      SStream_concat0(O, ".b"); \
933
0
      break; \
934
0
    case 16: \
935
0
      SStream_concat0(O, ".h"); \
936
0
      break; \
937
0
    case 32: \
938
0
      SStream_concat0(O, ".s"); \
939
0
      break; \
940
1.08k
    case 64: \
941
1.08k
      SStream_concat0(O, ".d"); \
942
1.08k
      break; \
943
0
    case 128: \
944
0
      SStream_concat0(O, ".q"); \
945
0
      break; \
946
0
    default: \
947
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
948
1.08k
    } \
949
1.08k
  }
printMatrix_32
Line
Count
Source
921
2.93k
  { \
922
2.93k
    AArch64_add_cs_detail_1( \
923
2.93k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
2.93k
      EltSize); \
925
2.93k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
2.93k
\
927
2.93k
    printRegName(O, MCOperand_getReg(RegOp)); \
928
2.93k
    switch (EltSize) { \
929
0
    case 0: \
930
0
      break; \
931
0
    case 8: \
932
0
      SStream_concat0(O, ".b"); \
933
0
      break; \
934
0
    case 16: \
935
0
      SStream_concat0(O, ".h"); \
936
0
      break; \
937
2.93k
    case 32: \
938
2.93k
      SStream_concat0(O, ".s"); \
939
2.93k
      break; \
940
0
    case 64: \
941
0
      SStream_concat0(O, ".d"); \
942
0
      break; \
943
0
    case 128: \
944
0
      SStream_concat0(O, ".q"); \
945
0
      break; \
946
0
    default: \
947
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
948
2.93k
    } \
949
2.93k
  }
printMatrix_16
Line
Count
Source
921
732
  { \
922
732
    AArch64_add_cs_detail_1( \
923
732
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
732
      EltSize); \
925
732
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
732
\
927
732
    printRegName(O, MCOperand_getReg(RegOp)); \
928
732
    switch (EltSize) { \
929
0
    case 0: \
930
0
      break; \
931
0
    case 8: \
932
0
      SStream_concat0(O, ".b"); \
933
0
      break; \
934
732
    case 16: \
935
732
      SStream_concat0(O, ".h"); \
936
732
      break; \
937
0
    case 32: \
938
0
      SStream_concat0(O, ".s"); \
939
0
      break; \
940
0
    case 64: \
941
0
      SStream_concat0(O, ".d"); \
942
0
      break; \
943
0
    case 128: \
944
0
      SStream_concat0(O, ".q"); \
945
0
      break; \
946
0
    default: \
947
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
948
732
    } \
949
732
  }
printMatrix_0
Line
Count
Source
921
781
  { \
922
781
    AArch64_add_cs_detail_1( \
923
781
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
781
      EltSize); \
925
781
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
781
\
927
781
    printRegName(O, MCOperand_getReg(RegOp)); \
928
781
    switch (EltSize) { \
929
781
    case 0: \
930
781
      break; \
931
0
    case 8: \
932
0
      SStream_concat0(O, ".b"); \
933
0
      break; \
934
0
    case 16: \
935
0
      SStream_concat0(O, ".h"); \
936
0
      break; \
937
0
    case 32: \
938
0
      SStream_concat0(O, ".s"); \
939
0
      break; \
940
0
    case 64: \
941
0
      SStream_concat0(O, ".d"); \
942
0
      break; \
943
0
    case 128: \
944
0
      SStream_concat0(O, ".q"); \
945
0
      break; \
946
0
    default: \
947
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
948
781
    } \
949
781
  }
950
DEFINE_printMatrix(64);
951
DEFINE_printMatrix(32);
952
DEFINE_printMatrix(16);
953
DEFINE_printMatrix(0);
954
955
#define DEFINE_printMatrixTileVector(IsVertical) \
956
  void CONCAT(printMatrixTileVector, \
957
        IsVertical)(MCInst * MI, unsigned OpNum, SStream *O) \
958
4.76k
  { \
959
4.76k
    AArch64_add_cs_detail_1( \
960
4.76k
      MI, \
961
4.76k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
962
4.76k
      OpNum, IsVertical); \
963
4.76k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
964
4.76k
\
965
4.76k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
966
4.76k
                  AArch64_NoRegAltName); \
967
4.76k
\
968
4.76k
    /* Diet builds have no register-name table; skip printing. */ \
969
4.76k
    if (!RegName) \
970
4.76k
      return; \
971
4.76k
\
972
4.76k
    unsigned buf_len = strlen(RegName) + 1; \
973
4.76k
    char *Base = cs_mem_calloc(1, buf_len); \
974
4.76k
    memcpy(Base, RegName, buf_len); \
975
4.76k
    char *Dot = strchr(Base, '.'); \
976
4.76k
    if (!Dot) { \
977
0
      SStream_concat0(O, RegName); \
978
0
      return; \
979
0
    } \
980
4.76k
    *Dot = '\0'; /* Split string */ \
981
4.76k
    char *Suffix = Dot + 1; \
982
4.76k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
983
4.76k
    SStream_concat1(O, '.'); \
984
4.76k
    SStream_concat0(O, Suffix); \
985
4.76k
    cs_mem_free(Base); \
986
4.76k
  }
printMatrixTileVector_0
Line
Count
Source
958
2.50k
  { \
959
2.50k
    AArch64_add_cs_detail_1( \
960
2.50k
      MI, \
961
2.50k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
962
2.50k
      OpNum, IsVertical); \
963
2.50k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
964
2.50k
\
965
2.50k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
966
2.50k
                  AArch64_NoRegAltName); \
967
2.50k
\
968
2.50k
    /* Diet builds have no register-name table; skip printing. */ \
969
2.50k
    if (!RegName) \
970
2.50k
      return; \
971
2.50k
\
972
2.50k
    unsigned buf_len = strlen(RegName) + 1; \
973
2.50k
    char *Base = cs_mem_calloc(1, buf_len); \
974
2.50k
    memcpy(Base, RegName, buf_len); \
975
2.50k
    char *Dot = strchr(Base, '.'); \
976
2.50k
    if (!Dot) { \
977
0
      SStream_concat0(O, RegName); \
978
0
      return; \
979
0
    } \
980
2.50k
    *Dot = '\0'; /* Split string */ \
981
2.50k
    char *Suffix = Dot + 1; \
982
2.50k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
983
2.50k
    SStream_concat1(O, '.'); \
984
2.50k
    SStream_concat0(O, Suffix); \
985
2.50k
    cs_mem_free(Base); \
986
2.50k
  }
printMatrixTileVector_1
Line
Count
Source
958
2.25k
  { \
959
2.25k
    AArch64_add_cs_detail_1( \
960
2.25k
      MI, \
961
2.25k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
962
2.25k
      OpNum, IsVertical); \
963
2.25k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
964
2.25k
\
965
2.25k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
966
2.25k
                  AArch64_NoRegAltName); \
967
2.25k
\
968
2.25k
    /* Diet builds have no register-name table; skip printing. */ \
969
2.25k
    if (!RegName) \
970
2.25k
      return; \
971
2.25k
\
972
2.25k
    unsigned buf_len = strlen(RegName) + 1; \
973
2.25k
    char *Base = cs_mem_calloc(1, buf_len); \
974
2.25k
    memcpy(Base, RegName, buf_len); \
975
2.25k
    char *Dot = strchr(Base, '.'); \
976
2.25k
    if (!Dot) { \
977
0
      SStream_concat0(O, RegName); \
978
0
      return; \
979
0
    } \
980
2.25k
    *Dot = '\0'; /* Split string */ \
981
2.25k
    char *Suffix = Dot + 1; \
982
2.25k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
983
2.25k
    SStream_concat1(O, '.'); \
984
2.25k
    SStream_concat0(O, Suffix); \
985
2.25k
    cs_mem_free(Base); \
986
2.25k
  }
987
DEFINE_printMatrixTileVector(0);
988
DEFINE_printMatrixTileVector(1);
989
990
void printMatrixTile(MCInst *MI, unsigned OpNum, SStream *O)
991
1.86k
{
992
1.86k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MatrixTile, OpNum);
993
1.86k
  MCOperand *RegOp = MCInst_getOperand(MI, (OpNum));
994
995
1.86k
  printRegName(O, MCOperand_getReg(RegOp));
996
1.86k
}
997
998
void printSVCROp(MCInst *MI, unsigned OpNum, SStream *O)
999
0
{
1000
0
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SVCROp, OpNum);
1001
0
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1002
1003
0
  unsigned svcrop = MCOperand_getImm(MO);
1004
0
  const AArch64SVCR_SVCR *SVCR = AArch64SVCR_lookupSVCRByEncoding(svcrop);
1005
1006
0
  SStream_concat0(O, SVCR->Name);
1007
0
}
1008
1009
void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
1010
328k
{
1011
328k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Operand, OpNo);
1012
328k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1013
328k
  if (MCOperand_isReg(Op)) {
1014
282k
    unsigned Reg = MCOperand_getReg(Op);
1015
282k
    printRegName(O, Reg);
1016
282k
  } else if (MCOperand_isImm(Op)) {
1017
46.1k
    Op = MCInst_getOperand(MI, (OpNo));
1018
46.1k
    SStream_concat(O, "%s", markup("<imm:"));
1019
46.1k
    printInt64Bang(O, MCOperand_getImm(Op));
1020
46.1k
    SStream_concat0(O, markup(">"));
1021
46.1k
  } else {
1022
0
    printUInt64Bang(O, MCInst_getOpVal(MI, OpNo));
1023
0
  }
1024
328k
}
1025
1026
void printImm(MCInst *MI, unsigned OpNo, SStream *O)
1027
4.37k
{
1028
4.37k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Imm, OpNo);
1029
4.37k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1030
4.37k
  SStream_concat(O, "%s", markup("<imm:"));
1031
4.37k
  printInt64Bang(O, MCOperand_getImm(Op));
1032
4.37k
  SStream_concat0(O, markup(">"));
1033
4.37k
}
1034
1035
void printImmHex(MCInst *MI, unsigned OpNo, SStream *O)
1036
113
{
1037
113
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ImmHex, OpNo);
1038
113
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1039
113
  SStream_concat(O, "%s", markup("<imm:"));
1040
113
  printInt64Bang(O, MCOperand_getImm(Op));
1041
113
  SStream_concat0(O, markup(">"));
1042
113
}
1043
1044
#define DEFINE_printSImm(Size) \
1045
  void CONCAT(printSImm, Size)(MCInst * MI, unsigned OpNo, SStream *O) \
1046
1.16k
  { \
1047
1.16k
    AArch64_add_cs_detail_1( \
1048
1.16k
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1049
1.16k
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1050
1.16k
    if (Size == 8) { \
1051
639
      SStream_concat(O, "%s", markup("<imm:")); \
1052
639
      printInt32Bang(O, MCOperand_getImm(Op)); \
1053
639
      SStream_concat0(O, markup(">")); \
1054
639
    } else if (Size == 16) { \
1055
523
      SStream_concat(O, "%s", markup("<imm:")); \
1056
523
      printInt32Bang(O, MCOperand_getImm(Op)); \
1057
523
      SStream_concat0(O, markup(">")); \
1058
523
    } else { \
1059
0
      SStream_concat(O, "%s", markup("<imm:")); \
1060
0
      printInt64Bang(O, MCOperand_getImm(Op)); \
1061
0
      SStream_concat0(O, markup(">")); \
1062
0
    } \
1063
1.16k
  }
printSImm_16
Line
Count
Source
1046
523
  { \
1047
523
    AArch64_add_cs_detail_1( \
1048
523
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1049
523
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1050
523
    if (Size == 8) { \
1051
0
      SStream_concat(O, "%s", markup("<imm:")); \
1052
0
      printInt32Bang(O, MCOperand_getImm(Op)); \
1053
0
      SStream_concat0(O, markup(">")); \
1054
523
    } else if (Size == 16) { \
1055
523
      SStream_concat(O, "%s", markup("<imm:")); \
1056
523
      printInt32Bang(O, MCOperand_getImm(Op)); \
1057
523
      SStream_concat0(O, markup(">")); \
1058
523
    } else { \
1059
0
      SStream_concat(O, "%s", markup("<imm:")); \
1060
0
      printInt64Bang(O, MCOperand_getImm(Op)); \
1061
0
      SStream_concat0(O, markup(">")); \
1062
0
    } \
1063
523
  }
printSImm_8
Line
Count
Source
1046
639
  { \
1047
639
    AArch64_add_cs_detail_1( \
1048
639
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1049
639
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1050
639
    if (Size == 8) { \
1051
639
      SStream_concat(O, "%s", markup("<imm:")); \
1052
639
      printInt32Bang(O, MCOperand_getImm(Op)); \
1053
639
      SStream_concat0(O, markup(">")); \
1054
639
    } else if (Size == 16) { \
1055
0
      SStream_concat(O, "%s", markup("<imm:")); \
1056
0
      printInt32Bang(O, MCOperand_getImm(Op)); \
1057
0
      SStream_concat0(O, markup(">")); \
1058
0
    } else { \
1059
0
      SStream_concat(O, "%s", markup("<imm:")); \
1060
0
      printInt64Bang(O, MCOperand_getImm(Op)); \
1061
0
      SStream_concat0(O, markup(">")); \
1062
0
    } \
1063
639
  }
1064
DEFINE_printSImm(16);
1065
DEFINE_printSImm(8);
1066
1067
void printPostIncOperand(MCInst *MI, unsigned OpNo, unsigned Imm, SStream *O)
1068
7.73k
{
1069
7.73k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1070
7.73k
  if (MCOperand_isReg(Op)) {
1071
7.73k
    unsigned Reg = MCOperand_getReg(Op);
1072
7.73k
    if (Reg == AArch64_XZR) {
1073
0
      SStream_concat(O, "%s", markup("<imm:"));
1074
0
      printUInt64Bang(O, Imm);
1075
0
      SStream_concat0(O, markup(">"));
1076
0
    } else
1077
7.73k
      printRegName(O, Reg);
1078
7.73k
  } else
1079
0
    CS_ASSERT_RET(0 &&
1080
7.73k
            "unknown operand kind in printPostIncOperand64");
1081
7.73k
}
1082
1083
void printVRegOperand(MCInst *MI, unsigned OpNo, SStream *O)
1084
61.8k
{
1085
61.8k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_VRegOperand, OpNo);
1086
61.8k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1087
1088
61.8k
  unsigned Reg = MCOperand_getReg(Op);
1089
61.8k
  printRegNameAlt(O, Reg, AArch64_vreg);
1090
61.8k
}
1091
1092
void printSysCROperand(MCInst *MI, unsigned OpNo, SStream *O)
1093
6.10k
{
1094
6.10k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SysCROperand, OpNo);
1095
6.10k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1096
1097
6.10k
  SStream_concat(O, "%s", "c");
1098
6.10k
  printUInt32(O, MCOperand_getImm(Op));
1099
6.10k
  SStream_concat1(O, '\0');
1100
6.10k
}
1101
1102
void printAddSubImm(MCInst *MI, unsigned OpNum, SStream *O)
1103
2.97k
{
1104
2.97k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AddSubImm, OpNum);
1105
2.97k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1106
2.97k
  if (MCOperand_isImm(MO)) {
1107
2.97k
    unsigned Val = (MCOperand_getImm(MO) & 0xfff);
1108
1109
2.97k
    unsigned Shift = AArch64_AM_getShiftValue(
1110
2.97k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))));
1111
2.97k
    SStream_concat(O, "%s", markup("<imm:"));
1112
2.97k
    printUInt32Bang(O, (Val));
1113
2.97k
    SStream_concat0(O, markup(">"));
1114
2.97k
    if (Shift != 0) {
1115
560
      printShifter(MI, OpNum + 1, O);
1116
560
    }
1117
2.97k
  } else {
1118
0
    printShifter(MI, OpNum + 1, O);
1119
0
  }
1120
2.97k
}
1121
1122
#define DEFINE_printLogicalImm(T) \
1123
  void CONCAT(printLogicalImm, T)(MCInst * MI, unsigned OpNum, \
1124
          SStream *O) \
1125
5.89k
  { \
1126
5.89k
    AArch64_add_cs_detail_1( \
1127
5.89k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
5.89k
      sizeof(T)); \
1129
5.89k
    uint64_t Val = \
1130
5.89k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
5.89k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
5.89k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
5.89k
             Val, 8 * sizeof(T)))); \
1134
5.89k
    SStream_concat0(O, markup(">")); \
1135
5.89k
  }
printLogicalImm_int64_t
Line
Count
Source
1125
2.20k
  { \
1126
2.20k
    AArch64_add_cs_detail_1( \
1127
2.20k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
2.20k
      sizeof(T)); \
1129
2.20k
    uint64_t Val = \
1130
2.20k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
2.20k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
2.20k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
2.20k
             Val, 8 * sizeof(T)))); \
1134
2.20k
    SStream_concat0(O, markup(">")); \
1135
2.20k
  }
printLogicalImm_int32_t
Line
Count
Source
1125
1.37k
  { \
1126
1.37k
    AArch64_add_cs_detail_1( \
1127
1.37k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
1.37k
      sizeof(T)); \
1129
1.37k
    uint64_t Val = \
1130
1.37k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
1.37k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
1.37k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
1.37k
             Val, 8 * sizeof(T)))); \
1134
1.37k
    SStream_concat0(O, markup(">")); \
1135
1.37k
  }
printLogicalImm_int8_t
Line
Count
Source
1125
1.32k
  { \
1126
1.32k
    AArch64_add_cs_detail_1( \
1127
1.32k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
1.32k
      sizeof(T)); \
1129
1.32k
    uint64_t Val = \
1130
1.32k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
1.32k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
1.32k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
1.32k
             Val, 8 * sizeof(T)))); \
1134
1.32k
    SStream_concat0(O, markup(">")); \
1135
1.32k
  }
printLogicalImm_int16_t
Line
Count
Source
1125
998
  { \
1126
998
    AArch64_add_cs_detail_1( \
1127
998
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
998
      sizeof(T)); \
1129
998
    uint64_t Val = \
1130
998
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
998
    SStream_concat(O, "%s", markup("<imm:")); \
1132
998
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
998
             Val, 8 * sizeof(T)))); \
1134
998
    SStream_concat0(O, markup(">")); \
1135
998
  }
1136
DEFINE_printLogicalImm(int64_t);
1137
DEFINE_printLogicalImm(int32_t);
1138
DEFINE_printLogicalImm(int8_t);
1139
DEFINE_printLogicalImm(int16_t);
1140
1141
void printShifter(MCInst *MI, unsigned OpNum, SStream *O)
1142
8.62k
{
1143
8.62k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Shifter, OpNum);
1144
8.62k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1145
  // LSL #0 should not be printed.
1146
8.62k
  if (AArch64_AM_getShiftType(Val) == AArch64_AM_LSL &&
1147
4.55k
      AArch64_AM_getShiftValue(Val) == 0)
1148
320
    return;
1149
8.30k
  SStream_concat(
1150
8.30k
    O, "%s%s%s%s#%u", ", ",
1151
8.30k
    AArch64_AM_getShiftExtendName(AArch64_AM_getShiftType(Val)),
1152
8.30k
    " ", markup("<imm:"), AArch64_AM_getShiftValue(Val));
1153
8.30k
  SStream_concat0(O, markup(">"));
1154
8.30k
}
1155
1156
void printShiftedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1157
5.05k
{
1158
5.05k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ShiftedRegister, OpNum);
1159
5.05k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1160
5.05k
  printShifter(MI, OpNum + 1, O);
1161
5.05k
}
1162
1163
void printExtendedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1164
1.48k
{
1165
1.48k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ExtendedRegister, OpNum);
1166
1.48k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1167
1.48k
  printArithExtend(MI, OpNum + 1, O);
1168
1.48k
}
1169
1170
void printArithExtend(MCInst *MI, unsigned OpNum, SStream *O)
1171
2.52k
{
1172
2.52k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ArithExtend, OpNum);
1173
2.52k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1174
2.52k
  AArch64_AM_ShiftExtendType ExtType = AArch64_AM_getArithExtendType(Val);
1175
2.52k
  unsigned ShiftVal = AArch64_AM_getArithShiftValue(Val);
1176
1177
  // If the destination or first source register operand is [W]SP, print
1178
  // UXTW/UXTX as LSL, and if the shift amount is also zero, print nothing at
1179
  // all.
1180
2.52k
  if (ExtType == AArch64_AM_UXTW || ExtType == AArch64_AM_UXTX) {
1181
1.44k
    unsigned Dest = MCOperand_getReg(MCInst_getOperand(MI, (0)));
1182
1.44k
    unsigned Src1 = MCOperand_getReg(MCInst_getOperand(MI, (1)));
1183
1.44k
    if (((Dest == AArch64_SP || Src1 == AArch64_SP) &&
1184
447
         ExtType == AArch64_AM_UXTX) ||
1185
1.03k
        ((Dest == AArch64_WSP || Src1 == AArch64_WSP) &&
1186
562
         ExtType == AArch64_AM_UXTW)) {
1187
562
      if (ShiftVal != 0) {
1188
562
        SStream_concat(O, "%s%s", ", lsl ",
1189
562
                 markup("<imm:"));
1190
562
        printUInt32Bang(O, ShiftVal);
1191
562
        SStream_concat0(O, markup(">"));
1192
562
      }
1193
562
      return;
1194
562
    }
1195
1.44k
  }
1196
1.96k
  SStream_concat(O, "%s", ", ");
1197
1.96k
  SStream_concat0(O, AArch64_AM_getShiftExtendName(ExtType));
1198
1.96k
  if (ShiftVal != 0) {
1199
1.70k
    SStream_concat(O, "%s%s#%d", " ", markup("<imm:"), ShiftVal);
1200
1.70k
    SStream_concat0(O, markup(">"));
1201
1.70k
  }
1202
1.96k
}
1203
1204
static void printMemExtendImpl(bool SignExtend, bool DoShift, unsigned Width,
1205
             char SrcRegKind, SStream *O, bool getUseMarkup)
1206
12.5k
{
1207
  // sxtw, sxtx, uxtw or lsl (== uxtx)
1208
12.5k
  bool IsLSL = !SignExtend && SrcRegKind == 'x';
1209
12.5k
  if (IsLSL)
1210
5.13k
    SStream_concat0(O, "lsl");
1211
7.41k
  else {
1212
7.41k
    SStream_concat(O, "%c%s", (SignExtend ? 's' : 'u'), "xt");
1213
7.41k
    SStream_concat1(O, SrcRegKind);
1214
7.41k
  }
1215
1216
12.5k
  if (DoShift || IsLSL) {
1217
9.93k
    SStream_concat0(O, " ");
1218
9.93k
    if (getUseMarkup)
1219
0
      SStream_concat0(O, "<imm:");
1220
9.93k
    unsigned ShiftAmount = DoShift ? Log2_32(Width / 8) : 0;
1221
9.93k
    SStream_concat(O, "%s%u", "#", ShiftAmount);
1222
9.93k
    if (getUseMarkup)
1223
0
      SStream_concat0(O, ">");
1224
9.93k
  }
1225
12.5k
}
1226
1227
void printMemExtend(MCInst *MI, unsigned OpNum, SStream *O, char SrcRegKind,
1228
        unsigned Width)
1229
2.39k
{
1230
2.39k
  bool SignExtend = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1231
2.39k
  bool DoShift = MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1)));
1232
2.39k
  printMemExtendImpl(SignExtend, DoShift, Width, SrcRegKind, O,
1233
2.39k
         getUseMarkup());
1234
2.39k
}
1235
1236
#define DEFINE_printRegWithShiftExtend(SignExtend, ExtWidth, SrcRegKind, \
1237
               Suffix) \
1238
  void CONCAT(printRegWithShiftExtend, \
1239
        CONCAT(SignExtend, \
1240
         CONCAT(ExtWidth, CONCAT(SrcRegKind, Suffix))))( \
1241
    MCInst * MI, unsigned OpNum, SStream *O) \
1242
13.0k
  { \
1243
13.0k
    AArch64_add_cs_detail_4( \
1244
13.0k
      MI, \
1245
13.0k
      CONCAT(CONCAT(CONCAT(CONCAT(AArch64_OP_GROUP_RegWithShiftExtend, \
1246
13.0k
                SignExtend), \
1247
13.0k
               ExtWidth), \
1248
13.0k
              SrcRegKind), \
1249
13.0k
             Suffix), \
1250
13.0k
      OpNum, SignExtend, ExtWidth, CHAR(SrcRegKind), \
1251
13.0k
      CHAR(Suffix)); \
1252
13.0k
    printOperand(MI, OpNum, O); \
1253
13.0k
    if (CHAR(Suffix) == 's' || CHAR(Suffix) == 'd') { \
1254
8.04k
      SStream_concat1(O, '.'); \
1255
8.04k
      SStream_concat1(O, CHAR(Suffix)); \
1256
8.04k
      SStream_concat1(O, '\0'); \
1257
8.04k
    } else \
1258
13.0k
      CS_ASSERT_RET((CHAR(Suffix) == '0') && \
1259
13.0k
              "Unsupported suffix size"); \
1260
13.0k
    bool DoShift = ExtWidth != 8; \
1261
13.0k
    if (SignExtend || DoShift || CHAR(SrcRegKind) == 'w') { \
1262
10.1k
      SStream_concat0(O, ", "); \
1263
10.1k
      printMemExtendImpl(SignExtend, DoShift, ExtWidth, \
1264
10.1k
             CHAR(SrcRegKind), O, \
1265
10.1k
             getUseMarkup()); \
1266
10.1k
    } \
1267
13.0k
  }
1268
1.21k
DEFINE_printRegWithShiftExtend(false, 8, x, d);
1269
762
DEFINE_printRegWithShiftExtend(true, 8, w, d);
1270
468
DEFINE_printRegWithShiftExtend(false, 8, w, d);
1271
1.67k
DEFINE_printRegWithShiftExtend(false, 8, x, 0);
1272
501
DEFINE_printRegWithShiftExtend(true, 8, w, s);
1273
147
DEFINE_printRegWithShiftExtend(false, 8, w, s);
1274
595
DEFINE_printRegWithShiftExtend(false, 64, x, d);
1275
484
DEFINE_printRegWithShiftExtend(true, 64, w, d);
1276
492
DEFINE_printRegWithShiftExtend(false, 64, w, d);
1277
662
DEFINE_printRegWithShiftExtend(false, 64, x, 0);
1278
260
DEFINE_printRegWithShiftExtend(true, 64, w, s);
1279
18
DEFINE_printRegWithShiftExtend(false, 64, w, s);
1280
154
DEFINE_printRegWithShiftExtend(false, 16, x, d);
1281
556
DEFINE_printRegWithShiftExtend(true, 16, w, d);
1282
505
DEFINE_printRegWithShiftExtend(false, 16, w, d);
1283
1.32k
DEFINE_printRegWithShiftExtend(false, 16, x, 0);
1284
66
DEFINE_printRegWithShiftExtend(true, 16, w, s);
1285
120
DEFINE_printRegWithShiftExtend(false, 16, w, s);
1286
288
DEFINE_printRegWithShiftExtend(false, 32, x, d);
1287
318
DEFINE_printRegWithShiftExtend(true, 32, w, d);
1288
668
DEFINE_printRegWithShiftExtend(false, 32, w, d);
1289
1.00k
DEFINE_printRegWithShiftExtend(false, 32, x, 0);
1290
214
DEFINE_printRegWithShiftExtend(true, 32, w, s);
1291
144
DEFINE_printRegWithShiftExtend(false, 32, w, s);
1292
14
DEFINE_printRegWithShiftExtend(false, 8, x, s);
1293
11
DEFINE_printRegWithShiftExtend(false, 16, x, s);
1294
19
DEFINE_printRegWithShiftExtend(false, 32, x, s);
1295
27
DEFINE_printRegWithShiftExtend(false, 64, x, s);
1296
360
DEFINE_printRegWithShiftExtend(false, 128, x, 0);
1297
1298
#define DEFINE_printPredicateAsCounter(EltSize) \
1299
  void CONCAT(printPredicateAsCounter, \
1300
        EltSize)(MCInst * MI, unsigned OpNum, SStream *O) \
1301
5.83k
  { \
1302
5.83k
    AArch64_add_cs_detail_1( \
1303
5.83k
      MI, \
1304
5.83k
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
5.83k
      OpNum, EltSize); \
1306
5.83k
    unsigned Reg = \
1307
5.83k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
5.83k
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
5.83k
      CS_ASSERT_RET( \
1310
5.83k
        0 && \
1311
5.83k
        "Unsupported predicate-as-counter register"); \
1312
5.83k
    SStream_concat(O, "%s", "pn"); \
1313
5.83k
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
5.83k
    switch (EltSize) { \
1315
4.87k
    case 0: \
1316
4.87k
      break; \
1317
61
    case 8: \
1318
61
      SStream_concat0(O, ".b"); \
1319
61
      break; \
1320
144
    case 16: \
1321
144
      SStream_concat0(O, ".h"); \
1322
144
      break; \
1323
126
    case 32: \
1324
126
      SStream_concat0(O, ".s"); \
1325
126
      break; \
1326
625
    case 64: \
1327
625
      SStream_concat0(O, ".d"); \
1328
625
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
5.83k
    } \
1332
5.83k
  }
printPredicateAsCounter_8
Line
Count
Source
1301
61
  { \
1302
61
    AArch64_add_cs_detail_1( \
1303
61
      MI, \
1304
61
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
61
      OpNum, EltSize); \
1306
61
    unsigned Reg = \
1307
61
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
61
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
61
      CS_ASSERT_RET( \
1310
61
        0 && \
1311
61
        "Unsupported predicate-as-counter register"); \
1312
61
    SStream_concat(O, "%s", "pn"); \
1313
61
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
61
    switch (EltSize) { \
1315
0
    case 0: \
1316
0
      break; \
1317
61
    case 8: \
1318
61
      SStream_concat0(O, ".b"); \
1319
61
      break; \
1320
0
    case 16: \
1321
0
      SStream_concat0(O, ".h"); \
1322
0
      break; \
1323
0
    case 32: \
1324
0
      SStream_concat0(O, ".s"); \
1325
0
      break; \
1326
0
    case 64: \
1327
0
      SStream_concat0(O, ".d"); \
1328
0
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
61
    } \
1332
61
  }
printPredicateAsCounter_64
Line
Count
Source
1301
625
  { \
1302
625
    AArch64_add_cs_detail_1( \
1303
625
      MI, \
1304
625
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
625
      OpNum, EltSize); \
1306
625
    unsigned Reg = \
1307
625
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
625
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
625
      CS_ASSERT_RET( \
1310
625
        0 && \
1311
625
        "Unsupported predicate-as-counter register"); \
1312
625
    SStream_concat(O, "%s", "pn"); \
1313
625
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
625
    switch (EltSize) { \
1315
0
    case 0: \
1316
0
      break; \
1317
0
    case 8: \
1318
0
      SStream_concat0(O, ".b"); \
1319
0
      break; \
1320
0
    case 16: \
1321
0
      SStream_concat0(O, ".h"); \
1322
0
      break; \
1323
0
    case 32: \
1324
0
      SStream_concat0(O, ".s"); \
1325
0
      break; \
1326
625
    case 64: \
1327
625
      SStream_concat0(O, ".d"); \
1328
625
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
625
    } \
1332
625
  }
printPredicateAsCounter_16
Line
Count
Source
1301
144
  { \
1302
144
    AArch64_add_cs_detail_1( \
1303
144
      MI, \
1304
144
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
144
      OpNum, EltSize); \
1306
144
    unsigned Reg = \
1307
144
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
144
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
144
      CS_ASSERT_RET( \
1310
144
        0 && \
1311
144
        "Unsupported predicate-as-counter register"); \
1312
144
    SStream_concat(O, "%s", "pn"); \
1313
144
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
144
    switch (EltSize) { \
1315
0
    case 0: \
1316
0
      break; \
1317
0
    case 8: \
1318
0
      SStream_concat0(O, ".b"); \
1319
0
      break; \
1320
144
    case 16: \
1321
144
      SStream_concat0(O, ".h"); \
1322
144
      break; \
1323
0
    case 32: \
1324
0
      SStream_concat0(O, ".s"); \
1325
0
      break; \
1326
0
    case 64: \
1327
0
      SStream_concat0(O, ".d"); \
1328
0
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
144
    } \
1332
144
  }
printPredicateAsCounter_32
Line
Count
Source
1301
126
  { \
1302
126
    AArch64_add_cs_detail_1( \
1303
126
      MI, \
1304
126
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
126
      OpNum, EltSize); \
1306
126
    unsigned Reg = \
1307
126
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
126
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
126
      CS_ASSERT_RET( \
1310
126
        0 && \
1311
126
        "Unsupported predicate-as-counter register"); \
1312
126
    SStream_concat(O, "%s", "pn"); \
1313
126
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
126
    switch (EltSize) { \
1315
0
    case 0: \
1316
0
      break; \
1317
0
    case 8: \
1318
0
      SStream_concat0(O, ".b"); \
1319
0
      break; \
1320
0
    case 16: \
1321
0
      SStream_concat0(O, ".h"); \
1322
0
      break; \
1323
126
    case 32: \
1324
126
      SStream_concat0(O, ".s"); \
1325
126
      break; \
1326
0
    case 64: \
1327
0
      SStream_concat0(O, ".d"); \
1328
0
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
126
    } \
1332
126
  }
printPredicateAsCounter_0
Line
Count
Source
1301
4.87k
  { \
1302
4.87k
    AArch64_add_cs_detail_1( \
1303
4.87k
      MI, \
1304
4.87k
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
4.87k
      OpNum, EltSize); \
1306
4.87k
    unsigned Reg = \
1307
4.87k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
4.87k
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
4.87k
      CS_ASSERT_RET( \
1310
4.87k
        0 && \
1311
4.87k
        "Unsupported predicate-as-counter register"); \
1312
4.87k
    SStream_concat(O, "%s", "pn"); \
1313
4.87k
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
4.87k
    switch (EltSize) { \
1315
4.87k
    case 0: \
1316
4.87k
      break; \
1317
0
    case 8: \
1318
0
      SStream_concat0(O, ".b"); \
1319
0
      break; \
1320
0
    case 16: \
1321
0
      SStream_concat0(O, ".h"); \
1322
0
      break; \
1323
0
    case 32: \
1324
0
      SStream_concat0(O, ".s"); \
1325
0
      break; \
1326
0
    case 64: \
1327
0
      SStream_concat0(O, ".d"); \
1328
0
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
4.87k
    } \
1332
4.87k
  }
1333
DEFINE_printPredicateAsCounter(8);
1334
DEFINE_printPredicateAsCounter(64);
1335
DEFINE_printPredicateAsCounter(16);
1336
DEFINE_printPredicateAsCounter(32);
1337
DEFINE_printPredicateAsCounter(0);
1338
1339
void printCondCode(MCInst *MI, unsigned OpNum, SStream *O)
1340
2.57k
{
1341
2.57k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_CondCode, OpNum);
1342
2.57k
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(
1343
2.57k
    MCInst_getOperand(MI, (OpNum)));
1344
2.57k
  SStream_concat0(O, AArch64CC_getCondCodeName(CC));
1345
2.57k
}
1346
1347
void printInverseCondCode(MCInst *MI, unsigned OpNum, SStream *O)
1348
179
{
1349
179
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_InverseCondCode, OpNum);
1350
179
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(
1351
179
    MCInst_getOperand(MI, (OpNum)));
1352
179
  SStream_concat0(O, AArch64CC_getCondCodeName(
1353
179
           AArch64CC_getInvertedCondCode(CC)));
1354
179
}
1355
1356
void printAMNoIndex(MCInst *MI, unsigned OpNum, SStream *O)
1357
0
{
1358
0
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AMNoIndex, OpNum);
1359
0
  SStream_concat0(O, "[");
1360
1361
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1362
0
  SStream_concat0(O, "]");
1363
0
}
1364
1365
#define DEFINE_printImmScale(Scale) \
1366
  void CONCAT(printImmScale, Scale)(MCInst * MI, unsigned OpNum, \
1367
            SStream *O) \
1368
17.4k
  { \
1369
17.4k
    AArch64_add_cs_detail_1( \
1370
17.4k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
17.4k
      Scale); \
1372
17.4k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
17.4k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
17.4k
              MI, (OpNum)))); \
1375
17.4k
    SStream_concat0(O, markup(">")); \
1376
17.4k
  }
printImmScale_8
Line
Count
Source
1368
5.25k
  { \
1369
5.25k
    AArch64_add_cs_detail_1( \
1370
5.25k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
5.25k
      Scale); \
1372
5.25k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
5.25k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
5.25k
              MI, (OpNum)))); \
1375
5.25k
    SStream_concat0(O, markup(">")); \
1376
5.25k
  }
printImmScale_2
Line
Count
Source
1368
968
  { \
1369
968
    AArch64_add_cs_detail_1( \
1370
968
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
968
      Scale); \
1372
968
    SStream_concat(O, "%s", markup("<imm:")); \
1373
968
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
968
              MI, (OpNum)))); \
1375
968
    SStream_concat0(O, markup(">")); \
1376
968
  }
printImmScale_4
Line
Count
Source
1368
7.79k
  { \
1369
7.79k
    AArch64_add_cs_detail_1( \
1370
7.79k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
7.79k
      Scale); \
1372
7.79k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
7.79k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
7.79k
              MI, (OpNum)))); \
1375
7.79k
    SStream_concat0(O, markup(">")); \
1376
7.79k
  }
printImmScale_16
Line
Count
Source
1368
3.03k
  { \
1369
3.03k
    AArch64_add_cs_detail_1( \
1370
3.03k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
3.03k
      Scale); \
1372
3.03k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
3.03k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
3.03k
              MI, (OpNum)))); \
1375
3.03k
    SStream_concat0(O, markup(">")); \
1376
3.03k
  }
printImmScale_32
Line
Count
Source
1368
26
  { \
1369
26
    AArch64_add_cs_detail_1( \
1370
26
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
26
      Scale); \
1372
26
    SStream_concat(O, "%s", markup("<imm:")); \
1373
26
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
26
              MI, (OpNum)))); \
1375
26
    SStream_concat0(O, markup(">")); \
1376
26
  }
printImmScale_3
Line
Count
Source
1368
329
  { \
1369
329
    AArch64_add_cs_detail_1( \
1370
329
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
329
      Scale); \
1372
329
    SStream_concat(O, "%s", markup("<imm:")); \
1373
329
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
329
              MI, (OpNum)))); \
1375
329
    SStream_concat0(O, markup(">")); \
1376
329
  }
1377
DEFINE_printImmScale(8);
1378
DEFINE_printImmScale(2);
1379
DEFINE_printImmScale(4);
1380
DEFINE_printImmScale(16);
1381
DEFINE_printImmScale(32);
1382
DEFINE_printImmScale(3);
1383
1384
#define DEFINE_printImmRangeScale(Scale, Offset) \
1385
  void CONCAT(printImmRangeScale, CONCAT(Scale, Offset))( \
1386
    MCInst * MI, unsigned OpNum, SStream *O) \
1387
4.39k
  { \
1388
4.39k
    AArch64_add_cs_detail_2( \
1389
4.39k
      MI, \
1390
4.39k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1391
4.39k
             Offset), \
1392
4.39k
      OpNum, Scale, Offset); \
1393
4.39k
    unsigned FirstImm = \
1394
4.39k
      Scale * \
1395
4.39k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1396
4.39k
    printUInt32(O, (FirstImm)); \
1397
4.39k
    SStream_concat(O, "%s", ":"); \
1398
4.39k
    printUInt32(O, (FirstImm + Offset)); \
1399
4.39k
    SStream_concat1(O, '\0'); \
1400
4.39k
  }
printImmRangeScale_2_1
Line
Count
Source
1387
2.28k
  { \
1388
2.28k
    AArch64_add_cs_detail_2( \
1389
2.28k
      MI, \
1390
2.28k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1391
2.28k
             Offset), \
1392
2.28k
      OpNum, Scale, Offset); \
1393
2.28k
    unsigned FirstImm = \
1394
2.28k
      Scale * \
1395
2.28k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1396
2.28k
    printUInt32(O, (FirstImm)); \
1397
2.28k
    SStream_concat(O, "%s", ":"); \
1398
2.28k
    printUInt32(O, (FirstImm + Offset)); \
1399
2.28k
    SStream_concat1(O, '\0'); \
1400
2.28k
  }
printImmRangeScale_4_3
Line
Count
Source
1387
2.11k
  { \
1388
2.11k
    AArch64_add_cs_detail_2( \
1389
2.11k
      MI, \
1390
2.11k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1391
2.11k
             Offset), \
1392
2.11k
      OpNum, Scale, Offset); \
1393
2.11k
    unsigned FirstImm = \
1394
2.11k
      Scale * \
1395
2.11k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1396
2.11k
    printUInt32(O, (FirstImm)); \
1397
2.11k
    SStream_concat(O, "%s", ":"); \
1398
2.11k
    printUInt32(O, (FirstImm + Offset)); \
1399
2.11k
    SStream_concat1(O, '\0'); \
1400
2.11k
  }
1401
DEFINE_printImmRangeScale(2, 1);
1402
DEFINE_printImmRangeScale(4, 3);
1403
1404
void printUImm12Offset(MCInst *MI, unsigned OpNum, unsigned Scale, SStream *O)
1405
5.71k
{
1406
5.71k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1407
5.71k
  if (MCOperand_isImm(MO)) {
1408
5.71k
    SStream_concat(O, "%s", markup("<imm:"));
1409
5.71k
    printUInt32Bang(O, (MCOperand_getImm(MO) * Scale));
1410
5.71k
    SStream_concat0(O, markup(">"));
1411
5.71k
  } else {
1412
0
    printUInt64Bang(O, MCOperand_getImm(MO));
1413
0
  }
1414
5.71k
}
1415
1416
void printAMIndexedWB(MCInst *MI, unsigned OpNum, unsigned Scale, SStream *O)
1417
0
{
1418
0
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum + 1));
1419
0
  SStream_concat0(O, "[");
1420
1421
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1422
0
  if (MCOperand_isImm(MO1)) {
1423
0
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
1424
0
    printUInt32Bang(O, MCOperand_getImm(MO1) * Scale);
1425
0
    SStream_concat0(O, markup(">"));
1426
0
  } else {
1427
0
    printUInt64Bang(O, MCOperand_getImm(MO1));
1428
0
  }
1429
0
  SStream_concat0(O, "]");
1430
0
}
1431
1432
void printRPRFMOperand(MCInst *MI, unsigned OpNum, SStream *O)
1433
228
{
1434
228
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_RPRFMOperand, OpNum);
1435
228
  unsigned prfop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1436
228
  const AArch64PRFM_PRFM *PRFM =
1437
228
    AArch64RPRFM_lookupRPRFMByEncoding(prfop);
1438
228
  if (PRFM) {
1439
58
    SStream_concat0(O, PRFM->Name);
1440
58
    return;
1441
58
  }
1442
1443
170
  printUInt32Bang(O, (prfop));
1444
170
  SStream_concat1(O, '\0');
1445
170
}
1446
1447
#define DEFINE_printPrefetchOp(IsSVEPrefetch) \
1448
  void CONCAT(printPrefetchOp, \
1449
        IsSVEPrefetch)(MCInst * MI, unsigned OpNum, SStream *O) \
1450
5.20k
  { \
1451
5.20k
    AArch64_add_cs_detail_1(MI, \
1452
5.20k
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1453
5.20k
                 IsSVEPrefetch), \
1454
5.20k
          OpNum, IsSVEPrefetch); \
1455
5.20k
    unsigned prfop = \
1456
5.20k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1457
5.20k
    if (IsSVEPrefetch) { \
1458
3.34k
      const AArch64SVEPRFM_SVEPRFM *PRFM = \
1459
3.34k
        AArch64SVEPRFM_lookupSVEPRFMByEncoding(prfop); \
1460
3.34k
      if (PRFM) { \
1461
3.10k
        SStream_concat0(O, PRFM->Name); \
1462
3.10k
        return; \
1463
3.10k
      } \
1464
3.34k
    } else { \
1465
1.86k
      const AArch64PRFM_PRFM *PRFM = \
1466
1.86k
        AArch64PRFM_lookupPRFMByEncoding(prfop); \
1467
1.86k
      if (PRFM && \
1468
1.86k
          AArch64_testFeatureList(MI->csh->mode, \
1469
1.20k
                PRFM->FeaturesRequired)) { \
1470
1.20k
        SStream_concat0(O, PRFM->Name); \
1471
1.20k
        return; \
1472
1.20k
      } \
1473
1.86k
    } \
1474
5.20k
\
1475
5.20k
    SStream_concat(O, "%s", markup("<imm:")); \
1476
901
    printUInt32Bang(O, (prfop)); \
1477
901
    SStream_concat0(O, markup(">")); \
1478
901
  }
printPrefetchOp_0
Line
Count
Source
1450
1.86k
  { \
1451
1.86k
    AArch64_add_cs_detail_1(MI, \
1452
1.86k
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1453
1.86k
                 IsSVEPrefetch), \
1454
1.86k
          OpNum, IsSVEPrefetch); \
1455
1.86k
    unsigned prfop = \
1456
1.86k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1457
1.86k
    if (IsSVEPrefetch) { \
1458
0
      const AArch64SVEPRFM_SVEPRFM *PRFM = \
1459
0
        AArch64SVEPRFM_lookupSVEPRFMByEncoding(prfop); \
1460
0
      if (PRFM) { \
1461
0
        SStream_concat0(O, PRFM->Name); \
1462
0
        return; \
1463
0
      } \
1464
1.86k
    } else { \
1465
1.86k
      const AArch64PRFM_PRFM *PRFM = \
1466
1.86k
        AArch64PRFM_lookupPRFMByEncoding(prfop); \
1467
1.86k
      if (PRFM && \
1468
1.86k
          AArch64_testFeatureList(MI->csh->mode, \
1469
1.20k
                PRFM->FeaturesRequired)) { \
1470
1.20k
        SStream_concat0(O, PRFM->Name); \
1471
1.20k
        return; \
1472
1.20k
      } \
1473
1.86k
    } \
1474
1.86k
\
1475
1.86k
    SStream_concat(O, "%s", markup("<imm:")); \
1476
656
    printUInt32Bang(O, (prfop)); \
1477
656
    SStream_concat0(O, markup(">")); \
1478
656
  }
printPrefetchOp_1
Line
Count
Source
1450
3.34k
  { \
1451
3.34k
    AArch64_add_cs_detail_1(MI, \
1452
3.34k
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1453
3.34k
                 IsSVEPrefetch), \
1454
3.34k
          OpNum, IsSVEPrefetch); \
1455
3.34k
    unsigned prfop = \
1456
3.34k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1457
3.34k
    if (IsSVEPrefetch) { \
1458
3.34k
      const AArch64SVEPRFM_SVEPRFM *PRFM = \
1459
3.34k
        AArch64SVEPRFM_lookupSVEPRFMByEncoding(prfop); \
1460
3.34k
      if (PRFM) { \
1461
3.10k
        SStream_concat0(O, PRFM->Name); \
1462
3.10k
        return; \
1463
3.10k
      } \
1464
3.34k
    } else { \
1465
0
      const AArch64PRFM_PRFM *PRFM = \
1466
0
        AArch64PRFM_lookupPRFMByEncoding(prfop); \
1467
0
      if (PRFM && \
1468
0
          AArch64_testFeatureList(MI->csh->mode, \
1469
0
                PRFM->FeaturesRequired)) { \
1470
0
        SStream_concat0(O, PRFM->Name); \
1471
0
        return; \
1472
0
      } \
1473
0
    } \
1474
3.34k
\
1475
3.34k
    SStream_concat(O, "%s", markup("<imm:")); \
1476
245
    printUInt32Bang(O, (prfop)); \
1477
245
    SStream_concat0(O, markup(">")); \
1478
245
  }
1479
DEFINE_printPrefetchOp(false);
1480
DEFINE_printPrefetchOp(true);
1481
1482
void printPSBHintOp(MCInst *MI, unsigned OpNum, SStream *O)
1483
425
{
1484
425
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_PSBHintOp, OpNum);
1485
425
  unsigned psbhintop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1486
425
  const AArch64PSBHint_PSB *PSB =
1487
425
    AArch64PSBHint_lookupPSBByEncoding(psbhintop);
1488
425
  if (PSB)
1489
425
    SStream_concat0(O, PSB->Name);
1490
0
  else {
1491
0
    SStream_concat(O, "%s", markup("<imm:"));
1492
0
    SStream_concat1(O, '#');
1493
0
    printUInt32Bang(O, (psbhintop));
1494
0
    SStream_concat0(O, markup(">"));
1495
0
  }
1496
425
}
1497
1498
void printBTIHintOp(MCInst *MI, unsigned OpNum, SStream *O)
1499
114
{
1500
114
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BTIHintOp, OpNum);
1501
114
  unsigned btihintop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) ^
1502
114
           32;
1503
114
  const AArch64BTIHint_BTI *BTI =
1504
114
    AArch64BTIHint_lookupBTIByEncoding(btihintop);
1505
114
  if (BTI)
1506
114
    SStream_concat0(O, BTI->Name);
1507
0
  else {
1508
0
    SStream_concat(O, "%s", markup("<imm:"));
1509
0
    printUInt32Bang(O, (btihintop));
1510
0
    SStream_concat0(O, markup(">"));
1511
0
  }
1512
114
}
1513
1514
static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1515
903
{
1516
903
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_FPImmOperand, OpNum);
1517
903
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1518
903
  float FPImm = MCOperand_isDFPImm(MO) ?
1519
0
            BitsToDouble(MCOperand_getImm(MO)) :
1520
903
            AArch64_AM_getFPImmFloat(MCOperand_getImm(MO));
1521
1522
  // 8 decimal places are enough to perfectly represent permitted floats.
1523
903
  SStream_concat(O, "%s", markup("<imm:"));
1524
903
  SStream_concat(O, "#%.8f", FPImm);
1525
903
  SStream_concat0(O, markup(">"));
1526
903
}
1527
1528
static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride /* = 1 */)
1529
103k
{
1530
267k
  while (Stride--) {
1531
164k
    switch (Reg) {
1532
0
    default:
1533
0
      CS_ASSERT_RET_VAL(0 && "Vector register expected!", 0);
1534
6.05k
    case AArch64_Q0:
1535
6.05k
      Reg = AArch64_Q1;
1536
6.05k
      break;
1537
4.81k
    case AArch64_Q1:
1538
4.81k
      Reg = AArch64_Q2;
1539
4.81k
      break;
1540
2.02k
    case AArch64_Q2:
1541
2.02k
      Reg = AArch64_Q3;
1542
2.02k
      break;
1543
1.80k
    case AArch64_Q3:
1544
1.80k
      Reg = AArch64_Q4;
1545
1.80k
      break;
1546
2.21k
    case AArch64_Q4:
1547
2.21k
      Reg = AArch64_Q5;
1548
2.21k
      break;
1549
2.47k
    case AArch64_Q5:
1550
2.47k
      Reg = AArch64_Q6;
1551
2.47k
      break;
1552
1.11k
    case AArch64_Q6:
1553
1.11k
      Reg = AArch64_Q7;
1554
1.11k
      break;
1555
729
    case AArch64_Q7:
1556
729
      Reg = AArch64_Q8;
1557
729
      break;
1558
865
    case AArch64_Q8:
1559
865
      Reg = AArch64_Q9;
1560
865
      break;
1561
1.19k
    case AArch64_Q9:
1562
1.19k
      Reg = AArch64_Q10;
1563
1.19k
      break;
1564
1.55k
    case AArch64_Q10:
1565
1.55k
      Reg = AArch64_Q11;
1566
1.55k
      break;
1567
1.79k
    case AArch64_Q11:
1568
1.79k
      Reg = AArch64_Q12;
1569
1.79k
      break;
1570
3.34k
    case AArch64_Q12:
1571
3.34k
      Reg = AArch64_Q13;
1572
3.34k
      break;
1573
2.47k
    case AArch64_Q13:
1574
2.47k
      Reg = AArch64_Q14;
1575
2.47k
      break;
1576
2.75k
    case AArch64_Q14:
1577
2.75k
      Reg = AArch64_Q15;
1578
2.75k
      break;
1579
606
    case AArch64_Q15:
1580
606
      Reg = AArch64_Q16;
1581
606
      break;
1582
1.35k
    case AArch64_Q16:
1583
1.35k
      Reg = AArch64_Q17;
1584
1.35k
      break;
1585
1.33k
    case AArch64_Q17:
1586
1.33k
      Reg = AArch64_Q18;
1587
1.33k
      break;
1588
1.33k
    case AArch64_Q18:
1589
1.33k
      Reg = AArch64_Q19;
1590
1.33k
      break;
1591
1.83k
    case AArch64_Q19:
1592
1.83k
      Reg = AArch64_Q20;
1593
1.83k
      break;
1594
2.74k
    case AArch64_Q20:
1595
2.74k
      Reg = AArch64_Q21;
1596
2.74k
      break;
1597
1.82k
    case AArch64_Q21:
1598
1.82k
      Reg = AArch64_Q22;
1599
1.82k
      break;
1600
2.67k
    case AArch64_Q22:
1601
2.67k
      Reg = AArch64_Q23;
1602
2.67k
      break;
1603
2.16k
    case AArch64_Q23:
1604
2.16k
      Reg = AArch64_Q24;
1605
2.16k
      break;
1606
1.83k
    case AArch64_Q24:
1607
1.83k
      Reg = AArch64_Q25;
1608
1.83k
      break;
1609
1.78k
    case AArch64_Q25:
1610
1.78k
      Reg = AArch64_Q26;
1611
1.78k
      break;
1612
1.10k
    case AArch64_Q26:
1613
1.10k
      Reg = AArch64_Q27;
1614
1.10k
      break;
1615
489
    case AArch64_Q27:
1616
489
      Reg = AArch64_Q28;
1617
489
      break;
1618
380
    case AArch64_Q28:
1619
380
      Reg = AArch64_Q29;
1620
380
      break;
1621
501
    case AArch64_Q29:
1622
501
      Reg = AArch64_Q30;
1623
501
      break;
1624
438
    case AArch64_Q30:
1625
438
      Reg = AArch64_Q31;
1626
438
      break;
1627
    // Vector lists can wrap around.
1628
2.22k
    case AArch64_Q31:
1629
2.22k
      Reg = AArch64_Q0;
1630
2.22k
      break;
1631
9.51k
    case AArch64_Z0:
1632
9.51k
      Reg = AArch64_Z1;
1633
9.51k
      break;
1634
6.37k
    case AArch64_Z1:
1635
6.37k
      Reg = AArch64_Z2;
1636
6.37k
      break;
1637
6.50k
    case AArch64_Z2:
1638
6.50k
      Reg = AArch64_Z3;
1639
6.50k
      break;
1640
2.22k
    case AArch64_Z3:
1641
2.22k
      Reg = AArch64_Z4;
1642
2.22k
      break;
1643
7.06k
    case AArch64_Z4:
1644
7.06k
      Reg = AArch64_Z5;
1645
7.06k
      break;
1646
5.81k
    case AArch64_Z5:
1647
5.81k
      Reg = AArch64_Z6;
1648
5.81k
      break;
1649
5.19k
    case AArch64_Z6:
1650
5.19k
      Reg = AArch64_Z7;
1651
5.19k
      break;
1652
2.42k
    case AArch64_Z7:
1653
2.42k
      Reg = AArch64_Z8;
1654
2.42k
      break;
1655
5.05k
    case AArch64_Z8:
1656
5.05k
      Reg = AArch64_Z9;
1657
5.05k
      break;
1658
3.90k
    case AArch64_Z9:
1659
3.90k
      Reg = AArch64_Z10;
1660
3.90k
      break;
1661
4.07k
    case AArch64_Z10:
1662
4.07k
      Reg = AArch64_Z11;
1663
4.07k
      break;
1664
2.16k
    case AArch64_Z11:
1665
2.16k
      Reg = AArch64_Z12;
1666
2.16k
      break;
1667
2.28k
    case AArch64_Z12:
1668
2.28k
      Reg = AArch64_Z13;
1669
2.28k
      break;
1670
2.18k
    case AArch64_Z13:
1671
2.18k
      Reg = AArch64_Z14;
1672
2.18k
      break;
1673
3.48k
    case AArch64_Z14:
1674
3.48k
      Reg = AArch64_Z15;
1675
3.48k
      break;
1676
2.14k
    case AArch64_Z15:
1677
2.14k
      Reg = AArch64_Z16;
1678
2.14k
      break;
1679
2.28k
    case AArch64_Z16:
1680
2.28k
      Reg = AArch64_Z17;
1681
2.28k
      break;
1682
995
    case AArch64_Z17:
1683
995
      Reg = AArch64_Z18;
1684
995
      break;
1685
1.70k
    case AArch64_Z18:
1686
1.70k
      Reg = AArch64_Z19;
1687
1.70k
      break;
1688
1.27k
    case AArch64_Z19:
1689
1.27k
      Reg = AArch64_Z20;
1690
1.27k
      break;
1691
2.10k
    case AArch64_Z20:
1692
2.10k
      Reg = AArch64_Z21;
1693
2.10k
      break;
1694
2.31k
    case AArch64_Z21:
1695
2.31k
      Reg = AArch64_Z22;
1696
2.31k
      break;
1697
2.79k
    case AArch64_Z22:
1698
2.79k
      Reg = AArch64_Z23;
1699
2.79k
      break;
1700
1.40k
    case AArch64_Z23:
1701
1.40k
      Reg = AArch64_Z24;
1702
1.40k
      break;
1703
3.09k
    case AArch64_Z24:
1704
3.09k
      Reg = AArch64_Z25;
1705
3.09k
      break;
1706
2.94k
    case AArch64_Z25:
1707
2.94k
      Reg = AArch64_Z26;
1708
2.94k
      break;
1709
3.90k
    case AArch64_Z26:
1710
3.90k
      Reg = AArch64_Z27;
1711
3.90k
      break;
1712
1.69k
    case AArch64_Z27:
1713
1.69k
      Reg = AArch64_Z28;
1714
1.69k
      break;
1715
1.87k
    case AArch64_Z28:
1716
1.87k
      Reg = AArch64_Z29;
1717
1.87k
      break;
1718
1.45k
    case AArch64_Z29:
1719
1.45k
      Reg = AArch64_Z30;
1720
1.45k
      break;
1721
1.45k
    case AArch64_Z30:
1722
1.45k
      Reg = AArch64_Z31;
1723
1.45k
      break;
1724
    // Vector lists can wrap around.
1725
1.53k
    case AArch64_Z31:
1726
1.53k
      Reg = AArch64_Z0;
1727
1.53k
      break;
1728
45
    case AArch64_P0:
1729
45
      Reg = AArch64_P1;
1730
45
      break;
1731
128
    case AArch64_P1:
1732
128
      Reg = AArch64_P2;
1733
128
      break;
1734
114
    case AArch64_P2:
1735
114
      Reg = AArch64_P3;
1736
114
      break;
1737
44
    case AArch64_P3:
1738
44
      Reg = AArch64_P4;
1739
44
      break;
1740
20
    case AArch64_P4:
1741
20
      Reg = AArch64_P5;
1742
20
      break;
1743
92
    case AArch64_P5:
1744
92
      Reg = AArch64_P6;
1745
92
      break;
1746
50
    case AArch64_P6:
1747
50
      Reg = AArch64_P7;
1748
50
      break;
1749
50
    case AArch64_P7:
1750
50
      Reg = AArch64_P8;
1751
50
      break;
1752
90
    case AArch64_P8:
1753
90
      Reg = AArch64_P9;
1754
90
      break;
1755
90
    case AArch64_P9:
1756
90
      Reg = AArch64_P10;
1757
90
      break;
1758
50
    case AArch64_P10:
1759
50
      Reg = AArch64_P11;
1760
50
      break;
1761
40
    case AArch64_P11:
1762
40
      Reg = AArch64_P12;
1763
40
      break;
1764
30
    case AArch64_P12:
1765
30
      Reg = AArch64_P13;
1766
30
      break;
1767
332
    case AArch64_P13:
1768
332
      Reg = AArch64_P14;
1769
332
      break;
1770
28
    case AArch64_P14:
1771
28
      Reg = AArch64_P15;
1772
28
      break;
1773
    // Vector lists can wrap around.
1774
82
    case AArch64_P15:
1775
82
      Reg = AArch64_P0;
1776
82
      break;
1777
164k
    }
1778
164k
  }
1779
103k
  return Reg;
1780
103k
}
1781
1782
#define DEFINE_printGPRSeqPairsClassOperand(size) \
1783
  void CONCAT(printGPRSeqPairsClassOperand, \
1784
        size)(MCInst * MI, unsigned OpNum, SStream *O) \
1785
1.80k
  { \
1786
1.80k
    AArch64_add_cs_detail_1( \
1787
1.80k
      MI, \
1788
1.80k
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1789
1.80k
             size), \
1790
1.80k
      OpNum, size); \
1791
1.80k
    CS_ASSERT_RET((size == 64 || size == 32) && \
1792
1.80k
            "Template parameter must be either 32 or 64"); \
1793
1.80k
    unsigned Reg = \
1794
1.80k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1795
1.80k
\
1796
1.80k
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1797
1.80k
                 AArch64_sube64; \
1798
1.80k
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1799
1.80k
                 AArch64_subo64; \
1800
1.80k
\
1801
1.80k
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1802
1.80k
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1803
1.80k
    printRegName(O, Even); \
1804
1.80k
    SStream_concat0(O, ", "); \
1805
1.80k
    printRegName(O, Odd); \
1806
1.80k
  }
printGPRSeqPairsClassOperand_32
Line
Count
Source
1785
214
  { \
1786
214
    AArch64_add_cs_detail_1( \
1787
214
      MI, \
1788
214
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1789
214
             size), \
1790
214
      OpNum, size); \
1791
214
    CS_ASSERT_RET((size == 64 || size == 32) && \
1792
214
            "Template parameter must be either 32 or 64"); \
1793
214
    unsigned Reg = \
1794
214
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1795
214
\
1796
214
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1797
214
                 AArch64_sube64; \
1798
214
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1799
214
                 AArch64_subo64; \
1800
214
\
1801
214
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1802
214
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1803
214
    printRegName(O, Even); \
1804
214
    SStream_concat0(O, ", "); \
1805
214
    printRegName(O, Odd); \
1806
214
  }
printGPRSeqPairsClassOperand_64
Line
Count
Source
1785
1.59k
  { \
1786
1.59k
    AArch64_add_cs_detail_1( \
1787
1.59k
      MI, \
1788
1.59k
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1789
1.59k
             size), \
1790
1.59k
      OpNum, size); \
1791
1.59k
    CS_ASSERT_RET((size == 64 || size == 32) && \
1792
1.59k
            "Template parameter must be either 32 or 64"); \
1793
1.59k
    unsigned Reg = \
1794
1.59k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1795
1.59k
\
1796
1.59k
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1797
1.59k
                 AArch64_sube64; \
1798
1.59k
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1799
1.59k
                 AArch64_subo64; \
1800
1.59k
\
1801
1.59k
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1802
1.59k
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1803
1.59k
    printRegName(O, Even); \
1804
1.59k
    SStream_concat0(O, ", "); \
1805
1.59k
    printRegName(O, Odd); \
1806
1.59k
  }
1807
DEFINE_printGPRSeqPairsClassOperand(32);
1808
DEFINE_printGPRSeqPairsClassOperand(64);
1809
1810
#define DEFINE_printMatrixIndex(Scale) \
1811
  void CONCAT(printMatrixIndex, Scale)(MCInst * MI, unsigned OpNum, \
1812
               SStream *O) \
1813
6.58k
  { \
1814
6.58k
    AArch64_add_cs_detail_1( \
1815
6.58k
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1816
6.58k
      OpNum, Scale); \
1817
6.58k
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1818
6.58k
                MI, (OpNum)))); \
1819
6.58k
  }
printMatrixIndex_8
Line
Count
Source
1813
75
  { \
1814
75
    AArch64_add_cs_detail_1( \
1815
75
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1816
75
      OpNum, Scale); \
1817
75
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1818
75
                MI, (OpNum)))); \
1819
75
  }
Unexecuted instantiation: printMatrixIndex_0
printMatrixIndex_1
Line
Count
Source
1813
6.51k
  { \
1814
6.51k
    AArch64_add_cs_detail_1( \
1815
6.51k
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1816
6.51k
      OpNum, Scale); \
1817
6.51k
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1818
6.51k
                MI, (OpNum)))); \
1819
6.51k
  }
1820
DEFINE_printMatrixIndex(8);
1821
DEFINE_printMatrixIndex(0);
1822
DEFINE_printMatrixIndex(1);
1823
1824
void printMatrixTileList(MCInst *MI, unsigned OpNum, SStream *O)
1825
489
{
1826
489
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MatrixTileList, OpNum);
1827
489
  unsigned MaxRegs = 8;
1828
489
  unsigned RegMask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1829
1830
489
  unsigned NumRegs = 0;
1831
4.40k
  for (unsigned I = 0; I < MaxRegs; ++I)
1832
3.91k
    if ((RegMask & (1 << I)) != 0)
1833
1.60k
      ++NumRegs;
1834
1835
489
  SStream_concat0(O, "{");
1836
489
  unsigned Printed = 0;
1837
4.40k
  for (unsigned I = 0; I < MaxRegs; ++I) {
1838
3.91k
    unsigned Reg = RegMask & (1 << I);
1839
3.91k
    if (Reg == 0)
1840
2.31k
      continue;
1841
1.60k
    printRegName(O, AArch64_ZAD0 + I);
1842
1.60k
    if (Printed + 1 != NumRegs)
1843
1.11k
      SStream_concat0(O, ", ");
1844
1.60k
    ++Printed;
1845
1.60k
  }
1846
489
  SStream_concat0(O, "}");
1847
489
}
1848
1849
void printVectorList(MCInst *MI, unsigned OpNum, SStream *O,
1850
         const char *LayoutSuffix)
1851
47.6k
{
1852
47.6k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1853
1854
47.6k
  SStream_concat0(O, "{ ");
1855
1856
  // Work out how many registers there are in the list (if there is an actual
1857
  // list).
1858
47.6k
  unsigned NumRegs = 1;
1859
47.6k
  if (MCRegisterClass_contains(
1860
47.6k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_DDRegClassID),
1861
47.6k
        Reg) ||
1862
47.2k
      MCRegisterClass_contains(
1863
47.2k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_ZPR2RegClassID),
1864
47.2k
        Reg) ||
1865
39.7k
      MCRegisterClass_contains(
1866
39.7k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_QQRegClassID),
1867
39.7k
        Reg) ||
1868
33.5k
      MCRegisterClass_contains(
1869
33.5k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_PPR2RegClassID),
1870
33.5k
        Reg) ||
1871
32.8k
      MCRegisterClass_contains(
1872
32.8k
        MCRegisterInfo_getRegClass(MI->MRI,
1873
32.8k
                 AArch64_ZPR2StridedRegClassID),
1874
32.8k
        Reg))
1875
16.6k
    NumRegs = 2;
1876
31.0k
  else if (MCRegisterClass_contains(
1877
31.0k
       MCRegisterInfo_getRegClass(MI->MRI,
1878
31.0k
                AArch64_DDDRegClassID),
1879
31.0k
       Reg) ||
1880
29.6k
     MCRegisterClass_contains(
1881
29.6k
       MCRegisterInfo_getRegClass(MI->MRI,
1882
29.6k
                AArch64_ZPR3RegClassID),
1883
29.6k
       Reg) ||
1884
29.1k
     MCRegisterClass_contains(
1885
29.1k
       MCRegisterInfo_getRegClass(MI->MRI,
1886
29.1k
                AArch64_QQQRegClassID),
1887
29.1k
       Reg))
1888
7.88k
    NumRegs = 3;
1889
23.1k
  else if (MCRegisterClass_contains(
1890
23.1k
       MCRegisterInfo_getRegClass(MI->MRI,
1891
23.1k
                AArch64_DDDDRegClassID),
1892
23.1k
       Reg) ||
1893
22.9k
     MCRegisterClass_contains(
1894
22.9k
       MCRegisterInfo_getRegClass(MI->MRI,
1895
22.9k
                AArch64_ZPR4RegClassID),
1896
22.9k
       Reg) ||
1897
18.1k
     MCRegisterClass_contains(
1898
18.1k
       MCRegisterInfo_getRegClass(MI->MRI,
1899
18.1k
                AArch64_QQQQRegClassID),
1900
18.1k
       Reg) ||
1901
13.3k
     MCRegisterClass_contains(
1902
13.3k
       MCRegisterInfo_getRegClass(
1903
13.3k
         MI->MRI, AArch64_ZPR4StridedRegClassID),
1904
13.3k
       Reg))
1905
11.0k
    NumRegs = 4;
1906
1907
47.6k
  unsigned Stride = 1;
1908
47.6k
  if (MCRegisterClass_contains(
1909
47.6k
        MCRegisterInfo_getRegClass(MI->MRI,
1910
47.6k
                 AArch64_ZPR2StridedRegClassID),
1911
47.6k
        Reg))
1912
1.88k
    Stride = 8;
1913
45.7k
  else if (MCRegisterClass_contains(
1914
45.7k
       MCRegisterInfo_getRegClass(
1915
45.7k
         MI->MRI, AArch64_ZPR4StridedRegClassID),
1916
45.7k
       Reg))
1917
1.24k
    Stride = 4;
1918
1919
  // Now forget about the list and find out what the first register is.
1920
47.6k
  if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_dsub0))
1921
1.90k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_dsub0);
1922
45.7k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_qsub0))
1923
17.1k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_qsub0);
1924
28.5k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_zsub0))
1925
15.8k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_zsub0);
1926
12.7k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_psub0))
1927
622
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_psub0);
1928
1929
  // If it's a D-reg, we need to promote it to the equivalent Q-reg before
1930
  // printing (otherwise getRegisterName fails).
1931
47.6k
  if (MCRegisterClass_contains(MCRegisterInfo_getRegClass(
1932
47.6k
               MI->MRI, AArch64_FPR64RegClassID),
1933
47.6k
             Reg)) {
1934
2.24k
    const MCRegisterClass *FPR128RC = MCRegisterInfo_getRegClass(
1935
2.24k
      MI->MRI, AArch64_FPR128RegClassID);
1936
2.24k
    Reg = MCRegisterInfo_getMatchingSuperReg(
1937
2.24k
      MI->MRI, Reg, AArch64_dsub, FPR128RC);
1938
2.24k
  }
1939
1940
47.6k
  if ((MCRegisterClass_contains(
1941
47.6k
         MCRegisterInfo_getRegClass(MI->MRI, AArch64_ZPRRegClassID),
1942
47.6k
         Reg) ||
1943
23.9k
       MCRegisterClass_contains(
1944
23.9k
         MCRegisterInfo_getRegClass(MI->MRI, AArch64_PPRRegClassID),
1945
23.9k
         Reg)) &&
1946
24.2k
      NumRegs > 1 && Stride == 1 &&
1947
      // Do not print the range when the last register is lower than the
1948
      // first. Because it is a wrap-around register.
1949
13.3k
      Reg < getNextVectorRegister(Reg, NumRegs - 1)) {
1950
13.2k
    printRegName(O, Reg);
1951
13.2k
    SStream_concat0(O, LayoutSuffix);
1952
13.2k
    if (NumRegs > 1) {
1953
      // Set of two sve registers should be separated by ','
1954
13.2k
      const char *split_char = NumRegs == 2 ? ", " : " - ";
1955
13.2k
      SStream_concat0(O, split_char);
1956
13.2k
      printRegName(O,
1957
13.2k
             (getNextVectorRegister(Reg, NumRegs - 1)));
1958
13.2k
      SStream_concat0(O, LayoutSuffix);
1959
13.2k
    }
1960
34.3k
  } else {
1961
110k
    for (unsigned i = 0; i < NumRegs;
1962
76.5k
         ++i, Reg = getNextVectorRegister(Reg, Stride)) {
1963
      // wrap-around sve register
1964
76.5k
      if (MCRegisterClass_contains(
1965
76.5k
            MCRegisterInfo_getRegClass(
1966
76.5k
              MI->MRI, AArch64_ZPRRegClassID),
1967
76.5k
            Reg) ||
1968
59.9k
          MCRegisterClass_contains(
1969
59.9k
            MCRegisterInfo_getRegClass(
1970
59.9k
              MI->MRI, AArch64_PPRRegClassID),
1971
59.9k
            Reg))
1972
16.7k
        printRegName(O, Reg);
1973
59.8k
      else
1974
59.8k
        printRegNameAlt(O, Reg, AArch64_vreg);
1975
76.5k
      SStream_concat0(O, LayoutSuffix);
1976
76.5k
      if (i + 1 != NumRegs)
1977
42.1k
        SStream_concat0(O, ", ");
1978
76.5k
    }
1979
34.3k
  }
1980
47.6k
  SStream_concat0(O, " }");
1981
47.6k
}
1982
1983
void printImplicitlyTypedVectorList(MCInst *MI, unsigned OpNum, SStream *O)
1984
0
{
1985
0
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ImplicitlyTypedVectorList,
1986
0
        OpNum);
1987
0
  printVectorList(MI, OpNum, O, "");
1988
0
}
1989
1990
#define DEFINE_printTypedVectorList(NumLanes, LaneKind) \
1991
  void CONCAT(printTypedVectorList, CONCAT(NumLanes, LaneKind))( \
1992
    MCInst * MI, unsigned OpNum, SStream *O) \
1993
47.6k
  { \
1994
47.6k
    AArch64_add_cs_detail_2( \
1995
47.6k
      MI, \
1996
47.6k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
47.6k
              NumLanes), \
1998
47.6k
             LaneKind), \
1999
47.6k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
47.6k
    if (CHAR(LaneKind) == '0') { \
2001
65
      printVectorList(MI, OpNum, O, ""); \
2002
65
      return; \
2003
65
    } \
2004
47.6k
    char Suffix[32]; \
2005
47.5k
    if (NumLanes) \
2006
47.5k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
7.76k
            CHAR(LaneKind)); \
2008
47.5k
    else \
2009
47.5k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
39.7k
            CHAR(LaneKind)); \
2011
47.5k
\
2012
47.5k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
47.5k
  }
printTypedVectorList_0_b
Line
Count
Source
1993
8.35k
  { \
1994
8.35k
    AArch64_add_cs_detail_2( \
1995
8.35k
      MI, \
1996
8.35k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
8.35k
              NumLanes), \
1998
8.35k
             LaneKind), \
1999
8.35k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
8.35k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
8.35k
    char Suffix[32]; \
2005
8.35k
    if (NumLanes) \
2006
8.35k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
8.35k
    else \
2009
8.35k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
8.35k
            CHAR(LaneKind)); \
2011
8.35k
\
2012
8.35k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
8.35k
  }
printTypedVectorList_0_d
Line
Count
Source
1993
11.7k
  { \
1994
11.7k
    AArch64_add_cs_detail_2( \
1995
11.7k
      MI, \
1996
11.7k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
11.7k
              NumLanes), \
1998
11.7k
             LaneKind), \
1999
11.7k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
11.7k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
11.7k
    char Suffix[32]; \
2005
11.7k
    if (NumLanes) \
2006
11.7k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
11.7k
    else \
2009
11.7k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
11.7k
            CHAR(LaneKind)); \
2011
11.7k
\
2012
11.7k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
11.7k
  }
printTypedVectorList_0_h
Line
Count
Source
1993
9.69k
  { \
1994
9.69k
    AArch64_add_cs_detail_2( \
1995
9.69k
      MI, \
1996
9.69k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
9.69k
              NumLanes), \
1998
9.69k
             LaneKind), \
1999
9.69k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
9.69k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
9.69k
    char Suffix[32]; \
2005
9.69k
    if (NumLanes) \
2006
9.69k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
9.69k
    else \
2009
9.69k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
9.69k
            CHAR(LaneKind)); \
2011
9.69k
\
2012
9.69k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
9.69k
  }
printTypedVectorList_0_s
Line
Count
Source
1993
9.68k
  { \
1994
9.68k
    AArch64_add_cs_detail_2( \
1995
9.68k
      MI, \
1996
9.68k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
9.68k
              NumLanes), \
1998
9.68k
             LaneKind), \
1999
9.68k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
9.68k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
9.68k
    char Suffix[32]; \
2005
9.68k
    if (NumLanes) \
2006
9.68k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
9.68k
    else \
2009
9.68k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
9.68k
            CHAR(LaneKind)); \
2011
9.68k
\
2012
9.68k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
9.68k
  }
printTypedVectorList_0_q
Line
Count
Source
1993
313
  { \
1994
313
    AArch64_add_cs_detail_2( \
1995
313
      MI, \
1996
313
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
313
              NumLanes), \
1998
313
             LaneKind), \
1999
313
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
313
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
313
    char Suffix[32]; \
2005
313
    if (NumLanes) \
2006
313
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
313
    else \
2009
313
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
313
            CHAR(LaneKind)); \
2011
313
\
2012
313
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
313
  }
printTypedVectorList_16_b
Line
Count
Source
1993
2.61k
  { \
1994
2.61k
    AArch64_add_cs_detail_2( \
1995
2.61k
      MI, \
1996
2.61k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
2.61k
              NumLanes), \
1998
2.61k
             LaneKind), \
1999
2.61k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
2.61k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
2.61k
    char Suffix[32]; \
2005
2.61k
    if (NumLanes) \
2006
2.61k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
2.61k
            CHAR(LaneKind)); \
2008
2.61k
    else \
2009
2.61k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
2.61k
\
2012
2.61k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
2.61k
  }
printTypedVectorList_1_d
Line
Count
Source
1993
810
  { \
1994
810
    AArch64_add_cs_detail_2( \
1995
810
      MI, \
1996
810
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
810
              NumLanes), \
1998
810
             LaneKind), \
1999
810
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
810
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
810
    char Suffix[32]; \
2005
810
    if (NumLanes) \
2006
810
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
810
            CHAR(LaneKind)); \
2008
810
    else \
2009
810
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
810
\
2012
810
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
810
  }
printTypedVectorList_2_d
Line
Count
Source
1993
762
  { \
1994
762
    AArch64_add_cs_detail_2( \
1995
762
      MI, \
1996
762
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
762
              NumLanes), \
1998
762
             LaneKind), \
1999
762
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
762
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
762
    char Suffix[32]; \
2005
762
    if (NumLanes) \
2006
762
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
762
            CHAR(LaneKind)); \
2008
762
    else \
2009
762
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
762
\
2012
762
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
762
  }
printTypedVectorList_2_s
Line
Count
Source
1993
644
  { \
1994
644
    AArch64_add_cs_detail_2( \
1995
644
      MI, \
1996
644
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
644
              NumLanes), \
1998
644
             LaneKind), \
1999
644
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
644
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
644
    char Suffix[32]; \
2005
644
    if (NumLanes) \
2006
644
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
644
            CHAR(LaneKind)); \
2008
644
    else \
2009
644
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
644
\
2012
644
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
644
  }
printTypedVectorList_4_h
Line
Count
Source
1993
278
  { \
1994
278
    AArch64_add_cs_detail_2( \
1995
278
      MI, \
1996
278
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
278
              NumLanes), \
1998
278
             LaneKind), \
1999
278
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
278
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
278
    char Suffix[32]; \
2005
278
    if (NumLanes) \
2006
278
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
278
            CHAR(LaneKind)); \
2008
278
    else \
2009
278
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
278
\
2012
278
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
278
  }
printTypedVectorList_4_s
Line
Count
Source
1993
854
  { \
1994
854
    AArch64_add_cs_detail_2( \
1995
854
      MI, \
1996
854
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
854
              NumLanes), \
1998
854
             LaneKind), \
1999
854
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
854
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
854
    char Suffix[32]; \
2005
854
    if (NumLanes) \
2006
854
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
854
            CHAR(LaneKind)); \
2008
854
    else \
2009
854
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
854
\
2012
854
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
854
  }
printTypedVectorList_8_b
Line
Count
Source
1993
514
  { \
1994
514
    AArch64_add_cs_detail_2( \
1995
514
      MI, \
1996
514
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
514
              NumLanes), \
1998
514
             LaneKind), \
1999
514
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
514
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
514
    char Suffix[32]; \
2005
514
    if (NumLanes) \
2006
514
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
514
            CHAR(LaneKind)); \
2008
514
    else \
2009
514
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
514
\
2012
514
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
514
  }
printTypedVectorList_8_h
Line
Count
Source
1993
1.28k
  { \
1994
1.28k
    AArch64_add_cs_detail_2( \
1995
1.28k
      MI, \
1996
1.28k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
1.28k
              NumLanes), \
1998
1.28k
             LaneKind), \
1999
1.28k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
1.28k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
1.28k
    char Suffix[32]; \
2005
1.28k
    if (NumLanes) \
2006
1.28k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
1.28k
            CHAR(LaneKind)); \
2008
1.28k
    else \
2009
1.28k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
1.28k
\
2012
1.28k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
1.28k
  }
printTypedVectorList_0_0
Line
Count
Source
1993
65
  { \
1994
65
    AArch64_add_cs_detail_2( \
1995
65
      MI, \
1996
65
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
65
              NumLanes), \
1998
65
             LaneKind), \
1999
65
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
65
    if (CHAR(LaneKind) == '0') { \
2001
65
      printVectorList(MI, OpNum, O, ""); \
2002
65
      return; \
2003
65
    } \
2004
65
    char Suffix[32]; \
2005
0
    if (NumLanes) \
2006
0
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
0
    else \
2009
0
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
0
\
2012
0
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
0
  }
2014
DEFINE_printTypedVectorList(0, b);
2015
DEFINE_printTypedVectorList(0, d);
2016
DEFINE_printTypedVectorList(0, h);
2017
DEFINE_printTypedVectorList(0, s);
2018
DEFINE_printTypedVectorList(0, q);
2019
DEFINE_printTypedVectorList(16, b);
2020
DEFINE_printTypedVectorList(1, d);
2021
DEFINE_printTypedVectorList(2, d);
2022
DEFINE_printTypedVectorList(2, s);
2023
DEFINE_printTypedVectorList(4, h);
2024
DEFINE_printTypedVectorList(4, s);
2025
DEFINE_printTypedVectorList(8, b);
2026
DEFINE_printTypedVectorList(8, h);
2027
DEFINE_printTypedVectorList(0, 0);
2028
2029
#define DEFINE_printVectorIndex(Scale) \
2030
  void CONCAT(printVectorIndex, Scale)(MCInst * MI, unsigned OpNum, \
2031
               SStream *O) \
2032
29.7k
  { \
2033
29.7k
    AArch64_add_cs_detail_1( \
2034
29.7k
      MI, CONCAT(AArch64_OP_GROUP_VectorIndex, Scale), \
2035
29.7k
      OpNum, Scale); \
2036
29.7k
    SStream_concat(O, "%s", "["); \
2037
29.7k
    printUInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
2038
29.7k
                 MI, (OpNum)))); \
2039
29.7k
    SStream_concat0(O, "]"); \
2040
29.7k
  }
printVectorIndex_1
Line
Count
Source
2032
29.7k
  { \
2033
29.7k
    AArch64_add_cs_detail_1( \
2034
29.7k
      MI, CONCAT(AArch64_OP_GROUP_VectorIndex, Scale), \
2035
29.7k
      OpNum, Scale); \
2036
29.7k
    SStream_concat(O, "%s", "["); \
2037
29.7k
    printUInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
2038
29.7k
                 MI, (OpNum)))); \
2039
29.7k
    SStream_concat0(O, "]"); \
2040
29.7k
  }
Unexecuted instantiation: printVectorIndex_8
2041
DEFINE_printVectorIndex(1);
2042
DEFINE_printVectorIndex(8);
2043
2044
void printAlignedLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
2045
10.5k
{
2046
10.5k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AlignedLabel, OpNum);
2047
10.5k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
2048
2049
  // If the label has already been resolved to an immediate offset (say, when
2050
  // we're running the disassembler), just print the immediate.
2051
10.5k
  if (MCOperand_isImm(Op)) {
2052
10.4k
    SStream_concat0(O, markup("<imm:"));
2053
10.4k
    int64_t Offset = MCOperand_getImm(Op) * 4;
2054
10.4k
    if (MI->csh->PrintBranchImmAsAddress)
2055
10.4k
      printUInt64(O, (Address + Offset));
2056
0
    else {
2057
0
      printUInt64Bang(O, (Offset));
2058
0
    }
2059
10.4k
    SStream_concat0(O, markup(">"));
2060
10.4k
    return;
2061
10.4k
  }
2062
2063
83
  printUInt64Bang(O, MCOperand_getImm(Op));
2064
83
}
2065
2066
void printAdrLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
2067
0
{
2068
0
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AdrLabel, OpNum);
2069
0
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
2070
2071
  // If the label has already been resolved to an immediate offset (say, when
2072
  // we're running the disassembler), just print the immediate.
2073
0
  if (MCOperand_isImm(Op)) {
2074
0
    const int64_t Offset = MCOperand_getImm(Op);
2075
0
    SStream_concat0(O, markup("<imm:"));
2076
0
    if (MI->csh->PrintBranchImmAsAddress)
2077
0
      printUInt64(O, ((Address & -4) + Offset));
2078
0
    else {
2079
0
      printUInt64Bang(O, Offset);
2080
0
    }
2081
0
    SStream_concat0(O, markup(">"));
2082
0
    return;
2083
0
  }
2084
2085
0
  printUInt64Bang(O, MCOperand_getImm(Op));
2086
0
}
2087
2088
void printAdrpLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
2089
0
{
2090
0
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AdrpLabel, OpNum);
2091
0
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
2092
2093
  // If the label has already been resolved to an immediate offset (say, when
2094
  // we're running the disassembler), just print the immediate.
2095
0
  if (MCOperand_isImm(Op)) {
2096
0
    const int64_t Offset = MCOperand_getImm(Op) * 4096;
2097
0
    SStream_concat0(O, markup("<imm:"));
2098
0
    if (MI->csh->PrintBranchImmAsAddress)
2099
0
      printUInt64(O, ((Address & -4096) + Offset));
2100
0
    else {
2101
0
      printUInt64Bang(O, Offset);
2102
0
    }
2103
0
    SStream_concat0(O, markup(">"));
2104
0
    return;
2105
0
  }
2106
2107
0
  printUInt64Bang(O, MCOperand_getImm(Op));
2108
0
}
2109
2110
void printAdrAdrpLabel(MCInst *MI, uint64_t Address, unsigned OpNum, SStream *O)
2111
6.35k
{
2112
6.35k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AdrAdrpLabel, OpNum);
2113
6.35k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
2114
2115
  // If the label has already been resolved to an immediate offset (say, when
2116
  // we're running the disassembler), just print the immediate.
2117
6.35k
  if (MCOperand_isImm(Op)) {
2118
6.35k
    int64_t Offset = MCOperand_getImm(Op);
2119
6.35k
    if (MCInst_getOpcode(MI) == AArch64_ADRP) {
2120
1.29k
      Offset = Offset * 4096;
2121
1.29k
      Address = Address & -4096;
2122
1.29k
    }
2123
6.35k
    SStream_concat0(O, markup(">"));
2124
6.35k
    if (MI->csh->PrintBranchImmAsAddress)
2125
6.35k
      printUInt64(O, (Address + Offset));
2126
0
    else {
2127
0
      printUInt64Bang(O, Offset);
2128
0
    }
2129
6.35k
    SStream_concat0(O, markup(">"));
2130
6.35k
    return;
2131
6.35k
  }
2132
2133
0
  printUInt64Bang(O, MCOperand_getImm(Op));
2134
0
}
2135
2136
/// Not part of upstream LLVM.
2137
/// Just prints the barrier options as documented in
2138
/// https://github.com/AsahiLinux/docs/blob/main/docs/hw/cpu/apple-instructions.md
2139
void printAppleSysBarrierOption(MCInst *MI, unsigned OpNo, SStream *O)
2140
251
{
2141
251
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AppleSysBarrierOption,
2142
251
        OpNo);
2143
251
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2144
251
  switch (Val) {
2145
5
  default:
2146
5
    SStream_concat0(O, "<undefined>");
2147
5
    break;
2148
8
  case 0:
2149
8
    SStream_concat0(O, "osh");
2150
8
    break;
2151
1
  case 1:
2152
1
    SStream_concat0(O, "nsh");
2153
1
    break;
2154
234
  case 2:
2155
234
    SStream_concat0(O, "ish");
2156
234
    break;
2157
3
  case 3:
2158
3
    SStream_concat0(O, "sy");
2159
3
    break;
2160
251
  }
2161
251
}
2162
2163
void printBarrierOption(MCInst *MI, unsigned OpNo, SStream *O)
2164
726
{
2165
726
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BarrierOption, OpNo);
2166
726
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2167
726
  unsigned Opcode = MCInst_getOpcode(MI);
2168
2169
726
  const char *Name;
2170
726
  if (Opcode == AArch64_ISB) {
2171
107
    const AArch64ISB_ISB *ISB = AArch64ISB_lookupISBByEncoding(Val);
2172
107
    Name = ISB ? ISB->Name : "";
2173
619
  } else if (Opcode == AArch64_TSB) {
2174
199
    const AArch64TSB_TSB *TSB = AArch64TSB_lookupTSBByEncoding(Val);
2175
199
    Name = TSB ? TSB->Name : "";
2176
420
  } else {
2177
420
    const AArch64DB_DB *DB = AArch64DB_lookupDBByEncoding(Val);
2178
420
    Name = DB ? DB->Name : "";
2179
420
  }
2180
726
  if (Name[0] != '\0')
2181
524
    SStream_concat0(O, Name);
2182
202
  else {
2183
202
    SStream_concat(O, "%s", markup("<imm:"));
2184
202
    printUInt32Bang(O, Val);
2185
202
    SStream_concat0(O, markup(">"));
2186
202
  }
2187
726
}
2188
2189
void printBarriernXSOption(MCInst *MI, unsigned OpNo, SStream *O)
2190
64
{
2191
64
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BarriernXSOption, OpNo);
2192
64
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2193
2194
64
  const char *Name;
2195
64
  const AArch64DBnXS_DBnXS *DB = AArch64DBnXS_lookupDBnXSByEncoding(Val);
2196
64
  Name = DB ? DB->Name : "";
2197
2198
64
  if (Name[0] != '\0')
2199
64
    SStream_concat0(O, Name);
2200
0
  else {
2201
0
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", Val);
2202
0
    SStream_concat0(O, markup(">"));
2203
0
  }
2204
64
}
2205
2206
static bool isValidSysReg(const AArch64SysReg_SysReg *Reg, bool Read,
2207
        unsigned mode)
2208
4.24k
{
2209
4.24k
  return (Reg && (Read ? Reg->Readable : Reg->Writeable) &&
2210
456
    AArch64_testFeatureList(mode, Reg->FeaturesRequired));
2211
4.24k
}
2212
2213
// Looks up a system register either by encoding or by name. Some system
2214
// registers share the same encoding between different architectures,
2215
// therefore a tablegen lookup by encoding will return an entry regardless
2216
// of the register's predication on a specific subtarget feature. To work
2217
// around this problem we keep an alternative name for such registers and
2218
// look them up by that name if the first lookup was unsuccessful.
2219
static const AArch64SysReg_SysReg *lookupSysReg(unsigned Val, bool Read,
2220
            unsigned mode)
2221
3.53k
{
2222
3.53k
  const AArch64SysReg_SysReg *Reg =
2223
3.53k
    AArch64SysReg_lookupSysRegByEncoding(Val);
2224
2225
3.53k
  if (Reg && !isValidSysReg(Reg, Read, mode))
2226
480
    Reg = AArch64SysReg_lookupSysRegByName(Reg->AltName);
2227
2228
3.53k
  return Reg;
2229
3.53k
}
2230
2231
void printMRSSystemRegister(MCInst *MI, unsigned OpNo, SStream *O)
2232
1.25k
{
2233
1.25k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MRSSystemRegister, OpNo);
2234
1.25k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2235
2236
  // Horrible hack for the one register that has identical encodings but
2237
  // different names in MSR and MRS. Because of this, one of MRS and MSR is
2238
  // going to get the wrong entry
2239
1.25k
  if (Val == AARCH64_SYSREG_DBGDTRRX_EL0) {
2240
268
    SStream_concat0(O, "DBGDTRRX_EL0");
2241
268
    return;
2242
268
  }
2243
2244
  // Horrible hack for two different registers having the same encoding.
2245
982
  if (Val == AARCH64_SYSREG_TRCEXTINSELR) {
2246
40
    SStream_concat0(O, "TRCEXTINSELR");
2247
40
    return;
2248
40
  }
2249
2250
942
  const AArch64SysReg_SysReg *Reg =
2251
942
    lookupSysReg(Val, true /*Read*/, MI->csh->mode);
2252
2253
942
  if (isValidSysReg(Reg, true /*Read*/, MI->csh->mode))
2254
94
    SStream_concat0(O, Reg->Name);
2255
848
  else {
2256
848
    char result[AARCH64_GRS_LEN + 1] = { 0 };
2257
848
    AArch64SysReg_genericRegisterString(Val, result);
2258
848
    SStream_concat0(O, result);
2259
848
  }
2260
942
}
2261
2262
void printMSRSystemRegister(MCInst *MI, unsigned OpNo, SStream *O)
2263
2.74k
{
2264
2.74k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MSRSystemRegister, OpNo);
2265
2.74k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2266
2267
  // Horrible hack for the one register that has identical encodings but
2268
  // different names in MSR and MRS. Because of this, one of MRS and MSR is
2269
  // going to get the wrong entry
2270
2.74k
  if (Val == AARCH64_SYSREG_DBGDTRTX_EL0) {
2271
130
    SStream_concat0(O, "DBGDTRTX_EL0");
2272
130
    return;
2273
130
  }
2274
2275
  // Horrible hack for two different registers having the same encoding.
2276
2.61k
  if (Val == AARCH64_SYSREG_TRCEXTINSELR) {
2277
18
    SStream_concat0(O, "TRCEXTINSELR");
2278
18
    return;
2279
18
  }
2280
2281
2.59k
  const AArch64SysReg_SysReg *Reg =
2282
2.59k
    lookupSysReg(Val, false /*Read*/, MI->csh->mode);
2283
2284
2.59k
  if (isValidSysReg(Reg, false /*Read*/, MI->csh->mode))
2285
134
    SStream_concat0(O, Reg->Name);
2286
2.46k
  else {
2287
2.46k
    char result[AARCH64_GRS_LEN + 1] = { 0 };
2288
2.46k
    AArch64SysReg_genericRegisterString(Val, result);
2289
2.46k
    SStream_concat0(O, result);
2290
2.46k
  }
2291
2.59k
}
2292
2293
void printSystemPStateField(MCInst *MI, unsigned OpNo, SStream *O)
2294
234
{
2295
234
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SystemPStateField, OpNo);
2296
234
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2297
2298
234
  const AArch64PState_PStateImm0_15 *PStateImm15 =
2299
234
    AArch64PState_lookupPStateImm0_15ByEncoding(Val);
2300
234
  const AArch64PState_PStateImm0_1 *PStateImm1 =
2301
234
    AArch64PState_lookupPStateImm0_1ByEncoding(Val);
2302
234
  if (PStateImm15 &&
2303
108
      AArch64_testFeatureList(MI->csh->mode,
2304
108
            PStateImm15->FeaturesRequired))
2305
108
    SStream_concat0(O, PStateImm15->Name);
2306
126
  else if (PStateImm1 &&
2307
126
     AArch64_testFeatureList(MI->csh->mode,
2308
126
           PStateImm1->FeaturesRequired))
2309
126
    SStream_concat0(O, PStateImm1->Name);
2310
0
  else {
2311
0
    printUInt32Bang(O, (Val));
2312
0
    SStream_concat1(O, '\0');
2313
0
  }
2314
234
}
2315
2316
void printSIMDType10Operand(MCInst *MI, unsigned OpNo, SStream *O)
2317
376
{
2318
376
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SIMDType10Operand, OpNo);
2319
376
  unsigned RawVal = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2320
376
  uint64_t Val = AArch64_AM_decodeAdvSIMDModImmType10(RawVal);
2321
376
  SStream_concat(O, "%s#%#016llx", markup("<imm:"), Val);
2322
376
  SStream_concat0(O, markup(">"));
2323
376
}
2324
2325
#define DEFINE_printComplexRotationOp(Angle, Remainder) \
2326
  static void CONCAT(printComplexRotationOp, CONCAT(Angle, Remainder))( \
2327
    MCInst * MI, unsigned OpNo, SStream *O) \
2328
2.46k
  { \
2329
2.46k
    AArch64_add_cs_detail_2( \
2330
2.46k
      MI, \
2331
2.46k
      CONCAT(CONCAT(AArch64_OP_GROUP_ComplexRotationOp, \
2332
2.46k
              Angle), \
2333
2.46k
             Remainder), \
2334
2.46k
      OpNo, Angle, Remainder); \
2335
2.46k
    unsigned Val = \
2336
2.46k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
2337
2.46k
    SStream_concat(O, "%s", markup("<imm:")); \
2338
2.46k
    SStream_concat(O, "#%" PRId32, \
2339
2.46k
             (int32_t)((Val * Angle) + Remainder)); \
2340
2.46k
    SStream_concat0(O, markup(">")); \
2341
2.46k
  }
2342
300
DEFINE_printComplexRotationOp(180, 90);
2343
2.16k
DEFINE_printComplexRotationOp(90, 0);
2344
2345
void printSVEPattern(MCInst *MI, unsigned OpNum, SStream *O)
2346
3.35k
{
2347
3.35k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SVEPattern, OpNum);
2348
3.35k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
2349
3.35k
  const AArch64SVEPredPattern_SVEPREDPAT *Pat =
2350
3.35k
    AArch64SVEPredPattern_lookupSVEPREDPATByEncoding(Val);
2351
3.35k
  if (Pat)
2352
2.01k
    SStream_concat0(O, Pat->Name);
2353
1.33k
  else
2354
1.33k
    printUInt32Bang(O, Val);
2355
3.35k
}
2356
2357
void printSVEVecLenSpecifier(MCInst *MI, unsigned OpNum, SStream *O)
2358
921
{
2359
921
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SVEVecLenSpecifier, OpNum);
2360
921
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
2361
  // Pattern has only 1 bit
2362
921
  if (Val > 1)
2363
0
    CS_ASSERT_RET(0 && "Invalid vector length specifier");
2364
921
  const AArch64SVEVecLenSpecifier_SVEVECLENSPECIFIER *Pat =
2365
921
    AArch64SVEVecLenSpecifier_lookupSVEVECLENSPECIFIERByEncoding(
2366
921
      Val);
2367
921
  if (Pat)
2368
921
    SStream_concat0(O, Pat->Name);
2369
921
}
2370
2371
#define DEFINE_printSVERegOp(suffix) \
2372
  void CONCAT(printSVERegOp, suffix)(MCInst * MI, unsigned OpNum, \
2373
             SStream *O) \
2374
124k
  { \
2375
124k
    AArch64_add_cs_detail_1( \
2376
124k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
124k
      CHAR(suffix)); \
2378
124k
    switch (CHAR(suffix)) { \
2379
35.6k
    case '0': \
2380
58.1k
    case 'b': \
2381
86.6k
    case 'h': \
2382
105k
    case 's': \
2383
123k
    case 'd': \
2384
124k
    case 'q': \
2385
124k
      break; \
2386
123k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
124k
    } \
2389
124k
\
2390
124k
    unsigned Reg = \
2391
124k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
124k
    printRegName(O, Reg); \
2393
124k
    if (CHAR(suffix) != '0') { \
2394
88.9k
      SStream_concat1(O, '.'); \
2395
88.9k
      SStream_concat1(O, CHAR(suffix)); \
2396
88.9k
    } \
2397
124k
  }
printSVERegOp_b
Line
Count
Source
2374
22.4k
  { \
2375
22.4k
    AArch64_add_cs_detail_1( \
2376
22.4k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
22.4k
      CHAR(suffix)); \
2378
22.4k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
22.4k
    case 'b': \
2381
22.4k
    case 'h': \
2382
22.4k
    case 's': \
2383
22.4k
    case 'd': \
2384
22.4k
    case 'q': \
2385
22.4k
      break; \
2386
22.4k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
22.4k
    } \
2389
22.4k
\
2390
22.4k
    unsigned Reg = \
2391
22.4k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
22.4k
    printRegName(O, Reg); \
2393
22.4k
    if (CHAR(suffix) != '0') { \
2394
22.4k
      SStream_concat1(O, '.'); \
2395
22.4k
      SStream_concat1(O, CHAR(suffix)); \
2396
22.4k
    } \
2397
22.4k
  }
printSVERegOp_d
Line
Count
Source
2374
18.1k
  { \
2375
18.1k
    AArch64_add_cs_detail_1( \
2376
18.1k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
18.1k
      CHAR(suffix)); \
2378
18.1k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
0
    case 'h': \
2382
0
    case 's': \
2383
18.1k
    case 'd': \
2384
18.1k
    case 'q': \
2385
18.1k
      break; \
2386
18.1k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
18.1k
    } \
2389
18.1k
\
2390
18.1k
    unsigned Reg = \
2391
18.1k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
18.1k
    printRegName(O, Reg); \
2393
18.1k
    if (CHAR(suffix) != '0') { \
2394
18.1k
      SStream_concat1(O, '.'); \
2395
18.1k
      SStream_concat1(O, CHAR(suffix)); \
2396
18.1k
    } \
2397
18.1k
  }
printSVERegOp_h
Line
Count
Source
2374
28.5k
  { \
2375
28.5k
    AArch64_add_cs_detail_1( \
2376
28.5k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
28.5k
      CHAR(suffix)); \
2378
28.5k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
28.5k
    case 'h': \
2382
28.5k
    case 's': \
2383
28.5k
    case 'd': \
2384
28.5k
    case 'q': \
2385
28.5k
      break; \
2386
28.5k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
28.5k
    } \
2389
28.5k
\
2390
28.5k
    unsigned Reg = \
2391
28.5k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
28.5k
    printRegName(O, Reg); \
2393
28.5k
    if (CHAR(suffix) != '0') { \
2394
28.5k
      SStream_concat1(O, '.'); \
2395
28.5k
      SStream_concat1(O, CHAR(suffix)); \
2396
28.5k
    } \
2397
28.5k
  }
printSVERegOp_s
Line
Count
Source
2374
18.6k
  { \
2375
18.6k
    AArch64_add_cs_detail_1( \
2376
18.6k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
18.6k
      CHAR(suffix)); \
2378
18.6k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
0
    case 'h': \
2382
18.6k
    case 's': \
2383
18.6k
    case 'd': \
2384
18.6k
    case 'q': \
2385
18.6k
      break; \
2386
18.6k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
18.6k
    } \
2389
18.6k
\
2390
18.6k
    unsigned Reg = \
2391
18.6k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
18.6k
    printRegName(O, Reg); \
2393
18.6k
    if (CHAR(suffix) != '0') { \
2394
18.6k
      SStream_concat1(O, '.'); \
2395
18.6k
      SStream_concat1(O, CHAR(suffix)); \
2396
18.6k
    } \
2397
18.6k
  }
printSVERegOp_0
Line
Count
Source
2374
35.6k
  { \
2375
35.6k
    AArch64_add_cs_detail_1( \
2376
35.6k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
35.6k
      CHAR(suffix)); \
2378
35.6k
    switch (CHAR(suffix)) { \
2379
35.6k
    case '0': \
2380
35.6k
    case 'b': \
2381
35.6k
    case 'h': \
2382
35.6k
    case 's': \
2383
35.6k
    case 'd': \
2384
35.6k
    case 'q': \
2385
35.6k
      break; \
2386
35.6k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
35.6k
    } \
2389
35.6k
\
2390
35.6k
    unsigned Reg = \
2391
35.6k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
35.6k
    printRegName(O, Reg); \
2393
35.6k
    if (CHAR(suffix) != '0') { \
2394
0
      SStream_concat1(O, '.'); \
2395
0
      SStream_concat1(O, CHAR(suffix)); \
2396
0
    } \
2397
35.6k
  }
printSVERegOp_q
Line
Count
Source
2374
1.13k
  { \
2375
1.13k
    AArch64_add_cs_detail_1( \
2376
1.13k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
1.13k
      CHAR(suffix)); \
2378
1.13k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
0
    case 'h': \
2382
0
    case 's': \
2383
0
    case 'd': \
2384
1.13k
    case 'q': \
2385
1.13k
      break; \
2386
0
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
1.13k
    } \
2389
1.13k
\
2390
1.13k
    unsigned Reg = \
2391
1.13k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
1.13k
    printRegName(O, Reg); \
2393
1.13k
    if (CHAR(suffix) != '0') { \
2394
1.13k
      SStream_concat1(O, '.'); \
2395
1.13k
      SStream_concat1(O, CHAR(suffix)); \
2396
1.13k
    } \
2397
1.13k
  }
2398
DEFINE_printSVERegOp(b);
2399
DEFINE_printSVERegOp(d);
2400
DEFINE_printSVERegOp(h);
2401
DEFINE_printSVERegOp(s);
2402
DEFINE_printSVERegOp(0);
2403
DEFINE_printSVERegOp(q);
2404
2405
#define DECLARE_printImmSVE_S32(T) \
2406
  void CONCAT(printImmSVE, T)(T Val, SStream * O) \
2407
2.01k
  { \
2408
2.01k
    printInt32Bang(O, Val); \
2409
2.01k
  }
printImmSVE_int16_t
Line
Count
Source
2407
1.05k
  { \
2408
1.05k
    printInt32Bang(O, Val); \
2409
1.05k
  }
printImmSVE_int8_t
Line
Count
Source
2407
431
  { \
2408
431
    printInt32Bang(O, Val); \
2409
431
  }
printImmSVE_int32_t
Line
Count
Source
2407
527
  { \
2408
527
    printInt32Bang(O, Val); \
2409
527
  }
2410
DECLARE_printImmSVE_S32(int16_t);
2411
DECLARE_printImmSVE_S32(int8_t);
2412
DECLARE_printImmSVE_S32(int32_t);
2413
2414
#define DECLARE_printImmSVE_U32(T) \
2415
  void CONCAT(printImmSVE, T)(T Val, SStream * O) \
2416
325
  { \
2417
325
    printUInt32Bang(O, Val); \
2418
325
  }
printImmSVE_uint16_t
Line
Count
Source
2416
137
  { \
2417
137
    printUInt32Bang(O, Val); \
2418
137
  }
printImmSVE_uint8_t
Line
Count
Source
2416
82
  { \
2417
82
    printUInt32Bang(O, Val); \
2418
82
  }
printImmSVE_uint32_t
Line
Count
Source
2416
106
  { \
2417
106
    printUInt32Bang(O, Val); \
2418
106
  }
2419
DECLARE_printImmSVE_U32(uint16_t);
2420
DECLARE_printImmSVE_U32(uint8_t);
2421
DECLARE_printImmSVE_U32(uint32_t);
2422
2423
#define DECLARE_printImmSVE_S64(T) \
2424
  void CONCAT(printImmSVE, T)(T Val, SStream * O) \
2425
607
  { \
2426
607
    printInt64Bang(O, Val); \
2427
607
  }
2428
DECLARE_printImmSVE_S64(int64_t);
2429
2430
#define DECLARE_printImmSVE_U64(T) \
2431
  void CONCAT(printImmSVE, T)(T Val, SStream * O) \
2432
208
  { \
2433
208
    printUInt64Bang(O, Val); \
2434
208
  }
2435
DECLARE_printImmSVE_U64(uint64_t);
2436
2437
#define DEFINE_isSignedType(T) \
2438
  static inline bool CONCAT(isSignedType, T)() \
2439
1.61k
  { \
2440
1.61k
    return CHAR(T) == 'i'; \
2441
1.61k
  }
AArch64InstPrinter.c:isSignedType_int16_t
Line
Count
Source
2439
172
  { \
2440
172
    return CHAR(T) == 'i'; \
2441
172
  }
AArch64InstPrinter.c:isSignedType_int8_t
Line
Count
Source
2439
431
  { \
2440
431
    return CHAR(T) == 'i'; \
2441
431
  }
AArch64InstPrinter.c:isSignedType_int64_t
Line
Count
Source
2439
249
  { \
2440
249
    return CHAR(T) == 'i'; \
2441
249
  }
AArch64InstPrinter.c:isSignedType_int32_t
Line
Count
Source
2439
233
  { \
2440
233
    return CHAR(T) == 'i'; \
2441
233
  }
AArch64InstPrinter.c:isSignedType_uint16_t
Line
Count
Source
2439
137
  { \
2440
137
    return CHAR(T) == 'i'; \
2441
137
  }
AArch64InstPrinter.c:isSignedType_uint8_t
Line
Count
Source
2439
82
  { \
2440
82
    return CHAR(T) == 'i'; \
2441
82
  }
AArch64InstPrinter.c:isSignedType_uint64_t
Line
Count
Source
2439
208
  { \
2440
208
    return CHAR(T) == 'i'; \
2441
208
  }
AArch64InstPrinter.c:isSignedType_uint32_t
Line
Count
Source
2439
106
  { \
2440
106
    return CHAR(T) == 'i'; \
2441
106
  }
2442
DEFINE_isSignedType(int8_t);
2443
DEFINE_isSignedType(int16_t);
2444
DEFINE_isSignedType(int32_t);
2445
DEFINE_isSignedType(int64_t);
2446
DEFINE_isSignedType(uint8_t);
2447
DEFINE_isSignedType(uint16_t);
2448
DEFINE_isSignedType(uint32_t);
2449
DEFINE_isSignedType(uint64_t);
2450
2451
#define DEFINE_printImm8OptLsl(T) \
2452
  void CONCAT(printImm8OptLsl, T)(MCInst * MI, unsigned OpNum, \
2453
          SStream *O) \
2454
1.96k
  { \
2455
1.96k
    AArch64_add_cs_detail_1( \
2456
1.96k
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
1.96k
      sizeof(T)); \
2458
1.96k
    unsigned UnscaledVal = \
2459
1.96k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
1.96k
    unsigned Shift = \
2461
1.96k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
1.96k
\
2463
1.96k
    if ((UnscaledVal == 0) && \
2464
1.96k
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
347
      SStream_concat(O, "%s", markup("<imm:")); \
2466
347
      SStream_concat1(O, '#'); \
2467
347
      printUInt64(O, (UnscaledVal)); \
2468
347
      SStream_concat0(O, markup(">")); \
2469
347
      printShifter(MI, OpNum + 1, O); \
2470
347
      return; \
2471
347
    } \
2472
1.96k
\
2473
1.96k
    T Val; \
2474
1.61k
    if (CONCAT(isSignedType, T)()) \
2475
1.61k
      Val = (int8_t)UnscaledVal * \
2476
1.08k
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
1.61k
    else \
2478
1.61k
      Val = (uint8_t)UnscaledVal * \
2479
533
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
1.61k
\
2481
1.61k
    CONCAT(printImmSVE, T)(Val, O); \
2482
1.61k
  }
printImm8OptLsl_int16_t
Line
Count
Source
2454
227
  { \
2455
227
    AArch64_add_cs_detail_1( \
2456
227
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
227
      sizeof(T)); \
2458
227
    unsigned UnscaledVal = \
2459
227
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
227
    unsigned Shift = \
2461
227
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
227
\
2463
227
    if ((UnscaledVal == 0) && \
2464
227
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
55
      SStream_concat(O, "%s", markup("<imm:")); \
2466
55
      SStream_concat1(O, '#'); \
2467
55
      printUInt64(O, (UnscaledVal)); \
2468
55
      SStream_concat0(O, markup(">")); \
2469
55
      printShifter(MI, OpNum + 1, O); \
2470
55
      return; \
2471
55
    } \
2472
227
\
2473
227
    T Val; \
2474
172
    if (CONCAT(isSignedType, T)()) \
2475
172
      Val = (int8_t)UnscaledVal * \
2476
172
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
172
    else \
2478
172
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
172
\
2481
172
    CONCAT(printImmSVE, T)(Val, O); \
2482
172
  }
printImm8OptLsl_int8_t
Line
Count
Source
2454
431
  { \
2455
431
    AArch64_add_cs_detail_1( \
2456
431
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
431
      sizeof(T)); \
2458
431
    unsigned UnscaledVal = \
2459
431
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
431
    unsigned Shift = \
2461
431
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
431
\
2463
431
    if ((UnscaledVal == 0) && \
2464
431
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
0
      SStream_concat(O, "%s", markup("<imm:")); \
2466
0
      SStream_concat1(O, '#'); \
2467
0
      printUInt64(O, (UnscaledVal)); \
2468
0
      SStream_concat0(O, markup(">")); \
2469
0
      printShifter(MI, OpNum + 1, O); \
2470
0
      return; \
2471
0
    } \
2472
431
\
2473
431
    T Val; \
2474
431
    if (CONCAT(isSignedType, T)()) \
2475
431
      Val = (int8_t)UnscaledVal * \
2476
431
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
431
    else \
2478
431
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
431
\
2481
431
    CONCAT(printImmSVE, T)(Val, O); \
2482
431
  }
printImm8OptLsl_int64_t
Line
Count
Source
2454
334
  { \
2455
334
    AArch64_add_cs_detail_1( \
2456
334
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
334
      sizeof(T)); \
2458
334
    unsigned UnscaledVal = \
2459
334
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
334
    unsigned Shift = \
2461
334
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
334
\
2463
334
    if ((UnscaledVal == 0) && \
2464
334
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
85
      SStream_concat(O, "%s", markup("<imm:")); \
2466
85
      SStream_concat1(O, '#'); \
2467
85
      printUInt64(O, (UnscaledVal)); \
2468
85
      SStream_concat0(O, markup(">")); \
2469
85
      printShifter(MI, OpNum + 1, O); \
2470
85
      return; \
2471
85
    } \
2472
334
\
2473
334
    T Val; \
2474
249
    if (CONCAT(isSignedType, T)()) \
2475
249
      Val = (int8_t)UnscaledVal * \
2476
249
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
249
    else \
2478
249
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
249
\
2481
249
    CONCAT(printImmSVE, T)(Val, O); \
2482
249
  }
printImm8OptLsl_int32_t
Line
Count
Source
2454
247
  { \
2455
247
    AArch64_add_cs_detail_1( \
2456
247
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
247
      sizeof(T)); \
2458
247
    unsigned UnscaledVal = \
2459
247
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
247
    unsigned Shift = \
2461
247
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
247
\
2463
247
    if ((UnscaledVal == 0) && \
2464
247
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
14
      SStream_concat(O, "%s", markup("<imm:")); \
2466
14
      SStream_concat1(O, '#'); \
2467
14
      printUInt64(O, (UnscaledVal)); \
2468
14
      SStream_concat0(O, markup(">")); \
2469
14
      printShifter(MI, OpNum + 1, O); \
2470
14
      return; \
2471
14
    } \
2472
247
\
2473
247
    T Val; \
2474
233
    if (CONCAT(isSignedType, T)()) \
2475
233
      Val = (int8_t)UnscaledVal * \
2476
233
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
233
    else \
2478
233
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
233
\
2481
233
    CONCAT(printImmSVE, T)(Val, O); \
2482
233
  }
printImm8OptLsl_uint16_t
Line
Count
Source
2454
222
  { \
2455
222
    AArch64_add_cs_detail_1( \
2456
222
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
222
      sizeof(T)); \
2458
222
    unsigned UnscaledVal = \
2459
222
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
222
    unsigned Shift = \
2461
222
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
222
\
2463
222
    if ((UnscaledVal == 0) && \
2464
222
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
85
      SStream_concat(O, "%s", markup("<imm:")); \
2466
85
      SStream_concat1(O, '#'); \
2467
85
      printUInt64(O, (UnscaledVal)); \
2468
85
      SStream_concat0(O, markup(">")); \
2469
85
      printShifter(MI, OpNum + 1, O); \
2470
85
      return; \
2471
85
    } \
2472
222
\
2473
222
    T Val; \
2474
137
    if (CONCAT(isSignedType, T)()) \
2475
137
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
137
    else \
2478
137
      Val = (uint8_t)UnscaledVal * \
2479
137
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
137
\
2481
137
    CONCAT(printImmSVE, T)(Val, O); \
2482
137
  }
printImm8OptLsl_uint8_t
Line
Count
Source
2454
82
  { \
2455
82
    AArch64_add_cs_detail_1( \
2456
82
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
82
      sizeof(T)); \
2458
82
    unsigned UnscaledVal = \
2459
82
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
82
    unsigned Shift = \
2461
82
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
82
\
2463
82
    if ((UnscaledVal == 0) && \
2464
82
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
0
      SStream_concat(O, "%s", markup("<imm:")); \
2466
0
      SStream_concat1(O, '#'); \
2467
0
      printUInt64(O, (UnscaledVal)); \
2468
0
      SStream_concat0(O, markup(">")); \
2469
0
      printShifter(MI, OpNum + 1, O); \
2470
0
      return; \
2471
0
    } \
2472
82
\
2473
82
    T Val; \
2474
82
    if (CONCAT(isSignedType, T)()) \
2475
82
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
82
    else \
2478
82
      Val = (uint8_t)UnscaledVal * \
2479
82
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
82
\
2481
82
    CONCAT(printImmSVE, T)(Val, O); \
2482
82
  }
printImm8OptLsl_uint64_t
Line
Count
Source
2454
291
  { \
2455
291
    AArch64_add_cs_detail_1( \
2456
291
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
291
      sizeof(T)); \
2458
291
    unsigned UnscaledVal = \
2459
291
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
291
    unsigned Shift = \
2461
291
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
291
\
2463
291
    if ((UnscaledVal == 0) && \
2464
291
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
83
      SStream_concat(O, "%s", markup("<imm:")); \
2466
83
      SStream_concat1(O, '#'); \
2467
83
      printUInt64(O, (UnscaledVal)); \
2468
83
      SStream_concat0(O, markup(">")); \
2469
83
      printShifter(MI, OpNum + 1, O); \
2470
83
      return; \
2471
83
    } \
2472
291
\
2473
291
    T Val; \
2474
208
    if (CONCAT(isSignedType, T)()) \
2475
208
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
208
    else \
2478
208
      Val = (uint8_t)UnscaledVal * \
2479
208
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
208
\
2481
208
    CONCAT(printImmSVE, T)(Val, O); \
2482
208
  }
printImm8OptLsl_uint32_t
Line
Count
Source
2454
131
  { \
2455
131
    AArch64_add_cs_detail_1( \
2456
131
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
131
      sizeof(T)); \
2458
131
    unsigned UnscaledVal = \
2459
131
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
131
    unsigned Shift = \
2461
131
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
131
\
2463
131
    if ((UnscaledVal == 0) && \
2464
131
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
25
      SStream_concat(O, "%s", markup("<imm:")); \
2466
25
      SStream_concat1(O, '#'); \
2467
25
      printUInt64(O, (UnscaledVal)); \
2468
25
      SStream_concat0(O, markup(">")); \
2469
25
      printShifter(MI, OpNum + 1, O); \
2470
25
      return; \
2471
25
    } \
2472
131
\
2473
131
    T Val; \
2474
106
    if (CONCAT(isSignedType, T)()) \
2475
106
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
106
    else \
2478
106
      Val = (uint8_t)UnscaledVal * \
2479
106
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
106
\
2481
106
    CONCAT(printImmSVE, T)(Val, O); \
2482
106
  }
2483
DEFINE_printImm8OptLsl(int16_t);
2484
DEFINE_printImm8OptLsl(int8_t);
2485
DEFINE_printImm8OptLsl(int64_t);
2486
DEFINE_printImm8OptLsl(int32_t);
2487
DEFINE_printImm8OptLsl(uint16_t);
2488
DEFINE_printImm8OptLsl(uint8_t);
2489
DEFINE_printImm8OptLsl(uint64_t);
2490
DEFINE_printImm8OptLsl(uint32_t);
2491
2492
#define DEFINE_printSVELogicalImm(T) \
2493
  void CONCAT(printSVELogicalImm, T)(MCInst * MI, unsigned OpNum, \
2494
             SStream *O) \
2495
1.98k
  { \
2496
1.98k
    AArch64_add_cs_detail_1( \
2497
1.98k
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
1.98k
      sizeof(T)); \
2499
1.98k
    typedef T SignedT; \
2500
1.98k
    typedef CONCATS(u, T) UnsignedT; \
2501
1.98k
\
2502
1.98k
    uint64_t Val = \
2503
1.98k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
1.98k
    UnsignedT PrintVal = \
2505
1.98k
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
1.98k
\
2507
1.98k
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
1.98k
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
1.98k
    else if ((uint16_t)PrintVal == PrintVal) \
2510
715
      CONCAT(printImmSVE, T)(PrintVal, O); \
2511
715
    else { \
2512
449
      SStream_concat(O, "%s", markup("<imm:")); \
2513
449
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2514
449
      SStream_concat0(O, markup(">")); \
2515
449
    } \
2516
1.98k
  }
printSVELogicalImm_int16_t
Line
Count
Source
2495
887
  { \
2496
887
    AArch64_add_cs_detail_1( \
2497
887
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
887
      sizeof(T)); \
2499
887
    typedef T SignedT; \
2500
887
    typedef CONCATS(u, T) UnsignedT; \
2501
887
\
2502
887
    uint64_t Val = \
2503
887
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
887
    UnsignedT PrintVal = \
2505
887
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
887
\
2507
887
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
887
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
887
    else if ((uint16_t)PrintVal == PrintVal) \
2510
0
      CONCAT(printImmSVE, T)(PrintVal, O); \
2511
0
    else { \
2512
0
      SStream_concat(O, "%s", markup("<imm:")); \
2513
0
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2514
0
      SStream_concat0(O, markup(">")); \
2515
0
    } \
2516
887
  }
printSVELogicalImm_int32_t
Line
Count
Source
2495
450
  { \
2496
450
    AArch64_add_cs_detail_1( \
2497
450
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
450
      sizeof(T)); \
2499
450
    typedef T SignedT; \
2500
450
    typedef CONCATS(u, T) UnsignedT; \
2501
450
\
2502
450
    uint64_t Val = \
2503
450
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
450
    UnsignedT PrintVal = \
2505
450
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
450
\
2507
450
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
450
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
450
    else if ((uint16_t)PrintVal == PrintVal) \
2510
173
      CONCAT(printImmSVE, T)(PrintVal, O); \
2511
173
    else { \
2512
156
      SStream_concat(O, "%s", markup("<imm:")); \
2513
156
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2514
156
      SStream_concat0(O, markup(">")); \
2515
156
    } \
2516
450
  }
printSVELogicalImm_int64_t
Line
Count
Source
2495
651
  { \
2496
651
    AArch64_add_cs_detail_1( \
2497
651
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
651
      sizeof(T)); \
2499
651
    typedef T SignedT; \
2500
651
    typedef CONCATS(u, T) UnsignedT; \
2501
651
\
2502
651
    uint64_t Val = \
2503
651
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
651
    UnsignedT PrintVal = \
2505
651
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
651
\
2507
651
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
651
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
651
    else if ((uint16_t)PrintVal == PrintVal) \
2510
542
      CONCAT(printImmSVE, T)(PrintVal, O); \
2511
542
    else { \
2512
293
      SStream_concat(O, "%s", markup("<imm:")); \
2513
293
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2514
293
      SStream_concat0(O, markup(">")); \
2515
293
    } \
2516
651
  }
2517
DEFINE_printSVELogicalImm(int16_t);
2518
DEFINE_printSVELogicalImm(int32_t);
2519
DEFINE_printSVELogicalImm(int64_t);
2520
2521
#define DEFINE_printZPRasFPR(Width) \
2522
  void CONCAT(printZPRasFPR, Width)(MCInst * MI, unsigned OpNum, \
2523
            SStream *O) \
2524
1.27k
  { \
2525
1.27k
    AArch64_add_cs_detail_1( \
2526
1.27k
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
1.27k
      Width); \
2528
1.27k
    unsigned Base; \
2529
1.27k
    switch (Width) { \
2530
176
    case 8: \
2531
176
      Base = AArch64_B0; \
2532
176
      break; \
2533
133
    case 16: \
2534
133
      Base = AArch64_H0; \
2535
133
      break; \
2536
403
    case 32: \
2537
403
      Base = AArch64_S0; \
2538
403
      break; \
2539
497
    case 64: \
2540
497
      Base = AArch64_D0; \
2541
497
      break; \
2542
69
    case 128: \
2543
69
      Base = AArch64_Q0; \
2544
69
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
1.27k
    } \
2548
1.27k
    unsigned Reg = \
2549
1.27k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
1.27k
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
1.27k
  }
printZPRasFPR_8
Line
Count
Source
2524
176
  { \
2525
176
    AArch64_add_cs_detail_1( \
2526
176
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
176
      Width); \
2528
176
    unsigned Base; \
2529
176
    switch (Width) { \
2530
176
    case 8: \
2531
176
      Base = AArch64_B0; \
2532
176
      break; \
2533
0
    case 16: \
2534
0
      Base = AArch64_H0; \
2535
0
      break; \
2536
0
    case 32: \
2537
0
      Base = AArch64_S0; \
2538
0
      break; \
2539
0
    case 64: \
2540
0
      Base = AArch64_D0; \
2541
0
      break; \
2542
0
    case 128: \
2543
0
      Base = AArch64_Q0; \
2544
0
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
176
    } \
2548
176
    unsigned Reg = \
2549
176
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
176
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
176
  }
printZPRasFPR_64
Line
Count
Source
2524
497
  { \
2525
497
    AArch64_add_cs_detail_1( \
2526
497
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
497
      Width); \
2528
497
    unsigned Base; \
2529
497
    switch (Width) { \
2530
0
    case 8: \
2531
0
      Base = AArch64_B0; \
2532
0
      break; \
2533
0
    case 16: \
2534
0
      Base = AArch64_H0; \
2535
0
      break; \
2536
0
    case 32: \
2537
0
      Base = AArch64_S0; \
2538
0
      break; \
2539
497
    case 64: \
2540
497
      Base = AArch64_D0; \
2541
497
      break; \
2542
0
    case 128: \
2543
0
      Base = AArch64_Q0; \
2544
0
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
497
    } \
2548
497
    unsigned Reg = \
2549
497
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
497
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
497
  }
printZPRasFPR_16
Line
Count
Source
2524
133
  { \
2525
133
    AArch64_add_cs_detail_1( \
2526
133
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
133
      Width); \
2528
133
    unsigned Base; \
2529
133
    switch (Width) { \
2530
0
    case 8: \
2531
0
      Base = AArch64_B0; \
2532
0
      break; \
2533
133
    case 16: \
2534
133
      Base = AArch64_H0; \
2535
133
      break; \
2536
0
    case 32: \
2537
0
      Base = AArch64_S0; \
2538
0
      break; \
2539
0
    case 64: \
2540
0
      Base = AArch64_D0; \
2541
0
      break; \
2542
0
    case 128: \
2543
0
      Base = AArch64_Q0; \
2544
0
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
133
    } \
2548
133
    unsigned Reg = \
2549
133
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
133
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
133
  }
printZPRasFPR_32
Line
Count
Source
2524
403
  { \
2525
403
    AArch64_add_cs_detail_1( \
2526
403
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
403
      Width); \
2528
403
    unsigned Base; \
2529
403
    switch (Width) { \
2530
0
    case 8: \
2531
0
      Base = AArch64_B0; \
2532
0
      break; \
2533
0
    case 16: \
2534
0
      Base = AArch64_H0; \
2535
0
      break; \
2536
403
    case 32: \
2537
403
      Base = AArch64_S0; \
2538
403
      break; \
2539
0
    case 64: \
2540
0
      Base = AArch64_D0; \
2541
0
      break; \
2542
0
    case 128: \
2543
0
      Base = AArch64_Q0; \
2544
0
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
403
    } \
2548
403
    unsigned Reg = \
2549
403
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
403
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
403
  }
printZPRasFPR_128
Line
Count
Source
2524
69
  { \
2525
69
    AArch64_add_cs_detail_1( \
2526
69
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
69
      Width); \
2528
69
    unsigned Base; \
2529
69
    switch (Width) { \
2530
0
    case 8: \
2531
0
      Base = AArch64_B0; \
2532
0
      break; \
2533
0
    case 16: \
2534
0
      Base = AArch64_H0; \
2535
0
      break; \
2536
0
    case 32: \
2537
0
      Base = AArch64_S0; \
2538
0
      break; \
2539
0
    case 64: \
2540
0
      Base = AArch64_D0; \
2541
0
      break; \
2542
69
    case 128: \
2543
69
      Base = AArch64_Q0; \
2544
69
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
69
    } \
2548
69
    unsigned Reg = \
2549
69
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
69
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
69
  }
2552
DEFINE_printZPRasFPR(8);
2553
DEFINE_printZPRasFPR(64);
2554
DEFINE_printZPRasFPR(16);
2555
DEFINE_printZPRasFPR(32);
2556
DEFINE_printZPRasFPR(128);
2557
2558
#define DEFINE_printExactFPImm(ImmIs0, ImmIs1) \
2559
  void CONCAT(printExactFPImm, CONCAT(ImmIs0, ImmIs1))( \
2560
    MCInst * MI, unsigned OpNum, SStream *O) \
2561
474
  { \
2562
474
    AArch64_add_cs_detail_2( \
2563
474
      MI, \
2564
474
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
474
             ImmIs1), \
2566
474
      OpNum, ImmIs0, ImmIs1); \
2567
474
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
474
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
474
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
474
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
474
    unsigned Val = \
2572
474
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
474
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
474
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
474
    SStream_concat0(O, markup(">")); \
2576
474
  }
printExactFPImm_AArch64ExactFPImm_half_AArch64ExactFPImm_one
Line
Count
Source
2561
86
  { \
2562
86
    AArch64_add_cs_detail_2( \
2563
86
      MI, \
2564
86
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
86
             ImmIs1), \
2566
86
      OpNum, ImmIs0, ImmIs1); \
2567
86
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
86
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
86
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
86
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
86
    unsigned Val = \
2572
86
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
86
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
86
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
86
    SStream_concat0(O, markup(">")); \
2576
86
  }
printExactFPImm_AArch64ExactFPImm_zero_AArch64ExactFPImm_one
Line
Count
Source
2561
229
  { \
2562
229
    AArch64_add_cs_detail_2( \
2563
229
      MI, \
2564
229
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
229
             ImmIs1), \
2566
229
      OpNum, ImmIs0, ImmIs1); \
2567
229
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
229
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
229
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
229
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
229
    unsigned Val = \
2572
229
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
229
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
229
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
229
    SStream_concat0(O, markup(">")); \
2576
229
  }
printExactFPImm_AArch64ExactFPImm_half_AArch64ExactFPImm_two
Line
Count
Source
2561
159
  { \
2562
159
    AArch64_add_cs_detail_2( \
2563
159
      MI, \
2564
159
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
159
             ImmIs1), \
2566
159
      OpNum, ImmIs0, ImmIs1); \
2567
159
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
159
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
159
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
159
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
159
    unsigned Val = \
2572
159
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
159
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
159
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
159
    SStream_concat0(O, markup(">")); \
2576
159
  }
2577
DEFINE_printExactFPImm(AArch64ExactFPImm_half, AArch64ExactFPImm_one);
2578
DEFINE_printExactFPImm(AArch64ExactFPImm_zero, AArch64ExactFPImm_one);
2579
DEFINE_printExactFPImm(AArch64ExactFPImm_half, AArch64ExactFPImm_two);
2580
2581
void printGPR64as32(MCInst *MI, unsigned OpNum, SStream *O)
2582
2.52k
{
2583
2.52k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_GPR64as32, OpNum);
2584
2.52k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2585
2.52k
  printRegName(O, getWRegFromXReg(Reg));
2586
2.52k
}
2587
2588
void printGPR64x8(MCInst *MI, unsigned OpNum, SStream *O)
2589
242
{
2590
242
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_GPR64x8, OpNum);
2591
242
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2592
242
  printRegName(O,
2593
242
         MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_x8sub_0));
2594
242
}
2595
2596
void printSyspXzrPair(MCInst *MI, unsigned OpNum, SStream *O)
2597
574
{
2598
574
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SyspXzrPair, OpNum);
2599
574
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2600
2601
574
  SStream_concat(O, "%s%s", getRegisterName(Reg, AArch64_NoRegAltName),
2602
574
           ", ");
2603
574
  SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
2604
574
}
2605
2606
const char *AArch64_LLVM_getRegisterName(unsigned RegNo, unsigned AltIdx)
2607
145k
{
2608
145k
  return getRegisterName(RegNo, AltIdx);
2609
145k
}
2610
2611
void AArch64_LLVM_printInstruction(MCInst *MI, SStream *O,
2612
           void * /* MCRegisterInfo* */ info)
2613
245k
{
2614
245k
  printInst(MI, MI->address, "", O);
2615
245k
}