Coverage Report

Created: 2026-06-15 06:41

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