Coverage Report

Created: 2026-07-15 06:35

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
338k
#define CONCAT(a, b) CONCAT_(a, b)
49
338k
#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
557k
{
81
557k
  SStream_concat(OS, "%s%s", markup("<reg:"),
82
557k
           getRegisterName(Reg, AArch64_NoRegAltName));
83
557k
  SStream_concat0(OS, markup(">"));
84
557k
}
85
86
void printRegNameAlt(SStream *OS, unsigned Reg, unsigned AltIdx)
87
116k
{
88
116k
  SStream_concat(OS, "%s%s", markup("<reg:"),
89
116k
           getRegisterName(Reg, AltIdx));
90
116k
  SStream_concat0(OS, markup(">"));
91
116k
}
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
273k
{
100
273k
  bool isAlias = false;
101
273k
  bool useAliasDetails = map_use_alias_details(MI);
102
273k
  map_set_fill_detail_ops(MI, useAliasDetails);
103
104
273k
  unsigned Opcode = MCInst_getOpcode(MI);
105
106
273k
  if (Opcode == AArch64_SYSxt) {
107
2.83k
    if (printSysAlias(MI, O)) {
108
439
      isAlias = true;
109
439
      MCInst_setIsAlias(MI, isAlias);
110
439
      if (useAliasDetails)
111
439
        return;
112
439
    }
113
2.83k
  }
114
115
273k
  if (Opcode == AArch64_SYSPxt || Opcode == AArch64_SYSPxt_XZR) {
116
3.76k
    if (printSyspAlias(MI, O)) {
117
1.77k
      isAlias = true;
118
1.77k
      MCInst_setIsAlias(MI, isAlias);
119
1.77k
      if (useAliasDetails)
120
1.77k
        return;
121
1.77k
    }
122
3.76k
  }
123
124
  // RPRFM overlaps PRFM (reg), so try to print it as RPRFM here.
125
271k
  if ((Opcode == AArch64_PRFMroX) || (Opcode == AArch64_PRFMroW)) {
126
291
    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
291
  }
133
134
  // SBFM/UBFM should print to a nicer aliased form if possible.
135
271k
  if (Opcode == AArch64_SBFMXri || Opcode == AArch64_SBFMWri ||
136
270k
      Opcode == AArch64_UBFMXri || Opcode == AArch64_UBFMWri) {
137
2.58k
    MCOperand *Op0 = MCInst_getOperand(MI, (0));
138
2.58k
    MCOperand *Op1 = MCInst_getOperand(MI, (1));
139
2.58k
    MCOperand *Op2 = MCInst_getOperand(MI, (2));
140
2.58k
    MCOperand *Op3 = MCInst_getOperand(MI, (3));
141
142
2.58k
    bool IsSigned = (Opcode == AArch64_SBFMXri ||
143
1.98k
         Opcode == AArch64_SBFMWri);
144
2.58k
    bool Is64Bit = (Opcode == AArch64_SBFMXri ||
145
1.98k
        Opcode == AArch64_UBFMXri);
146
2.58k
    if (MCOperand_isImm(Op2) && MCOperand_getImm(Op2) == 0 &&
147
1.06k
        MCOperand_isImm(Op3)) {
148
1.06k
      const char *AsmMnemonic = NULL;
149
150
1.06k
      switch (MCOperand_getImm(Op3)) {
151
200
      default:
152
200
        break;
153
368
      case 7:
154
368
        if (IsSigned)
155
117
          AsmMnemonic = "sxtb";
156
251
        else if (!Is64Bit)
157
192
          AsmMnemonic = "uxtb";
158
368
        break;
159
199
      case 15:
160
199
        if (IsSigned)
161
89
          AsmMnemonic = "sxth";
162
110
        else if (!Is64Bit)
163
107
          AsmMnemonic = "uxth";
164
199
        break;
165
293
      case 31:
166
        // *xtw is only valid for signed 64-bit operations.
167
293
        if (Is64Bit && IsSigned)
168
43
          AsmMnemonic = "sxtw";
169
293
        break;
170
1.06k
      }
171
172
1.06k
      if (AsmMnemonic) {
173
548
        SStream_concat(O, "%s", AsmMnemonic);
174
548
        SStream_concat0(O, " ");
175
176
548
        printRegName(O, MCOperand_getReg(Op0));
177
548
        SStream_concat0(O, ", ");
178
548
        printRegName(O, getWRegFromXReg(
179
548
              MCOperand_getReg(Op1)));
180
548
        if (detail_is_set(MI) && useAliasDetails) {
181
548
          AArch64_set_detail_op_reg(
182
548
            MI, 0, MCOperand_getReg(Op0));
183
548
          AArch64_set_detail_op_reg(
184
548
            MI, 1,
185
548
            getWRegFromXReg(
186
548
              MCOperand_getReg(Op1)));
187
548
          if (strings_match(AsmMnemonic, "uxtb"))
188
192
            AArch64_get_detail_op(MI, -1)
189
192
              ->ext =
190
192
              AARCH64_EXT_UXTB;
191
356
          else if (strings_match(AsmMnemonic,
192
356
                     "sxtb"))
193
117
            AArch64_get_detail_op(MI, -1)
194
117
              ->ext =
195
117
              AARCH64_EXT_SXTB;
196
239
          else if (strings_match(AsmMnemonic,
197
239
                     "uxth"))
198
107
            AArch64_get_detail_op(MI, -1)
199
107
              ->ext =
200
107
              AARCH64_EXT_UXTH;
201
132
          else if (strings_match(AsmMnemonic,
202
132
                     "sxth"))
203
89
            AArch64_get_detail_op(MI, -1)
204
89
              ->ext =
205
89
              AARCH64_EXT_SXTH;
206
43
          else if (strings_match(AsmMnemonic,
207
43
                     "sxtw"))
208
43
            AArch64_get_detail_op(MI, -1)
209
43
              ->ext =
210
43
              AARCH64_EXT_SXTW;
211
0
          else
212
0
            AArch64_get_detail_op(MI, -1)
213
0
              ->ext =
214
0
              AARCH64_EXT_INVALID;
215
548
        }
216
548
        isAlias = true;
217
548
        MCInst_setIsAlias(MI, isAlias);
218
548
        if (useAliasDetails)
219
548
          return;
220
0
        else
221
0
          goto add_real_detail;
222
548
      }
223
1.06k
    }
224
225
    // All immediate shifts are aliases, implemented using the Bitfield
226
    // instruction. In all cases the immediate shift amount shift must be in
227
    // the range 0 to (reg.size -1).
228
2.03k
    if (MCOperand_isImm(Op2) && MCOperand_isImm(Op3)) {
229
2.03k
      const char *AsmMnemonic = NULL;
230
2.03k
      int shift = 0;
231
2.03k
      int64_t immr = MCOperand_getImm(Op2);
232
2.03k
      int64_t imms = MCOperand_getImm(Op3);
233
2.03k
      if (Opcode == AArch64_UBFMWri && imms != 0x1F &&
234
310
          ((imms + 1) == immr)) {
235
57
        AsmMnemonic = "lsl";
236
57
        shift = 31 - imms;
237
1.97k
      } else if (Opcode == AArch64_UBFMXri && imms != 0x3f &&
238
779
           ((imms + 1 == immr))) {
239
277
        AsmMnemonic = "lsl";
240
277
        shift = 63 - imms;
241
1.70k
      } else if (Opcode == AArch64_UBFMWri && imms == 0x1f) {
242
75
        AsmMnemonic = "lsr";
243
75
        shift = immr;
244
1.62k
      } else if (Opcode == AArch64_UBFMXri && imms == 0x3f) {
245
21
        AsmMnemonic = "lsr";
246
21
        shift = immr;
247
1.60k
      } else if (Opcode == AArch64_SBFMWri && imms == 0x1f) {
248
255
        AsmMnemonic = "asr";
249
255
        shift = immr;
250
1.34k
      } else if (Opcode == AArch64_SBFMXri && imms == 0x3f) {
251
113
        AsmMnemonic = "asr";
252
113
        shift = immr;
253
113
      }
254
2.03k
      if (AsmMnemonic) {
255
798
        SStream_concat(O, "%s", AsmMnemonic);
256
798
        SStream_concat0(O, " ");
257
258
798
        printRegName(O, MCOperand_getReg(Op0));
259
798
        SStream_concat0(O, ", ");
260
798
        printRegName(O, MCOperand_getReg(Op1));
261
798
        SStream_concat(O, "%s%s#%d", ", ",
262
798
                 markup("<imm:"), shift);
263
798
        SStream_concat0(O, markup(">"));
264
798
        if (detail_is_set(MI) && useAliasDetails) {
265
798
          AArch64_set_detail_op_reg(
266
798
            MI, 0, MCOperand_getReg(Op0));
267
798
          AArch64_set_detail_op_reg(
268
798
            MI, 1, MCOperand_getReg(Op1));
269
798
          if (strings_match(AsmMnemonic, "lsl"))
270
334
            AArch64_get_detail_op(MI, -1)
271
334
              ->shift.type =
272
334
              AARCH64_SFT_LSL;
273
464
          else if (strings_match(AsmMnemonic,
274
464
                     "lsr"))
275
96
            AArch64_get_detail_op(MI, -1)
276
96
              ->shift.type =
277
96
              AARCH64_SFT_LSR;
278
368
          else if (strings_match(AsmMnemonic,
279
368
                     "asr"))
280
368
            AArch64_get_detail_op(MI, -1)
281
368
              ->shift.type =
282
368
              AARCH64_SFT_ASR;
283
0
          else
284
0
            AArch64_get_detail_op(MI, -1)
285
0
              ->shift.type =
286
0
              AARCH64_SFT_INVALID;
287
798
          AArch64_get_detail_op(MI, -1)
288
798
            ->shift.value = shift;
289
798
        }
290
798
        isAlias = true;
291
798
        MCInst_setIsAlias(MI, isAlias);
292
798
        if (useAliasDetails)
293
798
          return;
294
0
        else
295
0
          goto add_real_detail;
296
798
      }
297
2.03k
    }
298
299
    // SBFIZ/UBFIZ aliases
300
1.23k
    if (MCOperand_getImm(Op2) > MCOperand_getImm(Op3)) {
301
514
      SStream_concat(O, "%s", (IsSigned ? "sbfiz" : "ubfiz"));
302
514
      SStream_concat0(O, " ");
303
304
514
      printRegName(O, MCOperand_getReg(Op0));
305
514
      SStream_concat0(O, ", ");
306
514
      printRegName(O, MCOperand_getReg(Op1));
307
514
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
308
514
      printUInt32Bang(O, (Is64Bit ? 64 : 32) -
309
514
               MCOperand_getImm(Op2));
310
514
      SStream_concat(O, "%s%s%s", markup(">"), ", ",
311
514
               markup("<imm:"));
312
514
      printInt64Bang(O, MCOperand_getImm(Op3) + 1);
313
514
      SStream_concat0(O, markup(">"));
314
514
      if (detail_is_set(MI) && useAliasDetails) {
315
514
        AArch64_set_detail_op_reg(
316
514
          MI, 0, MCOperand_getReg(Op0));
317
514
        AArch64_set_detail_op_reg(
318
514
          MI, 1, MCOperand_getReg(Op1));
319
514
        AArch64_set_detail_op_imm(
320
514
          MI, 2, AARCH64_OP_IMM,
321
514
          (Is64Bit ? 64 : 32) -
322
514
            MCOperand_getImm(Op2));
323
514
        AArch64_set_detail_op_imm(
324
514
          MI, 3, AARCH64_OP_IMM,
325
514
          MCOperand_getImm(Op3) + 1);
326
514
      }
327
514
      isAlias = true;
328
514
      MCInst_setIsAlias(MI, isAlias);
329
514
      if (useAliasDetails)
330
514
        return;
331
0
      else
332
0
        goto add_real_detail;
333
514
    }
334
335
    // Otherwise SBFX/UBFX is the preferred form
336
722
    SStream_concat(O, "%s", (IsSigned ? "sbfx" : "ubfx"));
337
722
    SStream_concat0(O, " ");
338
339
722
    printRegName(O, MCOperand_getReg(Op0));
340
722
    SStream_concat0(O, ", ");
341
722
    printRegName(O, MCOperand_getReg(Op1));
342
722
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
343
722
    printInt64Bang(O, MCOperand_getImm(Op2));
344
722
    SStream_concat(O, "%s%s%s", markup(">"), ", ", markup("<imm:"));
345
722
    printInt64Bang(O, MCOperand_getImm(Op3) -
346
722
            MCOperand_getImm(Op2) + 1);
347
722
    SStream_concat0(O, markup(">"));
348
722
    if (detail_is_set(MI) && useAliasDetails) {
349
722
      AArch64_set_detail_op_reg(MI, 0, MCOperand_getReg(Op0));
350
722
      AArch64_set_detail_op_reg(MI, 1, MCOperand_getReg(Op1));
351
722
      AArch64_set_detail_op_imm(MI, 2, AARCH64_OP_IMM,
352
722
              MCOperand_getImm(Op2));
353
722
      AArch64_set_detail_op_imm(
354
722
        MI, 3, AARCH64_OP_IMM,
355
722
        MCOperand_getImm(Op3) - MCOperand_getImm(Op2) +
356
722
          1);
357
722
    }
358
722
    isAlias = true;
359
722
    MCInst_setIsAlias(MI, isAlias);
360
722
    if (useAliasDetails)
361
722
      return;
362
0
    else
363
0
      goto add_real_detail;
364
722
  }
365
366
268k
  if (Opcode == AArch64_BFMXri || Opcode == AArch64_BFMWri) {
367
750
    isAlias = true;
368
750
    MCInst_setIsAlias(MI, isAlias);
369
750
    MCOperand *Op0 = MCInst_getOperand(MI, (0)); // Op1 == Op0
370
750
    MCOperand *Op2 = MCInst_getOperand(MI, (2));
371
750
    int ImmR = MCOperand_getImm(MCInst_getOperand(MI, (3)));
372
750
    int ImmS = MCOperand_getImm(MCInst_getOperand(MI, (4)));
373
374
750
    if ((MCOperand_getReg(Op2) == AArch64_WZR ||
375
711
         MCOperand_getReg(Op2) == AArch64_XZR) &&
376
485
        (ImmR == 0 || ImmS < ImmR) &&
377
229
        (AArch64_getFeatureBits(MI->csh->mode,
378
229
              AArch64_FeatureAll) ||
379
0
         AArch64_getFeatureBits(MI->csh->mode,
380
229
              AArch64_HasV8_2aOps))) {
381
      // BFC takes precedence over its entire range, sligtly differently
382
      // to BFI.
383
229
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
384
229
      int LSB = (BitWidth - ImmR) % BitWidth;
385
229
      int Width = ImmS + 1;
386
387
229
      SStream_concat0(O, "bfc ");
388
229
      printRegName(O, MCOperand_getReg(Op0));
389
229
      SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"),
390
229
               LSB);
391
229
      SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
392
229
               markup("<imm:"), Width);
393
229
      SStream_concat0(O, markup(">"));
394
229
      if (detail_is_set(MI) && useAliasDetails) {
395
229
        AArch64_set_detail_op_reg(
396
229
          MI, 0, MCOperand_getReg(Op0));
397
229
        AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM,
398
229
                LSB);
399
229
        AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM,
400
229
                Width);
401
229
      }
402
403
229
      if (useAliasDetails)
404
229
        return;
405
0
      else
406
0
        goto add_real_detail;
407
521
    } else if (ImmS < ImmR) {
408
      // BFI alias
409
158
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
410
158
      int LSB = (BitWidth - ImmR) % BitWidth;
411
158
      int Width = ImmS + 1;
412
413
158
      SStream_concat0(O, "bfi ");
414
158
      printRegName(O, MCOperand_getReg(Op0));
415
158
      SStream_concat0(O, ", ");
416
158
      printRegName(O, MCOperand_getReg(Op2));
417
158
      SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"),
418
158
               LSB);
419
158
      SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
420
158
               markup("<imm:"), Width);
421
158
      SStream_concat0(O, markup(">"));
422
158
      if (detail_is_set(MI) && useAliasDetails) {
423
158
        AArch64_set_detail_op_reg(
424
158
          MI, 0, MCOperand_getReg(Op0));
425
158
        AArch64_set_detail_op_reg(
426
158
          MI, 2, MCOperand_getReg(Op2));
427
158
        AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM,
428
158
                LSB);
429
158
        AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM,
430
158
                Width);
431
158
      }
432
158
      if (useAliasDetails)
433
158
        return;
434
0
      else
435
0
        goto add_real_detail;
436
158
    }
437
438
363
    int LSB = ImmR;
439
363
    int Width = ImmS - ImmR + 1;
440
    // Otherwise BFXIL the preferred form
441
363
    SStream_concat0(O, "bfxil ");
442
363
    printRegName(O, MCOperand_getReg(Op0));
443
363
    SStream_concat0(O, ", ");
444
363
    printRegName(O, MCOperand_getReg(Op2));
445
363
    SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"), LSB);
446
363
    SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
447
363
             markup("<imm:"), Width);
448
363
    SStream_concat0(O, markup(">"));
449
363
    if (detail_is_set(MI) && useAliasDetails) {
450
363
      AArch64_set_detail_op_reg(MI, 0, MCOperand_getReg(Op0));
451
363
      AArch64_set_detail_op_reg(MI, 2, MCOperand_getReg(Op2));
452
363
      AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM, LSB);
453
363
      AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM, Width);
454
363
    }
455
363
    if (useAliasDetails)
456
363
      return;
457
363
  }
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
268k
  if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi ||
463
267k
       Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) &&
464
2.00k
      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
268k
  if ((Opcode == AArch64_MOVKXi || Opcode == AArch64_MOVKWi) &&
473
1.42k
      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
268k
  if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi) &&
487
806
      MCOperand_isImm(MCInst_getOperand(MI, (1))) &&
488
806
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
489
806
    int RegWidth = Opcode == AArch64_MOVZXi ? 64 : 32;
490
806
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, (2)));
491
806
    uint64_t Value =
492
806
      (uint64_t)MCOperand_getImm(MCInst_getOperand(MI, (1)))
493
806
      << Shift;
