Coverage Report

Created: 2026-02-26 07:11

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