Coverage Report

Created: 2026-09-28 06:34

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
216k
#define CONCAT(a, b) CONCAT_(a, b)
49
216k
#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
374k
{
81
374k
  SStream_concat(OS, "%s%s", markup("<reg:"),
82
374k
           getRegisterName(Reg, AArch64_NoRegAltName));
83
374k
  SStream_concat0(OS, markup(">"));
84
374k
}
85
86
void printRegNameAlt(SStream *OS, unsigned Reg, unsigned AltIdx)
87
85.3k
{
88
85.3k
  SStream_concat(OS, "%s%s", markup("<reg:"),
89
85.3k
           getRegisterName(Reg, AltIdx));
90
85.3k
  SStream_concat0(OS, markup(">"));
91
85.3k
}
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
186k
{
100
186k
  bool isAlias = false;
101
186k
  bool useAliasDetails = map_use_alias_details(MI);
102
186k
  map_set_fill_detail_ops(MI, useAliasDetails);
103
104
186k
  unsigned Opcode = MCInst_getOpcode(MI);
105
106
186k
  if (Opcode == AArch64_SYSxt) {
107
1.37k
    if (printSysAlias(MI, O)) {
108
480
      isAlias = true;
109
480
      MCInst_setIsAlias(MI, isAlias);
110
480
      if (useAliasDetails)
111
480
        return;
112
480
    }
113
1.37k
  }
114
115
186k
  if (Opcode == AArch64_SYSPxt || Opcode == AArch64_SYSPxt_XZR) {
116
1.22k
    if (printSyspAlias(MI, O)) {
117
514
      isAlias = true;
118
514
      MCInst_setIsAlias(MI, isAlias);
119
514
      if (useAliasDetails)
120
514
        return;
121
514
    }
122
1.22k
  }
123
124
  // RPRFM overlaps PRFM (reg), so try to print it as RPRFM here.
125
185k
  if ((Opcode == AArch64_PRFMroX) || (Opcode == AArch64_PRFMroW)) {
126
230
    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
230
  }
133
134
  // SBFM/UBFM should print to a nicer aliased form if possible.
135
185k
  if (Opcode == AArch64_SBFMXri || Opcode == AArch64_SBFMWri ||
136
184k
      Opcode == AArch64_UBFMXri || Opcode == AArch64_UBFMWri) {
137
1.93k
    MCOperand *Op0 = MCInst_getOperand(MI, (0));
138
1.93k
    MCOperand *Op1 = MCInst_getOperand(MI, (1));
139
1.93k
    MCOperand *Op2 = MCInst_getOperand(MI, (2));
140
1.93k
    MCOperand *Op3 = MCInst_getOperand(MI, (3));
141
142
1.93k
    bool IsSigned = (Opcode == AArch64_SBFMXri ||
143
1.11k
         Opcode == AArch64_SBFMWri);
144
1.93k
    bool Is64Bit = (Opcode == AArch64_SBFMXri ||
145
1.11k
        Opcode == AArch64_UBFMXri);
146
1.93k
    if (MCOperand_isImm(Op2) && MCOperand_getImm(Op2) == 0 &&
147
742
        MCOperand_isImm(Op3)) {
148
742
      const char *AsmMnemonic = NULL;
149
150
742
      switch (MCOperand_getImm(Op3)) {
151
148
      default:
152
148
        break;
153
285
      case 7:
154
285
        if (IsSigned)
155
247
          AsmMnemonic = "sxtb";
156
38
        else if (!Is64Bit)
157
22
          AsmMnemonic = "uxtb";
158
285
        break;
159
153
      case 15:
160
153
        if (IsSigned)
161
81
          AsmMnemonic = "sxth";
162
72
        else if (!Is64Bit)
163
3
          AsmMnemonic = "uxth";
164
153
        break;
165
156
      case 31:
166
        // *xtw is only valid for signed 64-bit operations.
167
156
        if (Is64Bit && IsSigned)
168
57
          AsmMnemonic = "sxtw";
169
156
        break;
170
742
      }
171
172
742
      if (AsmMnemonic) {
173
410
        SStream_concat(O, "%s", AsmMnemonic);
174
410
        SStream_concat0(O, " ");
175
176
410
        printRegName(O, MCOperand_getReg(Op0));
177
410
        SStream_concat0(O, ", ");
178
410
        printRegName(O, getWRegFromXReg(
179
410
              MCOperand_getReg(Op1)));
180
410
        if (detail_is_set(MI) && useAliasDetails) {
181
410
          AArch64_set_detail_op_reg(
182
410
            MI, 0, MCOperand_getReg(Op0));
183
410
          AArch64_set_detail_op_reg(
184
410
            MI, 1,
185
410
            getWRegFromXReg(
186
410
              MCOperand_getReg(Op1)));
187
410
          if (strings_match(AsmMnemonic, "uxtb"))
188
22
            AArch64_get_detail_op(MI, -1)
189
22
              ->ext =
190
22
              AARCH64_EXT_UXTB;
191
388
          else if (strings_match(AsmMnemonic,
192
388
                     "sxtb"))
193
247
            AArch64_get_detail_op(MI, -1)
194
247
              ->ext =
195
247
              AARCH64_EXT_SXTB;
196
141
          else if (strings_match(AsmMnemonic,
197
141
                     "uxth"))
198
3
            AArch64_get_detail_op(MI, -1)
199
3
              ->ext =
200
3
              AARCH64_EXT_UXTH;
201
138
          else if (strings_match(AsmMnemonic,
202
138
                     "sxth"))
203
81
            AArch64_get_detail_op(MI, -1)
204
81
              ->ext =
205
81
              AARCH64_EXT_SXTH;
206
57
          else if (strings_match(AsmMnemonic,
207
57
                     "sxtw"))
208
57
            AArch64_get_detail_op(MI, -1)
209
57
              ->ext =
210
57
              AARCH64_EXT_SXTW;
211
0
          else
212
0
            AArch64_get_detail_op(MI, -1)
213
0
              ->ext =
214
0
              AARCH64_EXT_INVALID;
215
410
        }
216
410
        isAlias = true;
217
410
        MCInst_setIsAlias(MI, isAlias);
218
410
        if (useAliasDetails)
219
410
          return;
220
0
        else
221
0
          goto add_real_detail;
222
410
      }
223
742
    }
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.52k
    if (MCOperand_isImm(Op2) && MCOperand_isImm(Op3)) {
229
1.52k
      const char *AsmMnemonic = NULL;
230
1.52k
      int shift = 0;
231
1.52k
      int64_t immr = MCOperand_getImm(Op2);
232
1.52k
      int64_t imms = MCOperand_getImm(Op3);
233
1.52k
      if (Opcode == AArch64_UBFMWri && imms != 0x1F &&
234
94
          ((imms + 1) == immr)) {
235
15
        AsmMnemonic = "lsl";
236
15
        shift = 31 - imms;
237
1.50k
      } else if (Opcode == AArch64_UBFMXri && imms != 0x3f &&
238
511
           ((imms + 1 == immr))) {
239
15
        AsmMnemonic = "lsl";
240
15
        shift = 63 - imms;
241
1.49k
      } else if (Opcode == AArch64_UBFMWri && imms == 0x1f) {
242
54
        AsmMnemonic = "lsr";
243
54
        shift = immr;
244
1.43k
      } else if (Opcode == AArch64_UBFMXri && imms == 0x3f) {
245
48
        AsmMnemonic = "lsr";
246
48
        shift = immr;
247
1.38k
      } else if (Opcode == AArch64_SBFMWri && imms == 0x1f) {
248
104
        AsmMnemonic = "asr";
249
104
        shift = immr;
250
1.28k
      } else if (Opcode == AArch64_SBFMXri && imms == 0x3f) {
251
351
        AsmMnemonic = "asr";
252
351
        shift = immr;
253
351
      }
254
1.52k
      if (AsmMnemonic) {
255
587
        SStream_concat(O, "%s", AsmMnemonic);
256
587
        SStream_concat0(O, " ");
257
258
587
        printRegName(O, MCOperand_getReg(Op0));
259
587
        SStream_concat0(O, ", ");
260
587
        printRegName(O, MCOperand_getReg(Op1));
261
587
        SStream_concat(O, "%s%s#%d", ", ",
262
587
                 markup("<imm:"), shift);
263
587
        SStream_concat0(O, markup(">"));
264
587
        if (detail_is_set(MI) && useAliasDetails) {
265
587
          AArch64_set_detail_op_reg(
266
587
            MI, 0, MCOperand_getReg(Op0));
267
587
          AArch64_set_detail_op_reg(
268
587
            MI, 1, MCOperand_getReg(Op1));
269
587
          if (strings_match(AsmMnemonic, "lsl"))
270
30
            AArch64_get_detail_op(MI, -1)
271
30
              ->shift.type =
272
30
              AARCH64_SFT_LSL;
273
557
          else if (strings_match(AsmMnemonic,
274
557
                     "lsr"))
275
102
            AArch64_get_detail_op(MI, -1)
276
102
              ->shift.type =
277
102
              AARCH64_SFT_LSR;
278
455
          else if (strings_match(AsmMnemonic,
279
455
                     "asr"))
280
455
            AArch64_get_detail_op(MI, -1)
281
455
              ->shift.type =
282
455
              AARCH64_SFT_ASR;
283
0
          else
284
0
            AArch64_get_detail_op(MI, -1)
285
0
              ->shift.type =
286
0
              AARCH64_SFT_INVALID;
287
587
          AArch64_get_detail_op(MI, -1)
288
587
            ->shift.value = shift;
289
587
        }
290
587
        isAlias = true;
291
587
        MCInst_setIsAlias(MI, isAlias);
292
587
        if (useAliasDetails)
293
587
          return;
294
0
        else
295
0
          goto add_real_detail;
296
587
      }
297
1.52k
    }
298
299
    // SBFIZ/UBFIZ aliases
300
933
    if (MCOperand_getImm(Op2) > MCOperand_getImm(Op3)) {
301
380
      SStream_concat(O, "%s", (IsSigned ? "sbfiz" : "ubfiz"));
302
380
      SStream_concat0(O, " ");
303
304
380
      printRegName(O, MCOperand_getReg(Op0));
305
380
      SStream_concat0(O, ", ");
306
380
      printRegName(O, MCOperand_getReg(Op1));
307
380
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
308
380
      printUInt32Bang(O, (Is64Bit ? 64 : 32) -
309
380
               MCOperand_getImm(Op2));
310
380
      SStream_concat(O, "%s%s%s", markup(">"), ", ",
311
380
               markup("<imm:"));
312
380
      printInt64Bang(O, MCOperand_getImm(Op3) + 1);
313
380
      SStream_concat0(O, markup(">"));
314
380
      if (detail_is_set(MI) && useAliasDetails) {
315
380
        AArch64_set_detail_op_reg(
316
380
          MI, 0, MCOperand_getReg(Op0));
317
380
        AArch64_set_detail_op_reg(
318
380
          MI, 1, MCOperand_getReg(Op1));
319
380
        AArch64_set_detail_op_imm(
320
380
          MI, 2, AARCH64_OP_IMM,
321
380
          (Is64Bit ? 64 : 32) -
322
380
            MCOperand_getImm(Op2));
323
380
        AArch64_set_detail_op_imm(
324
380
          MI, 3, AARCH64_OP_IMM,
325
380
          MCOperand_getImm(Op3) + 1);
326
380
      }
327
380
      isAlias = true;
328
380
      MCInst_setIsAlias(MI, isAlias);
329
380
      if (useAliasDetails)
330
380
        return;
331
0
      else
332
0
        goto add_real_detail;
333
380
    }
334
335
    // Otherwise SBFX/UBFX is the preferred form
336
553
    SStream_concat(O, "%s", (IsSigned ? "sbfx" : "ubfx"));
337
553
    SStream_concat0(O, " ");
338
339
553
    printRegName(O, MCOperand_getReg(Op0));
340
553
    SStream_concat0(O, ", ");
341
553
    printRegName(O, MCOperand_getReg(Op1));
342
553
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
343
553
    printInt64Bang(O, MCOperand_getImm(Op2));
344
553
    SStream_concat(O, "%s%s%s", markup(">"), ", ", markup("<imm:"));
345
553
    printInt64Bang(O, MCOperand_getImm(Op3) -
346
553
            MCOperand_getImm(Op2) + 1);
347
553
    SStream_concat0(O, markup(">"));
348
553
    if (detail_is_set(MI) && useAliasDetails) {
349
553
      AArch64_set_detail_op_reg(MI, 0, MCOperand_getReg(Op0));
350
553
      AArch64_set_detail_op_reg(MI, 1, MCOperand_getReg(Op1));
351
553
      AArch64_set_detail_op_imm(MI, 2, AARCH64_OP_IMM,
352
553
              MCOperand_getImm(Op2));
353
553
      AArch64_set_detail_op_imm(
354
553
        MI, 3, AARCH64_OP_IMM,
355
553
        MCOperand_getImm(Op3) - MCOperand_getImm(Op2) +
356
553
          1);
357
553
    }
358
553
    isAlias = true;
359
553
    MCInst_setIsAlias(MI, isAlias);
360
553
    if (useAliasDetails)
361
553
      return;
362
0
    else
363
0
      goto add_real_detail;
364
553
  }
365
366
183k
  if (Opcode == AArch64_BFMXri || Opcode == AArch64_BFMWri) {
367
507
    isAlias = true;
368
507
    MCInst_setIsAlias(MI, isAlias);
369
507
    MCOperand *Op0 = MCInst_getOperand(MI, (0)); // Op1 == Op0
370
507
    MCOperand *Op2 = MCInst_getOperand(MI, (2));
371
507
    int ImmR = MCOperand_getImm(MCInst_getOperand(MI, (3)));
372
507
    int ImmS = MCOperand_getImm(MCInst_getOperand(MI, (4)));
373
374
507
    if ((MCOperand_getReg(Op2) == AArch64_WZR ||
375
483
         MCOperand_getReg(Op2) == AArch64_XZR) &&
376
264
        (ImmR == 0 || ImmS < ImmR) &&
377
71
        (AArch64_getFeatureBits(MI->csh->mode,
378
71
              AArch64_FeatureAll) ||
379
0
         AArch64_getFeatureBits(MI->csh->mode,
380
71
              AArch64_HasV8_2aOps))) {
381
      // BFC takes precedence over its entire range, sligtly differently
382
      // to BFI.
383
71
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
384
71
      int LSB = (BitWidth - ImmR) % BitWidth;
385
71
      int Width = ImmS + 1;
386
387
71
      SStream_concat0(O, "bfc ");
388
71
      printRegName(O, MCOperand_getReg(Op0));
389
71
      SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"),
390
71
               LSB);
391
71
      SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
392
71
               markup("<imm:"), Width);
393
71
      SStream_concat0(O, markup(">"));
394
71
      if (detail_is_set(MI) && useAliasDetails) {
395
71
        AArch64_set_detail_op_reg(
396
71
          MI, 0, MCOperand_getReg(Op0));
397
71
        AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM,
398
71
                LSB);
399
71
        AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM,
400
71
                Width);
401
71
      }
402
403
71
      if (useAliasDetails)
404
71
        return;
405
0
      else
406
0
        goto add_real_detail;
407
436
    } else if (ImmS < ImmR) {
408
      // BFI alias
409
142
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
410
142
      int LSB = (BitWidth - ImmR) % BitWidth;
411
142
      int Width = ImmS + 1;
412
413
142
      SStream_concat0(O, "bfi ");
414
142
      printRegName(O, MCOperand_getReg(Op0));
415
142
      SStream_concat0(O, ", ");
416
142
      printRegName(O, MCOperand_getReg(Op2));
417
142
      SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"),
418
142
               LSB);
419
142
      SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
420
142
               markup("<imm:"), Width);
421
142
      SStream_concat0(O, markup(">"));
422
142
      if (detail_is_set(MI) && useAliasDetails) {
423
142
        AArch64_set_detail_op_reg(
424
142
          MI, 0, MCOperand_getReg(Op0));
425
142
        AArch64_set_detail_op_reg(
426
142
          MI, 2, MCOperand_getReg(Op2));
427
142
        AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM,
428
142
                LSB);
429
142
        AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM,
430
142
                Width);
431
142
      }
432
142
      if (useAliasDetails)
433
142
        return;
434
0
      else
435
0
        goto add_real_detail;
436
142
    }
437
438
294
    int LSB = ImmR;
439
294
    int Width = ImmS - ImmR + 1;
440
    // Otherwise BFXIL the preferred form
441
294
    SStream_concat0(O, "bfxil ");
442
294
    printRegName(O, MCOperand_getReg(Op0));
443
294
    SStream_concat0(O, ", ");
444
294
    printRegName(O, MCOperand_getReg(Op2));
445
294
    SStream_concat(O, "%s%s#%d", ", ", markup("<imm:"), LSB);
446
294
    SStream_concat(O, "%s%s%s#%d", markup(">"), ", ",
447
294
             markup("<imm:"), Width);
448
294
    SStream_concat0(O, markup(">"));
449
294
    if (detail_is_set(MI) && useAliasDetails) {
450
294
      AArch64_set_detail_op_reg(MI, 0, MCOperand_getReg(Op0));
451
294
      AArch64_set_detail_op_reg(MI, 2, MCOperand_getReg(Op2));
452
294
      AArch64_set_detail_op_imm(MI, 3, AARCH64_OP_IMM, LSB);
453
294
      AArch64_set_detail_op_imm(MI, 4, AARCH64_OP_IMM, Width);
454
294
    }
455
294
    if (useAliasDetails)
456
294
      return;
457
294
  }
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
183k
  if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi ||
463
182k
       Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) &&
464
1.37k
      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
183k
  if ((Opcode == AArch64_MOVKXi || Opcode == AArch64_MOVKWi) &&
473
464
      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
183k
  if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi) &&
487
443
      MCOperand_isImm(MCInst_getOperand(MI, (1))) &&
488
443
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
489
443
    int RegWidth = Opcode == AArch64_MOVZXi ? 64 : 32;
490
443
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, (2)));
491
443
    uint64_t Value =
492
443
      (uint64_t)MCOperand_getImm(MCInst_getOperand(MI, (1)))
493
443
      << Shift;
494
495
443
    bool SuppressMovAlias =
496
443
      (MI->csh->syntax &
497
443
       CS_OPT_SYNTAX_AARCH64_EXPLICIT_WIDE_IMM) &&
498
0
      Shift != 0;