494
495
806
    if (AArch64_AM_isMOVZMovAlias(
496
806
          Value, Shift, Opcode == AArch64_MOVZXi ? 64 : 32)) {
497
641
      isAlias = true;
498
641
      MCInst_setIsAlias(MI, isAlias);
499
641
      SStream_concat0(O, "mov ");
500
641
      printRegName(O, MCOperand_getReg(
501
641
            MCInst_getOperand(MI, (0))));
502
641
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
503
641
      printInt64Bang(O, SignExtend64(Value, RegWidth));
504
641
      SStream_concat0(O, markup(">"));
505
641
      if (detail_is_set(MI) && useAliasDetails) {
506
641
        AArch64_set_detail_op_reg(
507
641
          MI, 0, MCInst_getOpVal(MI, 0));
508
641
        AArch64_set_detail_op_imm(
509
641
          MI, 1, AARCH64_OP_IMM,
510
641
          SignExtend64(Value, RegWidth));
511
641
      }
512
641
      if (useAliasDetails)
513
641
        return;
514
641
    }
515
806
  }
516
517
267k
  if ((Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) &&
518
1.19k
      MCOperand_isImm(MCInst_getOperand(MI, (1))) &&
519
1.19k
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
520
1.19k
    int RegWidth = Opcode == AArch64_MOVNXi ? 64 : 32;
521
1.19k
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, (2)));
522
1.19k
    uint64_t Value =
523
1.19k
      ~((uint64_t)MCOperand_getImm(MCInst_getOperand(MI, (1)))
524
1.19k
        << Shift);
525
1.19k
    if (RegWidth == 32)
526
82
      Value = Value & 0xffffffff;
527
528
1.19k
    if (AArch64_AM_isMOVNMovAlias(Value, Shift, RegWidth)) {
529
1.15k
      isAlias = true;
530
1.15k
      MCInst_setIsAlias(MI, isAlias);
531
1.15k
      SStream_concat0(O, "mov ");
532
1.15k
      printRegName(O, MCOperand_getReg(
533
1.15k
            MCInst_getOperand(MI, (0))));
534
1.15k
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
535
1.15k
      printInt64Bang(O, SignExtend64(Value, RegWidth));
536
1.15k
      SStream_concat0(O, markup(">"));
537
1.15k
      if (detail_is_set(MI) && useAliasDetails) {
538
1.15k
        AArch64_set_detail_op_reg(
539
1.15k
          MI, 0, MCInst_getOpVal(MI, 0));
540
1.15k
        AArch64_set_detail_op_imm(
541
1.15k
          MI, 1, AARCH64_OP_IMM,
542
1.15k
          SignExtend64(Value, RegWidth));
543
1.15k
      }
544
1.15k
      if (useAliasDetails)
545
1.15k
        return;
546
1.15k
    }
547
1.19k
  }
548
549
266k
  if ((Opcode == AArch64_ORRXri || Opcode == AArch64_ORRWri) &&
550
2.54k
      (MCOperand_getReg(MCInst_getOperand(MI, (1))) == AArch64_XZR ||
551
1.50k
       MCOperand_getReg(MCInst_getOperand(MI, (1))) == AArch64_WZR) &&
552
1.61k
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
553
1.61k
    int RegWidth = Opcode == AArch64_ORRXri ? 64 : 32;
554
1.61k
    uint64_t Value = AArch64_AM_decodeLogicalImmediate(
555
1.61k
      MCOperand_getImm(MCInst_getOperand(MI, (2))), RegWidth);
556
1.61k
    if (!AArch64_AM_isAnyMOVWMovAlias(Value, RegWidth)) {
557
827
      isAlias = true;
558
827
      MCInst_setIsAlias(MI, isAlias);
559
827
      SStream_concat0(O, "mov ");
560
827
      printRegName(O, MCOperand_getReg(
561
827
            MCInst_getOperand(MI, (0))));
562
827
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
563
827
      printInt64Bang(O, SignExtend64(Value, RegWidth));
564
827
      SStream_concat0(O, markup(">"));
565
827
      if (detail_is_set(MI) && useAliasDetails) {
566
827
        AArch64_set_detail_op_reg(
567
827
          MI, 0, MCInst_getOpVal(MI, 0));
568
827
        AArch64_set_detail_op_imm(
569
827
          MI, 2, AARCH64_OP_IMM,
570
827
          SignExtend64(Value, RegWidth));
571
827
      }
572
827
      if (useAliasDetails)
573
827
        return;
574
827
    }
575
1.61k
  }
576
577
265k
  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
265k
  if (!isAlias)
592
265k
    isAlias |= printAliasInstr(MI, Address, O);
593
594
265k
add_real_detail:
595
265k
  MCInst_setIsAlias(MI, isAlias);
596
597
265k
  if (!isAlias || !useAliasDetails) {
598
237k
    map_set_fill_detail_ops(MI, !(isAlias && useAliasDetails));
599
237k
    if (isAlias)
600
0
      SStream_Close(O);
601
237k
    printInstruction(MI, Address, O);
602
237k
    if (isAlias)
603
0
      SStream_Open(O);
604
237k
  }
605
265k
}
606
607
bool printRangePrefetchAlias(MCInst *MI, SStream *O, const char *Annot)
608
291
{
609
291
  unsigned Opcode = MCInst_getOpcode(MI);
610
611
291
#ifndef NDEBUG
612
613
291
#endif
614
615
291
  unsigned PRFOp = MCOperand_getImm(MCInst_getOperand(MI, (0)));
616
291
  unsigned Mask = 0x18; // 0b11000
617
291
  if ((PRFOp & Mask) != Mask)
618
291
    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
291
}
655
656
bool printSysAlias(MCInst *MI, SStream *O)
657
2.83k
{
658
2.83k
  MCOperand *Op1 = MCInst_getOperand(MI, (0));
659
2.83k
  MCOperand *Cn = MCInst_getOperand(MI, (1));
660
2.83k
  MCOperand *Cm = MCInst_getOperand(MI, (2));
661
2.83k
  MCOperand *Op2 = MCInst_getOperand(MI, (3));
662
663
2.83k
  unsigned Op1Val = MCOperand_getImm(Op1);
664
2.83k
  unsigned CnVal = MCOperand_getImm(Cn);
665
2.83k
  unsigned CmVal = MCOperand_getImm(Cm);
666
2.83k
  unsigned Op2Val = MCOperand_getImm(Op2);
667
668
2.83k
  uint16_t Encoding = Op2Val;
669
2.83k
  Encoding |= CmVal << 3;
670
2.83k
  Encoding |= CnVal << 7;
671
2.83k
  Encoding |= Op1Val << 11;
672
673
2.83k
  bool NeedsReg;
674
2.83k
  const char *Ins;
675
2.83k
  const char *Name;
676
677
2.83k
  if (CnVal == 7) {
678
1.55k
    switch (CmVal) {
679
60
    default:
680
60
      return false;
681
    // Maybe IC, maybe Prediction Restriction
682
263
    case 1:
683
263
      switch (Op1Val) {
684
93
      default:
685
93
        return false;
686
74
      case 0:
687
74
        goto Search_IC;
688
96
      case 3:
689
96
        goto Search_PRCTX;
690
263
      }
691
    // Prediction Restriction aliases
692
350
    case 3: {
693
446
Search_PRCTX:
694
446
      if (Op1Val != 3 || CnVal != 7 || CmVal != 3)
695
111
        return false;
696
697
335
      unsigned int Requires =
698
335
        Op2Val == 6 ? AArch64_FeatureSPECRES2 :
699
335
                AArch64_FeaturePredRes;
700
335
      if (!(AArch64_getFeatureBits(MI->csh->mode,
701
335
                 AArch64_FeatureAll) ||
702
0
            AArch64_getFeatureBits(MI->csh->mode, Requires)))
703
0
        return false;
704
705
335
      NeedsReg = true;
706
335
      switch (Op2Val) {
707
280
      default:
708
280
        return false;
709
5
      case 4:
710
5
        Ins = "cfp ";
711
5
        break;
712
21
      case 5:
713
21
        Ins = "dvp ";
714
21
        break;
715
18
      case 6:
716
18
        Ins = "cosp ";
717
18
        break;
718
11
      case 7:
719
11
        Ins = "cpp ";
720
11
        break;
721
335
      }
722
55
      Name = "RCTX";
723
55
    } break;
724
    // IC aliases
725
383
    case 5: {
726
457
Search_IC: {
727
457
  const AArch64IC_IC *IC = AArch64IC_lookupICByEncoding(Encoding);
728
457
  if (!IC ||
729
153
      !AArch64_testFeatureList(MI->csh->mode, IC->FeaturesRequired))
730
304
    return false;
731
153
  if (detail_is_set(MI)) {
732
153
    aarch64_sysop sysop = { 0 };
733
153
    sysop.reg = IC->SysReg;
734
153
    sysop.sub_type = AARCH64_OP_IC;
735
153
    AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
736
153
    AArch64_get_detail_op(MI, 0)->sysop = sysop;
737
153
    AArch64_inc_op_count(MI);
738
153
  }
739
740
153
  NeedsReg = IC->NeedsReg;
741
153
  Ins = "ic ";
742
153
  Name = IC->Name;
743
153
}
744
153
    } break;
745
    // DC aliases
746
30
    case 4:
747
119
    case 6:
748
157
    case 10:
749
177
    case 11:
750
195
    case 12:
751
216
    case 13:
752
360
    case 14: {
753
360
      const AArch64DC_DC *DC =
754
360
        AArch64DC_lookupDCByEncoding(Encoding);
755
360
      if (!DC || !AArch64_testFeatureList(
756
96
             MI->csh->mode, DC->FeaturesRequired))
757
264
        return false;
758
96
      if (detail_is_set(MI)) {
759
96
        aarch64_sysop sysop = { 0 };
760
96
        sysop.alias = DC->SysAlias;
761
96
        sysop.sub_type = AARCH64_OP_DC;
762
96
        AArch64_get_detail_op(MI, 0)->type =
763
96
          AARCH64_OP_SYSALIAS;
764
96
        AArch64_get_detail_op(MI, 0)->sysop = sysop;
765
96
        AArch64_inc_op_count(MI);
766
96
      }
767
768
96
      NeedsReg = true;
769
96
      Ins = "dc ";
770
96
      Name = DC->Name;
771
96
    } break;
772
    // AT aliases
773
40
    case 8:
774
139
    case 9: {
775
139
      const AArch64AT_AT *AT =
776
139
        AArch64AT_lookupATByEncoding(Encoding);
777
139
      if (!AT || !AArch64_testFeatureList(
778
42
             MI->csh->mode, AT->FeaturesRequired))
779
97
        return false;
780
781
42
      if (detail_is_set(MI)) {
782
42
        aarch64_sysop sysop = { 0 };
783
42
        sysop.alias = AT->SysAlias;
784
42
        sysop.sub_type = AARCH64_OP_AT;
785
42
        AArch64_get_detail_op(MI, 0)->type =
786
42
          AARCH64_OP_SYSALIAS;
787
42
        AArch64_get_detail_op(MI, 0)->sysop = sysop;
788
42
        AArch64_inc_op_count(MI);
789
42
      }
790
42
      NeedsReg = true;
791
42
      Ins = "at ";
792
42
      Name = AT->Name;
793
42
    } break;
794
1.55k
    }
795
1.55k
  } else if (CnVal == 8 || CnVal == 9) {
796
    // TLBI aliases
797
243
    const AArch64TLBI_TLBI *TLBI =
798
243
      AArch64TLBI_lookupTLBIByEncoding(Encoding);
799
243
    if (!TLBI || !AArch64_testFeatureList(MI->csh->mode,
800
93
                  TLBI->FeaturesRequired))
801
150
      return false;
802
803
93
    if (detail_is_set(MI)) {
804
93
      aarch64_sysop sysop = { 0 };
805
93
      sysop.reg = TLBI->SysReg;
806
93
      sysop.sub_type = AARCH64_OP_TLBI;
807
93
      AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
808
93
      AArch64_get_detail_op(MI, 0)->sysop = sysop;
809
93
      AArch64_inc_op_count(MI);
810
93
    }
811
93
    NeedsReg = TLBI->NeedsReg;
812
93
    Ins = "tlbi ";
813
93
    Name = TLBI->Name;
814
93
  } else
815
1.03k
    return false;
816
817
878
#define TMP_STR_LEN 32
818
439
  char Str[TMP_STR_LEN] = { 0 };
819
439
  append_to_str_lower(Str, TMP_STR_LEN, Ins);
820
439
  append_to_str_lower(Str, TMP_STR_LEN, Name);
821
439
#undef TMP_STR_LEN
822
823
439
  SStream_concat1(O, ' ');
824
439
  SStream_concat0(O, Str);
825
439
  if (NeedsReg) {
826
276
    SStream_concat0(O, ", ");
827
276
    printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (4))));
828
276
    AArch64_set_detail_op_reg(MI, 4, MCInst_getOpVal(MI, 4));
829
276
  }
830
831
439
  return true;
832
2.83k
}
833
834
bool printSyspAlias(MCInst *MI, SStream *O)
835
3.76k
{
836
3.76k
  MCOperand *Op1 = MCInst_getOperand(MI, (0));
837
3.76k
  MCOperand *Cn = MCInst_getOperand(MI, (1));
838
3.76k
  MCOperand *Cm = MCInst_getOperand(MI, (2));
839
3.76k
  MCOperand *Op2 = MCInst_getOperand(MI, (3));
840
841
3.76k
  unsigned Op1Val = MCOperand_getImm(Op1);
842
3.76k
  unsigned CnVal = MCOperand_getImm(Cn);
843
3.76k
  unsigned CmVal = MCOperand_getImm(Cm);
844
3.76k
  unsigned Op2Val = MCOperand_getImm(Op2);
845
846
3.76k
  uint16_t Encoding = Op2Val;
847
3.76k
  Encoding |= CmVal << 3;
848
3.76k
  Encoding |= CnVal << 7;
849
3.76k
  Encoding |= Op1Val << 11;
850
851
3.76k
  const char *Ins;
852
3.76k
  const char *Name;
853
854
3.76k
  if (CnVal == 8 || CnVal == 9) {
855
    // TLBIP aliases
856
857
2.48k
    if (CnVal == 9) {
858
359
      if (!AArch64_getFeatureBits(MI->csh->mode,
859
359
                AArch64_FeatureAll) ||
860
359
          !AArch64_getFeatureBits(MI->csh->mode,
861
359
                AArch64_FeatureXS))
862
0
        return false;
863
359
      Encoding &= ~(1 << 7);
864
359
    }
865
866
2.48k
    const AArch64TLBI_TLBI *TLBI =
867
2.48k
      AArch64TLBI_lookupTLBIByEncoding(Encoding);
868
2.48k
    if (!TLBI || !AArch64_testFeatureList(MI->csh->mode,
869
1.77k
                  TLBI->FeaturesRequired))
870
716
      return false;
871
872
1.77k
    if (detail_is_set(MI)) {
873
1.77k
      aarch64_sysop sysop = { 0 };
874
1.77k
      sysop.reg = TLBI->SysReg;
875
1.77k
      sysop.sub_type = AARCH64_OP_TLBI;
876
1.77k
      AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
877
1.77k
      AArch64_get_detail_op(MI, 0)->sysop = sysop;
878
1.77k
      AArch64_inc_op_count(MI);
879
1.77k
    }
880
1.77k
    Ins = "tlbip ";
881
1.77k
    Name = TLBI->Name;
882
1.77k
  } else
883
1.28k
    return false;
884
885
3.79k
#define TMP_STR_LEN 32
886
1.77k
  char Str[TMP_STR_LEN] = { 0 };
887
1.77k
  append_to_str_lower(Str, TMP_STR_LEN, Ins);
888
1.77k
  append_to_str_lower(Str, TMP_STR_LEN, Name);
889
890
1.77k
  if (CnVal == 9) {
891
256
    append_to_str_lower(Str, TMP_STR_LEN, "nxs");
892
256
  }
893
1.77k
#undef TMP_STR_LEN
894
895
1.77k
  SStream_concat1(O, ' ');
896
1.77k
  SStream_concat0(O, Str);
897
1.77k
  SStream_concat0(O, ", ");
898
1.77k
  if (MCOperand_getReg(MCInst_getOperand(MI, (4))) == AArch64_XZR)
899
1.42k
    printSyspXzrPair(MI, 4, O);
900
343
  else
901
343
    CONCAT(printGPRSeqPairsClassOperand, 64)(MI, 4, O);
902
903
1.77k
  return true;
904
3.76k
}
905
906
#define DEFINE_printMatrix(EltSize) \
907
  void CONCAT(printMatrix, EltSize)(MCInst * MI, unsigned OpNum, \
908
            SStream *O) \
909
6.81k
  { \
910
6.81k
    AArch64_add_cs_detail_1( \
911
6.81k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
912
6.81k
      EltSize); \
913
6.81k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
914
6.81k
\
915
6.81k
    printRegName(O, MCOperand_getReg(RegOp)); \
916
6.81k
    switch (EltSize) { \
917
333
    case 0: \
918
333
      break; \
919
0
    case 8: \
920
0
      SStream_concat0(O, ".b"); \
921
0
      break; \
922
1.82k
    case 16: \
923
1.82k
      SStream_concat0(O, ".h"); \
924
1.82k
      break; \
925
3.43k
    case 32: \
926
3.43k
      SStream_concat0(O, ".s"); \
927
3.43k
      break; \
928
1.23k
    case 64: \
929
1.23k
      SStream_concat0(O, ".d"); \
930
1.23k
      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
6.81k
    } \
937
6.81k
  }
printMatrix_64
Line
Count
Source
909
1.23k
  { \
910
1.23k
    AArch64_add_cs_detail_1( \
911
1.23k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
912
1.23k
      EltSize); \
913
1.23k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
914
1.23k
\
915
1.23k
    printRegName(O, MCOperand_getReg(RegOp)); \
916
1.23k
    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.23k
    case 64: \
929
1.23k
      SStream_concat0(O, ".d"); \
930
1.23k
      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.23k
    } \
937
1.23k
  }
printMatrix_32
Line
Count
Source
909
3.43k
  { \
910
3.43k
    AArch64_add_cs_detail_1( \
911
3.43k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
912
3.43k
      EltSize); \
913
3.43k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
914
3.43k
\
915
3.43k
    printRegName(O, MCOperand_getReg(RegOp)); \
916
3.43k
    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
3.43k
    case 32: \
926
3.43k
      SStream_concat0(O, ".s"); \
927
3.43k
      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
3.43k
    } \
937
3.43k
  }
