Coverage Report

Created: 2026-11-21 09:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/opcodes/aarch64-opc.c
Line
Count
Source
1
/* aarch64-opc.c -- AArch64 opcode support.
2
   Copyright (C) 2009-2026 Free Software Foundation, Inc.
3
   Contributed by ARM Ltd.
4
5
   This file is part of the GNU opcodes library.
6
7
   This library is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   It is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; see the file COPYING3. If not,
19
   see <http://www.gnu.org/licenses/>.  */
20
21
#include "sysdep.h"
22
#include <assert.h>
23
#include <stdlib.h>
24
#include <stdio.h>
25
#include <stdint.h>
26
#include <stdarg.h>
27
#include <inttypes.h>
28
29
#include "opintl.h"
30
#include "libiberty.h"
31
32
#include "aarch64-opc.h"
33
34
#ifdef DEBUG_AARCH64
35
int debug_dump = false;
36
#endif /* DEBUG_AARCH64 */
37
38
/* The enumeration strings associated with each value of a 5-bit SVE
39
   pattern operand.  A null entry indicates a reserved meaning.  */
40
const char *const aarch64_sve_pattern_array[32] = {
41
  /* 0-7.  */
42
  "pow2",
43
  "vl1",
44
  "vl2",
45
  "vl3",
46
  "vl4",
47
  "vl5",
48
  "vl6",
49
  "vl7",
50
  /* 8-15.  */
51
  "vl8",
52
  "vl16",
53
  "vl32",
54
  "vl64",
55
  "vl128",
56
  "vl256",
57
  0,
58
  0,
59
  /* 16-23.  */
60
  0,
61
  0,
62
  0,
63
  0,
64
  0,
65
  0,
66
  0,
67
  0,
68
  /* 24-31.  */
69
  0,
70
  0,
71
  0,
72
  0,
73
  0,
74
  "mul4",
75
  "mul3",
76
  "all"
77
};
78
79
/* The enumeration strings associated with each value of a 4-bit SVE
80
   prefetch operand.  A null entry indicates a reserved meaning.  */
81
const char *const aarch64_sve_prfop_array[16] = {
82
  /* 0-7.  */
83
  "pldl1keep",
84
  "pldl1strm",
85
  "pldl2keep",
86
  "pldl2strm",
87
  "pldl3keep",
88
  "pldl3strm",
89
  0,
90
  0,
91
  /* 8-15.  */
92
  "pstl1keep",
93
  "pstl1strm",
94
  "pstl2keep",
95
  "pstl2strm",
96
  "pstl3keep",
97
  "pstl3strm",
98
  0,
99
  0
100
};
101
102
/* The enumeration strings associated with each value of a 6-bit RPRFM
103
   operation.  */
104
const char *const aarch64_rprfmop_array[64] = {
105
  "pldkeep",
106
  "pstkeep",
107
  0,
108
  0,
109
  "pldstrm",
110
  "pststrm"
111
};
112
113
/* Vector length multiples for a predicate-as-counter operand.  Used in things
114
   like AARCH64_OPND_SME_VLxN_10.  */
115
const char *const aarch64_sme_vlxn_array[2] = {
116
  "vlx2",
117
  "vlx4"
118
};
119
120
/* Values accepted by the brb alias.  */
121
const char *const aarch64_brbop_array[] = {
122
  "iall",
123
  "inj",
124
};
125
126
/* Helper functions to determine which operand to be used to encode/decode
127
   the size:Q fields for AdvSIMD instructions.  */
128
129
static inline bool
130
vector_qualifier_p (enum aarch64_opnd_qualifier qualifier)
131
807k
{
132
807k
  return (qualifier >= AARCH64_OPND_QLF_V_8B
133
645k
    && qualifier <= AARCH64_OPND_QLF_V_1Q);
134
807k
}
135
136
static inline bool
137
fp_qualifier_p (enum aarch64_opnd_qualifier qualifier)
138
1.02k
{
139
1.02k
  return (qualifier >= AARCH64_OPND_QLF_S_B
140
1.02k
    && qualifier <= AARCH64_OPND_QLF_S_Q);
141
1.02k
}
142
143
enum data_pattern
144
{
145
  DP_UNKNOWN,
146
  DP_VECTOR_3SAME,
147
  DP_VECTOR_LONG,
148
  DP_VECTOR_WIDE,
149
  DP_VECTOR_ACROSS_LANES,
150
};
151
152
static const char significant_operand_index [] =
153
{
154
  0,  /* DP_UNKNOWN, by default using operand 0.  */
155
  0,  /* DP_VECTOR_3SAME */
156
  1,  /* DP_VECTOR_LONG */
157
  2,  /* DP_VECTOR_WIDE */
158
  1,  /* DP_VECTOR_ACROSS_LANES */
159
};
160
161
/* Given a sequence of qualifiers in QUALIFIERS, determine and return
162
   the data pattern.
163
   N.B. QUALIFIERS is a possible sequence of qualifiers each of which
164
   corresponds to one of a sequence of operands.  */
165
166
static enum data_pattern
167
get_data_pattern (const aarch64_opnd_qualifier_seq_t qualifiers)
168
350k
{
169
350k
  if (vector_qualifier_p (qualifiers[0]))
170
349k
    {
171
      /* e.g. v.4s, v.4s, v.4s
172
     or v.4h, v.4h, v.h[3].  */
173
349k
      if (qualifiers[0] == qualifiers[1]
174
167k
    && vector_qualifier_p (qualifiers[2])
175
120k
    && (aarch64_get_qualifier_esize (qualifiers[0])
176
120k
        == aarch64_get_qualifier_esize (qualifiers[2])))
177
114k
  return DP_VECTOR_3SAME;
178
      /* e.g. v.8h, v.8b, v.8b.
179
           or v.4s, v.4h, v.h[2].
180
     or v.8h, v.16b.  */
181
234k
      if (vector_qualifier_p (qualifiers[1])
182
164k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
183
164k
    && (aarch64_get_qualifier_esize (qualifiers[0])
184
164k
        == aarch64_get_qualifier_esize (qualifiers[1]) << 1))
185
59.5k
  return DP_VECTOR_LONG;
186
      /* e.g. v.8h, v.8h, v.8b.  */
187
175k
      if (qualifiers[0] == qualifiers[1]
188
53.2k
    && vector_qualifier_p (qualifiers[2])
189
6.10k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
190
6.10k
    && (aarch64_get_qualifier_esize (qualifiers[0])
191
6.10k
        == aarch64_get_qualifier_esize (qualifiers[2]) << 1))
192
6.10k
  return DP_VECTOR_WIDE;
193
175k
    }
194
1.02k
  else if (fp_qualifier_p (qualifiers[0]))
195
1.02k
    {
196
      /* e.g. SADDLV <V><d>, <Vn>.<T>.  */
197
1.02k
      if (vector_qualifier_p (qualifiers[1])
198
853
    && (qualifiers[2] == AARCH64_OPND_QLF_UNUSED))
199
853
  return DP_VECTOR_ACROSS_LANES;
200
1.02k
    }
201
202
169k
  return DP_UNKNOWN;
203
350k
}
204
205
/* Select the operand to do the encoding/decoding of the 'size:Q' fields in
206
   the AdvSIMD instructions.  */
207
/* N.B. it is possible to do some optimization that doesn't call
208
   get_data_pattern each time when we need to select an operand.  We can
209
   either buffer the caculated the result or statically generate the data,
210
   however, it is not obvious that the optimization will bring significant
211
   benefit.  */
212
213
int
214
aarch64_select_operand_for_sizeq_field_coding (const aarch64_opcode *opcode)
215
350k
{
216
350k
  return
217
350k
    significant_operand_index [get_data_pattern (opcode->qualifiers_list[0])];
218
350k
}
219

220
enum aarch64_operand_class
221
aarch64_get_operand_class (enum aarch64_opnd type)
222
2.90M
{
223
2.90M
  return aarch64_operands[type].op_class;
224
2.90M
}
225
226
const char *
227
aarch64_get_operand_name (enum aarch64_opnd type)
228
0
{
229
0
  return aarch64_operands[type].name;
230
0
}
231
232
/* Get operand description string.
233
   This is usually for the diagnosis purpose.  */
234
const char *
235
aarch64_get_operand_desc (enum aarch64_opnd type)
236
0
{
237
0
  return aarch64_operands[type].desc;
238
0
}
239
240
/* Table of all conditional affixes.  */
241
const aarch64_cond aarch64_conds[16] =
242
{
243
  {{"eq", "none"}, 0x0},
244
  {{"ne", "any"}, 0x1},
245
  {{"cs", "hs", "nlast"}, 0x2},
246
  {{"cc", "lo", "ul", "last"}, 0x3},
247
  {{"mi", "first"}, 0x4},
248
  {{"pl", "nfrst"}, 0x5},
249
  {{"vs"}, 0x6},
250
  {{"vc"}, 0x7},
251
  {{"hi", "pmore"}, 0x8},
252
  {{"ls", "plast"}, 0x9},
253
  {{"ge", "tcont"}, 0xa},
254
  {{"lt", "tstop"}, 0xb},
255
  {{"gt"}, 0xc},
256
  {{"le"}, 0xd},
257
  {{"al"}, 0xe},
258
  {{"nv"}, 0xf},
259
};
260
261
const aarch64_cond *
262
get_cond_from_value (aarch64_insn value)
263
68.7k
{
264
68.7k
  assert (value < 16);
265
68.7k
  return &aarch64_conds[(unsigned int) value];
266
68.7k
}
267
268
const aarch64_cond *
269
get_inverted_cond (const aarch64_cond *cond)
270
506
{
271
506
  return &aarch64_conds[cond->value ^ 0x1];
272
506
}
273
274
/* Table describing the operand extension/shifting operators; indexed by
275
   enum aarch64_modifier_kind.
276
277
   The value column provides the most common values for encoding modifiers,
278
   which enables table-driven encoding/decoding for the modifiers.  */
279
const struct aarch64_name_value_pair aarch64_operand_modifiers [] =
280
{
281
    {"none", 0x0},
282
    {"msl",  0x0},
283
    {"ror",  0x3},
284
    {"asr",  0x2},
285
    {"lsr",  0x1},
286
    {"lsl",  0x0},
287
    {"uxtb", 0x0},
288
    {"uxth", 0x1},
289
    {"uxtw", 0x2},
290
    {"uxtx", 0x3},
291
    {"sxtb", 0x4},
292
    {"sxth", 0x5},
293
    {"sxtw", 0x6},
294
    {"sxtx", 0x7},
295
    {"mul", 0x0},
296
    {"mul vl", 0x0},
297
    {NULL, 0},
298
};
299
300
enum aarch64_modifier_kind
301
aarch64_get_operand_modifier (const struct aarch64_name_value_pair *desc)
302
0
{
303
0
  return desc - aarch64_operand_modifiers;
304
0
}
305
306
aarch64_insn
307
aarch64_get_operand_modifier_value (enum aarch64_modifier_kind kind)
308
0
{
309
0
  return aarch64_operand_modifiers[kind].value;
310
0
}
311
312
enum aarch64_modifier_kind
313
aarch64_get_operand_modifier_from_value (aarch64_insn value,
314
           bool extend_p)
315
681k
{
316
681k
  if (extend_p)
317
120k
    return AARCH64_MOD_UXTB + value;
318
560k
  else
319
560k
    return AARCH64_MOD_LSL - value;
320
681k
}
321
322
bool
323
aarch64_extend_operator_p (enum aarch64_modifier_kind kind)
324
53.9k
{
325
53.9k
  return kind > AARCH64_MOD_LSL && kind <= AARCH64_MOD_SXTX;
326
53.9k
}
327
328
static inline bool
329
aarch64_shift_operator_p (enum aarch64_modifier_kind kind)
330
537k
{
331
537k
  return kind >= AARCH64_MOD_ROR && kind <= AARCH64_MOD_LSL;
332
537k
}
333
334
const struct aarch64_name_value_pair aarch64_barrier_options[16] =
335
{
336
    { "#0x00", 0x0 },
337
    { "oshld", 0x1 },
338
    { "oshst", 0x2 },
339
    { "osh",   0x3 },
340
    { "#0x04", 0x4 },
341
    { "nshld", 0x5 },
342
    { "nshst", 0x6 },
343
    { "nsh",   0x7 },
344
    { "#0x08", 0x8 },
345
    { "ishld", 0x9 },
346
    { "ishst", 0xa },
347
    { "ish",   0xb },
348
    { "#0x0c", 0xc },
349
    { "ld",    0xd },
350
    { "st",    0xe },
351
    { "sy",    0xf },
352
};
353
354
const struct aarch64_name_value_pair aarch64_barrier_dsb_nxs_options[4] =
355
{                       /*  CRm<3:2>  #imm  */
356
    { "oshnxs", 16 },    /*    00       16   */
357
    { "nshnxs", 20 },    /*    01       20   */
358
    { "ishnxs", 24 },    /*    10       24   */
359
    { "synxs",  28 },    /*    11       28   */
360
};
361
362
/* Table describing the operands supported by the aliases of the HINT
363
   instruction.
364
365
   The name column is the operand that is accepted for the alias.  The value
366
   column is the hint number of the alias.  The list of operands is terminated
367
   by NULL in the name column.  */
368
369
const struct aarch64_name_value_pair aarch64_hint_options[] =
370
{
371
  /* BTI.  This is also the F_DEFAULT entry for AARCH64_OPND_BTI_TARGET.
372
     BTI R and SHUH must be the first and second entries respectively
373
     so that F_DEFAULT refers to the correct table entries.  */
374
  { "r",  HINT_OPD_R },   /* BTI R.  */
375
  { "",   HINT_OPD_NPHINT}, /* SHUH. */
376
  { "csync",  HINT_OPD_CSYNC }, /* PSB CSYNC.  */
377
  { "dsync",  HINT_OPD_DSYNC }, /* GCSB DSYNC.  */
378
  { "c",  HINT_OPD_C },   /* BTI C.  */
379
  { "j",  HINT_OPD_J },   /* BTI J.  */
380
  { "jc", HINT_OPD_JC },    /* BTI JC.  */
381
  { "keep", HINT_OPD_KEEP },  /* STSHH KEEP  */
382
  { "strm", HINT_OPD_STRM },  /* STSHH STRM  */
383
  { "ph", HINT_OPD_PHINT }, /* SHUH PH.  */
384
  { NULL, HINT_OPD_NULL },
385
};
386
387
/* op -> op:       load = 0 instruction = 1 store = 2
388
   l  -> level:    1-3
389
   t  -> temporal: temporal (retained) = 0 non-temporal (streaming) = 1   */
390
#define B(op,l,t) (((op) << 3) | (((l) - 1) << 1) | (t))
391
const struct aarch64_name_value_pair aarch64_prfops[32] =
392
{
393
  { "pldl1keep", B(0, 1, 0) },
394
  { "pldl1strm", B(0, 1, 1) },
395
  { "pldl2keep", B(0, 2, 0) },
396
  { "pldl2strm", B(0, 2, 1) },
397
  { "pldl3keep", B(0, 3, 0) },
398
  { "pldl3strm", B(0, 3, 1) },
399
  { "pldslckeep", B(0, 4, 0) },
400
  { "pldslcstrm", B(0, 4, 1) },
401
  { "plil1keep", B(1, 1, 0) },
402
  { "plil1strm", B(1, 1, 1) },
403
  { "plil2keep", B(1, 2, 0) },
404
  { "plil2strm", B(1, 2, 1) },
405
  { "plil3keep", B(1, 3, 0) },
406
  { "plil3strm", B(1, 3, 1) },
407
  { "plislckeep", B(1, 4, 0) },
408
  { "plislcstrm", B(1, 4, 1) },
409
  { "pstl1keep", B(2, 1, 0) },
410
  { "pstl1strm", B(2, 1, 1) },
411
  { "pstl2keep", B(2, 2, 0) },
412
  { "pstl2strm", B(2, 2, 1) },
413
  { "pstl3keep", B(2, 3, 0) },
414
  { "pstl3strm", B(2, 3, 1) },
415
  { "pstslckeep", B(2, 4, 0) },
416
  { "pstslcstrm", B(2, 4, 1) },
417
  { "ir", B(3, 1, 0) },
418
  { NULL, 0x19 },
419
  { NULL, 0x1a },
420
  { NULL, 0x1b },
421
  { NULL, 0x1c },
422
  { NULL, 0x1d },
423
  { NULL, 0x1e },
424
  { NULL, 0x1f },
425
};
426
#undef B
427

428
/* Utilities on value constraint.  */
429
430
static inline bool
431
value_in_range_p (int64_t value, int64_t low, int64_t high)
432
3.04M
{
433
3.04M
  return (low <= value) && (value <= high);
434
3.04M
}
435
436
/* Return true if VALUE is a multiple of ALIGN.  */
437
static inline bool
438
value_aligned_p (int64_t value, int align)
439
2.05M
{
440
2.05M
  return (value % align) == 0;
441
2.05M
}
442
443
/* A signed value fits in a field.  */
444
static inline bool
445
value_fit_signed_field_p (int64_t value, unsigned width)
446
1.35M
{
447
1.35M
  assert (width < 32);
448
1.35M
  if (width < sizeof (value) * 8)
449
1.35M
    {
450
1.35M
      int64_t lim = (uint64_t) 1 << (width - 1);
451
1.35M
      if (value >= -lim && value < lim)
452
1.35M
  return true;
453
1.35M
    }
454
0
  return false;
455
1.35M
}
456
457
/* An unsigned value fits in a field.  */
458
static inline bool
459
value_fit_unsigned_field_p (int64_t value, unsigned width)
460
2.35M
{
461
2.35M
  assert (width < 32);
462
2.35M
  if (width < sizeof (value) * 8)
463
2.35M
    {
464
2.35M
      int64_t lim = (uint64_t) 1 << width;
465
2.35M
      if (value >= 0 && value < lim)
466
2.35M
  return true;
467
2.35M
    }
468
0
  return false;
469
2.35M
}
470
471
/* Return true if OPERAND is SP or WSP.  */
472
bool
473
aarch64_stack_pointer_p (const aarch64_opnd_info *operand)
474
168k
{
475
168k
  return ((aarch64_get_operand_class (operand->type)
476
168k
     == AARCH64_OPND_CLASS_INT_REG)
477
168k
    && operand_maybe_stack_pointer (aarch64_operands + operand->type)
478
109k
    && operand->reg.regno == 31);
479
168k
}
480
481
/* Return 1 if OPERAND is XZR or WZP.  */
482
int
483
aarch64_zero_register_p (const aarch64_opnd_info *operand)
484
0
{
485
0
  return ((aarch64_get_operand_class (operand->type)
486
0
     == AARCH64_OPND_CLASS_INT_REG)
487
0
    && !operand_maybe_stack_pointer (aarch64_operands + operand->type)
488
0
    && operand->reg.regno == 31);
489
0
}
490
491
enum operand_qualifier_kind
492
{
493
  OQK_NIL,
494
  OQK_OPD_VARIANT,
495
  OQK_VALUE_IN_RANGE,
496
  OQK_MISC,
497
};
498
499
/* Operand qualifier description.  */
500
struct operand_qualifier_data
501
{
502
  /* The usage of the three data fields depends on the qualifier kind.  */
503
  int data0;
504
  int data1;
505
  int data2;
506
  /* Description.  */
507
  const char *desc;
508
  /* Kind.  */
509
  enum operand_qualifier_kind kind;
510
};
511
512
/* Indexed by the operand qualifier enumerators.  */
513
static const struct operand_qualifier_data aarch64_opnd_qualifiers[] =
514
{
515
  {0, 0, 0, "UNUSED", OQK_NIL},
516
  {0, 0, 0, "NIL", OQK_NIL},
517
  {0, 0, 0, "UNKNOWN", OQK_NIL},
518
519
  /* Operand variant qualifiers.
520
     First 3 fields:
521
     element size, number of elements and common value for encoding.  */
522
523
  {4, 1, 0x0, "w", OQK_OPD_VARIANT},
524
  {8, 1, 0x1, "x", OQK_OPD_VARIANT},
525
526
  {1, 1, 0x0, "b", OQK_OPD_VARIANT},
527
  {2, 1, 0x1, "h", OQK_OPD_VARIANT},
528
  {4, 1, 0x2, "s", OQK_OPD_VARIANT},
529
  {8, 1, 0x3, "d", OQK_OPD_VARIANT},
530
  {16, 1, 0x4, "q", OQK_OPD_VARIANT},
531
  {2, 1, 0x0, "2b", OQK_OPD_VARIANT},
532
  {4, 1, 0x0, "4b", OQK_OPD_VARIANT},
533
  {4, 1, 0x0, "2h", OQK_OPD_VARIANT},
534
535
  {1, 4, 0x0, "4b", OQK_OPD_VARIANT},
536
  {1, 8, 0x0, "8b", OQK_OPD_VARIANT},
537
  {1, 16, 0x1, "16b", OQK_OPD_VARIANT},
538
  {2, 2, 0x0, "2h", OQK_OPD_VARIANT},
539
  {2, 4, 0x2, "4h", OQK_OPD_VARIANT},
540
  {2, 8, 0x3, "8h", OQK_OPD_VARIANT},
541
  {4, 2, 0x4, "2s", OQK_OPD_VARIANT},
542
  {4, 4, 0x5, "4s", OQK_OPD_VARIANT},
543
  {8, 1, 0x6, "1d", OQK_OPD_VARIANT},
544
  {8, 2, 0x7, "2d", OQK_OPD_VARIANT},
545
  {16, 1, 0x8, "1q", OQK_OPD_VARIANT},
546
547
  {0, 0, 0, "z", OQK_OPD_VARIANT},
548
  {0, 0, 0, "m", OQK_OPD_VARIANT},
549
550
  /* Qualifier for scaled immediate for Tag granule (stg,st2g,etc).  */
551
  {16, 0, 0, "tag", OQK_OPD_VARIANT},
552
553
  /* Qualifiers constraining the value range.
554
     First 3 fields:
555
     Lower bound, higher bound, unused.  */
556
557
  {0, 15, 0, "CR",       OQK_VALUE_IN_RANGE},
558
  {0,  7, 0, "imm_0_7" , OQK_VALUE_IN_RANGE},
559
  {0, 15, 0, "imm_0_15", OQK_VALUE_IN_RANGE},
560
  {0, 31, 0, "imm_0_31", OQK_VALUE_IN_RANGE},
561
  {0, 63, 0, "imm_0_63", OQK_VALUE_IN_RANGE},
562
  {1, 32, 0, "imm_1_32", OQK_VALUE_IN_RANGE},
563
  {1, 64, 0, "imm_1_64", OQK_VALUE_IN_RANGE},
564
565
  /* Qualifiers for miscellaneous purpose.
566
     First 3 fields:
567
     unused, unused and unused.  */
568
569
  {0, 0, 0, "lsl", 0},
570
  {0, 0, 0, "msl", 0},
571
572
  {0, 0, 0, "retrieving", 0},
573
574
  /* This shouldn't ever be used.  */
575
  {0, 0, 0, "ERR", OQK_NIL},
576
};
577
578
static inline bool
579
operand_variant_qualifier_p (aarch64_opnd_qualifier_t qualifier)
580
12.0M
{
581
12.0M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_OPD_VARIANT;
582
12.0M
}
583
584
static inline bool
585
qualifier_value_in_range_constraint_p (aarch64_opnd_qualifier_t qualifier)
586
4.37M
{
587
4.37M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_VALUE_IN_RANGE;
588
4.37M
}
589
590
const char*
591
aarch64_get_qualifier_name (aarch64_opnd_qualifier_t qualifier)
592
4.62M
{
593
4.62M
  return aarch64_opnd_qualifiers[qualifier].desc;
594
4.62M
}
595
596
/* Given an operand qualifier, return the expected data element size
597
   of a qualified operand.  */
598
unsigned char
599
aarch64_get_qualifier_esize (aarch64_opnd_qualifier_t qualifier)
600
8.66M
{
601
8.66M
  assert (operand_variant_qualifier_p (qualifier));
602
8.66M
  return aarch64_opnd_qualifiers[qualifier].data0;
603
8.66M
}
604
605
unsigned char
606
aarch64_get_qualifier_nelem (aarch64_opnd_qualifier_t qualifier)
607
109k
{
608
109k
  assert (operand_variant_qualifier_p (qualifier));
609
109k
  return aarch64_opnd_qualifiers[qualifier].data1;
610
109k
}
611
612
aarch64_insn
613
aarch64_get_qualifier_standard_value (aarch64_opnd_qualifier_t qualifier)
614
3.32M
{
615
3.32M
  assert (operand_variant_qualifier_p (qualifier));
616
3.32M
  return aarch64_opnd_qualifiers[qualifier].data2;
617
3.32M
}
618
619
static int
620
get_lower_bound (aarch64_opnd_qualifier_t qualifier)
621
487k
{
622
487k
  assert (qualifier_value_in_range_constraint_p (qualifier));
623
487k
  return aarch64_opnd_qualifiers[qualifier].data0;
624
487k
}
625
626
static int
627
get_upper_bound (aarch64_opnd_qualifier_t qualifier)
628
522k
{
629
522k
  assert (qualifier_value_in_range_constraint_p (qualifier));
630
522k
  return aarch64_opnd_qualifiers[qualifier].data1;
631
522k
}
632
633
#ifdef DEBUG_AARCH64
634
void
635
aarch64_verbose (const char *str, ...)
636
{
637
  va_list ap;
638
  va_start (ap, str);
639
  printf ("#### ");
640
  vprintf (str, ap);
641
  printf ("\n");
642
  va_end (ap);
643
}
644
645
static inline void
646
dump_qualifier_sequence (const aarch64_opnd_qualifier_t *qualifier)
647
{
648
  int i;
649
  printf ("#### \t");
650
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i, ++qualifier)
651
    printf ("%s,", aarch64_get_qualifier_name (*qualifier));
652
  printf ("\n");
653
}
654
655
static void
656
dump_match_qualifiers (const struct aarch64_opnd_info *opnd,
657
           const aarch64_opnd_qualifier_t *qualifier)
658
{
659
  int i;
660
  aarch64_opnd_qualifier_t curr[AARCH64_MAX_OPND_NUM];
661
662
  aarch64_verbose ("dump_match_qualifiers:");
663
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
664
    curr[i] = opnd[i].qualifier;
665
  dump_qualifier_sequence (curr);
666
  aarch64_verbose ("against");
667
  dump_qualifier_sequence (qualifier);
668
}
669
#endif /* DEBUG_AARCH64 */
670
671
/* This function checks if the given instruction INSN is a destructive
672
   instruction based on the usage of the registers.  It does not recognize
673
   unary destructive instructions.  */
674
bool
675
aarch64_is_destructive_by_operands (const aarch64_opcode *opcode)
676
539
{
677
539
  int i = 0;
678
539
  const enum aarch64_opnd *opnds = opcode->operands;
679
680
539
  if (opnds[0] == AARCH64_OPND_NIL)
681
0
    return false;
682
683
1.51k
  while (opnds[++i] != AARCH64_OPND_NIL)
684
1.29k
    if (opnds[i] == opnds[0])
685
320
      return true;
686
687
219
  return false;
688
539
}
689
690
/* TODO improve this, we can have an extra field at the runtime to
691
   store the number of operands rather than calculating it every time.  */
692
693
int
694
aarch64_num_of_operands (const aarch64_opcode *opcode)
695
10.0M
{
696
10.0M
  int i = 0;
697
10.0M
  const enum aarch64_opnd *opnds = opcode->operands;
698
34.7M
  while (opnds[i++] != AARCH64_OPND_NIL)
699
24.6M
    ;
700
10.0M
  --i;
701
10.0M
  assert (i >= 0 && i <= AARCH64_MAX_OPND_NUM);
702
10.0M
  return i;
703
10.0M
}
704
705
/* Find the best matched qualifier sequence in *QUALIFIERS_LIST for INST.
706
   If succeeds, fill the found sequence in *RET, return 1; otherwise return 0.
707
708
   Store the smallest number of non-matching qualifiers in *INVALID_COUNT.
709
   This is always 0 if the function succeeds.
710
711
   N.B. on the entry, it is very likely that only some operands in *INST
712
   have had their qualifiers been established.
713
714
   If STOP_AT is not -1, the function will only try to match
715
   the qualifier sequence for operands before and including the operand
716
   of index STOP_AT; and on success *RET will only be filled with the first
717
   (STOP_AT+1) qualifiers.
718
719
   A couple examples of the matching algorithm:
720
721
   X,W,NIL should match
722
   X,W,NIL
723
724
   NIL,NIL should match
725
   X  ,NIL
726
727
   Apart from serving the main encoding routine, this can also be called
728
   during or after the operand decoding.  */
729
730
int
731
aarch64_find_best_match (const aarch64_inst *inst,
732
       const aarch64_opnd_qualifier_seq_t *qualifiers_list,
733
       int stop_at, aarch64_opnd_qualifier_t *ret,
734
       int *invalid_count)
735
9.07M
{
736
9.07M
  int i, num_opnds, invalid, min_invalid;
737
9.07M
  const aarch64_opnd_qualifier_t *qualifiers;
738
739
9.07M
  num_opnds = aarch64_num_of_operands (inst->opcode);
740
9.07M
  if (num_opnds == 0)
741
80
    {
742
80
      DEBUG_TRACE ("SUCCEED: no operand");
743
80
      *invalid_count = 0;
744
80
      return 1;
745
80
    }
746
747
9.07M
  if (stop_at < 0 || stop_at >= num_opnds)
748
7.92M
    stop_at = num_opnds - 1;
749
750
  /* For each pattern.  */
751
9.07M
  min_invalid = num_opnds;
752
12.5M
  for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list)
753
12.5M
    {
754
12.5M
      int j;
755
12.5M
      qualifiers = *qualifiers_list;
756
757
      /* Start as positive.  */
758
12.5M
      invalid = 0;
759
760
12.5M
      DEBUG_TRACE ("%d", i);
761
#ifdef DEBUG_AARCH64
762
      if (debug_dump)
763
  dump_match_qualifiers (inst->operands, qualifiers);
764
#endif
765
766
      /* The first entry should be taken literally, even if it's an empty
767
   qualifier sequence.  In other positions an empty sequence acts as a
768
   terminator.  */
769
12.5M
      if (i > 0 && empty_qualifier_sequence_p (qualifiers))
770
69.1k
  break;
771
772
43.3M
      for (j = 0; j < num_opnds && j <= stop_at; ++j, ++qualifiers)
773
30.8M
  if (inst->operands[j].qualifier != *qualifiers
774
20.9M
       && inst->operands[j].qualifier != AARCH64_OPND_QLF_UNKNOWN)
775
4.89M
    invalid += 1;
776
777
12.4M
      if (min_invalid > invalid)
778
11.0M
  min_invalid = invalid;
779
780
      /* Qualifiers established.  */
781
12.4M
      if (min_invalid == 0)
782
9.00M
  break;
783
12.4M
    }
784
785
9.07M
  *invalid_count = min_invalid;
786
9.07M
  if (min_invalid == 0)
787
9.00M
    {
788
      /* Fill the result in *RET.  */
789
9.00M
      int j;
790
9.00M
      qualifiers = *qualifiers_list;
791
792
9.00M
      DEBUG_TRACE ("complete qualifiers using list %d", i);
793
#ifdef DEBUG_AARCH64
794
      if (debug_dump)
795
  dump_qualifier_sequence (qualifiers);
796
#endif
797
798
30.3M
      for (j = 0; j <= stop_at; ++j, ++qualifiers)
799
21.3M
  ret[j] = *qualifiers;
800
50.7M
      for (; j < AARCH64_MAX_OPND_NUM; ++j)
801
41.6M
  ret[j] = AARCH64_OPND_QLF_UNKNOWN;
802
803
9.00M
      DEBUG_TRACE ("SUCCESS");
804
9.00M
      return 1;
805
9.00M
    }
806
807
69.1k
  DEBUG_TRACE ("FAIL");
808
69.1k
  return 0;
809
9.07M
}
810
811
/* Operand qualifier matching and resolving.
812
813
   Return 1 if the operand qualifier(s) in *INST match one of the qualifier
814
   sequences in INST->OPCODE->qualifiers_list; otherwise return 0.
815
816
   Store the smallest number of non-matching qualifiers in *INVALID_COUNT.
817
   This is always 0 if the function succeeds.
818
819
   if UPDATE_P, update the qualifier(s) in *INST after the matching
820
   succeeds.  */
821
822
static int
823
match_operands_qualifier (aarch64_inst *inst, bool update_p,
824
        int *invalid_count)
825
7.92M
{
826
7.92M
  int i;
827
7.92M
  aarch64_opnd_qualifier_seq_t qualifiers;
828
829
7.92M
  if (!aarch64_find_best_match (inst, inst->opcode->qualifiers_list, -1,
830
7.92M
        qualifiers, invalid_count))
831
41.5k
    {
832
41.5k
      DEBUG_TRACE ("matching FAIL");
833
41.5k
      return 0;
834
41.5k
    }
835
836
  /* Update the qualifiers.  */
837
7.88M
  if (update_p)
838
26.3M
    for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
839
26.3M
      {
840
26.3M
  if (inst->opcode->operands[i] == AARCH64_OPND_NIL)
841
7.88M
    break;
842
18.4M
  DEBUG_TRACE_IF (inst->operands[i].qualifier != qualifiers[i],
843
18.4M
      "update %s with %s for operand %d",
844
18.4M
      aarch64_get_qualifier_name (inst->operands[i].qualifier),
845
18.4M
      aarch64_get_qualifier_name (qualifiers[i]), i);
846
18.4M
  inst->operands[i].qualifier = qualifiers[i];
847
18.4M
      }
848
849
7.88M
  DEBUG_TRACE ("matching SUCCESS");
850
7.88M
  return 1;
851
7.92M
}
852
853
/* Return TRUE if VALUE is a wide constant that can be moved into a general
854
   register by MOVZ.
855
856
   IS32 indicates whether value is a 32-bit immediate or not.
857
   If SHIFT_AMOUNT is not NULL, on the return of TRUE, the logical left shift
858
   amount will be returned in *SHIFT_AMOUNT.  */
