Coverage Report

Created: 2026-08-28 06:16

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