Coverage Report

Created: 2026-06-06 06:15

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