printMatrix_16
Line
Count
Source
909
1.82k
  { \
910
1.82k
    AArch64_add_cs_detail_1( \
911
1.82k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
912
1.82k
      EltSize); \
913
1.82k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
914
1.82k
\
915
1.82k
    printRegName(O, MCOperand_getReg(RegOp)); \
916
1.82k
    switch (EltSize) { \
917
0
    case 0: \
918
0
      break; \
919
0
    case 8: \
920
0
      SStream_concat0(O, ".b"); \
921
0
      break; \
922
1.82k
    case 16: \
923
1.82k
      SStream_concat0(O, ".h"); \
924
1.82k
      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.82k
    } \
937
1.82k
  }
printMatrix_0
Line
Count
Source
909
333
  { \
910
333
    AArch64_add_cs_detail_1( \
911
333
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
912
333
      EltSize); \
913
333
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
914
333
\
915
333
    printRegName(O, MCOperand_getReg(RegOp)); \
916
333
    switch (EltSize) { \
917
333
    case 0: \
918
333
      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
333
    } \
937
333
  }
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
6.39k
  { \
947
6.39k
    AArch64_add_cs_detail_1( \
948
6.39k
      MI, \
949
6.39k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
950
6.39k
      OpNum, IsVertical); \
951
6.39k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
952
6.39k
\
953
6.39k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
954
6.39k
                  AArch64_NoRegAltName); \
955
6.39k
\
956
6.39k
    unsigned buf_len = strlen(RegName) + 1; \
957
6.39k
    char *Base = cs_mem_calloc(1, buf_len); \
958
6.39k
    memcpy(Base, RegName, buf_len); \
959
6.39k
    char *Dot = strchr(Base, '.'); \
960
6.39k
    if (!Dot) { \
961
0
      SStream_concat0(O, RegName); \
962
0
      return; \
963
0
    } \
964
6.39k
    *Dot = '\0'; /* Split string */ \
965
6.39k
    char *Suffix = Dot + 1; \
966
6.39k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
967
6.39k
    SStream_concat1(O, '.'); \
968
6.39k
    SStream_concat0(O, Suffix); \
969
6.39k
    cs_mem_free(Base); \
970
6.39k
  }
printMatrixTileVector_0
Line
Count
Source
946
2.71k
  { \
947
2.71k
    AArch64_add_cs_detail_1( \
948
2.71k
      MI, \
949
2.71k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
950
2.71k
      OpNum, IsVertical); \
951
2.71k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
952
2.71k
\
953
2.71k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
954
2.71k
                  AArch64_NoRegAltName); \
955
2.71k
\
956
2.71k
    unsigned buf_len = strlen(RegName) + 1; \
957
2.71k
    char *Base = cs_mem_calloc(1, buf_len); \
958
2.71k
    memcpy(Base, RegName, buf_len); \
959
2.71k
    char *Dot = strchr(Base, '.'); \
960
2.71k
    if (!Dot) { \
961
0
      SStream_concat0(O, RegName); \
962
0
      return; \
963
0
    } \
964
2.71k
    *Dot = '\0'; /* Split string */ \
965
2.71k
    char *Suffix = Dot + 1; \
966
2.71k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
967
2.71k
    SStream_concat1(O, '.'); \
968
2.71k
    SStream_concat0(O, Suffix); \
969
2.71k
    cs_mem_free(Base); \
970
2.71k
  }
printMatrixTileVector_1
Line
Count
Source
946
3.68k
  { \
947
3.68k
    AArch64_add_cs_detail_1( \
948
3.68k
      MI, \
949
3.68k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
950
3.68k
      OpNum, IsVertical); \
951
3.68k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
952
3.68k
\
953
3.68k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
954
3.68k
                  AArch64_NoRegAltName); \
955
3.68k
\
956
3.68k
    unsigned buf_len = strlen(RegName) + 1; \
957
3.68k
    char *Base = cs_mem_calloc(1, buf_len); \
958
3.68k
    memcpy(Base, RegName, buf_len); \
959
3.68k
    char *Dot = strchr(Base, '.'); \
960
3.68k
    if (!Dot) { \
961
0
      SStream_concat0(O, RegName); \
962
0
      return; \
963
0
    } \
964
3.68k
    *Dot = '\0'; /* Split string */ \
965
3.68k
    char *Suffix = Dot + 1; \
966
3.68k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
967
3.68k
    SStream_concat1(O, '.'); \
968
3.68k
    SStream_concat0(O, Suffix); \
969
3.68k
    cs_mem_free(Base); \
970
3.68k
  }
971
DEFINE_printMatrixTileVector(0);
972
DEFINE_printMatrixTileVector(1);
973
974
void printMatrixTile(MCInst *MI, unsigned OpNum, SStream *O)
975
2.11k
{
976
2.11k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MatrixTile, OpNum);
977
2.11k
  MCOperand *RegOp = MCInst_getOperand(MI, (OpNum));
978
979
2.11k
  printRegName(O, MCOperand_getReg(RegOp));
980
2.11k
}
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
358k
{
995
358k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Operand, OpNo);
996
358k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
997
358k
  if (MCOperand_isReg(Op)) {
998
307k
    unsigned Reg = MCOperand_getReg(Op);
999
307k
    printRegName(O, Reg);
1000
307k
  } else if (MCOperand_isImm(Op)) {
1001
51.5k
    Op = MCInst_getOperand(MI, (OpNo));
1002
51.5k
    SStream_concat(O, "%s", markup("<imm:"));
1003
51.5k
    printInt64Bang(O, MCOperand_getImm(Op));
1004
51.5k
    SStream_concat0(O, markup(">"));
1005
51.5k
  } else {
1006
0
    printUInt64Bang(O, MCInst_getOpVal(MI, OpNo));
1007
0
  }
1008
358k
}
1009
1010
void printImm(MCInst *MI, unsigned OpNo, SStream *O)
1011
4.72k
{
1012
4.72k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Imm, OpNo);
1013
4.72k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1014
4.72k
  SStream_concat(O, "%s", markup("<imm:"));
1015
4.72k
  printInt64Bang(O, MCOperand_getImm(Op));
1016
4.72k
  SStream_concat0(O, markup(">"));
1017
4.72k
}
1018
1019
void printImmHex(MCInst *MI, unsigned OpNo, SStream *O)
1020
289
{
1021
289
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ImmHex, OpNo);
1022
289
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1023
289
  SStream_concat(O, "%s", markup("<imm:"));
1024
289
  printInt64Bang(O, MCOperand_getImm(Op));
1025
289
  SStream_concat0(O, markup(">"));
1026
289
}
1027
1028
#define DEFINE_printSImm(Size) \
1029
  void CONCAT(printSImm, Size)(MCInst * MI, unsigned OpNo, SStream *O) \
1030
647
  { \
1031
647
    AArch64_add_cs_detail_1( \
1032
647
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1033
647
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1034
647
    if (Size == 8) { \
1035
107
      SStream_concat(O, "%s", markup("<imm:")); \
1036
107
      printInt32Bang(O, MCOperand_getImm(Op)); \
1037
107
      SStream_concat0(O, markup(">")); \
1038
540
    } else if (Size == 16) { \
1039
540
      SStream_concat(O, "%s", markup("<imm:")); \
1040
540
      printInt32Bang(O, MCOperand_getImm(Op)); \
1041
540
      SStream_concat0(O, markup(">")); \
1042
540
    } 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
647
  }
printSImm_16
Line
Count
Source
1030
540
  { \
1031
540
    AArch64_add_cs_detail_1( \
1032
540
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1033
540
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1034
540
    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
540
    } else if (Size == 16) { \
1039
540
      SStream_concat(O, "%s", markup("<imm:")); \
1040
540
      printInt32Bang(O, MCOperand_getImm(Op)); \
1041
540
      SStream_concat0(O, markup(">")); \
1042
540
    } 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
540
  }
printSImm_8
Line
Count
Source
1030
107
  { \
1031
107
    AArch64_add_cs_detail_1( \
1032
107
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1033
107
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1034
107
    if (Size == 8) { \
1035
107
      SStream_concat(O, "%s", markup("<imm:")); \
1036
107
      printInt32Bang(O, MCOperand_getImm(Op)); \
1037
107
      SStream_concat0(O, markup(">")); \
1038
107
    } 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
107
  }
1048
DEFINE_printSImm(16);
1049
DEFINE_printSImm(8);
1050
1051
void printPostIncOperand(MCInst *MI, unsigned OpNo, unsigned Imm, SStream *O)
1052
7.78k
{
1053
7.78k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1054
7.78k
  if (MCOperand_isReg(Op)) {
1055
7.78k
    unsigned Reg = MCOperand_getReg(Op);
1056
7.78k
    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
7.78k
      printRegName(O, Reg);
1062
7.78k
  } else
1063
0
    CS_ASSERT_RET(0 &&
1064
7.78k
            "unknown operand kind in printPostIncOperand64");
1065
7.78k
}
1066
1067
void printVRegOperand(MCInst *MI, unsigned OpNo, SStream *O)
1068
57.1k
{
1069
57.1k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_VRegOperand, OpNo);
1070
57.1k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1071
1072
57.1k
  unsigned Reg = MCOperand_getReg(Op);
1073
57.1k
  printRegNameAlt(O, Reg, AArch64_vreg);
1074
57.1k
}
1075
1076
void printSysCROperand(MCInst *MI, unsigned OpNo, SStream *O)
1077
8.94k
{
1078
8.94k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SysCROperand, OpNo);
1079
8.94k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1080
1081
8.94k
  SStream_concat(O, "%s", "c");
1082
8.94k
  printUInt32(O, MCOperand_getImm(Op));
1083
8.94k
  SStream_concat1(O, '\0');
1084
8.94k
}
1085
1086
void printAddSubImm(MCInst *MI, unsigned OpNum, SStream *O)
1087
3.08k
{
1088
3.08k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AddSubImm, OpNum);
1089
3.08k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1090
3.08k
  if (MCOperand_isImm(MO)) {
1091
3.08k
    unsigned Val = (MCOperand_getImm(MO) & 0xfff);
1092
1093
3.08k
    unsigned Shift = AArch64_AM_getShiftValue(
1094
3.08k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))));
1095
3.08k
    SStream_concat(O, "%s", markup("<imm:"));
1096
3.08k
    printUInt32Bang(O, (Val));
1097
3.08k
    SStream_concat0(O, markup(">"));
1098
3.08k
    if (Shift != 0) {
1099
814
      printShifter(MI, OpNum + 1, O);
1100
814
    }
1101
3.08k
  } else {
1102
0
    printShifter(MI, OpNum + 1, O);
1103
0
  }
1104
3.08k
}
1105
1106
#define DEFINE_printLogicalImm(T) \
1107
  void CONCAT(printLogicalImm, T)(MCInst * MI, unsigned OpNum, \
1108
          SStream *O) \
1109
7.37k
  { \
1110
7.37k
    AArch64_add_cs_detail_1( \
1111
7.37k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1112
7.37k
      sizeof(T)); \
1113
7.37k
    uint64_t Val = \
1114
7.37k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1115
7.37k
    SStream_concat(O, "%s", markup("<imm:")); \
1116
7.37k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1117
7.37k
             Val, 8 * sizeof(T)))); \
1118
7.37k
    SStream_concat0(O, markup(">")); \
1119
7.37k
  }
printLogicalImm_int64_t
Line
Count
Source
1109
2.75k
  { \
1110
2.75k
    AArch64_add_cs_detail_1( \
1111
2.75k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1112
2.75k
      sizeof(T)); \
1113
2.75k
    uint64_t Val = \
1114
2.75k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1115
2.75k
    SStream_concat(O, "%s", markup("<imm:")); \
1116
2.75k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1117
2.75k
             Val, 8 * sizeof(T)))); \
1118
2.75k
    SStream_concat0(O, markup(">")); \
1119
2.75k
  }
printLogicalImm_int32_t
Line
Count
Source
1109
1.54k
  { \
1110
1.54k
    AArch64_add_cs_detail_1( \
1111
1.54k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1112
1.54k
      sizeof(T)); \
1113
1.54k
    uint64_t Val = \
1114
1.54k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1115
1.54k
    SStream_concat(O, "%s", markup("<imm:")); \
1116
1.54k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1117
1.54k
             Val, 8 * sizeof(T)))); \
1118
1.54k
    SStream_concat0(O, markup(">")); \
1119
1.54k
  }
printLogicalImm_int8_t
Line
Count
Source
1109
2.02k
  { \
1110
2.02k
    AArch64_add_cs_detail_1( \
1111
2.02k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1112
2.02k
      sizeof(T)); \
1113
2.02k
    uint64_t Val = \
1114
2.02k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1115
2.02k
    SStream_concat(O, "%s", markup("<imm:")); \
1116
2.02k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1117
2.02k
             Val, 8 * sizeof(T)))); \
1118
2.02k
    SStream_concat0(O, markup(">")); \
1119
2.02k
  }
printLogicalImm_int16_t
Line
Count
Source
1109
1.05k
  { \
1110
1.05k
    AArch64_add_cs_detail_1( \
1111
1.05k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1112
1.05k
      sizeof(T)); \
1113
1.05k
    uint64_t Val = \
1114
1.05k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1115
1.05k
    SStream_concat(O, "%s", markup("<imm:")); \
1116
1.05k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1117
1.05k
             Val, 8 * sizeof(T)))); \
1118
1.05k
    SStream_concat0(O, markup(">")); \
1119
1.05k
  }
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.38k
{
1127
9.38k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Shifter, OpNum);
1128
9.38k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1129
  // LSL #0 should not be printed.
1130
9.38k
  if (AArch64_AM_getShiftType(Val) == AArch64_AM_LSL &&
1131
4.89k
      AArch64_AM_getShiftValue(Val) == 0)
1132
557
    return;
1133
8.83k
  SStream_concat(
1134
8.83k
    O, "%s%s%s%s#%u", ", ",
1135
8.83k
    AArch64_AM_getShiftExtendName(AArch64_AM_getShiftType(Val)),
1136
8.83k
    " ", markup("<imm:"), AArch64_AM_getShiftValue(Val));
1137
8.83k
  SStream_concat0(O, markup(">"));
1138
8.83k
}
1139
1140
void printShiftedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1141
5.38k
{
1142
5.38k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ShiftedRegister, OpNum);
1143
5.38k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1144
5.38k
  printShifter(MI, OpNum + 1, O);
1145
5.38k
}
1146
1147
void printExtendedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1148
1.69k
{
1149
1.69k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ExtendedRegister, OpNum);
1150
1.69k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1151
1.69k
  printArithExtend(MI, OpNum + 1, O);
1152
1.69k
}
1153
1154
void printArithExtend(MCInst *MI, unsigned OpNum, SStream *O)
1155
2.52k
{
1156
2.52k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ArithExtend, OpNum);
1157
2.52k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1158
2.52k
  AArch64_AM_ShiftExtendType ExtType = AArch64_AM_getArithExtendType(Val);
1159
2.52k
  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
2.52k
  if (ExtType == AArch64_AM_UXTW || ExtType == AArch64_AM_UXTX) {
1165
1.00k
    unsigned Dest = MCOperand_getReg(MCInst_getOperand(MI, (0)));
1166
1.00k
    unsigned Src1 = MCOperand_getReg(MCInst_getOperand(MI, (1)));
1167
1.00k
    if (((Dest == AArch64_SP || Src1 == AArch64_SP) &&
1168
424
         ExtType == AArch64_AM_UXTX) ||
1169
588
        ((Dest == AArch64_WSP || Src1 == AArch64_WSP) &&
1170
452
         ExtType == AArch64_AM_UXTW)) {
1171
452
      if (ShiftVal != 0) {
1172
452
        SStream_concat(O, "%s%s", ", lsl ",
1173
452
                 markup("<imm:"));
1174
452
        printUInt32Bang(O, ShiftVal);
1175
452
        SStream_concat0(O, markup(">"));
1176
452
      }
1177
452
      return;
1178
452
    }
1179
1.00k
  }
1180
2.06k
  SStream_concat(O, "%s", ", ");
1181
2.06k
  SStream_concat0(O, AArch64_AM_getShiftExtendName(ExtType));
1182
2.06k
  if (ShiftVal != 0) {
1183
1.83k
    SStream_concat(O, "%s%s#%d", " ", markup("<imm:"), ShiftVal);
1184
1.83k
    SStream_concat0(O, markup(">"));
1185
1.83k
  }
1186
2.06k
}
1187
1188
static void printMemExtendImpl(bool SignExtend, bool DoShift, unsigned Width,
1189
             char SrcRegKind, SStream *O, bool getUseMarkup)
1190
15.9k
{
1191
  // sxtw, sxtx, uxtw or lsl (== uxtx)
1192
15.9k
  bool IsLSL = !SignExtend && SrcRegKind == 'x';
1193
15.9k
  if (IsLSL)
1194
7.24k
    SStream_concat0(O, "lsl");
1195
8.73k
  else {
1196
8.73k
    SStream_concat(O, "%c%s", (SignExtend ? 's' : 'u'), "xt");
1197
8.73k
    SStream_concat1(O, SrcRegKind);
1198
8.73k
  }
1199
1200
15.9k
  if (DoShift || IsLSL) {
1201
13.0k
    SStream_concat0(O, " ");
1202
13.0k
    if (getUseMarkup)
1203
0
      SStream_concat0(O, "<imm:");
1204
13.0k
    unsigned ShiftAmount = DoShift ? Log2_32(Width / 8) : 0;
1205
13.0k
    SStream_concat(O, "%s%u", "#", ShiftAmount);
1206
13.0k
    if (getUseMarkup)
1207
0
      SStream_concat0(O, ">");
1208
13.0k
  }
1209
15.9k
}
1210
1211
void printMemExtend(MCInst *MI, unsigned OpNum, SStream *O, char SrcRegKind,
1212
        unsigned Width)
1213
2.07k
{
1214
2.07k
  bool SignExtend = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1215
2.07k
  bool DoShift = MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1)));
1216
2.07k
  printMemExtendImpl(SignExtend, DoShift, Width, SrcRegKind, O,
1217
2.07k
         getUseMarkup());