499
500
443
    if (!SuppressMovAlias &&
501
443
        AArch64_AM_isMOVZMovAlias(
502
443
          Value, Shift, Opcode == AArch64_MOVZXi ? 64 : 32)) {
503
292
      isAlias = true;
504
292
      MCInst_setIsAlias(MI, isAlias);
505
292
      SStream_concat0(O, "mov ");
506
292
      printRegName(O, MCOperand_getReg(
507
292
            MCInst_getOperand(MI, (0))));
508
292
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
509
292
      printInt64Bang(O, SignExtend64(Value, RegWidth));
510
292
      SStream_concat0(O, markup(">"));
511
292
      if (detail_is_set(MI) && useAliasDetails) {
512
292
        AArch64_set_detail_op_reg(
513
292
          MI, 0, MCInst_getOpVal(MI, 0));
514
292
        AArch64_set_detail_op_imm(
515
292
          MI, 1, AARCH64_OP_IMM,
516
292
          SignExtend64(Value, RegWidth));
517
292
      }
518
292
      if (useAliasDetails)
519
292
        return;
520
292
    }
521
443
  }
522
523
182k
  if ((Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) &&
524
931
      MCOperand_isImm(MCInst_getOperand(MI, (1))) &&
525
931
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
526
931
    int RegWidth = Opcode == AArch64_MOVNXi ? 64 : 32;
527
931
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, (2)));
528
931
    uint64_t Value =
529
931
      ~((uint64_t)MCOperand_getImm(MCInst_getOperand(MI, (1)))
530
931
        << Shift);
531
931
    if (RegWidth == 32)
532
53
      Value = Value & 0xffffffff;
533
534
931
    bool SuppressMovAlias =
535
931
      (MI->csh->syntax &
536
931
       CS_OPT_SYNTAX_AARCH64_EXPLICIT_WIDE_IMM) &&
537
0
      Shift != 0;
538
539
931
    if (!SuppressMovAlias &&
540
931
        AArch64_AM_isMOVNMovAlias(Value, Shift, RegWidth)) {
541
666
      isAlias = true;
542
666
      MCInst_setIsAlias(MI, isAlias);
543
666
      SStream_concat0(O, "mov ");
544
666
      printRegName(O, MCOperand_getReg(
545
666
            MCInst_getOperand(MI, (0))));
546
666
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
547
666
      printInt64Bang(O, SignExtend64(Value, RegWidth));
548
666
      SStream_concat0(O, markup(">"));
549
666
      if (detail_is_set(MI) && useAliasDetails) {
550
666
        AArch64_set_detail_op_reg(
551
666
          MI, 0, MCInst_getOpVal(MI, 0));
552
666
        AArch64_set_detail_op_imm(
553
666
          MI, 1, AARCH64_OP_IMM,
554
666
          SignExtend64(Value, RegWidth));
555
666
      }
556
666
      if (useAliasDetails)
557
666
        return;
558
666
    }
559
931
  }
560
561
182k
  if ((Opcode == AArch64_ORRXri || Opcode == AArch64_ORRWri) &&
562
1.74k
      (MCOperand_getReg(MCInst_getOperand(MI, (1))) == AArch64_XZR ||
563
1.15k
       MCOperand_getReg(MCInst_getOperand(MI, (1))) == AArch64_WZR) &&
564
836
      MCOperand_isImm(MCInst_getOperand(MI, (2)))) {
565
836
    int RegWidth = Opcode == AArch64_ORRXri ? 64 : 32;
566
836
    uint64_t Value = AArch64_AM_decodeLogicalImmediate(
567
836
      MCOperand_getImm(MCInst_getOperand(MI, (2))), RegWidth);
568
836
    if (!AArch64_AM_isAnyMOVWMovAlias(Value, RegWidth)) {
569
445
      isAlias = true;
570
445
      MCInst_setIsAlias(MI, isAlias);
571
445
      SStream_concat0(O, "mov ");
572
445
      printRegName(O, MCOperand_getReg(
573
445
            MCInst_getOperand(MI, (0))));
574
445
      SStream_concat(O, "%s%s", ", ", markup("<imm:"));
575
445
      printInt64Bang(O, SignExtend64(Value, RegWidth));
576
445
      SStream_concat0(O, markup(">"));
577
445
      if (detail_is_set(MI) && useAliasDetails) {
578
445
        AArch64_set_detail_op_reg(
579
445
          MI, 0, MCInst_getOpVal(MI, 0));
580
445
        AArch64_set_detail_op_imm(
581
445
          MI, 2, AARCH64_OP_IMM,
582
445
          SignExtend64(Value, RegWidth));
583
445
      }
584
445
      if (useAliasDetails)
585
445
        return;
586
445
    }
587
836
  }
588
589
181k
  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
181k
  if (!isAlias)
604
181k
    isAlias |= printAliasInstr(MI, Address, O);
605
606
181k
add_real_detail:
607
181k
  MCInst_setIsAlias(MI, isAlias);
608
609
181k
  if (!isAlias || !useAliasDetails) {
610
163k
    map_set_fill_detail_ops(MI, !(isAlias && useAliasDetails));
611
163k
    if (isAlias)
612
0
      SStream_Close(O);
613
163k
    printInstruction(MI, Address, O);
614
163k
    if (isAlias)
615
0
      SStream_Open(O);
616
163k
  }
617
181k
}
618
619
bool printRangePrefetchAlias(MCInst *MI, SStream *O, const char *Annot)
620
230
{
621
230
  unsigned Opcode = MCInst_getOpcode(MI);
622
623
230
#ifndef NDEBUG
624
625
230
#endif
626
627
230
  unsigned PRFOp = MCOperand_getImm(MCInst_getOperand(MI, (0)));
628
230
  unsigned Mask = 0x18; // 0b11000
629
230
  if ((PRFOp & Mask) != Mask)
630
230
    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
230
}
667
668
bool printSysAlias(MCInst *MI, SStream *O)
669
1.37k
{
670
1.37k
  MCOperand *Op1 = MCInst_getOperand(MI, (0));
671
1.37k
  MCOperand *Cn = MCInst_getOperand(MI, (1));
672
1.37k
  MCOperand *Cm = MCInst_getOperand(MI, (2));
673
1.37k
  MCOperand *Op2 = MCInst_getOperand(MI, (3));
674
675
1.37k
  unsigned Op1Val = MCOperand_getImm(Op1);
676
1.37k
  unsigned CnVal = MCOperand_getImm(Cn);
677
1.37k
  unsigned CmVal = MCOperand_getImm(Cm);
678
1.37k
  unsigned Op2Val = MCOperand_getImm(Op2);
679
680
1.37k
  uint16_t Encoding = Op2Val;
681
1.37k
  Encoding |= CmVal << 3;
682
1.37k
  Encoding |= CnVal << 7;
683
1.37k
  Encoding |= Op1Val << 11;
684
685
1.37k
  bool NeedsReg;
686
1.37k
  const char *Ins;
687
1.37k
  const char *Name;
688
689
1.37k
  if (CnVal == 7) {
690
955
    switch (CmVal) {
691
65
    default:
692
65
      return false;
693
    // Maybe IC, maybe Prediction Restriction
694
60
    case 1:
695
60
      switch (Op1Val) {
696
9
      default:
697
9
        return false;
698
32
      case 0:
699
32
        goto Search_IC;
700
19
      case 3:
701
19
        goto Search_PRCTX;
702
60
      }
703
    // Prediction Restriction aliases
704
66
    case 3: {
705
85
Search_PRCTX:
706
85
      if (Op1Val != 3 || CnVal != 7 || CmVal != 3)
707
23
        return false;
708
709
62
      unsigned int Requires =
710
62
        Op2Val == 6 ? AArch64_FeatureSPECRES2 :
711
62
                AArch64_FeaturePredRes;
712
62
      if (!(AArch64_getFeatureBits(MI->csh->mode,
713
62
                 AArch64_FeatureAll) ||
714
0
            AArch64_getFeatureBits(MI->csh->mode, Requires)))
715
0
        return false;
716
717
62
      NeedsReg = true;
718
62
      switch (Op2Val) {
719
9
      default:
720
9
        return false;
721
5
      case 4:
722
5
        Ins = "cfp ";
723
5
        break;
724
25
      case 5:
725
25
        Ins = "dvp ";
726
25
        break;
727
0
      case 6:
728
0
        Ins = "cosp ";
729
0
        break;
730
23
      case 7:
731
23
        Ins = "cpp ";
732
23
        break;
733
62
      }
734
53
      Name = "RCTX";
735
53
    } break;
736
    // IC aliases
737
117
    case 5: {
738
149
Search_IC: {
739
149
  const AArch64IC_IC *IC = AArch64IC_lookupICByEncoding(Encoding);
740
149
  if (!IC ||
741
79
      !AArch64_testFeatureList(MI->csh->mode, IC->FeaturesRequired))
742
70
    return false;
743
79
  if (detail_is_set(MI)) {
744
79
    aarch64_sysop sysop = { 0 };
745
79
    sysop.reg = IC->SysReg;
746
79
    sysop.sub_type = AARCH64_OP_IC;
747
79
    AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
748
79
    AArch64_get_detail_op(MI, 0)->sysop = sysop;
749
79
    AArch64_inc_op_count(MI);
750
79
  }
751
752
79
  NeedsReg = IC->NeedsReg;
753
79
  Ins = "ic ";
754
79
  Name = IC->Name;
755
79
}
756
79
    } break;
757
    // DC aliases
758
7
    case 4:
759
41
    case 6:
760
54
    case 10:
761
63
    case 11:
762
91
    case 12:
763
167
    case 13:
764
385
    case 14: {
765
385
      const AArch64DC_DC *DC =
766
385
        AArch64DC_lookupDCByEncoding(Encoding);
767
385
      if (!DC || !AArch64_testFeatureList(
768
136
             MI->csh->mode, DC->FeaturesRequired))
769
249
        return false;
770
136
      if (detail_is_set(MI)) {
771
136
        aarch64_sysop sysop = { 0 };
772
136
        sysop.alias = DC->SysAlias;
773
136
        sysop.sub_type = AARCH64_OP_DC;
774
136
        AArch64_get_detail_op(MI, 0)->type =
775
136
          AARCH64_OP_SYSALIAS;
776
136
        AArch64_get_detail_op(MI, 0)->sysop = sysop;
777
136
        AArch64_inc_op_count(MI);
778
136
      }
779
780
136
      NeedsReg = true;
781
136
      Ins = "dc ";
782
136
      Name = DC->Name;
783
136
    } break;
784
    // AT aliases
785
99
    case 8:
786
262
    case 9: {
787
262
      const AArch64AT_AT *AT =
788
262
        AArch64AT_lookupATByEncoding(Encoding);
789
262
      if (!AT || !AArch64_testFeatureList(
790
98
             MI->csh->mode, AT->FeaturesRequired))
791
164
        return false;
792
793
98
      if (detail_is_set(MI)) {
794
98
        aarch64_sysop sysop = { 0 };
795
98
        sysop.alias = AT->SysAlias;
796
98
        sysop.sub_type = AARCH64_OP_AT;
797
98
        AArch64_get_detail_op(MI, 0)->type =
798
98
          AARCH64_OP_SYSALIAS;
799
98
        AArch64_get_detail_op(MI, 0)->sysop = sysop;
800
98
        AArch64_inc_op_count(MI);
801
98
      }
802
98
      NeedsReg = true;
803
98
      Ins = "at ";
804
98
      Name = AT->Name;
805
98
    } break;
806
955
    }
807
955
  } else if (CnVal == 8 || CnVal == 9) {
808
    // TLBI aliases
809
173
    const AArch64TLBI_TLBI *TLBI =
810
173
      AArch64TLBI_lookupTLBIByEncoding(Encoding);
811
173
    if (!TLBI || !AArch64_testFeatureList(MI->csh->mode,
812
114
                  TLBI->FeaturesRequired))
813
59
      return false;
814
815
114
    if (detail_is_set(MI)) {
816
114
      aarch64_sysop sysop = { 0 };
817
114
      sysop.reg = TLBI->SysReg;
818
114
      sysop.sub_type = AARCH64_OP_TLBI;
819
114
      AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
820
114
      AArch64_get_detail_op(MI, 0)->sysop = sysop;
821
114
      AArch64_inc_op_count(MI);
822
114
    }
823
114
    NeedsReg = TLBI->NeedsReg;
824
114
    Ins = "tlbi ";
825
114
    Name = TLBI->Name;
826
114
  } else
827
250
    return false;
828
829
960
#define TMP_STR_LEN 32
830
480
  char Str[TMP_STR_LEN] = { 0 };
831
480
  append_to_str_lower(Str, TMP_STR_LEN, Ins);
832
480
  append_to_str_lower(Str, TMP_STR_LEN, Name);
833
480
#undef TMP_STR_LEN
834
835
480
  SStream_concat1(O, ' ');
836
480
  SStream_concat0(O, Str);
837
480
  if (NeedsReg) {
838
354
    SStream_concat0(O, ", ");
839
354
    printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (4))));
840
354
    AArch64_set_detail_op_reg(MI, 4, MCInst_getOpVal(MI, 4));
841
354
  }
842
843
480
  return true;
844
1.37k
}
845
846
bool printSyspAlias(MCInst *MI, SStream *O)
847
1.22k
{
848
1.22k
  MCOperand *Op1 = MCInst_getOperand(MI, (0));
849
1.22k
  MCOperand *Cn = MCInst_getOperand(MI, (1));
850
1.22k
  MCOperand *Cm = MCInst_getOperand(MI, (2));
851
1.22k
  MCOperand *Op2 = MCInst_getOperand(MI, (3));
852
853
1.22k
  unsigned Op1Val = MCOperand_getImm(Op1);
854
1.22k
  unsigned CnVal = MCOperand_getImm(Cn);
855
1.22k
  unsigned CmVal = MCOperand_getImm(Cm);
856
1.22k
  unsigned Op2Val = MCOperand_getImm(Op2);
857
858
1.22k
  uint16_t Encoding = Op2Val;
859
1.22k
  Encoding |= CmVal << 3;
860
1.22k
  Encoding |= CnVal << 7;
861
1.22k
  Encoding |= Op1Val << 11;
862
863
1.22k
  const char *Ins;
864
1.22k
  const char *Name;
865
866
1.22k
  if (CnVal == 8 || CnVal == 9) {
867
    // TLBIP aliases
868
869
697
    if (CnVal == 9) {
870
65
      if (!AArch64_getFeatureBits(MI->csh->mode,
871
65
                AArch64_FeatureAll) ||
872
65
          !AArch64_getFeatureBits(MI->csh->mode,
873
65
                AArch64_FeatureXS))
874
0
        return false;
875
65
      Encoding &= ~(1 << 7);
876
65
    }
877
878
697
    const AArch64TLBI_TLBI *TLBI =
879
697
      AArch64TLBI_lookupTLBIByEncoding(Encoding);
880
697
    if (!TLBI || !AArch64_testFeatureList(MI->csh->mode,
881
514
                  TLBI->FeaturesRequired))
882
183
      return false;
883
884
514
    if (detail_is_set(MI)) {
885
514
      aarch64_sysop sysop = { 0 };
886
514
      sysop.reg = TLBI->SysReg;
887
514
      sysop.sub_type = AARCH64_OP_TLBI;
888
514
      AArch64_get_detail_op(MI, 0)->type = AARCH64_OP_SYSREG;
889
514
      AArch64_get_detail_op(MI, 0)->sysop = sysop;
890
514
      AArch64_inc_op_count(MI);
891
514
    }
892
514
    Ins = "tlbip ";
893
514
    Name = TLBI->Name;
894
514
  } else
895
528
    return false;
896
897
1.08k
#define TMP_STR_LEN 32
898
514
  char Str[TMP_STR_LEN] = { 0 };
899
514
  append_to_str_lower(Str, TMP_STR_LEN, Ins);
900
514
  append_to_str_lower(Str, TMP_STR_LEN, Name);
901
902
514
  if (CnVal == 9) {
903
59
    append_to_str_lower(Str, TMP_STR_LEN, "nxs");
904
59
  }
905
514
#undef TMP_STR_LEN
906
907
514
  SStream_concat1(O, ' ');
908
514
  SStream_concat0(O, Str);
909
514
  SStream_concat0(O, ", ");
910
514
  if (MCOperand_getReg(MCInst_getOperand(MI, (4))) == AArch64_XZR)
911
437
    printSyspXzrPair(MI, 4, O);
912
77
  else
913
77
    CONCAT(printGPRSeqPairsClassOperand, 64)(MI, 4, O);
914
915
514
  return true;
916
1.22k
}
917
918
#define DEFINE_printMatrix(EltSize) \
919
  void CONCAT(printMatrix, EltSize)(MCInst * MI, unsigned OpNum, \
920
            SStream *O) \
921
3.63k
  { \
922
3.63k
    AArch64_add_cs_detail_1( \
923
3.63k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
3.63k
      EltSize); \
925
3.63k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
3.63k
\
927
3.63k
    printRegName(O, MCOperand_getReg(RegOp)); \
928
3.63k
    switch (EltSize) { \
929
191
    case 0: \
930
191
      break; \
931
0
    case 8: \
932
0
      SStream_concat0(O, ".b"); \
933
0
      break; \
934
575
    case 16: \
935
575
      SStream_concat0(O, ".h"); \
936
575
      break; \
937
2.03k
    case 32: \
938
2.03k
      SStream_concat0(O, ".s"); \
939
2.03k
      break; \
940
838
    case 64: \
941
838
      SStream_concat0(O, ".d"); \
942
838
      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
3.63k
    } \
949
3.63k
  }
printMatrix_64
Line
Count
Source
921
838
  { \
922
838
    AArch64_add_cs_detail_1( \
923
838
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
838
      EltSize); \
925
838
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
838
\
927
838
    printRegName(O, MCOperand_getReg(RegOp)); \
928
838
    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
838
    case 64: \
941
838
      SStream_concat0(O, ".d"); \
942
838
      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
838
    } \
949
838
  }
printMatrix_32
Line
Count
Source
921
2.03k
  { \
922
2.03k
    AArch64_add_cs_detail_1( \
923
2.03k
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
2.03k
      EltSize); \
925
2.03k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
2.03k
\
927
2.03k
    printRegName(O, MCOperand_getReg(RegOp)); \
928
2.03k
    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.03k
    case 32: \
938
2.03k
      SStream_concat0(O, ".s"); \
939
2.03k
      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.03k
    } \
949
2.03k
  }
printMatrix_16
Line
Count
Source
921
575
  { \
922
575
    AArch64_add_cs_detail_1( \
923
575
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
575
      EltSize); \
925
575
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
575
\
927
575
    printRegName(O, MCOperand_getReg(RegOp)); \
928
575
    switch (EltSize) { \
929
0
    case 0: \
930
0
      break; \
931
0
    case 8: \
932
0
      SStream_concat0(O, ".b"); \
933
0
      break; \
934
575
    case 16: \
935
575
      SStream_concat0(O, ".h"); \
936
575
      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
575
    } \
949
575
  }
