Coverage Report

Created: 2026-05-11 07:54

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
621k
{
132
621k
  return (qualifier >= AARCH64_OPND_QLF_V_8B
133
498k
    && qualifier <= AARCH64_OPND_QLF_V_1Q);
134
621k
}
135
136
static inline bool
137
fp_qualifier_p (enum aarch64_opnd_qualifier qualifier)
138
602
{
139
602
  return (qualifier >= AARCH64_OPND_QLF_S_B
140
602
    && qualifier <= AARCH64_OPND_QLF_S_Q);
141
602
}
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
270k
{
169
270k
  if (vector_qualifier_p (qualifiers[0]))
170
269k
    {
171
      /* e.g. v.4s, v.4s, v.4s
172
     or v.4h, v.4h, v.h[3].  */
173
269k
      if (qualifiers[0] == qualifiers[1]
174
129k
    && vector_qualifier_p (qualifiers[2])
175
94.0k
    && (aarch64_get_qualifier_esize (qualifiers[0])
176
94.0k
        == aarch64_get_qualifier_esize (qualifiers[1]))
177
94.0k
    && (aarch64_get_qualifier_esize (qualifiers[0])
178
94.0k
        == aarch64_get_qualifier_esize (qualifiers[2])))
179
89.3k
  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
180k
      if (vector_qualifier_p (qualifiers[1])
184
126k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
185
126k
    && (aarch64_get_qualifier_esize (qualifiers[0])
186
126k
        == aarch64_get_qualifier_esize (qualifiers[1]) << 1))
187
45.5k
  return DP_VECTOR_LONG;
188
      /* e.g. v.8h, v.8h, v.8b.  */
189
135k
      if (qualifiers[0] == qualifiers[1]
190
40.2k
    && vector_qualifier_p (qualifiers[2])
191
4.66k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
192
4.66k
    && (aarch64_get_qualifier_esize (qualifiers[0])
193
4.66k
        == aarch64_get_qualifier_esize (qualifiers[2]) << 1)
194
4.66k
    && (aarch64_get_qualifier_esize (qualifiers[0])
195
4.66k
        == aarch64_get_qualifier_esize (qualifiers[1])))
196
4.66k
  return DP_VECTOR_WIDE;
197
135k
    }
198
602
  else if (fp_qualifier_p (qualifiers[0]))
199
602
    {
200
      /* e.g. SADDLV <V><d>, <Vn>.<T>.  */
201
602
      if (vector_qualifier_p (qualifiers[1])
202
534
    && qualifiers[2] == AARCH64_OPND_QLF_NIL)
203
534
  return DP_VECTOR_ACROSS_LANES;
204
602
    }
205
206
130k
  return DP_UNKNOWN;
207
270k
}
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
270k
{
220
270k
  return
221
270k
    significant_operand_index [get_data_pattern (opcode->qualifiers_list[0])];
222
270k
}
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
2.13M
{
452
2.13M
  return aarch64_operands[type].op_class;
453
2.13M
}
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
53.1k
{
493
53.1k
  assert (value < 16);
494
53.1k
  return &aarch64_conds[(unsigned int) value];
495
53.1k
}
496
497
const aarch64_cond *
498
get_inverted_cond (const aarch64_cond *cond)
499
221
{
500
221
  return &aarch64_conds[cond->value ^ 0x1];
501
221
}
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
503k
{
545
503k
  if (extend_p)
546
98.5k
    return AARCH64_MOD_UXTB + value;
547
405k
  else
548
405k
    return AARCH64_MOD_LSL - value;
549
503k
}
550
551
bool
552
aarch64_extend_operator_p (enum aarch64_modifier_kind kind)
553
40.9k
{
554
40.9k
  return kind > AARCH64_MOD_LSL && kind <= AARCH64_MOD_SXTX;
555
40.9k
}
556
557
static inline bool
558
aarch64_shift_operator_p (enum aarch64_modifier_kind kind)
559
389k
{
560
389k
  return kind >= AARCH64_MOD_ROR && kind <= AARCH64_MOD_LSL;
561
389k
}
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.28M
{
662
2.28M
  return (low <= value) && (value <= high);
663
2.28M
}
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.54M
{
669
1.54M
  return (value % align) == 0;
670
1.54M
}
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
1.00M
{
676
1.00M
  assert (width < 32);
677
1.00M
  if (width < sizeof (value) * 8)
678
1.00M
    {
679
1.00M
      int64_t lim = (uint64_t) 1 << (width - 1);
680
1.00M
      if (value >= -lim && value < lim)
681
1.00M
  return true;
682
1.00M
    }
683
0
  return false;
684
1.00M
}
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.76M
{
690
1.76M
  assert (width < 32);
691
1.76M
  if (width < sizeof (value) * 8)
692
1.76M
    {
693
1.76M
      int64_t lim = (uint64_t) 1 << width;
694
1.76M
      if (value >= 0 && value < lim)
695
1.76M
  return true;
696
1.76M
    }
697
0
  return false;
698
1.76M
}
699
700
/* Return true if OPERAND is SP or WSP.  */
701
bool
702
aarch64_stack_pointer_p (const aarch64_opnd_info *operand)
703
128k
{
704
128k
  return ((aarch64_get_operand_class (operand->type)
705
128k
     == AARCH64_OPND_CLASS_INT_REG)
706
128k
    && operand_maybe_stack_pointer (aarch64_operands + operand->type)
707
82.3k
    && operand->reg.regno == 31);
708
128k
}
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.67M
{
728
3.67M
  switch (operand->qualifier)
729
3.67M
    {
730
4.81k
    case AARCH64_OPND_QLF_W:
731
4.81k
      if (target == AARCH64_OPND_QLF_WSP && aarch64_stack_pointer_p (operand))
732
329
  return true;
733
4.48k
      break;
734
767k
    case AARCH64_OPND_QLF_X:
735
767k
      if (target == AARCH64_OPND_QLF_SP && aarch64_stack_pointer_p (operand))
736
35
  return true;
737
767k
      break;
738
767k
    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.90M
    default:
749
2.90M
      break;
750
3.67M
    }
751
752
3.67M
  return false;
753
3.67M
}
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
9.25M
{
891
9.25M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_OPD_VARIANT;
892
9.25M
}
893
894
static inline bool
895
qualifier_value_in_range_constraint_p (aarch64_opnd_qualifier_t qualifier)
896
3.26M
{
897
3.26M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_VALUE_IN_RANGE;
898
3.26M
}
899
900
const char*
901
aarch64_get_qualifier_name (aarch64_opnd_qualifier_t qualifier)
902
3.52M
{
903
3.52M
  return aarch64_opnd_qualifiers[qualifier].desc;
904
3.52M
}
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
6.69M
{
911
6.69M
  assert (operand_variant_qualifier_p (qualifier));
912
6.69M
  return aarch64_opnd_qualifiers[qualifier].data0;
913
6.69M
}
914
915
unsigned char
916
aarch64_get_qualifier_nelem (aarch64_opnd_qualifier_t qualifier)
917
83.5k
{
918
83.5k
  assert (operand_variant_qualifier_p (qualifier));
919
83.5k
  return aarch64_opnd_qualifiers[qualifier].data1;
920
83.5k
}
921
922
aarch64_insn
923
aarch64_get_qualifier_standard_value (aarch64_opnd_qualifier_t qualifier)
924
2.47M
{
925
2.47M
  assert (operand_variant_qualifier_p (qualifier));
926
2.47M
  return aarch64_opnd_qualifiers[qualifier].data2;
927
2.47M
}
928
929
static int
930
get_lower_bound (aarch64_opnd_qualifier_t qualifier)
931
363k
{
932
363k
  assert (qualifier_value_in_range_constraint_p (qualifier));
933
363k
  return aarch64_opnd_qualifiers[qualifier].data0;
934
363k
}
935
936
static int
937
get_upper_bound (aarch64_opnd_qualifier_t qualifier)
938
387k
{
939
387k
  assert (qualifier_value_in_range_constraint_p (qualifier));
940
387k
  return aarch64_opnd_qualifiers[qualifier].data1;
941
387k
}
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
464
{
987
464
  int i = 0;
988
464
  const enum aarch64_opnd *opnds = opcode->operands;
989
990
464
  if (opnds[0] == AARCH64_OPND_NIL)
991
0
    return false;
992
993
1.39k
  while (opnds[++i] != AARCH64_OPND_NIL)
994
1.16k
    if (opnds[i] == opnds[0])
995
232
      return true;
996
997
232
  return false;
998
464
}
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
7.54M
{
1006
7.54M
  int i = 0;
1007
7.54M
  const enum aarch64_opnd *opnds = opcode->operands;
1008
25.9M
  while (opnds[i++] != AARCH64_OPND_NIL)
1009
18.4M
    ;
1010
7.54M
  --i;
1011
7.54M
  assert (i >= 0 && i <= AARCH64_MAX_OPND_NUM);
1012
7.54M
  return i;
1013
7.54M
}
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.80M
{
1046
6.80M
  int i, num_opnds, invalid, min_invalid;
1047
6.80M
  const aarch64_opnd_qualifier_t *qualifiers;
1048
1049
6.80M
  num_opnds = aarch64_num_of_operands (inst->opcode);
1050
6.80M
  if (num_opnds == 0)
1051
69
    {
1052
69
      DEBUG_TRACE ("SUCCEED: no operand");
1053
69
      *invalid_count = 0;
1054
69
      return 1;
1055
69
    }
1056
1057
6.80M
  if (stop_at < 0 || stop_at >= num_opnds)
1058
5.93M
    stop_at = num_opnds - 1;
1059
1060
  /* For each pattern.  */
1061
6.80M
  min_invalid = num_opnds;
1062
9.40M
  for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list)
1063
9.40M
    {
1064
9.40M
      int j;
1065
9.40M
      qualifiers = *qualifiers_list;
1066
1067
      /* Start as positive.  */
1068
9.40M
      invalid = 0;
1069
1070
9.40M
      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
9.40M
      if (i > 0 && empty_qualifier_sequence_p (qualifiers))
1080
54.2k
  break;
1081
1082
32.4M
      for (j = 0; j < num_opnds && j <= stop_at; ++j, ++qualifiers)
1083
23.0M
  {
1084
23.0M
    if (inst->operands[j].qualifier == AARCH64_OPND_QLF_NIL
1085
12.8M
        && !(inst->opcode->flags & F_STRICT))
1086
12.1M
      {
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
12.1M
        continue;
1094
12.1M
      }
1095
10.9M
    else if (*qualifiers != inst->operands[j].qualifier)
1096
3.67M
      {
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.67M
        if (operand_also_qualified_p (inst->operands + j, *qualifiers))
1101
364
    continue;
1102
3.67M
        else
1103
3.67M
    invalid += 1;
1104
3.67M
      }
1105
7.25M
    else
1106
7.25M
      continue; /* Equal qualifiers are certainly matched.  */
1107
23.0M
  }
1108
1109
9.35M
      if (min_invalid > invalid)
1110
8.24M
  min_invalid = invalid;
1111
1112
      /* Qualifiers established.  */
1113
9.35M
      if (min_invalid == 0)
1114
6.74M
  break;
1115
9.35M
    }
1116
1117
6.80M
  *invalid_count = min_invalid;
1118
6.80M
  if (min_invalid == 0)
1119
6.74M
    {
1120
      /* Fill the result in *RET.  */
1121
6.74M
      int j;
1122
6.74M
      qualifiers = *qualifiers_list;
1123
1124
6.74M
      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
22.7M
      for (j = 0; j <= stop_at; ++j, ++qualifiers)
1131
15.9M
  ret[j] = *qualifiers;
1132
38.0M
      for (; j < AARCH64_MAX_OPND_NUM; ++j)
1133
31.2M
  ret[j] = AARCH64_OPND_QLF_NIL;
1134
1135
6.74M
      DEBUG_TRACE ("SUCCESS");
1136
6.74M
      return 1;
1137
6.74M
    }
1138
1139
54.2k
  DEBUG_TRACE ("FAIL");
1140
54.2k
  return 0;
1141
6.80M
}
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.93M
{
1158
5.93M
  int i;
1159
5.93M
  aarch64_opnd_qualifier_seq_t qualifiers;
1160
1161
5.93M
  if (!aarch64_find_best_match (inst, inst->opcode->qualifiers_list, -1,
1162
5.93M
        qualifiers, invalid_count))
1163
32.8k
    {
1164
32.8k
      DEBUG_TRACE ("matching FAIL");
1165
32.8k
      return 0;
1166
32.8k
    }
1167
1168
  /* Update the qualifiers.  */
1169
5.89M
  if (update_p)
1170
19.6M
    for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
1171
19.6M
      {
1172
19.6M
  if (inst->opcode->operands[i] == AARCH64_OPND_NIL)
1173
5.89M
    break;
1174
13.7M
  DEBUG_TRACE_IF (inst->operands[i].qualifier != qualifiers[i],
1175
13.7M
      "update %s with %s for operand %d",
1176
13.7M
      aarch64_get_qualifier_name (inst->operands[i].qualifier),
1177
13.7M
      aarch64_get_qualifier_name (qualifiers[i]), i);
1178
13.7M
  inst->operands[i].qualifier = qualifiers[i];
1179
13.7M
      }
1180
1181
5.89M
  DEBUG_TRACE ("matching SUCCESS");
1182
5.89M
  return 1;
1183
5.93M
}
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
70.4k
{
1195
70.4k
  int amount;
1196
1197
70.4k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1198
1199
70.4k
  if (is32)
1200
13.4k
    {
1201
      /* Allow all zeros or all ones in top 32-bits, so that
1202
   32-bit constant expressions like ~0x80000000 are
1203
   permitted.  */
1204
13.4k
      if (value >> 32 != 0 && value >> 32 != 0xffffffff)
1205
  /* Immediate out of range.  */
1206
0
  return false;
1207
13.4k
      value &= 0xffffffff;
1208
13.4k
    }
1209
1210
  /* first, try movz then movn */
1211
70.4k
  amount = -1;
1212
70.4k
  if ((value & ((uint64_t) 0xffff << 0)) == value)
1213
17.5k
    amount = 0;
1214
52.8k
  else if ((value & ((uint64_t) 0xffff << 16)) == value)
1215
8.69k
    amount = 16;
1216
44.1k
  else if (!is32 && (value & ((uint64_t) 0xffff << 32)) == value)
1217
14.7k
    amount = 32;
1218
29.3k
  else if (!is32 && (value & ((uint64_t) 0xffff << 48)) == value)
1219
4.06k
    amount = 48;
1220
1221
70.4k
  if (amount == -1)
1222
25.3k
    {
1223
25.3k
      DEBUG_TRACE ("exit false with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1224
25.3k
      return false;
1225
25.3k
    }
1226
1227
45.1k
  if (shift_amount != NULL)
1228
0
    *shift_amount = amount;
1229
1230
45.1k
  DEBUG_TRACE ("exit true with amount %d", amount);
1231
1232
45.1k
  return true;
1233
70.4k
}
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
258k
#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
3.08M
{
1267
3.08M
  const simd_imm_encoding *imm1 = (const simd_imm_encoding *)i1;
1268
3.08M
  const simd_imm_encoding *imm2 = (const simd_imm_encoding *)i2;
1269
1270
3.08M
  if (imm1->imm < imm2->imm)
1271
1.54M
    return -1;
1272
1.54M
  if (imm1->imm > imm2->imm)
1273
1.28M
    return +1;
1274
258k
  return 0;
1275
1.54M
}
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
258k
{
1368
258k
  simd_imm_encoding imm_enc;
1369
258k
  const simd_imm_encoding *imm_encoding;
1370
258k
  static bool initialized = false;
1371
258k
  uint64_t upper;
1372
258k
  int i;
1373
1374
258k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 "), esize: %d", value,
1375
258k
         value, esize);
1376
1377
258k
  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
258k
  upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
1386
258k
  if ((value & ~upper) != value && (value | upper) != value)
1387
0
    return false;
1388
1389
  /* Replicate to a full 64-bit value.  */
1390
258k
  value &= ~upper;
1391
445k
  for (i = esize * 8; i < 64; i *= 2)
1392
186k
    value |= (value << i);
1393
1394
258k
  imm_enc.imm = value;
1395
258k
  imm_encoding = (const simd_imm_encoding *)
1396
258k
    bsearch(&imm_enc, simd_immediates, TOTAL_IMM_NB,
1397
258k
            sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1398
258k
  if (imm_encoding == NULL)
1399
0
    {
1400
0
      DEBUG_TRACE ("exit with false");
1401
0
      return false;
1402
0
    }
1403
258k
  if (encoding != NULL)
1404
0
    *encoding = imm_encoding->encoding;
1405
258k
  DEBUG_TRACE ("exit with true");
1406
258k
  return true;
1407
258k
}
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
724
{
1416
724
  int i, ret;
1417
724
  uint32_t byte;
1418
1419
724
  ret = 0;
1420
6.51k
  for (i = 0; i < 8; i++)
1421
5.79k
    {
1422
5.79k
      byte = (imm >> (8 * i)) & 0xff;
1423
5.79k
      if (byte == 0xff)
1424
3.82k
  ret |= 1 << i;
1425
1.96k
      else if (byte != 0x00)
1426
0
  return -1;
1427
5.79k
    }
1428
724
  return ret;
1429
724
}
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
2.05k
{
1449
2.05k
  if (mismatch_detail == NULL)
1450
2.05k
    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
35.3k
{
1482
35.3k
  if (mismatch_detail == NULL)
1483
35.3k
    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
481
{
1512
481
  if (mismatch_detail == NULL)
1513
481
    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
70.5k
{
1522
70.5k
  if (mismatch_detail == NULL)
1523
70.5k
    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
569
{
1554
569
  if (mismatch_detail == NULL)
1555
569
    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
41.7k
{
1584
41.7k
  if (mismatch_detail == NULL)
1585
41.7k
    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
65.2k
{
1599
65.2k
  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
65.2k
  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
65.2k
  return true;
1612
65.2k
}
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
295k
{
1622
295k
  if (opnd->reglist.num_regs != num_regs)
1623
569
    {
1624
569
      set_reg_list_length_error (mismatch_detail, idx, num_regs);
1625
569
      return false;
1626
569
    }
1627
294k
  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
294k
  return true;
1633
294k
}
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
992k
{
1667
992k
  const aarch64_operand *operand = get_operand_from_code (type);
1668
992k
  uint8_t size = get_operand_fields_width (operand);
1669
992k
  bool unsigned_imm = operand_need_unsigned_offset (operand);
1670
992k
  bool (*value_fit_field) (int64_t, unsigned)
1671
992k
    = (unsigned_imm
1672
992k
      ? value_fit_unsigned_field_p
1673
992k
      : value_fit_signed_field_p);
1674
1675
992k
  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
992k
  return true;
1682
992k
}
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
153k
{
1702
153k
  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
153k
  int max_index = max_value * range_size;
1718
153k
  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
153k
  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
153k
  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
153k
  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
153k
  return true;
1760
153k
}
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.6k
{
1768
17.6k
  unsigned num_bytes = 0; /* total number of bytes transferred.  */
1769
17.6k
  enum aarch64_operand_class opnd_class;
1770
17.6k
  enum aarch64_opnd type;
1771
1772
52.4k
  for (int i = 0; i < AARCH64_MAX_OPND_NUM; i++)
1773
52.4k
    {
1774
52.4k
      type = opnds[i].type;
1775
52.4k
      opnd_class = aarch64_operands[type].op_class;
1776
52.4k
      if (opnd_class == AARCH64_OPND_CLASS_ADDRESS)
1777
17.6k
  break;
1778
34.8k
      num_bytes += aarch64_get_qualifier_esize (opnds[i].qualifier);
1779
34.8k
    }
1780
17.6k
  return num_bytes;
1781
17.6k
}
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
13.7M
{
1806
13.7M
  unsigned num, modifiers, shift;
1807
13.7M
  unsigned char size;
1808
13.7M
  int64_t imm, min_value, max_value;
1809
13.7M
  uint64_t uvalue, mask;
1810
13.7M
  const aarch64_opnd_info *opnd = opnds + idx;
1811
13.7M
  aarch64_opnd_qualifier_t qualifier = opnd->qualifier;
1812
13.7M
  int i;
1813
1814
13.7M
  assert (opcode->operands[idx] == opnd->type && opnd->type == type);
1815
1816
13.7M
  switch (aarch64_operands[type].op_class)
1817
13.7M
    {
1818
4.41M
    case AARCH64_OPND_CLASS_INT_REG:
1819
      /* Check for pair of xzr registers.  */
1820
4.41M
      if (type == AARCH64_OPND_PAIRREG_OR_XZR
1821
2.40k
    && opnds[idx - 1].reg.regno == 0x1f)
1822
922
  {
1823
922
    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
922
  }
1831
      /* Check pair reg constraints for instructions taking a pair of
1832
   consecutively-numbered general-purpose registers.  */
1833
4.41M
      else if (type == AARCH64_OPND_PAIRREG
1834
4.40M
         || type == AARCH64_OPND_PAIRREG_OR_XZR)
1835
5.82k
  {
1836
5.82k
    assert (idx == 1 || idx == 2 || idx == 3 || idx == 5);
1837
5.82k
    if (opnds[idx - 1].reg.regno % 2 != 0)
1838
2.05k
      {
1839
2.05k
        set_syntax_error (mismatch_detail, idx - 1,
1840
2.05k
        _("reg pair must start from even reg"));
1841
2.05k
        return false;
1842
2.05k
      }
1843
3.76k
    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.76k
    break;
1850
3.76k
  }
1851
1852
      /* <Xt> may be optional in some IC and TLBI instructions.  */
1853
4.40M
      if (type == AARCH64_OPND_Rt_SYS)
1854
455
  {
1855
455
    assert (idx == 1 && (aarch64_get_operand_class (opnds[0].type)
1856
455
             == AARCH64_OPND_CLASS_SYSTEM));
1857
455
    if (!(opnds[1].present && aarch64_sys_ins_reg_tlbid_xt (opnds[0].sysins_op)))
1858
453
      {
1859
453
        if (opnds[1].present
1860
451
      && !aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
1861
351
    {
1862
351
      set_other_error (mismatch_detail, idx, _("extraneous register"));
1863
351
      return false;
1864
351
    }
1865
102
        if (!opnds[1].present
1866
2
      && 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
102
     }
1872
455
  }
1873
4.40M
      switch (qualifier)
1874
4.40M
  {
1875
3.02k
  case AARCH64_OPND_QLF_WSP:
1876
3.61k
  case AARCH64_OPND_QLF_SP:
1877
3.61k
    if (!aarch64_stack_pointer_p (opnd))
1878
3.21k
      {
1879
3.21k
        set_other_error (mismatch_detail, idx,
1880
3.21k
           _("stack pointer register expected"));
1881
3.21k
        return false;
1882
3.21k
      }
1883
394
    break;
1884
4.40M
  default:
1885
4.40M
    break;
1886
4.40M
  }
1887
4.40M
      break;
1888
1889
4.40M
    case AARCH64_OPND_CLASS_SVE_REG:
1890
1.22M
      switch (type)
1891
1.22M
  {
1892
2.71k
  case AARCH64_OPND_SVE_Zm3_INDEX:
1893
8.98k
  case AARCH64_OPND_SVE_Zm3_22_INDEX:
1894
9.25k
  case AARCH64_OPND_SVE_Zm3_19_INDEX:
1895
13.8k
  case AARCH64_OPND_SVE_Zm3_11_INDEX:
1896
16.6k
  case AARCH64_OPND_SVE_Zm3_10_INDEX:
1897
20.1k
  case AARCH64_OPND_SVE_Zm4_11_INDEX:
1898
24.1k
  case AARCH64_OPND_SVE_Zm4_INDEX:
1899
24.1k
    size = get_operand_fields_width (get_operand_from_code (type));
1900
24.1k
    shift = get_operand_specific_data (&aarch64_operands[type]);
1901
24.1k
    if (!check_reglane (opnd, mismatch_detail, idx,
1902
24.1k
            "z", 0, (1 << shift) - 1,
1903
24.1k
            0, (1u << (size - shift)) - 1))
1904
0
      return false;
1905
24.1k
    break;
1906
1907
24.1k
  case AARCH64_OPND_SVE_Zm1_23_INDEX:
1908
318
    size = get_operand_fields_width (get_operand_from_code (type));
1909
318
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 1))
1910
0
      return 0;
1911
318
    break;
1912
1913
318
  case AARCH64_OPND_SME_Zn_INDEX2_19:
1914
1.21k
  case AARCH64_OPND_SVE_Zm2_22_INDEX:
1915
1.21k
    size = get_operand_fields_width (get_operand_from_code (type));
1916
1.21k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 3))
1917
0
      return 0;
1918
1.21k
    break;
1919
1920
1.29k
  case AARCH64_OPND_SVE_Zn_INDEX:
1921
1.29k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1922
1.29k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1923
1.29k
            0, 64 / size - 1))
1924
0
      return false;
1925
1.29k
    break;
1926
1927
1.29k
  case AARCH64_OPND_SVE_Zn_5_INDEX:
1928
433
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1929
433
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1930
433
            0, 16 / size - 1))
1931
0
      return false;
1932
433
    break;
1933
1934
433
  case AARCH64_OPND_SME_PNn3_INDEX1:
1935
159
  case AARCH64_OPND_SME_PNn3_INDEX2:
1936
159
    size = get_operand_field_width (get_operand_from_code (type), 0);
1937
159
    if (!check_reglane (opnd, mismatch_detail, idx, "pn", 8, 15,
1938
159
            0, (1 << size) - 1))
1939
0
      return false;
1940
159
    break;
1941
1942
642
  case AARCH64_OPND_SVE_Zm3_12_INDEX:
1943
724
  case AARCH64_OPND_SME_Zn_INDEX1_16:
1944
1.08k
  case AARCH64_OPND_SME_Zn_INDEX2_15:
1945
1.64k
  case AARCH64_OPND_SME_Zn_INDEX2_16:
1946
1.78k
  case AARCH64_OPND_SME_Zn_INDEX3_14:
1947
1.99k
  case AARCH64_OPND_SME_Zn_INDEX3_15:
1948
2.14k
  case AARCH64_OPND_SME_Zn_INDEX4_14:
1949
2.23k
  case AARCH64_OPND_SVE_Zn0_INDEX:
1950
2.37k
  case AARCH64_OPND_SVE_Zn1_17_INDEX:
1951
2.42k
  case AARCH64_OPND_SVE_Zn2_18_INDEX:
1952
2.44k
  case AARCH64_OPND_SVE_Zn3_22_INDEX:
1953
2.54k
  case AARCH64_OPND_SVE_Zd0_INDEX:
1954
2.63k
  case AARCH64_OPND_SVE_Zd1_17_INDEX:
1955
2.65k
  case AARCH64_OPND_SVE_Zd2_18_INDEX:
1956
2.66k
  case AARCH64_OPND_SVE_Zd3_22_INDEX:
1957
2.66k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1958
2.66k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1959
2.66k
            0, (1 << size) - 1))
1960
0
      return false;
1961
2.66k
    break;
1962
1963
2.66k
  case AARCH64_OPND_SME_Zm_INDEX1:
1964
1.39k
  case AARCH64_OPND_SME_Zm_INDEX2:
1965
1.46k
  case AARCH64_OPND_SME_Zm_INDEX2_3:
1966
2.86k
  case AARCH64_OPND_SME_Zm_INDEX3_1:
1967
4.57k
  case AARCH64_OPND_SME_Zm_INDEX3_2:
1968
5.23k
  case AARCH64_OPND_SME_Zm_INDEX3_3:
1969
8.73k
  case AARCH64_OPND_SME_Zm_INDEX3_10:
1970
10.3k
  case AARCH64_OPND_SME_Zm_INDEX4_1:
1971
10.8k
  case AARCH64_OPND_SME_Zm_INDEX4_2:
1972
24.6k
  case AARCH64_OPND_SME_Zm_INDEX4_3:
1973
28.7k
  case AARCH64_OPND_SME_Zm_INDEX4_10:
1974
28.7k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1975
28.7k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 15,
1976
28.7k
            0, (1 << size) - 1))
