Coverage Report

Created: 2026-03-10 08:46

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