859
860
bool
861
aarch64_wide_constant_p (uint64_t value, int is32, unsigned int *shift_amount)
862
102k
{
863
102k
  int amount;
864
865
102k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
866
867
102k
  if (is32)
868
16.8k
    {
869
      /* Allow all zeros or all ones in top 32-bits, so that
870
   32-bit constant expressions like ~0x80000000 are
871
   permitted.  */
872
16.8k
      if (value >> 32 != 0 && value >> 32 != 0xffffffff)
873
  /* Immediate out of range.  */
874
0
  return false;
875
16.8k
      value &= 0xffffffff;
876
16.8k
    }
877
878
  /* first, try movz then movn */
879
102k
  amount = -1;
880
102k
  if ((value & ((uint64_t) 0xffff << 0)) == value)
881
24.1k
    amount = 0;
882
78.2k
  else if ((value & ((uint64_t) 0xffff << 16)) == value)
883
12.3k
    amount = 16;
884
65.9k
  else if (!is32 && (value & ((uint64_t) 0xffff << 32)) == value)
885
27.9k
    amount = 32;
886
37.9k
  else if (!is32 && (value & ((uint64_t) 0xffff << 48)) == value)
887
5.53k
    amount = 48;
888
889
102k
  if (amount == -1)
890
32.4k
    {
891
32.4k
      DEBUG_TRACE ("exit false with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
892
32.4k
      return false;
893
32.4k
    }
894
895
70.0k
  if (shift_amount != NULL)
896
0
    *shift_amount = amount;
897
898
70.0k
  DEBUG_TRACE ("exit true with amount %d", amount);
899
900
70.0k
  return true;
901
102k
}
902
903
/* Build the accepted values for immediate logical SIMD instructions.
904
905
   The standard encodings of the immediate value are:
906
     N      imms     immr         SIMD size  R             S
907
     1      ssssss   rrrrrr       64      UInt(rrrrrr)  UInt(ssssss)
908
     0      0sssss   0rrrrr       32      UInt(rrrrr)   UInt(sssss)
909
     0      10ssss   00rrrr       16      UInt(rrrr)    UInt(ssss)
910
     0      110sss   000rrr       8       UInt(rrr)     UInt(sss)
911
     0      1110ss   0000rr       4       UInt(rr)      UInt(ss)
912
     0      11110s   00000r       2       UInt(r)       UInt(s)
913
   where all-ones value of S is reserved.
914
915
   Let's call E the SIMD size.
916
917
   The immediate value is: S+1 bits '1' rotated to the right by R.
918
919
   The total of valid encodings is 64*63 + 32*31 + ... + 2*1 = 5334
920
   (remember S != E - 1).  */
921
922
342k
#define TOTAL_IMM_NB  5334
923
924
typedef struct
925
{
926
  uint64_t imm;
927
  aarch64_insn encoding;
928
} simd_imm_encoding;
929
930
static simd_imm_encoding simd_immediates[TOTAL_IMM_NB];
931
932
static int
933
simd_imm_encoding_cmp(const void *i1, const void *i2)
934
4.03M
{
935
4.03M
  const simd_imm_encoding *imm1 = (const simd_imm_encoding *)i1;
936
4.03M
  const simd_imm_encoding *imm2 = (const simd_imm_encoding *)i2;
937
938
4.03M
  if (imm1->imm < imm2->imm)
939
2.01M
    return -1;
940
2.01M
  if (imm1->imm > imm2->imm)
941
1.67M
    return +1;
942
342k
  return 0;
943
2.01M
}
944
945
/* immediate bitfield standard encoding
946
   imm13<12> imm13<5:0> imm13<11:6> SIMD size R      S
947
   1         ssssss     rrrrrr      64        rrrrrr ssssss
948
   0         0sssss     0rrrrr      32        rrrrr  sssss
949
   0         10ssss     00rrrr      16        rrrr   ssss
950
   0         110sss     000rrr      8         rrr    sss
951
   0         1110ss     0000rr      4         rr     ss
952
   0         11110s     00000r      2         r      s  */
953
static inline int
954
encode_immediate_bitfield (int is64, uint32_t s, uint32_t r)
955
10.6k
{
956
10.6k
  return (is64 << 12) | (r << 6) | s;
957
10.6k
}
958
959
static void
960
build_immediate_table (void)
961
2
{
962
2
  uint32_t log_e, e, s, r, s_mask;
963
2
  uint64_t mask, imm;
964
2
  int nb_imms;
965
2
  int is64;
966
967
2
  nb_imms = 0;
968
14
  for (log_e = 1; log_e <= 6; log_e++)
969
12
    {
970
      /* Get element size.  */
971
12
      e = 1u << log_e;
972
12
      if (log_e == 6)
973
2
  {
974
2
    is64 = 1;
975
2
    mask = 0xffffffffffffffffull;
976
2
    s_mask = 0;
977
2
  }
978
10
      else
979
10
  {
980
10
    is64 = 0;
981
10
    mask = (1ull << e) - 1;
982
    /* log_e  s_mask
983
       1     ((1 << 4) - 1) << 2 = 111100
984
       2     ((1 << 3) - 1) << 3 = 111000
985
       3     ((1 << 2) - 1) << 4 = 110000
986
       4     ((1 << 1) - 1) << 5 = 100000
987
       5     ((1 << 0) - 1) << 6 = 000000  */
988
10
    s_mask = ((1u << (5 - log_e)) - 1) << (log_e + 1);
989
10
  }
990
252
      for (s = 0; s < e - 1; s++)
991
10.9k
  for (r = 0; r < e; r++)
992
10.6k
    {
993
      /* s+1 consecutive bits to 1 (s < 63) */
994
10.6k
      imm = (1ull << (s + 1)) - 1;
995
      /* rotate right by r */
996
10.6k
      if (r != 0)
997
10.4k
        imm = (imm >> r) | ((imm << (e - r)) & mask);
998
      /* replicate the constant depending on SIMD size */
999
10.6k
      switch (log_e)
1000
10.6k
        {
1001
4
        case 1: imm = (imm <<  2) | imm;
1002
    /* Fall through.  */
1003
28
        case 2: imm = (imm <<  4) | imm;
1004
    /* Fall through.  */
1005
140
        case 3: imm = (imm <<  8) | imm;
1006
    /* Fall through.  */
1007
620
        case 4: imm = (imm << 16) | imm;
1008
    /* Fall through.  */
1009
2.60k
        case 5: imm = (imm << 32) | imm;
1010
    /* Fall through.  */
1011
10.6k
        case 6: break;
1012
0
        default: abort ();
1013
10.6k
        }
1014
10.6k
      simd_immediates[nb_imms].imm = imm;
1015
10.6k
      simd_immediates[nb_imms].encoding =
1016
10.6k
        encode_immediate_bitfield(is64, s | s_mask, r);
1017
10.6k
      nb_imms++;
1018
10.6k
    }
1019
12
    }
1020
2
  assert (nb_imms == TOTAL_IMM_NB);
1021
2
  qsort(simd_immediates, nb_imms,
1022
2
  sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1023
2
}
1024
1025
/* Return TRUE if VALUE is a valid logical immediate, i.e. bitmask, that can
1026
   be accepted by logical (immediate) instructions
1027
   e.g. ORR <Xd|SP>, <Xn>, #<imm>.
1028
1029
   ESIZE is the number of bytes in the decoded immediate value.
1030
   If ENCODING is not NULL, on the return of TRUE, the standard encoding for
1031
   VALUE will be returned in *ENCODING.  */
1032
1033
bool
1034
aarch64_logical_immediate_p (uint64_t value, int esize, aarch64_insn *encoding)
1035
342k
{
1036
342k
  simd_imm_encoding imm_enc;
1037
342k
  const simd_imm_encoding *imm_encoding;
1038
342k
  static bool initialized = false;
1039
342k
  uint64_t upper;
1040
342k
  int i;
1041
1042
342k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 "), esize: %d", value,
1043
342k
         value, esize);
1044
1045
342k
  if (!initialized)
1046
2
    {
1047
2
      build_immediate_table ();
1048
2
      initialized = true;
1049
2
    }
1050
1051
  /* Allow all zeros or all ones in top bits, so that
1052
     constant expressions like ~1 are permitted.  */
1053
342k
  upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
1054
342k
  if ((value & ~upper) != value && (value | upper) != value)
1055
0
    return false;
1056
1057
  /* Replicate to a full 64-bit value.  */
1058
342k
  value &= ~upper;
1059
594k
  for (i = esize * 8; i < 64; i *= 2)
1060
252k
    value |= (value << i);
1061
1062
342k
  imm_enc.imm = value;
1063
342k
  imm_encoding = (const simd_imm_encoding *)
1064
342k
    bsearch(&imm_enc, simd_immediates, TOTAL_IMM_NB,
1065
342k
            sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1066
342k
  if (imm_encoding == NULL)
1067
0
    {
1068
0
      DEBUG_TRACE ("exit with false");
1069
0
      return false;
1070
0
    }
1071
342k
  if (encoding != NULL)
1072
0
    *encoding = imm_encoding->encoding;
1073
342k
  DEBUG_TRACE ("exit with true");
1074
342k
  return true;
1075
342k
}
1076
1077
/* If 64-bit immediate IMM is in the format of
1078
   "aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh",
1079
   where a, b, c, d, e, f, g and h are independently 0 or 1, return an integer
1080
   of value "abcdefgh".  Otherwise return -1.  */
1081
int
1082
aarch64_shrink_expanded_imm8 (uint64_t imm)
1083
603
{
1084
603
  int i, ret;
1085
603
  uint32_t byte;
1086
1087
603
  ret = 0;
1088
5.42k
  for (i = 0; i < 8; i++)
1089
4.82k
    {
1090
4.82k
      byte = (imm >> (8 * i)) & 0xff;
1091
4.82k
      if (byte == 0xff)
1092
2.56k
  ret |= 1 << i;
1093
2.25k
      else if (byte != 0x00)
1094
0
  return -1;
1095
4.82k
    }
1096
603
  return ret;
1097
603
}
1098
1099
/* Utility inline functions for operand_general_constraint_met_p.  */
1100
1101
static inline void
1102
set_error (aarch64_operand_error *mismatch_detail,
1103
     enum aarch64_operand_error_kind kind, int idx,
1104
     const char* error)
1105
0
{
1106
0
  if (mismatch_detail == NULL)
1107
0
    return;
1108
0
  mismatch_detail->kind = kind;
1109
0
  mismatch_detail->index = idx;
1110
0
  mismatch_detail->error = error;
1111
0
}
1112
1113
static inline void
1114
set_syntax_error (aarch64_operand_error *mismatch_detail, int idx,
1115
      const char* error)
1116
3.28k
{
1117
3.28k
  if (mismatch_detail == NULL)
1118
3.28k
    return;
1119
0
  set_error (mismatch_detail, AARCH64_OPDE_SYNTAX_ERROR, idx, error);
1120
0
}
1121
1122
static inline void
1123
set_invalid_regno_error (aarch64_operand_error *mismatch_detail, int idx,
1124
       const char *prefix, int lower_bound, int upper_bound)
1125
0
{
1126
0
  if (mismatch_detail == NULL)
1127
0
    return;
1128
0
  set_error (mismatch_detail, AARCH64_OPDE_INVALID_REGNO, idx, NULL);
1129
0
  mismatch_detail->data[0].s = prefix;
1130
0
  mismatch_detail->data[1].i = lower_bound;
1131
0
  mismatch_detail->data[2].i = upper_bound;
1132
0
}
1133
1134
static inline void
1135
set_out_of_range_error (aarch64_operand_error *mismatch_detail,
1136
      int idx, int lower_bound, int upper_bound,
1137
      const char* error)
1138
0
{
1139
0
  if (mismatch_detail == NULL)
1140
0
    return;
1141
0
  set_error (mismatch_detail, AARCH64_OPDE_OUT_OF_RANGE, idx, error);
1142
0
  mismatch_detail->data[0].i = lower_bound;
1143
0
  mismatch_detail->data[1].i = upper_bound;
1144
0
}
1145
1146
static inline void
1147
set_imm_out_of_range_error (aarch64_operand_error *mismatch_detail,
1148
          int idx, int lower_bound, int upper_bound)
1149
48.8k
{
1150
48.8k
  if (mismatch_detail == NULL)
1151
48.8k
    return;
1152
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1153
0
        _("immediate value"));
1154
0
}
1155
1156
static inline void
1157
set_offset_out_of_range_error (aarch64_operand_error *mismatch_detail,
1158
             int idx, int lower_bound, int upper_bound)
1159
0
{
1160
0
  if (mismatch_detail == NULL)
1161
0
    return;
1162
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1163
0
        _("immediate offset"));
1164
0
}
1165
1166
static inline void
1167
set_regno_out_of_range_error (aarch64_operand_error *mismatch_detail,
1168
            int idx, int lower_bound, int upper_bound)
1169
0
{
1170
0
  if (mismatch_detail == NULL)
1171
0
    return;
1172
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1173
0
        _("register number"));
1174
0
}
1175
1176
static inline void
1177
set_elem_idx_out_of_range_error (aarch64_operand_error *mismatch_detail,
1178
         int idx, int lower_bound, int upper_bound)
1179
593
{
1180
593
  if (mismatch_detail == NULL)
1181
593
    return;
1182
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1183
0
        _("register element index"));
1184
0
}
1185
1186
static inline void
1187
set_sft_amount_out_of_range_error (aarch64_operand_error *mismatch_detail,
1188
           int idx, int lower_bound, int upper_bound)
1189
97.2k
{
1190
97.2k
  if (mismatch_detail == NULL)
1191
97.2k
    return;
1192
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1193
0
        _("shift amount"));
1194
0
}
1195
1196
/* Report that the MUL modifier in operand IDX should be in the range
1197
   [LOWER_BOUND, UPPER_BOUND].  */
1198
static inline void
1199
set_multiplier_out_of_range_error (aarch64_operand_error *mismatch_detail,
1200
           int idx, int lower_bound, int upper_bound)
1201
0
{
1202
0
  if (mismatch_detail == NULL)
1203
0
    return;
1204
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1205
0
        _("multiplier"));
1206
0
}
1207
1208
static inline void
1209
set_unaligned_error (aarch64_operand_error *mismatch_detail, int idx,
1210
         int alignment)
1211
0
{
1212
0
  if (mismatch_detail == NULL)
1213
0
    return;
1214
0
  set_error (mismatch_detail, AARCH64_OPDE_UNALIGNED, idx, NULL);
1215
0
  mismatch_detail->data[0].i = alignment;
1216
0
}
1217
1218
static inline void
1219
set_reg_list_length_error (aarch64_operand_error *mismatch_detail, int idx,
1220
         int expected_num)
1221
948
{
1222
948
  if (mismatch_detail == NULL)
1223
948
    return;
1224
0
  set_error (mismatch_detail, AARCH64_OPDE_REG_LIST_LENGTH, idx, NULL);
1225
0
  mismatch_detail->data[0].i = 1 << expected_num;
1226
0
}
1227
1228
static inline void
1229
set_reg_list_stride_error (aarch64_operand_error *mismatch_detail, int idx,
1230
         int expected_num)
1231
0
{
1232
0
  if (mismatch_detail == NULL)
1233
0
    return;
1234
0
  set_error (mismatch_detail, AARCH64_OPDE_REG_LIST_STRIDE, idx, NULL);
1235
0
  mismatch_detail->data[0].i = 1 << expected_num;
1236
0
}
1237
1238
static inline void
1239
set_invalid_vg_size (aarch64_operand_error *mismatch_detail,
1240
         int idx, int expected)
1241
0
{
1242
0
  if (mismatch_detail == NULL)
1243
0
    return;
1244
0
  set_error (mismatch_detail, AARCH64_OPDE_INVALID_VG_SIZE, idx, NULL);
1245
0
  mismatch_detail->data[0].i = expected;
1246
0
}
1247
1248
static inline void
1249
set_other_error (aarch64_operand_error *mismatch_detail, int idx,
1250
     const char* error)
1251
46.4k
{
1252
46.4k
  if (mismatch_detail == NULL)
1253
46.4k
    return;
1254
0
  set_error (mismatch_detail, AARCH64_OPDE_OTHER_ERROR, idx, error);
1255
0
}
1256
1257
/* Check that indexed register operand OPND has a register in the range
1258
   [MIN_REGNO, MAX_REGNO] and an index in the range [MIN_INDEX, MAX_INDEX].
1259
   PREFIX is the register prefix, such as "z" for SVE vector registers.  */
1260
1261
static bool
1262
check_reglane (const aarch64_opnd_info *opnd,
1263
         aarch64_operand_error *mismatch_detail, int idx,
1264
         const char *prefix, int min_regno, int max_regno,
1265
         int min_index, int max_index)
1266
89.6k
{
1267
89.6k
  if (!value_in_range_p (opnd->reglane.regno, min_regno, max_regno))
1268
0
    {
1269
0
      set_invalid_regno_error (mismatch_detail, idx, prefix, min_regno,
1270
0
             max_regno);
1271
0
      return false;
1272
0
    }
1273
89.6k
  if (!value_in_range_p (opnd->reglane.index, min_index, max_index))
1274
0
    {
1275
0
      set_elem_idx_out_of_range_error (mismatch_detail, idx, min_index,
1276
0
               max_index);
1277
0
      return false;
1278
0
    }
1279
89.6k
  return true;
1280
89.6k
}
1281
1282
/* Check that register list operand OPND has NUM_REGS registers and a
1283
   register stride of STRIDE.  */
1284
1285
static bool
1286
check_reglist (const aarch64_opnd_info *opnd,
1287
         aarch64_operand_error *mismatch_detail, int idx,
1288
         int num_regs, int stride)
1289
388k
{
1290
388k
  if (opnd->reglist.num_regs != num_regs)
1291
948
    {
1292
948
      set_reg_list_length_error (mismatch_detail, idx, num_regs);
1293
948
      return false;
1294
948
    }
1295
387k
  if (opnd->reglist.stride != stride)
1296
0
    {
1297
0
      set_reg_list_stride_error (mismatch_detail, idx, stride);
1298
0
      return false;
1299
0
    }
1300
387k
  return true;
1301
387k
}
1302
1303
typedef struct
1304
{
1305
  int64_t min;
1306
  int64_t max;
1307
} imm_range_t;
1308
1309
static imm_range_t
1310
imm_range_min_max (unsigned size, bool signed_rng)
1311
0
{
1312
0
  assert (size < 63);
1313
0
  imm_range_t r;
1314
0
  if (signed_rng)
1315
0
    {
1316
0
      r.max = (((int64_t) 0x1) << (size - 1)) - 1;
1317
0
      r.min = - r.max - 1;
1318
0
    }
1319
0
  else
1320
0
    {
1321
0
      r.max = (((int64_t) 0x1) << size) - 1;
1322
0
      r.min = 0;
1323
0
    }
1324
0
  return r;
1325
0
}
1326
1327
/* Check that an immediate value is in the range provided by the
1328
   operand type.  */
1329
static bool
1330
check_immediate_out_of_range (int64_t imm,
1331
            enum aarch64_opnd type,
1332
            aarch64_operand_error *mismatch_detail,
1333
            int idx)
1334
1.33M
{
1335
1.33M
  const aarch64_operand *operand = get_operand_from_code (type);
1336
1.33M
  uint8_t size = get_operand_fields_width (operand);
1337
1.33M
  bool unsigned_imm = operand_need_unsigned_offset (operand);
1338
1.33M
  bool (*value_fit_field) (int64_t, unsigned)
1339
1.33M
    = (unsigned_imm
1340
1.33M
      ? value_fit_unsigned_field_p
1341
1.33M
      : value_fit_signed_field_p);
1342
1343
1.33M
  if (!value_fit_field (imm, size))
1344
0
    {
1345
0
      imm_range_t rng = imm_range_min_max (size, !unsigned_imm);
1346
0
      set_imm_out_of_range_error (mismatch_detail, idx, rng.min, rng.max);
1347
0
      return false;
1348
0
    }
1349
1.33M
  return true;
1350
1.33M
}
1351
1352
/* Check that indexed ZA operand OPND has:
1353
1354
   - a selection register in the range [MIN_WREG, MIN_WREG + 3]
1355
1356
   - RANGE_SIZE consecutive immediate offsets.
1357
1358
   - an initial immediate offset that is a multiple of RANGE_SIZE
1359
     in the range [0, MAX_VALUE * RANGE_SIZE]
1360
1361
   - a vector group size of GROUP_SIZE.
1362
1363
   - STATUS_VG for cases where VGx2 or VGx4 is mandatory.  */
1364
static bool
1365
check_za_access (const aarch64_opnd_info *opnd,
1366
     aarch64_operand_error *mismatch_detail, int idx,
1367
     int min_wreg, int max_value, unsigned int range_size,
1368
     int group_size, bool status_vg)
1369
193k
{
1370
193k
  if (!value_in_range_p (opnd->indexed_za.index.regno, min_wreg, min_wreg + 3))
1371
0
    {
1372
0
      if (min_wreg == 12)
1373
0
  set_other_error (mismatch_detail, idx,
1374
0
       _("expected a selection register in the"
1375
0
         " range w12-w15"));
1376
0
      else if (min_wreg == 8)
1377
0
  set_other_error (mismatch_detail, idx,
1378
0
       _("expected a selection register in the"
1379
0
         " range w8-w11"));
1380
0
      else
1381
0
  abort ();
1382
0
      return false;
1383
0
    }
1384
1385
193k
  int max_index = max_value * range_size;
1386
193k
  if (!value_in_range_p (opnd->indexed_za.index.imm, 0, max_index))
1387
0
    {
1388
0
      set_offset_out_of_range_error (mismatch_detail, idx, 0, max_index);
1389
0
      return false;
1390
0
    }
1391
1392
193k
  if ((opnd->indexed_za.index.imm % range_size) != 0)
1393
0
    {
1394
0
      assert (range_size == 2 || range_size == 4);
1395
0
      set_other_error (mismatch_detail, idx,
1396
0
           range_size == 2
1397
0
           ? _("starting offset is not a multiple of 2")
1398
0
           : _("starting offset is not a multiple of 4"));
1399
0
      return false;
1400
0
    }
1401
1402
193k
  if (opnd->indexed_za.index.countm1 != range_size - 1)
1403
0
    {
1404
0
      if (range_size == 1)
1405
0
  set_other_error (mismatch_detail, idx,
1406
0
       _("expected a single offset rather than"
1407
0
         " a range"));
1408
0
      else if (range_size == 2)
1409
0
  set_other_error (mismatch_detail, idx,
1410
0
       _("expected a range of two offsets"));
1411
0
      else if (range_size == 4)
1412
0
  set_other_error (mismatch_detail, idx,
1413
0
       _("expected a range of four offsets"));
1414
0
      else
1415
0
  abort ();
1416
0
      return false;
1417
0
    }
1418
1419
  /* The vector group specifier is optional in assembly code.  */
1420
193k
  if (opnd->indexed_za.group_size != group_size
1421
0
      && (status_vg || opnd->indexed_za.group_size != 0 ))
1422
0
    {
1423
0
      set_invalid_vg_size (mismatch_detail, idx, group_size);
1424
0
      return false;
1425
0
    }
1426
1427
193k
  return true;
1428
193k
}
1429
1430
/* Given a load/store operation, calculate the size of transferred data via a
1431
   cumulative sum of qualifier sizes preceding the address operand in the
1432
   OPNDS operand list argument.  */
1433
int
1434
calc_ldst_datasize (const aarch64_opnd_info *opnds)
1435
16.0k
{
1436
16.0k
  unsigned num_bytes = 0; /* total number of bytes transferred.  */
1437
16.0k
  enum aarch64_operand_class opnd_class;
1438
16.0k
  enum aarch64_opnd type;
1439
1440
47.4k
  for (int i = 0; i < AARCH64_MAX_OPND_NUM; i++)
1441
47.4k
    {
1442
47.4k
      type = opnds[i].type;
1443
47.4k
      opnd_class = aarch64_operands[type].op_class;
1444
47.4k
      if (opnd_class == AARCH64_OPND_CLASS_ADDRESS)
1445
16.0k
  break;
1446
31.3k
      num_bytes += aarch64_get_qualifier_esize (opnds[i].qualifier);
1447
31.3k
    }
1448
16.0k
  return num_bytes;
1449
16.0k
}
1450
1451
1452
/* General constraint checking based on operand code.
1453
1454
   Return 1 if OPNDS[IDX] meets the general constraint of operand code TYPE
1455
   as the IDXth operand of opcode OPCODE.  Otherwise return 0.
1456
1457
   This function has to be called after the qualifiers for all operands
1458
   have been resolved.
1459
1460
   Mismatching error message is returned in *MISMATCH_DETAIL upon request,
1461
   i.e. when MISMATCH_DETAIL is non-NULL.  This avoids the generation
1462
   of error message during the disassembling where error message is not
1463
   wanted.  We avoid the dynamic construction of strings of error messages
1464
   here (i.e. in libopcodes), as it is costly and complicated; instead, we
1465
   use a combination of error code, static string and some integer data to
1466
   represent an error.  */
1467
1468
static bool
1469
operand_general_constraint_met_p (const aarch64_opnd_info *opnds, int idx,
1470
          enum aarch64_opnd type,
1471
          const aarch64_opcode *opcode,
1472
          aarch64_operand_error *mismatch_detail)
1473
18.3M
{
1474
18.3M
  unsigned num, modifiers, shift;
1475
18.3M
  unsigned char size;
1476
18.3M
  int64_t imm, min_value, max_value;
1477
18.3M
  uint64_t uvalue, mask;
1478
18.3M
  const aarch64_opnd_info *opnd = opnds + idx;
1479
18.3M
  aarch64_opnd_qualifier_t qualifier = opnd->qualifier;
1480
18.3M
  int i;
1481
1482
18.3M
  assert (opcode->operands[idx] == opnd->type && opnd->type == type);
1483
1484
18.3M
  switch (aarch64_operands[type].op_class)
1485
18.3M
    {
1486
5.99M
    case AARCH64_OPND_CLASS_INT_REG:
1487
5.99M
      switch (type)
1488
5.99M
  {
1489
7.38k
  case AARCH64_OPND_PAIRREG:
1490
10.6k
  case AARCH64_OPND_PAIRREG_OR_XZR:
1491
    /* Check for pair of xzr registers.  */
1492
10.6k
    if (type == AARCH64_OPND_PAIRREG_OR_XZR
1493
3.26k
        && opnds[idx - 1].reg.regno == 0x1f)
1494
1.34k
      {
1495
1.34k
        if (opnds[idx].reg.regno != 0x1f)
1496
0
    {
1497
0
      set_syntax_error (mismatch_detail, idx - 1,
1498
0
          _("second reg in pair should be xzr if first is xzr"));
1499
0
      return false;
1500
0
    }
1501
1.34k
        break;
1502
1.34k
      }
1503
    /* Check pair reg constraints for instructions taking a pair of
1504
       consecutively-numbered general-purpose registers.  */
1505
10.6k
    assert (idx == 1 || idx == 2 || idx == 3 || idx == 5);
1506
9.29k
    if (opnds[idx - 1].reg.regno % 2 != 0)
1507
3.28k
      {
1508
3.28k
        set_syntax_error (mismatch_detail, idx - 1,
1509
3.28k
        _("reg pair must start from even reg"));
1510
3.28k
        return false;
1511
3.28k
      }
1512
6.01k
    if (opnds[idx].reg.regno != opnds[idx - 1].reg.regno + 1)
1513
0
      {
1514
0
        set_syntax_error (mismatch_detail, idx,
1515
0
        _("reg pair must be contiguous"));
1516
0
        return false;
1517
0
      }
1518
6.01k
    break;
1519
1520
6.01k
  case AARCH64_OPND_Rt_SYS:
1521
    /* <Xt> may be optional in some IC and TLBI instructions.  */
1522
937
    assert (idx == 1 && (aarch64_get_operand_class (opnds[0].type)
1523
937
             == AARCH64_OPND_CLASS_SYSTEM));
1524
937
    if (!(opnds[1].present && aarch64_sys_ins_reg_tlbid_xt (opnds[0].sysins_op)))
1525
911
      {
1526
911
        if (opnds[1].present
1527
892
      && !aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
1528
668
    {
1529
668
      set_other_error (mismatch_detail, idx, _("extraneous register"));
1530
668
      return false;
1531
668
    }
1532
243
        if (!opnds[1].present
1533
19
      && aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
1534
0
    {
1535
0
      set_other_error (mismatch_detail, idx, _("missing register"));
1536
0
      return false;
1537
0
    }
1538
243
      }
1539
269
    break;
1540
1541
360
  case AARCH64_OPND_Rt_LS64:
1542
360
    if (opnd->reg.regno > 22 || opnd->reg.regno % 2 != 0)
1543
346
      {
1544
346
        set_other_error (mismatch_detail, idx,
1545
346
             _("invalid Rt register number in 64-byte load/store"));
1546
346
        return false;
1547
346
      }
1548
14
    break;
1549
1550
14
  case AARCH64_OPND_Rd_NOT_ZR:
1551
0
    if (opnd->reg.regno == 31)
1552
0
      {
1553
0
        set_other_error (mismatch_detail, idx,
1554
0
             _("xzr is not allowed"));
1555
0
        return false;
1556
0
      }
1557
0
    break;
1558
1559
5.98M
  default:
1560
5.98M
    break;
1561
5.99M
  }
1562
5.99M
      break;
1563
1564
5.99M
    case AARCH64_OPND_CLASS_SVE_REG:
1565
1.63M
      switch (type)
1566
1.63M
  {
1567
5.22k
  case AARCH64_OPND_SVE_Zm3_INDEX:
1568
14.0k
  case AARCH64_OPND_SVE_Zm3_22_INDEX:
1569
14.5k
  case AARCH64_OPND_SVE_Zm3_19_INDEX:
1570
20.6k
  case AARCH64_OPND_SVE_Zm3_11_INDEX:
1571
23.9k
  case AARCH64_OPND_SVE_Zm3_10_INDEX:
1572
27.5k
  case AARCH64_OPND_SVE_Zm4_11_INDEX:
1573
33.3k
  case AARCH64_OPND_SVE_Zm4_INDEX:
1574
33.3k
    size = get_operand_fields_width (get_operand_from_code (type));
1575
33.3k
    shift = get_operand_specific_data (&aarch64_operands[type]);
1576
33.3k
    if (!check_reglane (opnd, mismatch_detail, idx,
1577
33.3k
            "z", 0, (1 << shift) - 1,
1578
33.3k
            0, (1u << (size - shift)) - 1))
1579
0
      return false;
1580
33.3k
    break;
1581
1582
33.3k
  case AARCH64_OPND_SVE_Zm1_23_INDEX:
1583
340
    size = get_operand_fields_width (get_operand_from_code (type));
1584
340
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 1))
1585
0
      return false;
1586
340
    break;
1587
1588
340
  case AARCH64_OPND_SME_Zn_INDEX2_19:
1589
1.26k
  case AARCH64_OPND_SVE_Zm2_22_INDEX:
1590
1.26k
    size = get_operand_fields_width (get_operand_from_code (type));
1591
1.26k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 3))
1592
0
      return false;
1593
1.26k
    break;
1594
1595
2.01k
  case AARCH64_OPND_SVE_Zn_INDEX:
1596
2.01k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1597
2.01k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1598
2.01k
            0, 64 / size - 1))
1599
0
      return false;
1600
2.01k
    break;
1601
1602
2.01k
  case AARCH64_OPND_SVE_Zn_5_INDEX:
1603
454
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1604
454
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1605
454
            0, 16 / size - 1))
1606
0
      return false;
1607
454
    break;
1608
1609
454
  case AARCH64_OPND_SME_PNn3_INDEX1:
1610
196
  case AARCH64_OPND_SME_PNn3_INDEX2:
1611
196
    size = get_operand_field_width (get_operand_from_code (type), 0);
1612
196
    if (!check_reglane (opnd, mismatch_detail, idx, "pn", 8, 15,
1613
196
            0, (1 << size) - 1))
1614
0
      return false;
1615
196
    break;
1616
1617
789
  case AARCH64_OPND_SVE_Zm3_12_INDEX:
1618
1.05k
  case AARCH64_OPND_SME_Zn_INDEX1_16:
1619
1.28k
  case AARCH64_OPND_SME_Zn_INDEX2_15:
1620
1.91k
  case AARCH64_OPND_SME_Zn_INDEX2_16:
1621
2.00k
  case AARCH64_OPND_SME_Zn_INDEX3_14:
1622
2.23k
  case AARCH64_OPND_SME_Zn_INDEX3_15:
1623
2.41k
  case AARCH64_OPND_SME_Zn_INDEX4_14:
1624
2.46k
  case AARCH64_OPND_SVE_Zn0_INDEX:
1625
2.56k
  case AARCH64_OPND_SVE_Zn1_17_INDEX:
1626
2.68k
  case AARCH64_OPND_SVE_Zn2_18_INDEX:
1627
3.09k
  case AARCH64_OPND_SVE_Zn3_22_INDEX:
1628
3.19k
  case AARCH64_OPND_SVE_Zd0_INDEX:
1629
3.29k
  case AARCH64_OPND_SVE_Zd1_17_INDEX:
1630
3.38k
  case AARCH64_OPND_SVE_Zd2_18_INDEX:
1631
3.48k
  case AARCH64_OPND_SVE_Zd3_22_INDEX:
1632
3.48k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1633
3.48k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1634
3.48k
            0, (1 << size) - 1))
1635
0
      return false;
1636
3.48k
    break;
1637
1638
3.48k
  case AARCH64_OPND_SME_Zm_INDEX1:
1639
3.14k
  case AARCH64_OPND_SME_Zm_INDEX2:
1640
3.38k
  case AARCH64_OPND_SME_Zm_INDEX2_3:
1641
4.97k
  case AARCH64_OPND_SME_Zm_INDEX3_1:
1642
7.47k
  case AARCH64_OPND_SME_Zm_INDEX3_2:
1643
8.14k
  case AARCH64_OPND_SME_Zm_INDEX3_3:
1644
12.5k
  case AARCH64_OPND_SME_Zm_INDEX3_10:
1645
14.8k
  case AARCH64_OPND_SME_Zm_INDEX4_1:
1646
16.4k
  case AARCH64_OPND_SME_Zm_INDEX4_2:
1647
33.0k
  case AARCH64_OPND_SME_Zm_INDEX4_3:
1648
39.4k
  case AARCH64_OPND_SME_Zm_INDEX4_10:
1649
39.4k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1650
39.4k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 15,
1651
39.4k
            0, (1 << size) - 1))
1652
0
      return false;
1653
39.4k
    break;
1654
1655
39.4k
  case AARCH64_OPND_SME_Zk_INDEX:
1656
5.12k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 3))
1657
0
      return false;
1658
5.12k
    if ((opnd->reglane.regno & 20) != 20)
1659
0
      {
1660
0
        set_other_error (mismatch_detail, idx,
1661
0
             _("register out of range"));
1662
0
        return false;
1663
0
      }
1664
5.12k
    break;
1665
1666
8.43k
  case AARCH64_OPND_SME_Zm:
1667
8.46k
  case AARCH64_OPND_SME_Zm_17:
1668
8.46k
    if (opnd->reg.regno > 15)
1669
0
      {
1670
0
        set_invalid_regno_error (mismatch_detail, idx, "z", 0, 15);
1671
0
        return false;
1672
0
      }
1673
8.46k
    break;
1674
1675
10.3k
  case AARCH64_OPND_SME_Zn_6_3:
1676
10.3k
    if (opnd->reg.regno > 15 || opnd->reg.regno % 2 != 0)
1677
0
      {
1678
0
        set_other_error (mismatch_detail, idx,
1679
0
             _("register out of range"));
1680
0
        return false;
1681
0
      }
1682
10.3k
    break;
1683
1684
10.3k
  case AARCH64_OPND_SME_Zm_17_3:
1685
10.1k
    if (opnd->reg.regno < 16 || opnd->reg.regno % 2 != 0)
1686
0
      {
1687
0
        set_other_error (mismatch_detail, idx,
1688
0
             _("register out of range"));
1689
0
        return false;
1690
0
      }
1691
10.1k
    break;
1692
1693
10.1k
  case AARCH64_OPND_SME_PnT_Wm_imm:
1694
9.10k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1695
9.10k
    max_value = 16 / size - 1;
1696
9.10k
    if (!check_za_access (opnd, mismatch_detail, idx,
1697
9.10k
        12, max_value, 1, 0, get_opcode_dependent_value (opcode)))
1698
0
      return false;
1699
9.10k
    break;
1700
1701
1.51M
  default:
1702
1.51M
    break;
1703
1.63M
  }
1704
1.63M
      break;
1705
1706
1.63M
    case AARCH64_OPND_CLASS_SVE_REGLIST:
1707
350k
      switch (type)
1708
350k
  {
1709
816
  case AARCH64_OPND_SME_Pdx2:
1710
22.8k
  case AARCH64_OPND_SME_Zdnx2:
1711
30.7k
  case AARCH64_OPND_SME_Zdnx4:
1712
31.1k
  case AARCH64_OPND_SME_Znx2_6_3:
1713
31.7k
  case AARCH64_OPND_SME_Zmx2_17_3:
1714
34.4k
  case AARCH64_OPND_SME_Zmx2:
1715
35.0k
  case AARCH64_OPND_SME_Zmx4:
1716
52.9k
  case AARCH64_OPND_SME_Znx2:
1717
53.0k
  case AARCH64_OPND_SME_Znx2_BIT_INDEX:
1718
58.8k
  case AARCH64_OPND_SME_Znx4:
1719
58.8k
    num = get_operand_specific_data (&aarch64_operands[type]);
1720
58.8k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1721
0
      return false;
1722
58.8k
    if (((opnd->reglist.first_regno % num) != 0)
1723
58.8k
        || (type == AARCH64_OPND_SME_Znx2_6_3
1724
422
      && opnd->reglist.first_regno > 15)
1725
58.8k
        || (type == AARCH64_OPND_SME_Zmx2_17_3
1726
584
      && opnd->reglist.first_regno < 16))
1727
0
      {
1728
0
        set_other_error (mismatch_detail, idx,
1729
0
             _("start register out of range"));
1730
0
        return false;
1731
0
      }
1732
58.8k
    break;
1733
1734
58.8k
  case AARCH64_OPND_SME_Ztx2_STRIDED:
1735
12.1k
  case AARCH64_OPND_SME_Ztx4_STRIDED:
1736
    /* 2-register lists have a stride of 8 and 4-register lists
1737
       have a stride of 4.  */
1738
12.1k
    num = get_operand_specific_data (&aarch64_operands[type]);
1739
12.1k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 16 / num))
1740
0
      return false;
