Coverage Report

Created: 2025-07-08 11:15

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