printMatrix_0
Line
Count
Source
921
191
  { \
922
191
    AArch64_add_cs_detail_1( \
923
191
      MI, CONCAT(AArch64_OP_GROUP_Matrix, EltSize), OpNum, \
924
191
      EltSize); \
925
191
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
926
191
\
927
191
    printRegName(O, MCOperand_getReg(RegOp)); \
928
191
    switch (EltSize) { \
929
191
    case 0: \
930
191
      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
191
    } \
949
191
  }
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.55k
  { \
959
3.55k
    AArch64_add_cs_detail_1( \
960
3.55k
      MI, \
961
3.55k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
962
3.55k
      OpNum, IsVertical); \
963
3.55k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
964
3.55k
\
965
3.55k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
966
3.55k
                  AArch64_NoRegAltName); \
967
3.55k
\
968
3.55k
    /* Diet builds have no register-name table; skip printing. */ \
969
3.55k
    if (!RegName) \
970
3.55k
      return; \
971
3.55k
\
972
3.55k
    unsigned buf_len = strlen(RegName) + 1; \
973
3.55k
    char *Base = cs_mem_calloc(1, buf_len); \
974
3.55k
    memcpy(Base, RegName, buf_len); \
975
3.55k
    char *Dot = strchr(Base, '.'); \
976
3.55k
    if (!Dot) { \
977
0
      SStream_concat0(O, RegName); \
978
0
      return; \
979
0
    } \
980
3.55k
    *Dot = '\0'; /* Split string */ \
981
3.55k
    char *Suffix = Dot + 1; \
982
3.55k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
983
3.55k
    SStream_concat1(O, '.'); \
984
3.55k
    SStream_concat0(O, Suffix); \
985
3.55k
    cs_mem_free(Base); \
986
3.55k
  }
printMatrixTileVector_0
Line
Count
Source
958
1.68k
  { \
959
1.68k
    AArch64_add_cs_detail_1( \
960
1.68k
      MI, \
961
1.68k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
962
1.68k
      OpNum, IsVertical); \
963
1.68k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
964
1.68k
\
965
1.68k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
966
1.68k
                  AArch64_NoRegAltName); \
967
1.68k
\
968
1.68k
    /* Diet builds have no register-name table; skip printing. */ \
969
1.68k
    if (!RegName) \
970
1.68k
      return; \
971
1.68k
\
972
1.68k
    unsigned buf_len = strlen(RegName) + 1; \
973
1.68k
    char *Base = cs_mem_calloc(1, buf_len); \
974
1.68k
    memcpy(Base, RegName, buf_len); \
975
1.68k
    char *Dot = strchr(Base, '.'); \
976
1.68k
    if (!Dot) { \
977
0
      SStream_concat0(O, RegName); \
978
0
      return; \
979
0
    } \
980
1.68k
    *Dot = '\0'; /* Split string */ \
981
1.68k
    char *Suffix = Dot + 1; \
982
1.68k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
983
1.68k
    SStream_concat1(O, '.'); \
984
1.68k
    SStream_concat0(O, Suffix); \
985
1.68k
    cs_mem_free(Base); \
986
1.68k
  }
printMatrixTileVector_1
Line
Count
Source
958
1.86k
  { \
959
1.86k
    AArch64_add_cs_detail_1( \
960
1.86k
      MI, \
961
1.86k
      CONCAT(AArch64_OP_GROUP_MatrixTileVector, IsVertical), \
962
1.86k
      OpNum, IsVertical); \
963
1.86k
    MCOperand *RegOp = MCInst_getOperand(MI, (OpNum)); \
964
1.86k
\
965
1.86k
    const char *RegName = getRegisterName(MCOperand_getReg(RegOp), \
966
1.86k
                  AArch64_NoRegAltName); \
967
1.86k
\
968
1.86k
    /* Diet builds have no register-name table; skip printing. */ \
969
1.86k
    if (!RegName) \
970
1.86k
      return; \
971
1.86k
\
972
1.86k
    unsigned buf_len = strlen(RegName) + 1; \
973
1.86k
    char *Base = cs_mem_calloc(1, buf_len); \
974
1.86k
    memcpy(Base, RegName, buf_len); \
975
1.86k
    char *Dot = strchr(Base, '.'); \
976
1.86k
    if (!Dot) { \
977
0
      SStream_concat0(O, RegName); \
978
0
      return; \
979
0
    } \
980
1.86k
    *Dot = '\0'; /* Split string */ \
981
1.86k
    char *Suffix = Dot + 1; \
982
1.86k
    SStream_concat(O, "%s%s", Base, (IsVertical ? "v" : "h")); \
983
1.86k
    SStream_concat1(O, '.'); \
984
1.86k
    SStream_concat0(O, Suffix); \
985
1.86k
    cs_mem_free(Base); \
986
1.86k
  }
987
DEFINE_printMatrixTileVector(0);
988
DEFINE_printMatrixTileVector(1);
989
990
void printMatrixTile(MCInst *MI, unsigned OpNum, SStream *O)
991
1.71k
{
992
1.71k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MatrixTile, OpNum);
993
1.71k
  MCOperand *RegOp = MCInst_getOperand(MI, (OpNum));
994
995
1.71k
  printRegName(O, MCOperand_getReg(RegOp));
996
1.71k
}
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
246k
{
1011
246k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Operand, OpNo);
1012
246k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1013
246k
  if (MCOperand_isReg(Op)) {
1014
214k
    unsigned Reg = MCOperand_getReg(Op);
1015
214k
    printRegName(O, Reg);
1016
214k
  } else if (MCOperand_isImm(Op)) {
1017
31.9k
    Op = MCInst_getOperand(MI, (OpNo));
1018
31.9k
    SStream_concat(O, "%s", markup("<imm:"));
1019
31.9k
    printInt64Bang(O, MCOperand_getImm(Op));
1020
31.9k
    SStream_concat0(O, markup(">"));
1021
31.9k
  } else {
1022
0
    printUInt64Bang(O, MCInst_getOpVal(MI, OpNo));
1023
0
  }
1024
246k
}
1025
1026
void printImm(MCInst *MI, unsigned OpNo, SStream *O)
1027
3.05k
{
1028
3.05k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Imm, OpNo);
1029
3.05k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1030
3.05k
  SStream_concat(O, "%s", markup("<imm:"));
1031
3.05k
  printInt64Bang(O, MCOperand_getImm(Op));
1032
3.05k
  SStream_concat0(O, markup(">"));
1033
3.05k
}
1034
1035
void printImmHex(MCInst *MI, unsigned OpNo, SStream *O)
1036
53
{
1037
53
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ImmHex, OpNo);
1038
53
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1039
53
  SStream_concat(O, "%s", markup("<imm:"));
1040
53
  printInt64Bang(O, MCOperand_getImm(Op));
1041
53
  SStream_concat0(O, markup(">"));
1042
53
}
1043
1044
#define DEFINE_printSImm(Size) \
1045
  void CONCAT(printSImm, Size)(MCInst * MI, unsigned OpNo, SStream *O) \
1046
633
  { \
1047
633
    AArch64_add_cs_detail_1( \
1048
633
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1049
633
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1050
633
    if (Size == 8) { \
1051
435
      SStream_concat(O, "%s", markup("<imm:")); \
1052
435
      printInt32Bang(O, MCOperand_getImm(Op)); \
1053
435
      SStream_concat0(O, markup(">")); \
1054
435
    } else if (Size == 16) { \
1055
198
      SStream_concat(O, "%s", markup("<imm:")); \
1056
198
      printInt32Bang(O, MCOperand_getImm(Op)); \
1057
198
      SStream_concat0(O, markup(">")); \
1058
198
    } 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
633
  }
printSImm_16
Line
Count
Source
1046
198
  { \
1047
198
    AArch64_add_cs_detail_1( \
1048
198
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1049
198
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1050
198
    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
198
    } else if (Size == 16) { \
1055
198
      SStream_concat(O, "%s", markup("<imm:")); \
1056
198
      printInt32Bang(O, MCOperand_getImm(Op)); \
1057
198
      SStream_concat0(O, markup(">")); \
1058
198
    } 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
198
  }
printSImm_8
Line
Count
Source
1046
435
  { \
1047
435
    AArch64_add_cs_detail_1( \
1048
435
      MI, CONCAT(AArch64_OP_GROUP_SImm, Size), OpNo, Size); \
1049
435
    MCOperand *Op = MCInst_getOperand(MI, (OpNo)); \
1050
435
    if (Size == 8) { \
1051
435
      SStream_concat(O, "%s", markup("<imm:")); \
1052
435
      printInt32Bang(O, MCOperand_getImm(Op)); \
1053
435
      SStream_concat0(O, markup(">")); \
1054
435
    } 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
435
  }
1064
DEFINE_printSImm(16);
1065
DEFINE_printSImm(8);
1066
1067
void printPostIncOperand(MCInst *MI, unsigned OpNo, unsigned Imm, SStream *O)
1068
5.58k
{
1069
5.58k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1070
5.58k
  if (MCOperand_isReg(Op)) {
1071
5.58k
    unsigned Reg = MCOperand_getReg(Op);
1072
5.58k
    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.58k
      printRegName(O, Reg);
1078
5.58k
  } else
1079
0
    CS_ASSERT_RET(0 &&
1080
5.58k
            "unknown operand kind in printPostIncOperand64");
1081
5.58k
}
1082
1083
void printVRegOperand(MCInst *MI, unsigned OpNo, SStream *O)
1084
46.0k
{
1085
46.0k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_VRegOperand, OpNo);
1086
46.0k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1087
1088
46.0k
  unsigned Reg = MCOperand_getReg(Op);
1089
46.0k
  printRegNameAlt(O, Reg, AArch64_vreg);
1090
46.0k
}
1091
1092
void printSysCROperand(MCInst *MI, unsigned OpNo, SStream *O)
1093
3.34k
{
1094
3.34k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SysCROperand, OpNo);
1095
3.34k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
1096
1097
3.34k
  SStream_concat(O, "%s", "c");
1098
3.34k
  printUInt32(O, MCOperand_getImm(Op));
1099
3.34k
  SStream_concat1(O, '\0');
1100
3.34k
}
1101
1102
void printAddSubImm(MCInst *MI, unsigned OpNum, SStream *O)
1103
1.96k
{
1104
1.96k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AddSubImm, OpNum);
1105
1.96k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1106
1.96k
  if (MCOperand_isImm(MO)) {
1107
1.96k
    unsigned Val = (MCOperand_getImm(MO) & 0xfff);
1108
1109
1.96k
    unsigned Shift = AArch64_AM_getShiftValue(
1110
1.96k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))));
1111
1.96k
    SStream_concat(O, "%s", markup("<imm:"));
1112
1.96k
    printUInt32Bang(O, (Val));
1113
1.96k
    SStream_concat0(O, markup(">"));
1114
1.96k
    if (Shift != 0) {
1115
562
      printShifter(MI, OpNum + 1, O);
1116
562
    }
1117
1.96k
  } else {
1118
0
    printShifter(MI, OpNum + 1, O);
1119
0
  }
1120
1.96k
}
1121
1122
#define DEFINE_printLogicalImm(T) \
1123
  void CONCAT(printLogicalImm, T)(MCInst * MI, unsigned OpNum, \
1124
          SStream *O) \
1125
5.49k
  { \
1126
5.49k
    AArch64_add_cs_detail_1( \
1127
5.49k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
5.49k
      sizeof(T)); \
1129
5.49k
    uint64_t Val = \
1130
5.49k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
5.49k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
5.49k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
5.49k
             Val, 8 * sizeof(T)))); \
1134
5.49k
    SStream_concat0(O, markup(">")); \
1135
5.49k
  }
printLogicalImm_int64_t
Line
Count
Source
1125
1.65k
  { \
1126
1.65k
    AArch64_add_cs_detail_1( \
1127
1.65k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
1.65k
      sizeof(T)); \
1129
1.65k
    uint64_t Val = \
1130
1.65k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
1.65k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
1.65k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
1.65k
             Val, 8 * sizeof(T)))); \
1134
1.65k
    SStream_concat0(O, markup(">")); \
1135
1.65k
  }
printLogicalImm_int32_t
Line
Count
Source
1125
1.22k
  { \
1126
1.22k
    AArch64_add_cs_detail_1( \
1127
1.22k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
1.22k
      sizeof(T)); \
1129
1.22k
    uint64_t Val = \
1130
1.22k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
1.22k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
1.22k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
1.22k
             Val, 8 * sizeof(T)))); \
1134
1.22k
    SStream_concat0(O, markup(">")); \
1135
1.22k
  }
printLogicalImm_int8_t
Line
Count
Source
1125
1.70k
  { \
1126
1.70k
    AArch64_add_cs_detail_1( \
1127
1.70k
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
1.70k
      sizeof(T)); \
1129
1.70k
    uint64_t Val = \
1130
1.70k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
1.70k
    SStream_concat(O, "%s", markup("<imm:")); \
1132
1.70k
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
1.70k
             Val, 8 * sizeof(T)))); \
1134
1.70k
    SStream_concat0(O, markup(">")); \
1135
1.70k
  }
printLogicalImm_int16_t
Line
Count
Source
1125
921
  { \
1126
921
    AArch64_add_cs_detail_1( \
1127
921
      MI, CONCAT(AArch64_OP_GROUP_LogicalImm, T), OpNum, \
1128
921
      sizeof(T)); \
1129
921
    uint64_t Val = \
1130
921
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1131
921
    SStream_concat(O, "%s", markup("<imm:")); \
1132
921
    printUInt64Bang(O, (AArch64_AM_decodeLogicalImmediate( \
1133
921
             Val, 8 * sizeof(T)))); \
1134
921
    SStream_concat0(O, markup(">")); \
1135
921
  }
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.36k
{
1143
7.36k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_Shifter, OpNum);
1144
7.36k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1145
  // LSL #0 should not be printed.
1146
7.36k
  if (AArch64_AM_getShiftType(Val) == AArch64_AM_LSL &&
1147
4.41k
      AArch64_AM_getShiftValue(Val) == 0)
1148
242
    return;
1149
7.11k
  SStream_concat(
1150
7.11k
    O, "%s%s%s%s#%u", ", ",
1151
7.11k
    AArch64_AM_getShiftExtendName(AArch64_AM_getShiftType(Val)),
1152
7.11k
    " ", markup("<imm:"), AArch64_AM_getShiftValue(Val));
1153
7.11k
  SStream_concat0(O, markup(">"));
1154
7.11k
}
1155
1156
void printShiftedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1157
4.66k
{
1158
4.66k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ShiftedRegister, OpNum);
1159
4.66k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1160
4.66k
  printShifter(MI, OpNum + 1, O);
1161
4.66k
}
1162
1163
void printExtendedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1164
2.26k
{
1165
2.26k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ExtendedRegister, OpNum);
1166
2.26k
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1167
2.26k
  printArithExtend(MI, OpNum + 1, O);
1168
2.26k
}
1169
1170
void printArithExtend(MCInst *MI, unsigned OpNum, SStream *O)
1171
2.80k
{
1172
2.80k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_ArithExtend, OpNum);
1173
2.80k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1174
2.80k
  AArch64_AM_ShiftExtendType ExtType = AArch64_AM_getArithExtendType(Val);
1175
2.80k
  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.80k
  if (ExtType == AArch64_AM_UXTW || ExtType == AArch64_AM_UXTX) {
1181
690
    unsigned Dest = MCOperand_getReg(MCInst_getOperand(MI, (0)));
1182
690
    unsigned Src1 = MCOperand_getReg(MCInst_getOperand(MI, (1)));
1183
690
    if (((Dest == AArch64_SP || Src1 == AArch64_SP) &&
1184
235
         ExtType == AArch64_AM_UXTX) ||
1185
484
        ((Dest == AArch64_WSP || Src1 == AArch64_WSP) &&
1186
323
         ExtType == AArch64_AM_UXTW)) {
1187
323
      if (ShiftVal != 0) {
1188
323
        SStream_concat(O, "%s%s", ", lsl ",
1189
323
                 markup("<imm:"));
1190
323
        printUInt32Bang(O, ShiftVal);
1191
323
        SStream_concat0(O, markup(">"));
1192
323
      }
1193
323
      return;
1194
323
    }
1195
690
  }
1196
2.47k
  SStream_concat(O, "%s", ", ");
1197
2.47k
  SStream_concat0(O, AArch64_AM_getShiftExtendName(ExtType));
1198
2.47k
  if (ShiftVal != 0) {
1199
2.39k
    SStream_concat(O, "%s%s#%d", " ", markup("<imm:"), ShiftVal);
1200
2.39k
    SStream_concat0(O, markup(">"));
1201
2.39k
  }
1202
2.47k
}
1203
1204
static void printMemExtendImpl(bool SignExtend, bool DoShift, unsigned Width,
1205
             char SrcRegKind, SStream *O, bool getUseMarkup)
1206
8.69k
{
1207
  // sxtw, sxtx, uxtw or lsl (== uxtx)
1208
8.69k
  bool IsLSL = !SignExtend && SrcRegKind == 'x';
1209
8.69k
  if (IsLSL)
1210
3.68k
    SStream_concat0(O, "lsl");
1211
5.00k
  else {
1212
5.00k
    SStream_concat(O, "%c%s", (SignExtend ? 's' : 'u'), "xt");
1213
5.00k
    SStream_concat1(O, SrcRegKind);
1214
5.00k
  }
1215
1216
8.69k
  if (DoShift || IsLSL) {
1217
6.54k
    SStream_concat0(O, " ");
1218
6.54k
    if (getUseMarkup)
1219
0
      SStream_concat0(O, "<imm:");
1220
6.54k
    unsigned ShiftAmount = DoShift ? Log2_32(Width / 8) : 0;
1221
6.54k
    SStream_concat(O, "%s%u", "#", ShiftAmount);
1222
6.54k
    if (getUseMarkup)
1223
0
      SStream_concat0(O, ">");
1224
6.54k
  }
1225
8.69k
}
1226
1227
void printMemExtend(MCInst *MI, unsigned OpNum, SStream *O, char SrcRegKind,
1228
        unsigned Width)
1229
1.80k
{
1230
1.80k
  bool SignExtend = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1231
1.80k
  bool DoShift = MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1)));
1232
1.80k
  printMemExtendImpl(SignExtend, DoShift, Width, SrcRegKind, O,
1233
1.80k
         getUseMarkup());