1741
12.1k
    num = 16 | (opnd->reglist.stride - 1);
1742
12.1k
    if ((opnd->reglist.first_regno & ~num) != 0)
1743
0
      {
1744
0
        set_other_error (mismatch_detail, idx,
1745
0
             _("start register out of range"));
1746
0
        return false;
1747
0
      }
1748
12.1k
    break;
1749
1750
12.1k
  case AARCH64_OPND_SME_PdxN:
1751
12.2k
  case AARCH64_OPND_SVE_ZnxN:
1752
278k
  case AARCH64_OPND_SVE_ZtxN:
1753
278k
    num = get_opcode_dependent_value (opcode);
1754
278k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1755
0
      return false;
1756
278k
    break;
1757
1758
278k
  case AARCH64_OPND_SME_Zmx2_INDEX_22:
1759
343
    num = get_operand_specific_data (&aarch64_operands[type]);
1760
343
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1761
0
        return false;
1762
343
    break;
1763
1764
374
  case AARCH64_OPND_SME_Zn7xN_UNTYPED:
1765
374
    num = get_opcode_dependent_value (opcode);
1766
374
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1767
0
        return false;
1768
374
    if (opnd->reglist.first_regno > 7)
1769
0
    {
1770
0
      set_other_error (mismatch_detail, idx, _("start register out of range"));
1771
0
      return false;
1772
0
    }
1773
374
    break;
1774
1775
374
  default:
1776
0
    abort ();
1777
350k
  }
1778
350k
      break;
1779
1780
350k
    case AARCH64_OPND_CLASS_ZA_ACCESS:
1781
184k
      switch (type)
1782
184k
  {
1783
1.55k
  case AARCH64_OPND_SME_ZA_HV_idx_src:
1784
78.3k
  case AARCH64_OPND_SME_ZA_HV_idx_dest:
1785
122k
  case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
1786
122k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1787
122k
    max_value = 16 / size - 1;
1788
122k
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, 1,
1789
122k
        get_opcode_dependent_value (opcode),
1790
122k
        get_opcode_dependent_vg_status (opcode)))
1791
0
      return false;
1792
122k
    break;
1793
1794
122k
  case AARCH64_OPND_SME_ZA_array_off4:
1795
955
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
1796
955
        get_opcode_dependent_value (opcode),
1797
955
        get_opcode_dependent_vg_status (opcode)))
1798
0
      return false;
1799
955
    break;
1800
1801
10.4k
  case AARCH64_OPND_SME_ZA_array_off3_0:
1802
11.3k
  case AARCH64_OPND_SME_ZA_array_off3_5:
1803
11.3k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 1,
1804
11.3k
        get_opcode_dependent_value (opcode),
1805
11.3k
        get_opcode_dependent_vg_status (opcode)))
1806
0
      return false;
1807
11.3k
    break;
1808
1809
11.3k
  case AARCH64_OPND_SME_ZA_array_off1x4:
1810
6.16k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 1, 4,
1811
6.16k
        get_opcode_dependent_value (opcode),
1812
6.16k
        get_opcode_dependent_vg_status (opcode)))
1813
0
      return false;
1814
6.16k
    break;
1815
1816
6.16k
  case AARCH64_OPND_SME_ZA_array_off2x2:
1817
5.89k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 2,
1818
5.89k
        get_opcode_dependent_value (opcode),
1819
5.89k
        get_opcode_dependent_vg_status (opcode)))
1820
0
      return false;
1821
5.89k
    break;
1822
1823
7.60k
  case AARCH64_OPND_SME_ZA_array_off2x4:
1824
7.60k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 4,
1825
7.60k
        get_opcode_dependent_value (opcode),
1826
7.60k
        get_opcode_dependent_vg_status (opcode)))
1827
0
      return false;
1828
7.60k
    break;
1829
1830
21.0k
  case AARCH64_OPND_SME_ZA_array_off3x2:
1831
21.0k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 2,
1832
21.0k
        get_opcode_dependent_value (opcode),
1833
21.0k
        get_opcode_dependent_vg_status (opcode)))
1834
0
      return false;
1835
21.0k
    break;
1836
1837
21.0k
  case AARCH64_OPND_SME_ZA_array_vrsb_1:
1838
157
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 7, 2,
1839
157
        get_opcode_dependent_value (opcode),
1840
157
        get_opcode_dependent_vg_status (opcode)))
1841
0
      return false;
1842
157
    break;
1843
1844
157
  case AARCH64_OPND_SME_ZA_array_vrsh_1:
1845
22
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 3, 2,
1846
22
        get_opcode_dependent_value (opcode),
1847
22
        get_opcode_dependent_vg_status (opcode)))
1848
0
      return false;
1849
22
    break;
1850
1851
116
  case AARCH64_OPND_SME_ZA_array_vrss_1:
1852
116
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 1, 2,
1853
116
        get_opcode_dependent_value (opcode),
1854
116
        get_opcode_dependent_vg_status (opcode)))
1855
0
      return false;
1856
116
    break;
1857
1858
253
  case AARCH64_OPND_SME_ZA_array_vrsd_1:
1859
253
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 0, 2,
1860
253
        get_opcode_dependent_value (opcode),
1861
253
        get_opcode_dependent_vg_status (opcode)))
1862
0
      return false;
1863
253
    break;
1864
1865
318
  case AARCH64_OPND_SME_ZA_array_vrsb_2:
1866
318
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 3, 4,
1867
318
        get_opcode_dependent_value (opcode),
1868
318
        get_opcode_dependent_vg_status (opcode)))
1869
0
      return false;
1870
318
    break;
1871
1872
537
  case AARCH64_OPND_SME_ZA_array_vrsh_2:
1873
537
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 1, 4,
1874
537
        get_opcode_dependent_value (opcode),
1875
537
        get_opcode_dependent_vg_status (opcode)))
1876
0
      return false;
1877
537
    break;
1878
1879
780
  case AARCH64_OPND_SME_ZA_ARRAY4:
1880
780
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
1881
780
        get_opcode_dependent_value (opcode),
1882
780
        get_opcode_dependent_vg_status (opcode)))
1883
0
      return false;
1884
780
    break;
1885
1886
780
  case AARCH64_OPND_SME_ZA_array_vrss_2:
1887
446
  case AARCH64_OPND_SME_ZA_array_vrsd_2:
1888
446
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 0, 4,
1889
446
        get_opcode_dependent_value (opcode),
1890
446
        get_opcode_dependent_vg_status (opcode)))
1891
0
      return false;
1892
446
    break;
1893
1894
5.09k
  case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
1895
6.76k
  case AARCH64_OPND_SME_ZA_HV_idx_destxN:
1896
6.76k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1897
6.76k
    num = get_opcode_dependent_value (opcode);
1898
6.76k
    max_value = 16 / num / size;
1899
6.76k
    if (max_value > 0)
1900
6.51k
      max_value -= 1;
1901
6.76k
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, num,
1902
6.76k
        0, get_opcode_dependent_value (opcode)))
1903
0
      return false;
1904
6.76k
    break;
1905
1906
6.76k
  default:
1907
0
    abort ();
1908
184k
  }
1909
184k
      break;
1910
1911
1.01M
    case AARCH64_OPND_CLASS_PRED_REG:
1912
1.01M
      switch (type)
1913
1.01M
  {
1914
2.51k
  case AARCH64_OPND_SME_PNd3:
1915
31.3k
  case AARCH64_OPND_SME_PNg3:
1916
31.3k
    if (opnd->reg.regno < 8)
1917
0
      {
1918
0
        set_invalid_regno_error (mismatch_detail, idx, "pn", 8, 15);
1919
0
        return false;
1920
0
      }
1921
31.3k
    break;
1922
1923
981k
  default:
1924
981k
    if (opnd->reg.regno >= 8
1925
72.6k
        && get_operand_fields_width (get_operand_from_code (type)) == 3)
1926
0
      {
1927
0
        set_invalid_regno_error (mismatch_detail, idx, "p", 0, 7);
1928
0
        return false;
1929
0
      }
1930
981k
    break;
1931
1.01M
  }
1932
1.01M
      break;
1933
1934
1.01M
    case AARCH64_OPND_CLASS_COND:
1935
23.8k
      if (type == AARCH64_OPND_COND1
1936
506
    && (opnds[idx].cond->value & 0xe) == 0xe)
1937
0
  {
1938
    /* Not allow AL or NV.  */
1939
0
    set_syntax_error (mismatch_detail, idx, NULL);
1940
0
  }
1941
23.8k
      break;
1942
1943
3.19M
    case AARCH64_OPND_CLASS_ADDRESS:
1944
      /* Check writeback.  */
1945
3.19M
      switch (opcode->iclass)
1946
3.19M
  {
1947
236k
  case ldst_pos:
1948
319k
  case ldst_unscaled:
1949
465k
  case ldstnapair_offs:
1950
642k
  case ldstpair_off:
1951
655k
  case ldst_unpriv:
1952
655k
    if (opnd->addr.writeback == 1)
1953
0
      {
1954
0
        set_syntax_error (mismatch_detail, idx,
1955
0
        _("unexpected address writeback"));
1956
0
        return false;
1957
0
      }
1958
655k
    break;
1959
655k
  case ldst_imm10:
1960
10.4k
    if (opnd->addr.writeback == 1 && opnd->addr.preind != 1)
1961
0
      {
1962
0
        set_syntax_error (mismatch_detail, idx,
1963
0
        _("unexpected address writeback"));
1964
0
        return false;
1965
0
      }
1966
10.4k
    break;
1967
51.6k
  case ldst_imm9:
1968
295k
  case ldstpair_indexed:
1969
301k
  case asisdlsep:
1970
315k
  case asisdlsop:
1971
315k
    if (opnd->addr.writeback == 0)
1972
0
      {
1973
0
        set_syntax_error (mismatch_detail, idx,
1974
0
        _("address writeback expected"));
1975
0
        return false;
1976
0
      }
1977
315k
    break;
1978
315k
  case rcpc3:
1979
21.8k
    if (opnd->addr.writeback)
1980
1.49k
      if ((type == AARCH64_OPND_RCPC3_ADDR_PREIND_WB
1981
360
     && !opnd->addr.preind)
1982
1.49k
    || (type == AARCH64_OPND_RCPC3_ADDR_POSTIND
1983
60
        && !opnd->addr.postind))
1984
0
        {
1985
0
    set_syntax_error (mismatch_detail, idx,
1986
0
          _("unexpected address writeback"));
1987
0
    return false;
1988
0
        }
1989
1990
21.8k
    break;
1991
2.19M
  default:
1992
2.19M
    assert (opnd->addr.writeback == 0);
1993
2.19M
    break;
1994
3.19M
  }
1995
3.19M
      switch (type)
1996
3.19M
  {
1997
542k
  case AARCH64_OPND_ADDR_SIMM7:
1998
    /* Scaled signed 7 bits immediate offset.  */
1999
    /* Get the size of the data element that is accessed, which may be
2000
       different from that of the source register size,
2001
       e.g. in strb/ldrb.  */
2002
542k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2003
542k
    if (!value_in_range_p (opnd->addr.offset.imm, -64 * size, 63 * size))
2004
0
      {
2005
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2006
0
               -64 * size, 63 * size);
2007
0
        return false;
2008
0
      }
2009
542k
    if (!value_aligned_p (opnd->addr.offset.imm, size))
2010
0
      {
2011
0
        set_unaligned_error (mismatch_detail, idx, size);
2012
0
        return false;
2013
0
      }
2014
542k
    break;
2015
542k
  case AARCH64_OPND_ADDR_OFFSET:
2016
140k
  case AARCH64_OPND_ADDR_SIMM9:
2017
    /* Unscaled signed 9 bits immediate offset.  */
2018
140k
    if (!value_in_range_p (opnd->addr.offset.imm, -256, 255))
2019
0
      {
2020
0
        set_offset_out_of_range_error (mismatch_detail, idx, -256, 255);
2021
0
        return false;
2022
0
      }
2023
140k
    break;
2024
2025
140k
  case AARCH64_OPND_ADDR_SIMM10:
2026
    /* Scaled signed 10 bits immediate offset.  */
2027
10.4k
    if (!value_in_range_p (opnd->addr.offset.imm, -4096, 4088))
2028
0
      {
2029
0
        set_offset_out_of_range_error (mismatch_detail, idx, -4096, 4088);
2030
0
        return false;
2031
0
      }
2032
10.4k
    if (!value_aligned_p (opnd->addr.offset.imm, 8))
2033
0
      {
2034
0
        set_unaligned_error (mismatch_detail, idx, 8);
2035
0
        return false;
2036
0
      }
2037
10.4k
    break;
2038
2039
22.8k
  case AARCH64_OPND_ADDR_SIMM11:
2040
    /* Signed 11 bits immediate offset (multiple of 16).  */
2041
22.8k
    if (!value_in_range_p (opnd->addr.offset.imm, -1024, 1008))
2042
0
      {
2043
0
        set_offset_out_of_range_error (mismatch_detail, idx, -1024, 1008);
2044
0
        return false;
2045
0
      }
2046
2047
22.8k
    if (!value_aligned_p (opnd->addr.offset.imm, 16))
2048
0
      {
2049
0
        set_unaligned_error (mismatch_detail, idx, 16);
2050
0
        return false;
2051
0
      }
2052
22.8k
    break;
2053
2054
22.8k
  case AARCH64_OPND_ADDR_SIMM13:
2055
    /* Signed 13 bits immediate offset (multiple of 16).  */
2056
7.79k
    if (!value_in_range_p (opnd->addr.offset.imm, -4096, 4080))
2057
0
      {
2058
0
        set_offset_out_of_range_error (mismatch_detail, idx, -4096, 4080);
2059
0
        return false;
2060
0
      }
2061
2062
7.79k
    if (!value_aligned_p (opnd->addr.offset.imm, 16))
2063
0
      {
2064
0
        set_unaligned_error (mismatch_detail, idx, 16);
2065
0
        return false;
2066
0
      }
2067
7.79k
    break;
2068
2069
20.2k
  case AARCH64_OPND_SIMD_ADDR_POST:
2070
    /* AdvSIMD load/store multiple structures, post-index.  */
2071
20.2k
    assert (idx == 1);
2072
20.2k
    if (opnd->addr.offset.is_reg)
2073
17.3k
      {
2074
17.3k
        if (value_in_range_p (opnd->addr.offset.regno, 0, 30))
2075
17.3k
    return true;
2076
0
        else
2077
0
    {
2078
0
      set_other_error (mismatch_detail, idx,
2079
0
           _("invalid register offset"));
2080
0
      return false;
2081
0
    }
2082
17.3k
      }
2083
2.89k
    else
2084
2.89k
      {
2085
2.89k
        const aarch64_opnd_info *prev = &opnds[idx-1];
2086
2.89k
        unsigned num_bytes; /* total number of bytes transferred.  */
2087
        /* The opcode dependent area stores the number of elements in
2088
     each structure to be loaded/stored.  */
2089
2.89k
        int is_ld1r = get_opcode_dependent_value (opcode) == 1;
2090
2.89k
        if (opcode->operands[0] == AARCH64_OPND_LVt_AL)
2091
    /* Special handling of loading single structure to all lane.  */
2092
695
    num_bytes = (is_ld1r ? 1 : prev->reglist.num_regs)
2093
695
      * aarch64_get_qualifier_esize (prev->qualifier);
2094
2.19k
        else
2095
2.19k
    num_bytes = prev->reglist.num_regs
2096
2.19k
      * aarch64_get_qualifier_esize (prev->qualifier)
2097
2.19k
      * aarch64_get_qualifier_nelem (prev->qualifier);
2098
2.89k
        if ((int) num_bytes != opnd->addr.offset.imm)
2099
0
    {
2100
0
      set_other_error (mismatch_detail, idx,
2101
0
           _("invalid post-increment amount"));
2102
0
      return false;
2103
0
    }
2104
2.89k
      }
2105
2.89k
    break;
2106
2107
65.8k
  case AARCH64_OPND_ADDR_REGOFF:
2108
    /* Get the size of the data element that is accessed, which may be
2109
       different from that of the source register size,
2110
       e.g. in strb/ldrb.  */
2111
65.8k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2112
    /* It is either no shift or shift by the binary logarithm of SIZE.  */
2113
65.8k
    if (opnd->shifter.amount != 0
2114
37.4k
        && opnd->shifter.amount != (int)get_logsz (size))
2115
0
      {
2116
0
        set_other_error (mismatch_detail, idx,
2117
0
             _("invalid shift amount"));
2118
0
        return false;
2119
0
      }
2120
    /* Only UXTW, LSL, SXTW and SXTX are the accepted extending
2121
       operators.  */
2122
65.8k
    switch (opnd->shifter.kind)
2123
65.8k
      {
2124
1.82k
      case AARCH64_MOD_UXTW:
2125
20.1k
      case AARCH64_MOD_LSL:
2126
22.4k
      case AARCH64_MOD_SXTW:
2127
28.0k
      case AARCH64_MOD_SXTX: break;
2128
37.8k
      default:
2129
37.8k
        set_other_error (mismatch_detail, idx,
2130
37.8k
             _("invalid extend/shift operator"));
2131
37.8k
        return false;
2132
65.8k
      }
2133
28.0k
    break;
2134
2135
236k
  case AARCH64_OPND_ADDR_UIMM12:
2136
236k
    imm = opnd->addr.offset.imm;
2137
    /* Get the size of the data element that is accessed, which may be
2138
       different from that of the source register size,
2139
       e.g. in strb/ldrb.  */
2140
236k
    size = aarch64_get_qualifier_esize (qualifier);
2141
236k
    if (!value_in_range_p (opnd->addr.offset.imm, 0, 4095 * size))
2142
0
      {
2143
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2144
0
               0, 4095 * size);
2145
0
        return false;
2146
0
      }
2147
236k
    if (!value_aligned_p (opnd->addr.offset.imm, size))
2148
0
      {
2149
0
        set_unaligned_error (mismatch_detail, idx, size);
2150
0
        return false;
2151
0
      }
2152
236k
    break;
2153
2154
236k
  case AARCH64_OPND_ADDR_PCREL9:
2155
281k
  case AARCH64_OPND_ADDR_PCREL14:
2156
282k
  case AARCH64_OPND_ADDR_UPCREL16:
2157
727k
  case AARCH64_OPND_ADDR_PCREL19:
2158
1.07M
  case AARCH64_OPND_ADDR_PCREL21:
2159
1.33M
  case AARCH64_OPND_ADDR_PCREL26:
2160
1.33M
    {
2161
1.33M
      imm = opnd->imm.value;
2162
1.33M
      if (operand_need_shift_by_two (get_operand_from_code (type)))
2163
990k
        {
2164
    /* The offset value in a PC-relative branch instruction is alway
2165
       4-byte aligned and is encoded without the lowest 2 bits.  */
2166
990k
    if (!value_aligned_p (imm, 4))
2167
0
      {
2168
0
        set_unaligned_error (mismatch_detail, idx, 4);
2169
0
        return false;
2170
0
      }
2171
    /* Right shift by 2 so that we can carry out the following check
2172
       canonically.  */
2173
990k
    imm >>= 2;
2174
990k
        }
2175
2176
1.33M
      if (!check_immediate_out_of_range (imm, type, mismatch_detail, idx))
2177
0
        return false;
2178
1.33M
    }
2179
1.33M
    break;
2180
2181
1.33M
  case AARCH64_OPND_SME_ADDR_RI_U4xVL:
2182
955
    if (!value_in_range_p (opnd->addr.offset.imm, 0, 15))
2183
0
      {
2184
0
        set_offset_out_of_range_error (mismatch_detail, idx, 0, 15);
2185
0
        return false;
2186
0
      }
2187
955
    break;
2188
2189
60.4k
  case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
2190
71.4k
  case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
2191
74.8k
  case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
2192
82.2k
  case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
2193
82.2k
    min_value = -8;
2194
82.2k
    max_value = 7;
2195
91.4k
  sve_imm_offset_vl:
2196
91.4k
    assert (!opnd->addr.offset.is_reg);
2197
91.4k
    assert (opnd->addr.preind);
2198
91.4k
    num = 1 + get_operand_specific_data (&aarch64_operands[type]);
2199
91.4k
    min_value *= num;
2200
91.4k
    max_value *= num;
2201
91.4k
    if ((opnd->addr.offset.imm != 0 && !opnd->shifter.operator_present)
2202
91.4k
        || (opnd->shifter.operator_present
2203
85.7k
      && opnd->shifter.kind != AARCH64_MOD_MUL_VL))
2204
0
      {
2205
0
        set_other_error (mismatch_detail, idx,
2206
0
             _("invalid addressing mode"));
2207
0
        return false;
2208
0
      }
2209
91.4k
    if (!value_in_range_p (opnd->addr.offset.imm, min_value, max_value))
2210
0
      {
2211
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2212
0
               min_value, max_value);
2213
0
        return false;
2214
0
      }
2215
91.4k
    if (!value_aligned_p (opnd->addr.offset.imm, num))
2216
0
      {
2217
0
        set_unaligned_error (mismatch_detail, idx, num);
2218
0
        return false;
2219
0
      }
2220
91.4k
    break;
2221
2222
91.4k
  case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
2223
2.87k
    min_value = -32;
2224
2.87k
    max_value = 31;
2225
2.87k
    goto sve_imm_offset_vl;
2226
2227
6.30k
  case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
2228
6.30k
    min_value = -256;
2229
6.30k
    max_value = 255;
2230
6.30k
    goto sve_imm_offset_vl;
2231
2232
5.34k
  case AARCH64_OPND_SVE_ADDR_RI_U6:
2233
10.8k
  case AARCH64_OPND_SVE_ADDR_RI_U6x2:
2234
12.7k
  case AARCH64_OPND_SVE_ADDR_RI_U6x4:
2235
14.2k
  case AARCH64_OPND_SVE_ADDR_RI_U6x8:
2236
14.2k
    min_value = 0;
2237
14.2k
    max_value = 63;
2238
34.2k
  sve_imm_offset:
2239
34.2k
    assert (!opnd->addr.offset.is_reg);
2240
34.2k
    assert (opnd->addr.preind);
2241
34.2k
    num = 1 << get_operand_specific_data (&aarch64_operands[type]);
2242
34.2k
    min_value *= num;
2243
34.2k
    max_value *= num;
2244
34.2k
    if (opnd->shifter.operator_present
2245
34.2k
        || opnd->shifter.amount_present)
2246
0
      {
2247
0
        set_other_error (mismatch_detail, idx,
2248
0
             _("invalid addressing mode"));
2249
0
        return false;
2250
0
      }
2251
34.2k
    if (!value_in_range_p (opnd->addr.offset.imm, min_value, max_value))
2252
0
      {
2253
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2254
0
               min_value, max_value);
2255
0
        return false;
2256
0
      }
2257
34.2k
    if (!value_aligned_p (opnd->addr.offset.imm, num))
2258
0
      {
2259
0
        set_unaligned_error (mismatch_detail, idx, num);
2260
0
        return false;
2261
0
      }
2262
34.2k
    break;
2263
2264
34.2k
  case AARCH64_OPND_SVE_ADDR_RI_S4x16:
2265
3.38k
  case AARCH64_OPND_SVE_ADDR_RI_S4x32:
2266
3.38k
    min_value = -8;
2267
3.38k
    max_value = 7;
2268
3.38k
    goto sve_imm_offset;
2269
2270
16.6k
  case AARCH64_OPND_SVE_ADDR_ZX:
2271
    /* Everything is already ensured by parse_operands or
2272
       aarch64_ext_sve_addr_rr_lsl (because this is a very specific
2273
       argument type).  */
2274
16.6k
    assert (opnd->addr.offset.is_reg);
2275
16.6k
    assert (opnd->addr.preind);
2276
16.6k
    assert ((aarch64_operands[type].flags & OPD_F_NO_ZR) == 0);
2277
16.6k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2278
16.6k
    assert (opnd->shifter.operator_present == 0);
2279
16.6k
    break;
2280
2281
16.6k
  case AARCH64_OPND_SVE_ADDR_RR:
2282
20.5k
  case AARCH64_OPND_SVE_ADDR_RR_LSL1:
2283
25.5k
  case AARCH64_OPND_SVE_ADDR_RR_LSL2:
2284
40.8k
  case AARCH64_OPND_SVE_ADDR_RR_LSL3:
2285
55.8k
  case AARCH64_OPND_SVE_ADDR_RR_LSL4:
2286
64.6k
  case AARCH64_OPND_SVE_ADDR_RM:
2287
68.4k
  case AARCH64_OPND_SVE_ADDR_RM_LSL1:
2288
72.9k
  case AARCH64_OPND_SVE_ADDR_RM_LSL2:
2289
76.4k
  case AARCH64_OPND_SVE_ADDR_RM_LSL3:
2290
76.4k
  case AARCH64_OPND_SVE_ADDR_RM_LSL4:
2291
91.6k
  case AARCH64_OPND_SVE_ADDR_RX:
2292
101k
  case AARCH64_OPND_SVE_ADDR_RX_LSL1:
2293
112k
  case AARCH64_OPND_SVE_ADDR_RX_LSL2:
2294
116k
  case AARCH64_OPND_SVE_ADDR_RX_LSL3:
2295
120k
  case AARCH64_OPND_SVE_ADDR_RX_LSL4:
2296
143k
  case AARCH64_OPND_SVE_ADDR_RZ:
2297
146k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
2298
149k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
2299
151k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
2300
151k
    modifiers = 1 << AARCH64_MOD_LSL;
2301
223k
  sve_rr_operand:
2302
223k
    assert (opnd->addr.offset.is_reg);
2303
223k
    assert (opnd->addr.preind);
2304
223k
    if ((aarch64_operands[type].flags & OPD_F_NO_ZR) != 0
2305
44.1k
        && opnd->addr.offset.regno == 31)
2306
0
      {
2307
0
        set_other_error (mismatch_detail, idx,
2308
0
             _("index register xzr is not allowed"));
2309
0
        return false;
2310
0
      }
2311
223k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2312
223k
        || (opnd->shifter.amount
2313
223k
      != get_operand_specific_data (&aarch64_operands[type])))
2314
0
      {
2315
0
        set_other_error (mismatch_detail, idx,
2316
0
             _("invalid addressing mode"));
2317
0
        return false;
2318
0
      }
2319
223k
    break;
2320
2321
223k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
2322
45.3k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
2323
46.9k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
2324
55.2k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
2325
56.4k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
2326
63.5k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
2327
64.1k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
2328
71.2k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
2329
71.2k
    modifiers = (1 << AARCH64_MOD_SXTW) | (1 << AARCH64_MOD_UXTW);
2330
71.2k
    goto sve_rr_operand;
2331
2332
5.46k
  case AARCH64_OPND_SVE_ADDR_ZI_U5:
2333
11.9k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
2334
15.0k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
2335
16.6k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
2336
16.6k
    min_value = 0;
2337
16.6k
    max_value = 31;
2338
16.6k
    goto sve_imm_offset;
2339
2340
865
  case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
2341
865
    modifiers = 1 << AARCH64_MOD_LSL;
2342
1.94k
  sve_zz_operand:
2343
1.94k
    assert (opnd->addr.offset.is_reg);
2344
1.94k
    assert (opnd->addr.preind);
2345
1.94k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2346
1.94k
        || opnd->shifter.amount < 0
2347
1.94k
        || opnd->shifter.amount > 3)
2348
0
      {
2349
0
        set_other_error (mismatch_detail, idx,
2350
0
             _("invalid addressing mode"));
2351
0
        return false;
2352
0
      }
2353
1.94k
    break;
2354
2355
1.94k
  case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
2356
258
    modifiers = (1 << AARCH64_MOD_SXTW);
2357
258
    goto sve_zz_operand;
2358
2359
821
  case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
2360
821
    modifiers = 1 << AARCH64_MOD_UXTW;
2361
821
    goto sve_zz_operand;
2362
2363
13.4k
  case AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB:
2364
14.1k
  case AARCH64_OPND_RCPC3_ADDR_OPT_POSTIND:
2365
14.5k
  case AARCH64_OPND_RCPC3_ADDR_PREIND_WB:
2366
14.5k
  case AARCH64_OPND_RCPC3_ADDR_POSTIND:
2367
14.5k
    {
2368
14.5k
      int num_bytes = calc_ldst_datasize (opnds);
2369
14.5k
      int abs_offset = (type == AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB
2370
1.18k
            || type == AARCH64_OPND_RCPC3_ADDR_PREIND_WB)
2371
14.5k
        ? opnd->addr.offset.imm * -1
2372
14.5k
        : opnd->addr.offset.imm;
2373
14.5k
      if ((int) num_bytes != abs_offset
2374
13.1k
    && opnd->addr.offset.imm != 0)
2375
0
        {
2376
0
    set_other_error (mismatch_detail, idx,
2377
0
         _("invalid increment amount"));
2378
0
    return false;
2379
0
        }
2380
14.5k
    }
2381
14.5k
    break;
2382
2383
14.5k
  case AARCH64_OPND_RCPC3_ADDR_OFFSET:
2384
7.17k
    if (!value_in_range_p (opnd->addr.offset.imm, -256, 255))
2385
0
      {
2386
0
        set_imm_out_of_range_error (mismatch_detail, idx, -256, 255);
2387
0
        return false;
2388
0
      }
2389
2390
429k
  default:
2391
429k
    break;
2392
3.19M
  }
2393
3.14M
      break;
2394
2395
3.14M
    case AARCH64_OPND_CLASS_SIMD_REGLIST:
2396
57.3k
      if (type == AARCH64_OPND_LEt)
2397
19.6k
  {
2398
    /* Get the upper bound for the element index.  */
2399
19.6k
    num = 16 / aarch64_get_qualifier_esize (qualifier) - 1;
2400
19.6k
    if (!value_in_range_p (opnd->reglist.index, 0, num))
2401
0
      {
2402
0
        set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
2403
0
        return false;
2404
0
      }
2405
19.6k
  }
2406
      /* The opcode dependent area stores the number of elements in
2407
   each structure to be loaded/stored.  */
2408
57.3k
      num = get_opcode_dependent_value (opcode);
2409
57.3k
      switch (type)
2410
57.3k
  {
2411
4.02k
  case AARCH64_OPND_LVn_LUT:
2412
4.02k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2413
0
      return 0;
2414
4.02k
    break;
2415
15.6k
  case AARCH64_OPND_LVt:
2416
15.6k
    assert (num >= 1 && num <= 4);
2417
    /* Unless LD1/ST1, the number of registers should be equal to that
2418
       of the structure elements.  */
2419
15.6k
    if (num != 1 && !check_reglist (opnd, mismatch_detail, idx, num, 1))
2420
948
      return false;
2421
14.6k
    break;
2422
14.6k
  case AARCH64_OPND_LVt_AL:
2423
21.9k
  case AARCH64_OPND_LEt:
2424
21.9k
    assert (num >= 1 && num <= 4);
2425
    /* The number of registers should be equal to that of the structure
2426
       elements.  */
2427
21.9k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2428
0
      return false;
2429
21.9k
    break;
2430
21.9k
  default:
2431
15.6k
    break;
2432
57.3k
  }
2433
56.3k
      if (opnd->reglist.stride != 1)
2434
0
  {
2435
0
    set_reg_list_stride_error (mismatch_detail, idx, 1);
2436
0
    return false;
2437
0
  }
2438
56.3k
      break;
2439
2440
3.36M
    case AARCH64_OPND_CLASS_IMMEDIATE:
2441
      /* Constraint check on immediate operand.  */
2442
3.36M
      imm = opnd->imm.value;
2443
      /* E.g. imm_0_31 constrains value to be 0..31.  */
2444
3.36M
      if (qualifier_value_in_range_constraint_p (qualifier)
2445
439k
    && !value_in_range_p (imm, get_lower_bound (qualifier),
2446
439k
        get_upper_bound (qualifier)))
2447
48.7k
  {
2448
48.7k
    set_imm_out_of_range_error (mismatch_detail, idx,
2449
48.7k
              get_lower_bound (qualifier),
2450
48.7k
              get_upper_bound (qualifier));
2451
48.7k
    return false;
2452
48.7k
  }
2453
2454
3.31M
      switch (type)