1218
2.07k
}
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
17.8k
  { \
1227
17.8k
    AArch64_add_cs_detail_4( \
1228
17.8k
      MI, \
1229
17.8k
      CONCAT(CONCAT(CONCAT(CONCAT(AArch64_OP_GROUP_RegWithShiftExtend, \
1230
17.8k
                SignExtend), \
1231
17.8k
               ExtWidth), \
1232
17.8k
              SrcRegKind), \
1233
17.8k
             Suffix), \
1234
17.8k
      OpNum, SignExtend, ExtWidth, CHAR(SrcRegKind), \
1235
17.8k
      CHAR(Suffix)); \
1236
17.8k
    printOperand(MI, OpNum, O); \
1237
17.8k
    if (CHAR(Suffix) == 's' || CHAR(Suffix) == 'd') { \
1238
10.3k
      SStream_concat1(O, '.'); \
1239
10.3k
      SStream_concat1(O, CHAR(Suffix)); \
1240
10.3k
      SStream_concat1(O, '\0'); \
1241
10.3k
    } else \
1242
17.8k
      CS_ASSERT_RET((CHAR(Suffix) == '0') && \
1243
17.8k
              "Unsupported suffix size"); \
1244
17.8k
    bool DoShift = ExtWidth != 8; \
1245
17.8k
    if (SignExtend || DoShift || CHAR(SrcRegKind) == 'w') { \
1246
13.9k
      SStream_concat0(O, ", "); \
1247
13.9k
      printMemExtendImpl(SignExtend, DoShift, ExtWidth, \
1248
13.9k
             CHAR(SrcRegKind), O, \
1249
13.9k
             getUseMarkup()); \
1250
13.9k
    } \
1251
17.8k
  }
1252
1.53k
DEFINE_printRegWithShiftExtend(false, 8, x, d);
1253
1.03k
DEFINE_printRegWithShiftExtend(true, 8, w, d);
1254
819
DEFINE_printRegWithShiftExtend(false, 8, w, d);
1255
2.34k
DEFINE_printRegWithShiftExtend(false, 8, x, 0);
1256
385
DEFINE_printRegWithShiftExtend(true, 8, w, s);
1257
351
DEFINE_printRegWithShiftExtend(false, 8, w, s);
1258
615
DEFINE_printRegWithShiftExtend(false, 64, x, d);
1259
808
DEFINE_printRegWithShiftExtend(true, 64, w, d);
1260
642
DEFINE_printRegWithShiftExtend(false, 64, w, d);
1261
1.20k
DEFINE_printRegWithShiftExtend(false, 64, x, 0);
1262
109
DEFINE_printRegWithShiftExtend(true, 64, w, s);
1263
16
DEFINE_printRegWithShiftExtend(false, 64, w, s);
1264
192
DEFINE_printRegWithShiftExtend(false, 16, x, d);
1265
423
DEFINE_printRegWithShiftExtend(true, 16, w, d);
1266
769
DEFINE_printRegWithShiftExtend(false, 16, w, d);
1267
1.67k
DEFINE_printRegWithShiftExtend(false, 16, x, 0);
1268
372
DEFINE_printRegWithShiftExtend(true, 16, w, s);
1269
207
DEFINE_printRegWithShiftExtend(false, 16, w, s);
1270
340
DEFINE_printRegWithShiftExtend(false, 32, x, d);
1271
513
DEFINE_printRegWithShiftExtend(true, 32, w, d);
1272
685
DEFINE_printRegWithShiftExtend(false, 32, w, d);
1273
708
DEFINE_printRegWithShiftExtend(false, 32, x, 0);
1274
50
DEFINE_printRegWithShiftExtend(true, 32, w, s);
1275
230
DEFINE_printRegWithShiftExtend(false, 32, w, s);
1276
81
DEFINE_printRegWithShiftExtend(false, 8, x, s);
1277
97
DEFINE_printRegWithShiftExtend(false, 16, x, s);
1278
16
DEFINE_printRegWithShiftExtend(false, 32, x, s);
1279
41
DEFINE_printRegWithShiftExtend(false, 64, x, s);
1280
1.60k
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
5.69k
  { \
1286
5.69k
    AArch64_add_cs_detail_1( \
1287
5.69k
      MI, \
1288
5.69k
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1289
5.69k
      OpNum, EltSize); \
1290
5.69k
    unsigned Reg = \
1291
5.69k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1292
5.69k
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1293
5.69k
      CS_ASSERT_RET( \
1294
5.69k
        0 && \
1295
5.69k
        "Unsupported predicate-as-counter register"); \
1296
5.69k
    SStream_concat(O, "%s", "pn"); \
1297
5.69k
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1298
5.69k
    switch (EltSize) { \
1299
4.94k
    case 0: \
1300
4.94k
      break; \
1301
175
    case 8: \
1302
175
      SStream_concat0(O, ".b"); \
1303
175
      break; \
1304
72
    case 16: \
1305
72
      SStream_concat0(O, ".h"); \
1306
72
      break; \
1307
219
    case 32: \
1308
219
      SStream_concat0(O, ".s"); \
1309
219
      break; \
1310
281
    case 64: \
1311
281
      SStream_concat0(O, ".d"); \
1312
281
      break; \
1313
0
    default: \
1314
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1315
5.69k
    } \
1316
5.69k
  }
printPredicateAsCounter_8
Line
Count
Source
1285
175
  { \
1286
175
    AArch64_add_cs_detail_1( \
1287
175
      MI, \
1288
175
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1289
175
      OpNum, EltSize); \
1290
175
    unsigned Reg = \
1291
175
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1292
175
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1293
175
      CS_ASSERT_RET( \
1294
175
        0 && \
1295
175
        "Unsupported predicate-as-counter register"); \
1296
175
    SStream_concat(O, "%s", "pn"); \
1297
175
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1298
175
    switch (EltSize) { \
1299
0
    case 0: \
1300
0
      break; \
1301
175
    case 8: \
1302
175
      SStream_concat0(O, ".b"); \
1303
175
      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
175
    } \
1316
175
  }
printPredicateAsCounter_64
Line
Count
Source
1285
281
  { \
1286
281
    AArch64_add_cs_detail_1( \
1287
281
      MI, \
1288
281
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1289
281
      OpNum, EltSize); \
1290
281
    unsigned Reg = \
1291
281
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1292
281
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1293
281
      CS_ASSERT_RET( \
1294
281
        0 && \
1295
281
        "Unsupported predicate-as-counter register"); \
1296
281
    SStream_concat(O, "%s", "pn"); \
1297
281
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1298
281
    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
281
    case 64: \
1311
281
      SStream_concat0(O, ".d"); \
1312
281
      break; \
1313
0
    default: \
1314
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1315
281
    } \
1316
281
  }
printPredicateAsCounter_16
Line
Count
Source
1285
72
  { \
1286
72
    AArch64_add_cs_detail_1( \
1287
72
      MI, \
1288
72
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1289
72
      OpNum, EltSize); \
1290
72
    unsigned Reg = \
1291
72
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1292
72
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1293
72
      CS_ASSERT_RET( \
1294
72
        0 && \
1295
72
        "Unsupported predicate-as-counter register"); \
1296
72
    SStream_concat(O, "%s", "pn"); \
1297
72
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1298
72
    switch (EltSize) { \
1299
0
    case 0: \
1300
0
      break; \
1301
0
    case 8: \
1302
0
      SStream_concat0(O, ".b"); \
1303
0
      break; \
1304
72
    case 16: \
1305
72
      SStream_concat0(O, ".h"); \
1306
72
      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
72
    } \
1316
72
  }
printPredicateAsCounter_32
Line
Count
Source
1285
219
  { \
1286
219
    AArch64_add_cs_detail_1( \
1287
219
      MI, \
1288
219
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1289
219
      OpNum, EltSize); \
1290
219
    unsigned Reg = \
1291
219
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1292
219
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1293
219
      CS_ASSERT_RET( \
1294
219
        0 && \
1295
219
        "Unsupported predicate-as-counter register"); \
1296
219
    SStream_concat(O, "%s", "pn"); \
1297
219
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1298
219
    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
219
    case 32: \
1308
219
      SStream_concat0(O, ".s"); \
1309
219
      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
219
    } \
1316
219
  }
printPredicateAsCounter_0
Line
Count
Source
1285
4.94k
  { \
1286
4.94k
    AArch64_add_cs_detail_1( \
1287
4.94k
      MI, \
1288
4.94k
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1289
4.94k
      OpNum, EltSize); \
1290
4.94k
    unsigned Reg = \
1291
4.94k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1292
4.94k
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1293
4.94k
      CS_ASSERT_RET( \
1294
4.94k
        0 && \
1295
4.94k
        "Unsupported predicate-as-counter register"); \
1296
4.94k
    SStream_concat(O, "%s", "pn"); \
1297
4.94k
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1298
4.94k
    switch (EltSize) { \
1299
4.94k
    case 0: \
1300
4.94k
      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
4.94k
    } \
1316
4.94k
  }
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.67k
{
1325
2.67k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_CondCode, OpNum);
1326
2.67k
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(
1327
2.67k
    MCInst_getOperand(MI, (OpNum)));
1328
2.67k
  SStream_concat0(O, AArch64CC_getCondCodeName(CC));
1329
2.67k
}
1330
1331
void printInverseCondCode(MCInst *MI, unsigned OpNum, SStream *O)
1332
167
{
1333
167
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_InverseCondCode, OpNum);
1334
167
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(
1335
167
    MCInst_getOperand(MI, (OpNum)));
1336
167
  SStream_concat0(O, AArch64CC_getCondCodeName(
1337
167
           AArch64CC_getInvertedCondCode(CC)));
1338
167
}
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
19.8k
  { \
1353
19.8k
    AArch64_add_cs_detail_1( \
1354
19.8k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1355
19.8k
      Scale); \
1356
19.8k
    SStream_concat(O, "%s", markup("<imm:")); \
1357
19.8k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1358
19.8k
              MI, (OpNum)))); \
1359
19.8k
    SStream_concat0(O, markup(">")); \
1360
19.8k
  }
printImmScale_8
Line
Count
Source
1352
5.48k
  { \
1353
5.48k
    AArch64_add_cs_detail_1( \
1354
5.48k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1355
5.48k
      Scale); \
1356
5.48k
    SStream_concat(O, "%s", markup("<imm:")); \
1357
5.48k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1358
5.48k
              MI, (OpNum)))); \
1359
5.48k
    SStream_concat0(O, markup(">")); \
1360
5.48k
  }
printImmScale_2
Line
Count
Source
1352
1.81k
  { \
1353
1.81k
    AArch64_add_cs_detail_1( \
1354
1.81k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1355
1.81k
      Scale); \
1356
1.81k
    SStream_concat(O, "%s", markup("<imm:")); \
1357
1.81k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1358
1.81k
              MI, (OpNum)))); \
1359
1.81k
    SStream_concat0(O, markup(">")); \
1360
1.81k
  }
printImmScale_4
Line
Count
Source
1352
8.14k
  { \
1353
8.14k
    AArch64_add_cs_detail_1( \
1354
8.14k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1355
8.14k
      Scale); \
1356
8.14k
    SStream_concat(O, "%s", markup("<imm:")); \
1357
8.14k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1358
8.14k
              MI, (OpNum)))); \
1359
8.14k
    SStream_concat0(O, markup(">")); \
1360
8.14k
  }
printImmScale_16
Line
Count
Source
1352
3.47k
  { \
1353
3.47k
    AArch64_add_cs_detail_1( \
1354
3.47k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1355
3.47k
      Scale); \
1356
3.47k
    SStream_concat(O, "%s", markup("<imm:")); \
1357
3.47k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1358
3.47k
              MI, (OpNum)))); \
1359
3.47k
    SStream_concat0(O, markup(">")); \
1360
3.47k
  }
printImmScale_32
Line
Count
Source
1352
104
  { \
1353
104
    AArch64_add_cs_detail_1( \
1354
104
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1355
104
      Scale); \
1356
104
    SStream_concat(O, "%s", markup("<imm:")); \
1357
104
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1358
104
              MI, (OpNum)))); \
1359
104
    SStream_concat0(O, markup(">")); \
1360
104
  }
printImmScale_3
Line
Count
Source
1352
787
  { \
1353
787
    AArch64_add_cs_detail_1( \
1354
787
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1355
787
      Scale); \
1356
787
    SStream_concat(O, "%s", markup("<imm:")); \
1357
787
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1358
787
              MI, (OpNum)))); \
1359
787
    SStream_concat0(O, markup(">")); \
1360
787
  }
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.28k
  { \
1372
5.28k
    AArch64_add_cs_detail_2( \
1373
5.28k
      MI, \
1374
5.28k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1375
5.28k
             Offset), \
1376
5.28k
      OpNum, Scale, Offset); \
1377
5.28k
    unsigned FirstImm = \
1378
5.28k
      Scale * \
1379
5.28k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1380
5.28k
    printUInt32(O, (FirstImm)); \
1381
5.28k
    SStream_concat(O, "%s", ":"); \
1382
5.28k
    printUInt32(O, (FirstImm + Offset)); \
1383
5.28k
    SStream_concat1(O, '\0'); \
1384
5.28k
  }
printImmRangeScale_2_1
Line
Count
Source
1371
3.24k
  { \
1372
3.24k
    AArch64_add_cs_detail_2( \
1373
3.24k
      MI, \
1374
3.24k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1375
3.24k
             Offset), \
1376
3.24k
      OpNum, Scale, Offset); \
1377
3.24k
    unsigned FirstImm = \
1378
3.24k
      Scale * \
1379
3.24k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1380
3.24k
    printUInt32(O, (FirstImm)); \
1381
3.24k
    SStream_concat(O, "%s", ":"); \
1382
3.24k
    printUInt32(O, (FirstImm + Offset)); \
1383
3.24k
    SStream_concat1(O, '\0'); \
1384
3.24k
  }
printImmRangeScale_4_3
Line
Count
Source
1371
2.03k
  { \
1372
2.03k
    AArch64_add_cs_detail_2( \
1373
2.03k
      MI, \
1374
2.03k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1375
2.03k
             Offset), \
1376
2.03k
      OpNum, Scale, Offset); \
1377
2.03k
    unsigned FirstImm = \
1378
2.03k
      Scale * \
1379
2.03k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1380
2.03k
    printUInt32(O, (FirstImm)); \
1381
2.03k
    SStream_concat(O, "%s", ":"); \
1382
2.03k
    printUInt32(O, (FirstImm + Offset)); \
1383
2.03k
    SStream_concat1(O, '\0'); \
1384
2.03k
  }
1385
DEFINE_printImmRangeScale(2, 1);
1386
DEFINE_printImmRangeScale(4, 3);
1387
1388
void printUImm12Offset(MCInst *MI, unsigned OpNum, unsigned Scale, SStream *O)
1389
6.19k
{
1390
6.19k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1391
6.19k
  if (MCOperand_isImm(MO)) {
1392
6.19k
    SStream_concat(O, "%s", markup("<imm:"));
1393
6.19k
    printUInt32Bang(O, (MCOperand_getImm(MO) * Scale));
1394
6.19k
    SStream_concat0(O, markup(">"));
1395
6.19k
  } else {
1396
0
    printUInt64Bang(O, MCOperand_getImm(MO));
1397
0
  }
1398
6.19k
}
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
325
{
1418
325
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_RPRFMOperand, OpNum);
1419
325
  unsigned prfop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1420
325
  const AArch64PRFM_PRFM *PRFM =
1421
325
    AArch64RPRFM_lookupRPRFMByEncoding(prfop);
1422
325
  if (PRFM) {
1423
175
    SStream_concat0(O, PRFM->Name);
1424
175
    return;
1425
175
  }
1426
1427
150
  printUInt32Bang(O, (prfop));
1428
150
  SStream_concat1(O, '\0');
1429
150
}
1430
1431
#define DEFINE_printPrefetchOp(IsSVEPrefetch) \
1432
  void CONCAT(printPrefetchOp, \
1433
        IsSVEPrefetch)(MCInst * MI, unsigned OpNum, SStream *O) \
1434
5.40k
  { \
1435
5.40k
    AArch64_add_cs_detail_1(MI, \
1436
5.40k
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1437
5.40k
                 IsSVEPrefetch), \
1438
5.40k
          OpNum, IsSVEPrefetch); \
1439
5.40k
    unsigned prfop = \
1440
5.40k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1441
5.40k
    if (IsSVEPrefetch) { \
1442
4.28k
      const AArch64SVEPRFM_SVEPRFM *PRFM = \
1443
4.28k
        AArch64SVEPRFM_lookupSVEPRFMByEncoding(prfop); \
1444
4.28k
      if (PRFM) { \
1445
3.85k
        SStream_concat0(O, PRFM->Name); \
1446
3.85k
        return; \
1447
3.85k
      } \
1448
4.28k
    } else { \
1449
1.11k
      const AArch64PRFM_PRFM *PRFM = \
1450
1.11k
        AArch64PRFM_lookupPRFMByEncoding(prfop); \
1451
1.11k
      if (PRFM && \
1452
1.11k
          AArch64_testFeatureList(MI->csh->mode, \
1453
669
                PRFM->FeaturesRequired)) { \
1454
669
        SStream_concat0(O, PRFM->Name); \
1455
669
        return; \
1456
669
      } \
1457
1.11k
    } \
1458
5.40k
\
1459
5.40k
    SStream_concat(O, "%s", markup("<imm:")); \
1460
882
    printUInt32Bang(O, (prfop)); \
1461
882
    SStream_concat0(O, markup(">")); \
1462
882
  }
printPrefetchOp_0
Line
Count
Source
1434
1.11k
  { \
1435
1.11k
    AArch64_add_cs_detail_1(MI, \
1436
1.11k
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1437
1.11k
                 IsSVEPrefetch), \
1438
1.11k
          OpNum, IsSVEPrefetch); \
1439
1.11k
    unsigned prfop = \
1440
1.11k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1441
1.11k
    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.11k
    } else { \
1449
1.11k
      const AArch64PRFM_PRFM *PRFM = \
1450
1.11k
        AArch64PRFM_lookupPRFMByEncoding(prfop); \
1451
1.11k
      if (PRFM && \
1452
1.11k
          AArch64_testFeatureList(MI->csh->mode, \
1453
669
                PRFM->FeaturesRequired)) { \
1454
669
        SStream_concat0(O, PRFM->Name); \
1455
669
        return; \
1456
669
      } \
1457
1.11k
    } \
1458
1.11k
\
1459
1.11k
    SStream_concat(O, "%s", markup("<imm:")); \
1460
450
    printUInt32Bang(O, (prfop)); \
1461
450
    SStream_concat0(O, markup(">")); \
1462
450
  }
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.85k
        SStream_concat0(O, PRFM->Name); \
1446
3.85k
        return; \
1447
3.85k
      } \
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
432
    printUInt32Bang(O, (prfop)); \
1461
432
    SStream_concat0(O, markup(">")); \
1462
432
  }
1463
DEFINE_printPrefetchOp(false);
1464
DEFINE_printPrefetchOp(true);
1465
1466
void printPSBHintOp(MCInst *MI, unsigned OpNum, SStream *O)
1467
283
{
1468
283
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_PSBHintOp, OpNum);
1469
283
  unsigned psbhintop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1470