1234
1.80k
}
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
9.43k
  { \
1243
9.43k
    AArch64_add_cs_detail_4( \
1244
9.43k
      MI, \
1245
9.43k
      CONCAT(CONCAT(CONCAT(CONCAT(AArch64_OP_GROUP_RegWithShiftExtend, \
1246
9.43k
                SignExtend), \
1247
9.43k
               ExtWidth), \
1248
9.43k
              SrcRegKind), \
1249
9.43k
             Suffix), \
1250
9.43k
      OpNum, SignExtend, ExtWidth, CHAR(SrcRegKind), \
1251
9.43k
      CHAR(Suffix)); \
1252
9.43k
    printOperand(MI, OpNum, O); \
1253
9.43k
    if (CHAR(Suffix) == 's' || CHAR(Suffix) == 'd') { \
1254
5.57k
      SStream_concat1(O, '.'); \
1255
5.57k
      SStream_concat1(O, CHAR(Suffix)); \
1256
5.57k
      SStream_concat1(O, '\0'); \
1257
5.57k
    } else \
1258
9.43k
      CS_ASSERT_RET((CHAR(Suffix) == '0') && \
1259
9.43k
              "Unsupported suffix size"); \
1260
9.43k
    bool DoShift = ExtWidth != 8; \
1261
9.43k
    if (SignExtend || DoShift || CHAR(SrcRegKind) == 'w') { \
1262
6.88k
      SStream_concat0(O, ", "); \
1263
6.88k
      printMemExtendImpl(SignExtend, DoShift, ExtWidth, \
1264
6.88k
             CHAR(SrcRegKind), O, \
1265
6.88k
             getUseMarkup()); \
1266
6.88k
    } \
1267
9.43k
  }
1268
946
DEFINE_printRegWithShiftExtend(false, 8, x, d);
1269
635
DEFINE_printRegWithShiftExtend(true, 8, w, d);
1270
295
DEFINE_printRegWithShiftExtend(false, 8, w, d);
1271
1.60k
DEFINE_printRegWithShiftExtend(false, 8, x, 0);
1272
190
DEFINE_printRegWithShiftExtend(true, 8, w, s);
1273
172
DEFINE_printRegWithShiftExtend(false, 8, w, s);
1274
537
DEFINE_printRegWithShiftExtend(false, 64, x, d);
1275
426
DEFINE_printRegWithShiftExtend(true, 64, w, d);
1276
358
DEFINE_printRegWithShiftExtend(false, 64, w, d);
1277
629
DEFINE_printRegWithShiftExtend(false, 64, x, 0);
1278
56
DEFINE_printRegWithShiftExtend(true, 64, w, s);
1279
15
DEFINE_printRegWithShiftExtend(false, 64, w, s);
1280
144
DEFINE_printRegWithShiftExtend(false, 16, x, d);
1281
226
DEFINE_printRegWithShiftExtend(true, 16, w, d);
1282
168
DEFINE_printRegWithShiftExtend(false, 16, w, d);
1283
1.03k
DEFINE_printRegWithShiftExtend(false, 16, x, 0);
1284
103
DEFINE_printRegWithShiftExtend(true, 16, w, s);
1285
193
DEFINE_printRegWithShiftExtend(false, 16, w, s);
1286
281
DEFINE_printRegWithShiftExtend(false, 32, x, d);
1287
202
DEFINE_printRegWithShiftExtend(true, 32, w, d);
1288
191
DEFINE_printRegWithShiftExtend(false, 32, w, d);
1289
403
DEFINE_printRegWithShiftExtend(false, 32, x, 0);
1290
204
DEFINE_printRegWithShiftExtend(true, 32, w, s);
1291
153
DEFINE_printRegWithShiftExtend(false, 32, w, s);
1292
0
DEFINE_printRegWithShiftExtend(false, 8, x, s);
1293
50
DEFINE_printRegWithShiftExtend(false, 16, x, s);
1294
21
DEFINE_printRegWithShiftExtend(false, 32, x, s);
1295
13
DEFINE_printRegWithShiftExtend(false, 64, x, s);
1296
192
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
4.15k
  { \
1302
4.15k
    AArch64_add_cs_detail_1( \
1303
4.15k
      MI, \
1304
4.15k
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
4.15k
      OpNum, EltSize); \
1306
4.15k
    unsigned Reg = \
1307
4.15k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
4.15k
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
4.15k
      CS_ASSERT_RET( \
1310
4.15k
        0 && \
1311
4.15k
        "Unsupported predicate-as-counter register"); \
1312
4.15k
    SStream_concat(O, "%s", "pn"); \
1313
4.15k
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
4.15k
    switch (EltSize) { \
1315
3.68k
    case 0: \
1316
3.68k
      break; \
1317
47
    case 8: \
1318
47
      SStream_concat0(O, ".b"); \
1319
47
      break; \
1320
69
    case 16: \
1321
69
      SStream_concat0(O, ".h"); \
1322
69
      break; \
1323
53
    case 32: \
1324
53
      SStream_concat0(O, ".s"); \
1325
53
      break; \
1326
294
    case 64: \
1327
294
      SStream_concat0(O, ".d"); \
1328
294
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
4.15k
    } \
1332
4.15k
  }
printPredicateAsCounter_8
Line
Count
Source
1301
47
  { \
1302
47
    AArch64_add_cs_detail_1( \
1303
47
      MI, \
1304
47
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
47
      OpNum, EltSize); \
1306
47
    unsigned Reg = \
1307
47
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
47
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
47
      CS_ASSERT_RET( \
1310
47
        0 && \
1311
47
        "Unsupported predicate-as-counter register"); \
1312
47
    SStream_concat(O, "%s", "pn"); \
1313
47
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
47
    switch (EltSize) { \
1315
0
    case 0: \
1316
0
      break; \
1317
47
    case 8: \
1318
47
      SStream_concat0(O, ".b"); \
1319
47
      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
47
    } \
1332
47
  }
printPredicateAsCounter_64
Line
Count
Source
1301
294
  { \
1302
294
    AArch64_add_cs_detail_1( \
1303
294
      MI, \
1304
294
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
294
      OpNum, EltSize); \
1306
294
    unsigned Reg = \
1307
294
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
294
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
294
      CS_ASSERT_RET( \
1310
294
        0 && \
1311
294
        "Unsupported predicate-as-counter register"); \
1312
294
    SStream_concat(O, "%s", "pn"); \
1313
294
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
294
    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
294
    case 64: \
1327
294
      SStream_concat0(O, ".d"); \
1328
294
      break; \
1329
0
    default: \
1330
0
      CS_ASSERT_RET(0 && "Unsupported element size"); \
1331
294
    } \
1332
294
  }
printPredicateAsCounter_16
Line
Count
Source
1301
69
  { \
1302
69
    AArch64_add_cs_detail_1( \
1303
69
      MI, \
1304
69
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
69
      OpNum, EltSize); \
1306
69
    unsigned Reg = \
1307
69
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
69
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
69
      CS_ASSERT_RET( \
1310
69
        0 && \
1311
69
        "Unsupported predicate-as-counter register"); \
1312
69
    SStream_concat(O, "%s", "pn"); \
1313
69
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
69
    switch (EltSize) { \
1315
0
    case 0: \
1316
0
      break; \
1317
0
    case 8: \
1318
0
      SStream_concat0(O, ".b"); \
1319
0
      break; \
1320
69
    case 16: \
1321
69
      SStream_concat0(O, ".h"); \
1322
69
      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
69
    } \
1332
69
  }
printPredicateAsCounter_32
Line
Count
Source
1301
53
  { \
1302
53
    AArch64_add_cs_detail_1( \
1303
53
      MI, \
1304
53
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
53
      OpNum, EltSize); \
1306
53
    unsigned Reg = \
1307
53
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
53
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
53
      CS_ASSERT_RET( \
1310
53
        0 && \
1311
53
        "Unsupported predicate-as-counter register"); \
1312
53
    SStream_concat(O, "%s", "pn"); \
1313
53
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
53
    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
53
    case 32: \
1324
53
      SStream_concat0(O, ".s"); \
1325
53
      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
53
    } \
1332
53
  }
printPredicateAsCounter_0
Line
Count
Source
1301
3.68k
  { \
1302
3.68k
    AArch64_add_cs_detail_1( \
1303
3.68k
      MI, \
1304
3.68k
      CONCAT(AArch64_OP_GROUP_PredicateAsCounter, EltSize), \
1305
3.68k
      OpNum, EltSize); \
1306
3.68k
    unsigned Reg = \
1307
3.68k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1308
3.68k
    if (Reg < AArch64_PN0 || Reg > AArch64_PN15) \
1309
3.68k
      CS_ASSERT_RET( \
1310
3.68k
        0 && \
1311
3.68k
        "Unsupported predicate-as-counter register"); \
1312
3.68k
    SStream_concat(O, "%s", "pn"); \
1313
3.68k
    SStream_concat(O, "%u", (Reg - AArch64_PN0)); \
1314
3.68k
    switch (EltSize) { \
1315
3.68k
    case 0: \
1316
3.68k
      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
3.68k
    } \
1332
3.68k
  }
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
1.74k
{
1341
1.74k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_CondCode, OpNum);
1342
1.74k
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(
1343
1.74k
    MCInst_getOperand(MI, (OpNum)));
1344
1.74k
  SStream_concat0(O, AArch64CC_getCondCodeName(CC));
1345
1.74k
}
1346
1347
void printInverseCondCode(MCInst *MI, unsigned OpNum, SStream *O)
1348
27
{
1349
27
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_InverseCondCode, OpNum);
1350
27
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(
1351
27
    MCInst_getOperand(MI, (OpNum)));
1352
27
  SStream_concat0(O, AArch64CC_getCondCodeName(
1353
27
           AArch64CC_getInvertedCondCode(CC)));
1354
27
}
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
12.9k
  { \
1369
12.9k
    AArch64_add_cs_detail_1( \
1370
12.9k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
12.9k
      Scale); \
1372
12.9k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
12.9k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
12.9k
              MI, (OpNum)))); \
1375
12.9k
    SStream_concat0(O, markup(">")); \
1376
12.9k
  }
printImmScale_8
Line
Count
Source
1368
3.35k
  { \
1369
3.35k
    AArch64_add_cs_detail_1( \
1370
3.35k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
3.35k
      Scale); \
1372
3.35k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
3.35k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
3.35k
              MI, (OpNum)))); \
1375
3.35k
    SStream_concat0(O, markup(">")); \
1376
3.35k
  }
printImmScale_2
Line
Count
Source
1368
1.31k
  { \
1369
1.31k
    AArch64_add_cs_detail_1( \
1370
1.31k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
1.31k
      Scale); \
1372
1.31k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
1.31k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
1.31k
              MI, (OpNum)))); \
1375
1.31k
    SStream_concat0(O, markup(">")); \
1376
1.31k
  }
printImmScale_4
Line
Count
Source
1368
5.72k
  { \
1369
5.72k
    AArch64_add_cs_detail_1( \
1370
5.72k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
5.72k
      Scale); \
1372
5.72k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
5.72k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
5.72k
              MI, (OpNum)))); \
1375
5.72k
    SStream_concat0(O, markup(">")); \
1376
5.72k
  }
printImmScale_16
Line
Count
Source
1368
1.98k
  { \
1369
1.98k
    AArch64_add_cs_detail_1( \
1370
1.98k
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
1.98k
      Scale); \
1372
1.98k
    SStream_concat(O, "%s", markup("<imm:")); \
1373
1.98k
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
1.98k
              MI, (OpNum)))); \
1375
1.98k
    SStream_concat0(O, markup(">")); \
1376
1.98k
  }
printImmScale_32
Line
Count
Source
1368
16
  { \
1369
16
    AArch64_add_cs_detail_1( \
1370
16
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
16
      Scale); \
1372
16
    SStream_concat(O, "%s", markup("<imm:")); \
1373
16
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
16
              MI, (OpNum)))); \
1375
16
    SStream_concat0(O, markup(">")); \
1376
16
  }
printImmScale_3
Line
Count
Source
1368
559
  { \
1369
559
    AArch64_add_cs_detail_1( \
1370
559
      MI, CONCAT(AArch64_OP_GROUP_ImmScale, Scale), OpNum, \
1371
559
      Scale); \
1372
559
    SStream_concat(O, "%s", markup("<imm:")); \
1373
559
    printInt32Bang(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1374
559
              MI, (OpNum)))); \
1375
559
    SStream_concat0(O, markup(">")); \
1376
559
  }
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.08k
  { \
1388
3.08k
    AArch64_add_cs_detail_2( \
1389
3.08k
      MI, \
1390
3.08k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1391
3.08k
             Offset), \
1392
3.08k
      OpNum, Scale, Offset); \
1393
3.08k
    unsigned FirstImm = \
1394
3.08k
      Scale * \
1395
3.08k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1396
3.08k
    printUInt32(O, (FirstImm)); \
1397
3.08k
    SStream_concat(O, "%s", ":"); \
1398
3.08k
    printUInt32(O, (FirstImm + Offset)); \
1399
3.08k
    SStream_concat1(O, '\0'); \
1400
3.08k
  }
printImmRangeScale_2_1
Line
Count
Source
1387
1.78k
  { \
1388
1.78k
    AArch64_add_cs_detail_2( \
1389
1.78k
      MI, \
1390
1.78k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1391
1.78k
             Offset), \
1392
1.78k
      OpNum, Scale, Offset); \
1393
1.78k
    unsigned FirstImm = \
1394
1.78k
      Scale * \
1395
1.78k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1396
1.78k
    printUInt32(O, (FirstImm)); \
1397
1.78k
    SStream_concat(O, "%s", ":"); \
1398
1.78k
    printUInt32(O, (FirstImm + Offset)); \
1399
1.78k
    SStream_concat1(O, '\0'); \
1400
1.78k
  }
printImmRangeScale_4_3
Line
Count
Source
1387
1.30k
  { \
1388
1.30k
    AArch64_add_cs_detail_2( \
1389
1.30k
      MI, \
1390
1.30k
      CONCAT(CONCAT(AArch64_OP_GROUP_ImmRangeScale, Scale), \
1391
1.30k
             Offset), \
1392
1.30k
      OpNum, Scale, Offset); \
1393
1.30k
    unsigned FirstImm = \
1394
1.30k
      Scale * \
1395
1.30k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1396
1.30k
    printUInt32(O, (FirstImm)); \
1397
1.30k
    SStream_concat(O, "%s", ":"); \
1398
1.30k
    printUInt32(O, (FirstImm + Offset)); \
1399
1.30k
    SStream_concat1(O, '\0'); \
1400
1.30k
  }
1401
DEFINE_printImmRangeScale(2, 1);
1402
DEFINE_printImmRangeScale(4, 3);
1403
1404
void printUImm12Offset(MCInst *MI, unsigned OpNum, unsigned Scale, SStream *O)
1405
4.23k
{
1406
4.23k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1407
4.23k
  if (MCOperand_isImm(MO)) {
1408
4.23k
    SStream_concat(O, "%s", markup("<imm:"));
1409
4.23k
    printUInt32Bang(O, (MCOperand_getImm(MO) * Scale));
1410
4.23k
    SStream_concat0(O, markup(">"));
1411
4.23k
  } else {
1412
0
    printUInt64Bang(O, MCOperand_getImm(MO));
1413
0
  }
1414
4.23k
}
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
498
{
1434
498
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_RPRFMOperand, OpNum);
1435
498
  unsigned prfop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1436
498
  const AArch64PRFM_PRFM *PRFM =
1437
498
    AArch64RPRFM_lookupRPRFMByEncoding(prfop);
1438
498
  if (PRFM) {
1439
300
    SStream_concat0(O, PRFM->Name);
1440
300
    return;
1441
300
  }
1442
1443
198
  printUInt32Bang(O, (prfop));
1444
198
  SStream_concat1(O, '\0');
1445
198
}
1446
1447
#define DEFINE_printPrefetchOp(IsSVEPrefetch) \
1448
  void CONCAT(printPrefetchOp, \
1449
        IsSVEPrefetch)(MCInst * MI, unsigned OpNum, SStream *O) \
1450
3.45k
  { \
1451
3.45k
    AArch64_add_cs_detail_1(MI, \
1452
3.45k
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1453
3.45k
                 IsSVEPrefetch), \
1454
3.45k
          OpNum, IsSVEPrefetch); \
1455
3.45k
    unsigned prfop = \
1456
3.45k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1457
3.45k
    if (IsSVEPrefetch) { \
1458
2.45k
      const AArch64SVEPRFM_SVEPRFM *PRFM = \
1459
2.45k
        AArch64SVEPRFM_lookupSVEPRFMByEncoding(prfop); \
1460
2.45k
      if (PRFM) { \
1461
2.09k
        SStream_concat0(O, PRFM->Name); \
1462
2.09k
        return; \
1463
2.09k
      } \
1464
2.45k
    } else { \
1465
999
      const AArch64PRFM_PRFM *PRFM = \
1466
999
        AArch64PRFM_lookupPRFMByEncoding(prfop); \
1467
999
      if (PRFM && \
1468
999
          AArch64_testFeatureList(MI->csh->mode, \
1469
635
                PRFM->FeaturesRequired)) { \
1470
635
        SStream_concat0(O, PRFM->Name); \
1471
635
        return; \
1472
635
      } \
1473
999
    } \
1474
3.45k
\
1475
3.45k
    SStream_concat(O, "%s", markup("<imm:")); \
1476
718
    printUInt32Bang(O, (prfop)); \
1477
718
    SStream_concat0(O, markup(">")); \
1478
718
  }
printPrefetchOp_0
Line
Count
Source
1450
999
  { \
1451
999
    AArch64_add_cs_detail_1(MI, \
1452
999
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1453
999
                 IsSVEPrefetch), \
1454
999
          OpNum, IsSVEPrefetch); \
1455
999
    unsigned prfop = \
1456
999
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1457
999
    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
999
    } else { \
1465
999
      const AArch64PRFM_PRFM *PRFM = \
1466
999
        AArch64PRFM_lookupPRFMByEncoding(prfop); \
1467
999
      if (PRFM && \
1468
999
          AArch64_testFeatureList(MI->csh->mode, \
1469
635
                PRFM->FeaturesRequired)) { \
1470
635
        SStream_concat0(O, PRFM->Name); \
1471
635
        return; \
1472
635
      } \
1473
999
    } \
1474
999
\
1475
999
    SStream_concat(O, "%s", markup("<imm:")); \
1476
364
    printUInt32Bang(O, (prfop)); \
1477
364
    SStream_concat0(O, markup(">")); \
1478
364
  }
printPrefetchOp_1
Line
Count
Source
1450
2.45k
  { \
1451
2.45k
    AArch64_add_cs_detail_1(MI, \
1452
2.45k
          CONCAT(AArch64_OP_GROUP_PrefetchOp, \
1453
2.45k
                 IsSVEPrefetch), \
1454
2.45k
          OpNum, IsSVEPrefetch); \
1455
2.45k
    unsigned prfop = \
1456
2.45k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
1457
2.45k
    if (IsSVEPrefetch) { \
1458
2.45k
      const AArch64SVEPRFM_SVEPRFM *PRFM = \
1459
2.45k
        AArch64SVEPRFM_lookupSVEPRFMByEncoding(prfop); \
1460
2.45k
      if (PRFM) { \
1461
2.09k
        SStream_concat0(O, PRFM->Name); \
1462
2.09k
        return; \
1463
2.09k
      } \
1464
2.45k
    } 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.45k
\
1475
2.45k
    SStream_concat(O, "%s", markup("<imm:")); \
1476
354
    printUInt32Bang(O, (prfop)); \
1477
354
    SStream_concat0(O, markup(">")); \
1478
354
  }