2455
3.31M
  {
2456
420k
  case AARCH64_OPND_AIMM:
2457
420k
    if (opnd->shifter.kind != AARCH64_MOD_LSL)
2458
0
      {
2459
0
        set_other_error (mismatch_detail, idx,
2460
0
             _("invalid shift operator"));
2461
0
        return false;
2462
0
      }
2463
420k
    if (opnd->shifter.amount != 0 && opnd->shifter.amount != 12)
2464
0
      {
2465
0
        set_other_error (mismatch_detail, idx,
2466
0
             _("shift amount must be 0 or 12"));
2467
0
        return false;
2468
0
      }
2469
420k
    if (!value_fit_unsigned_field_p (opnd->imm.value, 12))
2470
0
      {
2471
0
        set_other_error (mismatch_detail, idx,
2472
0
             _("immediate out of range"));
2473
0
        return false;
2474
0
      }
2475
420k
    break;
2476
2477
420k
  case AARCH64_OPND_HALF:
2478
115k
    assert (idx == 1 && opnds[0].type == AARCH64_OPND_Rd);
2479
115k
    if (opnd->shifter.kind != AARCH64_MOD_LSL)
2480
0
      {
2481
0
        set_other_error (mismatch_detail, idx,
2482
0
             _("invalid shift operator"));
2483
0
        return false;
2484
0
      }
2485
115k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2486
115k
    if (!value_aligned_p (opnd->shifter.amount, 16))
2487
0
      {
2488
0
        set_other_error (mismatch_detail, idx,
2489
0
             _("shift amount must be a multiple of 16"));
2490
0
        return false;
2491
0
      }
2492
115k
    if (!value_in_range_p (opnd->shifter.amount, 0, size * 8 - 16))
2493
17.9k
      {
2494
17.9k
        set_sft_amount_out_of_range_error (mismatch_detail, idx,
2495
17.9k
             0, size * 8 - 16);
2496
17.9k
        return false;
2497
17.9k
      }
2498
97.8k
    if (opnd->imm.value < 0)
2499
0
      {
2500
0
        set_other_error (mismatch_detail, idx,
2501
0
             _("negative immediate value not allowed"));
2502
0
        return false;
2503
0
      }
2504
97.8k
    if (!value_fit_unsigned_field_p (opnd->imm.value, 16))
2505
0
      {
2506
0
        set_other_error (mismatch_detail, idx,
2507
0
             _("immediate out of range"));
2508
0
        return false;
2509
0
      }
2510
97.8k
    break;
2511
2512
97.8k
  case AARCH64_OPND_IMM_MOV:
2513
69.9k
      {
2514
69.9k
        int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2515
69.9k
        imm = opnd->imm.value;
2516
69.9k
        assert (idx == 1);
2517
69.9k
        switch (opcode->op)
2518
69.9k
    {
2519
31.5k
    case OP_MOV_IMM_WIDEN:
2520
31.5k
      imm = ~imm;
2521
      /* Fall through.  */
2522
69.2k
    case OP_MOV_IMM_WIDE:
2523
69.2k
      if (!aarch64_wide_constant_p (imm, esize == 4, NULL))
2524
0
        {
2525
0
          set_other_error (mismatch_detail, idx,
2526
0
               _("immediate out of range"));
2527
0
          return false;
2528
0
        }
2529
69.2k
      break;
2530
69.2k
    case OP_MOV_IMM_LOG:
2531
671
      if (!aarch64_logical_immediate_p (imm, esize, NULL))
2532
0
        {
2533
0
          set_other_error (mismatch_detail, idx,
2534
0
               _("immediate out of range"));
2535
0
          return false;
2536
0
        }
2537
671
      break;
2538
671
    default:
2539
0
      assert (0);
2540
0
      return false;
2541
69.9k
    }
2542
69.9k
      }
2543
69.9k
    break;
2544
2545
69.9k
  case AARCH64_OPND_NZCV:
2546
10.2k
  case AARCH64_OPND_CCMP_IMM:
2547
11.5k
  case AARCH64_OPND_EXCEPTION:
2548
1.78M
  case AARCH64_OPND_UNDEFINED:
2549
1.78M
  case AARCH64_OPND_TME_UIMM16:
2550
1.78M
  case AARCH64_OPND_UIMM4:
2551
1.78M
  case AARCH64_OPND_UIMM4_ADDG:
2552
1.78M
  case AARCH64_OPND_UIMM7:
2553
1.79M
  case AARCH64_OPND_UIMM3_OP1:
2554
1.80M
  case AARCH64_OPND_UIMM3_OP2:
2555
1.80M
  case AARCH64_OPND_SVE_UIMM3:
2556
1.83M
  case AARCH64_OPND_SVE_UIMM7:
2557
1.83M
  case AARCH64_OPND_SVE_UIMM8:
2558
1.83M
  case AARCH64_OPND_SVE_UIMM4:
2559
1.83M
  case AARCH64_OPND_SVE_UIMM8_53:
2560
1.83M
  case AARCH64_OPND_CSSC_UIMM8:
2561
1.83M
    size = get_operand_fields_width (get_operand_from_code (type));
2562
1.83M
    assert (size < 32);
2563
1.83M
    if (!value_fit_unsigned_field_p (opnd->imm.value, size))
2564
0
      {
2565
0
        set_imm_out_of_range_error (mismatch_detail, idx, 0,
2566
0
            (1u << size) - 1);
2567
0
        return false;
2568
0
      }
2569
1.83M
    break;
2570
2571
1.83M
  case AARCH64_OPND_UIMM10:
2572
    /* Scaled unsigned 10 bits immediate offset.  */
2573
4.38k
    if (!value_in_range_p (opnd->imm.value, 0, 1008))
2574
0
      {
2575
0
        set_imm_out_of_range_error (mismatch_detail, idx, 0, 1008);
2576
0
        return false;
2577
0
      }
2578
2579
4.38k
    if (!value_aligned_p (opnd->imm.value, 16))
2580
0
      {
2581
0
        set_unaligned_error (mismatch_detail, idx, 16);
2582
0
        return false;
2583
0
      }
2584
4.38k
    break;
2585
2586
13.0k
  case AARCH64_OPND_SIMM5:
2587
13.7k
  case AARCH64_OPND_SVE_SIMM5:
2588
14.1k
  case AARCH64_OPND_SVE_SIMM5B:
2589
15.1k
  case AARCH64_OPND_SVE_SIMM6:
2590
15.7k
  case AARCH64_OPND_SVE_SIMM8:
2591
17.2k
  case AARCH64_OPND_CSSC_SIMM8:
2592
17.2k
    size = get_operand_fields_width (get_operand_from_code (type));
2593
17.2k
    assert (size < 32);
2594
17.2k
    if (!value_fit_signed_field_p (opnd->imm.value, size))
2595
0
      {
2596
0
        imm_range_t rng = imm_range_min_max (size, true);
2597
0
        set_imm_out_of_range_error (mismatch_detail, idx, rng.min,
2598
0
            rng.max);
2599
0
        return false;
2600
0
      }
2601
17.2k
    break;
2602
2603
34.2k
  case AARCH64_OPND_WIDTH:
2604
34.2k
    assert (idx > 1 && opnds[idx-1].type == AARCH64_OPND_IMM
2605
34.2k
      && opnds[0].type == AARCH64_OPND_Rd);
2606
34.2k
    size = get_upper_bound (qualifier);
2607
34.2k
    if (opnd->imm.value + opnds[idx-1].imm.value > size)
2608
      /* lsb+width <= reg.size  */
2609
0
      {
2610
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1,
2611
0
            size - opnds[idx-1].imm.value);
2612
0
        return false;
2613
0
      }
2614
34.2k
    break;
2615
2616
294k
  case AARCH64_OPND_LIMM:
2617
338k
  case AARCH64_OPND_SVE_LIMM:
2618
338k
    {
2619
338k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2620
338k
      uint64_t uimm = opnd->imm.value;
2621
338k
      if (opcode->op == OP_BIC)
2622
0
        uimm = ~uimm;
2623
338k
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
2624
0
        {
2625
0
    set_other_error (mismatch_detail, idx,
2626
0
         _("immediate out of range"));
2627
0
    return false;
2628
0
        }
2629
338k
    }
2630
338k
    break;
2631
2632
338k
  case AARCH64_OPND_IMM0:
2633
585
  case AARCH64_OPND_FPIMM0:
2634
585
    if (opnd->imm.value != 0)
2635
0
      {
2636
0
        set_other_error (mismatch_detail, idx,
2637
0
             _("immediate zero expected"));
2638
0
        return false;
2639
0
      }
2640
585
    break;
2641
2642
872
  case AARCH64_OPND_IMM_ROT1:
2643
17.6k
  case AARCH64_OPND_IMM_ROT2:
2644
27.2k
  case AARCH64_OPND_SVE_IMM_ROT2:
2645
27.2k
    if (opnd->imm.value != 0
2646
19.6k
        && opnd->imm.value != 90
2647
13.0k
        && opnd->imm.value != 180
2648
8.36k
        && opnd->imm.value != 270)
2649
0
      {
2650
0
        set_other_error (mismatch_detail, idx,
2651
0
             _("rotate expected to be 0, 90, 180 or 270"));
2652
0
        return false;
2653
0
      }
2654
27.2k
    break;
2655
2656
27.2k
  case AARCH64_OPND_IMM_ROT3:
2657
1.04k
  case AARCH64_OPND_SVE_IMM_ROT1:
2658
1.43k
  case AARCH64_OPND_SVE_IMM_ROT3:
2659
1.43k
    if (opnd->imm.value != 90 && opnd->imm.value != 270)
2660
0
      {
2661
0
        set_other_error (mismatch_detail, idx,
2662
0
             _("rotate expected to be 90 or 270"));
2663
0
        return false;
2664
0
      }
2665
1.43k
    break;
2666
2667
1.43k
  case AARCH64_OPND_SHLL_IMM:
2668
322
    assert (idx == 2);
2669
322
    size = 8 * aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
2670
322
    if (opnd->imm.value != size)
2671
0
      {
2672
0
        set_other_error (mismatch_detail, idx,
2673
0
             _("invalid shift amount"));
2674
0
        return false;
2675
0
      }
2676
322
    break;
2677
2678
8.65k
  case AARCH64_OPND_IMM_VLSL:
2679
8.65k
    size = aarch64_get_qualifier_esize (qualifier);
2680
8.65k
    if (!value_in_range_p (opnd->imm.value, 0, size * 8 - 1))
2681
0
      {
2682
0
        set_imm_out_of_range_error (mismatch_detail, idx, 0,
2683
0
            size * 8 - 1);
2684
0
        return false;
2685
0
      }
2686
8.65k
    break;
2687
2688
13.2k
  case AARCH64_OPND_IMM_VLSR:
2689
13.2k
    size = aarch64_get_qualifier_esize (qualifier);
2690
13.2k
    if (!value_in_range_p (opnd->imm.value, 1, size * 8))
2691
0
      {
2692
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, size * 8);
2693
0
        return false;
2694
0
      }
2695
13.2k
    break;
2696
2697
13.2k
  case AARCH64_OPND_SIMD_IMM:
2698
4.29k
  case AARCH64_OPND_SIMD_IMM_SFT:
2699
    /* Qualifier check.  */
2700
4.29k
    switch (qualifier)
2701
4.29k
      {
2702
3.20k
      case AARCH64_OPND_QLF_LSL:
2703
3.20k
        if (opnd->shifter.kind != AARCH64_MOD_LSL)
2704
0
    {
2705
0
      set_other_error (mismatch_detail, idx,
2706
0
           _("invalid shift operator"));
2707
0
      return false;
2708
0
    }
2709
3.20k
        break;
2710
3.20k
      case AARCH64_OPND_QLF_MSL:
2711
484
        if (opnd->shifter.kind != AARCH64_MOD_MSL)
2712
0
    {
2713
0
      set_other_error (mismatch_detail, idx,
2714
0
           _("invalid shift operator"));
2715
0
      return false;
2716
0
    }
2717
484
        break;
2718
603
      case AARCH64_OPND_QLF_NIL:
2719
603
        if (opnd->shifter.kind != AARCH64_MOD_NONE)
2720
0
    {
2721
0
      set_other_error (mismatch_detail, idx,
2722
0
           _("shift is not permitted"));
2723
0
      return false;
2724
0
    }
2725
603
        break;
2726
603
      default:
2727
0
        assert (0);
2728
0
        return false;
2729
4.29k
      }
2730
    /* Is the immediate valid?  */
2731
4.29k
    assert (idx == 1);
2732
4.29k
    if (aarch64_get_qualifier_esize (opnds[0].qualifier) != 8)
2733
3.68k
      {
2734
        /* uimm8 or simm8 */
2735
3.68k
        if (!value_in_range_p (opnd->imm.value, -128, 255))
2736
0
    {
2737
0
      set_imm_out_of_range_error (mismatch_detail, idx, -128, 255);
2738
0
      return false;
2739
0
    }
2740
3.68k
      }
2741
603
    else if (aarch64_shrink_expanded_imm8 (opnd->imm.value) < 0)
2742
0
      {
2743
        /* uimm64 is not
2744
     'aaaaaaaabbbbbbbbccccccccddddddddeeeeeeee
2745
     ffffffffgggggggghhhhhhhh'.  */
2746
0
        set_other_error (mismatch_detail, idx,
2747
0
             _("invalid value for immediate"));
2748
0
        return false;
2749
0
      }
2750
    /* Is the shift amount valid?  */
2751
4.29k
    switch (opnd->shifter.kind)
2752
4.29k
      {
2753
3.20k
      case AARCH64_MOD_LSL:
2754
3.20k
        size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2755
3.20k
        if (!value_in_range_p (opnd->shifter.amount, 0, (size - 1) * 8))
2756
0
    {
2757
0
      set_sft_amount_out_of_range_error (mismatch_detail, idx, 0,
2758
0
                 (size - 1) * 8);
2759
0
      return false;
2760
0
    }
2761
3.20k
        if (!value_aligned_p (opnd->shifter.amount, 8))
2762
0
    {
2763
0
      set_unaligned_error (mismatch_detail, idx, 8);
2764
0
      return false;
2765
0
    }
2766
3.20k
        break;
2767
3.20k
      case AARCH64_MOD_MSL:
2768
        /* Only 8 and 16 are valid shift amount.  */
2769
484
        if (opnd->shifter.amount != 8 && opnd->shifter.amount != 16)
2770
0
    {
2771
0
      set_other_error (mismatch_detail, idx,
2772
0
           _("shift amount must be 0 or 16"));
2773
0
      return false;
2774
0
    }
2775
484
        break;
2776
603
      default:
2777
603
        if (opnd->shifter.kind != AARCH64_MOD_NONE)
2778
0
    {
2779
0
      set_other_error (mismatch_detail, idx,
2780
0
           _("invalid shift operator"));
2781
0
      return false;
2782
0
    }
2783
603
        break;
2784
4.29k
      }
2785
4.29k
    break;
2786
2787
4.29k
  case AARCH64_OPND_FPIMM:
2788
2.30k
  case AARCH64_OPND_SIMD_FPIMM:
2789
3.98k
  case AARCH64_OPND_SVE_FPIMM8:
2790
3.98k
    if (opnd->imm.is_fp == 0)
2791
0
      {
2792
0
        set_other_error (mismatch_detail, idx,
2793
0
             _("floating-point immediate expected"));
2794
0
        return false;
2795
0
      }
2796
    /* The value is expected to be an 8-bit floating-point constant with
2797
       sign, 3-bit exponent and normalized 4 bits of precision, encoded
2798
       in "a:b:c:d:e:f:g:h" or FLD_imm8 (depending on the type of the
2799
       instruction).  */
2800
3.98k
    if (!value_in_range_p (opnd->imm.value, 0, 255))
2801
0
      {
2802
0
        set_other_error (mismatch_detail, idx,
2803
0
             _("immediate out of range"));
2804
0
        return false;
2805
0
      }
2806
3.98k
    if (opnd->shifter.kind != AARCH64_MOD_NONE)
2807
0
      {
2808
0
        set_other_error (mismatch_detail, idx,
2809
0
             _("invalid shift operator"));
2810
0
        return false;
2811
0
      }
2812
3.98k
    break;
2813
2814
3.98k
  case AARCH64_OPND_SVE_AIMM:
2815
2.64k
    min_value = 0;
2816
21.6k
  sve_aimm:
2817
21.6k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2818
21.6k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2819
21.6k
    mask = ~((uint64_t) -1 << (size * 4) << (size * 4));
2820
21.6k
    uvalue = opnd->imm.value;
2821
21.6k
    shift = opnd->shifter.amount;
2822
21.6k
    if (size == 1)
2823
4.08k
      {
2824
4.08k
        if (shift != 0)
2825
146
    {
2826
146
      set_other_error (mismatch_detail, idx,
2827
146
           _("no shift amount allowed for"
2828
146
             " 8-bit constants"));
2829
146
      return false;
2830
146
    }
2831
4.08k
      }
2832
17.5k
    else
2833
17.5k
      {
2834
17.5k
        if (shift != 0 && shift != 8)
2835
0
    {
2836
0
      set_other_error (mismatch_detail, idx,
2837
0
           _("shift amount must be 0 or 8"));
2838
0
      return false;
2839
0
    }
2840
17.5k
        if (shift == 0 && (uvalue & 0xff) == 0)
2841
7.50k
    {
2842
7.50k
      shift = 8;
2843
7.50k
      uvalue = (int64_t) uvalue / 256;
2844
7.50k
    }
2845
17.5k
      }
2846
21.4k
    mask >>= shift;
2847
21.4k
    if ((uvalue & mask) != uvalue && (uvalue | ~mask) != uvalue)
2848
1.65k
      {
2849
1.65k
        set_other_error (mismatch_detail, idx,
2850
1.65k
             _("immediate too big for element size"));
2851
1.65k
        return false;
2852
1.65k
      }
2853
19.8k
    uvalue = (uvalue - min_value) & mask;
2854
19.8k
    if (uvalue > 0xff)
2855
0
      {
2856
0
        set_other_error (mismatch_detail, idx,
2857
0
             _("invalid arithmetic immediate"));
2858
0
        return false;
2859
0
      }
2860
19.8k
    break;
2861
2862
19.8k
  case AARCH64_OPND_SVE_ASIMM:
2863
18.9k
    min_value = -128;
2864
18.9k
    goto sve_aimm;
2865
2866
98
  case AARCH64_OPND_SVE_I1_HALF_ONE:
2867
98
    assert (opnd->imm.is_fp);
2868
98
    if (opnd->imm.value != 0x3f000000 && opnd->imm.value != 0x3f800000)
2869
0
      {
2870
0
        set_other_error (mismatch_detail, idx,
2871
0
             _("floating-point value must be 0.5 or 1.0"));
2872
0
        return false;
2873
0
      }
2874
98
    break;
2875
2876
198
  case AARCH64_OPND_SVE_I1_HALF_TWO:
2877
198
    assert (opnd->imm.is_fp);
2878
198
    if (opnd->imm.value != 0x3f000000 && opnd->imm.value != 0x40000000)
2879
0
      {
2880
0
        set_other_error (mismatch_detail, idx,
2881
0
             _("floating-point value must be 0.5 or 2.0"));
2882
0
        return false;
2883
0
      }
2884
198
    break;
2885
2886
1.06k
  case AARCH64_OPND_SVE_I1_ZERO_ONE:
2887
1.06k
    assert (opnd->imm.is_fp);
2888
1.06k
    if (opnd->imm.value != 0 && opnd->imm.value != 0x3f800000)
2889
0
      {
2890
0
        set_other_error (mismatch_detail, idx,
2891
0
             _("floating-point value must be 0.0 or 1.0"));
2892
0
        return false;
2893
0
      }
2894
1.06k
    break;
2895
2896
1.06k
  case AARCH64_OPND_SVE_INV_LIMM:
2897
0
    {
2898
0
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2899
0
      uint64_t uimm = ~opnd->imm.value;
2900
0
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
2901
0
        {
2902
0
    set_other_error (mismatch_detail, idx,
2903
0
         _("immediate out of range"));
2904
0
    return false;
2905
0
        }
2906
0
    }
2907
0
    break;
2908
2909
3.22k
  case AARCH64_OPND_SVE_LIMM_MOV:
2910
3.22k
    {
2911
3.22k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2912
3.22k
      uint64_t uimm = opnd->imm.value;
2913
3.22k
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
2914
0
        {
2915
0
    set_other_error (mismatch_detail, idx,
2916
0
         _("immediate out of range"));
2917
0
    return false;
2918
0
        }
2919
3.22k
      if (!aarch64_sve_dupm_mov_immediate_p (uimm, esize))
2920
0
        {
2921
0
    set_other_error (mismatch_detail, idx,
2922
0
         _("invalid replicated MOV immediate"));
2923
0
    return false;
2924
0
        }
2925
3.22k
    }
2926
3.22k
    break;
2927
2928
7.09k
  case AARCH64_OPND_SVE_PATTERN_SCALED:
2929
7.09k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL);
2930
7.09k
    if (!value_in_range_p (opnd->shifter.amount, 1, 16))
2931
0
      {
2932
0
        set_multiplier_out_of_range_error (mismatch_detail, idx, 1, 16);
2933
0
        return false;
2934
0
      }
2935
7.09k
    break;
2936
2937
7.09k
  case AARCH64_OPND_SVE_SHLIMM_PRED:
2938
1.74k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED:
2939
2.65k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
2940
2.65k
    size = aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
2941
2.65k
    if (!value_in_range_p (opnd->imm.value, 0, 8 * size - 1))
2942
0
      {
2943
0
        set_imm_out_of_range_error (mismatch_detail, idx,
2944
0
            0, 8 * size - 1);
2945
0
        return false;
2946
0
      }
2947
2.65k
    break;
2948
2949
2.65k
  case AARCH64_OPND_SME_SHRIMM3:
2950
376
  case AARCH64_OPND_SME_SHRIMM4:
2951
376
    size = 1 << get_operand_fields_width (get_operand_from_code (type));
2952
376
    if (!value_in_range_p (opnd->imm.value, 1, size))
2953
0
      {
2954
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, size);
2955
0
        return false;
2956
0
      }
2957
376
    break;
2958
2959
376
  case AARCH64_OPND_SME_SHRIMM5:
2960
2.26k
  case AARCH64_OPND_SVE_SHRIMM_PRED:
2961
4.39k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED:
2962
9.26k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
2963
9.26k
    num = (type == AARCH64_OPND_SVE_SHRIMM_UNPRED_22) ? 2 : 1;
2964
9.26k
    size = aarch64_get_qualifier_esize (opnds[idx - num].qualifier);
2965
9.26k
    if (!value_in_range_p (opnd->imm.value, 1, 8 * size))
2966
0
      {
2967
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, 8*size);
2968
0
        return false;
2969
0
      }
2970
9.26k
    break;
2971
2972
9.26k
  case AARCH64_OPND_SME_ZT0_INDEX:
2973
110
    if (!value_in_range_p (opnd->imm.value, 0, 56))
2974
0
      {
2975
0
        set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, 56);
2976
0
        return false;
2977
0
      }
2978
110
    if (opnd->imm.value % 8 != 0)
2979
0
      {
2980
0
        set_other_error (mismatch_detail, idx,
2981
0
             _("byte index must be a multiple of 8"));
2982
0
        return false;
2983
0
      }
2984
110
    break;
2985
2986
333
  case AARCH64_OPND_SME_ZT0_INDEX_MUL_VL:
2987
333
    if (!value_in_range_p (opnd->imm.value, 0, 3))
2988
0
      {
2989
0
        set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, 3);
2990
0
        return 0;
2991
0
      }
2992
333
    break;
2993
2994
374k
  default:
2995
374k
    break;
2996
3.31M
  }
2997
3.30M
      break;
2998
2999
3.30M
    case AARCH64_OPND_CLASS_SYSTEM:
3000
66.5k
      switch (type)
3001
66.5k
  {
3002
194
  case AARCH64_OPND_PSTATEFIELD:
3003
399
    for (i = 0; aarch64_pstatefields[i].name; ++i)
3004
399
      if (aarch64_pstatefields[i].value == opnd->pstatefield)
3005
194
        break;
3006
194
    assert (aarch64_pstatefields[i].name);
3007
194
    assert (idx == 0 && opnds[1].type == AARCH64_OPND_UIMM4);
3008
194
    max_value = F_GET_REG_MAX_VALUE (aarch64_pstatefields[i].flags);
3009
194
    if (opnds[1].imm.value < 0 || opnds[1].imm.value > max_value)
3010
126
      {
3011
126
        set_imm_out_of_range_error (mismatch_detail, 1, 0, max_value);
3012
126
        return false;
3013
126
      }
3014
68
    break;
3015
46.7k
  case AARCH64_OPND_PRFOP:
3016
46.7k
    if (opcode->iclass == ldst_regoff && opnd->prfop->value >= 24)
3017
1.10k
      {
3018
1.10k
        set_other_error (mismatch_detail, idx,
3019
1.10k
             _("the register-index form of PRFM does"
3020
1.10k
         " not accept opcodes in the range 24-31"));
3021
1.10k
        return false;
3022
1.10k
      }
3023
45.6k
    break;
3024
45.6k
  default:
3025
19.6k
    break;
3026
66.5k
  }
3027
65.3k
      break;
3028
3029
101k
    case AARCH64_OPND_CLASS_SIMD_ELEMENT:
3030
      /* Get the upper bound for the element index.  */
3031
101k
      if (opcode->op == OP_FCMLA_ELEM)
3032
  /* FCMLA index range depends on the vector size of other operands
3033
     and is halfed because complex numbers take two elements.  */
3034
7.80k
  num = aarch64_get_qualifier_nelem (opnds[0].qualifier)
3035
7.80k
        * aarch64_get_qualifier_esize (opnds[0].qualifier) / 2;
3036
93.4k
      else if (opcode->iclass == lut)
3037
4.02k
  {
3038
4.02k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
3039
4.02k
    if (!check_reglane (opnd, mismatch_detail, idx, "v", 0, 31,
3040
4.02k
            0, (1 << size) - 1))
3041
0
      return 0;
3042
4.02k
    break;
3043
4.02k
  }
3044
89.4k
      else
3045
89.4k
  num = 16;
3046
97.2k
      num = num / aarch64_get_qualifier_esize (qualifier) - 1;
3047
97.2k
      assert (aarch64_get_qualifier_nelem (qualifier) == 1);
3048
3049
      /* Index out-of-range.  */
3050
97.2k
      if (!value_in_range_p (opnd->reglane.index, 0, num))
3051
593
  {
3052
593
    set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
3053
593
    return false;
3054
593
  }
3055
      /* SMLAL<Q> <Vd>.<Ta>, <Vn>.<Tb>, <Vm>.<Ts>[<index>].
3056
   <Vm> Is the vector register (V0-V31) or (V0-V15), whose
3057
   number is encoded in "size:M:Rm":
3058
   size <Vm>
3059
   00   RESERVED
3060
   01   0:Rm
3061
   10   M:Rm
3062
   11   RESERVED  */
3063
96.6k
      if (type == AARCH64_OPND_Em16
3064
46.5k
    && (qualifier == AARCH64_OPND_QLF_S_H
3065
10.4k
        || qualifier == AARCH64_OPND_QLF_S_2B)
3066
39.1k
    && !value_in_range_p (opnd->reglane.regno, 0, 15))
3067
0
  {
3068
0
    set_regno_out_of_range_error (mismatch_detail, idx, 0, 15);
3069
0
    return false;
3070
0
  }
3071
96.6k
      if (type == AARCH64_OPND_Em8
3072
3.51k
    && !value_in_range_p (opnd->reglane.regno, 0, 7))
3073
0
  {
3074
0
    set_regno_out_of_range_error (mismatch_detail, idx, 0, 7);
3075
0
    return 0;
3076
0
  }
3077
96.6k
      break;
3078
3079
592k
    case AARCH64_OPND_CLASS_MODIFIED_REG:
3080
592k
      assert (idx == 1 || idx == 2);
3081
592k
      switch (type)
3082
592k
  {
3083
53.9k
  case AARCH64_OPND_Rm_EXT:
3084
53.9k
    if (!aarch64_extend_operator_p (opnd->shifter.kind)
3085
0
        && opnd->shifter.kind != AARCH64_MOD_LSL)
3086
0
      {
3087
0
        set_other_error (mismatch_detail, idx,
3088
0
             _("extend operator expected"));
3089
0
        return false;
3090
0
      }
3091
    /* It is not optional unless at least one of "Rd" or "Rn" is '11111'
3092
       (i.e. SP), in which case it defaults to LSL. The LSL alias is
3093
       only valid when "Rd" or "Rn" is '11111', and is preferred in that
3094
       case.  */
3095
53.9k
    if (!aarch64_stack_pointer_p (opnds + 0)
3096
52.6k
        && (idx != 2 || !aarch64_stack_pointer_p (opnds + 1)))
3097
50.6k
      {
3098
50.6k
        if (!opnd->shifter.operator_present)
3099
0
    {
3100
0
      set_other_error (mismatch_detail, idx,
3101
0
           _("missing extend operator"));
3102
0
      return false;
3103
0
    }
3104
50.6k
        else if (opnd->shifter.kind == AARCH64_MOD_LSL)
3105
0
    {
3106
0
      set_other_error (mismatch_detail, idx,
3107
0
           _("'LSL' operator not allowed"));
3108
0
      return false;
3109
0
    }
3110
50.6k
      }
3111
53.9k
    assert (opnd->shifter.operator_present  /* Default to LSL.  */
3112
53.9k
      || opnd->shifter.kind == AARCH64_MOD_LSL);
3113
53.9k
    if (!value_in_range_p (opnd->shifter.amount, 0, 4))
3114
8.55k
      {
3115
8.55k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, 4);
3116
8.55k
        return false;
3117
8.55k
      }
3118
    /* In the 64-bit form, the final register operand is written as Wm
3119
       for all but the (possibly omitted) UXTX/LSL and SXTX
3120
       operators.
3121
       N.B. GAS allows X register to be used with any operator as a
3122
       programming convenience.  */
3123
45.3k
    if (qualifier == AARCH64_OPND_QLF_X
3124
4.69k
        && opnd->shifter.kind != AARCH64_MOD_LSL
3125
4.69k
        && opnd->shifter.kind != AARCH64_MOD_UXTX
3126
2.15k
        && opnd->shifter.kind != AARCH64_MOD_SXTX)
3127
0
      {
3128
0
        set_other_error (mismatch_detail, idx, _("W register expected"));
3129
0
        return false;
3130
0
      }
3131
45.3k
    break;
3132
3133
537k
  case AARCH64_OPND_Rm_SFT:
3134
    /* ROR is not available to the shifted register operand in
3135
       arithmetic instructions.  */
3136
537k
    if (!aarch64_shift_operator_p (opnd->shifter.kind))
3137
0
      {
3138
0
        set_other_error (mismatch_detail, idx,
3139
0
             _("shift operator expected"));
3140
0
        return false;
3141
0
      }
3142
537k
    if (opnd->shifter.kind == AARCH64_MOD_ROR
3143
83.6k
        && opcode->iclass != log_shift)
3144
0
      {
3145
0
        set_other_error (mismatch_detail, idx,
3146
0
             _("'ROR' operator not allowed"));
3147
0
        return false;
3148
0
      }
3149
537k
    num = qualifier == AARCH64_OPND_QLF_W ? 31 : 63;
3150
537k
    if (!value_in_range_p (opnd->shifter.amount, 0, num))
3151
70.7k
      {
3152
70.7k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, num);
3153
70.7k
        return false;
3154
70.7k
      }
3155
466k
    break;
3156
3157
466k
  case AARCH64_OPND_Rm_LSL:
3158
    /* We expect here that opnd->shifter.kind != AARCH64_MOD_LSL
3159
       because the parser already restricts the type of shift to LSL only,
3160
       so another check of shift kind would be redundant.  */
3161
835
    if (!value_in_range_p (opnd->shifter.amount, 0, 7))
3162
0
      {
3163
0
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, 7);
3164
0
        return false;
3165
0
      }
3166
835
    break;
3167
3168
835
  default:
3169
0
    break;
3170
592k
  }
3171
512k
      break;
3172
3173
1.79M
    default:
3174
1.79M
      break;
3175
18.3M
    }
3176
3177
18.1M
  return true;
3178
18.3M
}
3179
3180
/* Main entrypoint for the operand constraint checking.
3181
3182
   Return 1 if operands of *INST meet the constraint applied by the operand
3183
   codes and operand qualifiers; otherwise return 0 and if MISMATCH_DETAIL is
3184
   not NULL, return the detail of the error in *MISMATCH_DETAIL.  N.B. when
3185
   adding more constraint checking, make sure MISMATCH_DETAIL->KIND is set
3186
   with a proper error kind rather than AARCH64_OPDE_NIL (GAS asserts non-NIL
3187
   error kind when it is notified that an instruction does not pass the check).
3188
3189
   Un-determined operand qualifiers may get established during the process.  */
3190
3191
bool
3192
aarch64_match_operands_constraint (aarch64_inst *inst,
3193
           aarch64_operand_error *mismatch_detail)
3194
7.92M
{
3195
7.92M
  int i;
3196
3197
7.92M
  DEBUG_TRACE ("enter");
3198
3199
7.92M
  i = inst->opcode->tied_operand;
3200
3201
7.92M
  if (i > 0)
3202
90.8k
    {
3203
      /* Check for tied_operands with specific opcode iclass.  */
3204
90.8k
      switch (inst->opcode->iclass)
3205
90.8k
        {
3206
        /* For SME LDR and STR instructions #imm must have the same numerical
3207
           value for both operands.
3208
        */
3209
910
        case sme_ldr:
3210
955
        case sme_str:
3211
955
          assert (inst->operands[0].type == AARCH64_OPND_SME_ZA_array_off4);
3212
955
          assert (inst->operands[1].type == AARCH64_OPND_SME_ADDR_RI_U4xVL);
3213
955
          if (inst->operands[0].indexed_za.index.imm
3214
955
              != inst->operands[1].addr.offset.imm)
3215
0
            {
3216
0
              if (mismatch_detail)
3217
0
                {
3218
0
                  mismatch_detail->kind = AARCH64_OPDE_UNTIED_IMMS;
3219
0
                  mismatch_detail->index = i;
3220
0
                }
3221
0
              return false;
3222
0
            }
3223
955
          break;
3224
3225
89.9k
        default:
3226
89.9k
    {
3227
      /* Check for cases where a source register needs to be the
3228
         same as the destination register.  Do this before
3229
         matching qualifiers since if an instruction has both
3230
         invalid tying and invalid qualifiers, the error about
3231
         qualifiers would suggest several alternative instructions
3232
         that also have invalid tying.  */
3233
89.9k
      enum aarch64_operand_class op_class
3234
89.9k
         = aarch64_get_operand_class (inst->operands[0].type);
3235
89.9k
      assert (aarch64_get_operand_class (inst->operands[i].type)
3236
89.9k
        == op_class);
3237
89.9k
      if (op_class == AARCH64_OPND_CLASS_SVE_REGLIST
3238
89.9k
    ? ((inst->operands[0].reglist.first_regno
3239
667
        != inst->operands[i].reglist.first_regno)
3240
667
       || (inst->operands[0].reglist.num_regs
3241
667
           != inst->operands[i].reglist.num_regs)
3242
667
       || (inst->operands[0].reglist.stride
3243
667
           != inst->operands[i].reglist.stride))
3244
89.9k
    : (inst->operands[0].reg.regno
3245
89.2k
       != inst->operands[i].reg.regno))
3246
0
        {
3247
0
    if (mismatch_detail)
3248
0
      {
3249
0
        mismatch_detail->kind = AARCH64_OPDE_UNTIED_OPERAND;
3250
0
        mismatch_detail->index = i;
3251
0
        mismatch_detail->error = NULL;
3252
0
      }
3253
0
    return false;
3254
0
        }
3255
89.9k
      break;
3256
89.9k
    }
3257
90.8k
        }
3258
90.8k
    }
3259
3260
  /* Match operands' qualifier.
3261
     *INST has already had qualifier establish for some, if not all, of
3262
     its operands; we need to find out whether these established
3263
     qualifiers match one of the qualifier sequence in
3264
     INST->OPCODE->QUALIFIERS_LIST.  If yes, we will assign each operand
3265
     with the corresponding qualifier in such a sequence.
3266
     Only basic operand constraint checking is done here; the more thorough
3267
     constraint checking will carried out by operand_general_constraint_met_p,
3268
     which has be to called after this in order to get all of the operands'
3269
     qualifiers established.  */
3270
7.92M
  int invalid_count;
3271
7.92M
  if (match_operands_qualifier (inst, true /* update_p */,
3272
7.92M
        &invalid_count) == 0)
3273
41.5k
    {
3274
41.5k
      DEBUG_TRACE ("FAIL on operand qualifier matching");
3275
41.5k
      if (mismatch_detail)
3276
0
  {
3277
    /* Return an error type to indicate that it is the qualifier
3278
       matching failure; we don't care about which operand as there
3279
       are enough information in the opcode table to reproduce it.  */
3280
0
    mismatch_detail->kind = AARCH64_OPDE_INVALID_VARIANT;
3281
0
    mismatch_detail->index = -1;
3282
0
    mismatch_detail->error = NULL;
3283
0
    mismatch_detail->data[0].i = invalid_count;
3284
0
  }
3285
41.5k
      return false;
3286
41.5k
    }
3287
3288
  /* Match operands' constraint.  */
3289
26.0M
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3290
26.0M
    {
3291
26.0M
      enum aarch64_opnd type = inst->opcode->operands[i];
3292
26.0M
      if (type == AARCH64_OPND_NIL)
3293
7.68M
  break;
3294
18.3M
      if (inst->operands[i].skip)
3295
0
  {
3296
0
    DEBUG_TRACE ("skip the incomplete operand %d", i);
3297
0
    continue;
3298
0
  }
3299
18.3M
      if (!operand_general_constraint_met_p (inst->operands, i, type,
3300
18.3M
               inst->opcode, mismatch_detail))
3301
192k
  {
3302
192k
    DEBUG_TRACE ("FAIL on operand %d", i);
3303
192k
    return false;
3304
192k
  }
3305
18.3M
    }
3306
3307
  /* Check constraints involving multiple operands.  */
3308
7.68M
  if (inst->opcode->flags & F_REQUIRES_SP)
3309
5.26k
    {
3310
5.26k
      bool sp_found = false;
3311
14.7k
      for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3312
14.7k
  {
3313
14.7k
    enum aarch64_opnd type = inst->opcode->operands[i];
3314
14.7k
    if (type == AARCH64_OPND_NIL)
3315
4.71k
      break;
3316
10.0k
    if (aarch64_stack_pointer_p (&(inst->operands[i])))
3317
553
      {
3318
553
        sp_found = true;
3319
553
        break;
3320
553
      }
3321
10.0k
  }
3322
5.26k
      if (!sp_found)
3323
4.71k
  {
3324
4.71k
    set_other_error (mismatch_detail, -1,
3325
4.71k
         _("expected at least one stack pointer operand"));
3326
4.71k
    return false;
3327
4.71k
  }
3328
5.26k
    }
3329
3330
7.68M
  DEBUG_TRACE ("PASS");
3331
3332
7.68M
  return true;
3333
7.68M
}
3334
3335
/* Replace INST->OPCODE with OPCODE and return the replaced OPCODE.
3336
   Also updates the TYPE of each INST->OPERANDS with the corresponding
3337
   value of OPCODE->OPERANDS.
3338
3339
   Note that some operand qualifiers may need to be manually cleared by
3340
   the caller before it further calls the aarch64_opcode_encode; by
3341
   doing this, it helps the qualifier matching facilities work
3342
   properly.  */