283
  const AArch64PSBHint_PSB *PSB =
1471
283
    AArch64PSBHint_lookupPSBByEncoding(psbhintop);
1472
283
  if (PSB)
1473
283
    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
283
}
1481
1482
void printBTIHintOp(MCInst *MI, unsigned OpNum, SStream *O)
1483
58
{
1484
58
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BTIHintOp, OpNum);
1485
58
  unsigned btihintop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) ^
1486
58
           32;
1487
58
  const AArch64BTIHint_BTI *BTI =
1488
58
    AArch64BTIHint_lookupBTIByEncoding(btihintop);
1489
58
  if (BTI)
1490
58
    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
58
}
1497
1498
static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1499
812
{
1500
812
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_FPImmOperand, OpNum);
1501
812
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1502
812
  float FPImm = MCOperand_isDFPImm(MO) ?
1503
0
            BitsToDouble(MCOperand_getImm(MO)) :
1504
812
            AArch64_AM_getFPImmFloat(MCOperand_getImm(MO));
1505
1506
  // 8 decimal places are enough to perfectly represent permitted floats.
1507
812
  SStream_concat(O, "%s", markup("<imm:"));
1508
812
  SStream_concat(O, "#%.8f", FPImm);
1509
812
  SStream_concat0(O, markup(">"));
1510
812
}
1511
1512
static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride /* = 1 */)
1513
115k
{
1514
298k
  while (Stride--) {
1515
183k
    switch (Reg) {
1516
0
    default:
1517
0
      CS_ASSERT_RET_VAL(0 && "Vector register expected!", 0);
1518
5.36k
    case AArch64_Q0:
1519
5.36k
      Reg = AArch64_Q1;
1520
5.36k
      break;
1521
4.36k
    case AArch64_Q1:
1522
4.36k
      Reg = AArch64_Q2;
1523
4.36k
      break;
1524
2.17k
    case AArch64_Q2:
1525
2.17k
      Reg = AArch64_Q3;
1526
2.17k
      break;
1527
1.73k
    case AArch64_Q3:
1528
1.73k
      Reg = AArch64_Q4;
1529
1.73k
      break;
1530
1.50k
    case AArch64_Q4:
1531
1.50k
      Reg = AArch64_Q5;
1532
1.50k
      break;
1533
1.64k
    case AArch64_Q5:
1534
1.64k
      Reg = AArch64_Q6;
1535
1.64k
      break;
1536
710
    case AArch64_Q6:
1537
710
      Reg = AArch64_Q7;
1538
710
      break;
1539
770
    case AArch64_Q7:
1540
770
      Reg = AArch64_Q8;
1541
770
      break;
1542
784
    case AArch64_Q8:
1543
784
      Reg = AArch64_Q9;
1544
784
      break;
1545
1.00k
    case AArch64_Q9:
1546
1.00k
      Reg = AArch64_Q10;
1547
1.00k
      break;
1548
1.50k
    case AArch64_Q10:
1549
1.50k
      Reg = AArch64_Q11;
1550
1.50k
      break;
1551
1.93k
    case AArch64_Q11:
1552
1.93k
      Reg = AArch64_Q12;
1553
1.93k
      break;
1554
3.46k
    case AArch64_Q12:
1555
3.46k
      Reg = AArch64_Q13;
1556
3.46k
      break;
1557
2.64k
    case AArch64_Q13:
1558
2.64k
      Reg = AArch64_Q14;
1559
2.64k
      break;
1560
2.46k
    case AArch64_Q14:
1561
2.46k
      Reg = AArch64_Q15;
1562
2.46k
      break;
1563
876
    case AArch64_Q15:
1564
876
      Reg = AArch64_Q16;
1565
876
      break;
1566
1.17k
    case AArch64_Q16:
1567
1.17k
      Reg = AArch64_Q17;
1568
1.17k
      break;
1569
1.28k
    case AArch64_Q17:
1570
1.28k
      Reg = AArch64_Q18;
1571
1.28k
      break;
1572
1.41k
    case AArch64_Q18:
1573
1.41k
      Reg = AArch64_Q19;
1574
1.41k
      break;
1575
1.95k
    case AArch64_Q19:
1576
1.95k
      Reg = AArch64_Q20;
1577
1.95k
      break;
1578
3.73k
    case AArch64_Q20:
1579
3.73k
      Reg = AArch64_Q21;
1580
3.73k
      break;
1581
2.41k
    case AArch64_Q21:
1582
2.41k
      Reg = AArch64_Q22;
1583
2.41k
      break;
1584
2.32k
    case AArch64_Q22:
1585
2.32k
      Reg = AArch64_Q23;
1586
2.32k
      break;
1587
1.85k
    case AArch64_Q23:
1588
1.85k
      Reg = AArch64_Q24;
1589
1.85k
      break;
1590
1.79k
    case AArch64_Q24:
1591
1.79k
      Reg = AArch64_Q25;
1592
1.79k
      break;
1593
1.67k
    case AArch64_Q25:
1594
1.67k
      Reg = AArch64_Q26;
1595
1.67k
      break;
1596
1.41k
    case AArch64_Q26:
1597
1.41k
      Reg = AArch64_Q27;
1598
1.41k
      break;
1599
969
    case AArch64_Q27:
1600
969
      Reg = AArch64_Q28;
1601
969
      break;
1602
793
    case AArch64_Q28:
1603
793
      Reg = AArch64_Q29;
1604
793
      break;
1605
897
    case AArch64_Q29:
1606
897
      Reg = AArch64_Q30;
1607
897
      break;
1608
635
    case AArch64_Q30:
1609
635
      Reg = AArch64_Q31;
1610
635
      break;
1611
    // Vector lists can wrap around.
1612
2.08k
    case AArch64_Q31:
1613
2.08k
      Reg = AArch64_Q0;
1614
2.08k
      break;
1615
9.73k
    case AArch64_Z0:
1616
9.73k
      Reg = AArch64_Z1;
1617
9.73k
      break;
1618
6.63k
    case AArch64_Z1:
1619
6.63k
      Reg = AArch64_Z2;
1620
6.63k
      break;
1621
7.10k
    case AArch64_Z2:
1622
7.10k
      Reg = AArch64_Z3;
1623
7.10k
      break;
1624
2.71k
    case AArch64_Z3:
1625
2.71k
      Reg = AArch64_Z4;
1626
2.71k
      break;
1627
11.4k
    case AArch64_Z4:
1628
11.4k
      Reg = AArch64_Z5;
1629
11.4k
      break;
1630
9.23k
    case AArch64_Z5:
1631
9.23k
      Reg = AArch64_Z6;
1632
9.23k
      break;
1633
6.95k
    case AArch64_Z6:
1634
6.95k
      Reg = AArch64_Z7;
1635
6.95k
      break;
1636
2.98k
    case AArch64_Z7:
1637
2.98k
      Reg = AArch64_Z8;
1638
2.98k
      break;
1639
7.10k
    case AArch64_Z8:
1640
7.10k
      Reg = AArch64_Z9;
1641
7.10k
      break;
1642
4.47k
    case AArch64_Z9:
1643
4.47k
      Reg = AArch64_Z10;
1644
4.47k
      break;
1645
4.77k
    case AArch64_Z10:
1646
4.77k
      Reg = AArch64_Z11;
1647
4.77k
      break;
1648
2.09k
    case AArch64_Z11:
1649
2.09k
      Reg = AArch64_Z12;
1650
2.09k
      break;
1651
2.90k
    case AArch64_Z12:
1652
2.90k
      Reg = AArch64_Z13;
1653
2.90k
      break;
1654
2.59k
    case AArch64_Z13:
1655
2.59k
      Reg = AArch64_Z14;
1656
2.59k
      break;
1657
3.87k
    case AArch64_Z14:
1658
3.87k
      Reg = AArch64_Z15;
1659
3.87k
      break;
1660
2.11k
    case AArch64_Z15:
1661
2.11k
      Reg = AArch64_Z16;
1662
2.11k
      break;
1663
2.01k
    case AArch64_Z16:
1664
2.01k
      Reg = AArch64_Z17;
1665
2.01k
      break;
1666
904
    case AArch64_Z17:
1667
904
      Reg = AArch64_Z18;
1668
904
      break;
1669
1.56k
    case AArch64_Z18:
1670
1.56k
      Reg = AArch64_Z19;
1671
1.56k
      break;
1672
1.24k
    case AArch64_Z19:
1673
1.24k
      Reg = AArch64_Z20;
1674
1.24k
      break;
1675
2.74k
    case AArch64_Z20:
1676
2.74k
      Reg = AArch64_Z21;
1677
2.74k
      break;
1678
2.75k
    case AArch64_Z21:
1679
2.75k
      Reg = AArch64_Z22;
1680
2.75k
      break;
1681
3.84k
    case AArch64_Z22:
1682
3.84k
      Reg = AArch64_Z23;
1683
3.84k
      break;
1684
1.35k
    case AArch64_Z23:
1685
1.35k
      Reg = AArch64_Z24;
1686
1.35k
      break;
1687
2.95k
    case AArch64_Z24:
1688
2.95k
      Reg = AArch64_Z25;
1689
2.95k
      break;
1690
2.92k
    case AArch64_Z25:
1691
2.92k
      Reg = AArch64_Z26;
1692
2.92k
      break;
1693
3.37k
    case AArch64_Z26:
1694
3.37k
      Reg = AArch64_Z27;
1695
3.37k
      break;
1696
2.03k
    case AArch64_Z27:
1697
2.03k
      Reg = AArch64_Z28;
1698
2.03k
      break;
1699
2.79k
    case AArch64_Z28:
1700
2.79k
      Reg = AArch64_Z29;
1701
2.79k
      break;
1702
1.50k
    case AArch64_Z29:
1703
1.50k
      Reg = AArch64_Z30;
1704
1.50k
      break;
1705
1.51k
    case AArch64_Z30:
1706
1.51k
      Reg = AArch64_Z31;
1707
1.51k
      break;
1708
    // Vector lists can wrap around.
1709
1.64k
    case AArch64_Z31:
1710
1.64k
      Reg = AArch64_Z0;
1711
1.64k
      break;
1712
62
    case AArch64_P0:
1713
62
      Reg = AArch64_P1;
1714
62
      break;
1715
330
    case AArch64_P1:
1716
330
      Reg = AArch64_P2;
1717
330
      break;
1718
112
    case AArch64_P2:
1719
112
      Reg = AArch64_P3;
1720
112
      break;
1721
262
    case AArch64_P3:
1722
262
      Reg = AArch64_P4;
1723
262
      break;
1724
24
    case AArch64_P4:
1725
24
      Reg = AArch64_P5;
1726
24
      break;
1727
136
    case AArch64_P5:
1728
136
      Reg = AArch64_P6;
1729
136
      break;
1730
114
    case AArch64_P6:
1731
114
      Reg = AArch64_P7;
1732
114
      break;
1733
238
    case AArch64_P7:
1734
238
      Reg = AArch64_P8;
1735
238
      break;
1736
30
    case AArch64_P8:
1737
30
      Reg = AArch64_P9;
1738
30
      break;
1739
22
    case AArch64_P9:
1740
22
      Reg = AArch64_P10;
1741
22
      break;
1742
102
    case AArch64_P10:
1743
102
      Reg = AArch64_P11;
1744
102
      break;
1745
44
    case AArch64_P11:
1746
44
      Reg = AArch64_P12;
1747
44
      break;
1748
156
    case AArch64_P12:
1749
156
      Reg = AArch64_P13;
1750
156
      break;
1751
320
    case AArch64_P13:
1752
320
      Reg = AArch64_P14;
1753
320
      break;
1754
78
    case AArch64_P14:
1755
78
      Reg = AArch64_P15;
1756
78
      break;
1757
    // Vector lists can wrap around.
1758
92
    case AArch64_P15:
1759
92
      Reg = AArch64_P0;
1760
92
      break;
1761
183k
    }
1762
183k
  }
1763
115k
  return Reg;
1764
115k
}
1765
1766
#define DEFINE_printGPRSeqPairsClassOperand(size) \
1767
  void CONCAT(printGPRSeqPairsClassOperand, \
1768
        size)(MCInst * MI, unsigned OpNum, SStream *O) \
1769
2.34k
  { \
1770
2.34k
    AArch64_add_cs_detail_1( \
1771
2.34k
      MI, \
1772
2.34k
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1773
2.34k
             size), \
1774
2.34k
      OpNum, size); \
1775
2.34k
    CS_ASSERT_RET((size == 64 || size == 32) && \
1776
2.34k
            "Template parameter must be either 32 or 64"); \
1777
2.34k
    unsigned Reg = \
1778
2.34k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1779
2.34k
\
1780
2.34k
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1781
2.34k
                 AArch64_sube64; \
1782
2.34k
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1783
2.34k
                 AArch64_subo64; \
1784
2.34k
\
1785
2.34k
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1786
2.34k
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1787
2.34k
    printRegName(O, Even); \
1788
2.34k
    SStream_concat0(O, ", "); \
1789
2.34k
    printRegName(O, Odd); \
1790
2.34k
  }
printGPRSeqPairsClassOperand_32
Line
Count
Source
1769
176
  { \
1770
176
    AArch64_add_cs_detail_1( \
1771
176
      MI, \
1772
176
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1773
176
             size), \
1774
176
      OpNum, size); \
1775
176
    CS_ASSERT_RET((size == 64 || size == 32) && \
1776
176
            "Template parameter must be either 32 or 64"); \
1777
176
    unsigned Reg = \
1778
176
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1779
176
\
1780
176
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1781
176
                 AArch64_sube64; \
1782
176
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1783
176
                 AArch64_subo64; \
1784
176
\
1785
176
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1786
176
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1787
176
    printRegName(O, Even); \
1788
176
    SStream_concat0(O, ", "); \
1789
176
    printRegName(O, Odd); \
1790
176
  }
printGPRSeqPairsClassOperand_64
Line
Count
Source
1769
2.17k
  { \
1770
2.17k
    AArch64_add_cs_detail_1( \
1771
2.17k
      MI, \
1772
2.17k
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1773
2.17k
             size), \
1774
2.17k
      OpNum, size); \
1775
2.17k
    CS_ASSERT_RET((size == 64 || size == 32) && \
1776
2.17k
            "Template parameter must be either 32 or 64"); \
1777
2.17k
    unsigned Reg = \
1778
2.17k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1779
2.17k
\
1780
2.17k
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1781
2.17k
                 AArch64_sube64; \
1782
2.17k
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1783
2.17k
                 AArch64_subo64; \
1784
2.17k
\
1785
2.17k
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1786
2.17k
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1787
2.17k
    printRegName(O, Even); \
1788
2.17k
    SStream_concat0(O, ", "); \
1789
2.17k
    printRegName(O, Odd); \
1790
2.17k
  }
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
8.74k
  { \
1798
8.74k
    AArch64_add_cs_detail_1( \
1799
8.74k
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1800
8.74k
      OpNum, Scale); \
1801
8.74k
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1802
8.74k
                MI, (OpNum)))); \
1803
8.74k
  }
printMatrixIndex_8
Line
Count
Source
1797
180
  { \
1798
180
    AArch64_add_cs_detail_1( \
1799
180
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1800
180
      OpNum, Scale); \
1801
180
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1802
180
                MI, (OpNum)))); \
1803
180
  }
Unexecuted instantiation: printMatrixIndex_0
printMatrixIndex_1
Line
Count
Source
1797
8.56k
  { \
1798
8.56k
    AArch64_add_cs_detail_1( \
1799
8.56k
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1800
8.56k
      OpNum, Scale); \
1801
8.56k
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1802
8.56k
                MI, (OpNum)))); \
1803
8.56k
  }
1804
DEFINE_printMatrixIndex(8);
1805
DEFINE_printMatrixIndex(0);
1806
DEFINE_printMatrixIndex(1);
1807
1808
void printMatrixTileList(MCInst *MI, unsigned OpNum, SStream *O)
1809
646
{
1810
646
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MatrixTileList, OpNum);
1811
646
  unsigned MaxRegs = 8;
1812
646
  unsigned RegMask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1813
1814
646
  unsigned NumRegs = 0;
1815
5.81k
  for (unsigned I = 0; I < MaxRegs; ++I)
1816
5.16k
    if ((RegMask & (1 << I)) != 0)
1817
2.85k
      ++NumRegs;
1818
1819
646
  SStream_concat0(O, "{");
1820
646
  unsigned Printed = 0;
1821
5.81k
  for (unsigned I = 0; I < MaxRegs; ++I) {
1822
5.16k
    unsigned Reg = RegMask & (1 << I);
1823
5.16k
    if (Reg == 0)
1824
2.31k
      continue;
1825
2.85k
    printRegName(O, AArch64_ZAD0 + I);
1826
2.85k
    if (Printed + 1 != NumRegs)
1827
2.20k
      SStream_concat0(O, ", ");
1828
2.85k
    ++Printed;
1829
2.85k
  }
1830
646
  SStream_concat0(O, "}");
1831
646
}
1832
1833
void printVectorList(MCInst *MI, unsigned OpNum, SStream *O,
1834
         const char *LayoutSuffix)
1835
56.8k
{
1836
56.8k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1837
1838
56.8k
  SStream_concat0(O, "{ ");
1839
1840
  // Work out how many registers there are in the list (if there is an actual
1841
  // list).
1842
56.8k
  unsigned NumRegs = 1;
1843
56.8k
  if (MCRegisterClass_contains(
1844
56.8k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_DDRegClassID),
1845
56.8k
        Reg) ||
1846
55.7k
      MCRegisterClass_contains(
1847
55.7k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_ZPR2RegClassID),
1848
55.7k
        Reg) ||
1849
46.3k
      MCRegisterClass_contains(
1850
46.3k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_QQRegClassID),
1851
46.3k
        Reg) ||
1852
41.8k
      MCRegisterClass_contains(
1853
41.8k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_PPR2RegClassID),
1854
41.8k
        Reg) ||
1855
40.8k
      MCRegisterClass_contains(
1856
40.8k
        MCRegisterInfo_getRegClass(MI->MRI,
1857
40.8k
                 AArch64_ZPR2StridedRegClassID),
1858
40.8k
        Reg))
1859
18.3k
    NumRegs = 2;