1479
DEFINE_printPrefetchOp(false);
1480
DEFINE_printPrefetchOp(true);
1481
1482
void printPSBHintOp(MCInst *MI, unsigned OpNum, SStream *O)
1483
299
{
1484
299
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_PSBHintOp, OpNum);
1485
299
  unsigned psbhintop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1486
299
  const AArch64PSBHint_PSB *PSB =
1487
299
    AArch64PSBHint_lookupPSBByEncoding(psbhintop);
1488
299
  if (PSB)
1489
299
    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
299
}
1497
1498
void printBTIHintOp(MCInst *MI, unsigned OpNum, SStream *O)
1499
486
{
1500
486
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BTIHintOp, OpNum);
1501
486
  unsigned btihintop = MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) ^
1502
486
           32;
1503
486
  const AArch64BTIHint_BTI *BTI =
1504
486
    AArch64BTIHint_lookupBTIByEncoding(btihintop);
1505
486
  if (BTI)
1506
486
    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
486
}
1513
1514
static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1515
705
{
1516
705
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_FPImmOperand, OpNum);
1517
705
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1518
705
  float FPImm = MCOperand_isDFPImm(MO) ?
1519
0
            BitsToDouble(MCOperand_getImm(MO)) :
1520
705
            AArch64_AM_getFPImmFloat(MCOperand_getImm(MO));
1521
1522
  // 8 decimal places are enough to perfectly represent permitted floats.
1523
705
  SStream_concat(O, "%s", markup("<imm:"));
1524
705
  SStream_concat(O, "#%.8f", FPImm);
1525
705
  SStream_concat0(O, markup(">"));
1526
705
}
1527
1528
static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride /* = 1 */)
1529
72.3k
{
1530
190k
  while (Stride--) {
1531
118k
    switch (Reg) {
1532
0
    default:
1533
0
      CS_ASSERT_RET_VAL(0 && "Vector register expected!", 0);
1534
3.31k
    case AArch64_Q0:
1535
3.31k
      Reg = AArch64_Q1;
1536
3.31k
      break;
1537
2.28k
    case AArch64_Q1:
1538
2.28k
      Reg = AArch64_Q2;
1539
2.28k
      break;
1540
1.28k
    case AArch64_Q2:
1541
1.28k
      Reg = AArch64_Q3;
1542
1.28k
      break;
1543
1.31k
    case AArch64_Q3:
1544
1.31k
      Reg = AArch64_Q4;
1545
1.31k
      break;
1546
1.28k
    case AArch64_Q4:
1547
1.28k
      Reg = AArch64_Q5;
1548
1.28k
      break;
1549
1.58k
    case AArch64_Q5:
1550
1.58k
      Reg = AArch64_Q6;
1551
1.58k
      break;
1552
584
    case AArch64_Q6:
1553
584
      Reg = AArch64_Q7;
1554
584
      break;
1555
580
    case AArch64_Q7:
1556
580
      Reg = AArch64_Q8;
1557
580
      break;
1558
639
    case AArch64_Q8:
1559
639
      Reg = AArch64_Q9;
1560
639
      break;
1561
664
    case AArch64_Q9:
1562
664
      Reg = AArch64_Q10;
1563
664
      break;
1564
1.22k
    case AArch64_Q10:
1565
1.22k
      Reg = AArch64_Q11;
1566
1.22k
      break;
1567
1.31k
    case AArch64_Q11:
1568
1.31k
      Reg = AArch64_Q12;
1569
1.31k
      break;
1570
2.74k
    case AArch64_Q12:
1571
2.74k
      Reg = AArch64_Q13;
1572
2.74k
      break;
1573
2.12k
    case AArch64_Q13:
1574
2.12k
      Reg = AArch64_Q14;
1575
2.12k
      break;
1576
2.20k
    case AArch64_Q14:
1577
2.20k
      Reg = AArch64_Q15;
1578
2.20k
      break;
1579
409
    case AArch64_Q15:
1580
409
      Reg = AArch64_Q16;
1581
409
      break;
1582
599
    case AArch64_Q16:
1583
599
      Reg = AArch64_Q17;
1584
599
      break;
1585
628
    case AArch64_Q17:
1586
628
      Reg = AArch64_Q18;
1587
628
      break;
1588
677
    case AArch64_Q18:
1589
677
      Reg = AArch64_Q19;
1590
677
      break;
1591
1.26k
    case AArch64_Q19:
1592
1.26k
      Reg = AArch64_Q20;
1593
1.26k
      break;
1594
2.09k
    case AArch64_Q20:
1595
2.09k
      Reg = AArch64_Q21;
1596
2.09k
      break;
1597
1.53k
    case AArch64_Q21:
1598
1.53k
      Reg = AArch64_Q22;
1599
1.53k
      break;
1600
1.47k
    case AArch64_Q22:
1601
1.47k
      Reg = AArch64_Q23;
1602
1.47k
      break;
1603
1.24k
    case AArch64_Q23:
1604
1.24k
      Reg = AArch64_Q24;
1605
1.24k
      break;
1606
1.07k
    case AArch64_Q24:
1607
1.07k
      Reg = AArch64_Q25;
1608
1.07k
      break;
1609
1.42k
    case AArch64_Q25:
1610
1.42k
      Reg = AArch64_Q26;
1611
1.42k
      break;
1612
1.08k
    case AArch64_Q26:
1613
1.08k
      Reg = AArch64_Q27;
1614
1.08k
      break;
1615
342
    case AArch64_Q27:
1616
342
      Reg = AArch64_Q28;
1617
342
      break;
1618
323
    case AArch64_Q28:
1619
323
      Reg = AArch64_Q29;
1620
323
      break;
1621
502
    case AArch64_Q29:
1622
502
      Reg = AArch64_Q30;
1623
502
      break;
1624
414
    case AArch64_Q30:
1625
414
      Reg = AArch64_Q31;
1626
414
      break;
1627
    // Vector lists can wrap around.
1628
1.11k
    case AArch64_Q31:
1629
1.11k
      Reg = AArch64_Q0;
1630
1.11k
      break;
1631
5.12k
    case AArch64_Z0:
1632
5.12k
      Reg = AArch64_Z1;
1633
5.12k
      break;
1634
3.77k
    case AArch64_Z1:
1635
3.77k
      Reg = AArch64_Z2;
1636
3.77k
      break;
1637
4.01k
    case AArch64_Z2:
1638
4.01k
      Reg = AArch64_Z3;
1639
4.01k
      break;
1640
1.37k
    case AArch64_Z3:
1641
1.37k
      Reg = AArch64_Z4;
1642
1.37k
      break;
1643
6.67k
    case AArch64_Z4:
1644
6.67k
      Reg = AArch64_Z5;
1645
6.67k
      break;
1646
4.40k
    case AArch64_Z5:
1647
4.40k
      Reg = AArch64_Z6;
1648
4.40k
      break;
1649
3.39k
    case AArch64_Z6:
1650
3.39k
      Reg = AArch64_Z7;
1651
3.39k
      break;
1652
1.06k
    case AArch64_Z7:
1653
1.06k
      Reg = AArch64_Z8;
1654
1.06k
      break;
1655
3.57k
    case AArch64_Z8:
1656
3.57k
      Reg = AArch64_Z9;
1657
3.57k
      break;
1658
2.50k
    case AArch64_Z9:
1659
2.50k
      Reg = AArch64_Z10;
1660
2.50k
      break;
1661
2.58k
    case AArch64_Z10:
1662
2.58k
      Reg = AArch64_Z11;
1663
2.58k
      break;
1664
1.05k
    case AArch64_Z11:
1665
1.05k
      Reg = AArch64_Z12;
1666
1.05k
      break;
1667
1.36k
    case AArch64_Z12:
1668
1.36k
      Reg = AArch64_Z13;
1669
1.36k
      break;
1670
1.26k
    case AArch64_Z13:
1671
1.26k
      Reg = AArch64_Z14;
1672
1.26k
      break;
1673
1.88k
    case AArch64_Z14:
1674
1.88k
      Reg = AArch64_Z15;
1675
1.88k
      break;
1676
1.17k
    case AArch64_Z15:
1677
1.17k
      Reg = AArch64_Z16;
1678
1.17k
      break;
1679
1.87k
    case AArch64_Z16:
1680
1.87k
      Reg = AArch64_Z17;
1681
1.87k
      break;
1682
1.06k
    case AArch64_Z17:
1683
1.06k
      Reg = AArch64_Z18;
1684
1.06k
      break;
1685
1.53k
    case AArch64_Z18:
1686
1.53k
      Reg = AArch64_Z19;
1687
1.53k
      break;
1688
1.31k
    case AArch64_Z19:
1689
1.31k
      Reg = AArch64_Z20;
1690
1.31k
      break;
1691
2.27k
    case AArch64_Z20:
1692
2.27k
      Reg = AArch64_Z21;
1693
2.27k
      break;
1694
2.34k
    case AArch64_Z21:
1695
2.34k
      Reg = AArch64_Z22;
1696
2.34k
      break;
1697
2.80k
    case AArch64_Z22:
1698
2.80k
      Reg = AArch64_Z23;
1699
2.80k
      break;
1700
1.42k
    case AArch64_Z23:
1701
1.42k
      Reg = AArch64_Z24;
1702
1.42k
      break;
1703
2.55k
    case AArch64_Z24:
1704
2.55k
      Reg = AArch64_Z25;
1705
2.55k
      break;
1706
2.92k
    case AArch64_Z25:
1707
2.92k
      Reg = AArch64_Z26;
1708
2.92k
      break;
1709
3.65k
    case AArch64_Z26:
1710
3.65k
      Reg = AArch64_Z27;
1711
3.65k
      break;
1712
1.63k
    case AArch64_Z27:
1713
1.63k
      Reg = AArch64_Z28;
1714
1.63k
      break;
1715
1.93k
    case AArch64_Z28:
1716
1.93k
      Reg = AArch64_Z29;
1717
1.93k
      break;
1718
1.47k
    case AArch64_Z29:
1719
1.47k
      Reg = AArch64_Z30;
1720
1.47k
      break;
1721
1.44k
    case AArch64_Z30:
1722
1.44k
      Reg = AArch64_Z31;
1723
1.44k
      break;
1724
    // Vector lists can wrap around.
1725
1.52k
    case AArch64_Z31:
1726
1.52k
      Reg = AArch64_Z0;
1727
1.52k
      break;
1728
180
    case AArch64_P0:
1729
180
      Reg = AArch64_P1;
1730
180
      break;
1731
84
    case AArch64_P1:
1732
84
      Reg = AArch64_P2;
1733
84
      break;
1734
140
    case AArch64_P2:
1735
140
      Reg = AArch64_P3;
1736
140
      break;
1737
24
    case AArch64_P3:
1738
24
      Reg = AArch64_P4;
1739
24
      break;
1740
38
    case AArch64_P4:
1741
38
      Reg = AArch64_P5;
1742
38
      break;
1743
160
    case AArch64_P5:
1744
160
      Reg = AArch64_P6;
1745
160
      break;
1746
28
    case AArch64_P6:
1747
28
      Reg = AArch64_P7;
1748
28
      break;
1749
30
    case AArch64_P7:
1750
30
      Reg = AArch64_P8;
1751
30
      break;
1752
76
    case AArch64_P8:
1753
76
      Reg = AArch64_P9;
1754
76
      break;
1755
34
    case AArch64_P9:
1756
34
      Reg = AArch64_P10;
1757
34
      break;
1758
30
    case AArch64_P10:
1759
30
      Reg = AArch64_P11;
1760
30
      break;
1761
22
    case AArch64_P11:
1762
22
      Reg = AArch64_P12;
1763
22
      break;
1764
26
    case AArch64_P12:
1765
26
      Reg = AArch64_P13;
1766
26
      break;
1767
576
    case AArch64_P13:
1768
576
      Reg = AArch64_P14;
1769
576
      break;
1770
22
    case AArch64_P14:
1771
22
      Reg = AArch64_P15;
1772
22
      break;
1773
    // Vector lists can wrap around.
1774
340
    case AArch64_P15:
1775
340
      Reg = AArch64_P0;
1776
340
      break;
1777
118k
    }
1778
118k
  }
1779
72.3k
  return Reg;
1780
72.3k
}
1781
1782
#define DEFINE_printGPRSeqPairsClassOperand(size) \
1783
  void CONCAT(printGPRSeqPairsClassOperand, \
1784
        size)(MCInst * MI, unsigned OpNum, SStream *O) \
1785
1.20k
  { \
1786
1.20k
    AArch64_add_cs_detail_1( \
1787
1.20k
      MI, \
1788
1.20k
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1789
1.20k
             size), \
1790
1.20k
      OpNum, size); \
1791
1.20k
    CS_ASSERT_RET((size == 64 || size == 32) && \
1792
1.20k
            "Template parameter must be either 32 or 64"); \
1793
1.20k
    unsigned Reg = \
1794
1.20k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1795
1.20k
\
1796
1.20k
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1797
1.20k
                 AArch64_sube64; \
1798
1.20k
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1799
1.20k
                 AArch64_subo64; \
1800
1.20k
\
1801
1.20k
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1802
1.20k
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1803
1.20k
    printRegName(O, Even); \
1804
1.20k
    SStream_concat0(O, ", "); \
1805
1.20k
    printRegName(O, Odd); \
1806
1.20k
  }
printGPRSeqPairsClassOperand_32
Line
Count
Source
1785
142
  { \
1786
142
    AArch64_add_cs_detail_1( \
1787
142
      MI, \
1788
142
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1789
142
             size), \
1790
142
      OpNum, size); \
1791
142
    CS_ASSERT_RET((size == 64 || size == 32) && \
1792
142
            "Template parameter must be either 32 or 64"); \
1793
142
    unsigned Reg = \
1794
142
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1795
142
\
1796
142
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1797
142
                 AArch64_sube64; \
1798
142
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1799
142
                 AArch64_subo64; \
1800
142
\
1801
142
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1802
142
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1803
142
    printRegName(O, Even); \
1804
142
    SStream_concat0(O, ", "); \
1805
142
    printRegName(O, Odd); \
1806
142
  }
printGPRSeqPairsClassOperand_64
Line
Count
Source
1785
1.06k
  { \
1786
1.06k
    AArch64_add_cs_detail_1( \
1787
1.06k
      MI, \
1788
1.06k
      CONCAT(AArch64_OP_GROUP_GPRSeqPairsClassOperand, \
1789
1.06k
             size), \
1790
1.06k
      OpNum, size); \
1791
1.06k
    CS_ASSERT_RET((size == 64 || size == 32) && \
1792
1.06k
            "Template parameter must be either 32 or 64"); \
1793
1.06k
    unsigned Reg = \
1794
1.06k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1795
1.06k
\
1796
1.06k
    unsigned Sube = (size == 32) ? AArch64_sube32 : \
1797
1.06k
                 AArch64_sube64; \
1798
1.06k
    unsigned Subo = (size == 32) ? AArch64_subo32 : \
1799
1.06k
                 AArch64_subo64; \
1800
1.06k
\
1801
1.06k
    unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube); \
1802
1.06k
    unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo); \
1803
1.06k
    printRegName(O, Even); \
1804
1.06k
    SStream_concat0(O, ", "); \
1805
1.06k
    printRegName(O, Odd); \
1806
1.06k
  }
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
4.67k
  { \
1814
4.67k
    AArch64_add_cs_detail_1( \
1815
4.67k
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1816
4.67k
      OpNum, Scale); \
1817
4.67k
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1818
4.67k
                MI, (OpNum)))); \
1819
4.67k
  }
printMatrixIndex_8
Line
Count
Source
1813
48
  { \
1814
48
    AArch64_add_cs_detail_1( \
1815
48
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1816
48
      OpNum, Scale); \
1817
48
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1818
48
                MI, (OpNum)))); \
1819
48
  }
Unexecuted instantiation: printMatrixIndex_0
printMatrixIndex_1
Line
Count
Source
1813
4.62k
  { \
1814
4.62k
    AArch64_add_cs_detail_1( \
1815
4.62k
      MI, CONCAT(AArch64_OP_GROUP_MatrixIndex, Scale), \
1816
4.62k
      OpNum, Scale); \
1817
4.62k
    printInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
1818
4.62k
                MI, (OpNum)))); \
1819
4.62k
  }
1820
DEFINE_printMatrixIndex(8);
1821
DEFINE_printMatrixIndex(0);
1822
DEFINE_printMatrixIndex(1);
1823
1824
void printMatrixTileList(MCInst *MI, unsigned OpNum, SStream *O)
1825
541
{
1826
541
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MatrixTileList, OpNum);
1827
541
  unsigned MaxRegs = 8;
1828
541
  unsigned RegMask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1829
1830
541
  unsigned NumRegs = 0;
1831
4.86k
  for (unsigned I = 0; I < MaxRegs; ++I)
1832
4.32k
    if ((RegMask & (1 << I)) != 0)
1833
1.73k
      ++NumRegs;
1834
1835
541
  SStream_concat0(O, "{");
1836
541
  unsigned Printed = 0;
1837
4.86k
  for (unsigned I = 0; I < MaxRegs; ++I) {
1838
4.32k
    unsigned Reg = RegMask & (1 << I);
1839
4.32k
    if (Reg == 0)
1840
2.59k
      continue;
1841
1.73k
    printRegName(O, AArch64_ZAD0 + I);
1842
1.73k
    if (Printed + 1 != NumRegs)
1843
1.20k
      SStream_concat0(O, ", ");
1844
1.73k
    ++Printed;
1845
1.73k
  }
1846
541
  SStream_concat0(O, "}");
1847
541
}
1848
1849
void printVectorList(MCInst *MI, unsigned OpNum, SStream *O,
1850
         const char *LayoutSuffix)
1851
34.9k
{
1852
34.9k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1853
1854
34.9k
  SStream_concat0(O, "{ ");
1855
1856
  // Work out how many registers there are in the list (if there is an actual
1857
  // list).
1858
34.9k
  unsigned NumRegs = 1;
1859
34.9k
  if (MCRegisterClass_contains(
1860
34.9k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_DDRegClassID),
1861
34.9k
        Reg) ||
1862
34.6k
      MCRegisterClass_contains(
1863
34.6k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_ZPR2RegClassID),
1864
34.6k
        Reg) ||
1865
29.4k
      MCRegisterClass_contains(
1866
29.4k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_QQRegClassID),
1867
29.4k
        Reg) ||
1868
25.7k
      MCRegisterClass_contains(
1869
25.7k
        MCRegisterInfo_getRegClass(MI->MRI, AArch64_PPR2RegClassID),
1870
25.7k
        Reg) ||