3343
3344
const aarch64_opcode*
3345
aarch64_replace_opcode (aarch64_inst *inst, const aarch64_opcode *opcode)
3346
106k
{
3347
106k
  int i;
3348
106k
  const aarch64_opcode *old = inst->opcode;
3349
3350
106k
  inst->opcode = opcode;
3351
3352
  /* Update the operand types.  */
3353
389k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3354
389k
    {
3355
389k
      inst->operands[i].type = opcode->operands[i];
3356
389k
      if (opcode->operands[i] == AARCH64_OPND_NIL)
3357
106k
  break;
3358
389k
    }
3359
3360
106k
  DEBUG_TRACE ("replace %s with %s", old->name, opcode->name);
3361
3362
106k
  return old;
3363
106k
}
3364
3365
int
3366
aarch64_operand_index (const enum aarch64_opnd *operands, enum aarch64_opnd operand)
3367
187k
{
3368
187k
  int i;
3369
219k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3370
219k
    if (operands[i] == operand)
3371
182k
      return i;
3372
37.5k
    else if (operands[i] == AARCH64_OPND_NIL)
3373
5.25k
      break;
3374
5.25k
  return -1;
3375
187k
}
3376

3377
/* R0...R30, followed by FOR31.  */
3378
#define BANK(R, FOR31) \
3379
  { R  (0), R  (1), R  (2), R  (3), R  (4), R  (5), R  (6), R  (7), \
3380
    R  (8), R  (9), R (10), R (11), R (12), R (13), R (14), R (15), \
3381
    R (16), R (17), R (18), R (19), R (20), R (21), R (22), R (23), \
3382
    R (24), R (25), R (26), R (27), R (28), R (29), R (30),  FOR31 }
3383
/* [0][0]  32-bit integer regs with sp   Wn
3384
   [0][1]  64-bit integer regs with sp   Xn  sf=1
3385
   [1][0]  32-bit integer regs with #0   Wn
3386
   [1][1]  64-bit integer regs with #0   Xn  sf=1 */
3387
static const char *int_reg[2][2][32] = {
3388
#define R32(X) "w" #X
3389
#define R64(X) "x" #X
3390
  { BANK (R32, "wsp"), BANK (R64, "sp") },
3391
  { BANK (R32, "wzr"), BANK (R64, "xzr") }
3392
#undef R64
3393
#undef R32
3394
};
3395
3396
/* Names of the SVE vector registers, first with .S suffixes,
3397
   then with .D suffixes.  */
3398
3399
static const char *sve_reg[2][32] = {
3400
#define ZS(X) "z" #X ".s"
3401
#define ZD(X) "z" #X ".d"
3402
  BANK (ZS, ZS (31)), BANK (ZD, ZD (31))
3403
#undef ZD
3404
#undef ZS
3405
};
3406
#undef BANK
3407
3408
/* Return the integer register name.
3409
   if SP_REG_P is not 0, R31 is an SP reg, other R31 is the zero reg.  */
3410
3411
static inline const char *
3412
get_int_reg_name (int regno, aarch64_opnd_qualifier_t qualifier, int sp_reg_p)
3413
4.73M
{
3414
4.73M
  const int has_zr = sp_reg_p ? 0 : 1;
3415
4.73M
  const int is_64 = aarch64_get_qualifier_esize (qualifier) == 4 ? 0 : 1;
3416
4.73M
  return int_reg[has_zr][is_64][regno];
3417
4.73M
}
3418
3419
/* Like get_int_reg_name, but IS_64 is always 1.  */
3420
3421
static inline const char *
3422
get_64bit_int_reg_name (int regno, int sp_reg_p)
3423
1.61M
{
3424
1.61M
  const int has_zr = sp_reg_p ? 0 : 1;
3425
1.61M
  return int_reg[has_zr][1][regno];
3426
1.61M
}
3427
3428
/* Get the name of the integer offset register in OPND, using the shift type
3429
   to decide whether it's a word or doubleword.  */
3430
3431
static inline const char *
3432
get_offset_int_reg_name (const aarch64_opnd_info *opnd)
3433
148k
{
3434
148k
  switch (opnd->shifter.kind)
3435
148k
    {
3436
1.82k
    case AARCH64_MOD_UXTW:
3437
4.07k
    case AARCH64_MOD_SXTW:
3438
4.07k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_W, 0);
3439
3440
138k
    case AARCH64_MOD_LSL:
3441
144k
    case AARCH64_MOD_SXTX:
3442
144k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_X, 0);
3443
3444
0
    default:
3445
0
      abort ();
3446
148k
    }
3447
148k
}
3448
3449
/* Get the name of the SVE vector offset register in OPND, using the operand
3450
   qualifier to decide whether the suffix should be .S or .D.  */
3451
3452
static inline const char *
3453
get_addr_sve_reg_name (int regno, aarch64_opnd_qualifier_t qualifier)
3454
139k
{
3455
139k
  assert (qualifier == AARCH64_OPND_QLF_S_S
3456
139k
    || qualifier == AARCH64_OPND_QLF_S_D);
3457
139k
  return sve_reg[qualifier == AARCH64_OPND_QLF_S_D][regno];
3458
139k
}
3459
3460
/* Types for expanding an encoded 8-bit value to a floating-point value.  */
3461
3462
typedef union
3463
{
3464
  uint64_t i;
3465
  double   d;
3466
} double_conv_t;
3467
3468
typedef union
3469
{
3470
  uint32_t i;
3471
  float    f;
3472
} single_conv_t;
3473
3474
typedef union
3475
{
3476
  uint32_t i;
3477
  float    f;
3478
} half_conv_t;
3479
3480
/* IMM8 is an 8-bit floating-point constant with sign, 3-bit exponent and
3481
   normalized 4 bits of precision, encoded in "a:b:c:d:e:f:g:h" or FLD_imm8
3482
   (depending on the type of the instruction).  IMM8 will be expanded to a
3483
   single-precision floating-point value (SIZE == 4) or a double-precision
3484
   floating-point value (SIZE == 8).  A half-precision floating-point value
3485
   (SIZE == 2) is expanded to a single-precision floating-point value.  The
3486
   expanded value is returned.  */
3487
3488
static uint64_t
3489
expand_fp_imm (int size, uint32_t imm8)
3490
3.14k
{
3491
3.14k
  uint64_t imm = 0;
3492
3.14k
  uint32_t imm8_7, imm8_6_0, imm8_6, imm8_6_repl4;
3493
3494
3.14k
  imm8_7 = (imm8 >> 7) & 0x01;  /* imm8<7>   */
3495
3.14k
  imm8_6_0 = imm8 & 0x7f; /* imm8<6:0> */
3496
3.14k
  imm8_6 = imm8_6_0 >> 6; /* imm8<6>   */
3497
3.14k
  imm8_6_repl4 = (imm8_6 << 3) | (imm8_6 << 2)
3498
3.14k
    | (imm8_6 << 1) | imm8_6; /* Replicate(imm8<6>,4) */
3499
3.14k
  if (size == 8)
3500
653
    {
3501
653
      imm = (imm8_7 << (63-32))   /* imm8<7>  */
3502
653
  | ((imm8_6 ^ 1) << (62-32)) /* NOT(imm8<6)  */
3503
653
  | (imm8_6_repl4 << (58-32)) | (imm8_6 << (57-32))
3504
653
  | (imm8_6 << (56-32)) | (imm8_6 << (55-32)) /* Replicate(imm8<6>,7) */
3505
653
  | (imm8_6_0 << (48-32));  /* imm8<6>:imm8<5:0>    */
3506
653
      imm <<= 32;
3507
653
    }
3508
2.49k
  else if (size == 4 || size == 2)
3509
2.49k
    {
3510
2.49k
      imm = (imm8_7 << 31)  /* imm8<7>              */
3511
2.49k
  | ((imm8_6 ^ 1) << 30)  /* NOT(imm8<6>)         */
3512
2.49k
  | (imm8_6_repl4 << 26)  /* Replicate(imm8<6>,4) */
3513
2.49k
  | (imm8_6_0 << 19); /* imm8<6>:imm8<5:0>    */
3514
2.49k
    }
3515
0
  else
3516
0
    {
3517
      /* An unsupported size.  */
3518
0
      assert (0);
3519
0
    }
3520
3521
3.14k
  return imm;
3522
3.14k
}
3523
3524
/* Return a string based on FMT with the register style applied.  */
3525
3526
static const char *
3527
style_reg (struct aarch64_styler *styler, const char *fmt, ...)
3528
11.6M
{
3529
11.6M
  const char *txt;
3530
11.6M
  va_list ap;
3531
3532
11.6M
  va_start (ap, fmt);
3533
11.6M
  txt = styler->apply_style (styler, dis_style_register, fmt, ap);
3534
11.6M
  va_end (ap);
3535
3536
11.6M
  return txt;
3537
11.6M
}
3538
3539
/* Return a string based on FMT with the immediate style applied.  */
3540
3541
static const char *
3542
style_imm (struct aarch64_styler *styler, const char *fmt, ...)
3543
4.69M
{
3544
4.69M
  const char *txt;
3545
4.69M
  va_list ap;
3546
3547
4.69M
  va_start (ap, fmt);
3548
4.69M
  txt = styler->apply_style (styler, dis_style_immediate, fmt, ap);
3549
4.69M
  va_end (ap);
3550
3551
4.69M
  return txt;
3552
4.69M
}
3553
3554
/* Return a string based on FMT with the sub-mnemonic style applied.  */
3555
3556
static const char *
3557
style_sub_mnem (struct aarch64_styler *styler, const char *fmt, ...)
3558
769k
{
3559
769k
  const char *txt;
3560
769k
  va_list ap;
3561
3562
769k
  va_start (ap, fmt);
3563
769k
  txt = styler->apply_style (styler, dis_style_sub_mnemonic, fmt, ap);
3564
769k
  va_end (ap);
3565
3566
769k
  return txt;
3567
769k
}
3568
3569
/* Return a string based on FMT with the address style applied.  */
3570
3571
static const char *
3572
style_addr (struct aarch64_styler *styler, const char *fmt, ...)
3573
1.43M
{
3574
1.43M
  const char *txt;
3575
1.43M
  va_list ap;
3576
3577
1.43M
  va_start (ap, fmt);
3578
1.43M
  txt = styler->apply_style (styler, dis_style_address, fmt, ap);
3579
1.43M
  va_end (ap);
3580
3581
1.43M
  return txt;
3582
1.43M
}
3583
3584
/* Produce the string representation of the register list operand *OPND
3585
   in the buffer pointed by BUF of size SIZE.  PREFIX is the part of
3586
   the register name that comes before the register number, such as "v".  */
3587
static void
3588
print_register_list (char *buf, size_t size, const aarch64_opnd_info *opnd,
3589
         const char *prefix, struct aarch64_styler *styler)
3590
403k
{
3591
403k
  const int mask = (prefix[0] == 'p' ? 15 : 31);
3592
403k
  const int num_regs = opnd->reglist.num_regs;
3593
403k
  const int stride = opnd->reglist.stride;
3594
403k
  const int first_reg = opnd->reglist.first_regno;
3595
403k
  const int last_reg = (first_reg + (num_regs - 1) * stride) & mask;
3596
403k
  const char *qlf_name = aarch64_get_qualifier_name (opnd->qualifier);
3597
403k
  char tb[16];  /* Temporary buffer.  */
3598
3599
403k
  assert (opnd->type != AARCH64_OPND_LEt || opnd->reglist.has_index);
3600
403k
  assert (num_regs >= 1 && num_regs <= 4);
3601
3602
  /* Prepare the index if any.  */
3603
403k
  if (opnd->reglist.has_index)
3604
    /* PR 21096: The %100 is to silence a warning about possible truncation.  */
3605
19.9k
    snprintf (tb, sizeof (tb), "[%s]",
3606
19.9k
        style_imm (styler, "%" PRIi64, (opnd->reglist.index % 100)));
3607
383k
  else
3608
383k
    tb[0] = '\0';
3609
3610
  /* The hyphenated form is preferred for disassembly if there is
3611
     more than one register in the list, and the register numbers
3612
     are monotonically increasing in increments of one.  */
3613
403k
  if (stride == 1 && num_regs > 1)
3614
123k
    if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3615
796
      snprintf (buf, size, "{%s-%s}%s",
3616
796
    style_reg (styler, "%s%d", prefix, first_reg),
3617
796
    style_reg (styler, "%s%d", prefix, last_reg), tb);
3618
122k
    else
3619
122k
      snprintf (buf, size, "{%s-%s}%s",
3620
122k
    style_reg (styler, "%s%d.%s", prefix, first_reg, qlf_name),
3621
122k
    style_reg (styler, "%s%d.%s", prefix, last_reg, qlf_name), tb);
3622
279k
  else
3623
279k
    {
3624
279k
      const int reg0 = first_reg;
3625
279k
      const int reg1 = (first_reg + stride) & mask;
3626
279k
      const int reg2 = (first_reg + stride * 2) & mask;
3627
279k
      const int reg3 = (first_reg + stride * 3) & mask;
3628
3629
279k
      switch (num_regs)
3630
279k
  {
3631
267k
  case 1:
3632
267k
    snprintf (buf, size, "{%s}%s",
3633
267k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3634
267k
        tb);
3635
267k
    break;
3636
7.68k
  case 2:
3637
7.68k
    snprintf (buf, size, "{%s, %s}%s",
3638
7.68k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3639
7.68k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3640
7.68k
        tb);
3641
7.68k
    break;
3642
0
  case 3:
3643
0
    snprintf (buf, size, "{%s, %s, %s}%s",
3644
0
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3645
0
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3646
0
        style_reg (styler, "%s%d.%s", prefix, reg2, qlf_name),
3647
0
        tb);
3648
0
    break;
3649
4.51k
  case 4:
3650
4.51k
    snprintf (buf, size, "{%s, %s, %s, %s}%s",
3651
4.51k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3652
4.51k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3653
4.51k
        style_reg (styler, "%s%d.%s", prefix, reg2, qlf_name),
3654
4.51k
        style_reg (styler, "%s%d.%s", prefix, reg3, qlf_name),
3655
4.51k
        tb);
3656
4.51k
    break;
3657
279k
  }
3658
279k
    }
3659
403k
}
3660
3661
/* Print the register+immediate address in OPND to BUF, which has SIZE
3662
   characters.  BASE is the name of the base register.  */
3663
3664
static void
3665
print_immediate_offset_address (char *buf, size_t size,
3666
        const aarch64_opnd_info *opnd,
3667
        const char *base,
3668
        struct aarch64_styler *styler)
3669
871k
{
3670
871k
  if (opnd->addr.writeback)
3671
302k
    {
3672
302k
      if (opnd->addr.preind)
3673
154k
        {
3674
154k
    if (opnd->type == AARCH64_OPND_ADDR_SIMM10 && !opnd->addr.offset.imm)
3675
91
      snprintf (buf, size, "[%s]!", style_reg (styler, base));
3676
154k
          else
3677
154k
      snprintf (buf, size, "[%s, %s]!",
3678
154k
          style_reg (styler, base),
3679
154k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
3680
154k
        }
3681
147k
      else
3682
147k
  snprintf (buf, size, "[%s], %s",
3683
147k
      style_reg (styler, base),
3684
147k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3685
302k
    }
3686
568k
  else
3687
568k
    {
3688
568k
      if (opnd->shifter.operator_present)
3689
84.3k
  {
3690
84.3k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL_VL);
3691
84.3k
    snprintf (buf, size, "[%s, %s, %s]",
3692
84.3k
        style_reg (styler, base),
3693
84.3k
        style_imm (styler, "#%d", opnd->addr.offset.imm),
3694
84.3k
        style_sub_mnem (styler, "mul vl"));
3695
84.3k
  }
3696
484k
      else if (opnd->addr.offset.imm)
3697
393k
  snprintf (buf, size, "[%s, %s]",
3698
393k
      style_reg (styler, base),
3699
393k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3700
91.2k
      else
3701
91.2k
  snprintf (buf, size, "[%s]", style_reg (styler, base));
3702
568k
    }
3703
871k
}
3704
3705
/* Produce the string representation of the register offset address operand
3706
   *OPND in the buffer pointed by BUF of size SIZE.  BASE and OFFSET are
3707
   the names of the base and offset registers.  */
3708
static void
3709
print_register_offset_address (char *buf, size_t size,
3710
             const aarch64_opnd_info *opnd,
3711
             const char *base, const char *offset,
3712
             struct aarch64_styler *styler)
3713
269k
{
3714
269k
  char tb[32];      /* Temporary buffer.  */
3715
269k
  bool print_extend_p = true;
3716
269k
  bool print_amount_p = true;
3717
269k
  const char *shift_name = aarch64_operand_modifiers[opnd->shifter.kind].name;
3718
3719
  /* This is the case where offset is the optional argument and the optional
3720
     argument is ignored in the disassembly.  */
3721
269k
  if (opnd->type == AARCH64_OPND_SVE_ADDR_ZX && offset != NULL
3722
16.6k
      && strcmp (offset,"xzr") == 0)
3723
526
    {
3724
      /* Example: [<Zn>.S{, <Xm>}].
3725
   When the assembly is [Z0.S, XZR] or [Z0.S], Xm is XZR in both the cases
3726
   and the preferred disassembly is [Z0.S], ignoring the optional Xm.  */
3727
526
      snprintf (buf, size, "[%s]", style_reg (styler, base));
3728
526
    }
3729
269k
  else
3730
269k
    {
3731
269k
      if (!opnd->shifter.amount && (opnd->qualifier != AARCH64_OPND_QLF_S_B
3732
5.03k
            || !opnd->shifter.amount_present))
3733
129k
  {
3734
    /* Not print the shift/extend amount when the amount is zero and
3735
       when it is not the special case of 8-bit load/store
3736
       instruction.  */
3737
129k
   print_amount_p = false;
3738
   /* Likewise, no need to print the shift operator LSL in such a
3739
      situation.  */
3740
129k
   if (opnd->shifter.kind == AARCH64_MOD_LSL)
3741
80.8k
     print_extend_p = false;
3742
129k
  }
3743
3744
      /* Prepare for the extend/shift.  */
3745
269k
      if (print_extend_p)
3746
188k
  {
3747
188k
    if (print_amount_p)
3748
139k
      snprintf (tb, sizeof (tb), ", %s %s",
3749
139k
          style_sub_mnem (styler, shift_name),
3750
139k
          style_imm (styler, "#%" PRIi64,
3751
    /* PR 21096: The %100 is to silence a warning about possible
3752
       truncation.  */
3753
139k
         (opnd->shifter.amount % 100)));
3754
48.8k
    else
3755
48.8k
      snprintf (tb, sizeof (tb), ", %s",
3756
48.8k
          style_sub_mnem (styler, shift_name));
3757
188k
  }
3758
80.8k
      else
3759
80.8k
  tb[0] = '\0';
3760
3761
269k
      snprintf (buf, size, "[%s, %s%s]", style_reg (styler, base),
3762
269k
    style_reg (styler, offset), tb);
3763
269k
    }
3764
269k
}
3765
3766
/* Print ZA tiles from imm8 in ZERO instruction.
3767
3768
   The preferred disassembly of this instruction uses the shortest list of tile
3769
   names that represent the encoded immediate mask.
3770
3771
   For example:
3772
    * An all-ones immediate is disassembled as {ZA}.
3773
    * An all-zeros immediate is disassembled as an empty list { }.
3774
*/
3775
static void
3776
print_sme_za_list (char *buf, size_t size, int mask,
3777
       struct aarch64_styler *styler)
3778
224
{
3779
224
  static const struct {
3780
224
    unsigned char mask;
3781
224
    char name[7];
3782
224
  } zan[] = {
3783
224
    { 0xff, "za" },
3784
224
    { 0x55, "za0.h" },
3785
224
    { 0xaa, "za1.h" },
3786
224
    { 0x11, "za0.s" },
3787
224
    { 0x22, "za1.s" },
3788
224
    { 0x44, "za2.s" },
3789
224
    { 0x88, "za3.s" },
3790
224
    { 0x01, "za0.d" },
3791
224
    { 0x02, "za1.d" },
3792
224
    { 0x04, "za2.d" },
3793
224
    { 0x08, "za3.d" },
3794
224
    { 0x10, "za4.d" },
3795
224
    { 0x20, "za5.d" },
3796
224
    { 0x40, "za6.d" },
3797
224
    { 0x80, "za7.d" },
3798
224
    { 0x00, " " },
3799
224
  };
3800
224
  int k;
3801
3802
224
  k = snprintf (buf, size, "{");
3803
1.94k
  for (unsigned int i = 0; i < ARRAY_SIZE (zan); i++)
3804
1.94k
    {
3805
1.94k
      if ((mask & zan[i].mask) == zan[i].mask)
3806
613
  {
3807
613
    mask &= ~zan[i].mask;
3808
613
    if (k > 1)
3809
406
      k += snprintf (buf + k, size - k, ", ");
3810
3811
613
    k += snprintf (buf + k, size - k, "%s",
3812
613
       style_reg (styler, zan[i].name));
3813
613
  }
3814
1.94k
      if (mask == 0)
3815
224
        break;
3816
1.94k
    }
3817
224
  snprintf (buf + k, size - k, "}");
3818
224
}
3819
3820
/* Generate the string representation of the operand OPNDS[IDX] for OPCODE
3821
   in *BUF.  The caller should pass in the maximum size of *BUF in SIZE.
3822
   PC, PCREL_P and ADDRESS are used to pass in and return information about
3823
   the PC-relative address calculation, where the PC value is passed in
3824
   PC.  If the operand is pc-relative related, *PCREL_P (if PCREL_P non-NULL)
3825
   will return 1 and *ADDRESS (if ADDRESS non-NULL) will return the
3826
   calculated address; otherwise, *PCREL_P (if PCREL_P non-NULL) returns 0.
3827
3828
   The function serves both the disassembler and the assembler diagnostics
3829
   issuer, which is the reason why it lives in this file.  */
3830
3831
void
3832
aarch64_print_operand (char *buf, size_t size, bfd_vma pc,
3833
           const aarch64_opcode *opcode,
3834
           const aarch64_opnd_info *opnds, int idx, int *pcrel_p,
3835
           bfd_vma *address, char** notes,
3836
           char *comment, size_t comment_size,
3837
           aarch64_feature_set features,
3838
           struct aarch64_styler *styler)
3839
15.2M
{
3840
15.2M
  unsigned int i, num_conds;
3841
15.2M
  const char *name = NULL;
3842
15.2M
  const aarch64_opnd_info *opnd = opnds + idx;
3843
15.2M
  enum aarch64_modifier_kind kind;
3844
15.2M
  uint64_t addr, enum_value;
3845
3846
15.2M
  if (comment != NULL)
3847
15.2M
    {
3848
15.2M
      assert (comment_size > 0);
3849
15.2M
      comment[0] = '\0';
3850
15.2M
    }
3851
0
  else
3852
15.2M
    assert (comment_size == 0);
3853
3854
15.2M
  buf[0] = '\0';
3855
15.2M
  if (pcrel_p)
3856
15.2M
    *pcrel_p = 0;
3857
3858
15.2M
  switch (opnd->type)
3859
15.2M
    {
3860
1.20M
    case AARCH64_OPND_Rd:
3861
1.20M
    case AARCH64_OPND_Rd_NOT_ZR:
3862
1.81M
    case AARCH64_OPND_Rn:
3863
1.93M
    case AARCH64_OPND_Rm:
3864
3.20M
    case AARCH64_OPND_Rt:
3865
3.49M
    case AARCH64_OPND_Rt2:
3866
3.65M
    case AARCH64_OPND_Rs:
3867
3.68M
    case AARCH64_OPND_Ra:
3868
3.68M
    case AARCH64_OPND_Rt_IN_SYS_ALIASES:
3869
3.68M
    case AARCH64_OPND_Rt_LS64:
3870
3.68M
    case AARCH64_OPND_Rt_SYS:
3871
3.68M
    case AARCH64_OPND_PAIRREG:
3872
3.69M
    case AARCH64_OPND_PAIRREG_OR_XZR:
3873
3.69M
    case AARCH64_OPND_SVE_Rm:
3874
3.69M
    case AARCH64_OPND_LSE128_Rt:
3875
3.69M
    case AARCH64_OPND_LSE128_Rt2:
3876
      /* The optional-ness of <Xt> in e.g. IC <ic_op>{, <Xt>} is determined by
3877
   the <ic_op>, therefore we use opnd->present to override the
3878
   generic optional-ness information.  */
3879
3.69M
      if (opnd->type == AARCH64_OPND_Rt_SYS)
3880
269
  {
3881
269
    if (!opnd->present)
3882
19
      break;
3883
269
  }
3884
3.69M
      else if ((opnd->type == AARCH64_OPND_Rt_IN_SYS_ALIASES)
3885
50
         && (opnd->reg.regno
3886
50
       != get_optional_operand_default_value (opcode)))
3887
50
  {
3888
    /* Avoid printing an invalid additional value for Rt in SYS aliases such as
3889
       BRB, provide a helpful comment instead */
3890
50
    snprintf (comment, comment_size, "unpredictable encoding (Rt!=31): #%u", opnd->reg.regno);
3891
50
    break;
3892
50
  }
3893
      /* Omit the operand, e.g. RET.  */
3894
3.69M
      else if (optional_operand_p (opcode, idx)
3895
5.10k
         && (opnd->reg.regno
3896
5.10k
       == get_optional_operand_default_value (opcode)))
3897
1.70k
  break;
3898
3.69M
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3899
3.68M
        || opnd->qualifier == AARCH64_OPND_QLF_X);
3900
3.68M
      snprintf (buf, size, "%s",
3901
3.68M
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
3902
3.68M
                 opnd->qualifier, 0)));
3903
3.68M
      break;
3904
3905
243k
    case AARCH64_OPND_Rd_SP:
3906
503k
    case AARCH64_OPND_Rn_SP:
3907
511k
    case AARCH64_OPND_Rt_SP:
3908
512k
    case AARCH64_OPND_SVE_Rn_SP:
3909
513k
    case AARCH64_OPND_Rm_SP:
3910
513k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3911
513k
        || opnd->qualifier == AARCH64_OPND_QLF_X);
3912
513k
      snprintf (buf, size, "%s",
3913
513k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
3914
513k
                 opnd->qualifier, 1)));
3915
513k
      break;
3916
3917
26.7k
    case AARCH64_OPND_Rm_EXT:
3918
26.7k
      kind = opnd->shifter.kind;
3919
26.7k
      assert (idx == 1 || idx == 2);
3920
26.7k
      if ((aarch64_stack_pointer_p (opnds)
3921
25.8k
     || (idx == 2 && aarch64_stack_pointer_p (opnds + 1)))
3922
1.91k
    && ((opnd->qualifier == AARCH64_OPND_QLF_W
3923
787
         && opnds[0].qualifier == AARCH64_OPND_QLF_W
3924
447
         && kind == AARCH64_MOD_UXTW)
3925
1.84k
        || (opnd->qualifier == AARCH64_OPND_QLF_X
3926
1.13k
      && kind == AARCH64_MOD_UXTX)))
3927
1.03k
  {
3928
    /* 'LSL' is the preferred form in this case.  */
3929
1.03k
    kind = AARCH64_MOD_LSL;
3930
1.03k
    if (opnd->shifter.amount == 0)
3931
456
      {
3932
        /* Shifter omitted.  */
3933
456
        snprintf (buf, size, "%s",
3934
456
      style_reg (styler,
3935
456
           get_int_reg_name (opnd->reg.regno,
3936
456
                 opnd->qualifier, 0)));
3937
456
        break;
3938
456
      }
3939
1.03k
  }
3940
26.3k
      if (opnd->shifter.amount)
3941
20.3k
  snprintf (buf, size, "%s, %s %s",
3942
20.3k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3943
20.3k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name),
3944
20.3k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
3945
5.98k
      else
3946
5.98k
  snprintf (buf, size, "%s, %s",
3947
5.98k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3948
5.98k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name));
3949
26.3k
      break;
3950
3951
329k
    case AARCH64_OPND_Rm_SFT:
3952
329k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3953
329k
        || opnd->qualifier == AARCH64_OPND_QLF_X);
3954
329k
      if (opnd->shifter.amount == 0 && opnd->shifter.kind == AARCH64_MOD_LSL)
3955
39.7k
  snprintf (buf, size, "%s",
3956
39.7k
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
3957
39.7k
                   opnd->qualifier, 0)));
3958
289k
      else
3959
289k
  snprintf (buf, size, "%s, %s %s",
3960
289k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3961
289k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
3962
289k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
3963
329k
      break;
3964
3965
835
    case AARCH64_OPND_Rm_LSL:
3966
835
      assert (opnd->qualifier == AARCH64_OPND_QLF_X);
3967
835
      assert (opnd->shifter.kind == AARCH64_MOD_LSL);
3968
835
      if (opnd->shifter.amount == 0)
3969
222
  snprintf (buf, size, "%s",
3970
222
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
3971
222
                   opnd->qualifier, 0)));
3972
613
      else
