Coverage Report

Created: 2026-03-11 06:06

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