1871
24.9k
      MCRegisterClass_contains(
1872
24.9k
        MCRegisterInfo_getRegClass(MI->MRI,
1873
24.9k
                 AArch64_ZPR2StridedRegClassID),
1874
24.9k
        Reg))
1875
12.0k
    NumRegs = 2;
1876
22.9k
  else if (MCRegisterClass_contains(
1877
22.9k
       MCRegisterInfo_getRegClass(MI->MRI,
1878
22.9k
                AArch64_DDDRegClassID),
1879
22.9k
       Reg) ||
1880
22.5k
     MCRegisterClass_contains(
1881
22.5k
       MCRegisterInfo_getRegClass(MI->MRI,
1882
22.5k
                AArch64_ZPR3RegClassID),
1883
22.5k
       Reg) ||
1884
21.9k
     MCRegisterClass_contains(
1885
21.9k
       MCRegisterInfo_getRegClass(MI->MRI,
1886
21.9k
                AArch64_QQQRegClassID),
1887
21.9k
       Reg))
1888
5.46k
    NumRegs = 3;
1889
17.5k
  else if (MCRegisterClass_contains(
1890
17.5k
       MCRegisterInfo_getRegClass(MI->MRI,
1891
17.5k
                AArch64_DDDDRegClassID),
1892
17.5k
       Reg) ||
1893
17.2k
     MCRegisterClass_contains(
1894
17.2k
       MCRegisterInfo_getRegClass(MI->MRI,
1895
17.2k
                AArch64_ZPR4RegClassID),
1896
17.2k
       Reg) ||
1897
13.8k
     MCRegisterClass_contains(
1898
13.8k
       MCRegisterInfo_getRegClass(MI->MRI,
1899
13.8k
                AArch64_QQQQRegClassID),
1900
13.8k
       Reg) ||
1901
10.6k
     MCRegisterClass_contains(
1902
10.6k
       MCRegisterInfo_getRegClass(
1903
10.6k
         MI->MRI, AArch64_ZPR4StridedRegClassID),
1904
10.6k
       Reg))
1905
7.21k
    NumRegs = 4;
1906
1907
34.9k
  unsigned Stride = 1;
1908
34.9k
  if (MCRegisterClass_contains(
1909
34.9k
        MCRegisterInfo_getRegClass(MI->MRI,
1910
34.9k
                 AArch64_ZPR2StridedRegClassID),
1911
34.9k
        Reg))
1912
1.92k
    Stride = 8;
1913
33.0k
  else if (MCRegisterClass_contains(
1914
33.0k
       MCRegisterInfo_getRegClass(
1915
33.0k
         MI->MRI, AArch64_ZPR4StridedRegClassID),
1916
33.0k
       Reg))
1917
333
    Stride = 4;
1918
1919
  // Now forget about the list and find out what the first register is.
1920
34.9k
  if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_dsub0))
1921
1.00k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_dsub0);
1922
33.9k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_qsub0))
1923
11.3k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_qsub0);
1924
22.5k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_zsub0))
1925
11.4k
    Reg = MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_zsub0);
1926
11.1k
  else if (MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_psub0))
1927
820
    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
34.9k
  if (MCRegisterClass_contains(MCRegisterInfo_getRegClass(
1932
34.9k
               MI->MRI, AArch64_FPR64RegClassID),
1933
34.9k
             Reg)) {
1934
1.24k
    const MCRegisterClass *FPR128RC = MCRegisterInfo_getRegClass(
1935
1.24k
      MI->MRI, AArch64_FPR128RegClassID);
1936
1.24k
    Reg = MCRegisterInfo_getMatchingSuperReg(
1937
1.24k
      MI->MRI, Reg, AArch64_dsub, FPR128RC);
1938
1.24k
  }
1939
1940
34.9k
  if ((MCRegisterClass_contains(
1941
34.9k
         MCRegisterInfo_getRegClass(MI->MRI, AArch64_ZPRRegClassID),
1942
34.9k
         Reg) ||
1943
15.9k
       MCRegisterClass_contains(
1944
15.9k
         MCRegisterInfo_getRegClass(MI->MRI, AArch64_PPRRegClassID),
1945
15.9k
         Reg)) &&
1946
19.8k
      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
10.0k
      Reg < getNextVectorRegister(Reg, NumRegs - 1)) {
1950
9.82k
    printRegName(O, Reg);
1951
9.82k
    SStream_concat0(O, LayoutSuffix);
1952
9.82k
    if (NumRegs > 1) {
1953
      // Set of two sve registers should be separated by ','
1954
9.82k
      const char *split_char = NumRegs == 2 ? ", " : " - ";
1955
9.82k
      SStream_concat0(O, split_char);
1956
9.82k
      printRegName(O,
1957
9.82k
             (getNextVectorRegister(Reg, NumRegs - 1)));
1958
9.82k
      SStream_concat0(O, LayoutSuffix);
1959
9.82k
    }
1960
25.1k
  } else {
1961
77.6k
    for (unsigned i = 0; i < NumRegs;
1962
52.4k
         ++i, Reg = getNextVectorRegister(Reg, Stride)) {
1963
      // wrap-around sve register
1964
52.4k
      if (MCRegisterClass_contains(
1965
52.4k
            MCRegisterInfo_getRegClass(
1966
52.4k
              MI->MRI, AArch64_ZPRRegClassID),
1967
52.4k
            Reg) ||
1968
39.6k
          MCRegisterClass_contains(
1969
39.6k
            MCRegisterInfo_getRegClass(
1970
39.6k
              MI->MRI, AArch64_PPRRegClassID),
1971
39.6k
            Reg))
1972
13.1k
        printRegName(O, Reg);
1973
39.3k
      else
1974
39.3k
        printRegNameAlt(O, Reg, AArch64_vreg);
1975
52.4k
      SStream_concat0(O, LayoutSuffix);
1976
52.4k
      if (i + 1 != NumRegs)
1977
27.3k
        SStream_concat0(O, ", ");
1978
52.4k
    }
1979
25.1k
  }
1980
34.9k
  SStream_concat0(O, " }");
1981
34.9k
}
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
34.9k
  { \
1994
34.9k
    AArch64_add_cs_detail_2( \
1995
34.9k
      MI, \
1996
34.9k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
34.9k
              NumLanes), \
1998
34.9k
             LaneKind), \
1999
34.9k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
34.9k
    if (CHAR(LaneKind) == '0') { \
2001
52
      printVectorList(MI, OpNum, O, ""); \
2002
52
      return; \
2003
52
    } \
2004
34.9k
    char Suffix[32]; \
2005
34.9k
    if (NumLanes) \
2006
34.9k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
5.53k
            CHAR(LaneKind)); \
2008
34.9k
    else \
2009
34.9k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
29.3k
            CHAR(LaneKind)); \
2011
34.9k
\
2012
34.9k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
34.9k
  }
printTypedVectorList_0_b
Line
Count
Source
1993
6.16k
  { \
1994
6.16k
    AArch64_add_cs_detail_2( \
1995
6.16k
      MI, \
1996
6.16k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
6.16k
              NumLanes), \
1998
6.16k
             LaneKind), \
1999
6.16k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
6.16k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
6.16k
    char Suffix[32]; \
2005
6.16k
    if (NumLanes) \
2006
6.16k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
6.16k
    else \
2009
6.16k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
6.16k
            CHAR(LaneKind)); \
2011
6.16k
\
2012
6.16k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
6.16k
  }
printTypedVectorList_0_d
Line
Count
Source
1993
8.66k
  { \
1994
8.66k
    AArch64_add_cs_detail_2( \
1995
8.66k
      MI, \
1996
8.66k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
8.66k
              NumLanes), \
1998
8.66k
             LaneKind), \
1999
8.66k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
8.66k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
8.66k
    char Suffix[32]; \
2005
8.66k
    if (NumLanes) \
2006
8.66k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
8.66k
    else \
2009
8.66k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
8.66k
            CHAR(LaneKind)); \
2011
8.66k
\
2012
8.66k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
8.66k
  }
printTypedVectorList_0_h
Line
Count
Source
1993
7.06k
  { \
1994
7.06k
    AArch64_add_cs_detail_2( \
1995
7.06k
      MI, \
1996
7.06k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
7.06k
              NumLanes), \
1998
7.06k
             LaneKind), \
1999
7.06k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
7.06k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
7.06k
    char Suffix[32]; \
2005
7.06k
    if (NumLanes) \
2006
7.06k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
7.06k
    else \
2009
7.06k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
7.06k
            CHAR(LaneKind)); \
2011
7.06k
\
2012
7.06k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
7.06k
  }
printTypedVectorList_0_s
Line
Count
Source
1993
7.25k
  { \
1994
7.25k
    AArch64_add_cs_detail_2( \
1995
7.25k
      MI, \
1996
7.25k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
7.25k
              NumLanes), \
1998
7.25k
             LaneKind), \
1999
7.25k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
7.25k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
7.25k
    char Suffix[32]; \
2005
7.25k
    if (NumLanes) \
2006
7.25k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
7.25k
    else \
2009
7.25k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
7.25k
            CHAR(LaneKind)); \
2011
7.25k
\
2012
7.25k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
7.25k
  }
printTypedVectorList_0_q
Line
Count
Source
1993
238
  { \
1994
238
    AArch64_add_cs_detail_2( \
1995
238
      MI, \
1996
238
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
238
              NumLanes), \
1998
238
             LaneKind), \
1999
238
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
238
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
238
    char Suffix[32]; \
2005
238
    if (NumLanes) \
2006
238
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
0
            CHAR(LaneKind)); \
2008
238
    else \
2009
238
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
238
            CHAR(LaneKind)); \
2011
238
\
2012
238
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
238
  }
printTypedVectorList_16_b
Line
Count
Source
1993
1.82k
  { \
1994
1.82k
    AArch64_add_cs_detail_2( \
1995
1.82k
      MI, \
1996
1.82k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
1.82k
              NumLanes), \
1998
1.82k
             LaneKind), \
1999
1.82k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
1.82k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
1.82k
    char Suffix[32]; \
2005
1.82k
    if (NumLanes) \
2006
1.82k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
1.82k
            CHAR(LaneKind)); \
2008
1.82k
    else \
2009
1.82k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
1.82k
\
2012
1.82k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
1.82k
  }
printTypedVectorList_1_d
Line
Count
Source
1993
208
  { \
1994
208
    AArch64_add_cs_detail_2( \
1995
208
      MI, \
1996
208
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
208
              NumLanes), \
1998
208
             LaneKind), \
1999
208
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
208
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
208
    char Suffix[32]; \
2005
208
    if (NumLanes) \
2006
208
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
208
            CHAR(LaneKind)); \
2008
208
    else \
2009
208
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
208
\
2012
208
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
208
  }
printTypedVectorList_2_d
Line
Count
Source
1993
470
  { \
1994
470
    AArch64_add_cs_detail_2( \
1995
470
      MI, \
1996
470
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
470
              NumLanes), \
1998
470
             LaneKind), \
1999
470
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
470
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
470
    char Suffix[32]; \
2005
470
    if (NumLanes) \
2006
470
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
470
            CHAR(LaneKind)); \
2008
470
    else \
2009
470
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
470
\
2012
470
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
470
  }
printTypedVectorList_2_s
Line
Count
Source
1993
372
  { \
1994
372
    AArch64_add_cs_detail_2( \
1995
372
      MI, \
1996
372
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
372
              NumLanes), \
1998
372
             LaneKind), \
1999
372
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
372
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
372
    char Suffix[32]; \
2005
372
    if (NumLanes) \
2006
372
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
372
            CHAR(LaneKind)); \
2008
372
    else \
2009
372
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
372
\
2012
372
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
372
  }
printTypedVectorList_4_h
Line
Count
Source
1993
249
  { \
1994
249
    AArch64_add_cs_detail_2( \
1995
249
      MI, \
1996
249
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
249
              NumLanes), \
1998
249
             LaneKind), \
1999
249
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
249
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
249
    char Suffix[32]; \
2005
249
    if (NumLanes) \
2006
249
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
249
            CHAR(LaneKind)); \
2008
249
    else \
2009
249
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
249
\
2012
249
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
249
  }
printTypedVectorList_4_s
Line
Count
Source
1993
772
  { \
1994
772
    AArch64_add_cs_detail_2( \
1995
772
      MI, \
1996
772
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
772
              NumLanes), \
1998
772
             LaneKind), \
1999
772
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
772
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
772
    char Suffix[32]; \
2005
772
    if (NumLanes) \
2006
772
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
772
            CHAR(LaneKind)); \
2008
772
    else \
2009
772
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
772
\
2012
772
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
772
  }
printTypedVectorList_8_b
Line
Count
Source
1993
417
  { \
1994
417
    AArch64_add_cs_detail_2( \
1995
417
      MI, \
1996
417
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
417
              NumLanes), \
1998
417
             LaneKind), \
1999
417
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
417
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
417
    char Suffix[32]; \
2005
417
    if (NumLanes) \
2006
417
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
417
            CHAR(LaneKind)); \
2008
417
    else \
2009
417
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
417
\
2012
417
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
417
  }
printTypedVectorList_8_h
Line
Count
Source
1993
1.21k
  { \
1994
1.21k
    AArch64_add_cs_detail_2( \
1995
1.21k
      MI, \
1996
1.21k
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
1.21k
              NumLanes), \
1998
1.21k
             LaneKind), \
1999
1.21k
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
1.21k
    if (CHAR(LaneKind) == '0') { \
2001
0
      printVectorList(MI, OpNum, O, ""); \
2002
0
      return; \
2003
0
    } \
2004
1.21k
    char Suffix[32]; \
2005
1.21k
    if (NumLanes) \
2006
1.21k
      cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, \
2007
1.21k
            CHAR(LaneKind)); \
2008
1.21k
    else \
2009
1.21k
      cs_snprintf(Suffix, sizeof(Suffix), ".%c", \
2010
0
            CHAR(LaneKind)); \
2011
1.21k
\
2012
1.21k
    printVectorList(MI, OpNum, O, ((const char *)&Suffix)); \
2013
1.21k
  }
printTypedVectorList_0_0
Line
Count
Source
1993
52
  { \
1994
52
    AArch64_add_cs_detail_2( \
1995
52
      MI, \
1996
52
      CONCAT(CONCAT(AArch64_OP_GROUP_TypedVectorList, \
1997
52
              NumLanes), \
1998
52
             LaneKind), \
1999
52
      OpNum, NumLanes, CHAR(LaneKind)); \
2000
52
    if (CHAR(LaneKind) == '0') { \
2001
52
      printVectorList(MI, OpNum, O, ""); \
2002
52
      return; \
2003
52
    } \
2004
52
    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
20.9k
  { \
2033
20.9k
    AArch64_add_cs_detail_1( \
2034
20.9k
      MI, CONCAT(AArch64_OP_GROUP_VectorIndex, Scale), \
2035
20.9k
      OpNum, Scale); \
2036
20.9k
    SStream_concat(O, "%s", "["); \
2037
20.9k
    printUInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
2038
20.9k
                 MI, (OpNum)))); \
2039
20.9k
    SStream_concat0(O, "]"); \
2040
20.9k
  }
printVectorIndex_1
Line
Count
Source
2032
20.9k
  { \
2033
20.9k
    AArch64_add_cs_detail_1( \
2034
20.9k
      MI, CONCAT(AArch64_OP_GROUP_VectorIndex, Scale), \
2035
20.9k
      OpNum, Scale); \
2036
20.9k
    SStream_concat(O, "%s", "["); \
2037
20.9k
    printUInt64(O, Scale * MCOperand_getImm(MCInst_getOperand( \
2038
20.9k
                 MI, (OpNum)))); \
2039
20.9k
    SStream_concat0(O, "]"); \
2040
20.9k
  }
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
8.57k
{
2046
8.57k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AlignedLabel, OpNum);
2047
8.57k
  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
8.57k
  if (MCOperand_isImm(Op)) {
2052
8.43k
    SStream_concat0(O, markup("<imm:"));
2053
8.43k
    int64_t Offset = MCOperand_getImm(Op) * 4;
2054
8.43k
    if (MI->csh->PrintBranchImmAsAddress)
2055
8.43k
      printUInt64(O, (Address + Offset));
2056
0
    else {
2057
0
      printUInt64Bang(O, (Offset));
2058
0
    }
2059
8.43k
    SStream_concat0(O, markup(">"));
2060
8.43k
    return;
2061
8.43k
  }
2062
2063
136
  printUInt64Bang(O, MCOperand_getImm(Op));
2064
136
}
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
5.10k
{
2112
5.10k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_AdrAdrpLabel, OpNum);
2113
5.10k
  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
5.10k
  if (MCOperand_isImm(Op)) {
2118
5.10k
    int64_t Offset = MCOperand_getImm(Op);
2119
5.10k
    if (MCInst_getOpcode(MI) == AArch64_ADRP) {
2120
860
      Offset = Offset * 4096;
2121
860
      Address = Address & -4096;
2122
860
    }
2123
5.10k
    SStream_concat0(O, markup(">"));
2124
5.10k
    if (MI->csh->PrintBranchImmAsAddress)
2125
5.10k
      printUInt64(O, (Address + Offset));
2126
0
    else {
2127
0
      printUInt64Bang(O, Offset);
2128
0
    }
2129
5.10k
    SStream_concat0(O, markup(">"));
2130
5.10k
    return;
2131
5.10k
  }
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
18
  default:
2146
18
    SStream_concat0(O, "<undefined>");
2147
18
    break;
2148
0
  case 0:
2149
0
    SStream_concat0(O, "osh");
2150
0
    break;
2151
0
  case 1:
2152
0
    SStream_concat0(O, "nsh");
2153
0
    break;
2154
60
  case 2:
2155
60
    SStream_concat0(O, "ish");
2156
60
    break;
2157
1
  case 3:
2158
1
    SStream_concat0(O, "sy");
2159
1
    break;
2160
79
  }
2161
79
}
2162
2163
void printBarrierOption(MCInst *MI, unsigned OpNo, SStream *O)
2164
324
{
2165
324
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BarrierOption, OpNo);
2166
324
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2167
324
  unsigned Opcode = MCInst_getOpcode(MI);
2168
2169
324
  const char *Name;
2170
324
  if (Opcode == AArch64_ISB) {
2171
124
    const AArch64ISB_ISB *ISB = AArch64ISB_lookupISBByEncoding(Val);
2172
124
    Name = ISB ? ISB->Name : "";
2173
200
  } else if (Opcode == AArch64_TSB) {
2174
90
    const AArch64TSB_TSB *TSB = AArch64TSB_lookupTSBByEncoding(Val);
2175
90
    Name = TSB ? TSB->Name : "";
2176
110
  } else {
2177
110
    const AArch64DB_DB *DB = AArch64DB_lookupDBByEncoding(Val);
2178
110
    Name = DB ? DB->Name : "";
2179
110
  }
2180
324
  if (Name[0] != '\0')
2181
182
    SStream_concat0(O, Name);