3973
613
  snprintf (buf, size, "%s, %s %s",
3974
613
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3975
613
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
3976
613
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
3977
835
      break;
3978
3979
114k
    case AARCH64_OPND_Fd:
3980
155k
    case AARCH64_OPND_Fn:
3981
207k
    case AARCH64_OPND_Fm:
3982
296k
    case AARCH64_OPND_Fa:
3983
774k
    case AARCH64_OPND_Ft:
3984
1.00M
    case AARCH64_OPND_Ft2:
3985
1.03M
    case AARCH64_OPND_Sd:
3986
1.05M
    case AARCH64_OPND_Sn:
3987
1.06M
    case AARCH64_OPND_Sm:
3988
1.06M
    case AARCH64_OPND_SVE_VZn:
3989
1.06M
    case AARCH64_OPND_SVE_Vd:
3990
1.06M
    case AARCH64_OPND_SVE_Vm:
3991
1.06M
    case AARCH64_OPND_SVE_Vn:
3992
1.06M
      snprintf (buf, size, "%s",
3993
1.06M
    style_reg (styler, "%s%d",
3994
1.06M
         aarch64_get_qualifier_name (opnd->qualifier),
3995
1.06M
         opnd->reg.regno));
3996
1.06M
      break;
3997
3998
9.28k
    case AARCH64_OPND_Va:
3999
291k
    case AARCH64_OPND_Vd:
4000
539k
    case AARCH64_OPND_Vn:
4001
707k
    case AARCH64_OPND_Vm:
4002
707k
      snprintf (buf, size, "%s",
4003
707k
    style_reg (styler, "v%d.%s", opnd->reg.regno,
4004
707k
         aarch64_get_qualifier_name (opnd->qualifier)));
4005
707k
      break;
4006
4007
1.77k
    case AARCH64_OPND_Ed:
4008
7.27k
    case AARCH64_OPND_En:
4009
41.9k
    case AARCH64_OPND_Em:
4010
88.5k
    case AARCH64_OPND_Em16:
4011
92.0k
    case AARCH64_OPND_Em8:
4012
92.0k
      snprintf (buf, size, "%s[%s]",
4013
92.0k
    style_reg (styler, "v%d.%s", opnd->reglane.regno,
4014
92.0k
         aarch64_get_qualifier_name (opnd->qualifier)),
4015
92.0k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4016
92.0k
      break;
4017
4018
902
    case AARCH64_OPND_Em_INDEX1_14:
4019
2.91k
    case AARCH64_OPND_Em_INDEX2_13:
4020
4.02k
    case AARCH64_OPND_Em_INDEX3_12:
4021
4.02k
      snprintf (buf, size, "%s[%s]",
4022
4.02k
    style_reg (styler, "v%d", opnd->reglane.regno),
4023
4.02k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4024
4.02k
      break;
4025
4026
315
    case AARCH64_OPND_VdD1:
4027
843
    case AARCH64_OPND_VnD1:
4028
843
      snprintf (buf, size, "%s[%s]",
4029
843
    style_reg (styler, "v%d.d", opnd->reg.regno),
4030
843
    style_imm (styler, "1"));
4031
843
      break;
4032
4033
15.6k
    case AARCH64_OPND_LVn:
4034
19.7k
    case AARCH64_OPND_LVn_LUT:
4035
34.4k
    case AARCH64_OPND_LVt:
4036
36.7k
    case AARCH64_OPND_LVt_AL:
4037
56.3k
    case AARCH64_OPND_LEt:
4038
56.3k
      print_register_list (buf, size, opnd, "v", styler);
4039
56.3k
      break;
4040
4041
87.5k
    case AARCH64_OPND_SVE_Pd:
4042
747k
    case AARCH64_OPND_SVE_Pg3:
4043
747k
    case AARCH64_OPND_SVE_Pg4_5:
4044
766k
    case AARCH64_OPND_SVE_Pg4_10:
4045
775k
    case AARCH64_OPND_SVE_Pg4_16:
4046
782k
    case AARCH64_OPND_SVE_Pm:
4047
790k
    case AARCH64_OPND_SVE_Pn:
4048
792k
    case AARCH64_OPND_SVE_Pt:
4049
866k
    case AARCH64_OPND_SME_Pm:
4050
866k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4051
142k
  snprintf (buf, size, "%s",
4052
142k
      style_reg (styler, "p%d", opnd->reg.regno));
4053
723k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
4054
420k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
4055
625k
  snprintf (buf, size, "%s",
4056
625k
      style_reg (styler, "p%d/%s", opnd->reg.regno,
4057
625k
           aarch64_get_qualifier_name (opnd->qualifier)));
4058
98.7k
      else
4059
98.7k
  snprintf (buf, size, "%s",
4060
98.7k
      style_reg (styler, "p%d.%s", opnd->reg.regno,
4061
98.7k
           aarch64_get_qualifier_name (opnd->qualifier)));
4062
866k
      break;
4063
4064
0
    case AARCH64_OPND_SVE_PNd:
4065
0
    case AARCH64_OPND_SVE_PNg4_10:
4066
0
    case AARCH64_OPND_SVE_PNn:
4067
0
    case AARCH64_OPND_SVE_PNt:
4068
2.51k
    case AARCH64_OPND_SME_PNd3:
4069
31.3k
    case AARCH64_OPND_SME_PNg3:
4070
31.4k
    case AARCH64_OPND_SME_PNn:
4071
31.4k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4072
9.62k
  snprintf (buf, size, "%s",
4073
9.62k
      style_reg (styler, "pn%d", opnd->reg.regno));
4074
21.7k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
4075
2.59k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
4076
19.1k
  snprintf (buf, size, "%s",
4077
19.1k
      style_reg (styler, "pn%d/%s", opnd->reg.regno,
4078
19.1k
           aarch64_get_qualifier_name (opnd->qualifier)));
4079
2.59k
      else
4080
2.59k
  snprintf (buf, size, "%s",
4081
2.59k
      style_reg (styler, "pn%d.%s", opnd->reg.regno,
4082
2.59k
           aarch64_get_qualifier_name (opnd->qualifier)));
4083
31.4k
      break;
4084
4085
816
    case AARCH64_OPND_SME_Pdx2:
4086
967
    case AARCH64_OPND_SME_PdxN:
4087
967
      print_register_list (buf, size, opnd, "p", styler);
4088
967
      break;
4089
4090
151
    case AARCH64_OPND_SME_PNn3_INDEX1:
4091
196
    case AARCH64_OPND_SME_PNn3_INDEX2:
4092
196
      snprintf (buf, size, "%s[%s]",
4093
196
    style_reg (styler, "pn%d", opnd->reglane.regno),
4094
196
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4095
196
      break;
4096
4097
7.37k
    case AARCH64_OPND_SVE_Za_5:
4098
16.2k
    case AARCH64_OPND_SVE_Za_16:
4099
448k
    case AARCH64_OPND_SVE_Zd:
4100
494k
    case AARCH64_OPND_SVE_Zm_5:
4101
799k
    case AARCH64_OPND_SVE_Zm_16:
4102
1.27M
    case AARCH64_OPND_SVE_Zn:
4103
1.27M
    case AARCH64_OPND_SVE_Zt:
4104
1.28M
    case AARCH64_OPND_SME_Zm:
4105
1.28M
    case AARCH64_OPND_SME_Zm_17:
4106
1.29M
    case AARCH64_OPND_SME_Zn_6_3:
4107
1.30M
    case AARCH64_OPND_SME_Zm_17_3:
4108
1.30M
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4109
3.17k
       snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
4110
1.30M
      else
4111
1.30M
       snprintf (buf, size, "%s",
4112
1.30M
     style_reg (styler, "z%d.%s", opnd->reg.regno,
4113
1.30M
          aarch64_get_qualifier_name (opnd->qualifier)));
4114
1.30M
      break;
4115
4116
12.0k
    case AARCH64_OPND_SVE_ZnxN:
4117
278k
    case AARCH64_OPND_SVE_ZtxN:
4118
298k
    case AARCH64_OPND_SME_Zdnx2:
4119
305k
    case AARCH64_OPND_SME_Zdnx4:
4120
306k
    case AARCH64_OPND_SME_Znx2_6_3:
4121
306k
    case AARCH64_OPND_SME_Zmx2_17_3:
4122
309k
    case AARCH64_OPND_SME_Zmx2:
4123
310k
    case AARCH64_OPND_SME_Zmx4:
4124
310k
    case AARCH64_OPND_SME_Zmx2_INDEX_22:
4125
327k
    case AARCH64_OPND_SME_Znx2:
4126
327k
    case AARCH64_OPND_SME_Znx2_BIT_INDEX:
4127
333k
    case AARCH64_OPND_SME_Znx4:
4128
333k
    case AARCH64_OPND_SME_Zn7xN_UNTYPED:
4129
341k
    case AARCH64_OPND_SME_Ztx2_STRIDED:
4130
345k
    case AARCH64_OPND_SME_Ztx4_STRIDED:
4131
345k
      print_register_list (buf, size, opnd, "z", styler);
4132
345k
      break;
4133
4134
340
    case AARCH64_OPND_SVE_Zm1_23_INDEX:
4135
1.46k
    case AARCH64_OPND_SVE_Zm2_22_INDEX:
4136
6.69k
    case AARCH64_OPND_SVE_Zm3_INDEX:
4137
15.5k
    case AARCH64_OPND_SVE_Zm3_22_INDEX:
4138
16.0k
    case AARCH64_OPND_SVE_Zm3_19_INDEX:
4139
16.8k
    case AARCH64_OPND_SVE_Zm3_12_INDEX:
4140
22.9k
    case AARCH64_OPND_SVE_Zm3_11_INDEX:
4141
26.2k
    case AARCH64_OPND_SVE_Zm3_10_INDEX:
4142
29.7k
    case AARCH64_OPND_SVE_Zm4_11_INDEX:
4143
35.6k
    case AARCH64_OPND_SVE_Zm4_INDEX:
4144
36.2k
    case AARCH64_OPND_SVE_Zn_INDEX:
4145
41.4k
    case AARCH64_OPND_SME_Zk_INDEX:
4146
41.7k
    case AARCH64_OPND_SME_Zm_INDEX1:
4147
44.5k
    case AARCH64_OPND_SME_Zm_INDEX2:
4148
44.7k
    case AARCH64_OPND_SME_Zm_INDEX2_3:
4149
46.3k
    case AARCH64_OPND_SME_Zm_INDEX3_1:
4150
48.8k
    case AARCH64_OPND_SME_Zm_INDEX3_2:
4151
49.5k
    case AARCH64_OPND_SME_Zm_INDEX3_3:
4152
53.9k
    case AARCH64_OPND_SME_Zm_INDEX3_10:
4153
54.4k
    case AARCH64_OPND_SVE_Zn_5_INDEX:
4154
56.7k
    case AARCH64_OPND_SME_Zm_INDEX4_1:
4155
58.3k
    case AARCH64_OPND_SME_Zm_INDEX4_2:
4156
74.9k
    case AARCH64_OPND_SME_Zm_INDEX4_3:
4157
81.2k
    case AARCH64_OPND_SME_Zm_INDEX4_10:
4158
81.5k
    case AARCH64_OPND_SME_Zn_INDEX1_16:
4159
81.7k
    case AARCH64_OPND_SME_Zn_INDEX2_15:
4160
82.4k
    case AARCH64_OPND_SME_Zn_INDEX2_16:
4161
82.5k
    case AARCH64_OPND_SME_Zn_INDEX2_19:
4162
82.6k
    case AARCH64_OPND_SME_Zn_INDEX3_14:
4163
82.8k
    case AARCH64_OPND_SME_Zn_INDEX3_15:
4164
83.0k
    case AARCH64_OPND_SME_Zn_INDEX4_14:
4165
83.0k
      snprintf (buf, size, "%s[%s]",
4166
83.0k
    (opnd->qualifier == AARCH64_OPND_QLF_NIL
4167
83.0k
     ? style_reg (styler, "z%d", opnd->reglane.regno)
4168
83.0k
     : style_reg (styler, "z%d.%s", opnd->reglane.regno,
4169
74.0k
            aarch64_get_qualifier_name (opnd->qualifier))),
4170
83.0k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4171
83.0k
      break;
4172
4173
50
    case AARCH64_OPND_SVE_Zn0_INDEX:
4174
157
    case AARCH64_OPND_SVE_Zn1_17_INDEX:
4175
270
    case AARCH64_OPND_SVE_Zn2_18_INDEX:
4176
688
    case AARCH64_OPND_SVE_Zn3_22_INDEX:
4177
782
    case AARCH64_OPND_SVE_Zd0_INDEX:
4178
885
    case AARCH64_OPND_SVE_Zd1_17_INDEX:
4179
971
    case AARCH64_OPND_SVE_Zd2_18_INDEX:
4180
1.07k
    case AARCH64_OPND_SVE_Zd3_22_INDEX:
4181
1.07k
      if (opnd->reglane.index == 0)
4182
252
  snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
4183
818
      else
4184
818
  snprintf (buf, size, "%s[%s]",
4185
818
      style_reg (styler, "z%d", opnd->reglane.regno),
4186
818
      style_imm (styler, "%" PRIi64, opnd->reglane.index));
4187
1.07k
      break;
4188
4189
1.72k
    case AARCH64_OPND_SME_ZAda_1b:
4190
70.7k
    case AARCH64_OPND_SME_ZAda_2b:
4191
89.3k
    case AARCH64_OPND_SME_ZAda_3b:
4192
89.3k
      snprintf (buf, size, "%s",
4193
89.3k
    style_reg (styler, "za%d.%s", opnd->reg.regno,
4194
89.3k
         aarch64_get_qualifier_name (opnd->qualifier)));
4195
89.3k
      break;
4196
4197
779
    case AARCH64_OPND_SME_ZA_HV_idx_src:
4198
3.32k
    case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
4199
41.7k
    case AARCH64_OPND_SME_ZA_HV_idx_dest:
4200
42.5k
    case AARCH64_OPND_SME_ZA_HV_idx_destxN:
4201
86.6k
    case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
4202
86.8k
    case AARCH64_OPND_SME_ZA_array_vrsb_1:
4203
86.8k
    case AARCH64_OPND_SME_ZA_array_vrsh_1:
4204
86.9k
    case AARCH64_OPND_SME_ZA_array_vrss_1:
4205
87.2k
    case AARCH64_OPND_SME_ZA_array_vrsd_1:
4206
87.5k
    case AARCH64_OPND_SME_ZA_array_vrsb_2:
4207
88.0k
    case AARCH64_OPND_SME_ZA_array_vrsh_2:
4208
88.2k
    case AARCH64_OPND_SME_ZA_array_vrss_2:
4209
88.5k
    case AARCH64_OPND_SME_ZA_array_vrsd_2:
4210
89.3k
    case AARCH64_OPND_SME_ZA_ARRAY4:
4211
89.3k
      snprintf (buf, size, "%s%s[%s, %s%s%s%s%s]%s",
4212
89.3k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "{" : "",
4213
89.3k
    style_reg (styler, "za%d%c%s%s",
4214
89.3k
         opnd->indexed_za.regno,
4215
89.3k
         opnd->indexed_za.v == 1 ? 'v' : 'h',
4216
89.3k
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4217
89.3k
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4218
89.3k
          ? ""
4219
89.3k
          : aarch64_get_qualifier_name (opnd->qualifier))),
4220
89.3k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4221
89.3k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4222
89.3k
    opnd->indexed_za.index.countm1 ? ":" : "",
4223
89.3k
    (opnd->indexed_za.index.countm1
4224
89.3k
     ? style_imm (styler, "%d",
4225
5.23k
            opnd->indexed_za.index.imm
4226
5.23k
            + opnd->indexed_za.index.countm1)
4227
89.3k
     : ""),
4228
89.3k
    opnd->indexed_za.group_size ? ", " : "",
4229
89.3k
    opnd->indexed_za.group_size == 2
4230
89.3k
    ? style_sub_mnem (styler, "vgx2")
4231
89.3k
    : opnd->indexed_za.group_size == 4
4232
89.3k
    ? style_sub_mnem (styler, "vgx4") : "",
4233
89.3k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "}" : "");
4234
89.3k
      break;
4235
4236
224
    case AARCH64_OPND_SME_list_of_64bit_tiles:
4237
224
      print_sme_za_list (buf, size, opnd->imm.value, styler);
4238
224
      break;
4239
4240
6.16k
    case AARCH64_OPND_SME_ZA_array_off1x4:
4241
12.0k
    case AARCH64_OPND_SME_ZA_array_off2x2:
4242
19.6k
    case AARCH64_OPND_SME_ZA_array_off2x4:
4243
29.9k
    case AARCH64_OPND_SME_ZA_array_off3_0:
4244
30.3k
    case AARCH64_OPND_SME_ZA_array_off3_5:
4245
51.4k
    case AARCH64_OPND_SME_ZA_array_off3x2:
4246
52.3k
    case AARCH64_OPND_SME_ZA_array_off4:
4247
52.3k
      snprintf (buf, size, "%s[%s, %s%s%s%s%s]",
4248
52.3k
    style_reg (styler, "za%s%s",
4249
52.3k
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4250
52.3k
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4251
52.3k
          ? ""
4252
52.3k
          : aarch64_get_qualifier_name (opnd->qualifier))),
4253
52.3k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4254
52.3k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4255
52.3k
    opnd->indexed_za.index.countm1 ? ":" : "",
4256
52.3k
    (opnd->indexed_za.index.countm1
4257
52.3k
     ? style_imm (styler, "%d",
4258
40.6k
            opnd->indexed_za.index.imm
4259
40.6k
            + opnd->indexed_za.index.countm1)
4260
52.3k
     : ""),
4261
52.3k
    opnd->indexed_za.group_size ? ", " : "",
4262
52.3k
    opnd->indexed_za.group_size == 2
4263
52.3k
    ? style_sub_mnem (styler, "vgx2")
4264
52.3k
    : opnd->indexed_za.group_size == 4
4265
38.3k
    ? style_sub_mnem (styler, "vgx4") : "");
4266
52.3k
      break;
4267
4268
3
    case AARCH64_OPND_SME_SM_ZA:
4269
3
      snprintf (buf, size, "%s",
4270
3
    style_reg (styler, opnd->reg.regno == 's' ? "sm" : "za"));
4271
3
      break;
4272
4273
4.55k
    case AARCH64_OPND_SME_PnT_Wm_imm:
4274
4.55k
      snprintf (buf, size, "%s[%s, %s]",
4275
4.55k
    style_reg (styler, "p%d.%s", opnd->indexed_za.regno,
4276
4.55k
         aarch64_get_qualifier_name (opnd->qualifier)),
4277
4.55k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4278
4.55k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm));
4279
4.55k
      break;
4280
4281
77
    case AARCH64_OPND_SME_VLxN_10:
4282
2.59k
    case AARCH64_OPND_SME_VLxN_13:
4283
2.59k
      enum_value = opnd->imm.value;
4284
2.59k
      assert (enum_value < ARRAY_SIZE (aarch64_sme_vlxn_array));
4285
2.59k
      snprintf (buf, size, "%s",
4286
2.59k
    style_sub_mnem (styler, aarch64_sme_vlxn_array[enum_value]));
4287
2.59k
      break;
4288
4289
50
    case AARCH64_OPND_BRBOP:
4290
50
      enum_value = opnd->imm.value;
4291
50
      assert (enum_value < ARRAY_SIZE (aarch64_brbop_array));
4292
50
      snprintf (buf, size, "%s",
4293
50
    style_sub_mnem (styler, aarch64_brbop_array[enum_value]));
4294
50
      break;
4295
4296
4.32k
    case AARCH64_OPND_CRn:
4297
8.64k
    case AARCH64_OPND_CRm:
4298
8.64k
      snprintf (buf, size, "%s",
4299
8.64k
    style_reg (styler, "C%" PRIi64, opnd->imm.value));
4300
8.64k
      break;
4301
4302
10.3k
    case AARCH64_OPND_IDX:
4303
10.9k
    case AARCH64_OPND_MASK:
4304
50.0k
    case AARCH64_OPND_IMM:
4305
75.3k
    case AARCH64_OPND_IMM_2:
4306
109k
    case AARCH64_OPND_WIDTH:
4307
113k
    case AARCH64_OPND_UIMM3_OP1:
4308
118k
    case AARCH64_OPND_UIMM3_OP2:
4309
276k
    case AARCH64_OPND_BIT_NUM:
4310
284k
    case AARCH64_OPND_IMM_VLSL:
4311
297k
    case AARCH64_OPND_IMM_VLSR:
4312
297k
    case AARCH64_OPND_SHLL_IMM:
4313
297k
    case AARCH64_OPND_IMM0:
4314
297k
    case AARCH64_OPND_IMMR:
4315
300k
    case AARCH64_OPND_IMMS:
4316
2.07M
    case AARCH64_OPND_UNDEFINED:
4317
2.07M
    case AARCH64_OPND_FBITS:
4318
2.07M
    case AARCH64_OPND_TME_UIMM16:
4319
2.08M
    case AARCH64_OPND_SIMM5:
4320
2.08M
    case AARCH64_OPND_SME_SHRIMM3:
4321
2.08M
    case AARCH64_OPND_SME_SHRIMM4:
4322
2.08M
    case AARCH64_OPND_SME_SHRIMM5:
4323
2.08M
    case AARCH64_OPND_SVE_SHLIMM_PRED:
4324
2.08M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED:
4325
2.09M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
4326
2.09M
    case AARCH64_OPND_SVE_SHRIMM_PRED:
4327
2.09M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED:
4328
2.09M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
4329
2.10M
    case AARCH64_OPND_SVE_SIMM5:
4330
2.10M
    case AARCH64_OPND_SVE_SIMM5B:
4331
2.10M
    case AARCH64_OPND_SVE_SIMM6:
4332
2.10M
    case AARCH64_OPND_SVE_SIMM8:
4333
2.10M
    case AARCH64_OPND_SVE_UIMM3:
4334
2.12M
    case AARCH64_OPND_SVE_UIMM7:
4335
2.12M
    case AARCH64_OPND_SVE_UIMM8:
4336
2.12M
    case AARCH64_OPND_SVE_UIMM4:
4337
2.13M
    case AARCH64_OPND_SVE_UIMM8_53:
4338
2.13M
    case AARCH64_OPND_IMM_ROT1:
4339
2.15M
    case AARCH64_OPND_IMM_ROT2:
4340
2.15M
    case AARCH64_OPND_IMM_ROT3:
4341
2.15M
    case AARCH64_OPND_SVE_IMM_ROT1:
4342
2.16M
    case AARCH64_OPND_SVE_IMM_ROT2:
4343
2.16M
    case AARCH64_OPND_SVE_IMM_ROT3:
4344
2.16M
    case AARCH64_OPND_CSSC_SIMM8:
4345
2.16M
    case AARCH64_OPND_CSSC_UIMM8:
4346
2.16M
      snprintf (buf, size, "%s",
4347
2.16M
    style_imm (styler, "#%" PRIi64, opnd->imm.value));
4348
2.16M
      break;
4349
4350
98
    case AARCH64_OPND_SVE_I1_HALF_ONE:
4351
296
    case AARCH64_OPND_SVE_I1_HALF_TWO:
4352
1.35k
    case AARCH64_OPND_SVE_I1_ZERO_ONE:
4353
1.35k
      {
4354
1.35k
  single_conv_t c;
4355
1.35k
  c.i = opnd->imm.value;
4356
1.35k
  snprintf (buf, size, "%s", style_imm (styler, "#%.1f", c.f));
4357
1.35k
  break;
4358
296
      }
4359
4360
375
    case AARCH64_OPND_SVE_PATTERN:
4361
375
      if (optional_operand_p (opcode, idx)
4362
375
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4363
59
  break;
4364
316
      enum_value = opnd->imm.value;
4365
316
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4366
316
      if (aarch64_sve_pattern_array[enum_value])
4367
149
  snprintf (buf, size, "%s",
4368
149
      style_reg (styler, aarch64_sve_pattern_array[enum_value]));
4369
167
      else
4370
167
  snprintf (buf, size, "%s",
4371
167
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4372
316
      break;
4373
4374
7.09k
    case AARCH64_OPND_SVE_PATTERN_SCALED:
4375
7.09k
      if (optional_operand_p (opcode, idx)
4376
7.09k
    && !opnd->shifter.operator_present
4377
768
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4378
376
  break;
4379
6.71k
      enum_value = opnd->imm.value;
4380
6.71k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4381
6.71k
      if (aarch64_sve_pattern_array[opnd->imm.value])
4382
4.62k
  snprintf (buf, size, "%s",
4383
4.62k
      style_reg (styler,
4384
4.62k
           aarch64_sve_pattern_array[opnd->imm.value]));
4385
2.09k
      else
4386
2.09k
  snprintf (buf, size, "%s",
4387
2.09k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4388
6.71k
      if (opnd->shifter.operator_present)
4389
6.32k
  {
4390
6.32k
    size_t len = strlen (buf);
4391
6.32k
    const char *shift_name
4392
6.32k
      = aarch64_operand_modifiers[opnd->shifter.kind].name;
4393
6.32k
    snprintf (buf + len, size - len, ", %s %s",
4394
6.32k
        style_sub_mnem (styler, shift_name),
4395
6.32k
        style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4396
6.32k
  }
4397
6.71k
      break;
4398
4399
19.6k
    case AARCH64_OPND_SVE_PRFOP:
4400
19.6k
      enum_value = opnd->imm.value;
4401
19.6k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_prfop_array));
4402
19.6k
      if (aarch64_sve_prfop_array[enum_value])
4403
13.1k
  snprintf (buf, size, "%s",
4404
13.1k
      style_reg (styler, aarch64_sve_prfop_array[enum_value]));
4405
6.50k
      else
4406
6.50k
  snprintf (buf, size, "%s",
4407
6.50k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4408
19.6k
      break;
4409
4410
69.9k
    case AARCH64_OPND_IMM_MOV:
4411
69.9k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4412
69.9k
  {
4413
10.4k
  case 4: /* e.g. MOV Wd, #<imm32>.  */
4414
10.4k
      {
4415
10.4k
        int imm32 = opnd->imm.value;
4416
10.4k
        snprintf (buf, size, "%s",
4417
10.4k
      style_imm (styler, "#0x%-20x", imm32));
4418
10.4k
        snprintf (comment, comment_size, "#%d", imm32);
4419
10.4k
      }
4420
10.4k
    break;
4421
59.4k
  case 8: /* e.g. MOV Xd, #<imm64>.  */
4422
59.4k
    snprintf (buf, size, "%s", style_imm (styler, "#0x%-20" PRIx64,
4423
59.4k
            opnd->imm.value));
4424
59.4k
    snprintf (comment, comment_size, "#%" PRIi64, opnd->imm.value);
4425
59.4k
    break;
4426
0
  default:
4427
0
    snprintf (buf, size, "<invalid>");
4428
0
    break;
4429
69.9k
  }
4430
69.9k
      break;
4431
4432
69.9k
    case AARCH64_OPND_FPIMM0:
4433
545
      snprintf (buf, size, "%s", style_imm (styler, "#0.0"));
4434
545
      break;
4435
4436
158k
    case AARCH64_OPND_LIMM:
4437
384k
    case AARCH64_OPND_AIMM:
4438
412k
    case AARCH64_OPND_HALF:
4439
412k
    case AARCH64_OPND_SVE_INV_LIMM:
4440
432k
    case AARCH64_OPND_SVE_LIMM:
4441
435k
    case AARCH64_OPND_SVE_LIMM_MOV:
4442
435k
      if (opnd->shifter.amount)
4443
99.5k
  snprintf (buf, size, "%s, %s %s",
4444
99.5k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4445
99.5k
      style_sub_mnem (styler, "lsl"),
4446
99.5k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4447
336k
      else
4448
336k
  snprintf (buf, size, "%s",
4449
336k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4450
435k
      break;
4451
4452
603
    case AARCH64_OPND_SIMD_IMM:
4453
4.29k
    case AARCH64_OPND_SIMD_IMM_SFT:
4454
4.29k
      if ((! opnd->shifter.amount && opnd->shifter.kind == AARCH64_MOD_LSL)
4455
3.09k
    || opnd->shifter.kind == AARCH64_MOD_NONE)
4456
1.79k
  snprintf (buf, size, "%s",
4457
1.79k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4458
2.49k
      else
4459
2.49k
  snprintf (buf, size, "%s, %s %s",
4460
2.49k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4461
2.49k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4462
2.49k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4463
4.29k
      break;
4464
4465
1.42k
    case AARCH64_OPND_SVE_AIMM:
4466
10.6k
    case AARCH64_OPND_SVE_ASIMM:
4467
10.6k
      if (opnd->shifter.amount)
4468
218
  snprintf (buf, size, "%s, %s %s",
4469
218
      style_imm (styler, "#%" PRIi64, opnd->imm.value),
4470
218
      style_sub_mnem (styler, "lsl"),
4471
218
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4472
10.4k
      else
4473
10.4k
  snprintf (buf, size, "%s",
4474
10.4k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4475
10.6k
      break;
4476
4477
131
    case AARCH64_OPND_FPIMM:
4478
2.30k
    case AARCH64_OPND_SIMD_FPIMM:
4479
3.14k
    case AARCH64_OPND_SVE_FPIMM8:
4480
3.14k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4481
3.14k
  {
4482
1.87k
  case 2: /* e.g. FMOV <Hd>, #<imm>.  */
4483
1.87k
      {
4484
1.87k
        half_conv_t c;
4485
1.87k
        c.i = expand_fp_imm (2, opnd->imm.value);
4486
1.87k
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4487
1.87k
      }
4488
1.87k
    break;
4489
616
  case 4: /* e.g. FMOV <Vd>.4S, #<imm>.  */
4490
616
      {
4491
616
        single_conv_t c;
4492
616
        c.i = expand_fp_imm (4, opnd->imm.value);
4493
616
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4494
616
      }
4495
616
    break;
4496
653
  case 8: /* e.g. FMOV <Sd>, #<imm>.  */
4497
653
      {
4498
653
        double_conv_t c;
4499
653
        c.i = expand_fp_imm (8, opnd->imm.value);
4500
653
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.d));
4501
653
      }
4502
653
    break;
4503
0
  default:
4504
0
    snprintf (buf, size, "<invalid>");
4505
0
    break;
4506
3.14k
  }
4507
3.14k
      break;
4508
4509
3.14k
    case AARCH64_OPND_CCMP_IMM:
4510
10.2k
    case AARCH64_OPND_NZCV:
4511
11.5k
    case AARCH64_OPND_EXCEPTION:
4512
11.6k
    case AARCH64_OPND_UIMM4:
4513
16.0k
    case AARCH64_OPND_UIMM4_ADDG:
4514
16.1k
    case AARCH64_OPND_UIMM7:
4515
20.4k
    case AARCH64_OPND_UIMM10:
4516
20.4k
      if (optional_operand_p (opcode, idx)
4517
295
    && (opnd->imm.value ==
4518
295
        (int64_t) get_optional_operand_default_value (opcode)))
4519
  /* Omit the operand, e.g. DCPS1.  */
4520
22
  break;
4521
20.4k
      snprintf (buf, size, "%s",
4522
20.4k
    style_imm (styler, "#0x%x", (unsigned int) opnd->imm.value));
4523
20.4k
      break;
4524
4525
18.5k
    case AARCH64_OPND_COND:
4526
19.0k
    case AARCH64_OPND_COND1:
4527
19.0k
      snprintf (buf, size, "%s",
4528
19.0k
    style_sub_mnem (styler, opnd->cond->names[0]));
4529
19.0k
      num_conds = ARRAY_SIZE (opnd->cond->names);
4530
37.9k
      for (i = 1; i < num_conds && opnd->cond->names[i]; ++i)
4531
18.9k
  {
4532
18.9k
    size_t len = comment != NULL ? strlen (comment) : 0;
4533
18.9k
    if (i == 1)
4534
12.6k
      snprintf (comment + len, comment_size - len, "%s = %s",
4535
12.6k
          opnd->cond->names[0], opnd->cond->names[i]);
4536
6.26k
    else
4537
6.26k
      snprintf (comment + len, comment_size - len, ", %s",
4538
6.26k
          opnd->cond->names[i]);
4539
18.9k
  }
4540
19.0k
      break;
4541
4542
148k
    case AARCH64_OPND_ADDR_ADRP:
4543
148k
      addr = ((pc + AARCH64_PCREL_OFFSET) & ~(uint64_t)0xfff)
4544
148k
  + opnd->imm.value;
4545
148k
      if (pcrel_p)
4546
148k
  *pcrel_p = 1;
4547
148k
      if (address)
4548
148k
  *address = addr;
4549
      /* This is not necessary during the disassembling, as print_address_func
4550
   in the disassemble_info will take care of the printing.  But some
4551
   other callers may be still interested in getting the string in *STR,
4552
   so here we do snprintf regardless.  */
4553
148k
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64 , addr));
4554
148k
      break;
4555
4556
69.2k
    case AARCH64_OPND_ADDR_PCREL9:
4557
227k
    case AARCH64_OPND_ADDR_PCREL14:
4558
228k
    case AARCH64_OPND_ADDR_UPCREL16:
4559
673k
    case AARCH64_OPND_ADDR_PCREL19:
4560
1.02M
    case AARCH64_OPND_ADDR_PCREL21:
4561
1.28M
    case AARCH64_OPND_ADDR_PCREL26:
4562
1.28M
      if (opnd->type == AARCH64_OPND_ADDR_UPCREL16)
4563
505
  addr = pc + AARCH64_PCREL_OFFSET - opnd->imm.value;
4564
1.28M
      else
4565
1.28M
  addr = pc + AARCH64_PCREL_OFFSET + opnd->imm.value;
4566
1.28M
      if (pcrel_p)
4567
1.28M
  *pcrel_p = 1;
4568
1.28M
      if (address)
4569
1.28M
  *address = addr;
4570
      /* This is not necessary during the disassembling, as print_address_func
4571
   in the disassemble_info will take care of the printing.  But some
4572
   other callers may be still interested in getting the string in *STR,
4573
   so here we do snprintf regardless.  */
4574
1.28M
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64, addr));
4575
1.28M
      break;
4576
4577
221k
    case AARCH64_OPND_ADDR_SIMPLE:
4578
238k
    case AARCH64_OPND_SIMD_ADDR_SIMPLE:
4579
258k
    case AARCH64_OPND_SIMD_ADDR_POST:
4580
258k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4581
258k
      if (opnd->type == AARCH64_OPND_SIMD_ADDR_POST)
4582
20.2k
  {
4583
20.2k
    if (opnd->addr.offset.is_reg)
4584
17.3k
      snprintf (buf, size, "[%s], %s",
4585
17.3k
          style_reg (styler, name),
4586
17.3k
          style_reg (styler, "x%d", opnd->addr.offset.regno));
4587
2.89k
    else
4588
2.89k
      snprintf (buf, size, "[%s], %s",
4589
2.89k
          style_reg (styler, name),
4590
2.89k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
4591
20.2k
  }
4592
238k
      else
4593
238k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4594
258k
      break;
4595
4596
28.0k
    case AARCH64_OPND_ADDR_REGOFF:
4597
42.1k
    case AARCH64_OPND_SVE_ADDR_RR:
4598
48.6k
    case AARCH64_OPND_SVE_ADDR_RR_LSL1:
4599
53.5k
    case AARCH64_OPND_SVE_ADDR_RR_LSL2:
4600
68.9k
    case AARCH64_OPND_SVE_ADDR_RR_LSL3:
4601
83.9k
    case AARCH64_OPND_SVE_ADDR_RR_LSL4:
4602
92.6k
    case AARCH64_OPND_SVE_ADDR_RM:
4603
96.4k
    case AARCH64_OPND_SVE_ADDR_RM_LSL1:
4604
100k
    case AARCH64_OPND_SVE_ADDR_RM_LSL2:
4605
104k
    case AARCH64_OPND_SVE_ADDR_RM_LSL3:
4606
104k
    case AARCH64_OPND_SVE_ADDR_RM_LSL4:
4607
119k
    case AARCH64_OPND_SVE_ADDR_RX:
4608
129k
    case AARCH64_OPND_SVE_ADDR_RX_LSL1:
4609
140k
    case AARCH64_OPND_SVE_ADDR_RX_LSL2:
4610
144k
    case AARCH64_OPND_SVE_ADDR_RX_LSL3:
4611
148k
    case AARCH64_OPND_SVE_ADDR_RX_LSL4:
4612
148k
      print_register_offset_address
4613
148k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4614
148k
   get_offset_int_reg_name (opnd), styler);
4615
148k
      break;
4616
4617
16.6k
    case AARCH64_OPND_SVE_ADDR_ZX:
4618
16.6k
      print_register_offset_address
4619
16.6k
  (buf, size, opnd,
4620
16.6k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4621
16.6k
   get_64bit_int_reg_name (opnd->addr.offset.regno, 0), styler);
4622
16.6k
      break;
4623
4624
23.0k
    case AARCH64_OPND_SVE_ADDR_RZ:
4625
26.2k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
4626
28.6k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
4627
31.3k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
4628
36.6k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
4629
76.6k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
4630
78.2k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
4631
86.5k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
4632
87.7k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
4633
94.8k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
4634
95.4k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
4635
102k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
4636
102k
      print_register_offset_address
4637
102k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4638
102k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4639
102k
   styler);
4640
102k
      break;
4641
4642
542k
    case AARCH64_OPND_ADDR_SIMM7:
4643
661k
    case AARCH64_OPND_ADDR_SIMM9:
4644
671k
    case AARCH64_OPND_ADDR_SIMM10:
4645
694k
    case AARCH64_OPND_ADDR_SIMM11:
4646
702k
    case AARCH64_OPND_ADDR_SIMM13:
4647
709k
    case AARCH64_OPND_RCPC3_ADDR_OFFSET:
4648
732k
    case AARCH64_OPND_ADDR_OFFSET:
4649
732k
    case AARCH64_OPND_RCPC3_ADDR_OPT_POSTIND:
4650
746k
    case AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB:
4651
746k
    case AARCH64_OPND_RCPC3_ADDR_POSTIND:
4652
746k
    case AARCH64_OPND_RCPC3_ADDR_PREIND_WB:
4653
747k
    case AARCH64_OPND_SME_ADDR_RI_U4xVL:
4654
748k
    case AARCH64_OPND_SVE_ADDR_RI_S4x16:
4655
751k
    case AARCH64_OPND_SVE_ADDR_RI_S4x32:
4656
811k
    case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
4657
822k
    case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
4658
825k
    case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
4659
833k
    case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
4660
836k
    case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
4661
840k
    case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
4662
846k
    case AARCH64_OPND_SVE_ADDR_RI_U6:
4663
851k
    case AARCH64_OPND_SVE_ADDR_RI_U6x2:
4664
853k
    case AARCH64_OPND_SVE_ADDR_RI_U6x4:
4665
854k
    case AARCH64_OPND_SVE_ADDR_RI_U6x8:
4666
854k
      print_immediate_offset_address
4667
854k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4668
854k
   styler);
4669
854k
      break;
4670
4671
5.46k
    case AARCH64_OPND_SVE_ADDR_ZI_U5:
4672
11.9k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
4673
15.0k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
4674
16.6k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
4675
16.6k
      print_immediate_offset_address
4676
16.6k
  (buf, size, opnd,
4677
16.6k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4678
16.6k
   styler);
4679
16.6k
      break;
4680
4681
865
    case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
4682
1.12k
    case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
4683
1.94k
    case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
4684
1.94k
      print_register_offset_address
4685
1.94k
  (buf, size, opnd,
4686
1.94k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4687
1.94k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4688
1.94k
   styler);
4689
1.94k
      break;
4690
4691
236k
    case AARCH64_OPND_ADDR_UIMM12:
4692
236k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4693
236k
      if (opnd->addr.offset.imm)
4694
222k
  snprintf (buf, size, "[%s, %s]",
4695
222k
      style_reg (styler, name),
4696
222k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
4697
13.9k
      else
4698
13.9k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4699
236k
      break;
4700
4701
11.5k
    case AARCH64_OPND_SYSREG:
4702
13.6k
    case AARCH64_OPND_SYSREG128:
4703
13.6k
      {
4704
13.6k
  int min_mismatch = 999;
4705
13.6k
  int best_index = -1;
4706
13.6k
  uint32_t op_flags = opnd->sysreg.flags;
4707
20.8M
  for (i = 0; aarch64_sys_regs[i].name; ++i)
4708
20.8M
    {
4709
20.8M
      const aarch64_sys_reg *sr = aarch64_sys_regs + i;
4710
4711
20.8M
      if (!(aarch64_sys_regs[i].value == opnd->sysreg.value)
4712
2.17k
    || aarch64_sys_reg_deprecated_p (aarch64_sys_regs[i].flags)
4713
2.17k
    || aarch64_sys_reg_alias_p (aarch64_sys_regs[i].flags))
4714
20.8M
        continue;
4715
4716
2.16k
      int mismatch_score = 0;
4717
2.16k
      if (!AARCH64_CPU_HAS_ALL_FEATURES (features, sr->features))
4718
649
        mismatch_score += 1;
4719
      /* This read/write check only works during disassembly.  During
4720
         assembly the value of op_flags was copied from sr->flags.  */
4721
2.16k
      if (((sr->flags & F_REG_READ) && (op_flags & F_REG_WRITE))
4722
1.78k
    || ((sr->flags & F_REG_WRITE) && (op_flags & F_REG_READ)))
4723
448
        mismatch_score += 2;
4724
4725
2.16k
      if (mismatch_score < min_mismatch)
4726
2.16k
        {
4727
2.16k
    min_mismatch = mismatch_score;
4728
2.16k
    best_index = i;
4729
2.16k
    if (mismatch_score == 0)
4730
1.06k
      break;
4731
2.16k
        }
4732
2.16k
    }
4733
13.6k
  if (best_index == -1)
4734
11.4k
    {
4735
      /* Use encoding-based name for unrecognised system register.  */
4736
11.4k
      unsigned int value = opnd->sysreg.value;
4737
11.4k
      snprintf (buf, size, "%s",
4738
11.4k
          style_reg (styler, "s%u_%u_c%u_c%u_%u",
4739
11.4k
         (value >> 14) & 0x3, (value >> 11) & 0x7,
4740
11.4k
         (value >> 7) & 0xf, (value >> 3) & 0xf,
4741
11.4k
         value & 0x7));
4742
11.4k
    }
4743
2.14k
  else
4744
2.14k
    {
4745
2.14k
      const aarch64_sys_reg *sr = aarch64_sys_regs + best_index;
4746
2.14k
      snprintf (buf, size, "%s", style_reg (styler, sr->name));
4747
4748
      /* Add a note if we violated read/write constraints.  */
4749
2.14k
      if (notes && min_mismatch)
4750
1.07k
        {
4751
1.07k
    if ((sr->flags & F_REG_READ) && (op_flags & F_REG_WRITE))
4752
362
      *notes = _("writing to a read-only register");
4753
717
    else if ((sr->flags & F_REG_WRITE) && (op_flags & F_REG_READ))
4754
68
      *notes = _("reading from a write-only register");
4755
1.07k
        }
4756
2.14k
    }
4757
13.6k
  break;
4758
11.5k
      }
4759
4760
68
    case AARCH64_OPND_PSTATEFIELD:
4761
266
      for (i = 0; aarch64_pstatefields[i].name; ++i)
4762
266
        if (aarch64_pstatefields[i].value == opnd->pstatefield)
4763
68
          {
4764
            /* PSTATEFIELD name is encoded partially in CRm[3:1] for SVCRSM,
4765
               SVCRZA and SVCRSMZA.  */
4766
68
            uint32_t flags = aarch64_pstatefields[i].flags;
4767
68
            if (flags & F_REG_IN_CRM
4768
0
                && (PSTATE_DECODE_CRM (opnd->sysreg.flags)
4769
0
                    != PSTATE_DECODE_CRM (flags)))
4770
0
              continue;
4771
68
            break;
4772
68
          }
4773
68
      assert (aarch64_pstatefields[i].name);
4774
68
      snprintf (buf, size, "%s",
4775
68
    style_reg (styler, aarch64_pstatefields[i].name));
4776
68
      break;
4777
4778
95
    case AARCH64_OPND_GIC:
4779
95
    case AARCH64_OPND_GICR:
4780
95
    case AARCH64_OPND_GSB:
4781
212
    case AARCH64_OPND_SYSREG_AT:
4782
252
    case AARCH64_OPND_SYSREG_DC:
4783
252
    case AARCH64_OPND_SYSREG_IC:
4784
436
    case AARCH64_OPND_SYSREG_TLBI:
4785
489
    case AARCH64_OPND_SYSREG_TLBIP:
4786
521
    case AARCH64_OPND_SYSREG_PLBI:
4787
522
    case AARCH64_OPND_SYSREG_SR:
4788
522
      snprintf (buf, size, "%s", style_reg (styler, opnd->sysins_op->name));
4789
522
      break;
4790
4791
107
    case AARCH64_OPND_BARRIER:
4792
157
    case AARCH64_OPND_BARRIER_DSB_NXS:
4793
157
      {
4794
157
  if (opnd->barrier->name[0] == '#')
4795
102
    snprintf (buf, size, "%s", style_imm (styler, opnd->barrier->name));
4796
55
  else
4797
55
    snprintf (buf, size, "%s",
4798
55
        style_sub_mnem (styler, opnd->barrier->name));
4799
157
      }
4800
157
      break;
4801
4802
170
    case AARCH64_OPND_BARRIER_ISB:
4803
      /* Operand can be omitted, e.g. in DCPS1.  */
4804
170
      if (! optional_operand_p (opcode, idx)
4805
170
    || (opnd->barrier->value
4806
170
        != get_optional_operand_default_value (opcode)))
4807
39
  snprintf (buf, size, "%s",
4808
39
      style_imm (styler, "#0x%x", opnd->barrier->value));
4809
170
      break;
4810
4811
45.3k
    case AARCH64_OPND_PRFOP:
4812
45.3k
      if ((opnd->prfop->name == NULL)
4813
39.6k
          || (opcode->iclass != ldst_pos && opnd->prfop->value == 0x18))
4814
18.6k
        snprintf (buf, size, "%s",
4815
18.6k
                  style_imm (styler, "#0x%02x", opnd->prfop->value));
4816
26.7k
      else
4817
26.7k
        snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->prfop->name));
4818
45.3k
      break;
4819
4820
907
    case AARCH64_OPND_RPRFMOP:
4821
907
      enum_value = opnd->imm.value;
4822
907
      if (enum_value < ARRAY_SIZE (aarch64_rprfmop_array)
4823
907
    && aarch64_rprfmop_array[enum_value])
4824
330
  snprintf (buf, size, "%s",
4825
330
      style_reg (styler, aarch64_rprfmop_array[enum_value]));
4826
577
      else
4827
577
  snprintf (buf, size, "%s",
4828
577
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4829
907
      break;
4830
4831
101
    case AARCH64_OPND_BARRIER_PSB:
4832
101
      snprintf (buf, size, "%s", style_sub_mnem (styler, "csync"));
4833
101
      break;
4834
4835
0
    case AARCH64_OPND_X16:
4836
0
      snprintf (buf, size, "%s", style_reg (styler, "x16"));
4837
0
      break;
4838
4839
2.07k
    case AARCH64_OPND_SME_ZT0:
4840
2.07k
      snprintf (buf, size, "%s", style_reg (styler, "zt0"));
4841
2.07k
      break;
4842
4843
110
    case AARCH64_OPND_SME_ZT0_INDEX:
4844
110
      snprintf (buf, size, "%s[%s]", style_reg (styler, "zt0"),
4845
110
    style_imm (styler, "%d", (int) opnd->imm.value));
4846
110
      break;
4847
333
    case AARCH64_OPND_SME_ZT0_INDEX_MUL_VL:
4848
333
      snprintf (buf, size, "%s[%s, %s]", style_reg (styler, "zt0"),
4849
333
    style_imm (styler, "%d", (int) opnd->imm.value),
4850
333
    style_sub_mnem (styler, "mul vl"));
4851
333
      break;
4852
4853
82
    case AARCH64_OPND_SME_ZT0_LIST:
4854
82
      snprintf (buf, size, "{%s}", style_reg (styler, "zt0"));
4855
82
      break;
4856
4857
0
    case AARCH64_OPND_BARRIER_GCSB:
4858
0
      snprintf (buf, size, "%s", style_sub_mnem (styler, "dsync"));
4859
0
      break;
4860
4861
1
    case AARCH64_OPND_NOT_BALANCED_10:
4862
371
    case AARCH64_OPND_NOT_BALANCED_17:
4863
371
      if (opnd->imm.value)
4864
69
  snprintf (buf, size, "%s", style_sub_mnem (styler, "nb"));
4865
371
      break;
4866
4867
219
    case AARCH64_OPND_BTI_TARGET:
4868
219
      snprintf (buf, size, "%s",
4869
219
    style_sub_mnem (styler, opnd->hint_option->name));
4870
219
      break;
4871
4872
28
    case AARCH64_OPND_STSHH_POLICY:
4873
28
      snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->hint_option->name));
4874
28
      break;
4875
4876
0
    case AARCH64_OPND_SHUH_PHINT:
4877
0
      if (*(opnd->hint_option->name))
4878
0
  snprintf (buf, size, "%s",
4879
0
      style_sub_mnem (styler, opnd->hint_option->name));
4880
0
      break;
4881
4882
8.47k
    case AARCH64_OPND_MOPS_ADDR_Rd:
4883
15.2k
    case AARCH64_OPND_MOPS_ADDR_Rs:
4884
15.2k
      snprintf (buf, size, "[%s]!",
4885
15.2k
    style_reg (styler,
4886
15.2k
         get_int_reg_name (opnd->reg.regno,
4887
15.2k
               AARCH64_OPND_QLF_X, 0)));
4888
15.2k
      break;
4889
4890
8.47k
    case AARCH64_OPND_MOPS_WB_Rn:
4891
8.47k
      snprintf (buf, size, "%s!",
4892
8.47k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
4893
8.47k
                 AARCH64_OPND_QLF_X, 0)));