1860
38.4k
  else if (MCRegisterClass_contains(
1861
38.4k
       MCRegisterInfo_getRegClass(MI->MRI,
1862
38.4k
                AArch64_DDDRegClassID),
1863
38.4k
       Reg) ||
1864
37.5k
     MCRegisterClass_contains(
1865
37.5k
       MCRegisterInfo_getRegClass(MI->MRI,
1866
37.5k
                AArch64_ZPR3RegClassID),
1867
37.5k
       Reg) ||
1868
36.6k
     MCRegisterClass_contains(
1869
36.6k
       MCRegisterInfo_getRegClass(MI->MRI,
1870
36.6k
                AArch64_QQQRegClassID),
1871
36.6k
       Reg))
1872
8.56k
    NumRegs = 3;
1873
29.9k
  else if (MCRegisterClass_contains(
1874
29.9k
       MCRegisterInfo_getRegClass(MI->MRI,
1875
29.9k
                AArch64_DDDDRegClassID),
1876
29.9k
       Reg) ||
1877
29.4k
     MCRegisterClass_contains(
1878
29.4k
       MCRegisterInfo_getRegClass(MI->MRI,
1879
29.4k
                AArch64_ZPR4RegClassID),
1880
29.4k
       Reg) ||
1881
23.5k
     MCRegisterClass_contains(
1882
23.5k
       MCRegisterInfo_getRegClass(MI->MRI,
1883
23.5k
                AArch64_QQQQRegClassID),
1884
23.5k
       Reg) ||
1885
18.8k
     MCRegisterClass_contains(
1886
18.8k
       MCRegisterInfo_getRegClass(
1887
18.8k
         MI->MRI, AArch64_ZPR4StridedRegClassID),
1888
18.8k
       Reg))
1889
11.8k
    NumRegs = 4;
1890
1891
56.8k
  unsigned Stride = 1;
1892
56.8k
  if (MCRegisterClass_contains(
1893
56.8k
        MCRegisterInfo_getRegClass(MI->MRI,
1894
56.8k
                 AArch64_ZPR2StridedRegClassID),
1895
56.8k
        Reg))
1896
2.36k
    Stride = 8;
1897
54.4k
  else if (MCRegisterClass_contains(
1898
54.4k
       MCRegisterInfo_getRegClass(
1899
54.4k
         MI->MRI, AArch64_ZPR4StridedRegClassID),
1900
54.4k
       Reg))
1901
812
    Stride = 4;
1902
1903
  // Now forget about the list and find out what the first register is.
1904
56.8k
  if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_dsub0))
1905
2.45k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_dsub0);
1906
54.3k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_qsub0))
1907
15.9k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_qsub0);
1908
38.3k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_zsub0))
1909
19.3k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_zsub0);
1910
19.0k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_psub0))
1911
1.03k
    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
56.8k
  if (MCRegisterClass_contains(MCRegisterInfo_getRegClass(
1916
56.8k
               MI->MRI, AArch64_FPR64RegClassID),
1917
56.8k
             Reg)) {
1918
2.81k
    const MCRegisterClass *FPR128RC = MCRegisterInfo_getRegClass(
1919
2.81k
      MI->MRI, AArch64_FPR128RegClassID);
1920
2.81k
    Reg = MCRegisterInfo_getMatchingSuperReg(
1921
2.81k
      MI->MRI, Reg, AArch64_dsub, FPR128RC);
1922
2.81k
  }
1923
1924
56.8k
  if ((MCRegisterClass_contains(
1925
56.8k
         MCRegisterInfo_getRegClass(MI->MRI, AArch64_ZPRRegClassID),
1926
56.8k
         Reg) ||
1927
23.8k
       MCRegisterClass_contains(
1928
23.8k
         MCRegisterInfo_getRegClass(MI->MRI, AArch64_PPRRegClassID),
1929
23.8k
         Reg)) &&
1930
34.0k
      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
17.1k
      Reg < getNextVectorRegister(Reg, NumRegs - 1)) {
1934
17.0k
    printRegName(O, Reg);
1935
17.0k
    SStream_concat0(O, LayoutSuffix);
1936
17.0k
    if (NumRegs > 1) {
1937
      // Set of two sve registers should be separated by ','
1938
17.0k
      const char *split_char = NumRegs == 2 ? ", " : " - ";
1939
17.0k
      SStream_concat0(O, split_char);
1940
17.0k
      printRegName(O,
1941
17.0k
             (getNextVectorRegister(Reg, NumRegs - 1)));
1942
17.0k
      SStream_concat0(O, LayoutSuffix);
1943
17.0k
    }
1944
39.8k
  } else {
1945
121k
    for (unsigned i = 0; i < NumRegs;
1946
81.2k
         ++i, Reg = getNextVectorRegister(Reg, Stride)) {
1947
      // wrap-around sve register
1948
81.2k
      if (MCRegisterClass_contains(
1949
81.2k
            MCRegisterInfo_getRegClass(
1950
81.2k
              MI->MRI, AArch64_ZPRRegClassID),
1951
81.2k
            Reg) ||
1952
59.4k
          MCRegisterClass_contains(
1953
59.4k
            MCRegisterInfo_getRegClass(
1954
59.4k
              MI->MRI, AArch64_PPRRegClassID),
1955
59.4k
            Reg))
1956
21.9k
        printRegName(O, Reg);
1957
59.3k
      else
1958
59.3k
        printRegNameAlt(O, Reg, AArch64_vreg);
1959
81.2k
      SStream_concat0(O, LayoutSuffix);
1960
81.2k
      if (i + 1 != NumRegs)
1961
41.4k
        SStream_concat0(O, ", ");
1962
81.2k
    }
1963
39.8k
  }
1964
56.8k
  SStream_concat0(O, " }");
1965
56.8k
}
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
56.8k
  { \
1978
56.8k
    AArch64_add_cs_detail_2( \
1979
56.8k
      MI, \
1980
56.8k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
56.8k
              NumLanes), \
1982
56.8k
             LaneKind), \
1983
56.8k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
56.8k
    if (CHAR(LaneKind) == '0') { \
1985
152
      printVectorList(MI, OpNum, O, ""); \
1986
152
      return; \
1987
152
    } \
1988
56.8k
    char Suffix[32]; \
1989
56.6k
    if (NumLanes) \
1990
56.6k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
8.16k
            CHAR(LaneKind)); \
1992
56.6k
    else \
1993
56.6k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
48.5k
            CHAR(LaneKind)); \
1995
56.6k
\
1996
56.6k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
56.6k
  }
printTypedVectorList_0_b
Line
Count
Source
1977
10.2k
  { \
1978
10.2k
    AArch64_add_cs_detail_2( \
1979
10.2k
      MI, \
1980
10.2k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
10.2k
              NumLanes), \
1982
10.2k
             LaneKind), \
1983
10.2k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
10.2k
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
10.2k
    char Suffix[32]; \
1989
10.2k
    if (NumLanes) \
1990
10.2k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
0
            CHAR(LaneKind)); \
1992
10.2k
    else \
1993
10.2k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
10.2k
            CHAR(LaneKind)); \
1995
10.2k
\
1996
10.2k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
10.2k
  }
printTypedVectorList_0_d
Line
Count
Source
1977
15.1k
  { \
1978
15.1k
    AArch64_add_cs_detail_2( \
1979
15.1k
      MI, \
1980
15.1k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
15.1k
              NumLanes), \
1982
15.1k
             LaneKind), \
1983
15.1k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
15.1k
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
15.1k
    char Suffix[32]; \
1989
15.1k
    if (NumLanes) \
1990
15.1k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
0
            CHAR(LaneKind)); \
1992
15.1k
    else \
1993
15.1k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
15.1k
            CHAR(LaneKind)); \
1995
15.1k
\
1996
15.1k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
15.1k
  }
printTypedVectorList_0_h
Line
Count
Source
1977
11.4k
  { \
1978
11.4k
    AArch64_add_cs_detail_2( \
1979
11.4k
      MI, \
1980
11.4k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
11.4k
              NumLanes), \
1982
11.4k
             LaneKind), \
1983
11.4k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
11.4k
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
11.4k
    char Suffix[32]; \
1989
11.4k
    if (NumLanes) \
1990
11.4k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
0
            CHAR(LaneKind)); \
1992
11.4k
    else \
1993
11.4k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
11.4k
            CHAR(LaneKind)); \
1995
11.4k
\
1996
11.4k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
11.4k
  }
printTypedVectorList_0_s
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_q
Line
Count
Source
1977
571
  { \
1978
571
    AArch64_add_cs_detail_2( \
1979
571
      MI, \
1980
571
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
571
              NumLanes), \
1982
571
             LaneKind), \
1983
571
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
571
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
571
    char Suffix[32]; \
1989
571
    if (NumLanes) \
1990
571
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
0
            CHAR(LaneKind)); \
1992
571
    else \
1993
571
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
571
            CHAR(LaneKind)); \
1995
571
\
1996
571
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
571
  }
printTypedVectorList_16_b
Line
Count
Source
1977
1.91k
  { \
1978
1.91k
    AArch64_add_cs_detail_2( \
1979
1.91k
      MI, \
1980
1.91k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
1.91k
              NumLanes), \
1982
1.91k
             LaneKind), \
1983
1.91k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
1.91k
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
1.91k
    char Suffix[32]; \
1989
1.91k
    if (NumLanes) \
1990
1.91k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
1.91k
            CHAR(LaneKind)); \
1992
1.91k
    else \
1993
1.91k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
1.91k
\
1996
1.91k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
1.91k
  }
printTypedVectorList_1_d
Line
Count
Source
1977
294
  { \
1978
294
    AArch64_add_cs_detail_2( \
1979
294
      MI, \
1980
294
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
294
              NumLanes), \
1982
294
             LaneKind), \
1983
294
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
294
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
294
    char Suffix[32]; \
1989
294
    if (NumLanes) \
1990
294
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
294
            CHAR(LaneKind)); \
1992
294
    else \
1993
294
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
294
\
1996
294
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
294
  }
printTypedVectorList_2_d
Line
Count
Source
1977
1.35k
  { \
1978
1.35k
    AArch64_add_cs_detail_2( \
1979
1.35k
      MI, \
1980
1.35k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
1.35k
              NumLanes), \
1982
1.35k
             LaneKind), \
1983
1.35k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
1.35k
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
1.35k
    char Suffix[32]; \
1989
1.35k
    if (NumLanes) \
1990
1.35k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
1.35k
            CHAR(LaneKind)); \
1992
1.35k
    else \
1993
1.35k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
1.35k
\
1996
1.35k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
1.35k
  }
printTypedVectorList_2_s
Line
Count
Source
1977
642
  { \
1978
642
    AArch64_add_cs_detail_2( \
1979
642
      MI, \
1980
642
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
642
              NumLanes), \
1982
642
             LaneKind), \
1983
642
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
642
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
642
    char Suffix[32]; \
1989
642
    if (NumLanes) \
1990
642
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
642
            CHAR(LaneKind)); \
1992
642
    else \
1993
642
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
642
\
1996
642
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
642
  }
printTypedVectorList_4_h
Line
Count
Source
1977
842
  { \
1978
842
    AArch64_add_cs_detail_2( \
1979
842
      MI, \
1980
842
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
842
              NumLanes), \
1982
842
             LaneKind), \
1983
842
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
842
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
842
    char Suffix[32]; \
1989
842
    if (NumLanes) \
1990
842
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
842
            CHAR(LaneKind)); \
1992
842
    else \
1993
842
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
842
\
1996
842
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
842
  }
printTypedVectorList_4_s
Line
Count
Source
1977
855
  { \
1978
855
    AArch64_add_cs_detail_2( \
1979
855
      MI, \
1980
855
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
855
              NumLanes), \
1982
855
             LaneKind), \
1983
855
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
855
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
855
    char Suffix[32]; \
1989
855
    if (NumLanes) \
1990
855
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
855
            CHAR(LaneKind)); \
1992
855
    else \
1993
855
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
855
\
1996
855
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
855
  }
printTypedVectorList_8_b
Line
Count
Source
1977
1.04k
  { \
1978
1.04k
    AArch64_add_cs_detail_2( \
1979
1.04k
      MI, \
1980
1.04k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
1.04k
              NumLanes), \
1982
1.04k
             LaneKind), \
1983
1.04k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
1.04k
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
1.04k
    char Suffix[32]; \
1989
1.04k
    if (NumLanes) \
1990
1.04k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
1.04k
            CHAR(LaneKind)); \
1992
1.04k
    else \
1993
1.04k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
1.04k
\
1996
1.04k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
1.04k
  }
printTypedVectorList_8_h
Line
Count
Source
1977
1.22k
  { \
1978
1.22k
    AArch64_add_cs_detail_2( \
1979
1.22k
      MI, \
1980
1.22k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
1.22k
              NumLanes), \
1982
1.22k
             LaneKind), \
1983
1.22k
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
1.22k
    if (CHAR(LaneKind) == '0') { \
1985
0
      printVectorList(MI, OpNum, O, ""); \
1986
0
      return; \
1987
0
    } \
1988
1.22k
    char Suffix[32]; \
1989
1.22k
    if (NumLanes) \
1990
1.22k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
1991
1.22k
            CHAR(LaneKind)); \
1992
1.22k
    else \
1993
1.22k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
1994
0
            CHAR(LaneKind)); \
1995
1.22k
\
1996
1.22k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
1997
1.22k
  }
printTypedVectorList_0_0
Line
Count
Source
1977
152
  { \
1978
152
    AArch64_add_cs_detail_2( \
1979
152
      MI, \
1980
152
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1981
152
              NumLanes), \
1982
152
             LaneKind), \
1983
152
      OpNum, NumLanes, CHAR(LaneKind)); \
1984
152
    if (CHAR(LaneKind) == '0') { \
1985
152
      printVectorList(MI, OpNum, O, ""); \
1986
152
      return; \
1987
152
    } \
1988
152
    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
32.9k
  { \
2017
32.9k
    AArch64_add_cs_detail_1( \
2018
32.9k
      MI, CONCAT(AArch64_OP_GROUP_VectorIndex, Scale), \
2019
32.9k
      OpNum, Scale); \
2020
32.9k
    SStream_concat(O, "%s", "["); \
2021
32.9k
    printUInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
2022
32.9k
                 MI, (OpNum)))); \
2023
32.9k
    SStream_concat0(O, "]"); \
2024
32.9k
  }
printVectorIndex_1
Line
Count
Source
2016
32.9k
  { \
2017
32.9k
    AArch64_add_cs_detail_1( \
2018
32.9k
      MI, CONCAT(AArch64_OP_GROUP_VectorIndex, Scale), \
2019
32.9k
      OpNum, Scale); \
2020
32.9k
    SStream_concat(O, "%s", "["); \
2021
32.9k
    printUInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
2022
32.9k
                 MI, (OpNum)))); \
2023
32.9k
    SStream_concat0(O, "]"); \
2024
32.9k
  }
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
12.8k
{
2030
12.8k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AlignedLabel, OpNum);
2031
12.8k
  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
12.8k
  if (MCOperand_isImm(Op)) {
2036
12.7k
    SStream_concat0(O, markup("<imm:"));
2037
12.7k
    int64_t Offset = MCOperand_getImm(Op) * 4;
2038
12.7k
    if (MI->csh->PrintBranchImmAsAddress)
2039
12.7k
      printUInt64(O, (Address + Offset));
2040
0
    else {
2041
0
      printUInt64Bang(O, (Offset));
2042
0
    }
2043
12.7k
    SStream_concat0(O, markup(">"));
2044
12.7k
    return;
2045
12.7k
  }
2046
2047
89
  printUInt64Bang(O, MCOperand_getImm(Op));
2048
89
}
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
7.00k
{
2096
7.00k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AdrAdrpLabel, OpNum);
2097
7.00k
  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
7.00k
  if (MCOperand_isImm(Op)) {
2102
7.00k
    int64_t Offset = MCOperand_getImm(Op);
2103
7.00k
    if (MCInst_getOpcode(MI) == AArch64_ADRP) {
2104
3.40k
      Offset = Offset * 4096;
2105
3.40k
      Address = Address & -4096;
2106
3.40k
    }
2107
7.00k
    SStream_concat0(O, markup(">"));
2108
7.00k
    if (MI->csh->PrintBranchImmAsAddress)
2109
7.00k
      printUInt64(O, (Address + Offset));
2110
0
    else {
2111
0
      printUInt64Bang(O, Offset);
2112
0
    }
2113
7.00k
    SStream_concat0(O, markup(">"));
2114
7.00k
    return;
2115
7.00k
  }
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
126
{
2125
126
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AppleSysBarrierOption,
2126
126
        OpNo);
2127
126
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2128
126
  switch (Val) {
2129
61
  default:
2130
61
    SStream_concat0(O, "<undefined>");
2131
61
    break;
2132
12
  case 0:
2133
12
    SStream_concat0(O, "osh");
2134
12
    break;
2135
32
  case 1:
2136
32
    SStream_concat0(O, "nsh");
2137
32
    break;
2138
11
  case 2:
2139
11
    SStream_concat0(O, "ish");
2140
11
    break;
2141
10
  case 3:
2142
10
    SStream_concat0(O, "sy");
2143
10
    break;
2144
126
  }
2145
126
}
2146
2147
void printBarrierOption(MCInst *MI, unsigned OpNo, SStream *O)
2148
837
{
2149
837
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BarrierOption, OpNo);
2150
837
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2151
837
  unsigned Opcode = MCInst_getOpcode(MI);
2152
2153
837
  const char *Name;
2154
837
  if (Opcode == AArch64_ISB) {
2155
7
    const AArch64ISB_ISB *ISB = AArch64ISB_lookupISBByEncoding(Val);
2156
7
    Name = ISB ? ISB->Name : "";
2157
830
  } else if (Opcode == AArch64_TSB) {
2158
15
    const AArch64TSB_TSB *TSB = AArch64TSB_lookupTSBByEncoding(Val);
2159
15
    Name = TSB ? TSB->Name : "";
2160
815
  } else {
2161
815
    const AArch64DB_DB *DB = AArch64DB_lookupDBByEncoding(Val);
2162
815
    Name = DB ? DB->Name : "";
2163
815
  }
2164
837
  if (Name[0] != '\0')
2165
613
    SStream_concat0(O, Name);
2166
224
  else {
2167
224
    SStream_concat(O, "%s", markup("<imm:"));
2168
224
    printUInt32Bang(O, Val);
2169
224
    SStream_concat0(O, markup(">"));
2170
224
  }
2171
837
}
2172
2173
void printBarriernXSOption(MCInst *MI, unsigned OpNo, SStream *O)
2174
285
{
2175
285
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BarriernXSOption, OpNo);
2176
285
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2177
2178
285
  const char *Name;
