Coverage Report

Created: 2026-05-30 06:22

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