2182
142
  else {
2183
142
    SStream_concat(O, "%s", markup("<imm:"));
2184
142
    printUInt32Bang(O, Val);
2185
142
    SStream_concat0(O, markup(">"));
2186
142
  }
2187
324
}
2188
2189
void printBarriernXSOption(MCInst *MI, unsigned OpNo, SStream *O)
2190
122
{
2191
122
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_BarriernXSOption, OpNo);
2192
122
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2193
2194
122
  const char *Name;
2195
122
  const AArch64DBnXS_DBnXS *DB = AArch64DBnXS_lookupDBnXSByEncoding(Val);
2196
122
  Name = DB ? DB->Name : "";
2197
2198
122
  if (Name[0] != '\0')
2199
122
    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
122
}
2205
2206
static bool isValidSysReg(const AArch64SysReg_SysReg *Reg, bool Read,
2207
        unsigned mode)
2208
3.39k
{
2209
3.39k
  return (Reg && (Read ? Reg->Readable : Reg->Writeable) &&
2210
338
    AArch64_testFeatureList(mode, Reg->FeaturesRequired));
2211
3.39k
}
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.94k
{
2222
2.94k
  const AArch64SysReg_SysReg *Reg =
2223
2.94k
    AArch64SysReg_lookupSysRegByEncoding(Val);
2224
2225
2.94k
  if (Reg && !isValidSysReg(Reg, Read, mode))
2226
275
    Reg = AArch64SysReg_lookupSysRegByName(Reg->AltName);
2227
2228
2.94k
  return Reg;
2229
2.94k
}
2230
2231
void printMRSSystemRegister(MCInst *MI, unsigned OpNo, SStream *O)
2232
1.18k
{
2233
1.18k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MRSSystemRegister, OpNo);
2234
1.18k
  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
1.18k
  if (Val == AARCH64_SYSREG_DBGDTRRX_EL0) {
2240
357
    SStream_concat0(O, "DBGDTRRX_EL0");
2241
357
    return;
2242
357
  }
2243
2244
  // Horrible hack for two different registers having the same encoding.
2245
831
  if (Val == AARCH64_SYSREG_TRCEXTINSELR) {
2246
26
    SStream_concat0(O, "TRCEXTINSELR");
2247
26
    return;
2248
26
  }
2249
2250
805
  const AArch64SysReg_SysReg *Reg =
2251
805
    lookupSysReg(Val, true /*Read*/, MI->csh->mode);
2252
2253
805
  if (isValidSysReg(Reg, true /*Read*/, MI->csh->mode))
2254
82
    SStream_concat0(O, Reg->Name);
2255
723
  else {
2256
723
    char result[AARCH64_GRS_LEN + 1] = { 0 };
2257
723
    AArch64SysReg_genericRegisterString(Val, result);
2258
723
    SStream_concat0(O, result);
2259
723
  }
2260
805
}
2261
2262
void printMSRSystemRegister(MCInst *MI, unsigned OpNo, SStream *O)
2263
2.33k
{
2264
2.33k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_MSRSystemRegister, OpNo);
2265
2.33k
  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.33k
  if (Val == AARCH64_SYSREG_DBGDTRTX_EL0) {
2271
139
    SStream_concat0(O, "DBGDTRTX_EL0");
2272
139
    return;
2273
139
  }
2274
2275
  // Horrible hack for two different registers having the same encoding.
2276
2.19k
  if (Val == AARCH64_SYSREG_TRCEXTINSELR) {
2277
50
    SStream_concat0(O, "TRCEXTINSELR");
2278
50
    return;
2279
50
  }
2280
2281
2.14k
  const AArch64SysReg_SysReg *Reg =
2282
2.14k
    lookupSysReg(Val, false /*Read*/, MI->csh->mode);
2283
2284
2.14k
  if (isValidSysReg(Reg, false /*Read*/, MI->csh->mode))
2285
87
    SStream_concat0(O, Reg->Name);
2286
2.05k
  else {
2287
2.05k
    char result[AARCH64_GRS_LEN + 1] = { 0 };
2288
2.05k
    AArch64SysReg_genericRegisterString(Val, result);
2289
2.05k
    SStream_concat0(O, result);
2290
2.05k
  }
2291
2.14k
}
2292
2293
void printSystemPStateField(MCInst *MI, unsigned OpNo, SStream *O)
2294
272
{
2295
272
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SystemPStateField, OpNo);
2296
272
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2297
2298
272
  const AArch64PState_PStateImm0_15 *PStateImm15 =
2299
272
    AArch64PState_lookupPStateImm0_15ByEncoding(Val);
2300
272
  const AArch64PState_PStateImm0_1 *PStateImm1 =
2301
272
    AArch64PState_lookupPStateImm0_1ByEncoding(Val);
2302
272
  if (PStateImm15 &&
2303
148
      AArch64_testFeatureList(MI->csh->mode,
2304
148
            PStateImm15->FeaturesRequired))
2305
148
    SStream_concat0(O, PStateImm15->Name);
2306
124
  else if (PStateImm1 &&
2307
124
     AArch64_testFeatureList(MI->csh->mode,
2308
124
           PStateImm1->FeaturesRequired))
2309
124
    SStream_concat0(O, PStateImm1->Name);
2310
0
  else {
2311
0
    printUInt32Bang(O, (Val));
2312
0
    SStream_concat1(O, '\0');
2313
0
  }
2314
272
}
2315
2316
void printSIMDType10Operand(MCInst *MI, unsigned OpNo, SStream *O)
2317
567
{
2318
567
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SIMDType10Operand, OpNo);
2319
567
  unsigned RawVal = MCOperand_getImm(MCInst_getOperand(MI, (OpNo)));
2320
567
  uint64_t Val = AArch64_AM_decodeAdvSIMDModImmType10(RawVal);
2321
567
  SStream_concat(O, "%s#%#016llx", markup("<imm:"), Val);
2322
567
  SStream_concat0(O, markup(">"));
2323
567
}
2324
2325
#define DEFINE_printComplexRotationOp(Angle, Remainder) \
2326
  static void CONCAT(printComplexRotationOp, CONCAT(Angle, Remainder))( \
2327
    MCInst * MI, unsigned OpNo, SStream *O) \
2328
2.12k
  { \
2329
2.12k
    AArch64_add_cs_detail_2( \
2330
2.12k
      MI, \
2331
2.12k
      CONCAT(CONCAT(AArch64_OP_GROUP_ComplexRotationOp, \
2332
2.12k
              Angle), \
2333
2.12k
             Remainder), \
2334
2.12k
      OpNo, Angle, Remainder); \
2335
2.12k
    unsigned Val = \
2336
2.12k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
2337
2.12k
    SStream_concat(O, "%s", markup("<imm:")); \
2338
2.12k
    SStream_concat(O, "#%" PRId32, \
2339
2.12k
             (int32_t)((Val * Angle) + Remainder)); \
2340
2.12k
    SStream_concat0(O, markup(">")); \
2341
2.12k
  }
2342
251
DEFINE_printComplexRotationOp(180, 90);
2343
1.87k
DEFINE_printComplexRotationOp(90, 0);
2344
2345
void printSVEPattern(MCInst *MI, unsigned OpNum, SStream *O)
2346
2.12k
{
2347
2.12k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SVEPattern, OpNum);
2348
2.12k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
2349
2.12k
  const AArch64SVEPredPattern_SVEPREDPAT *Pat =
2350
2.12k
    AArch64SVEPredPattern_lookupSVEPREDPATByEncoding(Val);
2351
2.12k
  if (Pat)
2352
1.28k
    SStream_concat0(O, Pat->Name);
2353
840
  else
2354
840
    printUInt32Bang(O, Val);
2355
2.12k
}
2356
2357
void printSVEVecLenSpecifier(MCInst *MI, unsigned OpNum, SStream *O)
2358
434
{
2359
434
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SVEVecLenSpecifier, OpNum);
2360
434
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
2361
  // Pattern has only 1 bit
2362
434
  if (Val > 1)
2363
0
    CS_ASSERT_RET(0 && "Invalid vector length specifier");
2364
434
  const AArch64SVEVecLenSpecifier_SVEVECLENSPECIFIER *Pat =
2365
434
    AArch64SVEVecLenSpecifier_lookupSVEVECLENSPECIFIERByEncoding(
2366
434
      Val);
2367
434
  if (Pat)
2368
434
    SStream_concat0(O, Pat->Name);
2369
434
}
2370
2371
#define DEFINE_printSVERegOp(suffix) \
2372
  void CONCAT(printSVERegOp, suffix)(MCInst * MI, unsigned OpNum, \
2373
             SStream *O) \
2374
96.0k
  { \
2375
96.0k
    AArch64_add_cs_detail_1( \
2376
96.0k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
96.0k
      CHAR(suffix)); \
2378
96.0k
    switch (CHAR(suffix)) { \
2379
29.1k
    case '0': \
2380
46.3k
    case 'b': \
2381
67.7k
    case 'h': \
2382
81.2k
    case 's': \
2383
95.6k
    case 'd': \
2384
96.0k
    case 'q': \
2385
96.0k
      break; \
2386
95.6k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
96.0k
    } \
2389
96.0k
\
2390
96.0k
    unsigned Reg = \
2391
96.0k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
96.0k
    printRegName(O, Reg); \
2393
96.0k
    if (CHAR(suffix) != '0') { \
2394
66.9k
      SStream_concat1(O, '.'); \
2395
66.9k
      SStream_concat1(O, CHAR(suffix)); \
2396
66.9k
    } \
2397
96.0k
  }
printSVERegOp_b
Line
Count
Source
2374
17.1k
  { \
2375
17.1k
    AArch64_add_cs_detail_1( \
2376
17.1k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
17.1k
      CHAR(suffix)); \
2378
17.1k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
17.1k
    case 'b': \
2381
17.1k
    case 'h': \
2382
17.1k
    case 's': \
2383
17.1k
    case 'd': \
2384
17.1k
    case 'q': \
2385
17.1k
      break; \
2386
17.1k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
17.1k
    } \
2389
17.1k
\
2390
17.1k
    unsigned Reg = \
2391
17.1k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
17.1k
    printRegName(O, Reg); \
2393
17.1k
    if (CHAR(suffix) != '0') { \
2394
17.1k
      SStream_concat1(O, '.'); \
2395
17.1k
      SStream_concat1(O, CHAR(suffix)); \
2396
17.1k
    } \
2397
17.1k
  }
printSVERegOp_d
Line
Count
Source
2374
14.3k
  { \
2375
14.3k
    AArch64_add_cs_detail_1( \
2376
14.3k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
14.3k
      CHAR(suffix)); \
2378
14.3k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
0
    case 'h': \
2382
0
    case 's': \
2383
14.3k
    case 'd': \
2384
14.3k
    case 'q': \
2385
14.3k
      break; \
2386
14.3k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
14.3k
    } \
2389
14.3k
\
2390
14.3k
    unsigned Reg = \
2391
14.3k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
14.3k
    printRegName(O, Reg); \
2393
14.3k
    if (CHAR(suffix) != '0') { \
2394
14.3k
      SStream_concat1(O, '.'); \
2395
14.3k
      SStream_concat1(O, CHAR(suffix)); \
2396
14.3k
    } \
2397
14.3k
  }
printSVERegOp_h
Line
Count
Source
2374
21.3k
  { \
2375
21.3k
    AArch64_add_cs_detail_1( \
2376
21.3k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
21.3k
      CHAR(suffix)); \
2378
21.3k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
21.3k
    case 'h': \
2382
21.3k
    case 's': \
2383
21.3k
    case 'd': \
2384
21.3k
    case 'q': \
2385
21.3k
      break; \
2386
21.3k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
21.3k
    } \
2389
21.3k
\
2390
21.3k
    unsigned Reg = \
2391
21.3k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
21.3k
    printRegName(O, Reg); \
2393
21.3k
    if (CHAR(suffix) != '0') { \
2394
21.3k
      SStream_concat1(O, '.'); \
2395
21.3k
      SStream_concat1(O, CHAR(suffix)); \
2396
21.3k
    } \
2397
21.3k
  }
printSVERegOp_s
Line
Count
Source
2374
13.5k
  { \
2375
13.5k
    AArch64_add_cs_detail_1( \
2376
13.5k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
13.5k
      CHAR(suffix)); \
2378
13.5k
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
0
    case 'h': \
2382
13.5k
    case 's': \
2383
13.5k
    case 'd': \
2384
13.5k
    case 'q': \
2385
13.5k
      break; \
2386
13.5k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
13.5k
    } \
2389
13.5k
\
2390
13.5k
    unsigned Reg = \
2391
13.5k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
13.5k
    printRegName(O, Reg); \
2393
13.5k
    if (CHAR(suffix) != '0') { \
2394
13.5k
      SStream_concat1(O, '.'); \
2395
13.5k
      SStream_concat1(O, CHAR(suffix)); \
2396
13.5k
    } \
2397
13.5k
  }
printSVERegOp_0
Line
Count
Source
2374
29.1k
  { \
2375
29.1k
    AArch64_add_cs_detail_1( \
2376
29.1k
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
29.1k
      CHAR(suffix)); \
2378
29.1k
    switch (CHAR(suffix)) { \
2379
29.1k
    case '0': \
2380
29.1k
    case 'b': \
2381
29.1k
    case 'h': \
2382
29.1k
    case 's': \
2383
29.1k
    case 'd': \
2384
29.1k
    case 'q': \
2385
29.1k
      break; \
2386
29.1k
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
29.1k
    } \
2389
29.1k
\
2390
29.1k
    unsigned Reg = \
2391
29.1k
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
29.1k
    printRegName(O, Reg); \
2393
29.1k
    if (CHAR(suffix) != '0') { \
2394
0
      SStream_concat1(O, '.'); \
2395
0
      SStream_concat1(O, CHAR(suffix)); \
2396
0
    } \
2397
29.1k
  }
printSVERegOp_q
Line
Count
Source
2374
401
  { \
2375
401
    AArch64_add_cs_detail_1( \
2376
401
      MI, CONCAT(AArch64_OP_GROUP_SVERegOp, suffix), OpNum, \
2377
401
      CHAR(suffix)); \
2378
401
    switch (CHAR(suffix)) { \
2379
0
    case '0': \
2380
0
    case 'b': \
2381
0
    case 'h': \
2382
0
    case 's': \
2383
0
    case 'd': \
2384
401
    case 'q': \
2385
401
      break; \
2386
0
    default: \
2387
0
      CS_ASSERT_RET(0 && "Invalid kind specifier."); \
2388
401
    } \
2389
401
\
2390
401
    unsigned Reg = \
2391
401
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2392
401
    printRegName(O, Reg); \
2393
401
    if (CHAR(suffix) != '0') { \
2394
401
      SStream_concat1(O, '.'); \
2395
401
      SStream_concat1(O, CHAR(suffix)); \
2396
401
    } \
2397
401
  }
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.89k
  { \
2408
1.89k
    printInt32Bang(O, Val); \
2409
1.89k
  }
printImmSVE_int16_t
Line
Count
Source
2407
1.08k
  { \
2408
1.08k
    printInt32Bang(O, Val); \
2409
1.08k
  }
printImmSVE_int8_t
Line
Count
Source
2407
137
  { \
2408
137
    printInt32Bang(O, Val); \
2409
137
  }
printImmSVE_int32_t
Line
Count
Source
2407
677
  { \
2408
677
    printInt32Bang(O, Val); \
2409
677
  }
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
204
  { \
2417
204
    printUInt32Bang(O, Val); \
2418
204
  }
printImmSVE_uint16_t
Line
Count
Source
2416
104
  { \
2417
104
    printUInt32Bang(O, Val); \
2418
104
  }
printImmSVE_uint8_t
Line
Count
Source
2416
32
  { \
2417
32
    printUInt32Bang(O, Val); \
2418
32
  }
printImmSVE_uint32_t
Line
Count
Source
2416
68
  { \
2417
68
    printUInt32Bang(O, Val); \
2418
68
  }
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
661
  { \
2426
661
    printInt64Bang(O, Val); \
2427
661
  }
2428
DECLARE_printImmSVE_S64(int64_t);
2429
2430
#define DECLARE_printImmSVE_U64(T) \
2431
  void CONCAT(printImmSVE, T)(T Val, SStream * O) \
2432
454
  { \
2433
454
    printUInt64Bang(O, Val); \
2434
454
  }
2435
DECLARE_printImmSVE_U64(uint64_t);
2436
2437
#define DEFINE_isSignedType(T) \
2438
  static inline bool CONCAT(isSignedType, T)() \
2439
1.29k
  { \
2440
1.29k
    return CHAR(T) == 'i'; \
2441
1.29k
  }
AArch64InstPrinter.c:isSignedType_int16_t
Line
Count
Source
2439
173
  { \
2440
173
    return CHAR(T) == 'i'; \
2441
173
  }
AArch64InstPrinter.c:isSignedType_int8_t
Line
Count
Source
2439
137
  { \
2440
137
    return CHAR(T) == 'i'; \
2441
137
  }
AArch64InstPrinter.c:isSignedType_int64_t
Line
Count
Source
2439
168
  { \
2440
168
    return CHAR(T) == 'i'; \
2441
168
  }
AArch64InstPrinter.c:isSignedType_int32_t
Line
Count
Source
2439
163
  { \
2440
163
    return CHAR(T) == 'i'; \
2441
163
  }
AArch64InstPrinter.c:isSignedType_uint16_t
Line
Count
Source
2439
104
  { \
2440
104
    return CHAR(T) == 'i'; \
2441
104
  }
AArch64InstPrinter.c:isSignedType_uint8_t
Line
Count
Source
2439
32
  { \
2440
32
    return CHAR(T) == 'i'; \
2441
32
  }
AArch64InstPrinter.c:isSignedType_uint64_t
Line
Count
Source
2439
454
  { \
2440
454
    return CHAR(T) == 'i'; \
2441
454
  }
AArch64InstPrinter.c:isSignedType_uint32_t
Line
Count
Source
2439
68
  { \
2440
68
    return CHAR(T) == 'i'; \
2441
68
  }
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.67k
  { \
2455
1.67k
    AArch64_add_cs_detail_1( \
2456
1.67k
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
1.67k
      sizeof(T)); \
2458
1.67k
    unsigned UnscaledVal = \
2459
1.67k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
1.67k
    unsigned Shift = \
2461
1.67k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
1.67k
\
2463
1.67k
    if ((UnscaledVal == 0) && \
2464
1.67k
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
373
      SStream_concat(O, "%s", markup("<imm:")); \
2466
373
      SStream_concat1(O, '#'); \
2467
373
      printUInt64(O, (UnscaledVal)); \
2468
373
      SStream_concat0(O, markup(">")); \
2469
373
      printShifter(MI, OpNum + 1, O); \
2470
373
      return; \
2471
373
    } \
2472
1.67k
\
2473
1.67k
    T Val; \
2474
1.29k
    if (CONCAT(isSignedType, T)()) \
2475
1.29k
      Val = (int8_t)UnscaledVal * \
2476
641
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
1.29k
    else \
2478
1.29k
      Val = (uint8_t)UnscaledVal * \
2479
658
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
1.29k
\
2481
1.29k
    CONCAT(printImmSVE, T)(Val, O); \
2482
1.29k
  }