2179
285
  const AArch64DBnXS_DBnXS *DB = AArch64DBnXS_lookupDBnXSByEncoding(Val);
2180
285
  Name = DB ? DB->Name : "";
2181
2182
285
  if (Name[0] != '\0')
2183
285
    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
285
}
2189
2190
static bool isValidSysReg(const AArch64SysReg_SysReg *Reg, bool Read,
2191
        unsigned mode)
2192
4.32k
{
2193
4.32k
  return (Reg && (Read ? Reg->Readable : Reg->Writeable) &&
2194
610
    AArch64_testFeatureList(mode, Reg->FeaturesRequired));
2195
4.32k
}
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
3.24k
{
2206
3.24k
  const AArch64SysReg_SysReg *Reg =
2207
3.24k
    AArch64SysReg_lookupSysRegByEncoding(Val);
2208
2209
3.24k
  if (Reg && !isValidSysReg(Reg, Read, mode))
2210
773
    Reg = AArch64SysReg_lookupSysRegByName(Reg->AltName);
2211
2212
3.24k
  return Reg;
2213
3.24k
}
2214
2215
void printMRSSystemRegister(MCInst *MI, unsigned OpNo, SStream *O)
2216
1.33k
{
2217
1.33k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MRSSystemRegister, OpNo);
2218
1.33k
  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
1.33k
  if (Val == AARCH64_SYSREG_DBGDTRRX_EL0) {
2224
171
    SStream_concat0(O, "DBGDTRRX_EL0");
2225
171
    return;
2226
171
  }
2227
2228
  // Horrible hack for two different registers having the same encoding.
2229
1.16k
  if (Val == AARCH64_SYSREG_TRCEXTINSELR) {
2230
16
    SStream_concat0(O, "TRCEXTINSELR");
2231
16
    return;
2232
16
  }
2233
2234
1.14k
  const AArch64SysReg_SysReg *Reg =
2235
1.14k
    lookupSysReg(Val, true /*Read*/, MI->csh->mode);
2236
2237
1.14k
  if (isValidSysReg(Reg, true /*Read*/, MI->csh->mode))
2238
91
    SStream_concat0(O, Reg->Name);
2239
1.05k
  else {
2240
1.05k
    char result[AARCH64_GRS_LEN + 1] = { 0 };
2241
1.05k
    AArch64SysReg_genericRegisterString(Val, result);
2242
1.05k
    SStream_concat0(O, result);
2243
1.05k
  }
2244
1.14k
}
2245
2246
void printMSRSystemRegister(MCInst *MI, unsigned OpNo, SStream *O)
2247
2.24k
{
2248
2.24k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MSRSystemRegister, OpNo);
2249
2.24k
  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.24k
  if (Val == AARCH64_SYSREG_DBGDTRTX_EL0) {
2255
76
    SStream_concat0(O, "DBGDTRTX_EL0");
2256
76
    return;
2257
76
  }
2258
2259
  // Horrible hack for two different registers having the same encoding.
2260
2.17k
  if (Val == AARCH64_SYSREG_TRCEXTINSELR) {
2261
68
    SStream_concat0(O, "TRCEXTINSELR");
2262
68
    return;
2263
68
  }
2264
2265
2.10k
  const AArch64SysReg_SysReg *Reg =
2266
2.10k
    lookupSysReg(Val, false /*Read*/, MI->csh->mode);
2267
2268
2.10k
  if (isValidSysReg(Reg, false /*Read*/, MI->csh->mode))
2269
214
    SStream_concat0(O, Reg->Name);
2270
1.88k
  else {
2271
1.88k
    char result[AARCH64_GRS_LEN + 1] = { 0 };
2272
1.88k
    AArch64SysReg_genericRegisterString(Val, result);
2273
1.88k
    SStream_concat0(O, result);
2274
1.88k
  }
2275
2.10k
}
2276
2277
void printSystemPStateField(MCInst *MI, unsigned OpNo, SStream *O)
2278
156
{
2279
156
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SystemPStateField, OpNo);
2280
156
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2281
2282
156
  const AArch64PState_PStateImm0_15 *PStateImm15 =
2283
156
    AArch64PState_lookupPStateImm0_15ByEncoding(Val);
2284
156
  const AArch64PState_PStateImm0_1 *PStateImm1 =
2285
156
    AArch64PState_lookupPStateImm0_1ByEncoding(Val);
2286
156
  if (PStateImm15 &&
2287
89
      AArch64_testFeatureList(MI->csh->mode,
2288
89
            PStateImm15->FeaturesRequired))
2289
89
    SStream_concat0(O, PStateImm15->Name);
2290
67
  else if (PStateImm1 &&
2291
67
     AArch64_testFeatureList(MI->csh->mode,
2292
67
           PStateImm1->FeaturesRequired))
2293
67
    SStream_concat0(O, PStateImm1->Name);
2294
0
  else {
2295
0
    printUInt32Bang(O, (Val));
2296
0
    SStream_concat1(O, '\0');
2297
0
  }
2298
156
}
2299
2300
void printSIMDType10Operand(MCInst *MI, unsigned OpNo, SStream *O)
2301
2.30k
{
2302
2.30k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SIMDType10Operand, OpNo);
2303
2.30k
  unsigned RawVal = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2304
2.30k
  uint64_t Val = AArch64_AM_decodeAdvSIMDModImmType10(RawVal);
2305
2.30k
  SStream_concat(O, "%s#%#016llx", markup("<imm:"), Val);
2306
2.30k
  SStream_concat0(O, markup(">"));
2307
2.30k
}
2308
2309
#define DEFINE_printComplexRotationOp(Angle, Remainder) \
2310
  static void CONCAT(printComplexRotationOp, CONCAT(Angle, Remainder))( \
2311
    MCInst * MI, unsigned OpNo, SStream *O) \
2312
3.05k
  { \
2313
3.05k
    AArch64_add_cs_detail_2( \
2314
3.05k
      MI, \
2315
3.05k
      CONCAT(CONCAT(AArch64_OP_GROUP_ComplexRotationOp, \
2316
3.05k
              Angle), \
2317
3.05k
             Remainder), \
2318
3.05k
      OpNo, Angle, Remainder); \
2319
3.05k
    unsigned Val = \
2320
3.05k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
2321
3.05k
    SStream_concat(O, "%s", markup("<imm:")); \
2322
3.05k
    SStream_concat(O, "#%" PRId32, \
2323
3.05k
             (int32_t)((Val * Angle) + Remainder)); \
2324
3.05k
    SStream_concat0(O, markup(">")); \
2325
3.05k
  }
2326
585
DEFINE_printComplexRotationOp(180, 90);
2327
2.47k
DEFINE_printComplexRotationOp(90, 0);
2328
2329
void printSVEPattern(MCInst *MI, unsigned OpNum, SStream *O)
2330
4.21k
{
2331
4.21k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SVEPattern, OpNum);
2332
4.21k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
2333
4.21k
  const AArch64SVEPredPattern_SVEPREDPAT *Pat =
2334
4.21k
    AArch64SVEPredPattern_lookupSVEPREDPATByEncoding(Val);
2335
4.21k
  if (Pat)
2336
1.98k
    SStream_concat0(O, Pat->Name);
2337
2.23k
  else
2338
2.23k
    printUInt32Bang(O, Val);
2339
4.21k
}
2340
2341
void printSVEVecLenSpecifier(MCInst *MI, unsigned OpNum, SStream *O)
2342
713
{
2343
713
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SVEVecLenSpecifier, OpNum);
2344
713
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
2345
  // Pattern has only 1 bit
2346
713
  if (Val > 1)
2347
0
    CS_ASSERT_RET(0 && "Invalid vector length specifier");
2348
713
  const AArch64SVEVecLenSpecifier_SVEVECLENSPECIFIER *Pat =
2349
713
    AArch64SVEVecLenSpecifier_lookupSVEVECLENSPECIFIERByEncoding(
2350
713
      Val);
2351
713
  if (Pat)
2352
713
    SStream_concat0(O, Pat->Name);
2353
713
}
2354
2355
#define DEFINE_printSVERegOp(suffix) \
2356
  void CONCAT(printSVERegOp, suffix)(MCInst * MI, unsigned OpNum, \
2357
             SStream *O) \
2358
147k
  { \
2359
147k
    AArch64_add_cs_detail_1( \
2360
147k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2361
147k
      CHAR(suffix)); \
2362
147k
    switch (CHAR(suffix)) { \
2363
48.0k
    case '0': \
2364
73.4k
    case 'b': \
2365
104k
    case 'h': \
2366
125k
    case 's': \
2367
147k
    case 'd': \
2368
147k
    case 'q': \
2369
147k
      break; \
2370
147k
    default: \
2371
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2372
147k
    } \
2373
147k
\
2374
147k
    unsigned Reg = \
2375
147k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2376
147k
    printRegName(O, Reg); \
2377
147k
    if (CHAR(suffix) != '0') { \
2378
99.6k
      SStream_concat1(O, '.'); \
2379
99.6k
      SStream_concat1(O, CHAR(suffix)); \
2380
99.6k
    } \
2381
147k
  }
printSVERegOp_b
Line
Count
Source
2358
25.3k
  { \
2359
25.3k
    AArch64_add_cs_detail_1( \
2360
25.3k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2361
25.3k
      CHAR(suffix)); \
2362
25.3k
    switch (CHAR(suffix)) { \
2363
0
    case '0': \
2364
25.3k
    case 'b': \
2365
25.3k
    case 'h': \
2366
25.3k
    case 's': \
2367
25.3k
    case 'd': \
2368
25.3k
    case 'q': \
2369
25.3k
      break; \
2370
25.3k
    default: \
2371
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2372
25.3k
    } \
2373
25.3k
\
2374
25.3k
    unsigned Reg = \
2375
25.3k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2376
25.3k
    printRegName(O, Reg); \
2377
25.3k
    if (CHAR(suffix) != '0') { \
2378
25.3k
      SStream_concat1(O, '.'); \
2379
25.3k
      SStream_concat1(O, CHAR(suffix)); \
2380
25.3k
    } \
2381
25.3k
  }
printSVERegOp_d
Line
Count
Source
2358
22.0k
  { \
2359
22.0k
    AArch64_add_cs_detail_1( \
2360
22.0k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2361
22.0k
      CHAR(suffix)); \
2362
22.0k
    switch (CHAR(suffix)) { \
2363
0
    case '0': \
2364
0
    case 'b': \
2365
0
    case 'h': \
2366
0
    case 's': \
2367
22.0k
    case 'd': \
2368
22.0k
    case 'q': \
2369
22.0k
      break; \
2370
22.0k
    default: \
2371
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2372
22.0k
    } \
2373
22.0k
\
2374
22.0k
    unsigned Reg = \
2375
22.0k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2376
22.0k
    printRegName(O, Reg); \
2377
22.0k
    if (CHAR(suffix) != '0') { \
2378
22.0k
      SStream_concat1(O, '.'); \
2379
22.0k
      SStream_concat1(O, CHAR(suffix)); \
2380
22.0k
    } \
2381
22.0k
  }
printSVERegOp_h
Line
Count
Source
2358
31.4k
  { \
2359
31.4k
    AArch64_add_cs_detail_1( \
2360
31.4k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2361
31.4k
      CHAR(suffix)); \
2362
31.4k
    switch (CHAR(suffix)) { \
2363
0
    case '0': \
2364
0
    case 'b': \
2365
31.4k
    case 'h': \
2366
31.4k
    case 's': \
2367
31.4k
    case 'd': \
2368
31.4k
    case 'q': \
2369
31.4k
      break; \
2370
31.4k
    default: \
2371
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2372
31.4k
    } \
2373
31.4k
\
2374
31.4k
    unsigned Reg = \
2375
31.4k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2376
31.4k
    printRegName(O, Reg); \
2377
31.4k
    if (CHAR(suffix) != '0') { \
2378
31.4k
      SStream_concat1(O, '.'); \
2379
31.4k
      SStream_concat1(O, CHAR(suffix)); \
2380
31.4k
    } \
2381
31.4k
  }
printSVERegOp_s
Line
Count
Source
2358
20.1k
  { \
2359
20.1k
    AArch64_add_cs_detail_1( \
2360
20.1k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2361
20.1k
      CHAR(suffix)); \
2362
20.1k
    switch (CHAR(suffix)) { \
2363
0
    case '0': \
2364
0
    case 'b': \
2365
0
    case 'h': \
2366
20.1k
    case 's': \
2367
20.1k
    case 'd': \
2368
20.1k
    case 'q': \
2369
20.1k
      break; \
2370
20.1k
    default: \
2371
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2372
20.1k
    } \
2373
20.1k
\
2374
20.1k
    unsigned Reg = \
2375
20.1k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2376
20.1k
    printRegName(O, Reg); \
2377
20.1k
    if (CHAR(suffix) != '0') { \
2378
20.1k
      SStream_concat1(O, '.'); \
2379
20.1k
      SStream_concat1(O, CHAR(suffix)); \
2380
20.1k
    } \
2381
20.1k
  }
printSVERegOp_0
Line
Count
Source
2358
48.0k
  { \
2359
48.0k
    AArch64_add_cs_detail_1( \
2360
48.0k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2361
48.0k
      CHAR(suffix)); \
2362
48.0k
    switch (CHAR(suffix)) { \
2363
48.0k
    case '0': \
2364
48.0k
    case 'b': \
2365
48.0k
    case 'h': \
2366
48.0k
    case 's': \
2367
48.0k
    case 'd': \
2368
48.0k
    case 'q': \
2369
48.0k
      break; \
2370
48.0k
    default: \
2371
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2372
48.0k
    } \
2373
48.0k
\
2374
48.0k
    unsigned Reg = \
2375
48.0k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2376
48.0k
    printRegName(O, Reg); \
2377
48.0k
    if (CHAR(suffix) != '0') { \
2378
0
      SStream_concat1(O, '.'); \
2379
0
      SStream_concat1(O, CHAR(suffix)); \
2380
0
    } \
2381
48.0k
  }
printSVERegOp_q
Line
Count
Source
2358
739
  { \
2359
739
    AArch64_add_cs_detail_1( \
2360
739
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2361
739
      CHAR(suffix)); \
2362
739
    switch (CHAR(suffix)) { \
2363
0
    case '0': \
2364
0
    case 'b': \
2365
0
    case 'h': \
2366
0
    case 's': \
2367
0
    case 'd': \
2368
739
    case 'q': \
2369
739
      break; \
2370
0
    default: \
2371
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2372
739
    } \
2373
739
\
2374
739
    unsigned Reg = \
2375
739
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2376
739
    printRegName(O, Reg); \
2377
739
    if (CHAR(suffix) != '0') { \
2378
739
      SStream_concat1(O, '.'); \
2379
739
      SStream_concat1(O, CHAR(suffix)); \
2380
739
    } \
2381
739
  }
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.48k
  { \
2392
2.48k
    printInt32Bang(O, Val); \
2393
2.48k
  }
printImmSVE_int16_t
Line
Count
Source
2391
1.46k
  { \
2392
1.46k
    printInt32Bang(O, Val); \
2393
1.46k
  }
printImmSVE_int8_t
Line
Count
Source
2391
244
  { \
2392
244
    printInt32Bang(O, Val); \
2393
244
  }
printImmSVE_int32_t
Line
Count
Source
2391
779
  { \
2392
779
    printInt32Bang(O, Val); \
2393
779
  }
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
495
  { \
2401
495
    printUInt32Bang(O, Val); \
2402
495
  }
printImmSVE_uint16_t
Line
Count
Source
2400
173
  { \
2401
173
    printUInt32Bang(O, Val); \
2402
173
  }
printImmSVE_uint8_t
Line
Count
Source
2400
243
  { \
2401
243
    printUInt32Bang(O, Val); \
2402
243
  }
printImmSVE_uint32_t
Line
Count
Source
2400
79
  { \
2401
79
    printUInt32Bang(O, Val); \
2402
79
  }
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
542
  { \
2410
542
    printInt64Bang(O, Val); \
2411
542
  }
2412
DECLARE_printImmSVE_S64(int64_t);
2413
2414
#define DECLARE_printImmSVE_U64(T) \
2415
  void CONCAT(printImmSVE, T)(T Val, SStream * O) \
2416
127
  { \
2417
127
    printUInt64Bang(O, Val); \
2418
127
  }
2419
DECLARE_printImmSVE_U64(uint64_t);
2420
2421
#define DEFINE_isSignedType(T) \
2422
  static inline bool CONCAT(isSignedType, T)() \
2423
1.44k
  { \
2424
1.44k
    return CHAR(T) == 'i'; \
2425
1.44k
  }
AArch64InstPrinter.c:isSignedType_int16_t
Line
Count
Source
2423
149
  { \
2424
149
    return CHAR(T) == 'i'; \
2425
149
  }
AArch64InstPrinter.c:isSignedType_int8_t
Line
Count
Source
2423
244
  { \
2424
244
    return CHAR(T) == 'i'; \
2425
244
  }
AArch64InstPrinter.c:isSignedType_int64_t
Line
Count
Source
2423
206
  { \
2424
206
    return CHAR(T) == 'i'; \
2425
206
  }
AArch64InstPrinter.c:isSignedType_int32_t
Line
Count
Source
2423
228
  { \
2424
228
    return CHAR(T) == 'i'; \
2425
228
  }
AArch64InstPrinter.c:isSignedType_uint16_t
Line
Count
Source
2423
173
  { \
2424
173
    return CHAR(T) == 'i'; \
2425
173
  }
AArch64InstPrinter.c:isSignedType_uint8_t
Line
Count
Source
2423
243
  { \
2424
243
    return CHAR(T) == 'i'; \
2425
243
  }
AArch64InstPrinter.c:isSignedType_uint64_t
Line
Count
Source
2423
127
  { \
2424
127
    return CHAR(T) == 'i'; \
2425
127
  }
