Coverage Report

Created: 2025-10-12 06:32

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