4894
8.47k
      break;
4895
4896
0
    default:
4897
0
      snprintf (buf, size, "<invalid>");
4898
0
      break;
4899
15.2M
    }
4900
15.2M
}
4901

4902
#define CPENC(op0,op1,crn,crm,op2) \
4903
  ((((op0) << 19) | ((op1) << 16) | ((crn) << 12) | ((crm) << 8) | ((op2) << 5)) >> 5)
4904
  /* for 3.9.3 Instructions for Accessing Special Purpose Registers */
4905
#define CPEN_(op1,crm,op2) CPENC(3,(op1),4,(crm),(op2))
4906
  /* for 3.9.10 System Instructions */
4907
#define CPENS(op1,crn,crm,op2) CPENC(1,(op1),(crn),(crm),(op2))
4908
4909
#define C0  0
4910
#define C1  1
4911
#define C2  2
4912
#define C3  3
4913
#define C4  4
4914
#define C5  5
4915
#define C6  6
4916
#define C7  7
4917
#define C8  8
4918
#define C9  9
4919
#define C10 10
4920
#define C11 11
4921
#define C12 12
4922
#define C13 13
4923
#define C14 14
4924
#define C15 15
4925
4926
/* TODO there is one more issues need to be resolved
4927
   1. handle cpu-implementation-defined system registers.
4928
4929
   Note that the F_REG_{READ,WRITE} flags mean read-only and write-only
4930
   respectively.  If neither of these are set then the register is read-write.  */
4931
const aarch64_sys_reg aarch64_sys_regs [] =
4932
{
4933
  #define SYSREG(name, encoding, flags, features) \
4934
    { name, encoding, flags, features },
4935
  #include "aarch64-sys-regs.def"
4936
  { 0, CPENC (0,0,0,0,0), 0, AARCH64_NO_FEATURES }
4937
  #undef SYSREG
4938
};
4939
4940
bool
4941
aarch64_sys_reg_deprecated_p (const uint32_t reg_flags)
4942
2.17k
{
4943
2.17k
  return (reg_flags & F_DEPRECATED) != 0;
4944
2.17k
}
4945
4946
bool
4947
aarch64_sys_reg_128bit_p (const uint32_t reg_flags)
4948
0
{
4949
0
  return (reg_flags & F_REG_128) != 0;
4950
0
}
4951
4952
bool
4953
aarch64_sys_reg_alias_p (const uint32_t reg_flags)
4954
2.17k
{
4955
2.17k
  return (reg_flags & F_REG_ALIAS) != 0;
4956
2.17k
}
4957
4958
/* The CPENC below is fairly misleading, the fields
4959
   here are not in CPENC form. They are in op2op1 form. The fields are encoded
4960
   by ins_pstatefield, which just shifts the value by the width of the fields
4961
   in a loop. So if you CPENC them only the first value will be set, the rest
4962
   are masked out to 0. As an example. op2 = 3, op1=2. CPENC would produce a
4963
   value of 0b110000000001000000 (0x30040) while what you want is
4964
   0b011010 (0x1a).  */
4965
const aarch64_sys_reg aarch64_pstatefields [] =
4966
{
4967
  { "spsel",  0x05, F_REG_MAX_VALUE (1), AARCH64_NO_FEATURES },
4968
  { "daifset",  0x1e, F_REG_MAX_VALUE (15), AARCH64_NO_FEATURES },
4969
  { "daifclr",  0x1f, F_REG_MAX_VALUE (15), AARCH64_NO_FEATURES },
4970
  { "pan",  0x04, F_REG_MAX_VALUE (1), AARCH64_FEATURE (PAN) },
4971
  { "uao",  0x03, F_REG_MAX_VALUE (1), AARCH64_FEATURE (V8_2A) },
4972
  { "ssbs", 0x19, F_REG_MAX_VALUE (1), AARCH64_FEATURE (SSBS) },
4973
  { "dit",  0x1a, F_REG_MAX_VALUE (1), AARCH64_FEATURE (V8_4A) },
4974
  { "tco",  0x1c, F_REG_MAX_VALUE (1), AARCH64_FEATURE (MEMTAG) },
4975
  { "svcrsm", 0x1b, PSTATE_ENCODE_CRM_AND_IMM (0x2,0x1) | F_REG_MAX_VALUE (1),
4976
    AARCH64_FEATURE (SME) },
4977
  { "svcrza", 0x1b, PSTATE_ENCODE_CRM_AND_IMM (0x4,0x1) | F_REG_MAX_VALUE (1),
4978
    AARCH64_FEATURE (SME) },
4979
  { "svcrsmza", 0x1b, PSTATE_ENCODE_CRM_AND_IMM (0x6,0x1) | F_REG_MAX_VALUE (1),
4980
    AARCH64_FEATURE (SME) },
4981
  { "allint", 0x08, F_REG_MAX_VALUE (1), AARCH64_FEATURE (V8_8A) },
4982
  { 0,  CPENC (0,0,0,0,0), 0, AARCH64_NO_FEATURES },
4983
};
4984
4985
bool
4986
aarch64_pstatefield_supported_p (const aarch64_feature_set features,
4987
         const aarch64_sys_reg *reg)