AArch64InstPrinter.c:isSignedType_uint32_t
Line
Count
Source
2423
79
  { \
2424
79
    return CHAR(T) == 'i'; \
2425
79
  }
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.77k
  { \
2439
1.77k
    AArch64_add_cs_detail_1( \
2440
1.77k
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
1.77k
      sizeof(T)); \
2442
1.77k
    unsigned UnscaledVal = \
2443
1.77k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
1.77k
    unsigned Shift = \
2445
1.77k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
1.77k
\
2447
1.77k
    if ((UnscaledVal == 0) && \
2448
1.77k
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2449
322
      SStream_concat(O, "%s", markup("<imm:")); \
2450
322
      SStream_concat1(O, '#'); \
2451
322
      printUInt64(O, (UnscaledVal)); \
2452
322
      SStream_concat0(O, markup(">")); \
2453
322
      printShifter(MI, OpNum + 1, O); \
2454
322
      return; \
2455
322
    } \
2456
1.77k
\
2457
1.77k
    T Val; \
2458
1.44k
    if (CONCAT(isSignedType, T)()) \
2459
1.44k
      Val = (int8_t)UnscaledVal * \
2460
827
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
1.44k
    else \
2462
1.44k
      Val = (uint8_t)UnscaledVal * \
2463
622
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
1.44k
\
2465
1.44k
    CONCAT(printImmSVE, T)(Val, O); \
2466
1.44k
  }
printImm8OptLsl_int16_t
Line
Count
Source
2438
186
  { \
2439
186
    AArch64_add_cs_detail_1( \
2440
186
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
186
      sizeof(T)); \
2442
186
    unsigned UnscaledVal = \
2443
186
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
186
    unsigned Shift = \
2445
186
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
186
\
2447
186
    if ((UnscaledVal == 0) && \
2448
186
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2449
37
      SStream_concat(O, "%s", markup("<imm:")); \
2450
37
      SStream_concat1(O, '#'); \
2451
37
      printUInt64(O, (UnscaledVal)); \
2452
37
      SStream_concat0(O, markup(">")); \
2453
37
      printShifter(MI, OpNum + 1, O); \
2454
37
      return; \
2455
37
    } \
2456
186
\
2457
186
    T Val; \
2458
149
    if (CONCAT(isSignedType, T)()) \
2459
149
      Val = (int8_t)UnscaledVal * \
2460
149
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
149
    else \
2462
149
      Val = (uint8_t)UnscaledVal * \
2463
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
149
\
2465
149
    CONCAT(printImmSVE, T)(Val, O); \
2466
149
  }
printImm8OptLsl_int8_t
Line
Count
Source
2438
244
  { \
2439
244
    AArch64_add_cs_detail_1( \
2440
244
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
244
      sizeof(T)); \
2442
244
    unsigned UnscaledVal = \
2443
244
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
244
    unsigned Shift = \
2445
244
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
244
\
2447
244
    if ((UnscaledVal == 0) && \
2448
244
        (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
244
\
2457
244
    T Val; \
2458
244
    if (CONCAT(isSignedType, T)()) \
2459
244
      Val = (int8_t)UnscaledVal * \
2460
244
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
244
    else \
2462
244
      Val = (uint8_t)UnscaledVal * \
2463
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
244
\
2465
244
    CONCAT(printImmSVE, T)(Val, O); \
2466
244
  }
printImm8OptLsl_int64_t
Line
Count
Source
2438
232
  { \
2439
232
    AArch64_add_cs_detail_1( \
2440
232
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
232
      sizeof(T)); \
2442
232
    unsigned UnscaledVal = \
2443
232
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
232
    unsigned Shift = \
2445
232
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
232
\
2447
232
    if ((UnscaledVal == 0) && \
2448
232
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2449
26
      SStream_concat(O, "%s", markup("<imm:")); \
2450
26
      SStream_concat1(O, '#'); \
2451
26
      printUInt64(O, (UnscaledVal)); \
2452
26
      SStream_concat0(O, markup(">")); \
2453
26
      printShifter(MI, OpNum + 1, O); \
2454
26
      return; \
2455
26
    } \
2456
232
\
2457
232
    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_int32_t
Line
Count
Source
2438
245
  { \
2439
245
    AArch64_add_cs_detail_1( \
2440
245
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
245
      sizeof(T)); \
2442
245
    unsigned UnscaledVal = \
2443
245
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
245
    unsigned Shift = \
2445
245
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
245
\
2447
245
    if ((UnscaledVal == 0) && \
2448
245
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2449
17
      SStream_concat(O, "%s", markup("<imm:")); \
2450
17
      SStream_concat1(O, '#'); \
2451
17
      printUInt64(O, (UnscaledVal)); \
2452
17
      SStream_concat0(O, markup(">")); \
2453
17
      printShifter(MI, OpNum + 1, O); \
2454
17
      return; \
2455
17
    } \
2456
245
\
2457
245
    T Val; \
2458
228
    if (CONCAT(isSignedType, T)()) \
2459
228
      Val = (int8_t)UnscaledVal * \
2460
228
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
228
    else \
2462
228
      Val = (uint8_t)UnscaledVal * \
2463
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
228
\
2465
228
    CONCAT(printImmSVE, T)(Val, O); \
2466
228
  }
printImm8OptLsl_uint16_t
Line
Count
Source
2438
269
  { \
2439
269
    AArch64_add_cs_detail_1( \
2440
269
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
269
      sizeof(T)); \
2442
269
    unsigned UnscaledVal = \
2443
269
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
269
    unsigned Shift = \
2445
269
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
269
\
2447
269
    if ((UnscaledVal == 0) && \
2448
269
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2449
96
      SStream_concat(O, "%s", markup("<imm:")); \
2450
96
      SStream_concat1(O, '#'); \
2451
96
      printUInt64(O, (UnscaledVal)); \
2452
96
      SStream_concat0(O, markup(">")); \
2453
96
      printShifter(MI, OpNum + 1, O); \
2454
96
      return; \
2455
96
    } \
2456
269
\
2457
269
    T Val; \
2458
173
    if (CONCAT(isSignedType, T)()) \
2459
173
      Val = (int8_t)UnscaledVal * \
2460
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
173
    else \
2462
173
      Val = (uint8_t)UnscaledVal * \
2463
173
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
173
\
2465
173
    CONCAT(printImmSVE, T)(Val, O); \
2466
173
  }
printImm8OptLsl_uint8_t
Line
Count
Source
2438
243
  { \
2439
243
    AArch64_add_cs_detail_1( \
2440
243
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
243
      sizeof(T)); \
2442
243
    unsigned UnscaledVal = \
2443
243
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
243
    unsigned Shift = \
2445
243
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
243
\
2447
243
    if ((UnscaledVal == 0) && \
2448
243
        (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
243
\
2457
243
    T Val; \
2458
243
    if (CONCAT(isSignedType, T)()) \
2459
243
      Val = (int8_t)UnscaledVal * \
2460
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
243
    else \
2462
243
      Val = (uint8_t)UnscaledVal * \
2463
243
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
243
\
2465
243
    CONCAT(printImmSVE, T)(Val, O); \
2466
243
  }
printImm8OptLsl_uint64_t
Line
Count
Source
2438
193
  { \
2439
193
    AArch64_add_cs_detail_1( \
2440
193
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2441
193
      sizeof(T)); \
2442
193
    unsigned UnscaledVal = \
2443
193
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2444
193
    unsigned Shift = \
2445
193
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2446
193
\
2447
193
    if ((UnscaledVal == 0) && \
2448
193
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2449
66
      SStream_concat(O, "%s", markup("<imm:")); \
2450
66
      SStream_concat1(O, '#'); \
2451
66
      printUInt64(O, (UnscaledVal)); \
2452
66
      SStream_concat0(O, markup(">")); \
2453
66
      printShifter(MI, OpNum + 1, O); \
2454
66
      return; \
2455
66
    } \
2456
193
\
2457
193
    T Val; \
2458
127
    if (CONCAT(isSignedType, T)()) \
2459
127
      Val = (int8_t)UnscaledVal * \
2460
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
127
    else \
2462
127
      Val = (uint8_t)UnscaledVal * \
2463
127
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
127
\
2465
127
    CONCAT(printImmSVE, T)(Val, O); \
2466
127
  }
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
80
      SStream_concat(O, "%s", markup("<imm:")); \
2450
80
      SStream_concat1(O, '#'); \
2451
80
      printUInt64(O, (UnscaledVal)); \
2452
80
      SStream_concat0(O, markup(">")); \
2453
80
      printShifter(MI, OpNum + 1, O); \
2454
80
      return; \
2455
80
    } \
2456
159
\
2457
159
    T Val; \
2458
79
    if (CONCAT(isSignedType, T)()) \
2459
79
      Val = (int8_t)UnscaledVal * \
2460
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2461
79
    else \
2462
79
      Val = (uint8_t)UnscaledVal * \
2463
79
            (1 << AArch64_AM_getShiftValue(Shift)); \
2464
79
\
2465
79
    CONCAT(printImmSVE, T)(Val, O); \
2466
79
  }
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.63k
  { \
2480
2.63k
    AArch64_add_cs_detail_1( \
2481
2.63k
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2482
2.63k
      sizeof(T)); \
2483
2.63k
    typedef T SignedT; \
2484
2.63k
    typedef CONCATS(u, T) UnsignedT; \
2485
2.63k
\
2486
2.63k
    uint64_t Val = \
2487
2.63k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2488
2.63k
    UnsignedT PrintVal = \
2489
2.63k
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2490
2.63k
\
2491
2.63k
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2492
2.63k
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2493
2.63k
    else if ((uint16_t)PrintVal == PrintVal) \
2494
592
      CONCAT(printImmSVE, T)(PrintVal, O); \
2495
592
    else { \
2496
437
      SStream_concat(O, "%s", markup("<imm:")); \
2497
437
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2498
437
      SStream_concat0(O, markup(">")); \
2499
437
    } \
2500
2.63k
  }
printSVELogicalImm_int16_t
Line
Count
Source
2479
1.31k
  { \
2480
1.31k
    AArch64_add_cs_detail_1( \
2481
1.31k
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2482
1.31k
      sizeof(T)); \
2483
1.31k
    typedef T SignedT; \
2484
1.31k
    typedef CONCATS(u, T) UnsignedT; \
2485
1.31k
\
2486
1.31k
    uint64_t Val = \
2487
1.31k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2488
1.31k
    UnsignedT PrintVal = \
2489
1.31k
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2490
1.31k
\
2491
1.31k
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2492
1.31k
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2493
1.31k
    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.31k
  }
printSVELogicalImm_int32_t
Line
Count
Source
2479
783
  { \
2480
783
    AArch64_add_cs_detail_1( \
2481
783
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2482
783
      sizeof(T)); \
2483
783
    typedef T SignedT; \
2484
783
    typedef CONCATS(u, T) UnsignedT; \
2485
783
\
2486
783
    uint64_t Val = \
2487
783
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2488
783
    UnsignedT PrintVal = \
2489
783
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2490
783
\
2491
783
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2492
783
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2493
783
    else if ((uint16_t)PrintVal == PrintVal) \
2494
248
      CONCAT(printImmSVE, T)(PrintVal, O); \
2495
248
    else { \
2496
232
      SStream_concat(O, "%s", markup("<imm:")); \
2497
232
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2498
232
      SStream_concat0(O, markup(">")); \
2499
232
    } \
2500
783
  }
printSVELogicalImm_int64_t
Line
Count
Source
2479
541
  { \
2480
541
    AArch64_add_cs_detail_1( \
2481
541
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2482
541
      sizeof(T)); \
2483
541
    typedef T SignedT; \
2484
541
    typedef CONCATS(u, T) UnsignedT; \
2485
541
\
2486
541
    uint64_t Val = \
2487
541
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2488
541
    UnsignedT PrintVal = \
2489
541
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2490
541
\
2491
541
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2492
541
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2493
541
    else if ((uint16_t)PrintVal == PrintVal) \
2494
344
      CONCAT(printImmSVE, T)(PrintVal, O); \
2495
344
    else { \
2496
205
      SStream_concat(O, "%s", markup("<imm:")); \
2497
205
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2498
205
      SStream_concat0(O, markup(">")); \
2499
205
    } \
2500
541
  }
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.57k
  { \
2509
1.57k
    AArch64_add_cs_detail_1( \
2510
1.57k
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2511
1.57k
      Width); \
2512
1.57k
    unsigned Base; \
2513
1.57k
    switch (Width) { \
2514
122
    case 8: \
2515
122
      Base = AArch64_B0; \
2516
122
      break; \
2517
569
    case 16: \
2518
569
      Base = AArch64_H0; \
2519
569
      break; \
2520
337
    case 32: \
2521
337
      Base = AArch64_S0; \
2522
337
      break; \
2523
475
    case 64: \
2524
475
      Base = AArch64_D0; \
2525
475
      break; \
2526
73
    case 128: \
2527
73
      Base = AArch64_Q0; \
2528
73
      break; \
2529
0
    default: \
2530
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2531
1.57k
    } \
2532
1.57k
    unsigned Reg = \
2533
1.57k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2534
1.57k
    printRegName(O, Reg - AArch64_Z0 + Base); \
2535
1.57k
  }
printZPRasFPR_8
Line
Count
Source
2508
122
  { \
2509
122
    AArch64_add_cs_detail_1( \
2510
122
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2511
122
      Width); \
2512
122
    unsigned Base; \
2513
122
    switch (Width) { \
2514
122
    case 8: \
2515
122
      Base = AArch64_B0; \
2516
122
      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
122
    } \
2532
122
    unsigned Reg = \
2533
122
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2534
122
    printRegName(O, Reg - AArch64_Z0 + Base); \
2535
122
  }
printZPRasFPR_64
Line
Count
Source
2508
475
  { \
2509
475
    AArch64_add_cs_detail_1( \
2510
475
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2511
475
      Width); \
2512
475
    unsigned Base; \
2513
475
    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
475
    case 64: \
2524
475
      Base = AArch64_D0; \
2525
475
      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
475
    } \
2532
475
    unsigned Reg = \
2533
475
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2534
475
    printRegName(O, Reg - AArch64_Z0 + Base); \
2535
475
  }
printZPRasFPR_16
Line
Count
Source
2508
569
  { \
2509
569
    AArch64_add_cs_detail_1( \
2510
569
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2511
569
      Width); \
2512
569
    unsigned Base; \
2513
569
    switch (Width) { \
2514
0
    case 8: \
2515
0
      Base = AArch64_B0; \
2516
0
      break; \
2517
569
    case 16: \
2518
569
      Base = AArch64_H0; \
2519
569
      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
569
    } \
2532
569
    unsigned Reg = \
2533
569
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2534
569
    printRegName(O, Reg - AArch64_Z0 + Base); \
2535
569
  }
printZPRasFPR_32
Line
Count
Source
2508
337
  { \
2509
337
    AArch64_add_cs_detail_1( \
2510
337
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2511
337
      Width); \
2512
337
    unsigned Base; \
2513
337
    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
337
    case 32: \
2521
337
      Base = AArch64_S0; \
2522
337
      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
337
    } \
2532
337
    unsigned Reg = \
2533
337
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2534
337
    printRegName(O, Reg - AArch64_Z0 + Base); \
2535
337
  }
printZPRasFPR_128
Line
Count
Source
2508
73
  { \
2509
73
    AArch64_add_cs_detail_1( \
2510
73
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2511
73
      Width); \
2512
73
    unsigned Base; \
2513
73
    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
73
    case 128: \
2527
73
      Base = AArch64_Q0; \
2528
73
      break; \
2529
0
    default: \
2530
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2531
73
    } \
2532
73
    unsigned Reg = \
2533
73
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2534
73
    printRegName(O, Reg - AArch64_Z0 + Base); \
2535
73
  }
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
381
  { \
2546
381
    AArch64_add_cs_detail_2( \
2547
381
      MI, \
2548
381
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2549
381
             ImmIs1), \
2550
381
      OpNum, ImmIs0, ImmIs1); \
2551
381
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2552
381
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2553
381
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2554
381
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2555
381
    unsigned Val = \
2556
381
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2557
381
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2558
381
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2559
381
    SStream_concat0(O, markup(">")); \
2560
381
  }
printExactFPImm_AArch64ExactFPImm_half_AArch64ExactFPImm_one
Line
Count
Source
2545
37
  { \
2546
37
    AArch64_add_cs_detail_2( \
2547
37
      MI, \
2548
37
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2549
37
             ImmIs1), \
2550
37
      OpNum, ImmIs0, ImmIs1); \
2551
37
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2552
37
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2553
37
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2554
37
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2555
37
    unsigned Val = \
2556
37
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2557
37
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2558
37
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2559
37
    SStream_concat0(O, markup(">")); \
2560
37
  }
printExactFPImm_AArch64ExactFPImm_zero_AArch64ExactFPImm_one
Line
Count
Source
2545
183
  { \
2546
183
    AArch64_add_cs_detail_2( \
2547
183
      MI, \
2548
183
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2549
183
             ImmIs1), \
2550
183
      OpNum, ImmIs0, ImmIs1); \
2551
183
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2552
183
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2553
183
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2554
183
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2555
183
    unsigned Val = \
2556
183
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2557
183
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2558
183
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2559
183
    SStream_concat0(O, markup(">")); \
2560
183
  }
printExactFPImm_AArch64ExactFPImm_half_AArch64ExactFPImm_two
Line
Count
Source
2545
161
  { \
2546
161
    AArch64_add_cs_detail_2( \
2547
161
      MI, \
2548
161
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2549
161
             ImmIs1), \
2550
161
      OpNum, ImmIs0, ImmIs1); \
2551
161
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2552
161
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2553
161
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2554
161
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2555
161
    unsigned Val = \
2556
161
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2557
161
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2558
161
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2559
161
    SStream_concat0(O, markup(">")); \
2560
161
  }
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.84k
{
2567
3.84k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_GPR64as32, OpNum);
2568
3.84k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2569
3.84k
  printRegName(O, getWRegFromXReg(Reg));
2570
3.84k
}
2571
2572
void printGPR64x8(MCInst *MI, unsigned OpNum, SStream *O)
2573
96
{
2574
96
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_GPR64x8, OpNum);
2575
96
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2576
96
  printRegName(O,
2577
96
         MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_x8sub_0));
2578
96
}
2579
2580
void printSyspXzrPair(MCInst *MI, unsigned OpNum, SStream *O)
2581
1.42k
{
2582
1.42k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SyspXzrPair, OpNum);
2583
1.42k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2584
2585
1.42k
  SStream_concat(O, "%s%s", getRegisterName(Reg, AArch64_NoRegAltName),
2586
1.42k
           ", ");
2587
1.42k
  SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
2588
1.42k
}
2589
2590
const char *AArch64_LLVM_getRegisterName(unsigned RegNo, unsigned AltIdx)
2591
158k
{
2592
158k
  return getRegisterName(RegNo, AltIdx);
2593
158k
}
2594
2595
void AArch64_LLVM_printInstruction(MCInst *MI, SStream *O,
2596
           void * /* MCRegisterInfo* */ info)
2597
273k
{
2598
273k
  printInst(MI, MI->address, "", O);
2599
273k
}