1977
0
      return false;
1978
28.7k
    break;
1979
1980
28.7k
  case AARCH64_OPND_SME_Zk_INDEX:
1981
3.13k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 3))
1982
0
      return false;
1983
3.13k
    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
3.13k
    break;
1990
1991
7.31k
  case AARCH64_OPND_SME_Zm:
1992
7.37k
  case AARCH64_OPND_SME_Zm_17:
1993
7.37k
    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.37k
    break;
1999
2000
7.37k
  case AARCH64_OPND_SME_Zn_6_3:
2001
7.37k
    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
7.37k
    break;
2008
2009
7.37k
  case AARCH64_OPND_SME_Zm_17_3:
2010
7.11k
    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
7.11k
    break;
2017
2018
7.11k
  case AARCH64_OPND_SME_PnT_Wm_imm:
2019
5.96k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2020
5.96k
    max_value = 16 / size - 1;
2021
5.96k
    if (!check_za_access (opnd, mismatch_detail, idx,
2022
5.96k
        12, max_value, 1, 0, get_opcode_dependent_value (opcode)))
2023
0
      return false;
2024
5.96k
    break;
2025
2026
1.13M
  default:
2027
1.13M
    break;
2028
1.22M
  }
2029
1.22M
      break;
2030
2031
1.22M
    case AARCH64_OPND_CLASS_SVE_REGLIST:
2032
268k
      switch (type)
2033
268k
  {
2034
731
  case AARCH64_OPND_SME_Pdx2:
2035
19.0k
  case AARCH64_OPND_SME_Zdnx2:
2036
25.0k
  case AARCH64_OPND_SME_Zdnx4:
2037
25.2k
  case AARCH64_OPND_SME_Znx2_6_3:
2038
25.6k
  case AARCH64_OPND_SME_Zmx2_17_3:
2039
27.2k
  case AARCH64_OPND_SME_Zmx2:
2040
27.5k
  case AARCH64_OPND_SME_Zmx4:
2041
39.2k
  case AARCH64_OPND_SME_Znx2:
2042
39.2k
  case AARCH64_OPND_SME_Znx2_BIT_INDEX:
2043
43.0k
  case AARCH64_OPND_SME_Znx4:
2044
43.0k
    num = get_operand_specific_data (&aarch64_operands[type]);
2045
43.0k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2046
0
      return false;
2047
43.0k
    if (((opnd->reglist.first_regno % num) != 0)
2048
43.0k
        || (type == AARCH64_OPND_SME_Znx2_6_3
2049
203
      && opnd->reglist.first_regno > 15)
2050
43.0k
        || (type == AARCH64_OPND_SME_Zmx2_17_3
2051
459
      && 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
43.0k
    break;
2058
2059
43.0k
  case AARCH64_OPND_SME_Ztx2_STRIDED:
2060
8.63k
  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
8.63k
    num = get_operand_specific_data (&aarch64_operands[type]);
2064
8.63k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 16 / num))
2065
0
      return false;
2066
8.63k
    num = 16 | (opnd->reglist.stride - 1);
2067
8.63k
    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
8.63k
    break;
2074
2075
8.63k
  case AARCH64_OPND_SME_PdxN:
2076
10.1k
  case AARCH64_OPND_SVE_ZnxN:
2077
216k
  case AARCH64_OPND_SVE_ZtxN:
2078
216k
    num = get_opcode_dependent_value (opcode);
2079
216k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2080
0
      return false;
2081
216k
    break;
2082
2083
216k
  case AARCH64_OPND_SME_Zmx2_INDEX_22:
2084
97
    num = get_operand_specific_data (&aarch64_operands[type]);
2085
97
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2086
0
        return false;
2087
97
    break;
2088
2089
97
  case AARCH64_OPND_SME_Zn7xN_UNTYPED:
2090
79
    num = get_opcode_dependent_value (opcode);
2091
79
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2092
0
        return false;
2093
79
    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
79
    break;
2099
2100
79
  default:
2101
0
    abort ();
2102
268k
  }
2103
268k
      break;
2104
2105
268k
    case AARCH64_OPND_CLASS_ZA_ACCESS:
2106
147k
      switch (type)
2107
147k
  {
2108
838
  case AARCH64_OPND_SME_ZA_HV_idx_src:
2109
63.9k
  case AARCH64_OPND_SME_ZA_HV_idx_dest:
2110
100k
  case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
2111
100k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2112
100k
    max_value = 16 / size - 1;
2113
100k
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, 1,
2114
100k
        get_opcode_dependent_value (opcode),
2115
100k
        get_opcode_dependent_vg_status (opcode)))
2116
0
      return false;
2117
100k
    break;
2118
2119
100k
  case AARCH64_OPND_SME_ZA_array_off4:
2120
702
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
2121
702
        get_opcode_dependent_value (opcode),
2122
702
        get_opcode_dependent_vg_status (opcode)))
2123
0
      return false;
2124
702
    break;
2125
2126
7.36k
  case AARCH64_OPND_SME_ZA_array_off3_0:
2127
8.06k
  case AARCH64_OPND_SME_ZA_array_off3_5:
2128
8.06k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 1,
2129
8.06k
        get_opcode_dependent_value (opcode),
2130
8.06k
        get_opcode_dependent_vg_status (opcode)))
2131
0
      return false;
2132
8.06k
    break;
2133
2134
8.06k
  case AARCH64_OPND_SME_ZA_array_off1x4:
2135
4.70k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 1, 4,
2136
4.70k
        get_opcode_dependent_value (opcode),
2137
4.70k
        get_opcode_dependent_vg_status (opcode)))
2138
0
      return false;
2139
4.70k
    break;
2140
2141
4.70k
  case AARCH64_OPND_SME_ZA_array_off2x2:
2142
3.57k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 2,
2143
3.57k
        get_opcode_dependent_value (opcode),
2144
3.57k
        get_opcode_dependent_vg_status (opcode)))
2145
0
      return false;
2146
3.57k
    break;
2147
2148
4.98k
  case AARCH64_OPND_SME_ZA_array_off2x4:
2149
4.98k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 4,
2150
4.98k
        get_opcode_dependent_value (opcode),
2151
4.98k
        get_opcode_dependent_vg_status (opcode)))
2152
0
      return false;
2153
4.98k
    break;
2154
2155
17.4k
  case AARCH64_OPND_SME_ZA_array_off3x2:
2156
17.4k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 2,
2157
17.4k
        get_opcode_dependent_value (opcode),
2158
17.4k
        get_opcode_dependent_vg_status (opcode)))
2159
0
      return false;
2160
17.4k
    break;
2161
2162
17.4k
  case AARCH64_OPND_SME_ZA_array_vrsb_1:
2163
120
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 7, 2,
2164
120
        get_opcode_dependent_value (opcode),
2165
120
        get_opcode_dependent_vg_status (opcode)))
2166
0
      return false;
2167
120
    break;
2168
2169
120
  case AARCH64_OPND_SME_ZA_array_vrsh_1:
2170
34
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 3, 2,
2171
34
        get_opcode_dependent_value (opcode),
2172
34
        get_opcode_dependent_vg_status (opcode)))
2173
0
      return false;
2174
34
    break;
2175
2176
34
  case AARCH64_OPND_SME_ZA_array_vrss_1:
2177
16
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 1, 2,
2178
16
        get_opcode_dependent_value (opcode),
2179
16
        get_opcode_dependent_vg_status (opcode)))
2180
0
      return false;
2181
16
    break;
2182
2183
270
  case AARCH64_OPND_SME_ZA_array_vrsd_1:
2184
270
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 0, 2,
2185
270
        get_opcode_dependent_value (opcode),
2186
270
        get_opcode_dependent_vg_status (opcode)))
2187
0
      return false;
2188
270
    break;
2189
2190
270
  case AARCH64_OPND_SME_ZA_array_vrsb_2:
2191
214
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 3, 4,
2192
214
        get_opcode_dependent_value (opcode),
2193
214
        get_opcode_dependent_vg_status (opcode)))
2194
0
      return false;
2195
214
    break;
2196
2197
214
  case AARCH64_OPND_SME_ZA_array_vrsh_2:
2198
100
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 1, 4,
2199
100
        get_opcode_dependent_value (opcode),
2200
100
        get_opcode_dependent_vg_status (opcode)))
2201
0
      return false;
2202
100
    break;
2203
2204
601
  case AARCH64_OPND_SME_ZA_ARRAY4:
2205
601
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
2206
601
        get_opcode_dependent_value (opcode),
2207
601
        get_opcode_dependent_vg_status (opcode)))
2208
0
      return false;
2209
601
    break;
2210
2211
601
  case AARCH64_OPND_SME_ZA_array_vrss_2:
2212
166
  case AARCH64_OPND_SME_ZA_array_vrsd_2:
2213
166
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 0, 4,
2214
166
        get_opcode_dependent_value (opcode),
2215
166
        get_opcode_dependent_vg_status (opcode)))
2216
0
      return false;
2217
166
    break;
2218
2219
4.23k
  case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
2220
5.94k
  case AARCH64_OPND_SME_ZA_HV_idx_destxN:
2221
5.94k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2222
5.94k
    num = get_opcode_dependent_value (opcode);
2223
5.94k
    max_value = 16 / num / size;
2224
5.94k
    if (max_value > 0)
2225
5.55k
      max_value -= 1;
2226
5.94k
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, num,
2227
5.94k
        0, get_opcode_dependent_value (opcode)))
2228
0
      return false;
2229
5.94k
    break;
2230
2231
5.94k
  default:
2232
0
    abort ();
2233
147k
  }
2234
147k
      break;
2235
2236
775k
    case AARCH64_OPND_CLASS_PRED_REG:
2237
775k
      switch (type)