printImm8OptLsl_int16_t
Line
Count
Source
2454
199
  { \
2455
199
    AArch64_add_cs_detail_1( \
2456
199
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
199
      sizeof(T)); \
2458
199
    unsigned UnscaledVal = \
2459
199
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
199
    unsigned Shift = \
2461
199
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
199
\
2463
199
    if ((UnscaledVal == 0) && \
2464
199
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
26
      SStream_concat(O, "%s", markup("<imm:")); \
2466
26
      SStream_concat1(O, '#'); \
2467
26
      printUInt64(O, (UnscaledVal)); \
2468
26
      SStream_concat0(O, markup(">")); \
2469
26
      printShifter(MI, OpNum + 1, O); \
2470
26
      return; \
2471
26
    } \
2472
199
\
2473
199
    T Val; \
2474
173
    if (CONCAT(isSignedType, T)()) \
2475
173
      Val = (int8_t)UnscaledVal * \
2476
173
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
173
    else \
2478
173
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
173
\
2481
173
    CONCAT(printImmSVE, T)(Val, O); \
2482
173
  }
printImm8OptLsl_int8_t
Line
Count
Source
2454
137
  { \
2455
137
    AArch64_add_cs_detail_1( \
2456
137
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
137
      sizeof(T)); \
2458
137
    unsigned UnscaledVal = \
2459
137
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
137
    unsigned Shift = \
2461
137
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
137
\
2463
137
    if ((UnscaledVal == 0) && \
2464
137
        (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
137
\
2473
137
    T Val; \
2474
137
    if (CONCAT(isSignedType, T)()) \
2475
137
      Val = (int8_t)UnscaledVal * \
2476
137
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
137
    else \
2478
137
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
137
\
2481
137
    CONCAT(printImmSVE, T)(Val, O); \
2482
137
  }
printImm8OptLsl_int64_t
Line
Count
Source
2454
232
  { \
2455
232
    AArch64_add_cs_detail_1( \
2456
232
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
232
      sizeof(T)); \
2458
232
    unsigned UnscaledVal = \
2459
232
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
232
    unsigned Shift = \
2461
232
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
232
\
2463
232
    if ((UnscaledVal == 0) && \
2464
232
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
64
      SStream_concat(O, "%s", markup("<imm:")); \
2466
64
      SStream_concat1(O, '#'); \
2467
64
      printUInt64(O, (UnscaledVal)); \
2468
64
      SStream_concat0(O, markup(">")); \
2469
64
      printShifter(MI, OpNum + 1, O); \
2470
64
      return; \
2471
64
    } \
2472
232
\
2473
232
    T Val; \
2474
168
    if (CONCAT(isSignedType, T)()) \
2475
168
      Val = (int8_t)UnscaledVal * \
2476
168
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
168
    else \
2478
168
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
168
\
2481
168
    CONCAT(printImmSVE, T)(Val, O); \
2482
168
  }
printImm8OptLsl_int32_t
Line
Count
Source
2454
207
  { \
2455
207
    AArch64_add_cs_detail_1( \
2456
207
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
207
      sizeof(T)); \
2458
207
    unsigned UnscaledVal = \
2459
207
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
207
    unsigned Shift = \
2461
207
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
207
\
2463
207
    if ((UnscaledVal == 0) && \
2464
207
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
44
      SStream_concat(O, "%s", markup("<imm:")); \
2466
44
      SStream_concat1(O, '#'); \
2467
44
      printUInt64(O, (UnscaledVal)); \
2468
44
      SStream_concat0(O, markup(">")); \
2469
44
      printShifter(MI, OpNum + 1, O); \
2470
44
      return; \
2471
44
    } \
2472
207
\
2473
207
    T Val; \
2474
163
    if (CONCAT(isSignedType, T)()) \
2475
163
      Val = (int8_t)UnscaledVal * \
2476
163
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
163
    else \
2478
163
      Val = (uint8_t)UnscaledVal * \
2479
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
163
\
2481
163
    CONCAT(printImmSVE, T)(Val, O); \
2482
163
  }
printImm8OptLsl_uint16_t
Line
Count
Source
2454
144
  { \
2455
144
    AArch64_add_cs_detail_1( \
2456
144
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
144
      sizeof(T)); \
2458
144
    unsigned UnscaledVal = \
2459
144
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
144
    unsigned Shift = \
2461
144
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
144
\
2463
144
    if ((UnscaledVal == 0) && \
2464
144
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
40
      SStream_concat(O, "%s", markup("<imm:")); \
2466
40
      SStream_concat1(O, '#'); \
2467
40
      printUInt64(O, (UnscaledVal)); \
2468
40
      SStream_concat0(O, markup(">")); \
2469
40
      printShifter(MI, OpNum + 1, O); \
2470
40
      return; \
2471
40
    } \
2472
144
\
2473
144
    T Val; \
2474
104
    if (CONCAT(isSignedType, T)()) \
2475
104
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
104
    else \
2478
104
      Val = (uint8_t)UnscaledVal * \
2479
104
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
104
\
2481
104
    CONCAT(printImmSVE, T)(Val, O); \
2482
104
  }
printImm8OptLsl_uint8_t
Line
Count
Source
2454
32
  { \
2455
32
    AArch64_add_cs_detail_1( \
2456
32
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
32
      sizeof(T)); \
2458
32
    unsigned UnscaledVal = \
2459
32
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
32
    unsigned Shift = \
2461
32
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
32
\
2463
32
    if ((UnscaledVal == 0) && \
2464
32
        (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
32
\
2473
32
    T Val; \
2474
32
    if (CONCAT(isSignedType, T)()) \
2475
32
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
32
    else \
2478
32
      Val = (uint8_t)UnscaledVal * \
2479
32
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
32
\
2481
32
    CONCAT(printImmSVE, T)(Val, O); \
2482
32
  }
printImm8OptLsl_uint64_t
Line
Count
Source
2454
635
  { \
2455
635
    AArch64_add_cs_detail_1( \
2456
635
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
635
      sizeof(T)); \
2458
635
    unsigned UnscaledVal = \
2459
635
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
635
    unsigned Shift = \
2461
635
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
635
\
2463
635
    if ((UnscaledVal == 0) && \
2464
635
        (AArch64_AM_getShiftValue(Shift) != 0)) { \
2465
181
      SStream_concat(O, "%s", markup("<imm:")); \
2466
181
      SStream_concat1(O, '#'); \
2467
181
      printUInt64(O, (UnscaledVal)); \
2468
181
      SStream_concat0(O, markup(">")); \
2469
181
      printShifter(MI, OpNum + 1, O); \
2470
181
      return; \
2471
181
    } \
2472
635
\
2473
635
    T Val; \
2474
454
    if (CONCAT(isSignedType, T)()) \
2475
454
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
454
    else \
2478
454
      Val = (uint8_t)UnscaledVal * \
2479
454
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
454
\
2481
454
    CONCAT(printImmSVE, T)(Val, O); \
2482
454
  }
printImm8OptLsl_uint32_t
Line
Count
Source
2454
86
  { \
2455
86
    AArch64_add_cs_detail_1( \
2456
86
      MI, CONCAT(AArch64_OP_GROUP_Imm8OptLsl, T), OpNum, \
2457
86
      sizeof(T)); \
2458
86
    unsigned UnscaledVal = \
2459
86
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2460
86
    unsigned Shift = \
2461
86
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum + 1))); \
2462
86
\
2463
86
    if ((UnscaledVal == 0) && \
2464
86
        (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
86
\
2473
86
    T Val; \
2474
68
    if (CONCAT(isSignedType, T)()) \
2475
68
      Val = (int8_t)UnscaledVal * \
2476
0
            (1 << AArch64_AM_getShiftValue(Shift)); \
2477
68
    else \
2478
68
      Val = (uint8_t)UnscaledVal * \
2479
68
            (1 << AArch64_AM_getShiftValue(Shift)); \
2480
68
\
2481
68
    CONCAT(printImmSVE, T)(Val, O); \
2482
68
  }
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
2.31k
  { \
2496
2.31k
    AArch64_add_cs_detail_1( \
2497
2.31k
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
2.31k
      sizeof(T)); \
2499
2.31k
    typedef T SignedT; \
2500
2.31k
    typedef CONCATS(u, T) UnsignedT; \
2501
2.31k
\
2502
2.31k
    uint64_t Val = \
2503
2.31k
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
2.31k
    UnsignedT PrintVal = \
2505
2.31k
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
2.31k
\
2507
2.31k
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
2.31k
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
2.31k
    else if ((uint16_t)PrintVal == PrintVal) \
2510
768
      CONCAT(printImmSVE, T)(PrintVal, O); \
2511
768
    else { \
2512
394
      SStream_concat(O, "%s", markup("<imm:")); \
2513
394
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2514
394
      SStream_concat0(O, markup(">")); \
2515
394
    } \
2516
2.31k
  }
printSVELogicalImm_int16_t
Line
Count
Source
2495
910
  { \
2496
910
    AArch64_add_cs_detail_1( \
2497
910
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
910
      sizeof(T)); \
2499
910
    typedef T SignedT; \
2500
910
    typedef CONCATS(u, T) UnsignedT; \
2501
910
\
2502
910
    uint64_t Val = \
2503
910
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
910
    UnsignedT PrintVal = \
2505
910
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
910
\
2507
910
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
910
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
910
    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
910
  }
printSVELogicalImm_int32_t
Line
Count
Source
2495
632
  { \
2496
632
    AArch64_add_cs_detail_1( \
2497
632
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
632
      sizeof(T)); \
2499
632
    typedef T SignedT; \
2500
632
    typedef CONCATS(u, T) UnsignedT; \
2501
632
\
2502
632
    uint64_t Val = \
2503
632
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
632
    UnsignedT PrintVal = \
2505
632
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
632
\
2507
632
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
632
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
632
    else if ((uint16_t)PrintVal == PrintVal) \
2510
124
      CONCAT(printImmSVE, T)(PrintVal, O); \
2511
124
    else { \
2512
118
      SStream_concat(O, "%s", markup("<imm:")); \
2513
118
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2514
118
      SStream_concat0(O, markup(">")); \
2515
118
    } \
2516
632
  }
printSVELogicalImm_int64_t
Line
Count
Source
2495
769
  { \
2496
769
    AArch64_add_cs_detail_1( \
2497
769
      MI, CONCAT(AArch64_OP_GROUP_SVELogicalImm, T), OpNum, \
2498
769
      sizeof(T)); \
2499
769
    typedef T SignedT; \
2500
769
    typedef CONCATS(u, T) UnsignedT; \
2501
769
\
2502
769
    uint64_t Val = \
2503
769
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2504
769
    UnsignedT PrintVal = \
2505
769
      AArch64_AM_decodeLogicalImmediate(Val, 64); \
2506
769
\
2507
769
    if ((int16_t)PrintVal == (SignedT)PrintVal) \
2508
769
      CONCAT(printImmSVE, T)((T)PrintVal, O); \
2509
769
    else if ((uint16_t)PrintVal == PrintVal) \
2510
644
      CONCAT(printImmSVE, T)(PrintVal, O); \
2511
644
    else { \
2512
276
      SStream_concat(O, "%s", markup("<imm:")); \
2513
276
      printUInt64Bang(O, ((uint64_t)PrintVal)); \
2514
276
      SStream_concat0(O, markup(">")); \
2515
276
    } \
2516
769
  }
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
836
  { \
2525
836
    AArch64_add_cs_detail_1( \
2526
836
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
836
      Width); \
2528
836
    unsigned Base; \
2529
836
    switch (Width) { \
2530
92
    case 8: \
2531
92
      Base = AArch64_B0; \
2532
92
      break; \
2533
128
    case 16: \
2534
128
      Base = AArch64_H0; \
2535
128
      break; \
2536
296
    case 32: \
2537
296
      Base = AArch64_S0; \
2538
296
      break; \
2539
311
    case 64: \
2540
311
      Base = AArch64_D0; \
2541
311
      break; \
2542
9
    case 128: \
2543
9
      Base = AArch64_Q0; \
2544
9
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
836
    } \
2548
836
    unsigned Reg = \
2549
836
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
836
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
836
  }
printZPRasFPR_8
Line
Count
Source
2524
92
  { \
2525
92
    AArch64_add_cs_detail_1( \
2526
92
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
92
      Width); \
2528
92
    unsigned Base; \
2529
92
    switch (Width) { \
2530
92
    case 8: \
2531
92
      Base = AArch64_B0; \
2532
92
      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
92
    } \
2548
92
    unsigned Reg = \
2549
92
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
92
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
92
  }
printZPRasFPR_64
Line
Count
Source
2524
311
  { \
2525
311
    AArch64_add_cs_detail_1( \
2526
311
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
311
      Width); \
2528
311
    unsigned Base; \
2529
311
    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
311
    case 64: \
2540
311
      Base = AArch64_D0; \
2541
311
      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
311
    } \
2548
311
    unsigned Reg = \
2549
311
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
311
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
311
  }
printZPRasFPR_16
Line
Count
Source
2524
128
  { \
2525
128
    AArch64_add_cs_detail_1( \
2526
128
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
128
      Width); \
2528
128
    unsigned Base; \
2529
128
    switch (Width) { \
2530
0
    case 8: \
2531
0
      Base = AArch64_B0; \
2532
0
      break; \
2533
128
    case 16: \
2534
128
      Base = AArch64_H0; \
2535
128
      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
128
    } \
2548
128
    unsigned Reg = \
2549
128
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
128
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
128
  }
printZPRasFPR_32
Line
Count
Source
2524
296
  { \
2525
296
    AArch64_add_cs_detail_1( \
2526
296
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
296
      Width); \
2528
296
    unsigned Base; \
2529
296
    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
296
    case 32: \
2537
296
      Base = AArch64_S0; \
2538
296
      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
296
    } \
2548
296
    unsigned Reg = \
2549
296
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
296
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
296
  }
printZPRasFPR_128
Line
Count
Source
2524
9
  { \
2525
9
    AArch64_add_cs_detail_1( \
2526
9
      MI, CONCAT(AArch64_OP_GROUP_ZPRasFPR, Width), OpNum, \
2527
9
      Width); \
2528
9
    unsigned Base; \
2529
9
    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
9
    case 128: \
2543
9
      Base = AArch64_Q0; \
2544
9
      break; \
2545
0
    default: \
2546
0
      CS_ASSERT_RET(0 && "Unsupported width"); \
2547
9
    } \
2548
9
    unsigned Reg = \
2549
9
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
2550
9
    printRegName(O, Reg - AArch64_Z0 + Base); \
2551
9
  }
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
356
  { \
2562
356
    AArch64_add_cs_detail_2( \
2563
356
      MI, \
2564
356
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
356
             ImmIs1), \
2566
356
      OpNum, ImmIs0, ImmIs1); \
2567
356
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
356
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
356
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
356
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
356
    unsigned Val = \
2572
356
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
356
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
356
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
356
    SStream_concat0(O, markup(">")); \
2576
356
  }
printExactFPImm_AArch64ExactFPImm_half_AArch64ExactFPImm_one
Line
Count
Source
2561
98
  { \
2562
98
    AArch64_add_cs_detail_2( \
2563
98
      MI, \
2564
98
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
98
             ImmIs1), \
2566
98
      OpNum, ImmIs0, ImmIs1); \
2567
98
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
98
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
98
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
98
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
98
    unsigned Val = \
2572
98
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
98
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
98
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
98
    SStream_concat0(O, markup(">")); \
2576
98
  }
printExactFPImm_AArch64ExactFPImm_zero_AArch64ExactFPImm_one
Line
Count
Source
2561
159
  { \
2562
159
    AArch64_add_cs_detail_2( \
2563
159
      MI, \
2564
159
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
159
             ImmIs1), \
2566
159
      OpNum, ImmIs0, ImmIs1); \
2567
159
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
159
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
159
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
159
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
159
    unsigned Val = \
2572
159
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
159
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
159
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
159
    SStream_concat0(O, markup(">")); \
2576
159
  }
printExactFPImm_AArch64ExactFPImm_half_AArch64ExactFPImm_two
Line
Count
Source
2561
99
  { \
2562
99
    AArch64_add_cs_detail_2( \
2563
99
      MI, \
2564
99
      CONCAT(CONCAT(AArch64_OP_GROUP_ExactFPImm, ImmIs0), \
2565
99
             ImmIs1), \
2566
99
      OpNum, ImmIs0, ImmIs1); \
2567
99
    const AArch64ExactFPImm_ExactFPImm *Imm0Desc = \
2568
99
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs0); \
2569
99
    const AArch64ExactFPImm_ExactFPImm *Imm1Desc = \
2570
99
      AArch64ExactFPImm_lookupExactFPImmByEnum(ImmIs1); \
2571
99
    unsigned Val = \
2572
99
      MCOperand_getImm(MCInst_getOperand(MI, (OpNum))); \
2573
99
    SStream_concat(O, "%s%s%s", markup("<imm:"), "#", \
2574
99
             (Val ? Imm1Desc->Repr : Imm0Desc->Repr)); \
2575
99
    SStream_concat0(O, markup(">")); \
2576
99
  }
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
1.94k
{
2583
1.94k
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_GPR64as32, OpNum);
2584
1.94k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2585
1.94k
  printRegName(O, getWRegFromXReg(Reg));
2586
1.94k
}
2587
2588
void printGPR64x8(MCInst *MI, unsigned OpNum, SStream *O)
2589
43
{
2590
43
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_GPR64x8, OpNum);
2591
43
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2592
43
  printRegName(O,
2593
43
         MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_x8sub_0));
2594
43
}
2595
2596
void printSyspXzrPair(MCInst *MI, unsigned OpNum, SStream *O)
2597
437
{
2598
437
  AArch64_add_cs_detail_0(MI, AArch64_OP_GROUP_SyspXzrPair, OpNum);
2599
437
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
2600
2601
437
  SStream_concat(O, "%s%s", getRegisterName(Reg, AArch64_NoRegAltName),
2602
437
           ", ");
2603
437
  SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
2604
437
}
2605
2606
const char *AArch64_LLVM_getRegisterName(unsigned RegNo, unsigned AltIdx)
2607
105k
{
2608
105k
  return getRegisterName(RegNo, AltIdx);
2609
105k
}
2610
2611
void AArch64_LLVM_printInstruction(MCInst *MI, SStream *O,
2612
           void * /* MCRegisterInfo* */ info)
2613
186k
{
2614
186k
  printInst(MI, MI->address, "", O);
2615
186k
}