4988
0
{
4989
0
  return AARCH64_CPU_HAS_ALL_FEATURES (features, reg->features);
4990
0
}
4991
4992
const aarch64_sys_ins_reg aarch64_sys_regs_ic[] =
4993
{
4994
    { "ialluis", CPENS(0,C7,C1,0), 0, AARCH64_NO_FEATURES },
4995
    { "iallu",   CPENS(0,C7,C5,0), 0, AARCH64_NO_FEATURES },
4996
    { "ivau",    CPENS (3, C7, C5, 1), F_HASXT, AARCH64_NO_FEATURES },
4997
    { 0, CPENS(0,0,0,0), 0, AARCH64_NO_FEATURES }
4998
};
4999
5000
const aarch64_sys_ins_reg aarch64_sys_regs_dc[] =
5001
{
5002
    { "zva",      CPENS (3, C7, C4, 1),  F_HASXT, AARCH64_NO_FEATURES },
5003
    { "gva",      CPENS (3, C7, C4, 3),  F_HASXT, AARCH64_FEATURE (MEMTAG) },
5004
    { "gzva",     CPENS (3, C7, C4, 4),  F_HASXT, AARCH64_FEATURE (MEMTAG) },
5005
    { "zgbva",      CPENS (3, C7, C4, 5),  F_HASXT, AARCH64_FEATURE (MTETC) },
5006
    { "gbva",     CPENS (3, C7, C4, 7),  F_HASXT, AARCH64_FEATURE (MTETC) },
5007
    { "ivac",       CPENS (0, C7, C6, 1),  F_HASXT, AARCH64_NO_FEATURES },
5008
    { "igvac",      CPENS (0, C7, C6, 3),  F_HASXT, AARCH64_FEATURE (MEMTAG) },
5009
    { "igsw",       CPENS (0, C7, C6, 4),  F_HASXT, AARCH64_FEATURE (MEMTAG) },
5010
    { "isw",      CPENS (0, C7, C6, 2),  F_HASXT, AARCH64_NO_FEATURES },
5011
    { "igdvac",     CPENS (0, C7, C6, 5),  F_HASXT, AARCH64_FEATURE (MEMTAG) },
5012
    { "igdsw",      CPENS (0, C7, C6, 6),  F_HASXT, AARCH64_FEATURE (MEMTAG) },
5013
    { "cigdvaps",   CPENS (0, C7, C15, 5), F_HASXT, AARCH64_FEATURES (2, MEMTAG, PoPS) },
5014
    { "civaps",     CPENS (0, C7, C15, 1), F_HASXT, AARCH64_FEATURE (PoPS) },
5015
    { "cvac",       CPENS (3, C7, C10, 1), F_HASXT, AARCH64_NO_FEATURES },
5016
    { "cgvac",      CPENS (3, C7, C10, 3), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5017
    { "cgdvac",     CPENS (3, C7, C10, 5), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5018
    { "cvaoc",      CPENS (3, C7, C11, 0), F_HASXT, AARCH64_FEATURE (OCCMO) },
5019
    { "cgdvaoc",    CPENS (3, C7, C11, 7), F_HASXT, AARCH64_FEATURES (2, OCCMO, MEMTAG) },
5020
    { "csw",      CPENS (0, C7, C10, 2), F_HASXT, AARCH64_NO_FEATURES },
5021
    { "cgsw",       CPENS (0, C7, C10, 4), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5022
    { "cgdsw",      CPENS (0, C7, C10, 6), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5023
    { "cvau",       CPENS (3, C7, C11, 1), F_HASXT, AARCH64_NO_FEATURES },
5024
    { "cvap",       CPENS (3, C7, C12, 1), F_HASXT, AARCH64_FEATURE (V8_2A) },
5025
    { "cgvap",      CPENS (3, C7, C12, 3), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5026
    { "cgdvap",     CPENS (3, C7, C12, 5), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5027
    { "cvadp",      CPENS (3, C7, C13, 1), F_HASXT, AARCH64_FEATURE (CVADP) },
5028
    { "cgvadp",     CPENS (3, C7, C13, 3), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5029
    { "cgdvadp",    CPENS (3, C7, C13, 5), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5030
    { "civac",      CPENS (3, C7, C14, 1), F_HASXT, AARCH64_NO_FEATURES },
5031
    { "cigvac",     CPENS (3, C7, C14, 3), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5032
    { "cigdvac",    CPENS (3, C7, C14, 5), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5033
    { "cisw",       CPENS (0, C7, C14, 2), F_HASXT, AARCH64_NO_FEATURES },
5034
    { "cigsw",      CPENS (0, C7, C14, 4), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5035
    { "cigdsw",     CPENS (0, C7, C14, 6), F_HASXT, AARCH64_FEATURE (MEMTAG) },
5036
    { "civaoc",     CPENS (3, C7, C15, 0), F_HASXT, AARCH64_FEATURE (OCCMO) },
5037
    { "cigdvaoc",   CPENS (3, C7, C15, 7), F_HASXT, AARCH64_FEATURES (2, OCCMO, MEMTAG) },
5038
    { "cipae",      CPENS (4, C7, C14, 0), F_HASXT, AARCH64_FEATURE (V8_7A) },
5039
    { "cigdpae",    CPENS (4, C7, C14, 7), F_HASXT, AARCH64_FEATURE (V8_7A) },
5040
    { "cipapa",     CPENS (6, C7, C14, 1), F_HASXT, AARCH64_NO_FEATURES },
5041
    { "cigdpapa",   CPENS (6, C7, C14, 5), F_HASXT, AARCH64_NO_FEATURES },
5042
    { 0,       CPENS(0,0,0,0), 0, AARCH64_NO_FEATURES }
5043
};
5044
5045
const aarch64_sys_ins_reg aarch64_sys_regs_at[] =
5046
{
5047
    { "s1e1r",      CPENS (0, C7, C8, 0), F_HASXT, AARCH64_NO_FEATURES },
5048
    { "s1e1w",      CPENS (0, C7, C8, 1), F_HASXT, AARCH64_NO_FEATURES },
5049
    { "s1e0r",      CPENS (0, C7, C8, 2), F_HASXT, AARCH64_NO_FEATURES },
5050
    { "s1e0w",      CPENS (0, C7, C8, 3), F_HASXT, AARCH64_NO_FEATURES },
5051
    { "s12e1r",     CPENS (4, C7, C8, 4), F_HASXT, AARCH64_NO_FEATURES },
5052
    { "s12e1w",     CPENS (4, C7, C8, 5), F_HASXT, AARCH64_NO_FEATURES },
5053
    { "s12e0r",     CPENS (4, C7, C8, 6), F_HASXT, AARCH64_NO_FEATURES },
5054
    { "s12e0w",     CPENS (4, C7, C8, 7), F_HASXT, AARCH64_NO_FEATURES },
5055
    { "s1e2r",      CPENS (4, C7, C8, 0), F_HASXT, AARCH64_NO_FEATURES },
5056
    { "s1e2w",      CPENS (4, C7, C8, 1), F_HASXT, AARCH64_NO_FEATURES },
5057
    { "s1e3r",      CPENS (6, C7, C8, 0), F_HASXT, AARCH64_NO_FEATURES },
5058
    { "s1e3w",      CPENS (6, C7, C8, 1), F_HASXT, AARCH64_NO_FEATURES },
5059
    { "s1e1rp",     CPENS (0, C7, C9, 0), F_HASXT, AARCH64_FEATURE (V8_2A) },
5060
    { "s1e1wp",     CPENS (0, C7, C9, 1), F_HASXT, AARCH64_FEATURE (V8_2A) },
5061
    { "s1e1a",      CPENS (0, C7, C9, 2), F_HASXT, AARCH64_FEATURE (ATS1A) },
5062
    { "s1e2a",      CPENS (4, C7, C9, 2), F_HASXT, AARCH64_FEATURE (ATS1A) },
5063
    { "s1e3a",      CPENS (6, C7, C9, 2), F_HASXT, AARCH64_FEATURE (ATS1A) },
5064
    { 0,       CPENS(0,0,0,0), 0, AARCH64_NO_FEATURES }
5065
};
5066
5067
const aarch64_sys_ins_reg aarch64_sys_regs_tlbi[] =
5068
{
5069
    { "rpaos",      CPENS (6, C8, C4, 3), F_HASXT, AARCH64_NO_FEATURES },
5070
    { "rpalos",     CPENS (6, C8, C4, 7), F_HASXT, AARCH64_NO_FEATURES },
5071
    { "paallos",    CPENS (6, C8, C1, 4), 0, AARCH64_NO_FEATURES },
5072
    { "paall",      CPENS (6, C8, C7, 4), 0, AARCH64_NO_FEATURES },
5073
5074
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5075
    { OP, CODE, FLAGS,  AARCH64_FEATURE (TLBID)}, \
5076
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURES (2, XS, TLBID)},
5077
5078
    TLBI_XS_OP ( "vmalle1is", CPENS (0, C8, C3, 0), F_TLBID_XT)
5079
    TLBI_XS_OP ( "vmalls12e1is",CPENS(4,C8, C3, 6), F_TLBID_XT)
5080
    TLBI_XS_OP ( "alle2is",   CPENS (4, C8, C3, 0), F_TLBID_XT)
5081
    TLBI_XS_OP ( "alle1is",   CPENS (4, C8, C3, 4), F_TLBID_XT)
5082
#undef TLBI_XS_OP
5083
5084
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5085
    { OP, CODE, FLAGS,  AARCH64_FEATURE (D128_TLBID)}, \
5086
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURES (2, XS, D128_TLBID)},
5087
5088
    TLBI_XS_OP ( "vae1is",    CPENS (0, C8, C3, 1), F_HASXT | F_REG_128)
5089
    TLBI_XS_OP ( "vaae1is",   CPENS (0, C8, C3, 3), F_HASXT | F_REG_128)
5090
    TLBI_XS_OP ( "ipas2e1is", CPENS (4, C8, C0, 1), F_HASXT | F_REG_128)
5091
    TLBI_XS_OP ( "ipas2le1is",CPENS (4, C8, C0, 5), F_HASXT | F_REG_128)
5092
    TLBI_XS_OP ( "vale1is",   CPENS (0, C8, C3, 5), F_HASXT | F_REG_128)
5093
    TLBI_XS_OP ( "vaale1is",  CPENS (0, C8, C3, 7), F_HASXT | F_REG_128)
5094
    TLBI_XS_OP ( "vae2is",    CPENS (4, C8, C3, 1), F_HASXT | F_REG_128)
5095
    TLBI_XS_OP ( "vale2is",   CPENS (4, C8, C3, 5), F_HASXT | F_REG_128)
5096
#undef TLBI_XS_OP
5097
5098
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5099
    { OP, CODE, FLAGS,  AARCH64_NO_FEATURES}, \
5100
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURE (XS)},
5101
5102
    TLBI_XS_OP ( "vmalle1",   CPENS (0, C8, C7, 0), 0)
5103
    TLBI_XS_OP ( "vmalls12e1",CPENS (4, C8, C7, 6), 0)
5104
    TLBI_XS_OP ( "alle2",     CPENS (4, C8, C7, 0), 0)
5105
    TLBI_XS_OP ( "alle1",     CPENS (4, C8, C7, 4), 0)
5106
    TLBI_XS_OP ( "alle3",     CPENS (6, C8, C7, 0), 0)
5107
    TLBI_XS_OP ( "alle3is",   CPENS (6, C8, C3, 0), 0)
5108
#undef TLBI_XS_OP
5109
5110
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5111
    { OP, CODE, FLAGS,  AARCH64_FEATURE (D128)}, \
5112
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURES (2, XS, D128)},
5113
5114
    TLBI_XS_OP ( "vae1",      CPENS (0, C8, C7, 1), F_HASXT | F_REG_128)
5115
    TLBI_XS_OP ( "aside1",    CPENS (0, C8, C7, 2), F_HASXT)
5116
    TLBI_XS_OP ( "vaae1",     CPENS (0, C8, C7, 3), F_HASXT | F_REG_128)
5117
    TLBI_XS_OP ( "aside1is",  CPENS (0, C8, C3, 2), F_HASXT)
5118
    TLBI_XS_OP ( "ipas2e1",   CPENS (4, C8, C4, 1), F_HASXT | F_REG_128)
5119
    TLBI_XS_OP ( "ipas2le1",  CPENS (4, C8, C4, 5), F_HASXT | F_REG_128)
5120
    TLBI_XS_OP ( "vae2",      CPENS (4, C8, C7, 1), F_HASXT | F_REG_128)
5121
    TLBI_XS_OP ( "vae3",      CPENS (6, C8, C7, 1), F_HASXT | F_REG_128)
5122
    TLBI_XS_OP ( "vae3is",    CPENS (6, C8, C3, 1), F_HASXT | F_REG_128)
5123
    TLBI_XS_OP ( "vale3is",   CPENS (6, C8, C3, 5), F_HASXT | F_REG_128)
5124
    TLBI_XS_OP ( "vale1",     CPENS (0, C8, C7, 5), F_HASXT | F_REG_128)
5125
    TLBI_XS_OP ( "vale2",     CPENS (4, C8, C7, 5), F_HASXT | F_REG_128)
5126
    TLBI_XS_OP ( "vale3",     CPENS (6, C8, C7, 5), F_HASXT | F_REG_128)
5127
    TLBI_XS_OP ( "vaale1",    CPENS (0, C8, C7, 7), F_HASXT | F_REG_128)
5128
#undef TLBI_XS_OP
5129
5130
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5131
    { OP, CODE, FLAGS,  AARCH64_FEATURES (2, V8_4A, TLBID)}, \
5132
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURES (2, XS, TLBID)},
5133
5134
    TLBI_XS_OP ( "vmalle1os",    CPENS (0, C8, C1, 0), F_TLBID_XT)
5135
    TLBI_XS_OP ( "vmalls12e1os", CPENS (4, C8, C1, 6), F_TLBID_XT)
5136
    TLBI_XS_OP ( "alle2os",      CPENS (4, C8, C1, 0), F_TLBID_XT)
5137
    TLBI_XS_OP ( "alle1os",      CPENS (4, C8, C1, 4), F_TLBID_XT)
5138
    TLBI_XS_OP ( "vmallws2e1is", CPENS (4, C8, C2, 2), F_TLBID_XT)
5139
    TLBI_XS_OP ( "vmallws2e1os", CPENS (4, C8, C5, 2), F_TLBID_XT)
5140
#undef TLBI_XS_OP
5141
5142
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5143
    { OP, CODE, FLAGS,  AARCH64_FEATURES (2, V8_4A, D128_TLBID)}, \
5144
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURES (2, XS, D128_TLBID)},
5145
5146
    TLBI_XS_OP ( "vae1os",       CPENS (0, C8, C1, 1), F_HASXT | F_REG_128)
5147
    TLBI_XS_OP ( "vaae1os",      CPENS (0, C8, C1, 3), F_HASXT | F_REG_128)
5148
    TLBI_XS_OP ( "vale1os",      CPENS (0, C8, C1, 5), F_HASXT | F_REG_128)
5149
    TLBI_XS_OP ( "vaale1os",     CPENS (0, C8, C1, 7), F_HASXT | F_REG_128)
5150
    TLBI_XS_OP ( "ipas2e1os",    CPENS (4, C8, C4, 0), F_HASXT | F_REG_128)
5151
    TLBI_XS_OP ( "ipas2le1os",   CPENS (4, C8, C4, 4), F_HASXT | F_REG_128)
5152
    TLBI_XS_OP ( "vae2os",       CPENS (4, C8, C1, 1), F_HASXT | F_REG_128)
5153
    TLBI_XS_OP ( "vale2os",      CPENS (4, C8, C1, 5), F_HASXT | F_REG_128)
5154
    TLBI_XS_OP ( "rvae1is",    CPENS (0, C8, C2, 1), F_HASXT | F_REG_128)
5155
    TLBI_XS_OP ( "rvaae1is",   CPENS (0, C8, C2, 3), F_HASXT | F_REG_128)
5156
    TLBI_XS_OP ( "rvale1is",   CPENS (0, C8, C2, 5), F_HASXT | F_REG_128)
5157
    TLBI_XS_OP ( "rvaale1is",  CPENS (0, C8, C2, 7), F_HASXT | F_REG_128)
5158
    TLBI_XS_OP ( "rvae1os",    CPENS (0, C8, C5, 1), F_HASXT | F_REG_128)
5159
    TLBI_XS_OP ( "rvaae1os",   CPENS (0, C8, C5, 3), F_HASXT | F_REG_128)
5160
    TLBI_XS_OP ( "rvale1os",   CPENS (0, C8, C5, 5), F_HASXT | F_REG_128)
5161
    TLBI_XS_OP ( "rvaale1os",  CPENS (0, C8, C5, 7), F_HASXT | F_REG_128)
5162
    TLBI_XS_OP ( "ripas2e1is", CPENS (4, C8, C0, 2), F_HASXT | F_REG_128)
5163
    TLBI_XS_OP ( "ripas2le1is",CPENS (4, C8, C0, 6), F_HASXT | F_REG_128)
5164
    TLBI_XS_OP ( "ripas2e1os", CPENS (4, C8, C4, 3), F_HASXT | F_REG_128)
5165
    TLBI_XS_OP ( "ripas2le1os",CPENS (4, C8, C4, 7), F_HASXT | F_REG_128)
5166
    TLBI_XS_OP ( "rvae2is",    CPENS (4, C8, C2, 1), F_HASXT | F_REG_128)
5167
    TLBI_XS_OP ( "rvale2is",   CPENS (4, C8, C2, 5), F_HASXT | F_REG_128)
5168
    TLBI_XS_OP ( "rvae2os",    CPENS (4, C8, C5, 1), F_HASXT | F_REG_128)
5169
    TLBI_XS_OP ( "rvale2os",   CPENS (4, C8, C5, 5), F_HASXT | F_REG_128)
5170
#undef TLBI_XS_OP
5171
5172
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5173
    { OP, CODE, FLAGS,  AARCH64_FEATURE (V8_4A)}, \
5174
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURE (XS)},
5175
5176
    TLBI_XS_OP ( "alle3os",      CPENS (6, C8, C1, 0), 0)
5177
    TLBI_XS_OP ( "vmallws2e1",  CPENS (4, C8, C6, 3), 0)
5178
#undef TLBI_XS_OP
5179
5180
#define TLBI_XS_OP(OP, CODE, FLAGS) \
5181
    { OP, CODE, FLAGS,  AARCH64_FEATURES (2, V8_4A, D128)}, \
5182
    { OP "nxs", CODE | CPENS (0, C9, 0, 0), FLAGS, AARCH64_FEATURES (2, XS, D128)},
5183
5184
    TLBI_XS_OP ( "aside1os",     CPENS (0, C8, C1, 2), F_HASXT)
5185
    TLBI_XS_OP ( "vae3os",       CPENS (6, C8, C1, 1), F_HASXT | F_REG_128 )
5186
    TLBI_XS_OP ( "vale3os",      CPENS (6, C8, C1, 5), F_HASXT | F_REG_128 )
5187
5188
    TLBI_XS_OP ( "rvae1",      CPENS (0, C8, C6, 1), F_HASXT | F_REG_128 )
5189
    TLBI_XS_OP ( "rvaae1",     CPENS (0, C8, C6, 3), F_HASXT | F_REG_128 )
5190
    TLBI_XS_OP ( "rvale1",     CPENS (0, C8, C6, 5), F_HASXT | F_REG_128 )
5191
    TLBI_XS_OP ( "rvaale1",    CPENS (0, C8, C6, 7), F_HASXT | F_REG_128 )
5192
    TLBI_XS_OP ( "ripas2e1",   CPENS (4, C8, C4, 2), F_HASXT | F_REG_128 )
5193
    TLBI_XS_OP ( "ripas2le1",  CPENS (4, C8, C4, 6), F_HASXT | F_REG_128 )
5194
    TLBI_XS_OP ( "rvae2",      CPENS (4, C8, C6, 1), F_HASXT | F_REG_128 )
5195
    TLBI_XS_OP ( "rvale2",     CPENS (4, C8, C6, 5), F_HASXT | F_REG_128 )
5196
    TLBI_XS_OP ( "rvae3",      CPENS (6, C8, C6, 1), F_HASXT | F_REG_128 )
5197
    TLBI_XS_OP ( "rvale3",     CPENS (6, C8, C6, 5), F_HASXT | F_REG_128 )
5198
    TLBI_XS_OP ( "rvae3is",    CPENS (6, C8, C2, 1), F_HASXT | F_REG_128 )
5199
    TLBI_XS_OP ( "rvale3is",   CPENS (6, C8, C2, 5), F_HASXT | F_REG_128 )
5200
    TLBI_XS_OP ( "rvae3os",    CPENS (6, C8, C5, 1), F_HASXT | F_REG_128 )
5201
    TLBI_XS_OP ( "rvale3os",   CPENS (6, C8, C5, 5), F_HASXT | F_REG_128 )
5202
#undef TLBI_XS_OP
5203
5204
    { 0,       CPENS(0,0,0,0), 0, AARCH64_NO_FEATURES }
5205
};
5206
5207
const aarch64_sys_ins_reg aarch64_sys_regs_plbi[] =
5208
{
5209
#define PLBI_XS_OP(OP, CODE, FLAGS) \
5210
    { OP, CODE, FLAGS, AARCH64_FEATURES (2, TLBID, POE2) }, \
5211
    { OP "nxs", CODE | CPENS (0, 0, C8, 0), FLAGS, AARCH64_FEATURES (3, TLBID, XS, POE2) },
5212
5213
    PLBI_XS_OP ( "alle1is", CPENS (4, C10, C3, 4),  F_TLBID_XT)
5214
    PLBI_XS_OP ( "alle1os", CPENS (4, C10, C1, 4),  F_TLBID_XT)
5215
    PLBI_XS_OP ( "alle2is", CPENS (4, C10, C3, 0),  F_TLBID_XT)
5216
    PLBI_XS_OP ( "alle2os", CPENS (4, C10, C1, 0),  F_TLBID_XT)
5217
    PLBI_XS_OP ( "vmalle1is", CPENS (0, C10, C3, 0),  F_TLBID_XT)
5218
    PLBI_XS_OP ( "vmalle1os", CPENS (0, C10, C1, 0),  F_TLBID_XT)
5219
5220
#undef PLBI_XS_OP
5221
5222
#define PLBI_XS_OP(OP, CODE, FLAGS) \
5223
    { OP, CODE, FLAGS, AARCH64_FEATURE (POE2) }, \
5224
    { OP "nxs", CODE | CPENS (0, 0, C8, 0), FLAGS, AARCH64_FEATURES (2, POE2, XS) },
5225
5226
    PLBI_XS_OP ( "alle1", CPENS (4, C10, C7, 4),  0 )
5227
    PLBI_XS_OP ( "alle2", CPENS (4, C10, C7, 0),  0 )
5228
    PLBI_XS_OP ( "alle3", CPENS (6, C10, C7, 0),  0 )
5229
    PLBI_XS_OP ( "alle3is", CPENS (6, C10, C3, 0),  0 )
5230
    PLBI_XS_OP ( "alle3os", CPENS (6, C10, C1, 0),  0 )
5231
    PLBI_XS_OP ( "aside1",  CPENS (0, C10, C7, 2),  F_HASXT )
5232
    PLBI_XS_OP ( "aside1is",  CPENS (0, C10, C3, 2),  F_HASXT )
5233
    PLBI_XS_OP ( "aside1os",  CPENS (0, C10, C1, 2),  F_HASXT )
5234
    PLBI_XS_OP ( "permae1", CPENS (0, C10, C7, 3),  F_HASXT )
5235
    PLBI_XS_OP ( "permae1is", CPENS (0, C10, C3, 3),  F_HASXT )
5236
    PLBI_XS_OP ( "permae1os", CPENS (0, C10, C1, 3),  F_HASXT )
5237
    PLBI_XS_OP ( "perme1",  CPENS (0, C10, C7, 1),  F_HASXT )
5238
    PLBI_XS_OP ( "perme1is",  CPENS (0, C10, C3, 1),  F_HASXT )
5239
    PLBI_XS_OP ( "perme1os",  CPENS (0, C10, C1, 1),  F_HASXT )
5240
    PLBI_XS_OP ( "perme2",  CPENS (4, C10, C7, 1),  F_HASXT )
5241
    PLBI_XS_OP ( "perme2is",  CPENS (4, C10, C3, 1),  F_HASXT )
5242
    PLBI_XS_OP ( "perme2os",  CPENS (4, C10, C1, 1),  F_HASXT )
5243
    PLBI_XS_OP ( "perme3",  CPENS (6, C10, C7, 1),  F_HASXT )
5244
    PLBI_XS_OP ( "perme3is",  CPENS (6, C10, C3, 1),  F_HASXT )
5245
    PLBI_XS_OP ( "perme3os",  CPENS (6, C10, C1, 1),  F_HASXT )
5246
    PLBI_XS_OP ( "vmalle1", CPENS (0, C10, C7, 0),  0 )
5247
5248
#undef PLBI_XS_OP
5249
5250
    { 0,  CPENS (0,0,0,0), 0, AARCH64_NO_FEATURES }
5251
};
5252
5253
const aarch64_sys_ins_reg aarch64_sys_ins_gic[] =
5254
{
5255
    { "cdaff", CPENS (0,C12,C1,3), 0, AARCH64_NO_FEATURES },
5256
    { "cddi", CPENS (0,C12,C2,0), 0, AARCH64_NO_FEATURES },
5257
    { "cddis", CPENS (0,C12,C1,0), 0, AARCH64_NO_FEATURES },
5258
    { "cden", CPENS (0,C12,C1,1), 0, AARCH64_NO_FEATURES },
5259
    { "cdeoi", CPENS (0,C12,C1,7), 0, AARCH64_NO_FEATURES },
5260
    { "cdhm", CPENS (0,C12,C2,1), 0, AARCH64_NO_FEATURES },
5261
    { "cdpend", CPENS (0,C12,C1,4), 0, AARCH64_NO_FEATURES },
5262
    { "cdpri", CPENS (0,C12,C1,2), 0, AARCH64_NO_FEATURES },
5263
    { "cdrcfg", CPENS (0,C12,C1,5), 0, AARCH64_NO_FEATURES },
5264
    { "vdaff", CPENS (4,C12,C1,3), 0, AARCH64_NO_FEATURES },
5265
    { "vddi", CPENS (4,C12,C2,0), 0, AARCH64_NO_FEATURES },
5266
    { "vddis", CPENS (4,C12,C1,0), 0, AARCH64_NO_FEATURES },
5267
    { "vden", CPENS (4,C12,C1,1), 0, AARCH64_NO_FEATURES },
5268
    { "vdhm", CPENS (4,C12,C2,1), 0, AARCH64_NO_FEATURES },
5269
    { "vdpend", CPENS (4,C12,C1,4), 0, AARCH64_NO_FEATURES },
5270
    { "vdpri", CPENS (4,C12,C1,2), 0, AARCH64_NO_FEATURES },
5271
    { "vdrcfg", CPENS (4,C12,C1,5), 0, AARCH64_NO_FEATURES },
5272
    { "ldaff", CPENS (6,C12,C1,3), 0, AARCH64_NO_FEATURES },
5273
    { "lddi", CPENS (6,C12,C2,0), 0, AARCH64_NO_FEATURES },
5274
    { "lddis", CPENS (6,C12,C1,0), 0, AARCH64_NO_FEATURES },
5275
    { "lden", CPENS (6,C12,C1,1), 0, AARCH64_NO_FEATURES },
5276
    { "ldhm", CPENS (6,C12,C2,1), 0, AARCH64_NO_FEATURES },
5277
    { "ldpend", CPENS (6,C12,C1,4), 0, AARCH64_NO_FEATURES },
5278
    { "ldpri", CPENS (6,C12,C1,2), 0, AARCH64_NO_FEATURES },
5279
    { "ldrcfg", CPENS (6,C12,C1,5), 0, AARCH64_NO_FEATURES },
5280
    { 0, CPENS (0,0,0,0), 0, AARCH64_NO_FEATURES }
5281
};
5282
5283
const aarch64_sys_ins_reg aarch64_sys_ins_gicr[] =
5284
{
5285
    { "cdia", CPENS (0,C12,C3,0), 0, AARCH64_NO_FEATURES },
5286
    { "cdnmia", CPENS (0,C12,C3,1), 0, AARCH64_NO_FEATURES },
5287
    { 0, CPENS (0,0,0,0), 0, AARCH64_NO_FEATURES }
5288
};
5289
5290
const aarch64_sys_ins_reg aarch64_sys_ins_gsb[] =
5291
{
5292
    { "sys", CPENS (0,C12,0,0), 0, AARCH64_NO_FEATURES },
5293
    { "ack", CPENS (0,C12,0,1), 0, AARCH64_NO_FEATURES },
5294
    { 0, CPENS (0,0,0,0), 0, AARCH64_NO_FEATURES }
5295
};
5296
5297
const aarch64_sys_ins_reg aarch64_sys_regs_sr[] =
5298
{
5299
    /* RCTX is somewhat unique in a way that it has different values
5300
       (op2) based on the instruction in which it is used (cfp/dvp/cpp).
5301
       Thus op2 is masked out and instead encoded directly in the
5302
       aarch64_opcode_table entries for the respective instructions.  */
5303
    { "rctx",   CPENS(3,C7,C3,0), F_HASXT | F_REG_WRITE, AARCH64_FEATURE (PREDRES) }, /* WO */
5304
    { 0,       CPENS(0,0,0,0), 0, AARCH64_NO_FEATURES }
5305
};
5306
5307
bool
5308
aarch64_sys_ins_reg_has_xt (const aarch64_sys_ins_reg *sys_ins_reg)
5309
1.12k
{
5310
1.12k
  return (sys_ins_reg->flags & F_HASXT) != 0;
5311
1.12k
}
5312
5313
bool
5314
aarch64_sys_ins_reg_tlbid_xt (const aarch64_sys_ins_reg *sys_ins_reg)
5315
918
{
5316
918
  return (sys_ins_reg->flags & F_TLBID_XT) != 0;
5317
918
}
5318
5319
extern bool
5320
aarch64_sys_ins_reg_supported_p (const aarch64_feature_set features,
5321
         const char *reg_name,
5322
         const aarch64_feature_set *reg_features)
5323
0
{
5324
  /* Armv8-R has no EL3.  */
5325
0
  if (AARCH64_CPU_HAS_FEATURE (features, V8R))
5326
0
    {
5327
0
      const char *suffix = strrchr (reg_name, '_');
5328
0
      if (suffix && !strcmp (suffix, "_el3"))
5329
0
  return false;
5330
0
    }
5331
5332
0
  return AARCH64_CPU_HAS_ALL_FEATURES (features, *reg_features);
5333
0
}
5334
5335
#undef C0
5336
#undef C1
5337
#undef C2
5338
#undef C3
5339
#undef C4
5340
#undef C5
5341
#undef C6
5342
#undef C7
5343
#undef C8
5344
#undef C9
5345
#undef C10
5346
#undef C11
5347
#undef C12
5348
#undef C13
5349
#undef C14
5350
#undef C15
5351
5352
97.1k
#define BIT(INSN,BT)     (((INSN) >> (BT)) & 1)
5353
147k
#define BITS(INSN,HI,LO) (((INSN) >> (LO)) & ((1 << (((HI) - (LO)) + 1)) - 1))
5354
5355
static enum err_type
5356
verify_ldpsw (const struct aarch64_inst *inst ATTRIBUTE_UNUSED,
5357
        const aarch64_insn insn, bfd_vma pc ATTRIBUTE_UNUSED,
5358
        bool encoding ATTRIBUTE_UNUSED,
5359
        aarch64_operand_error *mismatch_detail ATTRIBUTE_UNUSED,
5360
        aarch64_instr_sequence *insn_sequence ATTRIBUTE_UNUSED)
5361
49.1k
{
5362
49.1k
  int t  = BITS (insn, 4, 0);
5363
49.1k
  int n  = BITS (insn, 9, 5);
5364
49.1k
  int t2 = BITS (insn, 14, 10);
5365
5366
49.1k
  if (BIT (insn, 23))
5367
14.2k
    {
5368
      /* Write back enabled.  */
5369
14.2k
      if ((t == n || t2 == n) && n != 31)
5370
1.10k
  return ERR_UND;
5371
14.2k
    }
5372
5373
48.0k
  if (BIT (insn, 22))
5374
48.0k
    {
5375
      /* Load */
5376
48.0k
      if (t == t2)
5377
4.97k
  return ERR_UND;
5378
48.0k
    }
5379
5380
43.0k
  return ERR_OK;
5381
48.0k
}
5382
5383
/* Verifier for vector by element 3 operands functions where the
5384
   conditions `if sz:L == 11 then UNDEFINED` holds.  */
5385
5386
static enum err_type
5387
verify_elem_sd (const struct aarch64_inst *inst, const aarch64_insn insn,
5388
    bfd_vma pc ATTRIBUTE_UNUSED, bool encoding,
5389
    aarch64_operand_error *mismatch_detail ATTRIBUTE_UNUSED,
5390
    aarch64_instr_sequence *insn_sequence ATTRIBUTE_UNUSED)
5391
2.89k
{
5392
2.89k
  const aarch64_insn undef_pattern = 0x3;
5393
2.89k
  aarch64_insn value;
5394
5395
2.89k
  assert (inst->opcode);
5396
2.89k
  assert (inst->opcode->operands[2] == AARCH64_OPND_Em);
5397
2.89k
  value = encoding ? inst->value : insn;
5398
2.89k
  assert (value);
5399
5400
2.89k
  if (undef_pattern == extract_fields (value, 0, 2, FLD_sz, FLD_L))
5401
706
    return ERR_UND;
5402
5403
2.18k
  return ERR_OK;
5404
2.89k
}
5405
5406
/* Check an instruction that takes three register operands and that
5407
   requires the register numbers to be distinct from one another.  */
5408
5409
static enum err_type
5410
verify_three_different_regs (const struct aarch64_inst *inst,
5411
           const aarch64_insn insn ATTRIBUTE_UNUSED,
5412
           bfd_vma pc ATTRIBUTE_UNUSED,
5413
           bool encoding ATTRIBUTE_UNUSED,
5414
           aarch64_operand_error *mismatch_detail
5415
             ATTRIBUTE_UNUSED,
5416
           aarch64_instr_sequence *insn_sequence
5417
             ATTRIBUTE_UNUSED)
5418
10.1k
{
5419
10.1k
  int rd, rs, rn;
5420
5421
10.1k
  rd = inst->operands[0].reg.regno;
5422
10.1k
  rs = inst->operands[1].reg.regno;
5423
10.1k
  rn = inst->operands[2].reg.regno;
5424
10.1k
  if (rd == rs || rd == rn || rs == rn)
5425
1.79k
    {
5426
1.79k
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5427
1.79k
      mismatch_detail->error
5428
1.79k
  = _("the three register operands must be distinct from one another");
5429
1.79k
      mismatch_detail->index = -1;
5430
1.79k
      return ERR_UND;
5431
1.79k
    }
5432
5433
8.34k
  return ERR_OK;
5434
10.1k
}
5435
5436
/* Check an instruction that takes two register operands and that
5437
   requires the register numbers to be distinct from each another.  */
5438
5439
static enum err_type
5440
verify_two_diff_regs (const struct aarch64_inst *inst,
5441
           const aarch64_insn insn ATTRIBUTE_UNUSED,
5442
           bfd_vma pc ATTRIBUTE_UNUSED,
5443
           bool encoding ATTRIBUTE_UNUSED,
5444
           aarch64_operand_error *mismatch_detail
5445
             ATTRIBUTE_UNUSED,
5446
           aarch64_instr_sequence *insn_sequence
5447
             ATTRIBUTE_UNUSED)
5448
233
{
5449
233
  int rd, rn;
5450
5451
233
  rd = inst->operands[0].reg.regno;
5452
233
  rn = inst->operands[1].reg.regno;
5453
233
  if (rd == rn)
5454
105
    {
5455
105
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5456
105
      mismatch_detail->error
5457
105
  = _("the two register operands must be distinct from each other");
5458
105
      mismatch_detail->index = -1;
5459
105
      return ERR_UND;
5460
105
    }
5461
5462
128
  return ERR_OK;
5463
233
}
5464
5465
/* Add INST to the end of INSN_SEQUENCE.  */
5466
5467
static void
5468
add_insn_to_sequence (const struct aarch64_inst *inst,
5469
          aarch64_instr_sequence *insn_sequence)
5470
8.58k
{
5471
8.58k
  insn_sequence->instr[insn_sequence->num_added_insns++] = *inst;
5472
8.58k
}
5473
5474
/* Initialize an instruction sequence insn_sequence with the instruction INST.
5475
   If INST is NULL the given insn_sequence is cleared and the sequence is left
5476
   uninitialized.  */
5477
5478
void
5479
init_insn_sequence (const struct aarch64_inst *inst,
5480
        aarch64_instr_sequence *insn_sequence)
5481
17.4k
{
5482
17.4k
  int num_req_entries = 0;
5483
5484
17.4k
  if (insn_sequence->instr)
5485
8.28k
    {
5486
8.28k
      XDELETE (insn_sequence->instr);
5487
8.28k
      insn_sequence->instr = NULL;
5488
8.28k
    }
5489
5490
  /* Handle all the cases here.  May need to think of something smarter than
5491
     a giant if/else chain if this grows.  At that time, a lookup table may be
5492
     best.  */
5493
17.4k
  if (inst && inst->opcode->constraints & C_SCAN_MOVPRFX)
5494
3.41k
    num_req_entries = 1;
5495
17.4k
  if (inst && (inst->opcode->constraints & C_SCAN_MOPS_PME) == C_SCAN_MOPS_P)
5496
4.87k
    num_req_entries = 2;
5497
5498
17.4k
  insn_sequence->num_added_insns = 0;
5499
17.4k
  insn_sequence->num_allocated_insns = num_req_entries;
5500
5501
17.4k
  if (num_req_entries != 0)
5502
8.28k
    {
5503
8.28k
      insn_sequence->instr = XCNEWVEC (aarch64_inst, num_req_entries);
5504
8.28k
      add_insn_to_sequence (inst, insn_sequence);
5505
8.28k
    }
5506
17.4k
}
5507
5508
/* Subroutine of verify_constraints.  Check whether the instruction
5509
   is part of a MOPS P/M/E sequence and, if so, whether sequencing
5510
   expectations are met.  Return true if the check passes, otherwise
5511
   describe the problem in MISMATCH_DETAIL.
5512
5513
   IS_NEW_SECTION is true if INST is assumed to start a new section.
5514
   The other arguments are as for verify_constraints.  */
5515
5516
static bool
5517
verify_mops_pme_sequence (const struct aarch64_inst *inst,
5518
        bool is_new_section,
5519
        aarch64_operand_error *mismatch_detail,
5520
        aarch64_instr_sequence *insn_sequence)
5521
249k
{
5522
249k
  const struct aarch64_opcode *opcode;
5523
249k
  const struct aarch64_inst *prev_insn;
5524
249k
  int i;
5525
5526
249k
  opcode = inst->opcode;
5527
249k
  if (insn_sequence->instr)
5528
7.79k
    prev_insn = insn_sequence->instr + (insn_sequence->num_added_insns - 1);
5529
241k
  else
5530
241k
    prev_insn = NULL;
5531
5532
249k
  if (prev_insn
5533
7.79k
      && (prev_insn->opcode->constraints & C_SCAN_MOPS_PME)
5534
4.42k
      && prev_insn->opcode != opcode - 1)
5535
4.12k
    {
5536
4.12k
      mismatch_detail->kind = AARCH64_OPDE_EXPECTED_A_AFTER_B;
5537
4.12k
      mismatch_detail->error = NULL;
5538
4.12k
      mismatch_detail->index = -1;
5539
4.12k
      mismatch_detail->data[0].s = prev_insn->opcode[1].name;
5540
4.12k
      mismatch_detail->data[1].s = prev_insn->opcode->name;
5541
4.12k
      mismatch_detail->non_fatal = true;
5542
4.12k
      return false;
5543
4.12k
    }
5544
5545
245k
  if (opcode->constraints & C_SCAN_MOPS_PME)
5546
3.59k
    {
5547
3.59k
      if (is_new_section || !prev_insn || prev_insn->opcode != opcode - 1)
5548
3.29k
  {
5549
3.29k
    mismatch_detail->kind = AARCH64_OPDE_A_SHOULD_FOLLOW_B;
5550
3.29k
    mismatch_detail->error = NULL;
5551
3.29k
    mismatch_detail->index = -1;
5552
3.29k
    mismatch_detail->data[0].s = opcode->name;
5553
3.29k
    mismatch_detail->data[1].s = opcode[-1].name;
5554
3.29k
    mismatch_detail->non_fatal = true;
5555
3.29k
    return false;
5556
3.29k
  }
5557
5558
674
      for (i = 0; i < 3; ++i)
5559
  /* There's no specific requirement for the data register to be
5560
     the same between consecutive SET* instructions.  */
5561
602
  if ((opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd
5562
303
       || opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs
5563
150
       || opcode->operands[i] == AARCH64_OPND_MOPS_WB_Rn)
5564
602
      && prev_insn->operands[i].reg.regno != inst->operands[i].reg.regno)
5565
227
    {
5566
227
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5567
227
      if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd)
5568
146
        mismatch_detail->error = _("destination register differs from "
5569
81
           "preceding instruction");
5570
81
      else if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs)
5571
3
        mismatch_detail->error = _("source register differs from "
5572
78
           "preceding instruction");
5573
78
      else
5574
78
        mismatch_detail->error = _("size register differs from "
5575
227
           "preceding instruction");
5576
227
      mismatch_detail->index = i;
5577
227
      mismatch_detail->non_fatal = true;
5578
227
      return false;
5579
227
    }
5580
299
    }
5581
5582
242k
  return true;
5583
245k
}
5584
5585
/*  This function verifies that the instruction INST adheres to its specified
5586
    constraints.  If it does then ERR_OK is returned, if not then ERR_VFI is
5587
    returned and MISMATCH_DETAIL contains the reason why verification failed.
5588
5589
    The function is called both during assembly and disassembly.  If assembling
5590
    then ENCODING will be TRUE, else FALSE.  If dissassembling PC will be set
5591
    and will contain the PC of the current instruction w.r.t to the section.
5592
5593
    If ENCODING and PC=0 then you are at a start of a section.  The constraints
5594
    are verified against the given state insn_sequence which is updated as it
5595
    transitions through the verification.  */
5596
5597
enum err_type
5598
verify_constraints (const struct aarch64_inst *inst,
5599
        const aarch64_insn insn ATTRIBUTE_UNUSED,
5600
        bfd_vma pc,
5601
        bool encoding,
5602
        aarch64_operand_error *mismatch_detail,
5603
        aarch64_instr_sequence *insn_sequence)
5604
6.83M
{
5605
6.83M
  assert (inst);
5606
6.83M
  assert (inst->opcode);
5607
5608
6.83M
  const struct aarch64_opcode *opcode = inst->opcode;
5609
6.83M
  if (!opcode->constraints && !insn_sequence->instr)
5610
6.57M
    return ERR_OK;
5611
5612
6.83M
  assert (insn_sequence);
5613
5614
258k
  enum err_type res = ERR_OK;
5615
5616
  /* This instruction puts a constraint on the insn_sequence.  */
5617
258k
  if (opcode->flags & F_SCAN)
5618
8.28k
    {
5619
8.28k
      if (insn_sequence->instr)
5620
790
  {
5621
790
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5622
790
    mismatch_detail->error = _("instruction opens new dependency "
5623
790
             "sequence without ending previous one");
5624
790
    mismatch_detail->index = -1;
5625
790
    mismatch_detail->non_fatal = true;
5626
790
    res = ERR_VFI;
5627
790
  }
5628
5629
8.28k
      init_insn_sequence (inst, insn_sequence);
5630
8.28k
      return res;
5631
8.28k
    }
5632
5633
258k
  bool is_new_section = (!encoding && pc == 0);
5634
249k
  if (!verify_mops_pme_sequence (inst, is_new_section, mismatch_detail,
5635
249k
         insn_sequence))
5636
7.65k
    {
5637
7.65k
      res = ERR_VFI;
5638
7.65k
      if ((opcode->constraints & C_SCAN_MOPS_PME) != C_SCAN_MOPS_M)
5639
5.78k
  init_insn_sequence (NULL, insn_sequence);
5640
7.65k
    }
5641
5642
  /* Verify constraints on an existing sequence.  */
5643
249k
  if (insn_sequence->instr)
5644
3.67k
    {
5645
3.67k
      const struct aarch64_opcode* inst_opcode = insn_sequence->instr->opcode;
5646
      /* If we're decoding and we hit PC=0 with an open sequence then we haven't
5647
   closed a previous one that we should have.  */
5648
3.67k
      if (is_new_section && res == ERR_OK)
5649
0
  {
5650
0
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5651
0
    mismatch_detail->error = _("previous `movprfx' sequence not closed");
5652
0
    mismatch_detail->index = -1;
5653
0
    mismatch_detail->non_fatal = true;
5654
0
    res = ERR_VFI;
5655
    /* Reset the sequence.  */
5656
0
    init_insn_sequence (NULL, insn_sequence);
5657
0
    return res;
5658
0
  }
5659
5660
      /* Validate C_SCAN_MOVPRFX constraints.  Move this to a lookup table.  */
5661
3.67k
      if (inst_opcode->constraints & C_SCAN_MOVPRFX)
5662
3.36k
  {
5663
    /* Check to see if the MOVPRFX SVE instruction is followed by an SVE
5664
       instruction for better error messages.  */
5665
3.36k
    bool sve_operand_p = false;
5666
12.4k
    for (int i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
5667
11.1k
      {
5668
11.1k
        enum aarch64_operand_class op_class
5669
11.1k
    = aarch64_get_operand_class (opcode->operands[i]);
5670
11.1k
        if (op_class == AARCH64_OPND_CLASS_SVE_REG
5671
9.58k
      || op_class == AARCH64_OPND_CLASS_SVE_REGLIST
5672
9.29k
      || op_class == AARCH64_OPND_CLASS_PRED_REG)
5673
2.07k
    {
5674
2.07k
      sve_operand_p = true;
5675
2.07k
      break;
5676
2.07k
    }
5677
11.1k
      }
5678
5679
3.36k
    if (!sve_operand_p)
5680
1.29k
      {
5681
1.29k
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5682
1.29k
        mismatch_detail->error = _("SVE instruction expected after "
5683
1.29k
           "`movprfx'");
5684
1.29k
        mismatch_detail->index = -1;
5685
1.29k
        mismatch_detail->non_fatal = true;
5686
1.29k
        res = ERR_VFI;
5687
1.29k
        goto done;
5688
1.29k
      }
5689
5690
    /* Check to see if the MOVPRFX SVE instruction is followed by an SVE
5691
       instruction that is allowed to be used with a MOVPRFX.  */
5692
2.07k
    if (!(opcode->constraints & C_SCAN_MOVPRFX))
5693
656
      {
5694
656
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5695
656
        mismatch_detail->error = _("SVE `movprfx' compatible instruction "
5696
656
           "expected");
5697
656
        mismatch_detail->index = -1;
5698
656
        mismatch_detail->non_fatal = true;
5699
656
        res = ERR_VFI;
5700
656
        goto done;
5701
656
      }
5702
5703
    /* Next check for usage of the predicate register.  */
5704
1.42k
    aarch64_opnd_info blk_dest = insn_sequence->instr->operands[0];
5705
1.42k
    aarch64_opnd_info blk_pred, inst_pred;
5706
1.42k
    memset (&blk_pred, 0, sizeof (aarch64_opnd_info));
5707
1.42k
    memset (&inst_pred, 0, sizeof (aarch64_opnd_info));
5708
1.42k
    bool predicated = false;
5709
1.42k
    assert (blk_dest.type == AARCH64_OPND_SVE_Zd);
5710
5711
    /* Determine if the movprfx instruction used is predicated or not.  */
5712
1.42k
    if (insn_sequence->instr->operands[1].type == AARCH64_OPND_SVE_Pg3)
5713
1.33k
      {
5714
1.33k
        predicated = true;
5715
1.33k
        blk_pred = insn_sequence->instr->operands[1];
5716
1.33k
      }
5717
5718
1.42k
    unsigned char max_elem_size = 0;
5719
1.42k
    unsigned char current_elem_size;
5720
1.42k
    int num_op_used = 0, last_op_usage = 0;
5721
1.42k
    int i, inst_pred_idx = -1;
5722
1.42k
    int num_ops = aarch64_num_of_operands (opcode);
5723
6.41k
    for (i = 0; i < num_ops; i++)
5724
4.99k
      {
5725
4.99k
        aarch64_opnd_info inst_op = inst->operands[i];
5726
4.99k
        switch (inst_op.type)
5727
4.99k
    {
5728
1.77k
      case AARCH64_OPND_SVE_Zd:
5729
2.30k
      case AARCH64_OPND_SVE_Zm_5:
5730
2.53k
      case AARCH64_OPND_SVE_Zm_16:
5731
3.07k
      case AARCH64_OPND_SVE_Zn:
5732
3.07k
      case AARCH64_OPND_SVE_Zt:
5733
3.13k
      case AARCH64_OPND_SVE_Vm:
5734
3.25k
      case AARCH64_OPND_SVE_Vn:
5735
3.25k
      case AARCH64_OPND_Va:
5736
3.25k
      case AARCH64_OPND_Vn:
5737
3.25k
      case AARCH64_OPND_Vm:
5738
3.25k
      case AARCH64_OPND_Sn:
5739
3.25k
      case AARCH64_OPND_Sm:
5740
3.25k
        if (inst_op.reg.regno == blk_dest.reg.regno)
5741
843
          {
5742
843
      num_op_used++;
5743
843
      last_op_usage = i;
5744
843
          }
5745
3.25k
        current_elem_size
5746
3.25k
          = aarch64_get_qualifier_esize (inst_op.qualifier);
5747
3.25k
        if (current_elem_size > max_elem_size)
5748
1.42k
          max_elem_size = current_elem_size;
5749
3.25k
        break;
5750
0
      case AARCH64_OPND_SVE_Pd:
5751
1.00k
      case AARCH64_OPND_SVE_Pg3:
5752
1.00k
      case AARCH64_OPND_SVE_Pg4_5:
5753
1.00k
      case AARCH64_OPND_SVE_Pg4_10:
5754
1.15k
      case AARCH64_OPND_SVE_Pg4_16:
5755
1.15k
      case AARCH64_OPND_SVE_Pm:
5756
1.15k
      case AARCH64_OPND_SVE_Pn:
5757
1.15k
      case AARCH64_OPND_SVE_Pt:
5758
1.15k
      case AARCH64_OPND_SME_Pm:
5759
1.15k
        inst_pred = inst_op;
5760
1.15k
        inst_pred_idx = i;
5761
1.15k
        break;
5762
590
      default:
5763
590
        break;
5764
4.99k
    }
5765
4.99k
      }
5766
5767
1.42k
     assert (max_elem_size != 0);
5768
1.42k
     aarch64_opnd_info inst_dest = inst->operands[0];
5769
     /* Determine the size that should be used to compare against the
5770
        movprfx size.  */
5771
1.42k
     current_elem_size
5772
1.42k
       = opcode->constraints & C_MAX_ELEM
5773
1.42k
         ? max_elem_size
5774
1.42k
         : aarch64_get_qualifier_esize (inst_dest.qualifier);
5775
5776
    /* If movprfx is predicated do some extra checks.  */
5777
1.42k
    if (predicated)
5778
1.33k
      {
5779
        /* The instruction must be predicated.  */
5780
1.33k
        if (inst_pred_idx < 0)
5781
270
    {
5782
270
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5783
270
      mismatch_detail->error = _("predicated instruction expected "
5784
270
               "after `movprfx'");
5785
270
      mismatch_detail->index = -1;
5786
270
      mismatch_detail->non_fatal = true;
5787
270
      res = ERR_VFI;
5788
270
      goto done;
5789
270
    }
5790
5791
        /* The instruction must have a merging predicate.  */
5792
1.06k
        if (inst_pred.qualifier != AARCH64_OPND_QLF_P_M)
5793
56
    {
5794
56
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5795
56
      mismatch_detail->error = _("merging predicate expected due "
5796
56
               "to preceding `movprfx'");
5797
56
      mismatch_detail->index = inst_pred_idx;
5798
56
      mismatch_detail->non_fatal = true;
5799
56
      res = ERR_VFI;
5800
56
      goto done;
5801
56
    }
5802
5803
        /* The same register must be used in instruction.  */
5804
1.01k
        if (blk_pred.reg.regno != inst_pred.reg.regno)
5805
557
    {
5806
557
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5807
557
      mismatch_detail->error = _("predicate register differs "
5808
557
               "from that in preceding "
5809
557
               "`movprfx'");
5810
557
      mismatch_detail->index = inst_pred_idx;
5811
557
      mismatch_detail->non_fatal = true;
5812
557
      res = ERR_VFI;
5813
557
      goto done;
5814
557
    }
5815
1.01k
      }
5816
5817
    /* Destructive operations by definition must allow one usage of the
5818
       same register.  */
5819
539
    int allowed_usage
5820
539
      = aarch64_is_destructive_by_operands (opcode) ? 2 : 1;
5821
5822
    /* Operand is not used at all.  */
5823
539
    if (num_op_used == 0)
5824
93
      {
5825
93
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5826
93
        mismatch_detail->error = _("output register of preceding "
5827
93
           "`movprfx' not used in current "
5828
93
           "instruction");
5829
93
        mismatch_detail->index = 0;
5830
93
        mismatch_detail->non_fatal = true;
5831
93
        res = ERR_VFI;
5832
93
        goto done;
5833
93
      }
5834
5835
    /* We now know it's used, now determine exactly where it's used.  */
5836
446
    if (blk_dest.reg.regno != inst_dest.reg.regno)
5837
81
      {
5838
81
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5839
81
        mismatch_detail->error = _("output register of preceding "
5840
81
           "`movprfx' expected as output");
5841
81
        mismatch_detail->index = 0;
5842
81
        mismatch_detail->non_fatal = true;
5843
81
        res = ERR_VFI;
5844
81
        goto done;
5845
81
      }
5846
5847
    /* Operand used more than allowed for the specific opcode type.  */
5848
365
    if (num_op_used > allowed_usage)
5849
116
      {
5850
116
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5851
116
        mismatch_detail->error = _("output register of preceding "
5852
116
           "`movprfx' used as input");
5853
116
        mismatch_detail->index = last_op_usage;
5854
116
        mismatch_detail->non_fatal = true;
5855
116
        res = ERR_VFI;
5856
116
        goto done;
5857
116
      }
5858
5859
    /* Now the only thing left is the qualifiers checks.  The register
5860
       must have the same maximum element size.  */
5861
249
    if (inst_dest.qualifier != AARCH64_OPND_QLF_NIL
5862
249
        && blk_dest.qualifier != AARCH64_OPND_QLF_NIL
5863
165
        && current_elem_size
5864
165
     != aarch64_get_qualifier_esize (blk_dest.qualifier))
5865
41
      {
5866
41
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5867
41
        mismatch_detail->error = _("register size not compatible with "
5868
41
           "previous `movprfx'");
5869
41
        mismatch_detail->index = 0;
5870
41
        mismatch_detail->non_fatal = true;
5871
41
        res = ERR_VFI;
5872
41
        goto done;
5873
41
      }
5874
249
  }
5875
5876
3.67k
    done:
5877
3.67k
      if (insn_sequence->num_added_insns == insn_sequence->num_allocated_insns)
5878
  /* We've checked the last instruction in the sequence and so
5879
     don't need the sequence any more.  */
5880
3.36k
  init_insn_sequence (NULL, insn_sequence);
5881
305
      else
5882
305
  add_insn_to_sequence (inst, insn_sequence);
5883
3.67k
    }
5884
5885
249k
  return res;
5886
249k
}
5887
5888
5889
/* Return true if VALUE cannot be moved into an SVE register using DUP
5890
   (with any element size, not just ESIZE) and if using DUPM would
5891
   therefore be OK.  ESIZE is the number of bytes in the immediate.  */
5892
5893
bool
5894
aarch64_sve_dupm_mov_immediate_p (uint64_t uvalue, int esize)
5895
7.97k
{
5896
7.97k
  int64_t svalue = uvalue;
5897
7.97k
  uint64_t upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
5898
5899
7.97k
  if ((uvalue & ~upper) != uvalue && (uvalue | upper) != uvalue)
5900
0
    return false;
5901
7.97k
  if (esize <= 4 || (uint32_t) uvalue == (uint32_t) (uvalue >> 32))
5902
6.32k
    {
5903
6.32k
      svalue = (int32_t) uvalue;
5904
6.32k
      if (esize <= 2 || (uint16_t) uvalue == (uint16_t) (uvalue >> 16))
5905
1.29k
  {
5906
1.29k
    svalue = (int16_t) uvalue;
5907
1.29k
    if (esize == 1 || (uint8_t) uvalue == (uint8_t) (uvalue >> 8))
5908
650
      return false;
5909
1.29k
  }
5910
6.32k
    }
5911
7.32k
  if ((svalue & 0xff) == 0)
5912
3.48k
    svalue /= 256;
5913
7.32k
  return svalue < -128 || svalue >= 128;
5914
7.97k
}
5915
5916
/* Return true if a CPU with the AARCH64_FEATURE_* bits in CPU_VARIANT
5917
   supports the instruction described by INST.  */
5918
5919
bool
5920
aarch64_cpu_supports_inst_p (aarch64_feature_set cpu_variant,
5921
           aarch64_inst *inst)
5922
0
{
5923
0
  if (!inst->opcode->avariant
5924
0
      || !AARCH64_CPU_HAS_ALL_FEATURES (cpu_variant, *inst->opcode->avariant))
5925
0
    return false;
5926
5927
0
  if (inst->opcode->iclass == sme_fp_sd
5928
0
      && inst->operands[0].qualifier == AARCH64_OPND_QLF_S_D
5929
0
      && !AARCH64_CPU_HAS_FEATURE (cpu_variant, SME_F64F64))
5930
0
    return false;
5931
5932
0
  if (inst->opcode->iclass == sme_int_sd
5933
0
      && inst->operands[0].qualifier == AARCH64_OPND_QLF_S_D
5934
0
      && !AARCH64_CPU_HAS_FEATURE (cpu_variant, SME_I16I64))
5935
0
    return false;
5936
5937
0
  return true;
5938
0
}
5939
5940
/* Include the opcode description table as well as the operand description
5941
   table.  */
5942
#define VERIFIER(x) verify_##x
5943
#include "aarch64-tbl.h"