2238
775k
  {
2239
1.22k
  case AARCH64_OPND_SME_PNd3:
2240
24.6k
  case AARCH64_OPND_SME_PNg3:
2241
24.6k
    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
24.6k
    break;
2247
2248
750k
  default:
2249
750k
    if (opnd->reg.regno >= 8
2250
54.7k
        && 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
750k
    break;
2256
775k
  }
2257
775k
      break;
2258
2259
775k
    case AARCH64_OPND_CLASS_COND:
2260
16.8k
      if (type == AARCH64_OPND_COND1
2261
221
    && (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
16.8k
      break;
2267
2268
2.40M
    case AARCH64_OPND_CLASS_ADDRESS:
2269
      /* Check writeback.  */
2270
2.40M
      switch (opcode->iclass)
2271
2.40M
  {
2272
180k
  case ldst_pos:
2273
242k
  case ldst_unscaled:
2274
349k
  case ldstnapair_offs:
2275
480k
  case ldstpair_off:
2276
490k
  case ldst_unpriv:
2277
490k
    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
490k
    break;
2284
490k
  case ldst_imm10:
2285
9.08k
    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
9.08k
    break;
2292
37.8k
  case ldst_imm9:
2293
223k
  case ldstpair_indexed:
2294
228k
  case asisdlsep:
2295
238k
  case asisdlsop:
2296
238k
    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
238k
    break;
2303
238k
  case rcpc3:
2304
21.7k
    if (opnd->addr.writeback)
2305
1.42k
      if ((type == AARCH64_OPND_RCPC3_ADDR_PREIND_WB
2306
231
     && !opnd->addr.preind)
2307
1.42k
    || (type == AARCH64_OPND_RCPC3_ADDR_POSTIND
2308
37
        && !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.7k
    break;
2316
1.64M
  default:
2317
1.64M
    assert (opnd->addr.writeback == 0);
2318
1.64M
    break;
2319
2.40M
  }
2320
2.40M
      switch (type)
2321
2.40M
  {
2322
406k
  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
406k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2328
406k
    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
406k
    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
406k
    break;
2340
406k
  case AARCH64_OPND_ADDR_OFFSET:
2341
103k
  case AARCH64_OPND_ADDR_SIMM9:
2342
    /* Unscaled signed 9 bits immediate offset.  */
2343
103k
    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
103k
    break;
2349
2350
103k
  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
9.08k
  case AARCH64_OPND_ADDR_SIMM10:
2363
    /* Scaled signed 10 bits immediate offset.  */
2364
9.08k
    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
9.08k
    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
9.08k
    break;
2375
2376
17.4k
  case AARCH64_OPND_ADDR_SIMM11:
2377
    /* Signed 11 bits immediate offset (multiple of 16).  */
2378
17.4k
    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
17.4k
    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
17.4k
    break;
2390
2391
17.4k
  case AARCH64_OPND_ADDR_SIMM13:
2392
    /* Signed 13 bits immediate offset (multiple of 16).  */
2393
5.65k
    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.65k
    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.65k
    break;
2405
2406
14.5k
  case AARCH64_OPND_SIMD_ADDR_POST:
2407
    /* AdvSIMD load/store multiple structures, post-index.  */
2408
14.5k
    assert (idx == 1);
2409
14.5k
    if (opnd->addr.offset.is_reg)
2410
11.8k
      {
2411
11.8k
        if (value_in_range_p (opnd->addr.offset.regno, 0, 30))
2412
11.8k
    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
11.8k
      }
2420
2.71k
    else
2421
2.71k
      {
2422
2.71k
        const aarch64_opnd_info *prev = &opnds[idx-1];
2423
2.71k
        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.71k
        int is_ld1r = get_opcode_dependent_value (opcode) == 1;
2427
2.71k
        if (opcode->operands[0] == AARCH64_OPND_LVt_AL)
2428
    /* Special handling of loading single structure to all lane.  */
2429
552
    num_bytes = (is_ld1r ? 1 : prev->reglist.num_regs)
2430
552
      * aarch64_get_qualifier_esize (prev->qualifier);
2431
2.16k
        else
2432
2.16k
    num_bytes = prev->reglist.num_regs
2433
2.16k
      * aarch64_get_qualifier_esize (prev->qualifier)
2434
2.16k
      * aarch64_get_qualifier_nelem (prev->qualifier);
2435
2.71k
        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.71k
      }
2442
2.71k
    break;
2443
2444
56.5k
  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
56.5k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2449
    /* It is either no shift or shift by the binary logarithm of SIZE.  */
2450
56.5k
    if (opnd->shifter.amount != 0
2451
32.7k
        && 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
56.5k
    switch (opnd->shifter.kind)
2460
56.5k
      {
2461
1.81k
      case AARCH64_MOD_UXTW:
2462
14.8k
      case AARCH64_MOD_LSL:
2463
16.6k
      case AARCH64_MOD_SXTW:
2464
20.8k
      case AARCH64_MOD_SXTX: break;
2465
35.7k
      default:
2466
35.7k
        set_other_error (mismatch_detail, idx,
2467
35.7k
             _("invalid extend/shift operator"));
2468
35.7k
        return false;
2469
56.5k
      }
2470
20.8k
    break;
2471
2472
180k
  case AARCH64_OPND_ADDR_UIMM12:
2473
180k
    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
180k
    size = aarch64_get_qualifier_esize (qualifier);
2478
180k
    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
180k
    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
180k
    break;
2490
2491
180k
  case AARCH64_OPND_ADDR_PCREL9:
2492
221k
  case AARCH64_OPND_ADDR_PCREL14:
2493
549k
  case AARCH64_OPND_ADDR_PCREL19:
2494
802k
  case AARCH64_OPND_ADDR_PCREL21:
2495
992k
  case AARCH64_OPND_ADDR_PCREL26:
2496
992k
    {
2497
992k
      imm = opnd->imm.value;
2498
992k
      if (operand_need_shift_by_two (get_operand_from_code (type)))
2499
739k
        {
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
739k
    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
739k
    imm >>= 2;
2510
739k
        }
2511
2512
992k
      if (!check_immediate_out_of_range (imm, type, mismatch_detail, idx))
2513
0
        return false;
2514
992k
    }
2515
992k
    break;
2516
2517
992k
  case AARCH64_OPND_SME_ADDR_RI_U4xVL:
2518
702
    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
702
    break;
2524
2525
50.8k
  case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
2526
60.1k
  case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
2527
62.4k
  case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
2528
69.3k
  case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
2529
69.3k
    min_value = -8;
2530
69.3k
    max_value = 7;
2531
76.4k
  sve_imm_offset_vl:
2532
76.4k
    assert (!opnd->addr.offset.is_reg);
2533
76.4k
    assert (opnd->addr.preind);
2534
76.4k
    num = 1 + get_operand_specific_data (&aarch64_operands[type]);
2535
76.4k
    min_value *= num;
2536
76.4k
    max_value *= num;
2537
76.4k
    if ((opnd->addr.offset.imm != 0 && !opnd->shifter.operator_present)
2538
76.4k
        || (opnd->shifter.operator_present
2539
71.7k
      && 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
76.4k
    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
76.4k
    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
76.4k
    break;
2557
2558
76.4k
  case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
2559
2.18k
    min_value = -32;
2560
2.18k
    max_value = 31;
2561
2.18k
    goto sve_imm_offset_vl;
2562
2563
4.85k
  case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
2564
4.85k
    min_value = -256;
2565
4.85k
    max_value = 255;
2566
4.85k
    goto sve_imm_offset_vl;
2567
2568
3.82k
  case AARCH64_OPND_SVE_ADDR_RI_U6:
2569
8.18k
  case AARCH64_OPND_SVE_ADDR_RI_U6x2:
2570
9.57k
  case AARCH64_OPND_SVE_ADDR_RI_U6x4:
2571
10.6k
  case AARCH64_OPND_SVE_ADDR_RI_U6x8:
2572
10.6k
    min_value = 0;
2573
10.6k
    max_value = 63;
2574
25.3k
  sve_imm_offset:
2575
25.3k
    assert (!opnd->addr.offset.is_reg);
2576
25.3k
    assert (opnd->addr.preind);
2577
25.3k
    num = 1 << get_operand_specific_data (&aarch64_operands[type]);
2578
25.3k
    min_value *= num;
2579
25.3k
    max_value *= num;
2580
25.3k
    if (opnd->shifter.operator_present
2581
25.3k
        || 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
25.3k
    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
25.3k
    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
25.3k
    break;
2599
2600
25.3k
  case AARCH64_OPND_SVE_ADDR_RI_S4x16:
2601
2.44k
  case AARCH64_OPND_SVE_ADDR_RI_S4x32:
2602
2.44k
    min_value = -8;
2603
2.44k
    max_value = 7;
2604
2.44k
    goto sve_imm_offset;
2605
2606
10.4k
  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
10.4k
    assert (opnd->addr.offset.is_reg);
2611
10.4k
    assert (opnd->addr.preind);
2612
10.4k
    assert ((aarch64_operands[type].flags & OPD_F_NO_ZR) == 0);
2613
10.4k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2614
10.4k
    assert (opnd->shifter.operator_present == 0);
2615
10.4k
    break;
2616
2617
10.4k
  case AARCH64_OPND_SVE_ADDR_RR:
2618
16.3k
  case AARCH64_OPND_SVE_ADDR_RR_LSL1:
2619
19.8k
  case AARCH64_OPND_SVE_ADDR_RR_LSL2:
2620
33.8k
  case AARCH64_OPND_SVE_ADDR_RR_LSL3:
2621
46.4k
  case AARCH64_OPND_SVE_ADDR_RR_LSL4:
2622
53.1k
  case AARCH64_OPND_SVE_ADDR_RM:
2623
56.4k
  case AARCH64_OPND_SVE_ADDR_RM_LSL1:
2624
59.3k
  case AARCH64_OPND_SVE_ADDR_RM_LSL2:
2625
62.5k
  case AARCH64_OPND_SVE_ADDR_RM_LSL3:
2626
62.5k
  case AARCH64_OPND_SVE_ADDR_RM_LSL4:
2627
74.0k
  case AARCH64_OPND_SVE_ADDR_RX:
2628
81.4k
  case AARCH64_OPND_SVE_ADDR_RX_LSL1:
2629
89.4k
  case AARCH64_OPND_SVE_ADDR_RX_LSL2:
2630
94.0k
  case AARCH64_OPND_SVE_ADDR_RX_LSL3:
2631
96.8k
  case AARCH64_OPND_SVE_ADDR_RX_LSL4:
2632
116k
  case AARCH64_OPND_SVE_ADDR_RZ:
2633
118k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
2634
120k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
2635
122k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
2636
122k
    modifiers = 1 << AARCH64_MOD_LSL;
2637
173k
  sve_rr_operand:
2638
173k
    assert (opnd->addr.offset.is_reg);
2639
173k
    assert (opnd->addr.preind);
2640
173k
    if ((aarch64_operands[type].flags & OPD_F_NO_ZR) != 0
2641
34.2k
        && 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
173k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2648
173k
        || (opnd->shifter.amount
2649
173k
      != 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
173k
    break;
2656
2657
173k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
2658
32.7k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
2659
34.0k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
2660
39.6k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
2661
40.6k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
2662
45.5k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
2663
46.0k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
2664
51.4k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
2665
51.4k
    modifiers = (1 << AARCH64_MOD_SXTW) | (1 << AARCH64_MOD_UXTW);
2666
51.4k
    goto sve_rr_operand;
2667
2668
3.69k
  case AARCH64_OPND_SVE_ADDR_ZI_U5:
2669
8.86k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
2670
11.0k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
2671
12.1k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
2672
12.1k
    min_value = 0;
2673
12.1k
    max_value = 31;
2674
12.1k
    goto sve_imm_offset;
2675
2676
957
  case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
2677
957
    modifiers = 1 << AARCH64_MOD_LSL;
2678
2.10k
  sve_zz_operand:
2679
2.10k
    assert (opnd->addr.offset.is_reg);
2680
2.10k
    assert (opnd->addr.preind);
2681
2.10k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2682
2.10k
        || opnd->shifter.amount < 0
2683
2.10k
        || 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
2.10k
    break;
2690
2691
2.10k
  case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
2692
139
    modifiers = (1 << AARCH64_MOD_SXTW);
2693
139
    goto sve_zz_operand;
2694
2695
1.01k
  case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
2696
1.01k
    modifiers = 1 << AARCH64_MOD_UXTW;
2697
1.01k
    goto sve_zz_operand;
2698
2699
15.1k
  case AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB:
2700
15.9k
  case AARCH64_OPND_RCPC3_ADDR_OPT_POSTIND:
2701
16.2k
  case AARCH64_OPND_RCPC3_ADDR_PREIND_WB:
2702
16.2k
  case AARCH64_OPND_RCPC3_ADDR_POSTIND:
2703
16.2k
    {
2704
16.2k
      int num_bytes = calc_ldst_datasize (opnds);
2705
16.2k
      int abs_offset = (type == AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB
2706
1.11k
            || type == AARCH64_OPND_RCPC3_ADDR_PREIND_WB)
2707
16.2k
        ? opnd->addr.offset.imm * -1
2708
16.2k
        : opnd->addr.offset.imm;
2709
16.2k
      if ((int) num_bytes != abs_offset
2710
14.8k
    && 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
16.2k
    }
2717
16.2k
    break;
2718
2719
16.2k
  case AARCH64_OPND_RCPC3_ADDR_OFFSET:
2720
5.41k
    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
315k
  default:
2727
315k
    break;
2728
2.40M
  }
2729
2.35M
      break;
2730
2731
2.35M
    case AARCH64_OPND_CLASS_SIMD_REGLIST:
2732
43.0k
      if (type == AARCH64_OPND_LEt)
2733
14.0k
  {
2734
    /* Get the upper bound for the element index.  */
2735
14.0k
    num = 16 / aarch64_get_qualifier_esize (qualifier) - 1;
2736
14.0k
    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
14.0k
  }
2742
      /* The opcode dependent area stores the number of elements in
2743
   each structure to be loaded/stored.  */
2744
43.0k
      num = get_opcode_dependent_value (opcode);
2745
43.0k
      switch (type)
2746
43.0k
  {
2747
3.08k
  case AARCH64_OPND_LVn_LUT:
2748
3.08k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2749
0
      return 0;
2750
3.08k
    break;
2751
11.5k
  case AARCH64_OPND_LVt:
2752
11.5k
    assert (num >= 1 && num <= 4);
2753
    /* Unless LD1/ST1, the number of registers should be equal to that
2754
       of the structure elements.  */
2755
11.5k
    if (num != 1 && !check_reglist (opnd, mismatch_detail, idx, num, 1))
2756
569
      return false;
2757
10.9k
    break;
2758
10.9k
  case AARCH64_OPND_LVt_AL:
2759
15.7k
  case AARCH64_OPND_LEt:
2760
15.7k
    assert (num >= 1 && num <= 4);
2761
    /* The number of registers should be equal to that of the structure
2762
       elements.  */
2763
15.7k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2764
0
      return false;
2765
15.7k
    break;
2766
15.7k
  default:
2767
12.6k
    break;
2768
43.0k
  }
2769
42.4k
      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
42.4k
      break;
2775
2776
2.51M
    case AARCH64_OPND_CLASS_IMMEDIATE:
2777
      /* Constraint check on immediate operand.  */
2778
2.51M
      imm = opnd->imm.value;
2779
      /* E.g. imm_0_31 constrains value to be 0..31.  */
2780
2.51M
      if (qualifier_value_in_range_constraint_p (qualifier)
2781
327k
    && !value_in_range_p (imm, get_lower_bound (qualifier),
2782
327k
        get_upper_bound (qualifier)))
2783
35.2k
  {
2784
35.2k
    set_imm_out_of_range_error (mismatch_detail, idx,
2785
35.2k
              get_lower_bound (qualifier),
2786
35.2k
              get_upper_bound (qualifier));
2787
35.2k
    return false;
2788
35.2k
  }
2789
2790
2.48M
      switch (type)
2791
2.48M
  {
2792
302k
  case AARCH64_OPND_AIMM:
2793
302k
    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
302k
    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
302k
    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
302k
    break;
2812
2813
302k
  case AARCH64_OPND_HALF:
2814
80.5k
    assert (idx == 1 && opnds[0].type == AARCH64_OPND_Rd);
2815
80.5k
    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
80.5k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2822
80.5k
    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
80.5k
    if (!value_in_range_p (opnd->shifter.amount, 0, size * 8 - 16))
2829
14.4k
      {
2830
14.4k
        set_sft_amount_out_of_range_error (mismatch_detail, idx,
2831
14.4k
             0, size * 8 - 16);
2832
14.4k
        return false;
2833
14.4k
      }
2834
66.0k
    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
66.0k
    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
66.0k
    break;
2847
2848
66.0k
  case AARCH64_OPND_IMM_MOV:
2849
45.2k
      {
2850
45.2k
        int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2851
45.2k
        imm = opnd->imm.value;
2852
45.2k
        assert (idx == 1);
2853
45.2k
        switch (opcode->op)
2854
45.2k
    {
2855
24.4k
    case OP_MOV_IMM_WIDEN:
2856
24.4k
      imm = ~imm;
2857
      /* Fall through.  */
2858
44.6k
    case OP_MOV_IMM_WIDE:
2859
44.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
44.6k
      break;
2866
44.6k
    case OP_MOV_IMM_LOG:
2867
591
      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
591
      break;
2874
591
    default:
2875
0
      assert (0);
2876
0
      return false;
2877
45.2k
    }
2878
45.2k
      }
2879
45.2k
    break;
2880
2881
45.2k
  case AARCH64_OPND_NZCV:
2882
7.18k
  case AARCH64_OPND_CCMP_IMM:
2883
8.00k
  case AARCH64_OPND_EXCEPTION:
2884
1.35M
  case AARCH64_OPND_UNDEFINED:
2885
1.35M
  case AARCH64_OPND_TME_UIMM16:
2886
1.35M
  case AARCH64_OPND_UIMM4:
2887
1.35M
  case AARCH64_OPND_UIMM4_ADDG:
2888
1.35M
  case AARCH64_OPND_UIMM7:
2889
1.36M
  case AARCH64_OPND_UIMM3_OP1:
2890
1.37M
  case AARCH64_OPND_UIMM3_OP2:
2891
1.37M
  case AARCH64_OPND_SVE_UIMM3:
2892
1.39M
  case AARCH64_OPND_SVE_UIMM7:
2893
1.39M
  case AARCH64_OPND_SVE_UIMM8:
2894
1.39M
  case AARCH64_OPND_SVE_UIMM4:
2895
1.39M
  case AARCH64_OPND_SVE_UIMM8_53:
2896
1.39M
  case AARCH64_OPND_CSSC_UIMM8:
2897
1.39M
    size = get_operand_fields_width (get_operand_from_code (type));
2898
1.39M
    assert (size < 32);
2899
1.39M
    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.39M
    break;
2906
2907
1.39M
  case AARCH64_OPND_UIMM10:
2908
    /* Scaled unsigned 10 bits immediate offset.  */
2909
2.72k
    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.72k
    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.72k
    break;
2921
2922
9.87k
  case AARCH64_OPND_SIMM5:
2923
10.1k
  case AARCH64_OPND_SVE_SIMM5:
2924
10.4k
  case AARCH64_OPND_SVE_SIMM5B:
2925
11.2k
  case AARCH64_OPND_SVE_SIMM6:
2926
11.8k
  case AARCH64_OPND_SVE_SIMM8:
2927
13.9k
  case AARCH64_OPND_CSSC_SIMM8:
2928
13.9k
    size = get_operand_fields_width (get_operand_from_code (type));
2929
13.9k
    assert (size < 32);
2930
13.9k
    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
13.9k
    break;
2938
2939
24.7k
  case AARCH64_OPND_WIDTH:
2940
24.7k
    assert (idx > 1 && opnds[idx-1].type == AARCH64_OPND_IMM
2941
24.7k
      && opnds[0].type == AARCH64_OPND_Rd);
2942
24.7k
    size = get_upper_bound (qualifier);
2943
24.7k
    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
24.7k
    break;
2951
2952
227k
  case AARCH64_OPND_LIMM:
2953
256k
  case AARCH64_OPND_SVE_LIMM:
2954
256k
    {
2955
256k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2956
256k
      uint64_t uimm = opnd->imm.value;
2957
256k
      if (opcode->op == OP_BIC)
2958
0
        uimm = ~uimm;
2959
256k
      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
256k
    }
2966
256k
    break;
2967
2968
256k
  case AARCH64_OPND_IMM0:
2969
405
  case AARCH64_OPND_FPIMM0:
2970
405
    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
405
    break;
2977
2978
602
  case AARCH64_OPND_IMM_ROT1:
2979
12.7k
  case AARCH64_OPND_IMM_ROT2:
2980
18.9k
  case AARCH64_OPND_SVE_IMM_ROT2:
2981
18.9k
    if (opnd->imm.value != 0
2982
14.1k
        && opnd->imm.value != 90
2983
9.08k
        && opnd->imm.value != 180
2984
5.80k
        && 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
18.9k
    break;
2991
2992
18.9k
  case AARCH64_OPND_IMM_ROT3:
2993
641
  case AARCH64_OPND_SVE_IMM_ROT1:
2994
751
  case AARCH64_OPND_SVE_IMM_ROT3:
2995
751
    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
751
    break;
3002
3003
751
  case AARCH64_OPND_SHLL_IMM:
3004
63
    assert (idx == 2);
3005
63
    size = 8 * aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
3006
63
    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
63
    break;
3013
3014
6.55k
  case AARCH64_OPND_IMM_VLSL:
3015
6.55k
    size = aarch64_get_qualifier_esize (qualifier);
3016
6.55k
    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
6.55k
    break;
3023
3024
10.4k
  case AARCH64_OPND_IMM_VLSR:
3025
10.4k
    size = aarch64_get_qualifier_esize (qualifier);
3026
10.4k
    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
10.4k
    break;
3032
3033
10.4k
  case AARCH64_OPND_SIMD_IMM:
3034
3.41k
  case AARCH64_OPND_SIMD_IMM_SFT:
3035
    /* Qualifier check.  */
3036
3.41k
    switch (qualifier)
3037
3.41k
      {
3038
2.41k
      case AARCH64_OPND_QLF_LSL:
3039
2.41k
        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
2.41k
        break;
3046
2.41k
      case AARCH64_OPND_QLF_MSL:
3047
282
        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
282
        break;
3054
724
      case AARCH64_OPND_QLF_NIL:
3055
724
        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
724
        break;
3062
724
      default:
3063
0
        assert (0);
3064
0
        return false;
3065
3.41k
      }
3066
    /* Is the immediate valid?  */
3067
3.41k
    assert (idx == 1);
3068
3.41k
    if (aarch64_get_qualifier_esize (opnds[0].qualifier) != 8)
3069
2.69k
      {
3070
        /* uimm8 or simm8 */
3071
2.69k
        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.69k
      }
3077
724
    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.41k
    switch (opnd->shifter.kind)
3088
3.41k
      {
3089
2.41k
      case AARCH64_MOD_LSL:
3090
2.41k
        size = aarch64_get_qualifier_esize (opnds[0].qualifier);
3091
2.41k
        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
2.41k
        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
2.41k
        break;
3103
2.41k
      case AARCH64_MOD_MSL:
3104
        /* Only 8 and 16 are valid shift amount.  */
3105
282
        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
282
        break;
3112
724
      default:
3113
724
        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
724
        break;
3120
3.41k
      }
3121
3.41k
    break;
3122
3123
3.41k
  case AARCH64_OPND_FPIMM:
3124
2.12k
  case AARCH64_OPND_SIMD_FPIMM:
3125
3.65k
  case AARCH64_OPND_SVE_FPIMM8:
3126
3.65k
    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
3.65k
    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
3.65k
    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
3.65k
    break;
3149
3150
3.65k
  case AARCH64_OPND_SVE_AIMM:
3151
2.22k
    min_value = 0;
3152
13.8k
  sve_aimm:
3153
13.8k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
3154
13.8k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
3155
13.8k
    mask = ~((uint64_t) -1 << (size * 4) << (size * 4));
3156
13.8k
    uvalue = opnd->imm.value;
3157
13.8k
    shift = opnd->shifter.amount;
3158
13.8k
    if (size == 1)
3159
3.78k
      {
3160
3.78k
        if (shift != 0)
3161
124
    {
3162
124
      set_other_error (mismatch_detail, idx,
3163
124
           _("no shift amount allowed for"
3164
124
             " 8-bit constants"));
3165
124
      return false;
3166
124
    }
3167
3.78k
      }
3168
10.1k
    else
3169
10.1k
      {
3170
10.1k
        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
10.1k
        if (shift == 0 && (uvalue & 0xff) == 0)
3177
3.79k
    {
3178
3.79k
      shift = 8;
3179
3.79k
      uvalue = (int64_t) uvalue / 256;
3180
3.79k
    }
3181
10.1k
      }
3182
13.7k
    mask >>= shift;
3183
13.7k
    if ((uvalue & mask) != uvalue && (uvalue | ~mask) != uvalue)
3184
1.38k
      {
3185
1.38k
        set_other_error (mismatch_detail, idx,
3186
1.38k
             _("immediate too big for element size"));
3187
1.38k
        return false;
3188
1.38k
      }
3189
12.3k
    uvalue = (uvalue - min_value) & mask;
3190
12.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
12.3k
    break;
3197
3198
12.3k
  case AARCH64_OPND_SVE_ASIMM:
3199
11.6k
    min_value = -128;
3200
11.6k
    goto sve_aimm;
3201
3202
55
  case AARCH64_OPND_SVE_I1_HALF_ONE:
3203
55
    assert (opnd->imm.is_fp);
3204
55
    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
55
    break;
3211
3212
215
  case AARCH64_OPND_SVE_I1_HALF_TWO:
3213
215
    assert (opnd->imm.is_fp);
3214
215
    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
215
    break;
3221
3222
1.36k
  case AARCH64_OPND_SVE_I1_ZERO_ONE:
3223
1.36k
    assert (opnd->imm.is_fp);
3224
1.36k
    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
1.36k
    break;
3231
3232
1.36k
  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
2.35k
  case AARCH64_OPND_SVE_LIMM_MOV:
3246
2.35k
    {
3247
2.35k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
3248
2.35k
      uint64_t uimm = opnd->imm.value;
3249
2.35k
      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
2.35k
      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
2.35k
    }
3262
2.35k
    break;
3263
3264
5.06k
  case AARCH64_OPND_SVE_PATTERN_SCALED:
3265
5.06k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL);
3266
5.06k
    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.06k
    break;
3272
3273
5.06k
  case AARCH64_OPND_SVE_SHLIMM_PRED:
3274
1.39k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED:
3275
2.03k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
3276
2.03k
    size = aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
3277
2.03k
    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
2.03k
    break;
3284
3285
2.03k
  case AARCH64_OPND_SME_SHRIMM3:
3286
354
  case AARCH64_OPND_SME_SHRIMM4:
3287
354
    size = 1 << get_operand_fields_width (get_operand_from_code (type));
3288
354
    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
354
    break;
3294
3295
354
  case AARCH64_OPND_SME_SHRIMM5:
3296
1.33k
  case AARCH64_OPND_SVE_SHRIMM_PRED:
3297
2.97k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED:
3298
6.81k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
3299
6.81k
    num = (type == AARCH64_OPND_SVE_SHRIMM_UNPRED_22) ? 2 : 1;
3300
6.81k
    size = aarch64_get_qualifier_esize (opnds[idx - num].qualifier);
3301
6.81k
    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
6.81k
    break;
3307
3308
6.81k
  case AARCH64_OPND_SME_ZT0_INDEX:
3309
90
    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
90
    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
90
    break;
3321
3322
102
  case AARCH64_OPND_SME_ZT0_INDEX_MUL_VL:
3323
102
    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
102
    break;
3329
3330
282k
  default:
3331
282k
    break;
3332
2.48M
  }
3333
2.46M
      break;
3334
3335
2.46M
    case AARCH64_OPND_CLASS_SYSTEM:
3336
45.4k
      switch (type)
3337
45.4k
  {
3338
98
  case AARCH64_OPND_PSTATEFIELD:
3339
339
    for (i = 0; aarch64_pstatefields[i].name; ++i)
3340
339
      if (aarch64_pstatefields[i].value == opnd->pstatefield)
3341
98
        break;
3342
98
    assert (aarch64_pstatefields[i].name);
3343
98
    assert (idx == 0 && opnds[1].type == AARCH64_OPND_UIMM4);
3344
98
    max_value = F_GET_REG_MAX_VALUE (aarch64_pstatefields[i].flags);
3345
98
    if (opnds[1].imm.value < 0 || opnds[1].imm.value > max_value)
3346
20
      {
3347
20
        set_imm_out_of_range_error (mismatch_detail, 1, 0, max_value);
3348
20
        return false;
3349
20
      }
3350
78
    break;
3351
32.1k
  case AARCH64_OPND_PRFOP:
3352
32.1k
    if (opcode->iclass == ldst_regoff && opnd->prfop->value >= 24)
3353
986
      {
3354
986
        set_other_error (mismatch_detail, idx,
3355
986
             _("the register-index form of PRFM does"
3356
986
         " not accept opcodes in the range 24-31"));
3357
986
        return false;
3358
986
      }
3359
31.1k
    break;
3360
31.1k
  default:
3361
13.2k
    break;
3362
45.4k
  }
3363
44.4k
      break;
3364
3365
76.9k
    case AARCH64_OPND_CLASS_SIMD_ELEMENT:
3366
      /* Get the upper bound for the element index.  */
3367
76.9k
      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.36k
  num = aarch64_get_qualifier_nelem (opnds[0].qualifier)
3371
5.36k
        * aarch64_get_qualifier_esize (opnds[0].qualifier) / 2;
3372
71.6k
      else if (opcode->iclass == lut)
3373
3.08k
  {
3374
3.08k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
3375
3.08k
    if (!check_reglane (opnd, mismatch_detail, idx, "v", 0, 31,
3376
3.08k
            0, (1 << size) - 1))
3377
0
      return 0;
3378
3.08k
    break;
3379
3.08k
  }
3380
68.5k
      else
3381
68.5k
  num = 16;
3382
73.8k
      num = num / aarch64_get_qualifier_esize (qualifier) - 1;
3383
73.8k
      assert (aarch64_get_qualifier_nelem (qualifier) == 1);
3384
3385
      /* Index out-of-range.  */
3386
73.8k
      if (!value_in_range_p (opnd->reglane.index, 0, num))
3387
481
  {
3388
481
    set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
3389
481
    return false;
3390
481
  }
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
73.3k
      if (type == AARCH64_OPND_Em16
3400
34.1k
    && (qualifier == AARCH64_OPND_QLF_S_H
3401
7.04k
        || qualifier == AARCH64_OPND_QLF_S_2B)
3402
29.2k
    && !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
73.3k
      if (type == AARCH64_OPND_Em8
3408
2.49k
    && !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
73.3k
      break;
3414
3415
431k
    case AARCH64_OPND_CLASS_MODIFIED_REG:
3416
431k
      assert (idx == 1 || idx == 2);
3417
431k
      switch (type)
3418
431k
  {
3419
40.9k
  case AARCH64_OPND_Rm_EXT:
3420
40.9k
    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.9k
    if (!aarch64_stack_pointer_p (opnds + 0)
3432
40.2k
        && (idx != 2 || !aarch64_stack_pointer_p (opnds + 1)))
3433
38.2k
      {
3434
38.2k
        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
38.2k
        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
38.2k
      }
3447
40.9k
    assert (opnd->shifter.operator_present  /* Default to LSL.  */
3448
40.9k
      || opnd->shifter.kind == AARCH64_MOD_LSL);
3449
40.9k
    if (!value_in_range_p (opnd->shifter.amount, 0, 4))
3450
6.16k
      {
3451
6.16k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, 4);
3452
6.16k
        return false;
3453
6.16k
      }
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.8k
    if (qualifier == AARCH64_OPND_QLF_X
3460
3.42k
        && opnd->shifter.kind != AARCH64_MOD_LSL
3461
3.42k
        && opnd->shifter.kind != AARCH64_MOD_UXTX
3462
1.65k
        && 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.8k
    break;
3468
3469
389k
  case AARCH64_OPND_Rm_SFT:
3470
    /* ROR is not available to the shifted register operand in
3471
       arithmetic instructions.  */
3472
389k
    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
389k
    if (opnd->shifter.kind == AARCH64_MOD_ROR
3479
62.8k
        && 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
389k
    num = qualifier == AARCH64_OPND_QLF_W ? 31 : 63;
3486
389k
    if (!value_in_range_p (opnd->shifter.amount, 0, num))
3487
49.9k
      {
3488
49.9k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, num);
3489
49.9k
        return false;
3490
49.9k
      }
3491
339k
    break;
3492
3493
339k
  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
681
    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
681
    break;
3503
3504
681
  default:
3505
0
    break;
3506
431k
  }
3507
375k
      break;
3508
3509
1.36M
    default:
3510
1.36M
      break;
3511
13.7M
    }
3512
3513
13.5M
  return true;
3514
13.7M
}
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.93M
{
3531
5.93M
  int i;
3532
3533
5.93M
  DEBUG_TRACE ("enter");
3534
3535
5.93M
  i = inst->opcode->tied_operand;
3536
3537
5.93M
  if (i > 0)
3538
62.4k
    {
3539
      /* Check for tied_operands with specific opcode iclass.  */
3540
62.4k
      switch (inst->opcode->iclass)
3541
62.4k
        {
3542
        /* For SME LDR and STR instructions #imm must have the same numerical
3543
           value for both operands.
3544
        */
3545
659
        case sme_ldr:
3546
702
        case sme_str:
3547
702
          assert (inst->operands[0].type == AARCH64_OPND_SME_ZA_array_off4);
3548
702
          assert (inst->operands[1].type == AARCH64_OPND_SME_ADDR_RI_U4xVL);
3549
702
          if (inst->operands[0].indexed_za.index.imm
3550
702
              != 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
702
          break;
3560
3561
61.7k
        default:
3562
61.7k
    {
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
61.7k
      enum aarch64_operand_class op_class
3570
61.7k
         = aarch64_get_operand_class (inst->operands[0].type);
3571
61.7k
      assert (aarch64_get_operand_class (inst->operands[i].type)
3572
61.7k
        == op_class);
3573
61.7k
      if (op_class == AARCH64_OPND_CLASS_SVE_REGLIST
3574
61.7k
    ? ((inst->operands[0].reglist.first_regno
3575
263
        != inst->operands[i].reglist.first_regno)
3576
263
       || (inst->operands[0].reglist.num_regs
3577
263
           != inst->operands[i].reglist.num_regs)
3578
263
       || (inst->operands[0].reglist.stride
3579
263
           != inst->operands[i].reglist.stride))
3580
61.7k
    : (inst->operands[0].reg.regno
3581
61.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
61.7k
      break;
3592
61.7k
    }
3593
62.4k
        }
3594
62.4k
    }
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.93M
  int invalid_count;
3607
5.93M
  if (match_operands_qualifier (inst, true /* update_p */,
3608
5.93M
        &invalid_count) == 0)
3609
32.8k
    {
3610
32.8k
      DEBUG_TRACE ("FAIL on operand qualifier matching");
3611
32.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
32.8k
      return false;
3622
32.8k
    }
3623
3624
  /* Match operands' constraint.  */
3625
19.4M
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3626
19.4M
    {
3627
19.4M
      enum aarch64_opnd type = inst->opcode->operands[i];
3628
19.4M
      if (type == AARCH64_OPND_NIL)
3629
5.74M
  break;
3630
13.7M
      if (inst->operands[i].skip)
3631
0
  {
3632
0
    DEBUG_TRACE ("skip the incomplete operand %d", i);
3633
0
    continue;
3634
0
  }
3635
13.7M
      if (!operand_general_constraint_met_p (inst->operands, i, type,
3636
13.7M
               inst->opcode, mismatch_detail))
3637
150k
  {
3638
150k
    DEBUG_TRACE ("FAIL on operand %d", i);
3639
150k
    return false;
3640
150k
  }
3641
13.7M
    }
3642
3643
5.74M
  DEBUG_TRACE ("PASS");
3644
3645
5.74M
  return true;
3646
5.89M
}
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
71.5k
{
3660
71.5k
  int i;
3661
71.5k
  const aarch64_opcode *old = inst->opcode;
3662
3663
71.5k
  inst->opcode = opcode;
3664
3665
  /* Update the operand types.  */
3666
264k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3667
264k
    {
3668
264k
      inst->operands[i].type = opcode->operands[i];
3669
264k
      if (opcode->operands[i] == AARCH64_OPND_NIL)
3670
71.5k
  break;
3671
264k
    }
3672
3673
71.5k
  DEBUG_TRACE ("replace %s with %s", old->name, opcode->name);
3674
3675
71.5k
  return old;
3676
71.5k
}
3677
3678
int
3679
aarch64_operand_index (const enum aarch64_opnd *operands, enum aarch64_opnd operand)
3680
136k
{
3681
136k
  int i;
3682
162k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3683
162k
    if (operands[i] == operand)
3684
132k
      return i;
3685
29.8k
    else if (operands[i] == AARCH64_OPND_NIL)
3686
4.62k
      break;
3687
4.62k
  return -1;
3688
136k
}
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.50M
{
3727
3.50M
  const int has_zr = sp_reg_p ? 0 : 1;
3728
3.50M
  const int is_64 = aarch64_get_qualifier_esize (qualifier) == 4 ? 0 : 1;
3729
3.50M
  return int_reg[has_zr][is_64][regno];
3730
3.50M
}
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.22M
{
3737
1.22M
  const int has_zr = sp_reg_p ? 0 : 1;
3738
1.22M
  return int_reg[has_zr][1][regno];
3739
1.22M
}
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
117k
{
3747
117k
  switch (opnd->shifter.kind)
3748
117k
    {
3749
1.81k
    case AARCH64_MOD_UXTW:
3750
3.60k
    case AARCH64_MOD_SXTW:
3751
3.60k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_W, 0);
3752
3753
109k
    case AARCH64_MOD_LSL:
3754
114k
    case AARCH64_MOD_SXTX:
3755
114k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_X, 0);
3756
3757
0
    default:
3758
0
      abort ();
3759
117k
    }
3760
117k
}
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
103k
{
3768
103k
  assert (qualifier == AARCH64_OPND_QLF_S_S
3769
103k
    || qualifier == AARCH64_OPND_QLF_S_D);
3770
103k
  return sve_reg[qualifier == AARCH64_OPND_QLF_S_D][regno];
3771
103k
}
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.88k
{
3804
2.88k
  uint64_t imm = 0;
3805
2.88k
  uint32_t imm8_7, imm8_6_0, imm8_6, imm8_6_repl4;
3806
3807
2.88k
  imm8_7 = (imm8 >> 7) & 0x01;  /* imm8<7>   */
3808
2.88k
  imm8_6_0 = imm8 & 0x7f; /* imm8<6:0> */
3809
2.88k
  imm8_6 = imm8_6_0 >> 6; /* imm8<6>   */
3810
2.88k
  imm8_6_repl4 = (imm8_6 << 3) | (imm8_6 << 2)
3811
2.88k
    | (imm8_6 << 1) | imm8_6; /* Replicate(imm8<6>,4) */
3812
2.88k
  if (size == 8)
3813
571
    {
3814
571
      imm = (imm8_7 << (63-32))   /* imm8<7>  */
3815
571
  | ((imm8_6 ^ 1) << (62-32)) /* NOT(imm8<6)  */
3816
571
  | (imm8_6_repl4 << (58-32)) | (imm8_6 << (57-32))
3817
571
  | (imm8_6 << (56-32)) | (imm8_6 << (55-32)) /* Replicate(imm8<6>,7) */
3818
571
  | (imm8_6_0 << (48-32));  /* imm8<6>:imm8<5:0>    */
3819
571
      imm <<= 32;
3820
571
    }
3821
2.31k
  else if (size == 4 || size == 2)
3822
2.31k
    {
3823
2.31k
      imm = (imm8_7 << 31)  /* imm8<7>              */
3824
2.31k
  | ((imm8_6 ^ 1) << 30)  /* NOT(imm8<6>)         */
3825
2.31k
  | (imm8_6_repl4 << 26)  /* Replicate(imm8<6>,4) */
3826
2.31k
  | (imm8_6_0 << 19); /* imm8<6>:imm8<5:0>    */
3827
2.31k
    }
3828
0
  else
3829
0
    {
3830
      /* An unsupported size.  */
3831
0
      assert (0);
3832
0
    }
3833
3834
2.88k
  return imm;
3835
2.88k
}
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
8.75M
{
3842
8.75M
  const char *txt;
3843
8.75M
  va_list ap;
3844
3845
8.75M
  va_start (ap, fmt);
3846
8.75M
  txt = styler->apply_style (styler, dis_style_register, fmt, ap);
3847
8.75M
  va_end (ap);
3848
3849
8.75M
  return txt;
3850
8.75M
}
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.55M
{
3857
3.55M
  const char *txt;
3858
3.55M
  va_list ap;
3859
3860
3.55M
  va_start (ap, fmt);
3861
3.55M
  txt = styler->apply_style (styler, dis_style_immediate, fmt, ap);
3862
3.55M
  va_end (ap);
3863
3864
3.55M
  return txt;
3865
3.55M
}
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
582k
{
3872
582k
  const char *txt;
3873
582k
  va_list ap;
3874
3875
582k
  va_start (ap, fmt);
3876
582k
  txt = styler->apply_style (styler, dis_style_sub_mnemonic, fmt, ap);
3877
582k
  va_end (ap);
3878
3879
582k
  return txt;
3880
582k
}
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
1.06M
{
3887
1.06M
  const char *txt;
3888
1.06M
  va_list ap;
3889
3890
1.06M
  va_start (ap, fmt);
3891
1.06M
  txt = styler->apply_style (styler, dis_style_address, fmt, ap);
3892
1.06M
  va_end (ap);
3893
3894
1.06M
  return txt;
3895
1.06M
}
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
307k
{
3904
307k
  const int mask = (prefix[0] == 'p' ? 15 : 31);
3905
307k
  const int num_regs = opnd->reglist.num_regs;
3906
307k
  const int stride = opnd->reglist.stride;
3907
307k
  const int first_reg = opnd->reglist.first_regno;
3908
307k
  const int last_reg = (first_reg + (num_regs - 1) * stride) & mask;
3909
307k
  const char *qlf_name = aarch64_get_qualifier_name (opnd->qualifier);
3910
307k
  char tb[16];  /* Temporary buffer.  */
3911
3912
307k
  assert (opnd->type != AARCH64_OPND_LEt || opnd->reglist.has_index);
3913
307k
  assert (num_regs >= 1 && num_regs <= 4);
3914
3915
  /* Prepare the index if any.  */
3916
307k
  if (opnd->reglist.has_index)
3917
    /* PR 21096: The %100 is to silence a warning about possible truncation.  */
3918
14.1k
    snprintf (tb, sizeof (tb), "[%s]",
3919
14.1k
        style_imm (styler, "%" PRIi64, (opnd->reglist.index % 100)));
3920
293k
  else
3921
293k
    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
307k
  if (stride == 1 && num_regs > 1)
3927
93.8k
    if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3928
203
      snprintf (buf, size, "{%s-%s}%s",
3929
203
    style_reg (styler, "%s%d", prefix, first_reg),
3930
203
    style_reg (styler, "%s%d", prefix, last_reg), tb);
3931
93.5k
    else
3932
93.5k
      snprintf (buf, size, "{%s-%s}%s",
3933
93.5k
    style_reg (styler, "%s%d.%s", prefix, first_reg, qlf_name),
3934
93.5k
    style_reg (styler, "%s%d.%s", prefix, last_reg, qlf_name), tb);
3935
213k
  else
3936
213k
    {
3937
213k
      const int reg0 = first_reg;
3938
213k
      const int reg1 = (first_reg + stride) & mask;
3939
213k
      const int reg2 = (first_reg + stride * 2) & mask;
3940
213k
      const int reg3 = (first_reg + stride * 3) & mask;
3941
3942
213k
      switch (num_regs)
3943
213k
  {
3944
204k
  case 1:
3945
204k
    snprintf (buf, size, "{%s}%s",
3946
204k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3947
204k
        tb);
3948
204k
    break;
3949
6.01k
  case 2:
3950
6.01k
    snprintf (buf, size, "{%s, %s}%s",
3951
6.01k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3952
6.01k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3953
6.01k
        tb);
3954
6.01k
    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.62k
  case 4:
3963
2.62k
    snprintf (buf, size, "{%s, %s, %s, %s}%s",
3964
2.62k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3965
2.62k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3966
2.62k
        style_reg (styler, "%s%d.%s", prefix, reg2, qlf_name),
3967
2.62k
        style_reg (styler, "%s%d.%s", prefix, reg3, qlf_name),
3968
2.62k
        tb);
3969
2.62k
    break;
3970
213k
  }
3971
213k
    }
3972
307k
}
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
664k
{
3983
664k
  if (opnd->addr.writeback)
3984
230k
    {
3985
230k
      if (opnd->addr.preind)
3986
121k
        {
3987
121k
    if (opnd->type == AARCH64_OPND_ADDR_SIMM10 && !opnd->addr.offset.imm)
3988
136
      snprintf (buf, size, "[%s]!", style_reg (styler, base));
3989
121k
          else
3990
121k
      snprintf (buf, size, "[%s, %s]!",
3991
121k
          style_reg (styler, base),
3992
121k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
3993
121k
        }
3994
108k
      else
3995
108k
  snprintf (buf, size, "[%s], %s",
3996
108k
      style_reg (styler, base),
3997
108k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3998
230k
    }
3999
434k
  else
4000
434k
    {
4001
434k
      if (opnd->shifter.operator_present)
4002
70.5k
  {
4003
70.5k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL_VL);
4004
70.5k
    snprintf (buf, size, "[%s, %s, %s]",
4005
70.5k
        style_reg (styler, base),
4006
70.5k
        style_imm (styler, "#%d", opnd->addr.offset.imm),
4007
70.5k
        style_sub_mnem (styler, "mul vl"));
4008
70.5k
  }
4009
364k
      else if (opnd->addr.offset.imm)
4010
294k
  snprintf (buf, size, "[%s, %s]",
4011
294k
      style_reg (styler, base),
4012
294k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
4013
69.4k
      else
4014
69.4k
  snprintf (buf, size, "[%s]", style_reg (styler, base));
4015
434k
    }
4016
664k
}
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
207k
{
4027
207k
  char tb[32];      /* Temporary buffer.  */
4028
207k
  bool print_extend_p = true;
4029
207k
  bool print_amount_p = true;
4030
207k
  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
207k
  if (opnd->type == AARCH64_OPND_SVE_ADDR_ZX && offset != NULL
4035
10.4k
      && strcmp (offset,"xzr") == 0)
4036
281
    {
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
281
      snprintf (buf, size, "[%s]", style_reg (styler, base));
4041
281
    }
4042
206k
  else
4043
206k
    {
4044
206k
      if (!opnd->shifter.amount && (opnd->qualifier != AARCH64_OPND_QLF_S_B
4045
4.30k
            || !opnd->shifter.amount_present))
4046
98.0k
  {
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
98.0k
   print_amount_p = false;
4051
   /* Likewise, no need to print the shift operator LSL in such a
4052
      situation.  */
4053
98.0k
   if (opnd->shifter.kind == AARCH64_MOD_LSL)
4054
61.7k
     print_extend_p = false;
4055
98.0k
  }
4056
4057
      /* Prepare for the extend/shift.  */
4058
206k
      if (print_extend_p)
4059
145k
  {
4060
145k
    if (print_amount_p)
4061
108k
      snprintf (tb, sizeof (tb), ", %s %s",
4062
108k
          style_sub_mnem (styler, shift_name),
4063
108k
          style_imm (styler, "#%" PRIi64,
4064
    /* PR 21096: The %100 is to silence a warning about possible
4065
       truncation.  */
4066
108k
         (opnd->shifter.amount % 100)));
4067
36.2k
    else
4068
36.2k
      snprintf (tb, sizeof (tb), ", %s",
4069
36.2k
          style_sub_mnem (styler, shift_name));
4070
145k
  }
4071
61.7k
      else
4072
61.7k
  tb[0] = '\0';
4073
4074
206k
      snprintf (buf, size, "[%s, %s%s]", style_reg (styler, base),
4075
206k
    style_reg (styler, offset), tb);
4076
206k
    }
4077
207k
}
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
252
{
4092
252
  static const struct {
4093
252
    unsigned char mask;
4094
252
    char name[7];
4095
252
  } zan[] = {
4096
252
    { 0xff, "za" },
4097
252
    { 0x55, "za0.h" },
4098
252
    { 0xaa, "za1.h" },
4099
252
    { 0x11, "za0.s" },
4100
252
    { 0x22, "za1.s" },
4101
252
    { 0x44, "za2.s" },
4102
252
    { 0x88, "za3.s" },
4103
252
    { 0x01, "za0.d" },
4104
252
    { 0x02, "za1.d" },
4105
252
    { 0x04, "za2.d" },
4106
252
    { 0x08, "za3.d" },
4107
252
    { 0x10, "za4.d" },
4108
252
    { 0x20, "za5.d" },
4109
252
    { 0x40, "za6.d" },
4110
252
    { 0x80, "za7.d" },
4111
252
    { 0x00, " " },
4112
252
  };
4113
252
  int k;
4114
4115
252
  k = snprintf (buf, size, "{");
4116
2.16k
  for (unsigned int i = 0; i < ARRAY_SIZE (zan); i++)
4117
2.16k
    {
4118
2.16k
      if ((mask & zan[i].mask) == zan[i].mask)
4119
698
  {
4120
698
    mask &= ~zan[i].mask;
4121
698
    if (k > 1)
4122
449
      k += snprintf (buf + k, size - k, ", ");
4123
4124
698
    k += snprintf (buf + k, size - k, "%s",
4125
698
       style_reg (styler, zan[i].name));
4126
698
  }
4127
2.16k
      if (mask == 0)
4128
252
        break;
4129
2.16k
    }
4130
252
  snprintf (buf + k, size - k, "}");
4131
252
}
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
11.4M
{
4153
11.4M
  unsigned int i, num_conds;
4154
11.4M
  const char *name = NULL;
4155
11.4M
  const aarch64_opnd_info *opnd = opnds + idx;
4156
11.4M
  enum aarch64_modifier_kind kind;
4157
11.4M
  uint64_t addr, enum_value;
4158
4159
11.4M
  if (comment != NULL)
4160
11.4M
    {
4161
11.4M
      assert (comment_size > 0);
4162
11.4M
      comment[0] = '\0';
4163
11.4M
    }
4164
0
  else
4165
11.4M
    assert (comment_size == 0);
4166
4167
11.4M
  buf[0] = '\0';
4168
11.4M
  if (pcrel_p)
4169
11.4M
    *pcrel_p = 0;
4170
4171
11.4M
  switch (opnd->type)
4172
11.4M
    {
4173
883k
    case AARCH64_OPND_Rd:
4174
1.33M
    case AARCH64_OPND_Rn:
4175
1.42M
    case AARCH64_OPND_Rm:
4176
2.37M
    case AARCH64_OPND_Rt:
4177
2.59M
    case AARCH64_OPND_Rt2:
4178
2.71M
    case AARCH64_OPND_Rs:
4179
2.73M
    case AARCH64_OPND_Ra:
4180
2.73M
    case AARCH64_OPND_Rt_IN_SYS_ALIASES:
4181
2.73M
    case AARCH64_OPND_Rt_LS64:
4182
2.73M
    case AARCH64_OPND_Rt_SYS:
4183
2.73M
    case AARCH64_OPND_PAIRREG:
4184
2.73M
    case AARCH64_OPND_PAIRREG_OR_XZR:
4185
2.73M
    case AARCH64_OPND_SVE_Rm:
4186
2.73M
    case AARCH64_OPND_LSE128_Rt:
4187
2.73M
    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.73M
      if (opnd->type == AARCH64_OPND_Rt_SYS)
4192
104
  {
4193
104
    if (!opnd->present)
4194
2
      break;
4195
104
  }
4196
2.73M
      else if ((opnd->type == AARCH64_OPND_Rt_IN_SYS_ALIASES)
4197
44
         && (opnd->reg.regno
4198
44
       != get_optional_operand_default_value (opcode)))
4199
44
  {
4200
    /* Avoid printing an invalid additional value for Rt in SYS aliases such as
4201
       BRB, provide a helpful comment instead */
4202
44
    snprintf (comment, comment_size, "unpredictable encoding (Rt!=31): #%u", opnd->reg.regno);
4203
44
    break;
4204
44
  }
4205
      /* Omit the operand, e.g. RET.  */
4206
2.73M
      else if (optional_operand_p (opcode, idx)
4207
4.06k
         && (opnd->reg.regno
4208
4.06k
       == get_optional_operand_default_value (opcode)))
4209
1.47k
  break;
4210
2.73M
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
4211
2.73M
        || opnd->qualifier == AARCH64_OPND_QLF_X);
4212
2.73M
      snprintf (buf, size, "%s",
4213
2.73M
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
4214
2.73M
                 opnd->qualifier, 0)));
4215
2.73M
      break;
4216
4217
173k
    case AARCH64_OPND_Rd_SP:
4218
361k
    case AARCH64_OPND_Rn_SP:
4219
366k
    case AARCH64_OPND_Rt_SP:
4220
367k
    case AARCH64_OPND_SVE_Rn_SP:
4221
367k
    case AARCH64_OPND_Rm_SP:
4222
367k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
4223
367k
        || opnd->qualifier == AARCH64_OPND_QLF_WSP
4224
367k
        || opnd->qualifier == AARCH64_OPND_QLF_X
4225
367k
        || opnd->qualifier == AARCH64_OPND_QLF_SP);
4226
367k
      snprintf (buf, size, "%s",
4227
367k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
4228
367k
                 opnd->qualifier, 1)));
4229
367k
      break;
4230
4231
20.3k
    case AARCH64_OPND_Rm_EXT:
4232
20.3k
      kind = opnd->shifter.kind;
4233
20.3k
      assert (idx == 1 || idx == 2);
4234
20.3k
      if ((aarch64_stack_pointer_p (opnds)
4235
19.9k
     || (idx == 2 && aarch64_stack_pointer_p (opnds + 1)))
4236
1.37k
    && ((opnd->qualifier == AARCH64_OPND_QLF_W
4237
695
         && opnds[0].qualifier == AARCH64_OPND_QLF_W
4238
405
         && kind == AARCH64_MOD_UXTW)
4239
1.31k
        || (opnd->qualifier == AARCH64_OPND_QLF_X
4240
677
      && kind == AARCH64_MOD_UXTX)))
4241
577
  {
4242
    /* 'LSL' is the preferred form in this case.  */
4243
577
    kind = AARCH64_MOD_LSL;
4244
577
    if (opnd->shifter.amount == 0)
4245
457
      {
4246
        /* Shifter omitted.  */
4247
457
        snprintf (buf, size, "%s",
4248
457
      style_reg (styler,
4249
457
           get_int_reg_name (opnd->reg.regno,
4250
457
                 opnd->qualifier, 0)));
4251
457
        break;
4252
457
      }
4253
577
  }
4254
19.8k
      if (opnd->shifter.amount)
4255
15.7k
  snprintf (buf, size, "%s, %s %s",
4256
15.7k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4257
15.7k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name),
4258
15.7k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4259
4.16k
      else
4260
4.16k
  snprintf (buf, size, "%s, %s",
4261
4.16k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4262
4.16k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name));
4263
19.8k
      break;
4264
4265
241k
    case AARCH64_OPND_Rm_SFT:
4266
241k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
4267
241k
        || opnd->qualifier == AARCH64_OPND_QLF_X);
4268
241k
      if (opnd->shifter.amount == 0 && opnd->shifter.kind == AARCH64_MOD_LSL)
4269
25.6k
  snprintf (buf, size, "%s",
4270
25.6k
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
4271
25.6k
                   opnd->qualifier, 0)));
4272
215k
      else
4273
215k
  snprintf (buf, size, "%s, %s %s",
4274
215k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4275
215k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4276
215k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4277
241k
      break;
4278
4279
681
    case AARCH64_OPND_Rm_LSL:
4280
681
      assert (opnd->qualifier == AARCH64_OPND_QLF_X);
4281
681
      assert (opnd->shifter.kind == AARCH64_MOD_LSL);
4282
681
      if (opnd->shifter.amount == 0)
4283
172
  snprintf (buf, size, "%s",
4284
172
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
4285
172
                   opnd->qualifier, 0)));
4286
509
      else
4287
509
  snprintf (buf, size, "%s, %s %s",
4288
509
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4289
509
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4290
509
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4291
681
      break;
4292
4293
86.2k
    case AARCH64_OPND_Fd:
4294
118k
    case AARCH64_OPND_Fn:
4295
158k
    case AARCH64_OPND_Fm:
4296
225k
    case AARCH64_OPND_Fa:
4297
585k
    case AARCH64_OPND_Ft:
4298
760k
    case AARCH64_OPND_Ft2:
4299
778k
    case AARCH64_OPND_Sd:
4300
795k
    case AARCH64_OPND_Sn:
4301
802k
    case AARCH64_OPND_Sm:
4302
802k
    case AARCH64_OPND_SVE_VZn:
4303
806k
    case AARCH64_OPND_SVE_Vd:
4304
806k
    case AARCH64_OPND_SVE_Vm:
4305
806k
    case AARCH64_OPND_SVE_Vn:
4306
806k
      snprintf (buf, size, "%s",
4307
806k
    style_reg (styler, "%s%d",
4308
806k
         aarch64_get_qualifier_name (opnd->qualifier),
4309
806k
         opnd->reg.regno));
4310
806k
      break;
4311
4312
8.66k
    case AARCH64_OPND_Va:
4313
229k
    case AARCH64_OPND_Vd:
4314
419k
    case AARCH64_OPND_Vn:
4315
550k
    case AARCH64_OPND_Vm:
4316
550k
      snprintf (buf, size, "%s",
4317
550k
    style_reg (styler, "v%d.%s", opnd->reg.regno,
4318
550k
         aarch64_get_qualifier_name (opnd->qualifier)));
4319
550k
      break;
4320
4321
1.39k
    case AARCH64_OPND_Ed:
4322
6.31k
    case AARCH64_OPND_En:
4323
33.0k
    case AARCH64_OPND_Em:
4324
67.2k
    case AARCH64_OPND_Em16:
4325
69.7k
    case AARCH64_OPND_Em8:
4326
69.7k
    case AARCH64_OPND_SM3_IMM2:
4327
69.7k
      snprintf (buf, size, "%s[%s]",
4328
69.7k
    style_reg (styler, "v%d.%s", opnd->reglane.regno,
4329
69.7k
         aarch64_get_qualifier_name (opnd->qualifier)),
4330
69.7k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4331
69.7k
      break;
4332
4333
972
    case AARCH64_OPND_Em_INDEX1_14:
4334
2.65k
    case AARCH64_OPND_Em_INDEX2_13:
4335
3.08k
    case AARCH64_OPND_Em_INDEX3_12:
4336
3.08k
      snprintf (buf, size, "%s[%s]",
4337
3.08k
    style_reg (styler, "v%d", opnd->reglane.regno),
4338
3.08k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4339
3.08k
      break;
4340
4341
185
    case AARCH64_OPND_VdD1:
4342
661
    case AARCH64_OPND_VnD1:
4343
661
      snprintf (buf, size, "%s[%s]",
4344
661
    style_reg (styler, "v%d.d", opnd->reg.regno),
4345
661
    style_imm (styler, "1"));
4346
661
      break;
4347
4348
12.6k
    case AARCH64_OPND_LVn:
4349
15.7k
    case AARCH64_OPND_LVn_LUT:
4350
26.6k
    case AARCH64_OPND_LVt:
4351
28.3k
    case AARCH64_OPND_LVt_AL:
4352
42.4k
    case AARCH64_OPND_LEt:
4353
42.4k
      print_register_list (buf, size, opnd, "v", styler);
4354
42.4k
      break;
4355
4356
64.0k
    case AARCH64_OPND_SVE_Pd:
4357
571k
    case AARCH64_OPND_SVE_Pg3:
4358
572k
    case AARCH64_OPND_SVE_Pg4_5:
4359
586k
    case AARCH64_OPND_SVE_Pg4_10:
4360
592k
    case AARCH64_OPND_SVE_Pg4_16:
4361
597k
    case AARCH64_OPND_SVE_Pm:
4362
603k
    case AARCH64_OPND_SVE_Pn:
4363
605k
    case AARCH64_OPND_SVE_Pt:
4364
665k
    case AARCH64_OPND_SME_Pm:
4365
665k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4366
112k
  snprintf (buf, size, "%s",
4367
112k
      style_reg (styler, "p%d", opnd->reg.regno));
4368
552k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
4369
324k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
4370
479k
  snprintf (buf, size, "%s",
4371
479k
      style_reg (styler, "p%d/%s", opnd->reg.regno,
4372
479k
           aarch64_get_qualifier_name (opnd->qualifier)));
4373
72.9k
      else
4374
72.9k
  snprintf (buf, size, "%s",
4375
72.9k
      style_reg (styler, "p%d.%s", opnd->reg.regno,
4376
72.9k
           aarch64_get_qualifier_name (opnd->qualifier)));
4377
665k
      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.22k
    case AARCH64_OPND_SME_PNd3:
4384
24.6k
    case AARCH64_OPND_SME_PNg3:
4385
24.6k
    case AARCH64_OPND_SME_PNn:
4386
24.6k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4387
8.25k
  snprintf (buf, size, "%s",
4388
8.25k
      style_reg (styler, "pn%d", opnd->reg.regno));
4389
16.4k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
4390
1.25k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
4391
15.1k
  snprintf (buf, size, "%s",
4392
15.1k
      style_reg (styler, "pn%d/%s", opnd->reg.regno,
4393
15.1k
           aarch64_get_qualifier_name (opnd->qualifier)));
4394
1.25k
      else
4395
1.25k
  snprintf (buf, size, "%s",
4396
1.25k
      style_reg (styler, "pn%d.%s", opnd->reg.regno,
4397
1.25k
           aarch64_get_qualifier_name (opnd->qualifier)));
4398
24.6k
      break;
4399
4400
731
    case AARCH64_OPND_SME_Pdx2:
4401
837
    case AARCH64_OPND_SME_PdxN:
4402
837
      print_register_list (buf, size, opnd, "p", styler);
4403
837
      break;
4404
4405
106
    case AARCH64_OPND_SME_PNn3_INDEX1:
4406
159
    case AARCH64_OPND_SME_PNn3_INDEX2:
4407
159
      snprintf (buf, size, "%s[%s]",
4408
159
    style_reg (styler, "pn%d", opnd->reglane.regno),
4409
159
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4410
159
      break;
4411
4412
5.84k
    case AARCH64_OPND_SVE_Za_5:
4413
12.6k
    case AARCH64_OPND_SVE_Za_16:
4414
329k
    case AARCH64_OPND_SVE_Zd:
4415
362k
    case AARCH64_OPND_SVE_Zm_5:
4416
595k
    case AARCH64_OPND_SVE_Zm_16:
4417
957k
    case AARCH64_OPND_SVE_Zn:
4418
959k
    case AARCH64_OPND_SVE_Zt:
4419
967k
    case AARCH64_OPND_SME_Zm:
4420
967k
    case AARCH64_OPND_SME_Zm_17:
4421
974k
    case AARCH64_OPND_SME_Zn_6_3:
4422
981k
    case AARCH64_OPND_SME_Zm_17_3:
4423
981k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4424
2.53k
       snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
4425
979k
      else
4426
979k
       snprintf (buf, size, "%s",
4427
979k
     style_reg (styler, "z%d.%s", opnd->reg.regno,
4428
979k
          aarch64_get_qualifier_name (opnd->qualifier)));
4429
981k
      break;
4430
4431
10.0k
    case AARCH64_OPND_SVE_ZnxN:
4432
216k
    case AARCH64_OPND_SVE_ZtxN:
4433
232k
    case AARCH64_OPND_SME_Zdnx2:
4434
238k
    case AARCH64_OPND_SME_Zdnx4:
4435
238k
    case AARCH64_OPND_SME_Znx2_6_3:
4436
238k
    case AARCH64_OPND_SME_Zmx2_17_3:
4437
240k
    case AARCH64_OPND_SME_Zmx2:
4438
240k
    case AARCH64_OPND_SME_Zmx4:
4439
240k
    case AARCH64_OPND_SME_Zmx2_INDEX_22:
4440
251k
    case AARCH64_OPND_SME_Znx2:
4441
251k
    case AARCH64_OPND_SME_Znx2_BIT_INDEX:
4442
255k
    case AARCH64_OPND_SME_Znx4:
4443
255k
    case AARCH64_OPND_SME_Zn7xN_UNTYPED:
4444
261k
    case AARCH64_OPND_SME_Ztx2_STRIDED:
4445
263k
    case AARCH64_OPND_SME_Ztx4_STRIDED:
4446
263k
      print_register_list (buf, size, opnd, "z", styler);
4447
263k
      break;
4448
4449
318
    case AARCH64_OPND_SVE_Zm1_23_INDEX:
4450
1.42k
    case AARCH64_OPND_SVE_Zm2_22_INDEX:
4451
4.14k
    case AARCH64_OPND_SVE_Zm3_INDEX:
4452
10.4k
    case AARCH64_OPND_SVE_Zm3_22_INDEX:
4453
10.6k
    case AARCH64_OPND_SVE_Zm3_19_INDEX:
4454
11.3k
    case AARCH64_OPND_SVE_Zm3_12_INDEX:
4455
15.9k
    case AARCH64_OPND_SVE_Zm3_11_INDEX:
4456
18.7k
    case AARCH64_OPND_SVE_Zm3_10_INDEX:
4457
22.2k
    case AARCH64_OPND_SVE_Zm4_11_INDEX:
4458
26.1k
    case AARCH64_OPND_SVE_Zm4_INDEX:
4459
26.8k
    case AARCH64_OPND_SVE_Zn_INDEX:
4460
29.9k
    case AARCH64_OPND_SME_Zk_INDEX:
4461
30.0k
    case AARCH64_OPND_SME_Zm_INDEX1:
4462
31.3k
    case AARCH64_OPND_SME_Zm_INDEX2:
4463
31.4k
    case AARCH64_OPND_SME_Zm_INDEX2_3:
4464
32.8k
    case AARCH64_OPND_SME_Zm_INDEX3_1:
4465
34.5k
    case AARCH64_OPND_SME_Zm_INDEX3_2:
4466
35.1k
    case AARCH64_OPND_SME_Zm_INDEX3_3:
4467
38.6k
    case AARCH64_OPND_SME_Zm_INDEX3_10:
4468
39.1k
    case AARCH64_OPND_SVE_Zn_5_INDEX:
4469
40.7k
    case AARCH64_OPND_SME_Zm_INDEX4_1:
4470
41.2k
    case AARCH64_OPND_SME_Zm_INDEX4_2:
4471
55.0k
    case AARCH64_OPND_SME_Zm_INDEX4_3:
4472
59.1k
    case AARCH64_OPND_SME_Zm_INDEX4_10:
4473
59.2k
    case AARCH64_OPND_SME_Zn_INDEX1_16:
4474
59.5k
    case AARCH64_OPND_SME_Zn_INDEX2_15:
4475
60.1k
    case AARCH64_OPND_SME_Zn_INDEX2_16:
4476
60.2k
    case AARCH64_OPND_SME_Zn_INDEX2_19:
4477
60.4k
    case AARCH64_OPND_SME_Zn_INDEX3_14:
4478
60.6k
    case AARCH64_OPND_SME_Zn_INDEX3_15:
4479
60.7k
    case AARCH64_OPND_SME_Zn_INDEX4_14:
4480
60.7k
      snprintf (buf, size, "%s[%s]",
4481
60.7k
    (opnd->qualifier == AARCH64_OPND_QLF_NIL
4482
60.7k
     ? style_reg (styler, "z%d", opnd->reglane.regno)
4483
60.7k
     : style_reg (styler, "z%d.%s", opnd->reglane.regno,
4484
54.0k
            aarch64_get_qualifier_name (opnd->qualifier))),
4485
60.7k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4486
60.7k
      break;
4487
4488
92
    case AARCH64_OPND_SVE_Zn0_INDEX:
4489
229
    case AARCH64_OPND_SVE_Zn1_17_INDEX:
4490
283
    case AARCH64_OPND_SVE_Zn2_18_INDEX:
4491
300
    case AARCH64_OPND_SVE_Zn3_22_INDEX:
4492
404
    case AARCH64_OPND_SVE_Zd0_INDEX:
4493
495
    case AARCH64_OPND_SVE_Zd1_17_INDEX:
4494
508
    case AARCH64_OPND_SVE_Zd2_18_INDEX:
4495
523
    case AARCH64_OPND_SVE_Zd3_22_INDEX:
4496
523
      if (opnd->reglane.index == 0)
4497
330
  snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
4498
193
      else
4499
193
  snprintf (buf, size, "%s[%s]",
4500
193
      style_reg (styler, "z%d", opnd->reglane.regno),
4501
193
      style_imm (styler, "%" PRIi64, opnd->reglane.index));
4502
523
      break;
4503
4504
1.46k
    case AARCH64_OPND_SME_ZAda_1b:
4505
57.7k
    case AARCH64_OPND_SME_ZAda_2b:
4506
70.7k
    case AARCH64_OPND_SME_ZAda_3b:
4507
70.7k
      snprintf (buf, size, "%s",
4508
70.7k
    style_reg (styler, "za%d.%s", opnd->reg.regno,
4509
70.7k
         aarch64_get_qualifier_name (opnd->qualifier)));
4510
70.7k
      break;
4511
4512
419
    case AARCH64_OPND_SME_ZA_HV_idx_src:
4513
2.53k
    case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
4514
34.1k
    case AARCH64_OPND_SME_ZA_HV_idx_dest:
4515
34.9k
    case AARCH64_OPND_SME_ZA_HV_idx_destxN:
4516
71.1k
    case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
4517
71.3k
    case AARCH64_OPND_SME_ZA_array_vrsb_1:
4518
71.3k
    case AARCH64_OPND_SME_ZA_array_vrsh_1:
4519
71.3k
    case AARCH64_OPND_SME_ZA_array_vrss_1:
4520
71.6k
    case AARCH64_OPND_SME_ZA_array_vrsd_1:
4521
71.8k
    case AARCH64_OPND_SME_ZA_array_vrsb_2:
4522
71.9k
    case AARCH64_OPND_SME_ZA_array_vrsh_2:
4523
72.0k
    case AARCH64_OPND_SME_ZA_array_vrss_2:
4524
72.1k
    case AARCH64_OPND_SME_ZA_array_vrsd_2:
4525
72.7k
    case AARCH64_OPND_SME_ZA_ARRAY4:
4526
72.7k
      snprintf (buf, size, "%s%s[%s, %s%s%s%s%s]%s",
4527
72.7k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "{" : "",
4528
72.7k
    style_reg (styler, "za%d%c%s%s",
4529
72.7k
         opnd->indexed_za.regno,
4530
72.7k
         opnd->indexed_za.v == 1 ? 'v' : 'h',
4531
72.7k
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4532
72.7k
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4533
72.7k
          ? ""
4534
72.7k
          : aarch64_get_qualifier_name (opnd->qualifier))),
4535
72.7k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4536
72.7k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4537
72.7k
    opnd->indexed_za.index.countm1 ? ":" : "",
4538
72.7k
    (opnd->indexed_za.index.countm1
4539
72.7k
     ? style_imm (styler, "%d",
4540
3.89k
            opnd->indexed_za.index.imm
4541
3.89k
            + opnd->indexed_za.index.countm1)
4542
72.7k
     : ""),
4543
72.7k
    opnd->indexed_za.group_size ? ", " : "",
4544
72.7k
    opnd->indexed_za.group_size == 2
4545
72.7k
    ? style_sub_mnem (styler, "vgx2")
4546
72.7k
    : opnd->indexed_za.group_size == 4
4547
72.7k
    ? style_sub_mnem (styler, "vgx4") : "",
4548
72.7k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "}" : "");
4549
72.7k
      break;
4550
4551
252
    case AARCH64_OPND_SME_list_of_64bit_tiles:
4552
252
      print_sme_za_list (buf, size, opnd->imm.value, styler);
4553
252
      break;
4554
4555
4.70k
    case AARCH64_OPND_SME_ZA_array_off1x4:
4556
8.28k
    case AARCH64_OPND_SME_ZA_array_off2x2:
4557
13.2k
    case AARCH64_OPND_SME_ZA_array_off2x4:
4558
20.4k
    case AARCH64_OPND_SME_ZA_array_off3_0:
4559
20.8k
    case AARCH64_OPND_SME_ZA_array_off3_5:
4560
38.3k
    case AARCH64_OPND_SME_ZA_array_off3x2:
4561
39.0k
    case AARCH64_OPND_SME_ZA_array_off4:
4562
39.0k
      snprintf (buf, size, "%s[%s, %s%s%s%s%s]",
4563
39.0k
    style_reg (styler, "za%s%s",
4564
39.0k
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4565
39.0k
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4566
39.0k
          ? ""
4567
39.0k
          : aarch64_get_qualifier_name (opnd->qualifier))),
4568
39.0k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4569
39.0k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4570
39.0k
    opnd->indexed_za.index.countm1 ? ":" : "",
4571
39.0k
    (opnd->indexed_za.index.countm1
4572
39.0k
     ? style_imm (styler, "%d",
4573
30.7k
            opnd->indexed_za.index.imm
4574
30.7k
            + opnd->indexed_za.index.countm1)
4575
39.0k
     : ""),
4576
39.0k
    opnd->indexed_za.group_size ? ", " : "",
4577
39.0k
    opnd->indexed_za.group_size == 2
4578
39.0k
    ? style_sub_mnem (styler, "vgx2")
4579
39.0k
    : opnd->indexed_za.group_size == 4
4580
29.5k
    ? style_sub_mnem (styler, "vgx4") : "");
4581
39.0k
      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.98k
    case AARCH64_OPND_SME_PnT_Wm_imm:
4589
2.98k
      snprintf (buf, size, "%s[%s, %s]",
4590
2.98k
    style_reg (styler, "p%d.%s", opnd->indexed_za.regno,
4591
2.98k
         aarch64_get_qualifier_name (opnd->qualifier)),
4592
2.98k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4593
2.98k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm));
4594
2.98k
      break;
4595
4596
29
    case AARCH64_OPND_SME_VLxN_10:
4597
1.25k
    case AARCH64_OPND_SME_VLxN_13:
4598
1.25k
      enum_value = opnd->imm.value;
4599
1.25k
      assert (enum_value < ARRAY_SIZE (aarch64_sme_vlxn_array));
4600
1.25k
      snprintf (buf, size, "%s",
4601
1.25k
    style_sub_mnem (styler, aarch64_sme_vlxn_array[enum_value]));
4602
1.25k
      break;
4603
4604
44
    case AARCH64_OPND_BRBOP:
4605
44
      enum_value = opnd->imm.value;
4606
44
      assert (enum_value < ARRAY_SIZE (aarch64_brbop_array));
4607
44
      snprintf (buf, size, "%s",
4608
44
    style_sub_mnem (styler, aarch64_brbop_array[enum_value]));
4609
44
      break;
4610
4611
3.49k
    case AARCH64_OPND_CRn:
4612
6.98k
    case AARCH64_OPND_CRm:
4613
6.98k
      snprintf (buf, size, "%s",
4614
6.98k
    style_reg (styler, "C%" PRIi64, opnd->imm.value));
4615
6.98k
      break;
4616
4617
6.73k
    case AARCH64_OPND_IDX:
4618
7.13k
    case AARCH64_OPND_MASK:
4619
35.9k
    case AARCH64_OPND_IMM:
4620
54.7k
    case AARCH64_OPND_IMM_2:
4621
79.4k
    case AARCH64_OPND_WIDTH:
4622
82.9k
    case AARCH64_OPND_UIMM3_OP1:
4623
86.4k
    case AARCH64_OPND_UIMM3_OP2:
4624
210k
    case AARCH64_OPND_BIT_NUM:
4625
216k
    case AARCH64_OPND_IMM_VLSL:
4626
226k
    case AARCH64_OPND_IMM_VLSR:
4627
226k
    case AARCH64_OPND_SHLL_IMM:
4628
226k
    case AARCH64_OPND_IMM0:
4629
226k
    case AARCH64_OPND_IMMR:
4630
228k
    case AARCH64_OPND_IMMS:
4631
1.57M
    case AARCH64_OPND_UNDEFINED:
4632
1.57M
    case AARCH64_OPND_FBITS:
4633
1.57M
    case AARCH64_OPND_TME_UIMM16:
4634
1.58M
    case AARCH64_OPND_SIMM5:
4635
1.58M
    case AARCH64_OPND_SME_SHRIMM3:
4636
1.58M
    case AARCH64_OPND_SME_SHRIMM4:
4637
1.58M
    case AARCH64_OPND_SME_SHRIMM5:
4638
1.58M
    case AARCH64_OPND_SVE_SHLIMM_PRED:
4639
1.59M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED:
4640
1.59M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
4641
1.59M
    case AARCH64_OPND_SVE_SHRIMM_PRED:
4642
1.59M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED:
4643
1.59M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
4644
1.59M
    case AARCH64_OPND_SVE_SIMM5:
4645
1.59M
    case AARCH64_OPND_SVE_SIMM5B:
4646
1.59M
    case AARCH64_OPND_SVE_SIMM6:
4647
1.59M
    case AARCH64_OPND_SVE_SIMM8:
4648
1.59M
    case AARCH64_OPND_SVE_UIMM3:
4649
1.62M
    case AARCH64_OPND_SVE_UIMM7:
4650
1.62M
    case AARCH64_OPND_SVE_UIMM8:
4651
1.62M
    case AARCH64_OPND_SVE_UIMM4:
4652
1.62M
    case AARCH64_OPND_SVE_UIMM8_53:
4653
1.62M
    case AARCH64_OPND_IMM_ROT1:
4654
1.63M
    case AARCH64_OPND_IMM_ROT2:
4655
1.63M
    case AARCH64_OPND_IMM_ROT3:
4656
1.63M
    case AARCH64_OPND_SVE_IMM_ROT1:
4657
1.64M
    case AARCH64_OPND_SVE_IMM_ROT2:
4658
1.64M
    case AARCH64_OPND_SVE_IMM_ROT3:
4659
1.64M
    case AARCH64_OPND_CSSC_SIMM8:
4660
1.64M
    case AARCH64_OPND_CSSC_UIMM8:
4661
1.64M
      snprintf (buf, size, "%s",
4662
1.64M
    style_imm (styler, "#%" PRIi64, opnd->imm.value));
4663
1.64M
      break;
4664
4665
55
    case AARCH64_OPND_SVE_I1_HALF_ONE:
4666
270
    case AARCH64_OPND_SVE_I1_HALF_TWO:
4667
1.63k
    case AARCH64_OPND_SVE_I1_ZERO_ONE:
4668
1.63k
      {
4669
1.63k
  single_conv_t c;
4670
1.63k
  c.i = opnd->imm.value;
4671
1.63k
  snprintf (buf, size, "%s", style_imm (styler, "#%.1f", c.f));
4672
1.63k
  break;
4673
270
      }
4674
4675
157
    case AARCH64_OPND_SVE_PATTERN:
4676
157
      if (optional_operand_p (opcode, idx)
4677
157
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4678
108
  break;
4679
49
      enum_value = opnd->imm.value;
4680
49
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4681
49
      if (aarch64_sve_pattern_array[enum_value])
4682
5
  snprintf (buf, size, "%s",
4683
5
      style_reg (styler, aarch64_sve_pattern_array[enum_value]));
4684
44
      else
4685
44
  snprintf (buf, size, "%s",
4686
44
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4687
49
      break;
4688
4689
5.06k
    case AARCH64_OPND_SVE_PATTERN_SCALED:
4690
5.06k
      if (optional_operand_p (opcode, idx)
4691
5.06k
    && !opnd->shifter.operator_present
4692
949
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4693
327
  break;
4694
4.73k
      enum_value = opnd->imm.value;
4695
4.73k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4696
4.73k
      if (aarch64_sve_pattern_array[opnd->imm.value])
4697
3.41k
  snprintf (buf, size, "%s",
4698
3.41k
      style_reg (styler,
4699
3.41k
           aarch64_sve_pattern_array[opnd->imm.value]));
4700
1.32k
      else
4701
1.32k
  snprintf (buf, size, "%s",
4702
1.32k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4703
4.73k
      if (opnd->shifter.operator_present)
4704
4.11k
  {
4705
4.11k
    size_t len = strlen (buf);
4706
4.11k
    const char *shift_name
4707
4.11k
      = aarch64_operand_modifiers[opnd->shifter.kind].name;
4708
4.11k
    snprintf (buf + len, size - len, ", %s %s",
4709
4.11k
        style_sub_mnem (styler, shift_name),
4710
4.11k
        style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4711
4.11k
  }
4712
4.73k
      break;
4713
4714
15.4k
    case AARCH64_OPND_SVE_PRFOP:
4715
15.4k
      enum_value = opnd->imm.value;
4716
15.4k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_prfop_array));
4717
15.4k
      if (aarch64_sve_prfop_array[enum_value])
4718
10.0k
  snprintf (buf, size, "%s",
4719
10.0k
      style_reg (styler, aarch64_sve_prfop_array[enum_value]));
4720
5.39k
      else
4721
5.39k
  snprintf (buf, size, "%s",
4722
5.39k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4723
15.4k
      break;
4724
4725
45.2k
    case AARCH64_OPND_IMM_MOV:
4726
45.2k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4727
45.2k
  {
4728
7.71k
  case 4: /* e.g. MOV Wd, #<imm32>.  */
4729
7.71k
      {
4730
7.71k
        int imm32 = opnd->imm.value;
4731
7.71k
        snprintf (buf, size, "%s",
4732
7.71k
      style_imm (styler, "#0x%-20x", imm32));
4733
7.71k
        snprintf (comment, comment_size, "#%d", imm32);
4734
7.71k
      }
4735
7.71k
    break;
4736
37.5k
  case 8: /* e.g. MOV Xd, #<imm64>.  */
4737
37.5k
    snprintf (buf, size, "%s", style_imm (styler, "#0x%-20" PRIx64,
4738
37.5k
            opnd->imm.value));
4739
37.5k
    snprintf (comment, comment_size, "#%" PRIi64, opnd->imm.value);
4740
37.5k
    break;
4741
0
  default:
4742
0
    snprintf (buf, size, "<invalid>");
4743
0
    break;
4744
45.2k
  }
4745
45.2k
      break;
4746
4747
45.2k
    case AARCH64_OPND_FPIMM0:
4748
378
      snprintf (buf, size, "%s", style_imm (styler, "#0.0"));
4749
378
      break;
4750
4751
121k
    case AARCH64_OPND_LIMM:
4752
284k
    case AARCH64_OPND_AIMM:
4753
305k
    case AARCH64_OPND_HALF:
4754
305k
    case AARCH64_OPND_SVE_INV_LIMM:
4755
318k
    case AARCH64_OPND_SVE_LIMM:
4756
321k
    case AARCH64_OPND_SVE_LIMM_MOV:
4757
321k
      if (opnd->shifter.amount)
4758
75.1k
  snprintf (buf, size, "%s, %s %s",
4759
75.1k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4760
75.1k
      style_sub_mnem (styler, "lsl"),
4761
75.1k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4762
245k
      else
4763
245k
  snprintf (buf, size, "%s",
4764
245k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4765
321k
      break;
4766
4767
724
    case AARCH64_OPND_SIMD_IMM:
4768
3.41k
    case AARCH64_OPND_SIMD_IMM_SFT:
4769
3.41k
      if ((! opnd->shifter.amount && opnd->shifter.kind == AARCH64_MOD_LSL)
4770
2.46k
    || opnd->shifter.kind == AARCH64_MOD_NONE)
4771
1.67k
  snprintf (buf, size, "%s",
4772
1.67k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4773
1.74k
      else
4774
1.74k
  snprintf (buf, size, "%s, %s %s",
4775
1.74k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4776
1.74k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4777
1.74k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4778
3.41k
      break;
4779
4780
1.13k
    case AARCH64_OPND_SVE_AIMM:
4781
6.75k
    case AARCH64_OPND_SVE_ASIMM:
4782
6.75k
      if (opnd->shifter.amount)
4783
176
  snprintf (buf, size, "%s, %s %s",
4784
176
      style_imm (styler, "#%" PRIi64, opnd->imm.value),
4785
176
      style_sub_mnem (styler, "lsl"),
4786
176
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4787
6.58k
      else
4788
6.58k
  snprintf (buf, size, "%s",
4789
6.58k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4790
6.75k
      break;
4791
4792
131
    case AARCH64_OPND_FPIMM:
4793
2.12k
    case AARCH64_OPND_SIMD_FPIMM:
4794
2.88k
    case AARCH64_OPND_SVE_FPIMM8:
4795
2.88k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4796
2.88k
  {
4797
1.79k
  case 2: /* e.g. FMOV <Hd>, #<imm>.  */
4798
1.79k
      {
4799
1.79k
        half_conv_t c;
4800
1.79k
        c.i = expand_fp_imm (2, opnd->imm.value);
4801
1.79k
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4802
1.79k
      }
4803
1.79k
    break;
4804
522
  case 4: /* e.g. FMOV <Vd>.4S, #<imm>.  */
4805
522
      {
4806
522
        single_conv_t c;
4807
522
        c.i = expand_fp_imm (4, opnd->imm.value);
4808
522
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4809
522
      }
4810
522
    break;
4811
571
  case 8: /* e.g. FMOV <Sd>, #<imm>.  */
4812
571
      {
4813
571
        double_conv_t c;
4814
571
        c.i = expand_fp_imm (8, opnd->imm.value);
4815
571
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.d));
4816
571
      }
4817
571
    break;
4818
0
  default:
4819
0
    snprintf (buf, size, "<invalid>");
4820
0
    break;
4821
2.88k
  }
4822
2.88k
      break;
4823
4824
2.88k
    case AARCH64_OPND_CCMP_IMM:
4825
7.18k
    case AARCH64_OPND_NZCV:
4826
8.00k
    case AARCH64_OPND_EXCEPTION:
4827
8.10k
    case AARCH64_OPND_UIMM4:
4828
10.8k
    case AARCH64_OPND_UIMM4_ADDG:
4829
10.9k
    case AARCH64_OPND_UIMM7:
4830
13.6k
    case AARCH64_OPND_UIMM10:
4831
13.6k
      if (optional_operand_p (opcode, idx)
4832
182
    && (opnd->imm.value ==
4833
182
        (int64_t) get_optional_operand_default_value (opcode)))
4834
  /* Omit the operand, e.g. DCPS1.  */
4835
31
  break;
4836
13.6k
      snprintf (buf, size, "%s",
4837
13.6k
    style_imm (styler, "#0x%x", (unsigned int) opnd->imm.value));
4838
13.6k
      break;
4839
4840
13.6k
    case AARCH64_OPND_COND:
4841
13.8k
    case AARCH64_OPND_COND1:
4842
13.8k
      snprintf (buf, size, "%s",
4843
13.8k
    style_sub_mnem (styler, opnd->cond->names[0]));
4844
13.8k
      num_conds = ARRAY_SIZE (opnd->cond->names);
4845
27.4k
      for (i = 1; i < num_conds && opnd->cond->names[i]; ++i)
4846
13.6k
  {
4847
13.6k
    size_t len = comment != NULL ? strlen (comment) : 0;
4848
13.6k
    if (i == 1)
4849
9.80k
      snprintf (comment + len, comment_size - len, "%s = %s",
4850
9.80k
          opnd->cond->names[0], opnd->cond->names[i]);
4851
3.84k
    else
4852
3.84k
      snprintf (comment + len, comment_size - len, ", %s",
4853
3.84k
          opnd->cond->names[i]);
4854
13.6k
  }
4855
13.8k
      break;
4856
4857
113k
    case AARCH64_OPND_ADDR_ADRP:
4858
113k
      addr = ((pc + AARCH64_PCREL_OFFSET) & ~(uint64_t)0xfff)
4859
113k
  + opnd->imm.value;
4860
113k
      if (pcrel_p)
4861
113k
  *pcrel_p = 1;
4862
113k
      if (address)
4863
113k
  *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
113k
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64 , addr));
4869
113k
      break;
4870
4871
54.4k
    case AARCH64_OPND_ADDR_PCREL9:
4872
178k
    case AARCH64_OPND_ADDR_PCREL14:
4873
506k
    case AARCH64_OPND_ADDR_PCREL19:
4874
759k
    case AARCH64_OPND_ADDR_PCREL21:
4875
949k
    case AARCH64_OPND_ADDR_PCREL26:
4876
949k
      addr = pc + AARCH64_PCREL_OFFSET + opnd->imm.value;
4877
949k
      if (pcrel_p)
4878
949k
  *pcrel_p = 1;
4879
949k
      if (address)
4880
949k
  *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
949k
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64, addr));
4886
949k
      break;
4887
4888
158k
    case AARCH64_OPND_ADDR_SIMPLE:
4889
171k
    case AARCH64_OPND_SIMD_ADDR_SIMPLE:
4890
186k
    case AARCH64_OPND_SIMD_ADDR_POST:
4891
186k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4892
186k
      if (opnd->type == AARCH64_OPND_SIMD_ADDR_POST)
4893
14.5k
  {
4894
14.5k
    if (opnd->addr.offset.is_reg)
4895
11.8k
      snprintf (buf, size, "[%s], %s",
4896
11.8k
          style_reg (styler, name),
4897
11.8k
          style_reg (styler, "x%d", opnd->addr.offset.regno));
4898
2.71k
    else
4899
2.71k
      snprintf (buf, size, "[%s], %s",
4900
2.71k
          style_reg (styler, name),
4901
2.71k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
4902
14.5k
  }
4903
171k
      else
4904
171k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4905
186k
      break;
4906
4907
20.8k
    case AARCH64_OPND_ADDR_REGOFF:
4908
30.6k
    case AARCH64_OPND_SVE_ADDR_RR:
4909
37.2k
    case AARCH64_OPND_SVE_ADDR_RR_LSL1:
4910
40.6k
    case AARCH64_OPND_SVE_ADDR_RR_LSL2:
4911
54.6k
    case AARCH64_OPND_SVE_ADDR_RR_LSL3:
4912
67.2k
    case AARCH64_OPND_SVE_ADDR_RR_LSL4:
4913
73.9k
    case AARCH64_OPND_SVE_ADDR_RM:
4914
77.2k
    case AARCH64_OPND_SVE_ADDR_RM_LSL1:
4915
80.1k
    case AARCH64_OPND_SVE_ADDR_RM_LSL2:
4916
83.4k
    case AARCH64_OPND_SVE_ADDR_RM_LSL3:
4917
83.4k
    case AARCH64_OPND_SVE_ADDR_RM_LSL4:
4918
94.9k
    case AARCH64_OPND_SVE_ADDR_RX:
4919
102k
    case AARCH64_OPND_SVE_ADDR_RX_LSL1:
4920
110k
    case AARCH64_OPND_SVE_ADDR_RX_LSL2:
4921
114k
    case AARCH64_OPND_SVE_ADDR_RX_LSL3:
4922
117k
    case AARCH64_OPND_SVE_ADDR_RX_LSL4:
4923
117k
      print_register_offset_address
4924
117k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4925
117k
   get_offset_int_reg_name (opnd), styler);
4926
117k
      break;
4927
4928
10.4k
    case AARCH64_OPND_SVE_ADDR_ZX:
4929
10.4k
      print_register_offset_address
4930
10.4k
  (buf, size, opnd,
4931
10.4k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4932
10.4k
   get_64bit_int_reg_name (opnd->addr.offset.regno, 0), styler);
4933
10.4k
      break;
4934
4935
19.6k
    case AARCH64_OPND_SVE_ADDR_RZ:
4936
21.8k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
4937
23.4k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
4938
25.4k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
4939
29.8k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
4940
58.2k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
4941
59.5k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
4942
65.1k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
4943
66.1k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
4944
71.0k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
4945
71.4k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
4946
76.9k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
4947
76.9k
      print_register_offset_address
4948
76.9k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4949
76.9k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4950
76.9k
   styler);
4951
76.9k
      break;
4952
4953
406k
    case AARCH64_OPND_ADDR_SIMM7:
4954
490k
    case AARCH64_OPND_ADDR_SIMM9:
4955
490k
    case AARCH64_OPND_ADDR_SIMM9_2:
4956
499k
    case AARCH64_OPND_ADDR_SIMM10:
4957
517k
    case AARCH64_OPND_ADDR_SIMM11:
4958
522k
    case AARCH64_OPND_ADDR_SIMM13:
4959
528k
    case AARCH64_OPND_RCPC3_ADDR_OFFSET:
4960
547k
    case AARCH64_OPND_ADDR_OFFSET:
4961
548k
    case AARCH64_OPND_RCPC3_ADDR_OPT_POSTIND:
4962
563k
    case AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB:
4963
563k
    case AARCH64_OPND_RCPC3_ADDR_POSTIND:
4964
563k
    case AARCH64_OPND_RCPC3_ADDR_PREIND_WB:
4965
564k
    case AARCH64_OPND_SME_ADDR_RI_U4xVL:
4966
565k
    case AARCH64_OPND_SVE_ADDR_RI_S4x16:
4967
567k
    case AARCH64_OPND_SVE_ADDR_RI_S4x32:
4968
617k
    case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
4969
627k
    case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
4970
629k
    case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
4971
636k
    case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
4972
638k
    case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
4973
642k
    case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
4974
645k
    case AARCH64_OPND_SVE_ADDR_RI_U6:
4975
650k
    case AARCH64_OPND_SVE_ADDR_RI_U6x2:
4976
651k
    case AARCH64_OPND_SVE_ADDR_RI_U6x4:
4977
652k
    case AARCH64_OPND_SVE_ADDR_RI_U6x8:
4978
652k
      print_immediate_offset_address
4979
652k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4980
652k
   styler);
4981
652k
      break;
4982
4983
3.69k
    case AARCH64_OPND_SVE_ADDR_ZI_U5:
4984
8.86k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
4985
11.0k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
4986
12.1k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
4987
12.1k
      print_immediate_offset_address
4988
12.1k
  (buf, size, opnd,
4989
12.1k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4990
12.1k
   styler);
4991
12.1k
      break;
4992
4993
957
    case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
4994
1.09k
    case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
4995
2.10k
    case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
4996
2.10k
      print_register_offset_address
4997
2.10k
  (buf, size, opnd,
4998
2.10k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4999
2.10k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
5000
2.10k
   styler);
5001
2.10k
      break;
5002
5003
180k
    case AARCH64_OPND_ADDR_UIMM12:
5004
180k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
5005
180k
      if (opnd->addr.offset.imm)
5006
171k
  snprintf (buf, size, "[%s, %s]",
5007
171k
      style_reg (styler, name),
5008
171k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
5009
9.20k
      else
5010
9.20k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
5011
180k
      break;
5012
5013
8.04k
    case AARCH64_OPND_SYSREG:
5014
9.00k
    case AARCH64_OPND_SYSREG128:
5015
9.00k
      {
5016
9.00k
  int min_mismatch = 999;
5017
9.00k
  int best_index = -1;
5018
9.00k
  uint32_t op_flags = opnd->sysreg.flags;
5019
14.3M
  for (i = 0; aarch64_sys_regs[i].name; ++i)
5020
14.3M
    {
5021
14.3M
      const aarch64_sys_reg *sr = aarch64_sys_regs + i;
5022
5023
14.3M
      if (!(aarch64_sys_regs[i].value == opnd->sysreg.value)
5024
1.50k
    || aarch64_sys_reg_deprecated_p (aarch64_sys_regs[i].flags)
5025
1.50k
    || aarch64_sys_reg_alias_p (aarch64_sys_regs[i].flags))
5026
14.3M
        continue;
5027
5028
1.50k
      int mismatch_score = 0;
5029
1.50k
      if (!AARCH64_CPU_HAS_ALL_FEATURES (features, sr->features))
5030
989
        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.50k
      if (((sr->flags & F_REG_READ) && (op_flags & F_REG_WRITE))
5034
1.36k
    || ((sr->flags & F_REG_WRITE) && (op_flags & F_REG_READ)))
5035
173
        mismatch_score += 2;
5036
5037
1.50k
      if (mismatch_score < min_mismatch)
5038
1.50k
        {
5039
1.50k
    min_mismatch = mismatch_score;
5040
1.50k
    best_index = i;
5041
1.50k
    if (mismatch_score == 0)
5042
346
      break;
5043
1.50k
        }
5044
1.50k
    }
5045
9.00k
  if (best_index == -1)
5046
7.51k
    {
5047
      /* Use encoding-based name for unrecognised system register.  */
5048
7.51k
      unsigned int value = opnd->sysreg.value;
5049
7.51k
      snprintf (buf, size, "%s",
5050
7.51k
          style_reg (styler, "s%u_%u_c%u_c%u_%u",
5051
7.51k
         (value >> 14) & 0x3, (value >> 11) & 0x7,
5052
7.51k
         (value >> 7) & 0xf, (value >> 3) & 0xf,
5053
7.51k
         value & 0x7));
5054
7.51k
    }
5055
1.48k
  else
5056
1.48k
    {
5057
1.48k
      const aarch64_sys_reg *sr = aarch64_sys_regs + best_index;
5058
1.48k
      snprintf (buf, size, "%s", style_reg (styler, sr->name));
5059
5060
      /* Add a note if we violated read/write constraints.  */
5061
1.48k
      if (notes && min_mismatch)
5062
1.14k
        {
5063
1.14k
    if ((sr->flags & F_REG_READ) && (op_flags & F_REG_WRITE))
5064
124
      *notes = _("writing to a read-only register");
5065
1.01k
    else if ((sr->flags & F_REG_WRITE) && (op_flags & F_REG_READ))
5066
27
      *notes = _("reading from a write-only register");
5067
1.14k
        }
5068
1.48k
    }
5069
9.00k
  break;
5070
8.04k
      }
5071
5072
78
    case AARCH64_OPND_PSTATEFIELD:
5073
312
      for (i = 0; aarch64_pstatefields[i].name; ++i)
5074
312
        if (aarch64_pstatefields[i].value == opnd->pstatefield)
5075
78
          {
5076
            /* PSTATEFIELD name is encoded partially in CRm[3:1] for SVCRSM,
5077
               SVCRZA and SVCRSMZA.  */
5078
78
            uint32_t flags = aarch64_pstatefields[i].flags;
5079
78
            if (flags & F_REG_IN_CRM
5080
0
                && (PSTATE_DECODE_CRM (opnd->sysreg.flags)
5081
0
                    != PSTATE_DECODE_CRM (flags)))
5082
0
              continue;
5083
78
            break;
5084
78
          }
5085
78
      assert (aarch64_pstatefields[i].name);
5086
78
      snprintf (buf, size, "%s",
5087
78
    style_reg (styler, aarch64_pstatefields[i].name));
5088
78
      break;
5089
5090
32
    case AARCH64_OPND_GIC:
5091
32
    case AARCH64_OPND_GICR:
5092
32
    case AARCH64_OPND_GSB:
5093
51
    case AARCH64_OPND_SYSREG_AT:
5094
157
    case AARCH64_OPND_SYSREG_DC:
5095
157
    case AARCH64_OPND_SYSREG_IC:
5096
258
    case AARCH64_OPND_SYSREG_TLBI:
5097
261
    case AARCH64_OPND_SYSREG_TLBIP:
5098
261
    case AARCH64_OPND_SYSREG_PLBI:
5099
261
    case AARCH64_OPND_SYSREG_MLBI:
5100
261
    case AARCH64_OPND_SYSREG_SR:
5101
261
      snprintf (buf, size, "%s", style_reg (styler, opnd->sysins_op->name));
5102
261
      break;
5103
5104
52
    case AARCH64_OPND_BARRIER:
5105
87
    case AARCH64_OPND_BARRIER_DSB_NXS:
5106
87
      {
5107
87
  if (opnd->barrier->name[0] == '#')
5108
49
    snprintf (buf, size, "%s", style_imm (styler, opnd->barrier->name));
5109
38
  else
5110
38
    snprintf (buf, size, "%s",
5111
38
        style_sub_mnem (styler, opnd->barrier->name));
5112
87
      }
5113
87
      break;
5114
5115
119
    case AARCH64_OPND_BARRIER_ISB:
5116
      /* Operand can be omitted, e.g. in DCPS1.  */
5117
119
      if (! optional_operand_p (opcode, idx)
5118
119
    || (opnd->barrier->value
5119
119
        != get_optional_operand_default_value (opcode)))
5120
15
  snprintf (buf, size, "%s",
5121
15
      style_imm (styler, "#0x%x", opnd->barrier->value));
5122
119
      break;
5123
5124
30.9k
    case AARCH64_OPND_PRFOP:
5125
30.9k
      if ((opnd->prfop->name == NULL)
5126
25.7k
          || (opcode->iclass != ldst_pos && opnd->prfop->value == 0x18))
5127
13.3k
        snprintf (buf, size, "%s",
5128
13.3k
                  style_imm (styler, "#0x%02x", opnd->prfop->value));
5129
17.5k
      else
5130
17.5k
        snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->prfop->name));
5131
30.9k
      break;
5132
5133
896
    case AARCH64_OPND_RPRFMOP:
5134
896
      enum_value = opnd->imm.value;
5135
896
      if (enum_value < ARRAY_SIZE (aarch64_rprfmop_array)
5136
896
    && aarch64_rprfmop_array[enum_value])
5137
116
  snprintf (buf, size, "%s",
5138
116
      style_reg (styler, aarch64_rprfmop_array[enum_value]));
5139
780
      else
5140
780
  snprintf (buf, size, "%s",
5141
780
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
5142
896
      break;
5143
5144
87
    case AARCH64_OPND_BARRIER_PSB:
5145
87
      snprintf (buf, size, "%s", style_sub_mnem (styler, "csync"));
5146
87
      break;
5147
5148
0
    case AARCH64_OPND_X16:
5149
0
      snprintf (buf, size, "%s", style_reg (styler, "x16"));
5150
0
      break;
5151
5152
1.62k
    case AARCH64_OPND_SME_ZT0:
5153
1.62k
      snprintf (buf, size, "%s", style_reg (styler, "zt0"));
5154
1.62k
      break;
5155
5156
90
    case AARCH64_OPND_SME_ZT0_INDEX:
5157
90
      snprintf (buf, size, "%s[%s]", style_reg (styler, "zt0"),
5158
90
    style_imm (styler, "%d", (int) opnd->imm.value));
5159
90
      break;
5160
102
    case AARCH64_OPND_SME_ZT0_INDEX_MUL_VL:
5161
102
      snprintf (buf, size, "%s[%s, %s]", style_reg (styler, "zt0"),
5162
102
    style_imm (styler, "%d", (int) opnd->imm.value),
5163
102
    style_sub_mnem (styler, "mul vl"));
5164
102
      break;
5165
5166
23
    case AARCH64_OPND_SME_ZT0_LIST:
5167
23
      snprintf (buf, size, "{%s}", style_reg (styler, "zt0"));
5168
23
      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
214
    case AARCH64_OPND_NOT_BALANCED_17:
5176
214
      if (opnd->imm.value)
5177
52
  snprintf (buf, size, "%s", style_sub_mnem (styler, "nb"));
5178
214
      break;
5179
5180
177
    case AARCH64_OPND_BTI_TARGET:
5181
177
      snprintf (buf, size, "%s",
5182
177
    style_sub_mnem (styler, opnd->hint_option->name));
5183
177
      break;
5184
5185
13
    case AARCH64_OPND_STSHH_POLICY:
5186
13
      snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->hint_option->name));
5187
13
      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
7.18k
    case AARCH64_OPND_MOPS_ADDR_Rd:
5196
13.1k
    case AARCH64_OPND_MOPS_ADDR_Rs:
5197
13.1k
      snprintf (buf, size, "[%s]!",
5198
13.1k
    style_reg (styler,
5199
13.1k
         get_int_reg_name (opnd->reg.regno,
5200
13.1k
               AARCH64_OPND_QLF_X, 0)));
5201
13.1k
      break;
5202
5203
7.18k
    case AARCH64_OPND_MOPS_WB_Rn:
5204
7.18k
      snprintf (buf, size, "%s!",
5205
7.18k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
5206
7.18k
                 AARCH64_OPND_QLF_X, 0)));
5207
7.18k
      break;
5208
5209
0
    default:
5210
0
      snprintf (buf, size, "<invalid>");
5211
0
      break;
5212
11.4M
    }
5213
11.4M
}
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.50k
{
5256
1.50k
  return (reg_flags & F_DEPRECATED) != 0;
5257
1.50k
}
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.50k
{
5268
1.50k
  return (reg_flags & F_REG_ALIAS) != 0;
5269
1.50k
}
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
554
{
5632
554
  return (sys_ins_reg->flags & F_HASXT) != 0;
5633
554
}
5634
5635
bool
5636
aarch64_sys_ins_reg_tlbid_xt (const aarch64_sys_ins_reg *sys_ins_reg)
5637
453
{
5638
453
  return (sys_ins_reg->flags & F_TLBID_XT) != 0;
5639
453
}
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
74.1k
#define BIT(INSN,BT)     (((INSN) >> (BT)) & 1)
5675
112k
#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
37.4k
{
5684
37.4k
  int t  = BITS (insn, 4, 0);
5685
37.4k
  int n  = BITS (insn, 9, 5);
5686
37.4k
  int t2 = BITS (insn, 14, 10);
5687
5688
37.4k
  if (BIT (insn, 23))
5689
10.9k
    {
5690
      /* Write back enabled.  */
5691
10.9k
      if ((t == n || t2 == n) && n != 31)
5692
826
  return ERR_UND;
5693
10.9k
    }
5694
5695
36.6k
  if (BIT (insn, 22))
5696
36.6k
    {
5697
      /* Load */
5698
36.6k
      if (t == t2)
5699
4.50k
  return ERR_UND;
5700
36.6k
    }
5701
5702
32.1k
  return ERR_OK;
5703
36.6k
}
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.35k
{
5714
2.35k
  const aarch64_insn undef_pattern = 0x3;
5715
2.35k
  aarch64_insn value;
5716
5717
2.35k
  assert (inst->opcode);
5718
2.35k
  assert (inst->opcode->operands[2] == AARCH64_OPND_Em);
5719
2.35k
  value = encoding ? inst->value : insn;
5720
2.35k
  assert (value);
5721
5722
2.35k
  if (undef_pattern == extract_fields (value, 0, 2, FLD_sz, FLD_L))
5723
710
    return ERR_UND;
5724
5725
1.64k
  return ERR_OK;
5726
2.35k
}
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.95k
{
5741
7.95k
  int rd, rs, rn;
5742
5743
7.95k
  rd = inst->operands[0].reg.regno;
5744
7.95k
  rs = inst->operands[1].reg.regno;
5745
7.95k
  rn = inst->operands[2].reg.regno;
5746
7.95k
  if (rd == rs || rd == rn || rs == rn)
5747
873
    {
5748
873
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5749
873
      mismatch_detail->error
5750
873
  = _("the three register operands must be distinct from one another");
5751
873
      mismatch_detail->index = -1;
5752
873
      return ERR_UND;
5753
873
    }
5754
5755
7.08k
  return ERR_OK;
5756
7.95k
}
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
176
{
5771
176
  int rd, rn;
5772
5773
176
  rd = inst->operands[0].reg.regno;
5774
176
  rn = inst->operands[1].reg.regno;
5775
176
  if (rd == rn)
5776
76
    {
5777
76
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5778
76
      mismatch_detail->error
5779
76
  = _("the two register operands must be distinct from each other");
5780
76
      mismatch_detail->index = -1;
5781
76
      return ERR_UND;
5782
76
    }
5783
5784
100
  return ERR_OK;
5785
176
}
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
7.53k
{
5793
7.53k
  insn_sequence->instr[insn_sequence->num_added_insns++] = *inst;
5794
7.53k
}
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
15.5k
{
5804
15.5k
  int num_req_entries = 0;
5805
5806
15.5k
  if (insn_sequence->instr)
5807
7.34k
    {
5808
7.34k
      XDELETE (insn_sequence->instr);
5809
7.34k
      insn_sequence->instr = NULL;
5810
7.34k
    }
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
15.5k
  if (inst && inst->opcode->constraints & C_SCAN_MOVPRFX)
5816
3.00k
    num_req_entries = 1;
5817
15.5k
  if (inst && (inst->opcode->constraints & C_SCAN_MOPS_PME) == C_SCAN_MOPS_P)
5818
4.34k
    num_req_entries = 2;
5819
5820
15.5k
  insn_sequence->num_added_insns = 0;
5821
15.5k
  insn_sequence->num_allocated_insns = num_req_entries;
5822
5823
15.5k
  if (num_req_entries != 0)
5824
7.34k
    {
5825
7.34k
      insn_sequence->instr = XCNEWVEC (aarch64_inst, num_req_entries);
5826
7.34k
      add_insn_to_sequence (inst, insn_sequence);
5827
7.34k
    }
5828
15.5k
}
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
183k
{
5844
183k
  const struct aarch64_opcode *opcode;
5845
183k
  const struct aarch64_inst *prev_insn;
5846
183k
  int i;
5847
5848
183k
  opcode = inst->opcode;
5849
183k
  if (insn_sequence->instr)
5850
7.02k
    prev_insn = insn_sequence->instr + (insn_sequence->num_added_insns - 1);
5851
176k
  else
5852
176k
    prev_insn = NULL;
5853
5854
183k
  if (prev_insn
5855
7.02k
      && (prev_insn->opcode->constraints & C_SCAN_MOPS_PME)
5856
4.07k
      && prev_insn->opcode != opcode - 1)
5857
3.89k
    {
5858
3.89k
      mismatch_detail->kind = AARCH64_OPDE_EXPECTED_A_AFTER_B;
5859
3.89k
      mismatch_detail->error = NULL;
5860
3.89k
      mismatch_detail->index = -1;
5861
3.89k
      mismatch_detail->data[0].s = prev_insn->opcode[1].name;
5862
3.89k
      mismatch_detail->data[1].s = prev_insn->opcode->name;
5863
3.89k
      mismatch_detail->non_fatal = true;
5864
3.89k
      return false;
5865
3.89k
    }
5866
5867
179k
  if (opcode->constraints & C_SCAN_MOPS_PME)
5868
2.82k
    {
5869
2.82k
      if (is_new_section || !prev_insn || prev_insn->opcode != opcode - 1)
5870
2.64k
  {
5871
2.64k
    mismatch_detail->kind = AARCH64_OPDE_A_SHOULD_FOLLOW_B;
5872
2.64k
    mismatch_detail->error = NULL;
5873
2.64k
    mismatch_detail->index = -1;
5874
2.64k
    mismatch_detail->data[0].s = opcode->name;
5875
2.64k
    mismatch_detail->data[1].s = opcode[-1].name;
5876
2.64k
    mismatch_detail->non_fatal = true;
5877
2.64k
    return false;
5878
2.64k
  }
5879
5880
438
      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
371
  if ((opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd
5884
192
       || opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs
5885
91
       || opcode->operands[i] == AARCH64_OPND_MOPS_WB_Rn)
5886
371
      && prev_insn->operands[i].reg.regno != inst->operands[i].reg.regno)
5887
112
    {
5888
112
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5889
112
      if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd)
5890
78
        mismatch_detail->error = _("destination register differs from "
5891
34
           "preceding instruction");
5892
34
      else if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs)
5893
10
        mismatch_detail->error = _("source register differs from "
5894
24
           "preceding instruction");
5895
24
      else
5896
24
        mismatch_detail->error = _("size register differs from "
5897
112
           "preceding instruction");
5898
112
      mismatch_detail->index = i;
5899
112
      mismatch_detail->non_fatal = true;
5900
112
      return false;
5901
112
    }
5902
179
    }
5903
5904
176k
  return true;
5905
179k
}
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
5.13M
{
5927
5.13M
  assert (inst);
5928
5.13M
  assert (inst->opcode);
5929
5930
5.13M
  const struct aarch64_opcode *opcode = inst->opcode;
5931
5.13M
  if (!opcode->constraints && !insn_sequence->instr)
5932
4.94M
    return ERR_OK;
5933
5934
5.13M
  assert (insn_sequence);
5935
5936
190k
  enum err_type res = ERR_OK;
5937
5938
  /* This instruction puts a constraint on the insn_sequence.  */
5939
190k
  if (opcode->flags & F_SCAN)
5940
7.34k
    {
5941
7.34k
      if (insn_sequence->instr)
5942
504
  {
5943
504
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5944
504
    mismatch_detail->error = _("instruction opens new dependency "
5945
504
             "sequence without ending previous one");
5946
504
    mismatch_detail->index = -1;
5947
504
    mismatch_detail->non_fatal = true;
5948
504
    res = ERR_VFI;
5949
504
  }
5950
5951
7.34k
      init_insn_sequence (inst, insn_sequence);
5952
7.34k
      return res;
5953
7.34k
    }
5954
5955
190k
  bool is_new_section = (!encoding && pc == 0);
5956
183k
  if (!verify_mops_pme_sequence (inst, is_new_section, mismatch_detail,
5957
183k
         insn_sequence))
5958
6.65k
    {
5959
6.65k
      res = ERR_VFI;
5960
6.65k
      if ((opcode->constraints & C_SCAN_MOPS_PME) != C_SCAN_MOPS_M)
5961
5.19k
  init_insn_sequence (NULL, insn_sequence);
5962
6.65k
    }
5963
5964
  /* Verify constraints on an existing sequence.  */
5965
183k
  if (insn_sequence->instr)
5966
3.13k
    {
5967
3.13k
      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
3.13k
      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
3.13k
      if (inst_opcode->constraints & C_SCAN_MOVPRFX)
5984
2.95k
  {
5985
    /* Check to see if the MOVPRFX SVE instruction is followed by an SVE
5986
       instruction for better error messages.  */
5987
2.95k
    bool sve_operand_p = false;
5988
10.3k
    for (int i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
5989
9.28k
      {
5990
9.28k
        enum aarch64_operand_class op_class
5991
9.28k
    = aarch64_get_operand_class (opcode->operands[i]);
5992
9.28k
        if (op_class == AARCH64_OPND_CLASS_SVE_REG
5993
8.06k
      || op_class == AARCH64_OPND_CLASS_SVE_REGLIST
5994
7.53k
      || op_class == AARCH64_OPND_CLASS_PRED_REG)
5995
1.90k
    {
5996
1.90k
      sve_operand_p = true;
5997
1.90k
      break;
5998
1.90k
    }
5999
9.28k
      }
6000
6001
2.95k
    if (!sve_operand_p)
6002
1.04k
      {
6003
1.04k
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6004
1.04k
        mismatch_detail->error = _("SVE instruction expected after "
6005
1.04k
           "`movprfx'");
6006
1.04k
        mismatch_detail->index = -1;
6007
1.04k
        mismatch_detail->non_fatal = true;
6008
1.04k
        res = ERR_VFI;
6009
1.04k
        goto done;
6010
1.04k
      }
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.90k
    if (!(opcode->constraints & C_SCAN_MOVPRFX))
6015
821
      {
6016
821
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6017
821
        mismatch_detail->error = _("SVE `movprfx' compatible instruction "
6018
821
           "expected");
6019
821
        mismatch_detail->index = -1;
6020
821
        mismatch_detail->non_fatal = true;
6021
821
        res = ERR_VFI;
6022
821
        goto done;
6023
821
      }
6024
6025
    /* Next check for usage of the predicate register.  */
6026
1.08k
    aarch64_opnd_info blk_dest = insn_sequence->instr->operands[0];
6027
1.08k
    aarch64_opnd_info blk_pred, inst_pred;
6028
1.08k
    memset (&blk_pred, 0, sizeof (aarch64_opnd_info));
6029
1.08k
    memset (&inst_pred, 0, sizeof (aarch64_opnd_info));
6030
1.08k
    bool predicated = false;
6031
1.08k
    assert (blk_dest.type == AARCH64_OPND_SVE_Zd);
6032
6033
    /* Determine if the movprfx instruction used is predicated or not.  */
6034
1.08k
    if (insn_sequence->instr->operands[1].type == AARCH64_OPND_SVE_Pg3)
6035
1.01k
      {
6036
1.01k
        predicated = true;
6037
1.01k
        blk_pred = insn_sequence->instr->operands[1];
6038
1.01k
      }
6039
6040
1.08k
    unsigned char max_elem_size = 0;
6041
1.08k
    unsigned char current_elem_size;
6042
1.08k
    int num_op_used = 0, last_op_usage = 0;
6043
1.08k
    int i, inst_pred_idx = -1;
6044
1.08k
    int num_ops = aarch64_num_of_operands (opcode);
6045
4.98k
    for (i = 0; i < num_ops; i++)
6046
3.90k
      {
6047
3.90k
        aarch64_opnd_info inst_op = inst->operands[i];
6048
3.90k
        switch (inst_op.type)
6049
3.90k
    {
6050
1.33k
      case AARCH64_OPND_SVE_Zd:
6051
1.78k
      case AARCH64_OPND_SVE_Zm_5:
6052
2.00k
      case AARCH64_OPND_SVE_Zm_16:
6053
2.47k
      case AARCH64_OPND_SVE_Zn:
6054
2.47k
      case AARCH64_OPND_SVE_Zt:
6055
2.53k
      case AARCH64_OPND_SVE_Vm:
6056
2.55k
      case AARCH64_OPND_SVE_Vn:
6057
2.55k
      case AARCH64_OPND_Va:
6058
2.55k
      case AARCH64_OPND_Vn:
6059
2.55k
      case AARCH64_OPND_Vm:
6060
2.55k
      case AARCH64_OPND_Sn:
6061
2.55k
      case AARCH64_OPND_Sm:
6062
2.55k
        if (inst_op.reg.regno == blk_dest.reg.regno)
6063
746
          {
6064
746
      num_op_used++;
6065
746
      last_op_usage = i;
6066
746
          }
6067
2.55k
        current_elem_size
6068
2.55k
          = aarch64_get_qualifier_esize (inst_op.qualifier);
6069
2.55k
        if (current_elem_size > max_elem_size)
6070
1.08k
          max_elem_size = current_elem_size;
6071
2.55k
        break;
6072
0
      case AARCH64_OPND_SVE_Pd:
6073
809
      case AARCH64_OPND_SVE_Pg3:
6074
809
      case AARCH64_OPND_SVE_Pg4_5:
6075
809
      case AARCH64_OPND_SVE_Pg4_10:
6076
857
      case AARCH64_OPND_SVE_Pg4_16:
6077
857
      case AARCH64_OPND_SVE_Pm:
6078
857
      case AARCH64_OPND_SVE_Pn:
6079
857
      case AARCH64_OPND_SVE_Pt:
6080
857
      case AARCH64_OPND_SME_Pm:
6081
857
        inst_pred = inst_op;
6082
857
        inst_pred_idx = i;
6083
857
        break;
6084
486
      default:
6085
486
        break;
6086
3.90k
    }
6087
3.90k
      }
6088
6089
1.08k
     assert (max_elem_size != 0);
6090
1.08k
     aarch64_opnd_info inst_dest = inst->operands[0];
6091
     /* Determine the size that should be used to compare against the
6092
        movprfx size.  */
6093
1.08k
     current_elem_size
6094
1.08k
       = opcode->constraints & C_MAX_ELEM
6095
1.08k
         ? max_elem_size
6096
1.08k
         : aarch64_get_qualifier_esize (inst_dest.qualifier);
6097
6098
    /* If movprfx is predicated do some extra checks.  */
6099
1.08k
    if (predicated)
6100
1.01k
      {
6101
        /* The instruction must be predicated.  */
6102
1.01k
        if (inst_pred_idx < 0)
6103
229
    {
6104
229
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6105
229
      mismatch_detail->error = _("predicated instruction expected "
6106
229
               "after `movprfx'");
6107
229
      mismatch_detail->index = -1;
6108
229
      mismatch_detail->non_fatal = true;
6109
229
      res = ERR_VFI;
6110
229
      goto done;
6111
229
    }
6112
6113
        /* The instruction must have a merging predicate.  */
6114
787
        if (inst_pred.qualifier != AARCH64_OPND_QLF_P_M)
6115
9
    {
6116
9
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6117
9
      mismatch_detail->error = _("merging predicate expected due "
6118
9
               "to preceding `movprfx'");
6119
9
      mismatch_detail->index = inst_pred_idx;
6120
9
      mismatch_detail->non_fatal = true;
6121
9
      res = ERR_VFI;
6122
9
      goto done;
6123
9
    }
6124
6125
        /* The same register must be used in instruction.  */
6126
778
        if (blk_pred.reg.regno != inst_pred.reg.regno)
6127
384
    {
6128
384
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6129
384
      mismatch_detail->error = _("predicate register differs "
6130
384
               "from that in preceding "
6131
384
               "`movprfx'");
6132
384
      mismatch_detail->index = inst_pred_idx;
6133
384
      mismatch_detail->non_fatal = true;
6134
384
      res = ERR_VFI;
6135
384
      goto done;
6136
384
    }
6137
778
      }
6138
6139
    /* Destructive operations by definition must allow one usage of the
6140
       same register.  */
6141
464
    int allowed_usage
6142
464
      = aarch64_is_destructive_by_operands (opcode) ? 2 : 1;
6143
6144
    /* Operand is not used at all.  */
6145
464
    if (num_op_used == 0)
6146
46
      {
6147
46
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6148
46
        mismatch_detail->error = _("output register of preceding "
6149
46
           "`movprfx' not used in current "
6150
46
           "instruction");
6151
46
        mismatch_detail->index = 0;
6152
46
        mismatch_detail->non_fatal = true;
6153
46
        res = ERR_VFI;
6154
46
        goto done;
6155
46
      }
6156
6157
    /* We now know it's used, now determine exactly where it's used.  */
6158
418
    if (blk_dest.reg.regno != inst_dest.reg.regno)
6159
110
      {
6160
110
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6161
110
        mismatch_detail->error = _("output register of preceding "
6162
110
           "`movprfx' expected as output");
6163
110
        mismatch_detail->index = 0;
6164
110
        mismatch_detail->non_fatal = true;
6165
110
        res = ERR_VFI;
6166
110
        goto done;
6167
110
      }
6168
6169
    /* Operand used more than allowed for the specific opcode type.  */
6170
308
    if (num_op_used > allowed_usage)
6171
118
      {
6172
118
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6173
118
        mismatch_detail->error = _("output register of preceding "
6174
118
           "`movprfx' used as input");
6175
118
        mismatch_detail->index = last_op_usage;
6176
118
        mismatch_detail->non_fatal = true;
6177
118
        res = ERR_VFI;
6178
118
        goto done;
6179
118
      }
6180
6181
    /* Now the only thing left is the qualifiers checks.  The register
6182
       must have the same maximum element size.  */
6183
190
    if (inst_dest.qualifier
6184
190
        && blk_dest.qualifier
6185
125
        && current_elem_size
6186
125
     != aarch64_get_qualifier_esize (blk_dest.qualifier))
6187
40
      {
6188
40
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6189
40
        mismatch_detail->error = _("register size not compatible with "
6190
40
           "previous `movprfx'");
6191
40
        mismatch_detail->index = 0;
6192
40
        mismatch_detail->non_fatal = true;
6193
40
        res = ERR_VFI;
6194
40
        goto done;
6195
40
      }
6196
190
  }
6197
6198
3.13k
    done:
6199
3.13k
      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.95k
  init_insn_sequence (NULL, insn_sequence);
6203
181
      else
6204
181
  add_insn_to_sequence (inst, insn_sequence);
6205
3.13k
    }
6206
6207
183k
  return res;
6208
183k
}
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
6.03k
{
6218
6.03k
  int64_t svalue = uvalue;
6219
6.03k
  uint64_t upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
6220
6221
6.03k
  if ((uvalue & ~upper) != uvalue && (uvalue | upper) != uvalue)
6222
0
    return false;
6223
6.03k
  if (esize <= 4 || (uint32_t) uvalue == (uint32_t) (uvalue >> 32))
6224
5.40k
    {
6225
5.40k
      svalue = (int32_t) uvalue;
6226
5.40k
      if (esize <= 2 || (uint16_t) uvalue == (uint16_t) (uvalue >> 16))
6227
1.29k
  {
6228
1.29k
    svalue = (int16_t) uvalue;
6229
1.29k
    if (esize == 1 || (uint8_t) uvalue == (uint8_t) (uvalue >> 8))
6230
657
      return false;
6231
1.29k
  }
6232
5.40k
    }
6233
5.38k
  if ((svalue & 0xff) == 0)
6234
2.12k
    svalue /= 256;
6235
5.38k
  return svalue < -128 || svalue >= 128;
6236
6.03k
}
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"