Coverage Report

Created: 2026-04-04 08:16

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
543k
{
132
543k
  return (qualifier >= AARCH64_OPND_QLF_V_8B
133
436k
    && qualifier <= AARCH64_OPND_QLF_V_1Q);
134
543k
}
135
136
static inline bool
137
fp_qualifier_p (enum aarch64_opnd_qualifier qualifier)
138
473
{
139
473
  return (qualifier >= AARCH64_OPND_QLF_S_B
140
473
    && qualifier <= AARCH64_OPND_QLF_S_Q);
141
473
}
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
237k
{
169
237k
  if (vector_qualifier_p (qualifiers[0]))
170
237k
    {
171
      /* e.g. v.4s, v.4s, v.4s
172
     or v.4h, v.4h, v.h[3].  */
173
237k
      if (qualifiers[0] == qualifiers[1]
174
115k
    && vector_qualifier_p (qualifiers[2])
175
85.1k
    && (aarch64_get_qualifier_esize (qualifiers[0])
176
85.1k
        == aarch64_get_qualifier_esize (qualifiers[1]))
177
85.1k
    && (aarch64_get_qualifier_esize (qualifiers[0])
178
85.1k
        == aarch64_get_qualifier_esize (qualifiers[2])))
179
81.9k
  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
155k
      if (vector_qualifier_p (qualifiers[1])
184
108k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
185
108k
    && (aarch64_get_qualifier_esize (qualifiers[0])
186
108k
        == aarch64_get_qualifier_esize (qualifiers[1]) << 1))
187
38.4k
  return DP_VECTOR_LONG;
188
      /* e.g. v.8h, v.8h, v.8b.  */
189
116k
      if (qualifiers[0] == qualifiers[1]
190
33.8k
    && vector_qualifier_p (qualifiers[2])
191
3.18k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
192
3.18k
    && (aarch64_get_qualifier_esize (qualifiers[0])
193
3.18k
        == aarch64_get_qualifier_esize (qualifiers[2]) << 1)
194
3.18k
    && (aarch64_get_qualifier_esize (qualifiers[0])
195
3.18k
        == aarch64_get_qualifier_esize (qualifiers[1])))
196
3.18k
  return DP_VECTOR_WIDE;
197
116k
    }
198
473
  else if (fp_qualifier_p (qualifiers[0]))
199
473
    {
200
      /* e.g. SADDLV <V><d>, <Vn>.<T>.  */
201
473
      if (vector_qualifier_p (qualifiers[1])
202
418
    && qualifiers[2] == AARCH64_OPND_QLF_NIL)
203
418
  return DP_VECTOR_ACROSS_LANES;
204
473
    }
205
206
113k
  return DP_UNKNOWN;
207
237k
}
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
237k
{
220
237k
  return
221
237k
    significant_operand_index [get_data_pattern (opcode->qualifiers_list[0])];
222
237k
}
223

224
/* Instruction bit-fields.
225
+   Keep synced with 'enum aarch64_field_kind'.  */
226
const aarch64_field aarch64_fields[] =
227
{
228
    AARCH64_FIELD_NIL,  /* NIL.  */
229
    AARCH64_FIELD_CONST (0, 1), /* CONST_0.  */
230
    AARCH64_FIELD_CONST (0, 2), /* CONST_00.  */
231
    AARCH64_FIELD_CONST (1, 2), /* CONST_01.  */
232
    AARCH64_FIELD_CONST (1, 1), /* CONST_1.  */
233
    AARCH64_FIELD ( 8, 4), /* CRm: in the system instructions.  */
234
    AARCH64_FIELD (10, 2), /* CRm_dsb_nxs: 2-bit imm. encoded in CRm<3:2>.  */
235
    AARCH64_FIELD (12, 4), /* CRn: in the system instructions.  */
236
    AARCH64_FIELD (10, 8), /* CSSC_imm8.  */
237
    AARCH64_FIELD (11, 1), /* H: in advsimd scalar x indexed element instructions.  */
238
    AARCH64_FIELD (21, 1), /* L: in advsimd scalar x indexed element instructions.  */
239
    AARCH64_FIELD ( 0, 5), /* LSE128_Rt: Shared input+output operand register.  */
240
    AARCH64_FIELD (16, 5), /* LSE128_Rt2: Shared input+output operand register 2.  */
241
    AARCH64_FIELD (20, 1), /* M: in advsimd scalar x indexed element instructions.  */
242
    AARCH64_FIELD (22, 1), /* N: in logical (immediate) instructions.  */
243
    AARCH64_FIELD (30, 1), /* Q: in most AdvSIMD instructions.  */
244
    AARCH64_FIELD (10, 5), /* Ra: in fp instructions.  */
245
    AARCH64_FIELD ( 0, 5), /* Rd: in many integer instructions.  */
246
    AARCH64_FIELD (16, 5), /* Rm: in ld/st reg offset and some integer inst.  */
247
    AARCH64_FIELD ( 5, 5), /* Rn: in many integer instructions.  */
248
    AARCH64_FIELD (16, 5), /* Rs: in load/store exclusive instructions.  */
249
    AARCH64_FIELD ( 0, 5), /* Rt: in load/store instructions.  */
250
    AARCH64_FIELD (10, 5), /* Rt2: in load/store pair instructions.  */
251
    AARCH64_FIELD (12, 1), /* S: in load/store reg offset instructions.  */
252
    AARCH64_FIELD (12, 2), /* SM3_imm2: Indexed element SM3 2 bits index immediate.  */
253
    AARCH64_FIELD ( 1, 3), /* SME_Pdx2: predicate register, multiple of 2, [3:1].  */
254
    AARCH64_FIELD (13, 3), /* SME_Pm: second source scalable predicate register P0-P7.  */
255
    AARCH64_FIELD ( 0, 3), /* SME_PNd3: PN0-PN7, bits [2:0].  */
256
    AARCH64_FIELD ( 5, 3), /* SME_PNn3: PN0-PN7, bits [7:5].  */
257
    AARCH64_FIELD (16, 1), /* SME_Q: Q class bit, bit 16.  */
258
    AARCH64_FIELD (16, 2), /* SME_Rm: index base register W12-W15 [17:16].  */
259
    AARCH64_FIELD (13, 2), /* SME_Rv: vector select register W12-W15, bits [14:13].  */
260
    AARCH64_FIELD (15, 1), /* SME_V: (horizontal / vertical tiles), bit 15.  */
261
    AARCH64_FIELD (10, 1), /* SME_VL_10: VLx2 or VLx4, bit [10].  */
262
    AARCH64_FIELD (13, 1), /* SME_VL_13: VLx2 or VLx4, bit [13].  */
263
    AARCH64_FIELD ( 0, 1), /* SME_ZAda_1b: tile ZA0-ZA1.  */
264
    AARCH64_FIELD ( 0, 2), /* SME_ZAda_2b: tile ZA0-ZA3.  */
265
    AARCH64_FIELD ( 0, 3), /* SME_ZAda_3b: tile ZA0-ZA7.  */
266
    AARCH64_FIELD ( 1, 4), /* SME_Zdn2: Z0-Z31, multiple of 2, bits [4:1].  */
267
    AARCH64_FIELD ( 2, 3), /* SME_Zdn4: Z0-Z31, multiple of 4, bits [4:2].  */
268
    AARCH64_FIELD (16, 4), /* SME_Zm: Z0-Z15, bits [19:16].  */
269
    AARCH64_FIELD (17, 3), /* SME_Zm17_3: Z0-Z15/Z16-Z31, multiple of 2, bits [19:17].  */
270
    AARCH64_FIELD (17, 4), /* SME_Zm2: Z0-Z31, multiple of 2, bits [20:17].  */
271
    AARCH64_FIELD (18, 3), /* SME_Zm4: Z0-Z31, multiple of 4, bits [20:18].  */
272
    AARCH64_FIELD ( 6, 4), /* SME_Zn2: Z0-Z31, multiple of 2, bits [9:6].  */
273
    AARCH64_FIELD ( 7, 3), /* SME_Zn4: Z0-Z31, multiple of 4, bits [9:7].  */
274
    AARCH64_FIELD ( 6, 3), /* SME_Zn6_3: Z0-Z15/Z16-Z31, multiple of 2, bits [8:6].  */
275
    AARCH64_FIELD ( 4, 1), /* SME_ZtT: upper bit of Zt, bit [4].  */
276
    AARCH64_FIELD ( 0, 3), /* SME_Zt3: lower 3 bits of Zt, bits [2:0].  */
277
    AARCH64_FIELD ( 0, 2), /* SME_Zt2: lower 2 bits of Zt, bits [1:0].  */
278
    AARCH64_FIELD (23, 1), /* SME_i1: immediate field, bit 23.  */
279
    AARCH64_FIELD (12, 2), /* SME_size_12: bits [13:12].  */
280
    AARCH64_FIELD (22, 2), /* SME_size_22: size<1>, size<0> class field, [23:22].  */
281
    AARCH64_FIELD (23, 1), /* SME_sz_23: bit [23].  */
282
    AARCH64_FIELD (22, 1), /* SME_tszh: immediate and qualifier field, bit 22.  */
283
    AARCH64_FIELD (18, 3), /* SME_tszl: immediate and qualifier field, bits [20:18].  */
284
    AARCH64_FIELD (0,  8), /* SME_zero_mask: list of up to 8 tile names separated by commas [7:0].  */
285
    AARCH64_FIELD ( 4, 1), /* SVE_M_4: Merge/zero select, bit 4.  */
286
    AARCH64_FIELD (14, 1), /* SVE_M_14: Merge/zero select, bit 14.  */
287
    AARCH64_FIELD (16, 1), /* SVE_M_16: Merge/zero select, bit 16.  */
288
    AARCH64_FIELD (17, 1), /* SVE_N: SVE equivalent of N.  */
289
    AARCH64_FIELD ( 0, 4), /* SVE_Pd: p0-p15, bits [3,0].  */
290
    AARCH64_FIELD (10, 3), /* SVE_Pg3: p0-p7, bits [12,10].  */
291
    AARCH64_FIELD ( 5, 4), /* SVE_Pg4_5: p0-p15, bits [8,5].  */
292
    AARCH64_FIELD (10, 4), /* SVE_Pg4_10: p0-p15, bits [13,10].  */
293
    AARCH64_FIELD (16, 4), /* SVE_Pg4_16: p0-p15, bits [19,16].  */
294
    AARCH64_FIELD (16, 4), /* SVE_Pm: p0-p15, bits [19,16].  */
295
    AARCH64_FIELD ( 5, 4), /* SVE_Pn: p0-p15, bits [8,5].  */
296
    AARCH64_FIELD ( 0, 4), /* SVE_Pt: p0-p15, bits [3,0].  */
297
    AARCH64_FIELD ( 5, 5), /* SVE_Rm: SVE alternative position for Rm.  */
298
    AARCH64_FIELD (16, 5), /* SVE_Rn: SVE alternative position for Rn.  */
299
    AARCH64_FIELD ( 0, 5), /* SVE_Vd: Scalar SIMD&FP register, bits [4,0].  */
300
    AARCH64_FIELD ( 5, 5), /* SVE_Vm: Scalar SIMD&FP register, bits [9,5].  */
301
    AARCH64_FIELD ( 5, 5), /* SVE_Vn: Scalar SIMD&FP register, bits [9,5].  */
302
    AARCH64_FIELD ( 5, 5), /* SVE_Za_5: SVE vector register, bits [9,5].  */
303
    AARCH64_FIELD (16, 5), /* SVE_Za_16: SVE vector register, bits [20,16].  */
304
    AARCH64_FIELD ( 0, 5), /* SVE_Zd: SVE vector register. bits [4,0].  */
305
    AARCH64_FIELD ( 5, 5), /* SVE_Zm_5: SVE vector register, bits [9,5].  */
306
    AARCH64_FIELD (16, 5), /* SVE_Zm_16: SVE vector register, bits [20,16]. */
307
    AARCH64_FIELD ( 5, 5), /* SVE_Zn: SVE vector register, bits [9,5].  */
308
    AARCH64_FIELD ( 0, 5), /* SVE_Zt: SVE vector register, bits [4,0].  */
309
    AARCH64_FIELD ( 5, 1), /* SVE_i1: single-bit immediate.  */
310
    AARCH64_FIELD (23, 1), /* SVE_i1_23: single-bit immediate.  */
311
    AARCH64_FIELD (22, 2), /* SVE_i2: 2-bit index, bits [23,22].  */
312
    AARCH64_FIELD (20, 1), /* SVE_i2h: high bit of 2bit immediate, bits.  */
313
    AARCH64_FIELD (22, 1), /* SVE_i3h: high bit of 3-bit immediate.  */
314
    AARCH64_FIELD (19, 2), /* SVE_i3h2: two high bits of 3bit immediate, bits [20,19].  */
315
    AARCH64_FIELD (22, 2), /* SVE_i3h3: two high bits of 3bit immediate, bits [22,23].  */
316
    AARCH64_FIELD (11, 1), /* SVE_i3l: low bit of 3-bit immediate.  */
317
    AARCH64_FIELD (12, 1), /* SVE_i3l2: low bit of 3-bit immediate, bit 12.  */
318
    AARCH64_FIELD (10, 2), /* SVE_i4l2: two low bits of 4bit immediate, bits [11,10].  */
319
    AARCH64_FIELD (16, 3), /* SVE_imm3: 3-bit immediate field.  */
320
    AARCH64_FIELD (16, 4), /* SVE_imm4: 4-bit immediate field.  */
321
    AARCH64_FIELD ( 5, 5), /* SVE_imm5: 5-bit immediate field.  */
322
    AARCH64_FIELD (16, 5), /* SVE_imm5b: secondary 5-bit immediate field.  */
323
    AARCH64_FIELD (16, 6), /* SVE_imm6: 6-bit immediate field.  */
324
    AARCH64_FIELD (14, 7), /* SVE_imm7: 7-bit immediate field.  */
325
    AARCH64_FIELD ( 5, 8), /* SVE_imm8: 8-bit immediate field.  */
326
    AARCH64_FIELD ( 5, 9), /* SVE_imm9: 9-bit immediate field.  */
327
    AARCH64_FIELD (11, 6), /* SVE_immr: SVE equivalent of immr.  */
328
    AARCH64_FIELD ( 5, 6), /* SVE_imms: SVE equivalent of imms.  */
329
    AARCH64_FIELD (10, 2), /* SVE_msz: 2-bit shift amount for ADR.  */
330
    AARCH64_FIELD ( 5, 5), /* SVE_pattern: vector pattern enumeration.  */
331
    AARCH64_FIELD ( 0, 4), /* SVE_prfop: prefetch operation for SVE PRF[BHWD].  */
332
    AARCH64_FIELD (16, 1), /* SVE_rot1: 1-bit rotation amount.  */
333
    AARCH64_FIELD (10, 2), /* SVE_rot2: 2-bit rotation amount.  */
334
    AARCH64_FIELD (10, 1), /* SVE_rot3: 1-bit rotation amount at bit 10.  */
335
    AARCH64_FIELD (17, 2), /* SVE_size: 2-bit element size, bits [18,17].  */
336
    AARCH64_FIELD (22, 1), /* SVE_sz: 1-bit element size select.  */
337
    AARCH64_FIELD (30, 1), /* SVE_sz2: 1-bit element size select.  */
338
    AARCH64_FIELD (17, 1), /* SVE_sz3: 1-bit element size select.  */
339
    AARCH64_FIELD (14, 1), /* SVE_sz4: 1-bit element size select.  */
340
    AARCH64_FIELD (16, 4), /* SVE_tsz: triangular size select.  */
341
    AARCH64_FIELD (22, 2), /* SVE_tszh: triangular size select high, bits [23,22].  */
342
    AARCH64_FIELD ( 8, 2), /* SVE_tszl_8: triangular size select low, bits [9,8].  */
343
    AARCH64_FIELD (19, 2), /* SVE_tszl_19: triangular size select low, bits [20,19].  */
344
    AARCH64_FIELD (14, 1), /* SVE_xs_14: UXTW/SXTW select (bit 14).  */
345
    AARCH64_FIELD (22, 1), /* SVE_xs_22: UXTW/SXTW select (bit 22).  */
346
    AARCH64_FIELD (22, 1), /* S_imm10: in LDRAA and LDRAB instructions.  */
347
    AARCH64_FIELD (16, 3), /* abc: a:b:c bits in AdvSIMD modified immediate.  */
348
    AARCH64_FIELD (13, 3), /* asisdlso_opcode: opcode in advsimd ld/st single element.  */
349
    AARCH64_FIELD (19, 5), /* b40: in the test bit and branch instructions.  */
350
    AARCH64_FIELD (31, 1), /* b5: in the test bit and branch instructions.  */
351
    AARCH64_FIELD (12, 4), /* cmode: in advsimd modified immediate instructions.  */
352
    AARCH64_FIELD (12, 4), /* cond: condition flags as a source operand.  */
353
    AARCH64_FIELD ( 0, 4), /* cond2: condition in truly conditional-executed inst.  */
354
    AARCH64_FIELD ( 5, 5), /* defgh: d:e:f:g:h bits in AdvSIMD modified immediate.  */
355
    AARCH64_FIELD (21, 2), /* hw: in move wide constant instructions.  */
356
    AARCH64_FIELD ( 0, 1), /* imm1_0: general immediate in bits [0].  */
357
    AARCH64_FIELD ( 2, 1), /* imm1_2: general immediate in bits [2].  */
358
    AARCH64_FIELD ( 3, 1), /* imm1_3: general immediate in bits [3].  */
359
    AARCH64_FIELD ( 8, 1), /* imm1_8: general immediate in bits [8].  */
360
    AARCH64_FIELD (10, 1), /* imm1_10: general immediate in bits [10].  */
361
    AARCH64_FIELD (14, 1), /* imm1_14: general immediate in bits [14].  */
362
    AARCH64_FIELD (15, 1), /* imm1_15: general immediate in bits [15].  */
363
    AARCH64_FIELD (16, 1), /* imm1_16: general immediate in bits [16].  */
364
    AARCH64_FIELD (22, 1), /* imm1_22: general immediate in bits [22].  */
365
    AARCH64_FIELD ( 0, 2), /* imm2_0: general immediate in bits [1:0].  */
366
    AARCH64_FIELD ( 1, 2), /* imm2_1: general immediate in bits [2:1].  */
367
    AARCH64_FIELD ( 2, 2), /* imm2_2: general immediate in bits [3:2].  */
368
    AARCH64_FIELD ( 4, 2), /* imm2_4: general immediate in bits [5:4].  */
369
    AARCH64_FIELD ( 8, 2), /* imm2_8: general immediate in bits [9:8].  */
370
    AARCH64_FIELD (10, 2), /* imm2_10: 2-bit immediate, bits [11:10] */
371
    AARCH64_FIELD (12, 2), /* imm2_12: 2-bit immediate, bits [13:12] */
372
    AARCH64_FIELD (13, 2), /* imm2_13: 2-bit immediate, bits [14:13] */
373
    AARCH64_FIELD (15, 2), /* imm2_15: 2-bit immediate, bits [16:15] */
374
    AARCH64_FIELD (16, 2), /* imm2_16: 2-bit immediate, bits [17:16] */
375
    AARCH64_FIELD (19, 2), /* imm2_19: 2-bit immediate, bits [20:19] */
376
    AARCH64_FIELD ( 0, 3), /* imm3_0: general immediate in bits [2:0].  */
377
    AARCH64_FIELD ( 5, 3), /* imm3_5: general immediate in bits [7:5].  */
378
    AARCH64_FIELD (10, 3), /* imm3_10: in add/sub extended reg instructions.  */
379
    AARCH64_FIELD (12, 3), /* imm3_12: general immediate in bits [14:12].  */
380
    AARCH64_FIELD (14, 3), /* imm3_14: general immediate in bits [16:14].  */
381
    AARCH64_FIELD (15, 3), /* imm3_15: general immediate in bits [17:15].  */
382
    AARCH64_FIELD (19, 3), /* imm3_19: general immediate in bits [21:19].  */
383
    AARCH64_FIELD ( 0, 4), /* imm4_0: in rmif instructions.  */
384
    AARCH64_FIELD ( 5, 4), /* imm4_5: in SME instructions.  */
385
    AARCH64_FIELD (10, 4), /* imm4_10: in adddg/subg instructions.  */
386
    AARCH64_FIELD (11, 4), /* imm4_11: in advsimd ext and advsimd ins instructions.  */
387
    AARCH64_FIELD (14, 4), /* imm4_14: general immediate in bits [17:14].  */
388
    AARCH64_FIELD (16, 5), /* imm5: in conditional compare (immediate) instructions.  */
389
    AARCH64_FIELD (10, 6), /* imm6_10: in add/sub reg shifted instructions.  */
390
    AARCH64_FIELD (15, 6), /* imm6_15: in rmif instructions.  */
391
    AARCH64_FIELD (15, 7), /* imm7: in load/store pair pre/post index instructions.  */
392
    AARCH64_FIELD (13, 8), /* imm8: in floating-point scalar move immediate inst.  */
393
    AARCH64_FIELD (12, 9), /* imm9: in load/store pre/post index instructions.  */
394
    AARCH64_FIELD ( 5, 9), /* imm9_5: in CB<cc> (immediate).  */
395
    AARCH64_FIELD (10,12), /* imm12: in ld/st unsigned imm or add/sub shifted inst.  */
396
    AARCH64_FIELD ( 5,14), /* imm14: in test bit and branch instructions.  */
397
    AARCH64_FIELD ( 0,16), /* imm16_0: in udf instruction. */
398
    AARCH64_FIELD ( 5,16), /* imm16_5: in exception instructions.  */
399
    AARCH64_FIELD (17, 1), /* imm17_1: in 1 bit element index.  */
400
    AARCH64_FIELD (17, 2), /* imm17_2: in 2 bits element index.  */
401
    AARCH64_FIELD ( 5,19), /* imm19: e.g. in CBZ.  */
402
    AARCH64_FIELD ( 0,26), /* imm26: in unconditional branch instructions.  */
403
    AARCH64_FIELD (16, 3), /* immb: in advsimd shift by immediate instructions.  */
404
    AARCH64_FIELD (19, 4), /* immh: in advsimd shift by immediate instructions.  */
405
    AARCH64_FIELD ( 5,19), /* immhi: e.g. in ADRP.  */
406
    AARCH64_FIELD (29, 2), /* immlo: e.g. in ADRP.  */
407
    AARCH64_FIELD (16, 6), /* immr: in bitfield and logical immediate instructions.  */
408
    AARCH64_FIELD (10, 6), /* imms: in bitfield and logical immediate instructions.  */
409
    AARCH64_FIELD (11, 1), /* index: in ld/st inst deciding the pre/post-index.  */
410
    AARCH64_FIELD (24, 1), /* index2: in ld/st pair inst deciding the pre/post-index.  */
411
    AARCH64_FIELD (30, 2), /* ldst_size: size field in ld/st reg offset inst.  */
412
    AARCH64_FIELD (13, 2), /* len: in advsimd tbl/tbx instructions.  */
413
    AARCH64_FIELD (30, 1), /* lse_sz: in LSE extension atomic instructions.  */
414
    AARCH64_FIELD ( 0, 4), /* nzcv: flag bit specifier, encoded in the "nzcv" field.  */
415
    AARCH64_FIELD (29, 1), /* op: in AdvSIMD modified immediate instructions.  */
416
    AARCH64_FIELD (19, 2), /* op0: in the system instructions.  */
417
    AARCH64_FIELD (16, 3), /* op1: in the system instructions.  */
418
    AARCH64_FIELD ( 5, 3), /* op2: in the system instructions.  */
419
    AARCH64_FIELD (22, 2), /* opc: in load/store reg offset instructions.  */
420
    AARCH64_FIELD (23, 1), /* opc1: in load/store reg offset instructions.  */
421
    AARCH64_FIELD (12, 4), /* opcode: in advsimd load/store instructions.  */
422
    AARCH64_FIELD (13, 3), /* option: in ld/st reg offset + add/sub extended reg inst.  */
423
    AARCH64_FIELD (11, 2), /* rotate1: FCMLA immediate rotate.  */
424
    AARCH64_FIELD (13, 2), /* rotate2: Indexed element FCMLA immediate rotate.  */
425
    AARCH64_FIELD (12, 1), /* rotate3: FCADD immediate rotate.  */
426
    AARCH64_FIELD (10, 6), /* scale: in the fixed-point scalar to fp converting inst.  */
427
    AARCH64_FIELD (31, 1), /* sf: in integer data processing instructions.  */
428
    AARCH64_FIELD (22, 2), /* shift: in add/sub reg/imm shifted instructions.  */
429
    AARCH64_FIELD (22, 2), /* size: in most AdvSIMD and floating-point instructions.  */
430
    AARCH64_FIELD (22, 1), /* sz: 1-bit element size select.  */
431
    AARCH64_FIELD (22, 2), /* type: floating point type field in fp data inst.  */
432
    AARCH64_FIELD (10, 2), /* vldst_size: size field in the AdvSIMD load/store inst.  */
433
    AARCH64_FIELD ( 5, 3), /* off3: immediate offset used to calculate slice number in a ZA tile.  */
434
    AARCH64_FIELD ( 5, 2), /* off2: immediate offset used to calculate slice number in a ZA tile.  */
435
    AARCH64_FIELD ( 7, 1), /* ZAn_1: name of the 1bit encoded ZA tile.  */
436
    AARCH64_FIELD ( 5, 1), /* ol: immediate offset used to calculate slice number in a ZA tile. */
437
    AARCH64_FIELD ( 6, 2), /* ZAn_2: name of the 2bit encoded ZA tile.  */
438
    AARCH64_FIELD ( 5, 3), /* ZAn_3: name of the 3bit encoded ZA tile.  */
439
    AARCH64_FIELD ( 6, 1), /* ZAn: name of the bit encoded ZA tile.  */
440
    AARCH64_FIELD (12, 4), /* opc2: in rcpc3 ld/st inst deciding the pre/post-index.  */
441
    AARCH64_FIELD (30, 2), /* rcpc3_size: in rcpc3 ld/st, field controls Rt/Rt2 width.  */
442
    AARCH64_FIELD ( 5, 1), /* FLD_brbop: used in BRB to mean IALL or INJ.  */
443
    AARCH64_FIELD ( 8, 1), /* ZA8_1: name of the 1 bit encoded ZA tile ZA0-ZA1.  */
444
    AARCH64_FIELD ( 7, 2), /* ZA7_2: name of the 2 bits encoded ZA tile ZA0-ZA3.  */
445
    AARCH64_FIELD ( 6, 3), /* ZA6_3: name of the 3 bits encoded ZA tile ZA0-ZA7.  */
446
    AARCH64_FIELD ( 5, 4), /* ZA5_4: name of the 4 bits encoded ZA tile ZA0-ZA15.  */
447
};
448
449
enum aarch64_operand_class
450
aarch64_get_operand_class (enum aarch64_opnd type)
451
1.86M
{
452
1.86M
  return aarch64_operands[type].op_class;
453
1.86M
}
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
45.4k
{
493
45.4k
  assert (value < 16);
494
45.4k
  return &aarch64_conds[(unsigned int) value];
495
45.4k
}
496
497
const aarch64_cond *
498
get_inverted_cond (const aarch64_cond *cond)
499
205
{
500
205
  return &aarch64_conds[cond->value ^ 0x1];
501
205
}
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
442k
{
545
442k
  if (extend_p)
546
84.4k
    return AARCH64_MOD_UXTB + value;
547
358k
  else
548
358k
    return AARCH64_MOD_LSL - value;
549
442k
}
550
551
bool
552
aarch64_extend_operator_p (enum aarch64_modifier_kind kind)
553
38.5k
{
554
38.5k
  return kind > AARCH64_MOD_LSL && kind <= AARCH64_MOD_SXTX;
555
38.5k
}
556
557
static inline bool
558
aarch64_shift_operator_p (enum aarch64_modifier_kind kind)
559
344k
{
560
344k
  return kind >= AARCH64_MOD_ROR && kind <= AARCH64_MOD_LSL;
561
344k
}
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
1.95M
{
662
1.95M
  return (low <= value) && (value <= high);
663
1.95M
}
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.33M
{
669
1.33M
  return (value % align) == 0;
670
1.33M
}
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
877k
{
676
877k
  assert (width < 32);
677
877k
  if (width < sizeof (value) * 8)
678
877k
    {
679
877k
      int64_t lim = (uint64_t) 1 << (width - 1);
680
877k
      if (value >= -lim && value < lim)
681
877k
  return true;
682
877k
    }
683
0
  return false;
684
877k
}
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.55M
{
690
1.55M
  assert (width < 32);
691
1.55M
  if (width < sizeof (value) * 8)
692
1.55M
    {
693
1.55M
      int64_t lim = (uint64_t) 1 << width;
694
1.55M
      if (value >= 0 && value < lim)
695
1.55M
  return true;
696
1.55M
    }
697
0
  return false;
698
1.55M
}
699
700
/* Return true if OPERAND is SP or WSP.  */
701
bool
702
aarch64_stack_pointer_p (const aarch64_opnd_info *operand)
703
120k
{
704
120k
  return ((aarch64_get_operand_class (operand->type)
705
120k
     == AARCH64_OPND_CLASS_INT_REG)
706
120k
    && operand_maybe_stack_pointer (aarch64_operands + operand->type)
707
75.6k
    && operand->reg.regno == 31);
708
120k
}
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.15M
{
728
3.15M
  switch (operand->qualifier)
729
3.15M
    {
730
4.42k
    case AARCH64_OPND_QLF_W:
731
4.42k
      if (target == AARCH64_OPND_QLF_WSP && aarch64_stack_pointer_p (operand))
732
200
  return true;
733
4.22k
      break;
734
656k
    case AARCH64_OPND_QLF_X:
735
656k
      if (target == AARCH64_OPND_QLF_SP && aarch64_stack_pointer_p (operand))
736
23
  return true;
737
656k
      break;
738
656k
    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.49M
    default:
749
2.49M
      break;
750
3.15M
    }
751
752
3.15M
  return false;
753
3.15M
}
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
7.99M
{
891
7.99M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_OPD_VARIANT;
892
7.99M
}
893
894
static inline bool
895
qualifier_value_in_range_constraint_p (aarch64_opnd_qualifier_t qualifier)
896
2.84M
{
897
2.84M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_VALUE_IN_RANGE;
898
2.84M
}
899
900
const char*
901
aarch64_get_qualifier_name (aarch64_opnd_qualifier_t qualifier)
902
3.03M
{
903
3.03M
  return aarch64_opnd_qualifiers[qualifier].desc;
904
3.03M
}
905
906
/* Given an operand qualifier, return the expected data element size
907
   of a qualified operand.  */
908
unsigned char
909
aarch64_get_qualifier_esize (aarch64_opnd_qualifier_t qualifier)
910
5.76M
{
911
5.76M
  assert (operand_variant_qualifier_p (qualifier));
912
5.76M
  return aarch64_opnd_qualifiers[qualifier].data0;
913
5.76M
}
914
915
unsigned char
916
aarch64_get_qualifier_nelem (aarch64_opnd_qualifier_t qualifier)
917
73.2k
{
918
73.2k
  assert (operand_variant_qualifier_p (qualifier));
919
73.2k
  return aarch64_opnd_qualifiers[qualifier].data1;
920
73.2k
}
921
922
aarch64_insn
923
aarch64_get_qualifier_standard_value (aarch64_opnd_qualifier_t qualifier)
924
2.15M
{
925
2.15M
  assert (operand_variant_qualifier_p (qualifier));
926
2.15M
  return aarch64_opnd_qualifiers[qualifier].data2;
927
2.15M
}
928
929
static int
930
get_lower_bound (aarch64_opnd_qualifier_t qualifier)
931
315k
{
932
315k
  assert (qualifier_value_in_range_constraint_p (qualifier));
933
315k
  return aarch64_opnd_qualifiers[qualifier].data0;
934
315k
}
935
936
static int
937
get_upper_bound (aarch64_opnd_qualifier_t qualifier)
938
335k
{
939
335k
  assert (qualifier_value_in_range_constraint_p (qualifier));
940
335k
  return aarch64_opnd_qualifiers[qualifier].data1;
941
335k
}
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
378
{
987
378
  int i = 0;
988
378
  const enum aarch64_opnd *opnds = opcode->operands;
989
990
378
  if (opnds[0] == AARCH64_OPND_NIL)
991
0
    return false;
992
993
1.01k
  while (opnds[++i] != AARCH64_OPND_NIL)
994
883
    if (opnds[i] == opnds[0])
995
251
      return true;
996
997
127
  return false;
998
378
}
999
1000
/* TODO improve this, we can have an extra field at the runtime to
1001
   store the number of operands rather than calculating it every time.  */
1002
1003
int
1004
aarch64_num_of_operands (const aarch64_opcode *opcode)
1005
6.55M
{
1006
6.55M
  int i = 0;
1007
6.55M
  const enum aarch64_opnd *opnds = opcode->operands;
1008
22.4M
  while (opnds[i++] != AARCH64_OPND_NIL)
1009
15.9M
    ;
1010
6.55M
  --i;
1011
6.55M
  assert (i >= 0 && i <= AARCH64_MAX_OPND_NUM);
1012
6.55M
  return i;
1013
6.55M
}
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
5.91M
{
1046
5.91M
  int i, num_opnds, invalid, min_invalid;
1047
5.91M
  const aarch64_opnd_qualifier_t *qualifiers;
1048
1049
5.91M
  num_opnds = aarch64_num_of_operands (inst->opcode);
1050
5.91M
  if (num_opnds == 0)
1051
43
    {
1052
43
      DEBUG_TRACE ("SUCCEED: no operand");
1053
43
      *invalid_count = 0;
1054
43
      return 1;
1055
43
    }
1056
1057
5.91M
  if (stop_at < 0 || stop_at >= num_opnds)
1058
5.16M
    stop_at = num_opnds - 1;
1059
1060
  /* For each pattern.  */
1061
5.91M
  min_invalid = num_opnds;
1062
8.15M
  for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list)
1063
8.15M
    {
1064
8.15M
      int j;
1065
8.15M
      qualifiers = *qualifiers_list;
1066
1067
      /* Start as positive.  */
1068
8.15M
      invalid = 0;
1069
1070
8.15M
      DEBUG_TRACE ("%d", i);
1071
#ifdef DEBUG_AARCH64
1072
      if (debug_dump)
1073
  dump_match_qualifiers (inst->operands, qualifiers);
1074
#endif
1075
1076
      /* The first entry should be taken literally, even if it's an empty
1077
   qualifier sequence.  (This matters for strict testing.)  In other
1078
   positions an empty sequence acts as a terminator.  */
1079
8.15M
      if (i > 0 && empty_qualifier_sequence_p (qualifiers))
1080
46.5k
  break;
1081
1082
28.1M
      for (j = 0; j < num_opnds && j <= stop_at; ++j, ++qualifiers)
1083
19.9M
  {
1084
19.9M
    if (inst->operands[j].qualifier == AARCH64_OPND_QLF_NIL
1085
11.1M
        && !(inst->opcode->flags & F_STRICT))
1086
10.6M
      {
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
10.6M
        continue;
1094
10.6M
      }
1095
9.38M
    else if (*qualifiers != inst->operands[j].qualifier)
1096
3.15M
      {
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.15M
        if (operand_also_qualified_p (inst->operands + j, *qualifiers))
1101
223
    continue;
1102
3.15M
        else
1103
3.15M
    invalid += 1;
1104
3.15M
      }
1105
6.22M
    else
1106
6.22M
      continue; /* Equal qualifiers are certainly matched.  */
1107
19.9M
  }
1108
1109
8.11M
      if (min_invalid > invalid)
1110
7.15M
  min_invalid = invalid;
1111
1112
      /* Qualifiers established.  */
1113
8.11M
      if (min_invalid == 0)
1114
5.86M
  break;
1115
8.11M
    }
1116
1117
5.91M
  *invalid_count = min_invalid;
1118
5.91M
  if (min_invalid == 0)
1119
5.86M
    {
1120
      /* Fill the result in *RET.  */
1121
5.86M
      int j;
1122
5.86M
      qualifiers = *qualifiers_list;
1123
1124
5.86M
      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
19.7M
      for (j = 0; j <= stop_at; ++j, ++qualifiers)
1131
13.8M
  ret[j] = *qualifiers;
1132
33.0M
      for (; j < AARCH64_MAX_OPND_NUM; ++j)
1133
27.2M
  ret[j] = AARCH64_OPND_QLF_NIL;
1134
1135
5.86M
      DEBUG_TRACE ("SUCCESS");
1136
5.86M
      return 1;
1137
5.86M
    }
1138
1139
46.5k
  DEBUG_TRACE ("FAIL");
1140
46.5k
  return 0;
1141
5.91M
}
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.16M
{
1158
5.16M
  int i;
1159
5.16M
  aarch64_opnd_qualifier_seq_t qualifiers;
1160
1161
5.16M
  if (!aarch64_find_best_match (inst, inst->opcode->qualifiers_list, -1,
1162
5.16M
        qualifiers, invalid_count))
1163
28.8k
    {
1164
28.8k
      DEBUG_TRACE ("matching FAIL");
1165
28.8k
      return 0;
1166
28.8k
    }
1167
1168
  /* Update the qualifiers.  */
1169
5.13M
  if (update_p)
1170
17.0M
    for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
1171
17.0M
      {
1172
17.0M
  if (inst->opcode->operands[i] == AARCH64_OPND_NIL)
1173
5.13M
    break;
1174
11.9M
  DEBUG_TRACE_IF (inst->operands[i].qualifier != qualifiers[i],
1175
11.9M
      "update %s with %s for operand %d",
1176
11.9M
      aarch64_get_qualifier_name (inst->operands[i].qualifier),
1177
11.9M
      aarch64_get_qualifier_name (qualifiers[i]), i);
1178
11.9M
  inst->operands[i].qualifier = qualifiers[i];
1179
11.9M
      }
1180
1181
5.13M
  DEBUG_TRACE ("matching SUCCESS");
1182
5.13M
  return 1;
1183
5.16M
}
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
53.0k
{
1195
53.0k
  int amount;
1196
1197
53.0k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1198
1199
53.0k
  if (is32)
1200
11.0k
    {
1201
      /* Allow all zeros or all ones in top 32-bits, so that
1202
   32-bit constant expressions like ~0x80000000 are
1203
   permitted.  */
1204
11.0k
      if (value >> 32 != 0 && value >> 32 != 0xffffffff)
1205
  /* Immediate out of range.  */
1206
0
  return false;
1207
11.0k
      value &= 0xffffffff;
1208
11.0k
    }
1209
1210
  /* first, try movz then movn */
1211
53.0k
  amount = -1;
1212
53.0k
  if ((value & ((uint64_t) 0xffff << 0)) == value)
1213
14.5k
    amount = 0;
1214
38.5k
  else if ((value & ((uint64_t) 0xffff << 16)) == value)
1215
6.60k
    amount = 16;
1216
31.9k
  else if (!is32 && (value & ((uint64_t) 0xffff << 32)) == value)
1217
8.14k
    amount = 32;
1218
23.8k
  else if (!is32 && (value & ((uint64_t) 0xffff << 48)) == value)
1219
3.60k
    amount = 48;
1220
1221
53.0k
  if (amount == -1)
1222
20.2k
    {
1223
20.2k
      DEBUG_TRACE ("exit false with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1224
20.2k
      return false;
1225
20.2k
    }
1226
1227
32.8k
  if (shift_amount != NULL)
1228
0
    *shift_amount = amount;
1229
1230
32.8k
  DEBUG_TRACE ("exit true with amount %d", amount);
1231
1232
32.8k
  return true;
1233
53.0k
}
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
222k
#define TOTAL_IMM_NB  5334
1255
1256
typedef struct
1257
{
1258
  uint64_t imm;
1259
  aarch64_insn encoding;
1260
} simd_imm_encoding;
1261
1262
static simd_imm_encoding simd_immediates[TOTAL_IMM_NB];
1263
1264
static int
1265
simd_imm_encoding_cmp(const void *i1, const void *i2)
1266
2.66M
{
1267
2.66M
  const simd_imm_encoding *imm1 = (const simd_imm_encoding *)i1;
1268
2.66M
  const simd_imm_encoding *imm2 = (const simd_imm_encoding *)i2;
1269
1270
2.66M
  if (imm1->imm < imm2->imm)
1271
1.34M
    return -1;
1272
1.32M
  if (imm1->imm > imm2->imm)
1273
1.09M
    return +1;
1274
222k
  return 0;
1275
1.32M
}
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
222k
{
1368
222k
  simd_imm_encoding imm_enc;
1369
222k
  const simd_imm_encoding *imm_encoding;
1370
222k
  static bool initialized = false;
1371
222k
  uint64_t upper;
1372
222k
  int i;
1373
1374
222k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 "), esize: %d", value,
1375
222k
         value, esize);
1376
1377
222k
  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
222k
  upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
1386
222k
  if ((value & ~upper) != value && (value | upper) != value)
1387
0
    return false;
1388
1389
  /* Replicate to a full 64-bit value.  */
1390
222k
  value &= ~upper;
1391
385k
  for (i = esize * 8; i < 64; i *= 2)
1392
162k
    value |= (value << i);
1393
1394
222k
  imm_enc.imm = value;
1395
222k
  imm_encoding = (const simd_imm_encoding *)
1396
222k
    bsearch(&imm_enc, simd_immediates, TOTAL_IMM_NB,
1397
222k
            sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1398
222k
  if (imm_encoding == NULL)
1399
0
    {
1400
0
      DEBUG_TRACE ("exit with false");
1401
0
      return false;
1402
0
    }
1403
222k
  if (encoding != NULL)
1404
0
    *encoding = imm_encoding->encoding;
1405
222k
  DEBUG_TRACE ("exit with true");
1406
222k
  return true;
1407
222k
}
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
700
{
1416
700
  int i, ret;
1417
700
  uint32_t byte;
1418
1419
700
  ret = 0;
1420
6.30k
  for (i = 0; i < 8; i++)
1421
5.60k
    {
1422
5.60k
      byte = (imm >> (8 * i)) & 0xff;
1423
5.60k
      if (byte == 0xff)
1424
3.69k
  ret |= 1 << i;
1425
1.90k
      else if (byte != 0x00)
1426
0
  return -1;
1427
5.60k
    }
1428
700
  return ret;
1429
700
}
1430
1431
/* Utility inline functions for operand_general_constraint_met_p.  */
1432
1433
static inline void
1434
set_error (aarch64_operand_error *mismatch_detail,
1435
     enum aarch64_operand_error_kind kind, int idx,
1436
     const char* error)
1437
0
{
1438
0
  if (mismatch_detail == NULL)
1439
0
    return;
1440
0
  mismatch_detail->kind = kind;
1441
0
  mismatch_detail->index = idx;
1442
0
  mismatch_detail->error = error;
1443
0
}
1444
1445
static inline void
1446
set_syntax_error (aarch64_operand_error *mismatch_detail, int idx,
1447
      const char* error)
1448
1.71k
{
1449
1.71k
  if (mismatch_detail == NULL)
1450
1.71k
    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
30.8k
{
1482
30.8k
  if (mismatch_detail == NULL)
1483
30.8k
    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
424
{
1512
424
  if (mismatch_detail == NULL)
1513
424
    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
62.4k
{
1522
62.4k
  if (mismatch_detail == NULL)
1523
62.4k
    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
526
{
1554
526
  if (mismatch_detail == NULL)
1555
526
    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
33.2k
{
1584
33.2k
  if (mismatch_detail == NULL)
1585
33.2k
    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
52.6k
{
1599
52.6k
  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
52.6k
  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
52.6k
  return true;
1612
52.6k
}
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
259k
{
1622
259k
  if (opnd->reglist.num_regs != num_regs)
1623
526
    {
1624
526
      set_reg_list_length_error (mismatch_detail, idx, num_regs);
1625
526
      return false;
1626
526
    }
1627
258k
  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
258k
  return true;
1633
258k
}
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
866k
{
1667
866k
  const aarch64_operand *operand = get_operand_from_code (type);
1668
866k
  uint8_t size = get_operand_fields_width (operand);
1669
866k
  bool unsigned_imm = operand_need_unsigned_offset (operand);
1670
866k
  bool (*value_fit_field) (int64_t, unsigned)
1671
866k
    = (unsigned_imm
1672
866k
      ? value_fit_unsigned_field_p
1673
866k
      : value_fit_signed_field_p);
1674
1675
866k
  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
866k
  return true;
1682
866k
}
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
121k
{
1702
121k
  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
121k
  int max_index = max_value * range_size;
1718
121k
  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
121k
  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
121k
  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
121k
  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
121k
  return true;
1760
121k
}
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
14.7k
{
1768
14.7k
  unsigned num_bytes = 0; /* total number of bytes transferred.  */
1769
14.7k
  enum aarch64_operand_class opnd_class;
1770
14.7k
  enum aarch64_opnd type;
1771
1772
43.9k
  for (int i = 0; i < AARCH64_MAX_OPND_NUM; i++)
1773
43.9k
    {
1774
43.9k
      type = opnds[i].type;
1775
43.9k
      opnd_class = aarch64_operands[type].op_class;
1776
43.9k
      if (opnd_class == AARCH64_OPND_CLASS_ADDRESS)
1777
14.7k
  break;
1778
29.1k
      num_bytes += aarch64_get_qualifier_esize (opnds[i].qualifier);
1779
29.1k
    }
1780
14.7k
  return num_bytes;
1781
14.7k
}
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
11.9M
{
1806
11.9M
  unsigned num, modifiers, shift;
1807
11.9M
  unsigned char size;
1808
11.9M
  int64_t imm, min_value, max_value;
1809
11.9M
  uint64_t uvalue, mask;
1810
11.9M
  const aarch64_opnd_info *opnd = opnds + idx;
1811
11.9M
  aarch64_opnd_qualifier_t qualifier = opnd->qualifier;
1812
11.9M
  int i;
1813
1814
11.9M
  assert (opcode->operands[idx] == opnd->type && opnd->type == type);
1815
1816
11.9M
  switch (aarch64_operands[type].op_class)
1817
11.9M
    {
1818
3.83M
    case AARCH64_OPND_CLASS_INT_REG:
1819
      /* Check for pair of xzr registers.  */
1820
3.83M
      if (type == AARCH64_OPND_PAIRREG_OR_XZR
1821
1.94k
    && opnds[idx - 1].reg.regno == 0x1f)
1822
726
  {
1823
726
    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
726
  }
1831
      /* Check pair reg constraints for instructions taking a pair of
1832
   consecutively-numbered general-purpose registers.  */
1833
3.83M
      else if (type == AARCH64_OPND_PAIRREG
1834
3.83M
         || type == AARCH64_OPND_PAIRREG_OR_XZR)
1835
5.01k
  {
1836
5.01k
    assert (idx == 1 || idx == 2 || idx == 3 || idx == 5);
1837
5.01k
    if (opnds[idx - 1].reg.regno % 2 != 0)
1838
1.71k
      {
1839
1.71k
        set_syntax_error (mismatch_detail, idx - 1,
1840
1.71k
        _("reg pair must start from even reg"));
1841
1.71k
        return false;
1842
1.71k
      }
1843
3.30k
    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.30k
    break;
1850
3.30k
  }
1851
1852
      /* <Xt> may be optional in some IC and TLBI instructions.  */
1853
3.83M
      if (type == AARCH64_OPND_Rt_SYS)
1854
245
  {
1855
245
    assert (idx == 1 && (aarch64_get_operand_class (opnds[0].type)
1856
245
             == AARCH64_OPND_CLASS_SYSTEM));
1857
245
    if (!(opnds[1].present && aarch64_sys_ins_reg_tlbid_xt (opnds[0].sysins_op)))
1858
245
      {
1859
245
        if (opnds[1].present
1860
125
      && !aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
1861
0
    {
1862
0
      set_other_error (mismatch_detail, idx, _("extraneous register"));
1863
0
      return false;
1864
0
    }
1865
245
        if (!opnds[1].present
1866
120
      && 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
245
     }
1872
245
  }
1873
3.83M
      switch (qualifier)
1874
3.83M
  {
1875
2.87k
  case AARCH64_OPND_QLF_WSP:
1876
3.27k
  case AARCH64_OPND_QLF_SP:
1877
3.27k
    if (!aarch64_stack_pointer_p (opnd))
1878
3.03k
      {
1879
3.03k
        set_other_error (mismatch_detail, idx,
1880
3.03k
           _("stack pointer register expected"));
1881
3.03k
        return false;
1882
3.03k
      }
1883
232
    break;
1884
3.82M
  default:
1885
3.82M
    break;
1886
3.83M
  }
1887
3.82M
      break;
1888
1889
3.82M
    case AARCH64_OPND_CLASS_SVE_REG:
1890
1.03M
      switch (type)
1891
1.03M
  {
1892
2.42k
  case AARCH64_OPND_SVE_Zm3_INDEX:
1893
8.41k
  case AARCH64_OPND_SVE_Zm3_22_INDEX:
1894
8.58k
  case AARCH64_OPND_SVE_Zm3_19_INDEX:
1895
12.0k
  case AARCH64_OPND_SVE_Zm3_11_INDEX:
1896
14.1k
  case AARCH64_OPND_SVE_Zm3_10_INDEX:
1897
16.9k
  case AARCH64_OPND_SVE_Zm4_11_INDEX:
1898
20.5k
  case AARCH64_OPND_SVE_Zm4_INDEX:
1899
20.5k
    size = get_operand_fields_width (get_operand_from_code (type));
1900
20.5k
    shift = get_operand_specific_data (&aarch64_operands[type]);
1901
20.5k
    if (!check_reglane (opnd, mismatch_detail, idx,
1902
20.5k
            "z", 0, (1 << shift) - 1,
1903
20.5k
            0, (1u << (size - shift)) - 1))
1904
0
      return false;
1905
20.5k
    break;
1906
1907
20.5k
  case AARCH64_OPND_SVE_Zm1_23_INDEX:
1908
422
    size = get_operand_fields_width (get_operand_from_code (type));
1909
422
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 1))
1910
0
      return 0;
1911
422
    break;
1912
1913
422
  case AARCH64_OPND_SME_Zn_INDEX2_19:
1914
354
  case AARCH64_OPND_SVE_Zm2_22_INDEX:
1915
354
    size = get_operand_fields_width (get_operand_from_code (type));
1916
354
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 3))
1917
0
      return 0;
1918
354
    break;
1919
1920
889
  case AARCH64_OPND_SVE_Zn_INDEX:
1921
889
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1922
889
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1923
889
            0, 64 / size - 1))
1924
0
      return false;
1925
889
    break;
1926
1927
889
  case AARCH64_OPND_SVE_Zn_5_INDEX:
1928
294
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1929
294
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1930
294
            0, 16 / size - 1))
1931
0
      return false;
1932
294
    break;
1933
1934
294
  case AARCH64_OPND_SME_PNn3_INDEX1:
1935
116
  case AARCH64_OPND_SME_PNn3_INDEX2:
1936
116
    size = get_operand_field_width (get_operand_from_code (type), 0);
1937
116
    if (!check_reglane (opnd, mismatch_detail, idx, "pn", 8, 15,
1938
116
            0, (1 << size) - 1))
1939
0
      return false;
1940
116
    break;
1941
1942
534
  case AARCH64_OPND_SVE_Zm3_12_INDEX:
1943
582
  case AARCH64_OPND_SME_Zn_INDEX1_16:
1944
834
  case AARCH64_OPND_SME_Zn_INDEX2_15:
1945
1.15k
  case AARCH64_OPND_SME_Zn_INDEX2_16:
1946
1.30k
  case AARCH64_OPND_SME_Zn_INDEX3_14:
1947
1.53k
  case AARCH64_OPND_SME_Zn_INDEX3_15:
1948
1.65k
  case AARCH64_OPND_SME_Zn_INDEX4_14:
1949
1.69k
  case AARCH64_OPND_SVE_Zn0_INDEX:
1950
1.76k
  case AARCH64_OPND_SVE_Zn1_17_INDEX:
1951
1.78k
  case AARCH64_OPND_SVE_Zn2_18_INDEX:
1952
1.82k
  case AARCH64_OPND_SVE_Zn3_22_INDEX:
1953
1.90k
  case AARCH64_OPND_SVE_Zd0_INDEX:
1954
1.93k
  case AARCH64_OPND_SVE_Zd1_17_INDEX:
1955
1.94k
  case AARCH64_OPND_SVE_Zd2_18_INDEX:
1956
1.96k
  case AARCH64_OPND_SVE_Zd3_22_INDEX:
1957
1.96k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1958
1.96k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1959
1.96k
            0, (1 << size) - 1))
1960
0
      return false;
1961
1.96k
    break;
1962
1963
1.96k
  case AARCH64_OPND_SME_Zm_INDEX1:
1964
962
  case AARCH64_OPND_SME_Zm_INDEX2:
1965
1.01k
  case AARCH64_OPND_SME_Zm_INDEX2_3:
1966
1.88k
  case AARCH64_OPND_SME_Zm_INDEX3_1:
1967
3.38k
  case AARCH64_OPND_SME_Zm_INDEX3_2:
1968
4.01k
  case AARCH64_OPND_SME_Zm_INDEX3_3:
1969
6.54k
  case AARCH64_OPND_SME_Zm_INDEX3_10:
1970
7.95k
  case AARCH64_OPND_SME_Zm_INDEX4_1:
1971
8.41k
  case AARCH64_OPND_SME_Zm_INDEX4_2:
1972
19.7k
  case AARCH64_OPND_SME_Zm_INDEX4_3:
1973
22.9k
  case AARCH64_OPND_SME_Zm_INDEX4_10:
1974
22.9k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1975
22.9k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 15,
1976
22.9k
            0, (1 << size) - 1))
1977
0
      return false;
1978
22.9k
    break;
1979
1980
22.9k
  case AARCH64_OPND_SME_Zk_INDEX:
1981
2.53k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31, 0, 3))
1982
0
      return false;
1983
2.53k
    if ((opnd->reglane.regno & 20) != 20)
1984
0
      {
1985
0
        set_other_error (mismatch_detail, idx,
1986
0
             _("register out of range"));
1987
0
        return false;
1988
0
      }
1989
2.53k
    break;
1990
1991
6.84k
  case AARCH64_OPND_SME_Zm:
1992
6.86k
  case AARCH64_OPND_SME_Zm_17:
1993
6.86k
    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
6.86k
    break;
1999
2000
6.86k
  case AARCH64_OPND_SME_Zn_6_3:
2001
6.79k
    if (opnd->reg.regno > 15 || opnd->reg.regno % 2 != 0)
2002
0
      {
2003
0
        set_other_error (mismatch_detail, idx,
2004
0
             _("register out of range"));
2005
0
        return false;
2006
0
      }
2007
6.79k
    break;
2008
2009
6.79k
  case AARCH64_OPND_SME_Zm_17_3:
2010
6.58k
    if (opnd->reg.regno < 16 || opnd->reg.regno % 2 != 0)
2011
0
      {
2012
0
        set_other_error (mismatch_detail, idx,
2013
0
             _("register out of range"));
2014
0
        return false;
2015
0
      }
2016
6.58k
    break;
2017
2018
6.58k
  case AARCH64_OPND_SME_PnT_Wm_imm:
2019
3.80k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2020
3.80k
    max_value = 16 / size - 1;
2021
3.80k
    if (!check_za_access (opnd, mismatch_detail, idx,
2022
3.80k
        12, max_value, 1, 0, get_opcode_dependent_value (opcode)))
2023
0
      return false;
2024
3.80k
    break;
2025
2026
964k
  default:
2027
964k
    break;
2028
1.03M
  }
2029
1.03M
      break;
2030
2031
1.03M
    case AARCH64_OPND_CLASS_SVE_REGLIST:
2032
235k
      switch (type)
2033
235k
  {
2034
503
  case AARCH64_OPND_SME_Pdx2:
2035
14.3k
  case AARCH64_OPND_SME_Zdnx2:
2036
18.4k
  case AARCH64_OPND_SME_Zdnx4:
2037
18.5k
  case AARCH64_OPND_SME_Znx2_6_3:
2038
18.9k
  case AARCH64_OPND_SME_Zmx2_17_3:
2039
20.0k
  case AARCH64_OPND_SME_Zmx2:
2040
20.2k
  case AARCH64_OPND_SME_Zmx4:
2041
29.4k
  case AARCH64_OPND_SME_Znx2:
2042
29.4k
  case AARCH64_OPND_SME_Znx2_BIT_INDEX:
2043
32.7k
  case AARCH64_OPND_SME_Znx4:
2044
32.7k
    num = get_operand_specific_data (&aarch64_operands[type]);
2045
32.7k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2046
0
      return false;
2047
32.7k
    if (((opnd->reglist.first_regno % num) != 0)
2048
32.7k
        || (type == AARCH64_OPND_SME_Znx2_6_3
2049
177
      && opnd->reglist.first_regno > 15)
2050
32.7k
        || (type == AARCH64_OPND_SME_Zmx2_17_3
2051
379
      && 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
32.7k
    break;
2058
2059
32.7k
  case AARCH64_OPND_SME_Ztx2_STRIDED:
2060
7.20k
  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
7.20k
    num = get_operand_specific_data (&aarch64_operands[type]);
2064
7.20k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 16 / num))
2065
0
      return false;
2066
7.20k
    num = 16 | (opnd->reglist.stride - 1);
2067
7.20k
    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
7.20k
    break;
2074
2075
7.20k
  case AARCH64_OPND_SME_PdxN:
2076
8.90k
  case AARCH64_OPND_SVE_ZnxN:
2077
195k
  case AARCH64_OPND_SVE_ZtxN:
2078
195k
    num = get_opcode_dependent_value (opcode);
2079
195k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2080
0
      return false;
2081
195k
    break;
2082
2083
195k
  case AARCH64_OPND_SME_Zmx2_INDEX_22:
2084
74
    num = get_operand_specific_data (&aarch64_operands[type]);
2085
74
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2086
0
        return false;
2087
74
    break;
2088
2089
74
  case AARCH64_OPND_SME_Zn7xN_UNTYPED:
2090
20
    num = get_opcode_dependent_value (opcode);
2091
20
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2092
0
        return false;
2093
20
    if (opnd->reglist.first_regno > 7)
2094
0
    {
2095
0
      set_other_error (mismatch_detail, idx, _("start register out of range"));
2096
0
      return false;
2097
0
    }
2098
20
    break;
2099
2100
20
  default:
2101
0
    abort ();
2102
235k
  }
2103
235k
      break;
2104
2105
235k
    case AARCH64_OPND_CLASS_ZA_ACCESS:
2106
117k
      switch (type)
2107
117k
  {
2108
558
  case AARCH64_OPND_SME_ZA_HV_idx_src:
2109
48.7k
  case AARCH64_OPND_SME_ZA_HV_idx_dest:
2110
80.0k
  case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
2111
80.0k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2112
80.0k
    max_value = 16 / size - 1;
2113
80.0k
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, 1,
2114
80.0k
        get_opcode_dependent_value (opcode),
2115
80.0k
        get_opcode_dependent_vg_status (opcode)))
2116
0
      return false;
2117
80.0k
    break;
2118
2119
80.0k
  case AARCH64_OPND_SME_ZA_array_off4:
2120
601
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
2121
601
        get_opcode_dependent_value (opcode),
2122
601
        get_opcode_dependent_vg_status (opcode)))
2123
0
      return false;
2124
601
    break;
2125
2126
6.01k
  case AARCH64_OPND_SME_ZA_array_off3_0:
2127
6.58k
  case AARCH64_OPND_SME_ZA_array_off3_5:
2128
6.58k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 1,
2129
6.58k
        get_opcode_dependent_value (opcode),
2130
6.58k
        get_opcode_dependent_vg_status (opcode)))
2131
0
      return false;
2132
6.58k
    break;
2133
2134
6.58k
  case AARCH64_OPND_SME_ZA_array_off1x4:
2135
3.69k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 1, 4,
2136
3.69k
        get_opcode_dependent_value (opcode),
2137
3.69k
        get_opcode_dependent_vg_status (opcode)))
2138
0
      return false;
2139
3.69k
    break;
2140
2141
3.69k
  case AARCH64_OPND_SME_ZA_array_off2x2:
2142
3.42k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 2,
2143
3.42k
        get_opcode_dependent_value (opcode),
2144
3.42k
        get_opcode_dependent_vg_status (opcode)))
2145
0
      return false;
2146
3.42k
    break;
2147
2148
4.10k
  case AARCH64_OPND_SME_ZA_array_off2x4:
2149
4.10k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 4,
2150
4.10k
        get_opcode_dependent_value (opcode),
2151
4.10k
        get_opcode_dependent_vg_status (opcode)))
2152
0
      return false;
2153
4.10k
    break;
2154
2155
13.8k
  case AARCH64_OPND_SME_ZA_array_off3x2:
2156
13.8k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 2,
2157
13.8k
        get_opcode_dependent_value (opcode),
2158
13.8k
        get_opcode_dependent_vg_status (opcode)))
2159
0
      return false;
2160
13.8k
    break;
2161
2162
13.8k
  case AARCH64_OPND_SME_ZA_array_vrsb_1:
2163
114
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 7, 2,
2164
114
        get_opcode_dependent_value (opcode),
2165
114
        get_opcode_dependent_vg_status (opcode)))
2166
0
      return false;
2167
114
    break;
2168
2169
114
  case AARCH64_OPND_SME_ZA_array_vrsh_1:
2170
25
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 3, 2,
2171
25
        get_opcode_dependent_value (opcode),
2172
25
        get_opcode_dependent_vg_status (opcode)))
2173
0
      return false;
2174
25
    break;
2175
2176
25
  case AARCH64_OPND_SME_ZA_array_vrss_1:
2177
0
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 1, 2,
2178
0
        get_opcode_dependent_value (opcode),
2179
0
        get_opcode_dependent_vg_status (opcode)))
2180
0
      return false;
2181
0
    break;
2182
2183
255
  case AARCH64_OPND_SME_ZA_array_vrsd_1:
2184
255
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 0, 2,
2185
255
        get_opcode_dependent_value (opcode),
2186
255
        get_opcode_dependent_vg_status (opcode)))
2187
0
      return false;
2188
255
    break;
2189
2190
255
  case AARCH64_OPND_SME_ZA_array_vrsb_2:
2191
222
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 3, 4,
2192
222
        get_opcode_dependent_value (opcode),
2193
222
        get_opcode_dependent_vg_status (opcode)))
2194
0
      return false;
2195
222
    break;
2196
2197
222
  case AARCH64_OPND_SME_ZA_array_vrsh_2:
2198
28
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 1, 4,
2199
28
        get_opcode_dependent_value (opcode),
2200
28
        get_opcode_dependent_vg_status (opcode)))
2201
0
      return false;
2202
28
    break;
2203
2204
508
  case AARCH64_OPND_SME_ZA_ARRAY4:
2205
508
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
2206
508
        get_opcode_dependent_value (opcode),
2207
508
        get_opcode_dependent_vg_status (opcode)))
2208
0
      return false;
2209
508
    break;
2210
2211
508
  case AARCH64_OPND_SME_ZA_array_vrss_2:
2212
220
  case AARCH64_OPND_SME_ZA_array_vrsd_2:
2213
220
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 0, 4,
2214
220
        get_opcode_dependent_value (opcode),
2215
220
        get_opcode_dependent_vg_status (opcode)))
2216
0
      return false;
2217
220
    break;
2218
2219
1.98k
  case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
2220
3.61k
  case AARCH64_OPND_SME_ZA_HV_idx_destxN:
2221
3.61k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2222
3.61k
    num = get_opcode_dependent_value (opcode);
2223
3.61k
    max_value = 16 / num / size;
2224
3.61k
    if (max_value > 0)
2225
3.31k
      max_value -= 1;
2226
3.61k
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, num,
2227
3.61k
        0, get_opcode_dependent_value (opcode)))
2228
0
      return false;
2229
3.61k
    break;
2230
2231
3.61k
  default:
2232
0
    abort ();
2233
117k
  }
2234
117k
      break;
2235
2236
655k
    case AARCH64_OPND_CLASS_PRED_REG:
2237
655k
      switch (type)
2238
655k
  {
2239
1.15k
  case AARCH64_OPND_SME_PNd3:
2240
20.2k
  case AARCH64_OPND_SME_PNg3:
2241
20.2k
    if (opnd->reg.regno < 8)
2242
0
      {
2243
0
        set_invalid_regno_error (mismatch_detail, idx, "pn", 8, 15);
2244
0
        return false;
2245
0
      }
2246
20.2k
    break;
2247
2248
634k
  default:
2249
634k
    if (opnd->reg.regno >= 8
2250
47.8k
        && 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
634k
    break;
2256
655k
  }
2257
655k
      break;
2258
2259
655k
    case AARCH64_OPND_CLASS_COND:
2260
15.3k
      if (type == AARCH64_OPND_COND1
2261
205
    && (opnds[idx].cond->value & 0xe) == 0xe)
2262
0
  {
2263
    /* Not allow AL or NV.  */
2264
0
    set_syntax_error (mismatch_detail, idx, NULL);
2265
0
  }
2266
15.3k
      break;
2267
2268
2.09M
    case AARCH64_OPND_CLASS_ADDRESS:
2269
      /* Check writeback.  */
2270
2.09M
      switch (opcode->iclass)
2271
2.09M
  {
2272
159k
  case ldst_pos:
2273
214k
  case ldst_unscaled:
2274
307k
  case ldstnapair_offs:
2275
419k
  case ldstpair_off:
2276
427k
  case ldst_unpriv:
2277
427k
    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
427k
    break;
2284
427k
  case ldst_imm10:
2285
7.14k
    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
7.14k
    break;
2292
33.0k
  case ldst_imm9:
2293
189k
  case ldstpair_indexed:
2294
193k
  case asisdlsep:
2295
201k
  case asisdlsop:
2296
201k
    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
201k
    break;
2303
201k
  case rcpc3:
2304
18.4k
    if (opnd->addr.writeback)
2305
1.24k
      if ((type == AARCH64_OPND_RCPC3_ADDR_PREIND_WB
2306
107
     && !opnd->addr.preind)
2307
1.24k
    || (type == AARCH64_OPND_RCPC3_ADDR_POSTIND
2308
36
        && !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
18.4k
    break;
2316
1.44M
  default:
2317
1.44M
    assert (opnd->addr.writeback == 0);
2318
1.44M
    break;
2319
2.09M
  }
2320
2.09M
      switch (type)
2321
2.09M
  {
2322
345k
  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
345k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2328
345k
    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
345k
    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
345k
    break;
2340
345k
  case AARCH64_OPND_ADDR_OFFSET:
2341
91.9k
  case AARCH64_OPND_ADDR_SIMM9:
2342
    /* Unscaled signed 9 bits immediate offset.  */
2343
91.9k
    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
91.9k
    break;
2349
2350
91.9k
  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
7.14k
  case AARCH64_OPND_ADDR_SIMM10:
2363
    /* Scaled signed 10 bits immediate offset.  */
2364
7.14k
    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
7.14k
    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
7.14k
    break;
2375
2376
15.5k
  case AARCH64_OPND_ADDR_SIMM11:
2377
    /* Signed 11 bits immediate offset (multiple of 16).  */
2378
15.5k
    if (!value_in_range_p (opnd->addr.offset.imm, -1024, 1008))
2379
0
      {
2380
0
        set_offset_out_of_range_error (mismatch_detail, idx, -1024, 1008);
2381
0
        return false;
2382
0
      }
2383
2384
15.5k
    if (!value_aligned_p (opnd->addr.offset.imm, 16))
2385
0
      {
2386
0
        set_unaligned_error (mismatch_detail, idx, 16);
2387
0
        return false;
2388
0
      }
2389
15.5k
    break;
2390
2391
15.5k
  case AARCH64_OPND_ADDR_SIMM13:
2392
    /* Signed 13 bits immediate offset (multiple of 16).  */
2393
5.11k
    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.11k
    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.11k
    break;
2405
2406
12.1k
  case AARCH64_OPND_SIMD_ADDR_POST:
2407
    /* AdvSIMD load/store multiple structures, post-index.  */
2408
12.1k
    assert (idx == 1);
2409
12.1k
    if (opnd->addr.offset.is_reg)
2410
10.4k
      {
2411
10.4k
        if (value_in_range_p (opnd->addr.offset.regno, 0, 30))
2412
10.4k
    return true;
2413
0
        else
2414
0
    {
2415
0
      set_other_error (mismatch_detail, idx,
2416
0
           _("invalid register offset"));
2417
0
      return false;
2418
0
    }
2419
10.4k
      }
2420
1.74k
    else
2421
1.74k
      {
2422
1.74k
        const aarch64_opnd_info *prev = &opnds[idx-1];
2423
1.74k
        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
1.74k
        int is_ld1r = get_opcode_dependent_value (opcode) == 1;
2427
1.74k
        if (opcode->operands[0] == AARCH64_OPND_LVt_AL)
2428
    /* Special handling of loading single structure to all lane.  */
2429
366
    num_bytes = (is_ld1r ? 1 : prev->reglist.num_regs)
2430
366
      * aarch64_get_qualifier_esize (prev->qualifier);
2431
1.38k
        else
2432
1.38k
    num_bytes = prev->reglist.num_regs
2433
1.38k
      * aarch64_get_qualifier_esize (prev->qualifier)
2434
1.38k
      * aarch64_get_qualifier_nelem (prev->qualifier);
2435
1.74k
        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
1.74k
      }
2442
1.74k
    break;
2443
2444
45.4k
  case AARCH64_OPND_ADDR_REGOFF:
2445
    /* Get the size of the data element that is accessed, which may be
2446
       different from that of the source register size,
2447
       e.g. in strb/ldrb.  */
2448
45.4k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2449
    /* It is either no shift or shift by the binary logarithm of SIZE.  */
2450
45.4k
    if (opnd->shifter.amount != 0
2451
26.3k
        && opnd->shifter.amount != (int)get_logsz (size))
2452
0
      {
2453
0
        set_other_error (mismatch_detail, idx,
2454
0
             _("invalid shift amount"));
2455
0
        return false;
2456
0
      }
2457
    /* Only UXTW, LSL, SXTW and SXTX are the accepted extending
2458
       operators.  */
2459
45.4k
    switch (opnd->shifter.kind)
2460
45.4k
      {
2461
1.43k
      case AARCH64_MOD_UXTW:
2462
11.9k
      case AARCH64_MOD_LSL:
2463
13.6k
      case AARCH64_MOD_SXTW:
2464
16.7k
      case AARCH64_MOD_SXTX: break;
2465
28.6k
      default:
2466
28.6k
        set_other_error (mismatch_detail, idx,
2467
28.6k
             _("invalid extend/shift operator"));
2468
28.6k
        return false;
2469
45.4k
      }
2470
16.7k
    break;
2471
2472
159k
  case AARCH64_OPND_ADDR_UIMM12:
2473
159k
    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
159k
    size = aarch64_get_qualifier_esize (qualifier);
2478
159k
    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
159k
    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
159k
    break;
2490
2491
159k
  case AARCH64_OPND_ADDR_PCREL9:
2492
195k
  case AARCH64_OPND_ADDR_PCREL14:
2493
481k
  case AARCH64_OPND_ADDR_PCREL19:
2494
705k
  case AARCH64_OPND_ADDR_PCREL21:
2495
866k
  case AARCH64_OPND_ADDR_PCREL26:
2496
866k
    {
2497
866k
      imm = opnd->imm.value;
2498
866k
      if (operand_need_shift_by_two (get_operand_from_code (type)))
2499
643k
        {
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
643k
    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
643k
    imm >>= 2;
2510
643k
        }
2511
2512
866k
      if (!check_immediate_out_of_range (imm, type, mismatch_detail, idx))
2513
0
        return false;
2514
866k
    }
2515
866k
    break;
2516
2517
866k
  case AARCH64_OPND_SME_ADDR_RI_U4xVL:
2518
601
    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
601
    break;
2524
2525
43.2k
  case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
2526
50.5k
  case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
2527
52.9k
  case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
2528
58.9k
  case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
2529
58.9k
    min_value = -8;
2530
58.9k
    max_value = 7;
2531
65.5k
  sve_imm_offset_vl:
2532
65.5k
    assert (!opnd->addr.offset.is_reg);
2533
65.5k
    assert (opnd->addr.preind);
2534
65.5k
    num = 1 + get_operand_specific_data (&aarch64_operands[type]);
2535
65.5k
    min_value *= num;
2536
65.5k
    max_value *= num;
2537
65.5k
    if ((opnd->addr.offset.imm != 0 && !opnd->shifter.operator_present)
2538
65.5k
        || (opnd->shifter.operator_present
2539
60.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
65.5k
    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
65.5k
    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
65.5k
    break;
2557
2558
65.5k
  case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
2559
1.80k
    min_value = -32;
2560
1.80k
    max_value = 31;
2561
1.80k
    goto sve_imm_offset_vl;
2562
2563
4.75k
  case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
2564
4.75k
    min_value = -256;
2565
4.75k
    max_value = 255;
2566
4.75k
    goto sve_imm_offset_vl;
2567
2568
2.77k
  case AARCH64_OPND_SVE_ADDR_RI_U6:
2569
6.75k
  case AARCH64_OPND_SVE_ADDR_RI_U6x2:
2570
8.22k
  case AARCH64_OPND_SVE_ADDR_RI_U6x4:
2571
9.21k
  case AARCH64_OPND_SVE_ADDR_RI_U6x8:
2572
9.21k
    min_value = 0;
2573
9.21k
    max_value = 63;
2574
22.2k
  sve_imm_offset:
2575
22.2k
    assert (!opnd->addr.offset.is_reg);
2576
22.2k
    assert (opnd->addr.preind);
2577
22.2k
    num = 1 << get_operand_specific_data (&aarch64_operands[type]);
2578
22.2k
    min_value *= num;
2579
22.2k
    max_value *= num;
2580
22.2k
    if (opnd->shifter.operator_present
2581
22.2k
        || opnd->shifter.amount_present)
2582
0
      {
2583
0
        set_other_error (mismatch_detail, idx,
2584
0
             _("invalid addressing mode"));
2585
0
        return false;
2586
0
      }
2587
22.2k
    if (!value_in_range_p (opnd->addr.offset.imm, min_value, max_value))
2588
0
      {
2589
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2590
0
               min_value, max_value);
2591
0
        return false;
2592
0
      }
2593
22.2k
    if (!value_aligned_p (opnd->addr.offset.imm, num))
2594
0
      {
2595
0
        set_unaligned_error (mismatch_detail, idx, num);
2596
0
        return false;
2597
0
      }
2598
22.2k
    break;
2599
2600
22.2k
  case AARCH64_OPND_SVE_ADDR_RI_S4x16:
2601
2.31k
  case AARCH64_OPND_SVE_ADDR_RI_S4x32:
2602
2.31k
    min_value = -8;
2603
2.31k
    max_value = 7;
2604
2.31k
    goto sve_imm_offset;
2605
2606
9.41k
  case AARCH64_OPND_SVE_ADDR_ZX:
2607
    /* Everything is already ensured by parse_operands or
2608
       aarch64_ext_sve_addr_rr_lsl (because this is a very specific
2609
       argument type).  */
2610
9.41k
    assert (opnd->addr.offset.is_reg);
2611
9.41k
    assert (opnd->addr.preind);
2612
9.41k
    assert ((aarch64_operands[type].flags & OPD_F_NO_ZR) == 0);
2613
9.41k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2614
9.41k
    assert (opnd->shifter.operator_present == 0);
2615
9.41k
    break;
2616
2617
9.41k
  case AARCH64_OPND_SVE_ADDR_RR:
2618
13.1k
  case AARCH64_OPND_SVE_ADDR_RR_LSL1:
2619
16.3k
  case AARCH64_OPND_SVE_ADDR_RR_LSL2:
2620
29.7k
  case AARCH64_OPND_SVE_ADDR_RR_LSL3:
2621
39.6k
  case AARCH64_OPND_SVE_ADDR_RR_LSL4:
2622
45.5k
  case AARCH64_OPND_SVE_ADDR_RM:
2623
48.2k
  case AARCH64_OPND_SVE_ADDR_RM_LSL1:
2624
50.2k
  case AARCH64_OPND_SVE_ADDR_RM_LSL2:
2625
52.8k
  case AARCH64_OPND_SVE_ADDR_RM_LSL3:
2626
52.8k
  case AARCH64_OPND_SVE_ADDR_RM_LSL4:
2627
64.1k
  case AARCH64_OPND_SVE_ADDR_RX:
2628
71.2k
  case AARCH64_OPND_SVE_ADDR_RX_LSL1:
2629
76.9k
  case AARCH64_OPND_SVE_ADDR_RX_LSL2:
2630
81.0k
  case AARCH64_OPND_SVE_ADDR_RX_LSL3:
2631
83.9k
  case AARCH64_OPND_SVE_ADDR_RX_LSL4:
2632
106k
  case AARCH64_OPND_SVE_ADDR_RZ:
2633
108k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
2634
109k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
2635
111k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
2636
111k
    modifiers = 1 << AARCH64_MOD_LSL;
2637
157k
  sve_rr_operand:
2638
157k
    assert (opnd->addr.offset.is_reg);
2639
157k
    assert (opnd->addr.preind);
2640
157k
    if ((aarch64_operands[type].flags & OPD_F_NO_ZR) != 0
2641
31.0k
        && 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
157k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2648
157k
        || (opnd->shifter.amount
2649
157k
      != 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
157k
    break;
2656
2657
157k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
2658
29.0k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
2659
30.1k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
2660
35.6k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
2661
36.5k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
2662
41.0k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
2663
41.3k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
2664
46.1k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
2665
46.1k
    modifiers = (1 << AARCH64_MOD_SXTW) | (1 << AARCH64_MOD_UXTW);
2666
46.1k
    goto sve_rr_operand;
2667
2668
3.34k
  case AARCH64_OPND_SVE_ADDR_ZI_U5:
2669
7.80k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
2670
9.90k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
2671
10.7k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
2672
10.7k
    min_value = 0;
2673
10.7k
    max_value = 31;
2674
10.7k
    goto sve_imm_offset;
2675
2676
887
  case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
2677
887
    modifiers = 1 << AARCH64_MOD_LSL;
2678
1.81k
  sve_zz_operand:
2679
1.81k
    assert (opnd->addr.offset.is_reg);
2680
1.81k
    assert (opnd->addr.preind);
2681
1.81k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2682
1.81k
        || opnd->shifter.amount < 0
2683
1.81k
        || opnd->shifter.amount > 3)
2684
0
      {
2685
0
        set_other_error (mismatch_detail, idx,
2686
0
             _("invalid addressing mode"));
2687
0
        return false;
2688
0
      }
2689
1.81k
    break;
2690
2691
1.81k
  case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
2692
158
    modifiers = (1 << AARCH64_MOD_SXTW);
2693
158
    goto sve_zz_operand;
2694
2695
766
  case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
2696
766
    modifiers = 1 << AARCH64_MOD_UXTW;
2697
766
    goto sve_zz_operand;
2698
2699
12.6k
  case AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB:
2700
13.3k
  case AARCH64_OPND_RCPC3_ADDR_OPT_POSTIND:
2701
13.4k
  case AARCH64_OPND_RCPC3_ADDR_PREIND_WB:
2702
13.5k
  case AARCH64_OPND_RCPC3_ADDR_POSTIND:
2703
13.5k
    {
2704
13.5k
      int num_bytes = calc_ldst_datasize (opnds);
2705
13.5k
      int abs_offset = (type == AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB
2706
809
            || type == AARCH64_OPND_RCPC3_ADDR_PREIND_WB)
2707
13.5k
        ? opnd->addr.offset.imm * -1
2708
13.5k
        : opnd->addr.offset.imm;
2709
13.5k
      if ((int) num_bytes != abs_offset
2710
12.2k
    && 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
13.5k
    }
2717
13.5k
    break;
2718
2719
13.5k
  case AARCH64_OPND_RCPC3_ADDR_OFFSET:
2720
4.93k
    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
279k
  default:
2727
279k
    break;
2728
2.09M
  }
2729
2.05M
      break;
2730
2731
2.05M
    case AARCH64_OPND_CLASS_SIMD_REGLIST:
2732
37.6k
      if (type == AARCH64_OPND_LEt)
2733
12.4k
  {
2734
    /* Get the upper bound for the element index.  */
2735
12.4k
    num = 16 / aarch64_get_qualifier_esize (qualifier) - 1;
2736
12.4k
    if (!value_in_range_p (opnd->reglist.index, 0, num))
2737
0
      {
2738
0
        set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
2739
0
        return false;
2740
0
      }
2741
12.4k
  }
2742
      /* The opcode dependent area stores the number of elements in
2743
   each structure to be loaded/stored.  */
2744
37.6k
      num = get_opcode_dependent_value (opcode);
2745
37.6k
      switch (type)
2746
37.6k
  {
2747
2.51k
  case AARCH64_OPND_LVn_LUT:
2748
2.51k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2749
0
      return 0;
2750
2.51k
    break;
2751
9.88k
  case AARCH64_OPND_LVt:
2752
9.88k
    assert (num >= 1 && num <= 4);
2753
    /* Unless LD1/ST1, the number of registers should be equal to that
2754
       of the structure elements.  */
2755
9.88k
    if (num != 1 && !check_reglist (opnd, mismatch_detail, idx, num, 1))
2756
526
      return false;
2757
9.35k
    break;
2758
9.35k
  case AARCH64_OPND_LVt_AL:
2759
13.8k
  case AARCH64_OPND_LEt:
2760
13.8k
    assert (num >= 1 && num <= 4);
2761
    /* The number of registers should be equal to that of the structure
2762
       elements.  */
2763
13.8k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2764
0
      return false;
2765
13.8k
    break;
2766
13.8k
  default:
2767
11.4k
    break;
2768
37.6k
  }
2769
37.1k
      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
37.1k
      break;
2775
2776
2.19M
    case AARCH64_OPND_CLASS_IMMEDIATE:
2777
      /* Constraint check on immediate operand.  */
2778
2.19M
      imm = opnd->imm.value;
2779
      /* E.g. imm_0_31 constrains value to be 0..31.  */
2780
2.19M
      if (qualifier_value_in_range_constraint_p (qualifier)
2781
284k
    && !value_in_range_p (imm, get_lower_bound (qualifier),
2782
284k
        get_upper_bound (qualifier)))
2783
30.8k
  {
2784
30.8k
    set_imm_out_of_range_error (mismatch_detail, idx,
2785
30.8k
              get_lower_bound (qualifier),
2786
30.8k
              get_upper_bound (qualifier));
2787
30.8k
    return false;
2788
30.8k
  }
2789
2790
2.16M
      switch (type)
2791
2.16M
  {
2792
259k
  case AARCH64_OPND_AIMM:
2793
259k
    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
259k
    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
259k
    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
259k
    break;
2812
2813
259k
  case AARCH64_OPND_HALF:
2814
66.0k
    assert (idx == 1 && opnds[0].type == AARCH64_OPND_Rd);
2815
66.0k
    if (opnd->shifter.kind != AARCH64_MOD_LSL)
2816
0
      {
2817
0
        set_other_error (mismatch_detail, idx,
2818
0
             _("invalid shift operator"));
2819
0
        return false;
2820
0
      }
2821
66.0k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2822
66.0k
    if (!value_aligned_p (opnd->shifter.amount, 16))
2823
0
      {
2824
0
        set_other_error (mismatch_detail, idx,
2825
0
             _("shift amount must be a multiple of 16"));
2826
0
        return false;
2827
0
      }
2828
66.0k
    if (!value_in_range_p (opnd->shifter.amount, 0, size * 8 - 16))
2829
13.2k
      {
2830
13.2k
        set_sft_amount_out_of_range_error (mismatch_detail, idx,
2831
13.2k
             0, size * 8 - 16);
2832
13.2k
        return false;
2833
13.2k
      }
2834
52.7k
    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
52.7k
    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
52.7k
    break;
2847
2848
52.7k
  case AARCH64_OPND_IMM_MOV:
2849
33.1k
      {
2850
33.1k
        int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2851
33.1k
        imm = opnd->imm.value;
2852
33.1k
        assert (idx == 1);
2853
33.1k
        switch (opcode->op)
2854
33.1k
    {
2855
19.4k
    case OP_MOV_IMM_WIDEN:
2856
19.4k
      imm = ~imm;
2857
      /* Fall through.  */
2858
32.5k
    case OP_MOV_IMM_WIDE:
2859
32.5k
      if (!aarch64_wide_constant_p (imm, esize == 4, NULL))
2860
0
        {
2861
0
          set_other_error (mismatch_detail, idx,
2862
0
               _("immediate out of range"));
2863
0
          return false;
2864
0
        }
2865
32.5k
      break;
2866
32.5k
    case OP_MOV_IMM_LOG:
2867
539
      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
539
      break;
2874
539
    default:
2875
0
      assert (0);
2876
0
      return false;
2877
33.1k
    }
2878
33.1k
      }
2879
33.1k
    break;
2880
2881
33.1k
  case AARCH64_OPND_NZCV:
2882
6.59k
  case AARCH64_OPND_CCMP_IMM:
2883
7.31k
  case AARCH64_OPND_EXCEPTION:
2884
1.20M
  case AARCH64_OPND_UNDEFINED:
2885
1.20M
  case AARCH64_OPND_TME_UIMM16:
2886
1.20M
  case AARCH64_OPND_UIMM4:
2887
1.20M
  case AARCH64_OPND_UIMM4_ADDG:
2888
1.20M
  case AARCH64_OPND_UIMM7:
2889
1.21M
  case AARCH64_OPND_UIMM3_OP1:
2890
1.21M
  case AARCH64_OPND_UIMM3_OP2:
2891
1.21M
  case AARCH64_OPND_SVE_UIMM3:
2892
1.23M
  case AARCH64_OPND_SVE_UIMM7:
2893
1.23M
  case AARCH64_OPND_SVE_UIMM8:
2894
1.23M
  case AARCH64_OPND_SVE_UIMM4:
2895
1.23M
  case AARCH64_OPND_SVE_UIMM8_53:
2896
1.23M
  case AARCH64_OPND_CSSC_UIMM8:
2897
1.23M
    size = get_operand_fields_width (get_operand_from_code (type));
2898
1.23M
    assert (size < 32);
2899
1.23M
    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.23M
    break;
2906
2907
1.23M
  case AARCH64_OPND_UIMM10:
2908
    /* Scaled unsigned 10 bits immediate offset.  */
2909
2.03k
    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.03k
    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.03k
    break;
2921
2922
7.95k
  case AARCH64_OPND_SIMM5:
2923
8.25k
  case AARCH64_OPND_SVE_SIMM5:
2924
8.45k
  case AARCH64_OPND_SVE_SIMM5B:
2925
9.03k
  case AARCH64_OPND_SVE_SIMM6:
2926
9.41k
  case AARCH64_OPND_SVE_SIMM8:
2927
10.8k
  case AARCH64_OPND_CSSC_SIMM8:
2928
10.8k
    size = get_operand_fields_width (get_operand_from_code (type));
2929
10.8k
    assert (size < 32);
2930
10.8k
    if (!value_fit_signed_field_p (opnd->imm.value, size))
2931
0
      {
2932
0
        imm_range_t rng = imm_range_min_max (size, true);
2933
0
        set_imm_out_of_range_error (mismatch_detail, idx, rng.min,
2934
0
            rng.max);
2935
0
        return false;
2936
0
      }
2937
10.8k
    break;
2938
2939
20.6k
  case AARCH64_OPND_WIDTH:
2940
20.6k
    assert (idx > 1 && opnds[idx-1].type == AARCH64_OPND_IMM
2941
20.6k
      && opnds[0].type == AARCH64_OPND_Rd);
2942
20.6k
    size = get_upper_bound (qualifier);
2943
20.6k
    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
20.6k
    break;
2951
2952
194k
  case AARCH64_OPND_LIMM:
2953
220k
  case AARCH64_OPND_SVE_LIMM:
2954
220k
    {
2955
220k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2956
220k
      uint64_t uimm = opnd->imm.value;
2957
220k
      if (opcode->op == OP_BIC)
2958
0
        uimm = ~uimm;
2959
220k
      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
220k
    }
2966
220k
    break;
2967
2968
220k
  case AARCH64_OPND_IMM0:
2969
358
  case AARCH64_OPND_FPIMM0:
2970
358
    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
358
    break;
2977
2978
592
  case AARCH64_OPND_IMM_ROT1:
2979
10.8k
  case AARCH64_OPND_IMM_ROT2:
2980
16.0k
  case AARCH64_OPND_SVE_IMM_ROT2:
2981
16.0k
    if (opnd->imm.value != 0
2982
11.8k
        && opnd->imm.value != 90
2983
7.90k
        && opnd->imm.value != 180
2984
5.22k
        && opnd->imm.value != 270)
2985
0
      {
2986
0
        set_other_error (mismatch_detail, idx,
2987
0
             _("rotate expected to be 0, 90, 180 or 270"));
2988
0
        return false;
2989
0
      }
2990
16.0k
    break;
2991
2992
16.0k
  case AARCH64_OPND_IMM_ROT3:
2993
492
  case AARCH64_OPND_SVE_IMM_ROT1:
2994
538
  case AARCH64_OPND_SVE_IMM_ROT3:
2995
538
    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
538
    break;
3002
3003
538
  case AARCH64_OPND_SHLL_IMM:
3004
131
    assert (idx == 2);
3005
131
    size = 8 * aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
3006
131
    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
131
    break;
3013
3014
5.81k
  case AARCH64_OPND_IMM_VLSL:
3015
5.81k
    size = aarch64_get_qualifier_esize (qualifier);
3016
5.81k
    if (!value_in_range_p (opnd->imm.value, 0, size * 8 - 1))
3017
0
      {
3018
0
        set_imm_out_of_range_error (mismatch_detail, idx, 0,
3019
0
            size * 8 - 1);
3020
0
        return false;
3021
0
      }
3022
5.81k
    break;
3023
3024
9.32k
  case AARCH64_OPND_IMM_VLSR:
3025
9.32k
    size = aarch64_get_qualifier_esize (qualifier);
3026
9.32k
    if (!value_in_range_p (opnd->imm.value, 1, size * 8))
3027
0
      {
3028
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, size * 8);
3029
0
        return false;
3030
0
      }
3031
9.32k
    break;
3032
3033
9.32k
  case AARCH64_OPND_SIMD_IMM:
3034
2.85k
  case AARCH64_OPND_SIMD_IMM_SFT:
3035
    /* Qualifier check.  */
3036
2.85k
    switch (qualifier)
3037
2.85k
      {
3038
1.89k
      case AARCH64_OPND_QLF_LSL:
3039
1.89k
        if (opnd->shifter.kind != AARCH64_MOD_LSL)
3040
0
    {
3041
0
      set_other_error (mismatch_detail, idx,
3042
0
           _("invalid shift operator"));
3043
0
      return false;
3044
0
    }
3045
1.89k
        break;
3046
1.89k
      case AARCH64_OPND_QLF_MSL:
3047
265
        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
265
        break;
3054
700
      case AARCH64_OPND_QLF_NIL:
3055
700
        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
700
        break;
3062
700
      default:
3063
0
        assert (0);
3064
0
        return false;
3065
2.85k
      }
3066
    /* Is the immediate valid?  */
3067
2.85k
    assert (idx == 1);
3068
2.85k
    if (aarch64_get_qualifier_esize (opnds[0].qualifier) != 8)
3069
2.15k
      {
3070
        /* uimm8 or simm8 */
3071
2.15k
        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.15k
      }
3077
700
    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
2.85k
    switch (opnd->shifter.kind)
3088
2.85k
      {
3089
1.89k
      case AARCH64_MOD_LSL:
3090
1.89k
        size = aarch64_get_qualifier_esize (opnds[0].qualifier);
3091
1.89k
        if (!value_in_range_p (opnd->shifter.amount, 0, (size - 1) * 8))
3092
0
    {
3093
0
      set_sft_amount_out_of_range_error (mismatch_detail, idx, 0,
3094
0
                 (size - 1) * 8);
3095
0
      return false;
3096
0
    }
3097
1.89k
        if (!value_aligned_p (opnd->shifter.amount, 8))
3098
0
    {
3099
0
      set_unaligned_error (mismatch_detail, idx, 8);
3100
0
      return false;
3101
0
    }
3102
1.89k
        break;
3103
1.89k
      case AARCH64_MOD_MSL:
3104
        /* Only 8 and 16 are valid shift amount.  */
3105
265
        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
265
        break;
3112
700
      default:
3113
700
        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
700
        break;
3120
2.85k
      }
3121
2.85k
    break;
3122
3123
2.85k
  case AARCH64_OPND_FPIMM:
3124
1.69k
  case AARCH64_OPND_SIMD_FPIMM:
3125
2.26k
  case AARCH64_OPND_SVE_FPIMM8:
3126
2.26k
    if (opnd->imm.is_fp == 0)
3127
0
      {
3128
0
        set_other_error (mismatch_detail, idx,
3129
0
             _("floating-point immediate expected"));
3130
0
        return false;
3131
0
      }
3132
    /* The value is expected to be an 8-bit floating-point constant with
3133
       sign, 3-bit exponent and normalized 4 bits of precision, encoded
3134
       in "a:b:c:d:e:f:g:h" or FLD_imm8 (depending on the type of the
3135
       instruction).  */
3136
2.26k
    if (!value_in_range_p (opnd->imm.value, 0, 255))
3137
0
      {
3138
0
        set_other_error (mismatch_detail, idx,
3139
0
             _("immediate out of range"));
3140
0
        return false;
3141
0
      }
3142
2.26k
    if (opnd->shifter.kind != AARCH64_MOD_NONE)
3143
0
      {
3144
0
        set_other_error (mismatch_detail, idx,
3145
0
             _("invalid shift operator"));
3146
0
        return false;
3147
0
      }
3148
2.26k
    break;
3149
3150
2.26k
  case AARCH64_OPND_SVE_AIMM:
3151
1.73k
    min_value = 0;
3152
13.0k
  sve_aimm:
3153
13.0k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
3154
13.0k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
3155
13.0k
    mask = ~((uint64_t) -1 << (size * 4) << (size * 4));
3156
13.0k
    uvalue = opnd->imm.value;
3157
13.0k
    shift = opnd->shifter.amount;
3158
13.0k
    if (size == 1)
3159
3.35k
      {
3160
3.35k
        if (shift != 0)
3161
91
    {
3162
91
      set_other_error (mismatch_detail, idx,
3163
91
           _("no shift amount allowed for"
3164
91
             " 8-bit constants"));
3165
91
      return false;
3166
91
    }
3167
3.35k
      }
3168
9.72k
    else
3169
9.72k
      {
3170
9.72k
        if (shift != 0 && shift != 8)
3171
0
    {
3172
0
      set_other_error (mismatch_detail, idx,
3173
0
           _("shift amount must be 0 or 8"));
3174
0
      return false;
3175
0
    }
3176
9.72k
        if (shift == 0 && (uvalue & 0xff) == 0)
3177
4.38k
    {
3178
4.38k
      shift = 8;
3179
4.38k
      uvalue = (int64_t) uvalue / 256;
3180
4.38k
    }
3181
9.72k
      }
3182
12.9k
    mask >>= shift;
3183
12.9k
    if ((uvalue & mask) != uvalue && (uvalue | ~mask) != uvalue)
3184
923
      {
3185
923
        set_other_error (mismatch_detail, idx,
3186
923
             _("immediate too big for element size"));
3187
923
        return false;
3188
923
      }
3189
12.0k
    uvalue = (uvalue - min_value) & mask;
3190
12.0k
    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.0k
    break;
3197
3198
12.0k
  case AARCH64_OPND_SVE_ASIMM:
3199
11.3k
    min_value = -128;
3200
11.3k
    goto sve_aimm;
3201
3202
36
  case AARCH64_OPND_SVE_I1_HALF_ONE:
3203
36
    assert (opnd->imm.is_fp);
3204
36
    if (opnd->imm.value != 0x3f000000 && opnd->imm.value != 0x3f800000)
3205
0
      {
3206
0
        set_other_error (mismatch_detail, idx,
3207
0
             _("floating-point value must be 0.5 or 1.0"));
3208
0
        return false;
3209
0
      }
3210
36
    break;
3211
3212
210
  case AARCH64_OPND_SVE_I1_HALF_TWO:
3213
210
    assert (opnd->imm.is_fp);
3214
210
    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
210
    break;
3221
3222
919
  case AARCH64_OPND_SVE_I1_ZERO_ONE:
3223
919
    assert (opnd->imm.is_fp);
3224
919
    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
919
    break;
3231
3232
919
  case AARCH64_OPND_SVE_INV_LIMM:
3233
0
    {
3234
0
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
3235
0
      uint64_t uimm = ~opnd->imm.value;
3236
0
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
3237
0
        {
3238
0
    set_other_error (mismatch_detail, idx,
3239
0
         _("immediate out of range"));
3240
0
    return false;
3241
0
        }
3242
0
    }
3243
0
    break;
3244
3245
1.90k
  case AARCH64_OPND_SVE_LIMM_MOV:
3246
1.90k
    {
3247
1.90k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
3248
1.90k
      uint64_t uimm = opnd->imm.value;
3249
1.90k
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
3250
0
        {
3251
0
    set_other_error (mismatch_detail, idx,
3252
0
         _("immediate out of range"));
3253
0
    return false;
3254
0
        }
3255
1.90k
      if (!aarch64_sve_dupm_mov_immediate_p (uimm, esize))
3256
0
        {
3257
0
    set_other_error (mismatch_detail, idx,
3258
0
         _("invalid replicated MOV immediate"));
3259
0
    return false;
3260
0
        }
3261
1.90k
    }
3262
1.90k
    break;
3263
3264
5.23k
  case AARCH64_OPND_SVE_PATTERN_SCALED:
3265
5.23k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL);
3266
5.23k
    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.23k
    break;
3272
3273
5.23k
  case AARCH64_OPND_SVE_SHLIMM_PRED:
3274
1.23k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED:
3275
1.71k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
3276
1.71k
    size = aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
3277
1.71k
    if (!value_in_range_p (opnd->imm.value, 0, 8 * size - 1))
3278
0
      {
3279
0
        set_imm_out_of_range_error (mismatch_detail, idx,
3280
0
            0, 8 * size - 1);
3281
0
        return false;
3282
0
      }
3283
1.71k
    break;
3284
3285
1.71k
  case AARCH64_OPND_SME_SHRIMM3:
3286
252
  case AARCH64_OPND_SME_SHRIMM4:
3287
252
    size = 1 << get_operand_fields_width (get_operand_from_code (type));
3288
252
    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
252
    break;
3294
3295
252
  case AARCH64_OPND_SME_SHRIMM5:
3296
1.44k
  case AARCH64_OPND_SVE_SHRIMM_PRED:
3297
2.64k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED:
3298
5.87k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
3299
5.87k
    num = (type == AARCH64_OPND_SVE_SHRIMM_UNPRED_22) ? 2 : 1;
3300
5.87k
    size = aarch64_get_qualifier_esize (opnds[idx - num].qualifier);
3301
5.87k
    if (!value_in_range_p (opnd->imm.value, 1, 8 * size))
3302
0
      {
3303
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, 8*size);
3304
0
        return false;
3305
0
      }
3306
5.87k
    break;
3307
3308
5.87k
  case AARCH64_OPND_SME_ZT0_INDEX:
3309
80
    if (!value_in_range_p (opnd->imm.value, 0, 56))
3310
0
      {
3311
0
        set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, 56);
3312
0
        return false;
3313
0
      }
3314
80
    if (opnd->imm.value % 8 != 0)
3315
0
      {
3316
0
        set_other_error (mismatch_detail, idx,
3317
0
             _("byte index must be a multiple of 8"));
3318
0
        return false;
3319
0
      }
3320
80
    break;
3321
3322
80
  case AARCH64_OPND_SME_ZT0_INDEX_MUL_VL:
3323
63
    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
63
    break;
3329
3330
244k
  default:
3331
244k
    break;
3332
2.16M
  }
3333
2.14M
      break;
3334
3335
2.14M
    case AARCH64_OPND_CLASS_SYSTEM:
3336
38.3k
      switch (type)
3337
38.3k
  {
3338
103
  case AARCH64_OPND_PSTATEFIELD:
3339
334
    for (i = 0; aarch64_pstatefields[i].name; ++i)
3340
334
      if (aarch64_pstatefields[i].value == opnd->pstatefield)
3341
103
        break;
3342
103
    assert (aarch64_pstatefields[i].name);
3343
103
    assert (idx == 0 && opnds[1].type == AARCH64_OPND_UIMM4);
3344
103
    max_value = F_GET_REG_MAX_VALUE (aarch64_pstatefields[i].flags);
3345
103
    if (opnds[1].imm.value < 0 || opnds[1].imm.value > max_value)
3346
26
      {
3347
26
        set_imm_out_of_range_error (mismatch_detail, 1, 0, max_value);
3348
26
        return false;
3349
26
      }
3350
77
    break;
3351
27.6k
  case AARCH64_OPND_PRFOP:
3352
27.6k
    if (opcode->iclass == ldst_regoff && opnd->prfop->value >= 24)
3353
481
      {
3354
481
        set_other_error (mismatch_detail, idx,
3355
481
             _("the register-index form of PRFM does"
3356
481
         " not accept opcodes in the range 24-31"));
3357
481
        return false;
3358
481
      }
3359
27.1k
    break;
3360
27.1k
  default:
3361
10.5k
    break;
3362
38.3k
  }
3363
37.8k
      break;
3364
3365
68.1k
    case AARCH64_OPND_CLASS_SIMD_ELEMENT:
3366
      /* Get the upper bound for the element index.  */
3367
68.1k
      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
4.85k
  num = aarch64_get_qualifier_nelem (opnds[0].qualifier)
3371
4.85k
        * aarch64_get_qualifier_esize (opnds[0].qualifier) / 2;
3372
63.3k
      else if (opcode->iclass == lut)
3373
2.51k
  {
3374
2.51k
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
3375
2.51k
    if (!check_reglane (opnd, mismatch_detail, idx, "v", 0, 31,
3376
2.51k
            0, (1 << size) - 1))
3377
0
      return 0;
3378
2.51k
    break;
3379
2.51k
  }
3380
60.8k
      else
3381
60.8k
  num = 16;
3382
65.6k
      num = num / aarch64_get_qualifier_esize (qualifier) - 1;
3383
65.6k
      assert (aarch64_get_qualifier_nelem (qualifier) == 1);
3384
3385
      /* Index out-of-range.  */
3386
65.6k
      if (!value_in_range_p (opnd->reglane.index, 0, num))
3387
424
  {
3388
424
    set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
3389
424
    return false;
3390
424
  }
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
65.2k
      if (type == AARCH64_OPND_Em16
3400
29.7k
    && (qualifier == AARCH64_OPND_QLF_S_H
3401
6.26k
        || qualifier == AARCH64_OPND_QLF_S_2B)
3402
25.3k
    && !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
65.2k
      if (type == AARCH64_OPND_Em8
3408
2.45k
    && !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
65.2k
      break;
3414
3415
383k
    case AARCH64_OPND_CLASS_MODIFIED_REG:
3416
383k
      assert (idx == 1 || idx == 2);
3417
383k
      switch (type)
3418
383k
  {
3419
38.5k
  case AARCH64_OPND_Rm_EXT:
3420
38.5k
    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
38.5k
    if (!aarch64_stack_pointer_p (opnds + 0)
3432
37.8k
        && (idx != 2 || !aarch64_stack_pointer_p (opnds + 1)))
3433
35.9k
      {
3434
35.9k
        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
35.9k
        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
35.9k
      }
3447
38.5k
    assert (opnd->shifter.operator_present  /* Default to LSL.  */
3448
38.5k
      || opnd->shifter.kind == AARCH64_MOD_LSL);
3449
38.5k
    if (!value_in_range_p (opnd->shifter.amount, 0, 4))
3450
5.22k
      {
3451
5.22k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, 4);
3452
5.22k
        return false;
3453
5.22k
      }
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
33.2k
    if (qualifier == AARCH64_OPND_QLF_X
3460
2.59k
        && opnd->shifter.kind != AARCH64_MOD_LSL
3461
2.59k
        && opnd->shifter.kind != AARCH64_MOD_UXTX
3462
1.35k
        && 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
33.2k
    break;
3468
3469
344k
  case AARCH64_OPND_Rm_SFT:
3470
    /* ROR is not available to the shifted register operand in
3471
       arithmetic instructions.  */
3472
344k
    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
344k
    if (opnd->shifter.kind == AARCH64_MOD_ROR
3479
54.0k
        && 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
344k
    num = qualifier == AARCH64_OPND_QLF_W ? 31 : 63;
3486
344k
    if (!value_in_range_p (opnd->shifter.amount, 0, num))
3487
43.9k
      {
3488
43.9k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, num);
3489
43.9k
        return false;
3490
43.9k
      }
3491
300k
    break;
3492
3493
300k
  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
690
    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
690
    break;
3503
3504
690
  default:
3505
0
    break;
3506
383k
  }
3507
334k
      break;
3508
3509
1.19M
    default:
3510
1.19M
      break;
3511
11.9M
    }
3512
3513
11.7M
  return true;
3514
11.9M
}
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.16M
{
3531
5.16M
  int i;
3532
3533
5.16M
  DEBUG_TRACE ("enter");
3534
3535
5.16M
  i = inst->opcode->tied_operand;
3536
3537
5.16M
  if (i > 0)
3538
54.4k
    {
3539
      /* Check for tied_operands with specific opcode iclass.  */
3540
54.4k
      switch (inst->opcode->iclass)
3541
54.4k
        {
3542
        /* For SME LDR and STR instructions #imm must have the same numerical
3543
           value for both operands.
3544
        */
3545
566
        case sme_ldr:
3546
601
        case sme_str:
3547
601
          assert (inst->operands[0].type == AARCH64_OPND_SME_ZA_array_off4);
3548
601
          assert (inst->operands[1].type == AARCH64_OPND_SME_ADDR_RI_U4xVL);
3549
601
          if (inst->operands[0].indexed_za.index.imm
3550
601
              != 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
601
          break;
3560
3561
53.8k
        default:
3562
53.8k
    {
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
53.8k
      enum aarch64_operand_class op_class
3570
53.8k
         = aarch64_get_operand_class (inst->operands[0].type);
3571
53.8k
      assert (aarch64_get_operand_class (inst->operands[i].type)
3572
53.8k
        == op_class);
3573
53.8k
      if (op_class == AARCH64_OPND_CLASS_SVE_REGLIST
3574
53.8k
    ? ((inst->operands[0].reglist.first_regno
3575
176
        != inst->operands[i].reglist.first_regno)
3576
176
       || (inst->operands[0].reglist.num_regs
3577
176
           != inst->operands[i].reglist.num_regs)
3578
176
       || (inst->operands[0].reglist.stride
3579
176
           != inst->operands[i].reglist.stride))
3580
53.8k
    : (inst->operands[0].reg.regno
3581
53.6k
       != 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
53.8k
      break;
3592
53.8k
    }
3593
54.4k
        }
3594
54.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.16M
  int invalid_count;
3607
5.16M
  if (match_operands_qualifier (inst, true /* update_p */,
3608
5.16M
        &invalid_count) == 0)
3609
28.8k
    {
3610
28.8k
      DEBUG_TRACE ("FAIL on operand qualifier matching");
3611
28.8k
      if (mismatch_detail)
3612
0
  {
3613
    /* Return an error type to indicate that it is the qualifier
3614
       matching failure; we don't care about which operand as there
3615
       are enough information in the opcode table to reproduce it.  */
3616
0
    mismatch_detail->kind = AARCH64_OPDE_INVALID_VARIANT;
3617
0
    mismatch_detail->index = -1;
3618
0
    mismatch_detail->error = NULL;
3619
0
    mismatch_detail->data[0].i = invalid_count;
3620
0
  }
3621
28.8k
      return false;
3622
28.8k
    }
3623
3624
  /* Match operands' constraint.  */
3625
16.9M
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3626
16.9M
    {
3627
16.9M
      enum aarch64_opnd type = inst->opcode->operands[i];
3628
16.9M
      if (type == AARCH64_OPND_NIL)
3629
5.00M
  break;
3630
11.9M
      if (inst->operands[i].skip)
3631
0
  {
3632
0
    DEBUG_TRACE ("skip the incomplete operand %d", i);
3633
0
    continue;
3634
0
  }
3635
11.9M
      if (!operand_general_constraint_met_p (inst->operands, i, type,
3636
11.9M
               inst->opcode, mismatch_detail))
3637
129k
  {
3638
129k
    DEBUG_TRACE ("FAIL on operand %d", i);
3639
129k
    return false;
3640
129k
  }
3641
11.9M
    }
3642
3643
5.00M
  DEBUG_TRACE ("PASS");
3644
3645
5.00M
  return true;
3646
5.13M
}
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
55.3k
{
3660
55.3k
  int i;
3661
55.3k
  const aarch64_opcode *old = inst->opcode;
3662
3663
55.3k
  inst->opcode = opcode;
3664
3665
  /* Update the operand types.  */
3666
208k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3667
208k
    {
3668
208k
      inst->operands[i].type = opcode->operands[i];
3669
208k
      if (opcode->operands[i] == AARCH64_OPND_NIL)
3670
55.3k
  break;
3671
208k
    }
3672
3673
55.3k
  DEBUG_TRACE ("replace %s with %s", old->name, opcode->name);
3674
3675
55.3k
  return old;
3676
55.3k
}
3677
3678
int
3679
aarch64_operand_index (const enum aarch64_opnd *operands, enum aarch64_opnd operand)
3680
119k
{
3681
119k
  int i;
3682
139k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3683
139k
    if (operands[i] == operand)
3684
115k
      return i;
3685
23.6k
    else if (operands[i] == AARCH64_OPND_NIL)
3686
3.64k
      break;
3687
3.64k
  return -1;
3688
119k
}
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.04M
{
3727
3.04M
  const int has_zr = sp_reg_p ? 0 : 1;
3728
3.04M
  const int is_64 = aarch64_get_qualifier_esize (qualifier) == 4 ? 0 : 1;
3729
3.04M
  return int_reg[has_zr][is_64][regno];
3730
3.04M
}
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.06M
{
3737
1.06M
  const int has_zr = sp_reg_p ? 0 : 1;
3738
1.06M
  return int_reg[has_zr][1][regno];
3739
1.06M
}
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
100k
{
3747
100k
  switch (opnd->shifter.kind)
3748
100k
    {
3749
1.43k
    case AARCH64_MOD_UXTW:
3750
3.16k
    case AARCH64_MOD_SXTW:
3751
3.16k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_W, 0);
3752
3753
94.4k
    case AARCH64_MOD_LSL:
3754
97.5k
    case AARCH64_MOD_SXTX:
3755
97.5k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_X, 0);
3756
3757
0
    default:
3758
0
      abort ();
3759
100k
    }
3760
100k
}
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
97.0k
{
3768
97.0k
  assert (qualifier == AARCH64_OPND_QLF_S_S
3769
97.0k
    || qualifier == AARCH64_OPND_QLF_S_D);
3770
97.0k
  return sve_reg[qualifier == AARCH64_OPND_QLF_S_D][regno];
3771
97.0k
}
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
1.98k
{
3804
1.98k
  uint64_t imm = 0;
3805
1.98k
  uint32_t imm8_7, imm8_6_0, imm8_6, imm8_6_repl4;
3806
3807
1.98k
  imm8_7 = (imm8 >> 7) & 0x01;  /* imm8<7>   */
3808
1.98k
  imm8_6_0 = imm8 & 0x7f; /* imm8<6:0> */
3809
1.98k
  imm8_6 = imm8_6_0 >> 6; /* imm8<6>   */
3810
1.98k
  imm8_6_repl4 = (imm8_6 << 3) | (imm8_6 << 2)
3811
1.98k
    | (imm8_6 << 1) | imm8_6; /* Replicate(imm8<6>,4) */
3812
1.98k
  if (size == 8)
3813
185
    {
3814
185
      imm = (imm8_7 << (63-32))   /* imm8<7>  */
3815
185
  | ((imm8_6 ^ 1) << (62-32)) /* NOT(imm8<6)  */
3816
185
  | (imm8_6_repl4 << (58-32)) | (imm8_6 << (57-32))
3817
185
  | (imm8_6 << (56-32)) | (imm8_6 << (55-32)) /* Replicate(imm8<6>,7) */
3818
185
  | (imm8_6_0 << (48-32));  /* imm8<6>:imm8<5:0>    */
3819
185
      imm <<= 32;
3820
185
    }
3821
1.79k
  else if (size == 4 || size == 2)
3822
1.79k
    {
3823
1.79k
      imm = (imm8_7 << 31)  /* imm8<7>              */
3824
1.79k
  | ((imm8_6 ^ 1) << 30)  /* NOT(imm8<6>)         */
3825
1.79k
  | (imm8_6_repl4 << 26)  /* Replicate(imm8<6>,4) */
3826
1.79k
  | (imm8_6_0 << 19); /* imm8<6>:imm8<5:0>    */
3827
1.79k
    }
3828
0
  else
3829
0
    {
3830
      /* An unsupported size.  */
3831
0
      assert (0);
3832
0
    }
3833
3834
1.98k
  return imm;
3835
1.98k
}
3836
3837
/* Return a string based on FMT with the register style applied.  */
3838
3839
static const char *
3840
style_reg (struct aarch64_styler *styler, const char *fmt, ...)
3841
7.57M
{
3842
7.57M
  const char *txt;
3843
7.57M
  va_list ap;
3844
3845
7.57M
  va_start (ap, fmt);
3846
7.57M
  txt = styler->apply_style (styler, dis_style_register, fmt, ap);
3847
7.57M
  va_end (ap);
3848
3849
7.57M
  return txt;
3850
7.57M
}
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.08M
{
3857
3.08M
  const char *txt;
3858
3.08M
  va_list ap;
3859
3860
3.08M
  va_start (ap, fmt);
3861
3.08M
  txt = styler->apply_style (styler, dis_style_immediate, fmt, ap);
3862
3.08M
  va_end (ap);
3863
3864
3.08M
  return txt;
3865
3.08M
}
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
510k
{
3872
510k
  const char *txt;
3873
510k
  va_list ap;
3874
3875
510k
  va_start (ap, fmt);
3876
510k
  txt = styler->apply_style (styler, dis_style_sub_mnemonic, fmt, ap);
3877
510k
  va_end (ap);
3878
3879
510k
  return txt;
3880
510k
}
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
928k
{
3887
928k
  const char *txt;
3888
928k
  va_list ap;
3889
3890
928k
  va_start (ap, fmt);
3891
928k
  txt = styler->apply_style (styler, dis_style_address, fmt, ap);
3892
928k
  va_end (ap);
3893
3894
928k
  return txt;
3895
928k
}
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
270k
{
3904
270k
  const int mask = (prefix[0] == 'p' ? 15 : 31);
3905
270k
  const int num_regs = opnd->reglist.num_regs;
3906
270k
  const int stride = opnd->reglist.stride;
3907
270k
  const int first_reg = opnd->reglist.first_regno;
3908
270k
  const int last_reg = (first_reg + (num_regs - 1) * stride) & mask;
3909
270k
  const char *qlf_name = aarch64_get_qualifier_name (opnd->qualifier);
3910
270k
  char tb[16];  /* Temporary buffer.  */
3911
3912
270k
  assert (opnd->type != AARCH64_OPND_LEt || opnd->reglist.has_index);
3913
270k
  assert (num_regs >= 1 && num_regs <= 4);
3914
3915
  /* Prepare the index if any.  */
3916
270k
  if (opnd->reglist.has_index)
3917
    /* PR 21096: The %100 is to silence a warning about possible truncation.  */
3918
12.5k
    snprintf (tb, sizeof (tb), "[%s]",
3919
12.5k
        style_imm (styler, "%" PRIi64, (opnd->reglist.index % 100)));
3920
258k
  else
3921
258k
    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
270k
  if (stride == 1 && num_regs > 1)
3927
77.9k
    if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3928
109
      snprintf (buf, size, "{%s-%s}%s",
3929
109
    style_reg (styler, "%s%d", prefix, first_reg),
3930
109
    style_reg (styler, "%s%d", prefix, last_reg), tb);
3931
77.8k
    else
3932
77.8k
      snprintf (buf, size, "{%s-%s}%s",
3933
77.8k
    style_reg (styler, "%s%d.%s", prefix, first_reg, qlf_name),
3934
77.8k
    style_reg (styler, "%s%d.%s", prefix, last_reg, qlf_name), tb);
3935
192k
  else
3936
192k
    {
3937
192k
      const int reg0 = first_reg;
3938
192k
      const int reg1 = (first_reg + stride) & mask;
3939
192k
      const int reg2 = (first_reg + stride * 2) & mask;
3940
192k
      const int reg3 = (first_reg + stride * 3) & mask;
3941
3942
192k
      switch (num_regs)
3943
192k
  {
3944
185k
  case 1:
3945
185k
    snprintf (buf, size, "{%s}%s",
3946
185k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3947
185k
        tb);
3948
185k
    break;
3949
4.73k
  case 2:
3950
4.73k
    snprintf (buf, size, "{%s, %s}%s",
3951
4.73k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3952
4.73k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3953
4.73k
        tb);
3954
4.73k
    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.47k
  case 4:
3963
2.47k
    snprintf (buf, size, "{%s, %s, %s, %s}%s",
3964
2.47k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3965
2.47k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3966
2.47k
        style_reg (styler, "%s%d.%s", prefix, reg2, qlf_name),
3967
2.47k
        style_reg (styler, "%s%d.%s", prefix, reg3, qlf_name),
3968
2.47k
        tb);
3969
2.47k
    break;
3970
192k
  }
3971
192k
    }
3972
270k
}
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
570k
{
3983
570k
  if (opnd->addr.writeback)
3984
194k
    {
3985
194k
      if (opnd->addr.preind)
3986
102k
        {
3987
102k
    if (opnd->type == AARCH64_OPND_ADDR_SIMM10 && !opnd->addr.offset.imm)
3988
86
      snprintf (buf, size, "[%s]!", style_reg (styler, base));
3989
102k
          else
3990
102k
      snprintf (buf, size, "[%s, %s]!",
3991
102k
          style_reg (styler, base),
3992
102k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
3993
102k
        }
3994
92.0k
      else
3995
92.0k
  snprintf (buf, size, "[%s], %s",
3996
92.0k
      style_reg (styler, base),
3997
92.0k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3998
194k
    }
3999
375k
  else
4000
375k
    {
4001
375k
      if (opnd->shifter.operator_present)
4002
59.5k
  {
4003
59.5k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL_VL);
4004
59.5k
    snprintf (buf, size, "[%s, %s, %s]",
4005
59.5k
        style_reg (styler, base),
4006
59.5k
        style_imm (styler, "#%d", opnd->addr.offset.imm),
4007
59.5k
        style_sub_mnem (styler, "mul vl"));
4008
59.5k
  }
4009
316k
      else if (opnd->addr.offset.imm)
4010
253k
  snprintf (buf, size, "[%s, %s]",
4011
253k
      style_reg (styler, base),
4012
253k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
4013
62.3k
      else
4014
62.3k
  snprintf (buf, size, "[%s]", style_reg (styler, base));
4015
375k
    }
4016
570k
}
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
185k
{
4027
185k
  char tb[32];      /* Temporary buffer.  */
4028
185k
  bool print_extend_p = true;
4029
185k
  bool print_amount_p = true;
4030
185k
  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
185k
  if (opnd->type == AARCH64_OPND_SVE_ADDR_ZX && offset != NULL
4035
9.41k
      && strcmp (offset,"xzr") == 0)
4036
327
    {
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
327
      snprintf (buf, size, "[%s]", style_reg (styler, base));
4041
327
    }
4042
184k
  else
4043
184k
    {
4044
184k
      if (!opnd->shifter.amount && (opnd->qualifier != AARCH64_OPND_QLF_S_B
4045
3.02k
            || !opnd->shifter.amount_present))
4046
92.2k
  {
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
92.2k
   print_amount_p = false;
4051
   /* Likewise, no need to print the shift operator LSL in such a
4052
      situation.  */
4053
92.2k
   if (opnd->shifter.kind == AARCH64_MOD_LSL)
4054
60.0k
     print_extend_p = false;
4055
92.2k
  }
4056
4057
      /* Prepare for the extend/shift.  */
4058
184k
      if (print_extend_p)
4059
124k
  {
4060
124k
    if (print_amount_p)
4061
92.6k
      snprintf (tb, sizeof (tb), ", %s %s",
4062
92.6k
          style_sub_mnem (styler, shift_name),
4063
92.6k
          style_imm (styler, "#%" PRIi64,
4064
    /* PR 21096: The %100 is to silence a warning about possible
4065
       truncation.  */
4066
92.6k
         (opnd->shifter.amount % 100)));
4067
32.1k
    else
4068
32.1k
      snprintf (tb, sizeof (tb), ", %s",
4069
32.1k
          style_sub_mnem (styler, shift_name));
4070
124k
  }
4071
60.0k
      else
4072
60.0k
  tb[0] = '\0';
4073
4074
184k
      snprintf (buf, size, "[%s, %s%s]", style_reg (styler, base),
4075
184k
    style_reg (styler, offset), tb);
4076
184k
    }
4077
185k
}
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
167
{
4092
167
  static const struct {
4093
167
    unsigned char mask;
4094
167
    char name[7];
4095
167
  } zan[] = {
4096
167
    { 0xff, "za" },
4097
167
    { 0x55, "za0.h" },
4098
167
    { 0xaa, "za1.h" },
4099
167
    { 0x11, "za0.s" },
4100
167
    { 0x22, "za1.s" },
4101
167
    { 0x44, "za2.s" },
4102
167
    { 0x88, "za3.s" },
4103
167
    { 0x01, "za0.d" },
4104
167
    { 0x02, "za1.d" },
4105
167
    { 0x04, "za2.d" },
4106
167
    { 0x08, "za3.d" },
4107
167
    { 0x10, "za4.d" },
4108
167
    { 0x20, "za5.d" },
4109
167
    { 0x40, "za6.d" },
4110
167
    { 0x80, "za7.d" },
4111
167
    { 0x00, " " },
4112
167
  };
4113
167
  int k;
4114
4115
167
  k = snprintf (buf, size, "{");
4116
1.48k
  for (unsigned int i = 0; i < ARRAY_SIZE (zan); i++)
4117
1.48k
    {
4118
1.48k
      if ((mask & zan[i].mask) == zan[i].mask)
4119
467
  {
4120
467
    mask &= ~zan[i].mask;
4121
467
    if (k > 1)
4122
302
      k += snprintf (buf + k, size - k, ", ");
4123
4124
467
    k += snprintf (buf + k, size - k, "%s",
4125
467
       style_reg (styler, zan[i].name));
4126
467
  }
4127
1.48k
      if (mask == 0)
4128
167
        break;
4129
1.48k
    }
4130
167
  snprintf (buf + k, size - k, "}");
4131
167
}
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
9.96M
{
4153
9.96M
  unsigned int i, num_conds;
4154
9.96M
  const char *name = NULL;
4155
9.96M
  const aarch64_opnd_info *opnd = opnds + idx;
4156
9.96M
  enum aarch64_modifier_kind kind;
4157
9.96M
  uint64_t addr, enum_value;
4158
4159
9.96M
  if (comment != NULL)
4160
9.96M
    {
4161
9.96M
      assert (comment_size > 0);
4162
9.96M
      comment[0] = '\0';
4163
9.96M
    }
4164
0
  else
4165
9.96M
    assert (comment_size == 0);
4166
4167
9.96M
  buf[0] = '\0';
4168
9.96M
  if (pcrel_p)
4169
9.96M
    *pcrel_p = 0;
4170
4171
9.96M
  switch (opnd->type)
4172
9.96M
    {
4173
771k
    case AARCH64_OPND_Rd:
4174
1.16M
    case AARCH64_OPND_Rn:
4175
1.24M
    case AARCH64_OPND_Rm:
4176
2.07M
    case AARCH64_OPND_Rt:
4177
2.25M
    case AARCH64_OPND_Rt2:
4178
2.36M
    case AARCH64_OPND_Rs:
4179
2.37M
    case AARCH64_OPND_Ra:
4180
2.37M
    case AARCH64_OPND_Rt_IN_SYS_ALIASES:
4181
2.37M
    case AARCH64_OPND_Rt_LS64:
4182
2.38M
    case AARCH64_OPND_Rt_SYS:
4183
2.38M
    case AARCH64_OPND_PAIRREG:
4184
2.38M
    case AARCH64_OPND_PAIRREG_OR_XZR:
4185
2.38M
    case AARCH64_OPND_SVE_Rm:
4186
2.38M
    case AARCH64_OPND_LSE128_Rt:
4187
2.38M
    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.38M
      if (opnd->type == AARCH64_OPND_Rt_SYS)
4192
245
  {
4193
245
    if (!opnd->present)
4194
120
      break;
4195
245
  }
4196
2.38M
      else if ((opnd->type == AARCH64_OPND_Rt_IN_SYS_ALIASES)
4197
8
         && (opnd->reg.regno
4198
8
       != get_optional_operand_default_value (opcode)))
4199
8
  {
4200
    /* Avoid printing an invalid additional value for Rt in SYS aliases such as
4201
       BRB, provide a helpful comment instead */
4202
8
    snprintf (comment, comment_size, "unpredictable encoding (Rt!=31): #%u", opnd->reg.regno);
4203
8
    break;
4204
8
  }
4205
      /* Omit the operand, e.g. RET.  */
4206
2.38M
      else if (optional_operand_p (opcode, idx)
4207
3.42k
         && (opnd->reg.regno
4208
3.42k
       == get_optional_operand_default_value (opcode)))
4209
1.36k
  break;
4210
2.38M
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
4211
2.38M
        || opnd->qualifier == AARCH64_OPND_QLF_X);
4212
2.38M
      snprintf (buf, size, "%s",
4213
2.38M
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
4214
2.38M
                 opnd->qualifier, 0)));
4215
2.38M
      break;
4216
4217
145k
    case AARCH64_OPND_Rd_SP:
4218
307k
    case AARCH64_OPND_Rn_SP:
4219
312k
    case AARCH64_OPND_Rt_SP:
4220
312k
    case AARCH64_OPND_SVE_Rn_SP:
4221
313k
    case AARCH64_OPND_Rm_SP:
4222
313k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
4223
313k
        || opnd->qualifier == AARCH64_OPND_QLF_WSP
4224
313k
        || opnd->qualifier == AARCH64_OPND_QLF_X
4225
313k
        || opnd->qualifier == AARCH64_OPND_QLF_SP);
4226
313k
      snprintf (buf, size, "%s",
4227
313k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
4228
313k
                 opnd->qualifier, 1)));
4229
313k
      break;
4230
4231
19.0k
    case AARCH64_OPND_Rm_EXT:
4232
19.0k
      kind = opnd->shifter.kind;
4233
19.0k
      assert (idx == 1 || idx == 2);
4234
19.0k
      if ((aarch64_stack_pointer_p (opnds)
4235
18.7k
     || (idx == 2 && aarch64_stack_pointer_p (opnds + 1)))
4236
1.22k
    && ((opnd->qualifier == AARCH64_OPND_QLF_W
4237
654
         && opnds[0].qualifier == AARCH64_OPND_QLF_W
4238
428
         && kind == AARCH64_MOD_UXTW)
4239
1.16k
        || (opnd->qualifier == AARCH64_OPND_QLF_X
4240
571
      && kind == AARCH64_MOD_UXTX)))
4241
448
  {
4242
    /* 'LSL' is the preferred form in this case.  */
4243
448
    kind = AARCH64_MOD_LSL;
4244
448
    if (opnd->shifter.amount == 0)
4245
344
      {
4246
        /* Shifter omitted.  */
4247
344
        snprintf (buf, size, "%s",
4248
344
      style_reg (styler,
4249
344
           get_int_reg_name (opnd->reg.regno,
4250
344
                 opnd->qualifier, 0)));
4251
344
        break;
4252
344
      }
4253
448
  }
4254
18.7k
      if (opnd->shifter.amount)
4255
15.6k
  snprintf (buf, size, "%s, %s %s",
4256
15.6k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4257
15.6k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name),
4258
15.6k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4259
3.13k
      else
4260
3.13k
  snprintf (buf, size, "%s, %s",
4261
3.13k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4262
3.13k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name));
4263
18.7k
      break;
4264
4265
211k
    case AARCH64_OPND_Rm_SFT:
4266
211k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
4267
211k
        || opnd->qualifier == AARCH64_OPND_QLF_X);
4268
211k
      if (opnd->shifter.amount == 0 && opnd->shifter.kind == AARCH64_MOD_LSL)
4269
22.4k
  snprintf (buf, size, "%s",
4270
22.4k
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
4271
22.4k
                   opnd->qualifier, 0)));
4272
189k
      else
4273
189k
  snprintf (buf, size, "%s, %s %s",
4274
189k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4275
189k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4276
189k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4277
211k
      break;
4278
4279
690
    case AARCH64_OPND_Rm_LSL:
4280
690
      assert (opnd->qualifier == AARCH64_OPND_QLF_X);
4281
690
      assert (opnd->shifter.kind == AARCH64_MOD_LSL);
4282
690
      if (opnd->shifter.amount == 0)
4283
163
  snprintf (buf, size, "%s",
4284
163
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
4285
163
                   opnd->qualifier, 0)));
4286
527
      else
4287
527
  snprintf (buf, size, "%s, %s %s",
4288
527
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
4289
527
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4290
527
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4291
690
      break;
4292
4293
73.0k
    case AARCH64_OPND_Fd:
4294
102k
    case AARCH64_OPND_Fn:
4295
137k
    case AARCH64_OPND_Fm:
4296
194k
    case AARCH64_OPND_Fa:
4297
507k
    case AARCH64_OPND_Ft:
4298
662k
    case AARCH64_OPND_Ft2:
4299
677k
    case AARCH64_OPND_Sd:
4300
692k
    case AARCH64_OPND_Sn:
4301
699k
    case AARCH64_OPND_Sm:
4302
699k
    case AARCH64_OPND_SVE_VZn:
4303
702k
    case AARCH64_OPND_SVE_Vd:
4304
702k
    case AARCH64_OPND_SVE_Vm:
4305
702k
    case AARCH64_OPND_SVE_Vn:
4306
702k
      snprintf (buf, size, "%s",
4307
702k
    style_reg (styler, "%s%d",
4308
702k
         aarch64_get_qualifier_name (opnd->qualifier),
4309
702k
         opnd->reg.regno));
4310
702k
      break;
4311
4312
7.61k
    case AARCH64_OPND_Va:
4313
202k
    case AARCH64_OPND_Vd:
4314
370k
    case AARCH64_OPND_Vn:
4315
486k
    case AARCH64_OPND_Vm:
4316
486k
      snprintf (buf, size, "%s",
4317
486k
    style_reg (styler, "v%d.%s", opnd->reg.regno,
4318
486k
         aarch64_get_qualifier_name (opnd->qualifier)));
4319
486k
      break;
4320
4321
1.40k
    case AARCH64_OPND_Ed:
4322
5.68k
    case AARCH64_OPND_En:
4323
29.5k
    case AARCH64_OPND_Em:
4324
59.3k
    case AARCH64_OPND_Em16:
4325
61.8k
    case AARCH64_OPND_Em8:
4326
61.8k
    case AARCH64_OPND_SM3_IMM2:
4327
61.8k
      snprintf (buf, size, "%s[%s]",
4328
61.8k
    style_reg (styler, "v%d.%s", opnd->reglane.regno,
4329
61.8k
         aarch64_get_qualifier_name (opnd->qualifier)),
4330
61.8k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4331
61.8k
      break;
4332
4333
800
    case AARCH64_OPND_Em_INDEX1_14:
4334
2.16k
    case AARCH64_OPND_Em_INDEX2_13:
4335
2.51k
    case AARCH64_OPND_Em_INDEX3_12:
4336
2.51k
      snprintf (buf, size, "%s[%s]",
4337
2.51k
    style_reg (styler, "v%d", opnd->reglane.regno),
4338
2.51k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4339
2.51k
      break;
4340
4341
130
    case AARCH64_OPND_VdD1:
4342
509
    case AARCH64_OPND_VnD1:
4343
509
      snprintf (buf, size, "%s[%s]",
4344
509
    style_reg (styler, "v%d.d", opnd->reg.regno),
4345
509
    style_imm (styler, "1"));
4346
509
      break;
4347
4348
11.4k
    case AARCH64_OPND_LVn:
4349
13.9k
    case AARCH64_OPND_LVn_LUT:
4350
23.3k
    case AARCH64_OPND_LVt:
4351
24.6k
    case AARCH64_OPND_LVt_AL:
4352
37.1k
    case AARCH64_OPND_LEt:
4353
37.1k
      print_register_list (buf, size, opnd, "v", styler);
4354
37.1k
      break;
4355
4356
53.3k
    case AARCH64_OPND_SVE_Pd:
4357
492k
    case AARCH64_OPND_SVE_Pg3:
4358
493k
    case AARCH64_OPND_SVE_Pg4_5:
4359
504k
    case AARCH64_OPND_SVE_Pg4_10:
4360
509k
    case AARCH64_OPND_SVE_Pg4_16:
4361
513k
    case AARCH64_OPND_SVE_Pm:
4362
517k
    case AARCH64_OPND_SVE_Pn:
4363
519k
    case AARCH64_OPND_SVE_Pt:
4364
568k
    case AARCH64_OPND_SME_Pm:
4365
568k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4366
94.4k
  snprintf (buf, size, "%s",
4367
94.4k
      style_reg (styler, "p%d", opnd->reg.regno));
4368
473k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
4369
267k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
4370
414k
  snprintf (buf, size, "%s",
4371
414k
      style_reg (styler, "p%d/%s", opnd->reg.regno,
4372
414k
           aarch64_get_qualifier_name (opnd->qualifier)));
4373
59.4k
      else
4374
59.4k
  snprintf (buf, size, "%s",
4375
59.4k
      style_reg (styler, "p%d.%s", opnd->reg.regno,
4376
59.4k
           aarch64_get_qualifier_name (opnd->qualifier)));
4377
568k
      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.15k
    case AARCH64_OPND_SME_PNd3:
4384
20.2k
    case AARCH64_OPND_SME_PNg3:
4385
20.3k
    case AARCH64_OPND_SME_PNn:
4386
20.3k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4387
6.60k
  snprintf (buf, size, "%s",
4388
6.60k
      style_reg (styler, "pn%d", opnd->reg.regno));
4389
13.7k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
4390
1.19k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
4391
12.5k
  snprintf (buf, size, "%s",
4392
12.5k
      style_reg (styler, "pn%d/%s", opnd->reg.regno,
4393
12.5k
           aarch64_get_qualifier_name (opnd->qualifier)));
4394
1.19k
      else
4395
1.19k
  snprintf (buf, size, "%s",
4396
1.19k
      style_reg (styler, "pn%d.%s", opnd->reg.regno,
4397
1.19k
           aarch64_get_qualifier_name (opnd->qualifier)));
4398
20.3k
      break;
4399
4400
503
    case AARCH64_OPND_SME_Pdx2:
4401
585
    case AARCH64_OPND_SME_PdxN:
4402
585
      print_register_list (buf, size, opnd, "p", styler);
4403
585
      break;
4404
4405
82
    case AARCH64_OPND_SME_PNn3_INDEX1:
4406
116
    case AARCH64_OPND_SME_PNn3_INDEX2:
4407
116
      snprintf (buf, size, "%s[%s]",
4408
116
    style_reg (styler, "pn%d", opnd->reglane.regno),
4409
116
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4410
116
      break;
4411
4412
4.97k
    case AARCH64_OPND_SVE_Za_5:
4413
10.9k
    case AARCH64_OPND_SVE_Za_16:
4414
284k
    case AARCH64_OPND_SVE_Zd:
4415
312k
    case AARCH64_OPND_SVE_Zm_5:
4416
510k
    case AARCH64_OPND_SVE_Zm_16:
4417
813k
    case AARCH64_OPND_SVE_Zn:
4418
815k
    case AARCH64_OPND_SVE_Zt:
4419
822k
    case AARCH64_OPND_SME_Zm:
4420
822k
    case AARCH64_OPND_SME_Zm_17:
4421
829k
    case AARCH64_OPND_SME_Zn_6_3:
4422
835k
    case AARCH64_OPND_SME_Zm_17_3:
4423
835k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
4424
2.30k
       snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
4425
833k
      else
4426
833k
       snprintf (buf, size, "%s",
4427
833k
     style_reg (styler, "z%d.%s", opnd->reg.regno,
4428
833k
          aarch64_get_qualifier_name (opnd->qualifier)));
4429
835k
      break;
4430
4431
8.82k
    case AARCH64_OPND_SVE_ZnxN:
4432
195k
    case AARCH64_OPND_SVE_ZtxN:
4433
208k
    case AARCH64_OPND_SME_Zdnx2:
4434
212k
    case AARCH64_OPND_SME_Zdnx4:
4435
212k
    case AARCH64_OPND_SME_Znx2_6_3:
4436
212k
    case AARCH64_OPND_SME_Zmx2_17_3:
4437
213k
    case AARCH64_OPND_SME_Zmx2:
4438
213k
    case AARCH64_OPND_SME_Zmx4:
4439
214k
    case AARCH64_OPND_SME_Zmx2_INDEX_22:
4440
222k
    case AARCH64_OPND_SME_Znx2:
4441
222k
    case AARCH64_OPND_SME_Znx2_BIT_INDEX:
4442
225k
    case AARCH64_OPND_SME_Znx4:
4443
225k
    case AARCH64_OPND_SME_Zn7xN_UNTYPED:
4444
230k
    case AARCH64_OPND_SME_Ztx2_STRIDED:
4445
232k
    case AARCH64_OPND_SME_Ztx4_STRIDED:
4446
232k
      print_register_list (buf, size, opnd, "z", styler);
4447
232k
      break;
4448
4449
422
    case AARCH64_OPND_SVE_Zm1_23_INDEX:
4450
733
    case AARCH64_OPND_SVE_Zm2_22_INDEX:
4451
3.15k
    case AARCH64_OPND_SVE_Zm3_INDEX:
4452
9.14k
    case AARCH64_OPND_SVE_Zm3_22_INDEX:
4453
9.31k
    case AARCH64_OPND_SVE_Zm3_19_INDEX:
4454
9.84k
    case AARCH64_OPND_SVE_Zm3_12_INDEX:
4455
13.3k
    case AARCH64_OPND_SVE_Zm3_11_INDEX:
4456
15.3k
    case AARCH64_OPND_SVE_Zm3_10_INDEX:
4457
18.1k
    case AARCH64_OPND_SVE_Zm4_11_INDEX:
4458
21.8k
    case AARCH64_OPND_SVE_Zm4_INDEX:
4459
22.2k
    case AARCH64_OPND_SVE_Zn_INDEX:
4460
24.8k
    case AARCH64_OPND_SME_Zk_INDEX:
4461
24.8k
    case AARCH64_OPND_SME_Zm_INDEX1:
4462
25.7k
    case AARCH64_OPND_SME_Zm_INDEX2:
4463
25.8k
    case AARCH64_OPND_SME_Zm_INDEX2_3:
4464
26.6k
    case AARCH64_OPND_SME_Zm_INDEX3_1:
4465
28.1k
    case AARCH64_OPND_SME_Zm_INDEX3_2:
4466
28.8k
    case AARCH64_OPND_SME_Zm_INDEX3_3:
4467
31.3k
    case AARCH64_OPND_SME_Zm_INDEX3_10:
4468
31.6k
    case AARCH64_OPND_SVE_Zn_5_INDEX:
4469
33.0k
    case AARCH64_OPND_SME_Zm_INDEX4_1:
4470
33.5k
    case AARCH64_OPND_SME_Zm_INDEX4_2:
4471
44.8k
    case AARCH64_OPND_SME_Zm_INDEX4_3:
4472
48.0k
    case AARCH64_OPND_SME_Zm_INDEX4_10:
4473
48.0k
    case AARCH64_OPND_SME_Zn_INDEX1_16:
4474
48.3k
    case AARCH64_OPND_SME_Zn_INDEX2_15:
4475
48.6k
    case AARCH64_OPND_SME_Zn_INDEX2_16:
4476
48.7k
    case AARCH64_OPND_SME_Zn_INDEX2_19:
4477
48.8k
    case AARCH64_OPND_SME_Zn_INDEX3_14:
4478
49.0k
    case AARCH64_OPND_SME_Zn_INDEX3_15:
4479
49.1k
    case AARCH64_OPND_SME_Zn_INDEX4_14:
4480
49.1k
      snprintf (buf, size, "%s[%s]",
4481
49.1k
    (opnd->qualifier == AARCH64_OPND_QLF_NIL
4482
49.1k
     ? style_reg (styler, "z%d", opnd->reglane.regno)
4483
49.1k
     : style_reg (styler, "z%d.%s", opnd->reglane.regno,
4484
44.2k
            aarch64_get_qualifier_name (opnd->qualifier))),
4485
49.1k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4486
49.1k
      break;
4487
4488
47
    case AARCH64_OPND_SVE_Zn0_INDEX:
4489
112
    case AARCH64_OPND_SVE_Zn1_17_INDEX:
4490
136
    case AARCH64_OPND_SVE_Zn2_18_INDEX:
4491
171
    case AARCH64_OPND_SVE_Zn3_22_INDEX:
4492
253
    case AARCH64_OPND_SVE_Zd0_INDEX:
4493
281
    case AARCH64_OPND_SVE_Zd1_17_INDEX:
4494
293
    case AARCH64_OPND_SVE_Zd2_18_INDEX:
4495
310
    case AARCH64_OPND_SVE_Zd3_22_INDEX:
4496
310
      if (opnd->reglane.index == 0)
4497
193
  snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
4498
117
      else
4499
117
  snprintf (buf, size, "%s[%s]",
4500
117
      style_reg (styler, "z%d", opnd->reglane.regno),
4501
117
      style_imm (styler, "%" PRIi64, opnd->reglane.index));
4502
310
      break;
4503
4504
1.12k
    case AARCH64_OPND_SME_ZAda_1b:
4505
47.8k
    case AARCH64_OPND_SME_ZAda_2b:
4506
58.7k
    case AARCH64_OPND_SME_ZAda_3b:
4507
58.7k
      snprintf (buf, size, "%s",
4508
58.7k
    style_reg (styler, "za%d.%s", opnd->reg.regno,
4509
58.7k
         aarch64_get_qualifier_name (opnd->qualifier)));
4510
58.7k
      break;
4511
4512
279
    case AARCH64_OPND_SME_ZA_HV_idx_src:
4513
1.26k
    case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
4514
25.3k
    case AARCH64_OPND_SME_ZA_HV_idx_dest:
4515
26.1k
    case AARCH64_OPND_SME_ZA_HV_idx_destxN:
4516
57.5k
    case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
4517
57.6k
    case AARCH64_OPND_SME_ZA_array_vrsb_1:
4518
57.6k
    case AARCH64_OPND_SME_ZA_array_vrsh_1:
4519
57.6k
    case AARCH64_OPND_SME_ZA_array_vrss_1:
4520
57.9k
    case AARCH64_OPND_SME_ZA_array_vrsd_1:
4521
58.1k
    case AARCH64_OPND_SME_ZA_array_vrsb_2:
4522
58.1k
    case AARCH64_OPND_SME_ZA_array_vrsh_2:
4523
58.3k
    case AARCH64_OPND_SME_ZA_array_vrss_2:
4524
58.3k
    case AARCH64_OPND_SME_ZA_array_vrsd_2:
4525
58.9k
    case AARCH64_OPND_SME_ZA_ARRAY4:
4526
58.9k
      snprintf (buf, size, "%s%s[%s, %s%s%s%s%s]%s",
4527
58.9k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "{" : "",
4528
58.9k
    style_reg (styler, "za%d%c%s%s",
4529
58.9k
         opnd->indexed_za.regno,
4530
58.9k
         opnd->indexed_za.v == 1 ? 'v' : 'h',
4531
58.9k
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4532
58.9k
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4533
58.9k
          ? ""
4534
58.9k
          : aarch64_get_qualifier_name (opnd->qualifier))),
4535
58.9k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4536
58.9k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4537
58.9k
    opnd->indexed_za.index.countm1 ? ":" : "",
4538
58.9k
    (opnd->indexed_za.index.countm1
4539
58.9k
     ? style_imm (styler, "%d",
4540
2.67k
            opnd->indexed_za.index.imm
4541
2.67k
            + opnd->indexed_za.index.countm1)
4542
58.9k
     : ""),
4543
58.9k
    opnd->indexed_za.group_size ? ", " : "",
4544
58.9k
    opnd->indexed_za.group_size == 2
4545
58.9k
    ? style_sub_mnem (styler, "vgx2")
4546
58.9k
    : opnd->indexed_za.group_size == 4
4547
58.9k
    ? style_sub_mnem (styler, "vgx4") : "",
4548
58.9k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "}" : "");
4549
58.9k
      break;
4550
4551
167
    case AARCH64_OPND_SME_list_of_64bit_tiles:
4552
167
      print_sme_za_list (buf, size, opnd->imm.value, styler);
4553
167
      break;
4554
4555
3.69k
    case AARCH64_OPND_SME_ZA_array_off1x4:
4556
7.12k
    case AARCH64_OPND_SME_ZA_array_off2x2:
4557
11.2k
    case AARCH64_OPND_SME_ZA_array_off2x4:
4558
17.1k
    case AARCH64_OPND_SME_ZA_array_off3_0:
4559
17.4k
    case AARCH64_OPND_SME_ZA_array_off3_5:
4560
31.3k
    case AARCH64_OPND_SME_ZA_array_off3x2:
4561
31.9k
    case AARCH64_OPND_SME_ZA_array_off4:
4562
31.9k
      snprintf (buf, size, "%s[%s, %s%s%s%s%s]",
4563
31.9k
    style_reg (styler, "za%s%s",
4564
31.9k
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4565
31.9k
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4566
31.9k
          ? ""
4567
31.9k
          : aarch64_get_qualifier_name (opnd->qualifier))),
4568
31.9k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4569
31.9k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4570
31.9k
    opnd->indexed_za.index.countm1 ? ":" : "",
4571
31.9k
    (opnd->indexed_za.index.countm1
4572
31.9k
     ? style_imm (styler, "%d",
4573
25.1k
            opnd->indexed_za.index.imm
4574
25.1k
            + opnd->indexed_za.index.countm1)
4575
31.9k
     : ""),
4576
31.9k
    opnd->indexed_za.group_size ? ", " : "",
4577
31.9k
    opnd->indexed_za.group_size == 2
4578
31.9k
    ? style_sub_mnem (styler, "vgx2")
4579
31.9k
    : opnd->indexed_za.group_size == 4
4580
24.1k
    ? style_sub_mnem (styler, "vgx4") : "");
4581
31.9k
      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
1.90k
    case AARCH64_OPND_SME_PnT_Wm_imm:
4589
1.90k
      snprintf (buf, size, "%s[%s, %s]",
4590
1.90k
    style_reg (styler, "p%d.%s", opnd->indexed_za.regno,
4591
1.90k
         aarch64_get_qualifier_name (opnd->qualifier)),
4592
1.90k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4593
1.90k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm));
4594
1.90k
      break;
4595
4596
46
    case AARCH64_OPND_SME_VLxN_10:
4597
1.19k
    case AARCH64_OPND_SME_VLxN_13:
4598
1.19k
      enum_value = opnd->imm.value;
4599
1.19k
      assert (enum_value < ARRAY_SIZE (aarch64_sme_vlxn_array));
4600
1.19k
      snprintf (buf, size, "%s",
4601
1.19k
    style_sub_mnem (styler, aarch64_sme_vlxn_array[enum_value]));
4602
1.19k
      break;
4603
4604
8
    case AARCH64_OPND_BRBOP:
4605
8
      enum_value = opnd->imm.value;
4606
8
      assert (enum_value < ARRAY_SIZE (aarch64_brbop_array));
4607
8
      snprintf (buf, size, "%s",
4608
8
    style_sub_mnem (styler, aarch64_brbop_array[enum_value]));
4609
8
      break;
4610
4611
3.05k
    case AARCH64_OPND_CRn:
4612
6.10k
    case AARCH64_OPND_CRm:
4613
6.10k
      snprintf (buf, size, "%s",
4614
6.10k
    style_reg (styler, "C%" PRIi64, opnd->imm.value));
4615
6.10k
      break;
4616
4617
5.84k
    case AARCH64_OPND_IDX:
4618
6.23k
    case AARCH64_OPND_MASK:
4619
29.7k
    case AARCH64_OPND_IMM:
4620
47.4k
    case AARCH64_OPND_IMM_2:
4621
68.1k
    case AARCH64_OPND_WIDTH:
4622
71.2k
    case AARCH64_OPND_UIMM3_OP1:
4623
74.2k
    case AARCH64_OPND_UIMM3_OP2:
4624
182k
    case AARCH64_OPND_BIT_NUM:
4625
187k
    case AARCH64_OPND_IMM_VLSL:
4626
197k
    case AARCH64_OPND_IMM_VLSR:
4627
197k
    case AARCH64_OPND_SHLL_IMM:
4628
197k
    case AARCH64_OPND_IMM0:
4629
197k
    case AARCH64_OPND_IMMR:
4630
199k
    case AARCH64_OPND_IMMS:
4631
1.39M
    case AARCH64_OPND_UNDEFINED:
4632
1.39M
    case AARCH64_OPND_FBITS:
4633
1.39M
    case AARCH64_OPND_TME_UIMM16:
4634
1.40M
    case AARCH64_OPND_SIMM5:
4635
1.40M
    case AARCH64_OPND_SME_SHRIMM3:
4636
1.40M
    case AARCH64_OPND_SME_SHRIMM4:
4637
1.40M
    case AARCH64_OPND_SME_SHRIMM5:
4638
1.40M
    case AARCH64_OPND_SVE_SHLIMM_PRED:
4639
1.40M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED:
4640
1.40M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
4641
1.40M
    case AARCH64_OPND_SVE_SHRIMM_PRED:
4642
1.40M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED:
4643
1.41M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
4644
1.41M
    case AARCH64_OPND_SVE_SIMM5:
4645
1.41M
    case AARCH64_OPND_SVE_SIMM5B:
4646
1.41M
    case AARCH64_OPND_SVE_SIMM6:
4647
1.41M
    case AARCH64_OPND_SVE_SIMM8:
4648
1.41M
    case AARCH64_OPND_SVE_UIMM3:
4649
1.43M
    case AARCH64_OPND_SVE_UIMM7:
4650
1.43M
    case AARCH64_OPND_SVE_UIMM8:
4651
1.43M
    case AARCH64_OPND_SVE_UIMM4:
4652
1.43M
    case AARCH64_OPND_SVE_UIMM8_53:
4653
1.43M
    case AARCH64_OPND_IMM_ROT1:
4654
1.44M
    case AARCH64_OPND_IMM_ROT2:
4655
1.44M
    case AARCH64_OPND_IMM_ROT3:
4656
1.44M
    case AARCH64_OPND_SVE_IMM_ROT1:
4657
1.45M
    case AARCH64_OPND_SVE_IMM_ROT2:
4658
1.45M
    case AARCH64_OPND_SVE_IMM_ROT3:
4659
1.45M
    case AARCH64_OPND_CSSC_SIMM8:
4660
1.45M
    case AARCH64_OPND_CSSC_UIMM8:
4661
1.45M
      snprintf (buf, size, "%s",
4662
1.45M
    style_imm (styler, "#%" PRIi64, opnd->imm.value));
4663
1.45M
      break;
4664
4665
36
    case AARCH64_OPND_SVE_I1_HALF_ONE:
4666
246
    case AARCH64_OPND_SVE_I1_HALF_TWO:
4667
1.16k
    case AARCH64_OPND_SVE_I1_ZERO_ONE:
4668
1.16k
      {
4669
1.16k
  single_conv_t c;
4670
1.16k
  c.i = opnd->imm.value;
4671
1.16k
  snprintf (buf, size, "%s", style_imm (styler, "#%.1f", c.f));
4672
1.16k
  break;
4673
246
      }
4674
4675
161
    case AARCH64_OPND_SVE_PATTERN:
4676
161
      if (optional_operand_p (opcode, idx)
4677
161
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4678
132
  break;
4679
29
      enum_value = opnd->imm.value;
4680
29
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4681
29
      if (aarch64_sve_pattern_array[enum_value])
4682
12
  snprintf (buf, size, "%s",
4683
12
      style_reg (styler, aarch64_sve_pattern_array[enum_value]));
4684
17
      else
4685
17
  snprintf (buf, size, "%s",
4686
17
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4687
29
      break;
4688
4689
5.23k
    case AARCH64_OPND_SVE_PATTERN_SCALED:
4690
5.23k
      if (optional_operand_p (opcode, idx)
4691
5.23k
    && !opnd->shifter.operator_present
4692
1.36k
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4693
804
  break;
4694
4.43k
      enum_value = opnd->imm.value;
4695
4.43k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4696
4.43k
      if (aarch64_sve_pattern_array[opnd->imm.value])
4697
2.92k
  snprintf (buf, size, "%s",
4698
2.92k
      style_reg (styler,
4699
2.92k
           aarch64_sve_pattern_array[opnd->imm.value]));
4700
1.51k
      else
4701
1.51k
  snprintf (buf, size, "%s",
4702
1.51k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4703
4.43k
      if (opnd->shifter.operator_present)
4704
3.87k
  {
4705
3.87k
    size_t len = strlen (buf);
4706
3.87k
    const char *shift_name
4707
3.87k
      = aarch64_operand_modifiers[opnd->shifter.kind].name;
4708
3.87k
    snprintf (buf + len, size - len, ", %s %s",
4709
3.87k
        style_sub_mnem (styler, shift_name),
4710
3.87k
        style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4711
3.87k
  }
4712
4.43k
      break;
4713
4714
12.6k
    case AARCH64_OPND_SVE_PRFOP:
4715
12.6k
      enum_value = opnd->imm.value;
4716
12.6k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_prfop_array));
4717
12.6k
      if (aarch64_sve_prfop_array[enum_value])
4718
7.83k
  snprintf (buf, size, "%s",
4719
7.83k
      style_reg (styler, aarch64_sve_prfop_array[enum_value]));
4720
4.79k
      else
4721
4.79k
  snprintf (buf, size, "%s",
4722
4.79k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4723
12.6k
      break;
4724
4725
33.1k
    case AARCH64_OPND_IMM_MOV:
4726
33.1k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4727
33.1k
  {
4728
6.54k
  case 4: /* e.g. MOV Wd, #<imm32>.  */
4729
6.54k
      {
4730
6.54k
        int imm32 = opnd->imm.value;
4731
6.54k
        snprintf (buf, size, "%s",
4732
6.54k
      style_imm (styler, "#0x%-20x", imm32));
4733
6.54k
        snprintf (comment, comment_size, "#%d", imm32);
4734
6.54k
      }
4735
6.54k
    break;
4736
26.5k
  case 8: /* e.g. MOV Xd, #<imm64>.  */
4737
26.5k
    snprintf (buf, size, "%s", style_imm (styler, "#0x%-20" PRIx64,
4738
26.5k
            opnd->imm.value));
4739
26.5k
    snprintf (comment, comment_size, "#%" PRIi64, opnd->imm.value);
4740
26.5k
    break;
4741
0
  default:
4742
0
    snprintf (buf, size, "<invalid>");
4743
0
    break;
4744
33.1k
  }
4745
33.1k
      break;
4746
4747
33.1k
    case AARCH64_OPND_FPIMM0:
4748
333
      snprintf (buf, size, "%s", style_imm (styler, "#0.0"));
4749
333
      break;
4750
4751
103k
    case AARCH64_OPND_LIMM:
4752
242k
    case AARCH64_OPND_AIMM:
4753
262k
    case AARCH64_OPND_HALF:
4754
262k
    case AARCH64_OPND_SVE_INV_LIMM:
4755
274k
    case AARCH64_OPND_SVE_LIMM:
4756
276k
    case AARCH64_OPND_SVE_LIMM_MOV:
4757
276k
      if (opnd->shifter.amount)
4758
67.7k
  snprintf (buf, size, "%s, %s %s",
4759
67.7k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4760
67.7k
      style_sub_mnem (styler, "lsl"),
4761
67.7k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4762
208k
      else
4763
208k
  snprintf (buf, size, "%s",
4764
208k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4765
276k
      break;
4766
4767
700
    case AARCH64_OPND_SIMD_IMM:
4768
2.85k
    case AARCH64_OPND_SIMD_IMM_SFT:
4769
2.85k
      if ((! opnd->shifter.amount && opnd->shifter.kind == AARCH64_MOD_LSL)
4770
2.21k
    || opnd->shifter.kind == AARCH64_MOD_NONE)
4771
1.34k
  snprintf (buf, size, "%s",
4772
1.34k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4773
1.51k
      else
4774
1.51k
  snprintf (buf, size, "%s, %s %s",
4775
1.51k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4776
1.51k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4777
1.51k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4778
2.85k
      break;
4779
4780
1.01k
    case AARCH64_OPND_SVE_AIMM:
4781
6.53k
    case AARCH64_OPND_SVE_ASIMM:
4782
6.53k
      if (opnd->shifter.amount)
4783
170
  snprintf (buf, size, "%s, %s %s",
4784
170
      style_imm (styler, "#%" PRIi64, opnd->imm.value),
4785
170
      style_sub_mnem (styler, "lsl"),
4786
170
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4787
6.36k
      else
4788
6.36k
  snprintf (buf, size, "%s",
4789
6.36k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4790
6.53k
      break;
4791
4792
124
    case AARCH64_OPND_FPIMM:
4793
1.69k
    case AARCH64_OPND_SIMD_FPIMM:
4794
1.98k
    case AARCH64_OPND_SVE_FPIMM8:
4795
1.98k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4796
1.98k
  {
4797
1.25k
  case 2: /* e.g. FMOV <Hd>, #<imm>.  */
4798
1.25k
      {
4799
1.25k
        half_conv_t c;
4800
1.25k
        c.i = expand_fp_imm (2, opnd->imm.value);
4801
1.25k
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4802
1.25k
      }
4803
1.25k
    break;
4804
538
  case 4: /* e.g. FMOV <Vd>.4S, #<imm>.  */
4805
538
      {
4806
538
        single_conv_t c;
4807
538
        c.i = expand_fp_imm (4, opnd->imm.value);
4808
538
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4809
538
      }
4810
538
    break;
4811
185
  case 8: /* e.g. FMOV <Sd>, #<imm>.  */
4812
185
      {
4813
185
        double_conv_t c;
4814
185
        c.i = expand_fp_imm (8, opnd->imm.value);
4815
185
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.d));
4816
185
      }
4817
185
    break;
4818
0
  default:
4819
0
    snprintf (buf, size, "<invalid>");
4820
0
    break;
4821
1.98k
  }
4822
1.98k
      break;
4823
4824
1.98k
    case AARCH64_OPND_CCMP_IMM:
4825
6.59k
    case AARCH64_OPND_NZCV:
4826
7.31k
    case AARCH64_OPND_EXCEPTION:
4827
7.42k
    case AARCH64_OPND_UIMM4:
4828
9.46k
    case AARCH64_OPND_UIMM4_ADDG:
4829
9.58k
    case AARCH64_OPND_UIMM7:
4830
11.6k
    case AARCH64_OPND_UIMM10:
4831
11.6k
      if (optional_operand_p (opcode, idx)
4832
198
    && (opnd->imm.value ==
4833
198
        (int64_t) get_optional_operand_default_value (opcode)))
4834
  /* Omit the operand, e.g. DCPS1.  */
4835
32
  break;
4836
11.5k
      snprintf (buf, size, "%s",
4837
11.5k
    style_imm (styler, "#0x%x", (unsigned int) opnd->imm.value));
4838
11.5k
      break;
4839
4840
12.2k
    case AARCH64_OPND_COND:
4841
12.4k
    case AARCH64_OPND_COND1:
4842
12.4k
      snprintf (buf, size, "%s",
4843
12.4k
    style_sub_mnem (styler, opnd->cond->names[0]));
4844
12.4k
      num_conds = ARRAY_SIZE (opnd->cond->names);
4845
25.0k
      for (i = 1; i < num_conds && opnd->cond->names[i]; ++i)
4846
12.5k
  {
4847
12.5k
    size_t len = comment != NULL ? strlen (comment) : 0;
4848
12.5k
    if (i == 1)
4849
9.01k
      snprintf (comment + len, comment_size - len, "%s = %s",
4850
9.01k
          opnd->cond->names[0], opnd->cond->names[i]);
4851
3.51k
    else
4852
3.51k
      snprintf (comment + len, comment_size - len, ", %s",
4853
3.51k
          opnd->cond->names[i]);
4854
12.5k
  }
4855
12.4k
      break;
4856
4857
99.6k
    case AARCH64_OPND_ADDR_ADRP:
4858
99.6k
      addr = ((pc + AARCH64_PCREL_OFFSET) & ~(uint64_t)0xfff)
4859
99.6k
  + opnd->imm.value;
4860
99.6k
      if (pcrel_p)
4861
99.6k
  *pcrel_p = 1;
4862
99.6k
      if (address)
4863
99.6k
  *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
99.6k
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64 , addr));
4869
99.6k
      break;
4870
4871
49.0k
    case AARCH64_OPND_ADDR_PCREL9:
4872
157k
    case AARCH64_OPND_ADDR_PCREL14:
4873
443k
    case AARCH64_OPND_ADDR_PCREL19:
4874
667k
    case AARCH64_OPND_ADDR_PCREL21:
4875
828k
    case AARCH64_OPND_ADDR_PCREL26:
4876
828k
      addr = pc + AARCH64_PCREL_OFFSET + opnd->imm.value;
4877
828k
      if (pcrel_p)
4878
828k
  *pcrel_p = 1;
4879
828k
      if (address)
4880
828k
  *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
828k
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64, addr));
4886
828k
      break;
4887
4888
141k
    case AARCH64_OPND_ADDR_SIMPLE:
4889
152k
    case AARCH64_OPND_SIMD_ADDR_SIMPLE:
4890
164k
    case AARCH64_OPND_SIMD_ADDR_POST:
4891
164k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4892
164k
      if (opnd->type == AARCH64_OPND_SIMD_ADDR_POST)
4893
12.1k
  {
4894
12.1k
    if (opnd->addr.offset.is_reg)
4895
10.4k
      snprintf (buf, size, "[%s], %s",
4896
10.4k
          style_reg (styler, name),
4897
10.4k
          style_reg (styler, "x%d", opnd->addr.offset.regno));
4898
1.74k
    else
4899
1.74k
      snprintf (buf, size, "[%s], %s",
4900
1.74k
          style_reg (styler, name),
4901
1.74k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
4902
12.1k
  }
4903
152k
      else
4904
152k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4905
164k
      break;
4906
4907
16.7k
    case AARCH64_OPND_ADDR_REGOFF:
4908
24.7k
    case AARCH64_OPND_SVE_ADDR_RR:
4909
29.8k
    case AARCH64_OPND_SVE_ADDR_RR_LSL1:
4910
33.0k
    case AARCH64_OPND_SVE_ADDR_RR_LSL2:
4911
46.5k
    case AARCH64_OPND_SVE_ADDR_RR_LSL3:
4912
56.4k
    case AARCH64_OPND_SVE_ADDR_RR_LSL4:
4913
62.2k
    case AARCH64_OPND_SVE_ADDR_RM:
4914
64.9k
    case AARCH64_OPND_SVE_ADDR_RM_LSL1:
4915
67.0k
    case AARCH64_OPND_SVE_ADDR_RM_LSL2:
4916
69.5k
    case AARCH64_OPND_SVE_ADDR_RM_LSL3:
4917
69.5k
    case AARCH64_OPND_SVE_ADDR_RM_LSL4:
4918
80.8k
    case AARCH64_OPND_SVE_ADDR_RX:
4919
87.9k
    case AARCH64_OPND_SVE_ADDR_RX_LSL1:
4920
93.6k
    case AARCH64_OPND_SVE_ADDR_RX_LSL2:
4921
97.7k
    case AARCH64_OPND_SVE_ADDR_RX_LSL3:
4922
100k
    case AARCH64_OPND_SVE_ADDR_RX_LSL4:
4923
100k
      print_register_offset_address
4924
100k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4925
100k
   get_offset_int_reg_name (opnd), styler);
4926
100k
      break;
4927
4928
9.41k
    case AARCH64_OPND_SVE_ADDR_ZX:
4929
9.41k
      print_register_offset_address
4930
9.41k
  (buf, size, opnd,
4931
9.41k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4932
9.41k
   get_64bit_int_reg_name (opnd->addr.offset.regno, 0), styler);
4933
9.41k
      break;
4934
4935
22.4k
    case AARCH64_OPND_SVE_ADDR_RZ:
4936
24.2k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
4937
25.4k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
4938
27.0k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
4939
30.9k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
4940
56.1k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
4941
57.2k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
4942
62.7k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
4943
63.6k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
4944
68.1k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
4945
68.4k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
4946
73.2k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
4947
73.2k
      print_register_offset_address
4948
73.2k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4949
73.2k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4950
73.2k
   styler);
4951
73.2k
      break;
4952
4953
345k
    case AARCH64_OPND_ADDR_SIMM7:
4954
421k
    case AARCH64_OPND_ADDR_SIMM9:
4955
421k
    case AARCH64_OPND_ADDR_SIMM9_2:
4956
428k
    case AARCH64_OPND_ADDR_SIMM10:
4957
443k
    case AARCH64_OPND_ADDR_SIMM11:
4958
448k
    case AARCH64_OPND_ADDR_SIMM13:
4959
453k
    case AARCH64_OPND_RCPC3_ADDR_OFFSET:
4960
469k
    case AARCH64_OPND_ADDR_OFFSET:
4961
470k
    case AARCH64_OPND_RCPC3_ADDR_OPT_POSTIND:
4962
483k
    case AARCH64_OPND_RCPC3_ADDR_OPT_PREIND_WB:
4963
483k
    case AARCH64_OPND_RCPC3_ADDR_POSTIND:
4964
483k
    case AARCH64_OPND_RCPC3_ADDR_PREIND_WB:
4965
484k
    case AARCH64_OPND_SME_ADDR_RI_U4xVL:
4966
484k
    case AARCH64_OPND_SVE_ADDR_RI_S4x16:
4967
486k
    case AARCH64_OPND_SVE_ADDR_RI_S4x32:
4968
529k
    case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
4969
536k
    case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
4970
539k
    case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
4971
545k
    case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
4972
547k
    case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
4973
550k
    case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
4974
553k
    case AARCH64_OPND_SVE_ADDR_RI_U6:
4975
557k
    case AARCH64_OPND_SVE_ADDR_RI_U6x2:
4976
558k
    case AARCH64_OPND_SVE_ADDR_RI_U6x4:
4977
559k
    case AARCH64_OPND_SVE_ADDR_RI_U6x8:
4978
559k
      print_immediate_offset_address
4979
559k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4980
559k
   styler);
4981
559k
      break;
4982
4983
3.34k
    case AARCH64_OPND_SVE_ADDR_ZI_U5:
4984
7.80k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
4985
9.90k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
4986
10.7k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
4987
10.7k
      print_immediate_offset_address
4988
10.7k
  (buf, size, opnd,
4989
10.7k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4990
10.7k
   styler);
4991
10.7k
      break;
4992
4993
887
    case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
4994
1.04k
    case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
4995
1.81k
    case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
4996
1.81k
      print_register_offset_address
4997
1.81k
  (buf, size, opnd,
4998
1.81k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4999
1.81k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
5000
1.81k
   styler);
5001
1.81k
      break;
5002
5003
159k
    case AARCH64_OPND_ADDR_UIMM12:
5004
159k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
5005
159k
      if (opnd->addr.offset.imm)
5006
151k
  snprintf (buf, size, "[%s, %s]",
5007
151k
      style_reg (styler, name),
5008
151k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
5009
8.13k
      else
5010
8.13k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
5011
159k
      break;
5012
5013
6.60k
    case AARCH64_OPND_SYSREG:
5014
7.59k
    case AARCH64_OPND_SYSREG128:
5015
7.59k
      {
5016
7.59k
  int min_mismatch = 999;
5017
7.59k
  int best_index = -1;
5018
7.59k
  uint32_t op_flags = opnd->sysreg.flags;
5019
12.2M
  for (i = 0; aarch64_sys_regs[i].name; ++i)
5020
12.2M
    {
5021
12.2M
      const aarch64_sys_reg *sr = aarch64_sys_regs + i;
5022
5023
12.2M
      if (!(aarch64_sys_regs[i].value == opnd->sysreg.value)
5024
1.17k
    || aarch64_sys_reg_deprecated_p (aarch64_sys_regs[i].flags)
5025
1.17k
    || aarch64_sys_reg_alias_p (aarch64_sys_regs[i].flags))
5026
12.2M
        continue;
5027
5028
1.17k
      int mismatch_score = 0;
5029
1.17k
      if (!AARCH64_CPU_HAS_ALL_FEATURES (features, sr->features))
5030
751
        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.17k
      if (((sr->flags & F_REG_READ) && (op_flags & F_REG_WRITE))
5034
1.01k
    || ((sr->flags & F_REG_WRITE) && (op_flags & F_REG_READ)))
5035
215
        mismatch_score += 2;
5036
5037
1.17k
      if (mismatch_score < min_mismatch)
5038
1.17k
        {
5039
1.17k
    min_mismatch = mismatch_score;
5040
1.17k
    best_index = i;
5041
1.17k
    if (mismatch_score == 0)
5042
213
      break;
5043
1.17k
        }
5044
1.17k
    }
5045
7.59k
  if (best_index == -1)
5046
6.44k
    {
5047
      /* Use encoding-based name for unrecognised system register.  */
5048
6.44k
      unsigned int value = opnd->sysreg.value;
5049
6.44k
      snprintf (buf, size, "%s",
5050
6.44k
          style_reg (styler, "s%u_%u_c%u_c%u_%u",
5051
6.44k
         (value >> 14) & 0x3, (value >> 11) & 0x7,
5052
6.44k
         (value >> 7) & 0xf, (value >> 3) & 0xf,
5053
6.44k
         value & 0x7));
5054
6.44k
    }
5055
1.15k
  else
5056
1.15k
    {
5057
1.15k
      const aarch64_sys_reg *sr = aarch64_sys_regs + best_index;
5058
1.15k
      snprintf (buf, size, "%s", style_reg (styler, sr->name));
5059
5060
      /* Add a note if we violated read/write constraints.  */
5061
1.15k
      if (notes && min_mismatch)
5062
942
        {
5063
942
    if ((sr->flags & F_REG_READ) && (op_flags & F_REG_WRITE))
5064
144
      *notes = _("writing to a read-only register");
5065
798
    else if ((sr->flags & F_REG_WRITE) && (op_flags & F_REG_READ))
5066
47
      *notes = _("reading from a write-only register");
5067
942
        }
5068
1.15k
    }
5069
7.59k
  break;
5070
6.60k
      }
5071
5072
77
    case AARCH64_OPND_PSTATEFIELD:
5073
308
      for (i = 0; aarch64_pstatefields[i].name; ++i)
5074
308
        if (aarch64_pstatefields[i].value == opnd->pstatefield)
5075
77
          {
5076
            /* PSTATEFIELD name is encoded partially in CRm[3:1] for SVCRSM,
5077
               SVCRZA and SVCRSMZA.  */
5078
77
            uint32_t flags = aarch64_pstatefields[i].flags;
5079
77
            if (flags & F_REG_IN_CRM
5080
0
                && (PSTATE_DECODE_CRM (opnd->sysreg.flags)
5081
0
                    != PSTATE_DECODE_CRM (flags)))
5082
0
              continue;
5083
77
            break;
5084
77
          }
5085
77
      assert (aarch64_pstatefields[i].name);
5086
77
      snprintf (buf, size, "%s",
5087
77
    style_reg (styler, aarch64_pstatefields[i].name));
5088
77
      break;
5089
5090
0
    case AARCH64_OPND_GIC:
5091
0
    case AARCH64_OPND_GICR:
5092
0
    case AARCH64_OPND_GSB:
5093
56
    case AARCH64_OPND_SYSREG_AT:
5094
132
    case AARCH64_OPND_SYSREG_DC:
5095
141
    case AARCH64_OPND_SYSREG_IC:
5096
265
    case AARCH64_OPND_SYSREG_TLBI:
5097
376
    case AARCH64_OPND_SYSREG_TLBIP:
5098
377
    case AARCH64_OPND_SYSREG_PLBI:
5099
377
    case AARCH64_OPND_SYSREG_MLBI:
5100
377
    case AARCH64_OPND_SYSREG_SR:
5101
377
      snprintf (buf, size, "%s", style_reg (styler, opnd->sysins_op->name));
5102
377
      break;
5103
5104
50
    case AARCH64_OPND_BARRIER:
5105
91
    case AARCH64_OPND_BARRIER_DSB_NXS:
5106
91
      {
5107
91
  if (opnd->barrier->name[0] == '#')
5108
48
    snprintf (buf, size, "%s", style_imm (styler, opnd->barrier->name));
5109
43
  else
5110
43
    snprintf (buf, size, "%s",
5111
43
        style_sub_mnem (styler, opnd->barrier->name));
5112
91
      }
5113
91
      break;
5114
5115
103
    case AARCH64_OPND_BARRIER_ISB:
5116
      /* Operand can be omitted, e.g. in DCPS1.  */
5117
103
      if (! optional_operand_p (opcode, idx)
5118
103
    || (opnd->barrier->value
5119
103
        != get_optional_operand_default_value (opcode)))
5120
13
  snprintf (buf, size, "%s",
5121
13
      style_imm (styler, "#0x%x", opnd->barrier->value));
5122
103
      break;
5123
5124
26.9k
    case AARCH64_OPND_PRFOP:
5125
26.9k
      if ((opnd->prfop->name == NULL)
5126
22.6k
          || (opcode->iclass != ldst_pos && opnd->prfop->value == 0x18))
5127
10.8k
        snprintf (buf, size, "%s",
5128
10.8k
                  style_imm (styler, "#0x%02x", opnd->prfop->value));
5129
16.0k
      else
5130
16.0k
        snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->prfop->name));
5131
26.9k
      break;
5132
5133
414
    case AARCH64_OPND_RPRFMOP:
5134
414
      enum_value = opnd->imm.value;
5135
414
      if (enum_value < ARRAY_SIZE (aarch64_rprfmop_array)
5136
414
    && aarch64_rprfmop_array[enum_value])
5137
30
  snprintf (buf, size, "%s",
5138
30
      style_reg (styler, aarch64_rprfmop_array[enum_value]));
5139
384
      else
5140
384
  snprintf (buf, size, "%s",
5141
384
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
5142
414
      break;
5143
5144
80
    case AARCH64_OPND_BARRIER_PSB:
5145
80
      snprintf (buf, size, "%s", style_sub_mnem (styler, "csync"));
5146
80
      break;
5147
5148
0
    case AARCH64_OPND_X16:
5149
0
      snprintf (buf, size, "%s", style_reg (styler, "x16"));
5150
0
      break;
5151
5152
1.15k
    case AARCH64_OPND_SME_ZT0:
5153
1.15k
      snprintf (buf, size, "%s", style_reg (styler, "zt0"));
5154
1.15k
      break;
5155
5156
80
    case AARCH64_OPND_SME_ZT0_INDEX:
5157
80
      snprintf (buf, size, "%s[%s]", style_reg (styler, "zt0"),
5158
80
    style_imm (styler, "%d", (int) opnd->imm.value));
5159
80
      break;
5160
63
    case AARCH64_OPND_SME_ZT0_INDEX_MUL_VL:
5161
63
      snprintf (buf, size, "%s[%s, %s]", style_reg (styler, "zt0"),
5162
63
    style_imm (styler, "%d", (int) opnd->imm.value),
5163
63
    style_sub_mnem (styler, "mul vl"));
5164
63
      break;
5165
5166
9
    case AARCH64_OPND_SME_ZT0_LIST:
5167
9
      snprintf (buf, size, "{%s}", style_reg (styler, "zt0"));
5168
9
      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
187
    case AARCH64_OPND_NOT_BALANCED_17:
5176
187
      if (opnd->imm.value)
5177
48
  snprintf (buf, size, "%s", style_sub_mnem (styler, "nb"));
5178
187
      break;
5179
5180
163
    case AARCH64_OPND_BTI_TARGET:
5181
163
      snprintf (buf, size, "%s",
5182
163
    style_sub_mnem (styler, opnd->hint_option->name));
5183
163
      break;
5184
5185
20
    case AARCH64_OPND_STSHH_POLICY:
5186
20
      snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->hint_option->name));
5187
20
      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
5.77k
    case AARCH64_OPND_MOPS_ADDR_Rd:
5196
10.4k
    case AARCH64_OPND_MOPS_ADDR_Rs:
5197
10.4k
      snprintf (buf, size, "[%s]!",
5198
10.4k
    style_reg (styler,
5199
10.4k
         get_int_reg_name (opnd->reg.regno,
5200
10.4k
               AARCH64_OPND_QLF_X, 0)));
5201
10.4k
      break;
5202
5203
5.77k
    case AARCH64_OPND_MOPS_WB_Rn:
5204
5.77k
      snprintf (buf, size, "%s!",
5205
5.77k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
5206
5.77k
                 AARCH64_OPND_QLF_X, 0)));
5207
5.77k
      break;
5208
5209
0
    default:
5210
0
      snprintf (buf, size, "<invalid>");
5211
0
      break;
5212
9.96M
    }
5213
9.96M
}
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.17k
{
5256
1.17k
  return (reg_flags & F_DEPRECATED) != 0;
5257
1.17k
}
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.17k
{
5268
1.17k
  return (reg_flags & F_REG_ALIAS) != 0;
5269
1.17k
}
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
490
{
5632
490
  return (sys_ins_reg->flags & F_HASXT) != 0;
5633
490
}
5634
5635
bool
5636
aarch64_sys_ins_reg_tlbid_xt (const aarch64_sys_ins_reg *sys_ins_reg)
5637
370
{
5638
370
  return (sys_ins_reg->flags & F_TLBID_XT) != 0;
5639
370
}
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
61.7k
#define BIT(INSN,BT)     (((INSN) >> (BT)) & 1)
5675
94.0k
#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
31.3k
{
5684
31.3k
  int t  = BITS (insn, 4, 0);
5685
31.3k
  int n  = BITS (insn, 9, 5);
5686
31.3k
  int t2 = BITS (insn, 14, 10);
5687
5688
31.3k
  if (BIT (insn, 23))
5689
9.14k
    {
5690
      /* Write back enabled.  */
5691
9.14k
      if ((t == n || t2 == n) && n != 31)
5692
918
  return ERR_UND;
5693
9.14k
    }
5694
5695
30.4k
  if (BIT (insn, 22))
5696
30.4k
    {
5697
      /* Load */
5698
30.4k
      if (t == t2)
5699
3.69k
  return ERR_UND;
5700
30.4k
    }
5701
5702
26.7k
  return ERR_OK;
5703
30.4k
}
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.05k
{
5714
2.05k
  const aarch64_insn undef_pattern = 0x3;
5715
2.05k
  aarch64_insn value;
5716
5717
2.05k
  assert (inst->opcode);
5718
2.05k
  assert (inst->opcode->operands[2] == AARCH64_OPND_Em);
5719
2.05k
  value = encoding ? inst->value : insn;
5720
2.05k
  assert (value);
5721
5722
2.05k
  if (undef_pattern == extract_fields (value, 0, 2, FLD_sz, FLD_L))
5723
404
    return ERR_UND;
5724
5725
1.64k
  return ERR_OK;
5726
2.05k
}
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
6.30k
{
5741
6.30k
  int rd, rs, rn;
5742
5743
6.30k
  rd = inst->operands[0].reg.regno;
5744
6.30k
  rs = inst->operands[1].reg.regno;
5745
6.30k
  rn = inst->operands[2].reg.regno;
5746
6.30k
  if (rd == rs || rd == rn || rs == rn)
5747
674
    {
5748
674
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5749
674
      mismatch_detail->error
5750
674
  = _("the three register operands must be distinct from one another");
5751
674
      mismatch_detail->index = -1;
5752
674
      return ERR_UND;
5753
674
    }
5754
5755
5.62k
  return ERR_OK;
5756
6.30k
}
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
147
{
5771
147
  int rd, rn;
5772
5773
147
  rd = inst->operands[0].reg.regno;
5774
147
  rn = inst->operands[1].reg.regno;
5775
147
  if (rd == rn)
5776
2
    {
5777
2
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5778
2
      mismatch_detail->error
5779
2
  = _("the two register operands must be distinct from each other");
5780
2
      mismatch_detail->index = -1;
5781
2
      return ERR_UND;
5782
2
    }
5783
5784
145
  return ERR_OK;
5785
147
}
5786
5787
/* Add INST to the end of INSN_SEQUENCE.  */
5788
5789
static void
5790
add_insn_to_sequence (const struct aarch64_inst *inst,
5791
          aarch64_instr_sequence *insn_sequence)
5792
6.24k
{
5793
6.24k
  insn_sequence->instr[insn_sequence->num_added_insns++] = *inst;
5794
6.24k
}
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
12.5k
{
5804
12.5k
  int num_req_entries = 0;
5805
5806
12.5k
  if (insn_sequence->instr)
5807
5.97k
    {
5808
5.97k
      XDELETE (insn_sequence->instr);
5809
5.97k
      insn_sequence->instr = NULL;
5810
5.97k
    }
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
12.5k
  if (inst && inst->opcode->constraints & C_SCAN_MOVPRFX)
5816
2.51k
    num_req_entries = 1;
5817
12.5k
  if (inst && (inst->opcode->constraints & C_SCAN_MOPS_PME) == C_SCAN_MOPS_P)
5818
3.45k
    num_req_entries = 2;
5819
5820
12.5k
  insn_sequence->num_added_insns = 0;
5821
12.5k
  insn_sequence->num_allocated_insns = num_req_entries;
5822
5823
12.5k
  if (num_req_entries != 0)
5824
5.97k
    {
5825
5.97k
      insn_sequence->instr = XCNEWVEC (aarch64_inst, num_req_entries);
5826
5.97k
      add_insn_to_sequence (inst, insn_sequence);
5827
5.97k
    }
5828
12.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
160k
{
5844
160k
  const struct aarch64_opcode *opcode;
5845
160k
  const struct aarch64_inst *prev_insn;
5846
160k
  int i;
5847
5848
160k
  opcode = inst->opcode;
5849
160k
  if (insn_sequence->instr)
5850
5.82k
    prev_insn = insn_sequence->instr + (insn_sequence->num_added_insns - 1);
5851
154k
  else
5852
154k
    prev_insn = NULL;
5853
5854
160k
  if (prev_insn
5855
5.82k
      && (prev_insn->opcode->constraints & C_SCAN_MOPS_PME)
5856
3.34k
      && prev_insn->opcode != opcode - 1)
5857
3.08k
    {
5858
3.08k
      mismatch_detail->kind = AARCH64_OPDE_EXPECTED_A_AFTER_B;
5859
3.08k
      mismatch_detail->error = NULL;
5860
3.08k
      mismatch_detail->index = -1;
5861
3.08k
      mismatch_detail->data[0].s = prev_insn->opcode[1].name;
5862
3.08k
      mismatch_detail->data[1].s = prev_insn->opcode->name;
5863
3.08k
      mismatch_detail->non_fatal = true;
5864
3.08k
      return false;
5865
3.08k
    }
5866
5867
157k
  if (opcode->constraints & C_SCAN_MOPS_PME)
5868
2.31k
    {
5869
2.31k
      if (is_new_section || !prev_insn || prev_insn->opcode != opcode - 1)
5870
2.04k
  {
5871
2.04k
    mismatch_detail->kind = AARCH64_OPDE_A_SHOULD_FOLLOW_B;
5872
2.04k
    mismatch_detail->error = NULL;
5873
2.04k
    mismatch_detail->index = -1;
5874
2.04k
    mismatch_detail->data[0].s = opcode->name;
5875
2.04k
    mismatch_detail->data[1].s = opcode[-1].name;
5876
2.04k
    mismatch_detail->non_fatal = true;
5877
2.04k
    return false;
5878
2.04k
  }
5879
5880
458
      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
448
  if ((opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd
5884
182
       || opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs
5885
86
       || opcode->operands[i] == AARCH64_OPND_MOPS_WB_Rn)
5886
448
      && prev_insn->operands[i].reg.regno != inst->operands[i].reg.regno)
5887
256
    {
5888
256
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5889
256
      if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd)
5890
170
        mismatch_detail->error = _("destination register differs from "
5891
86
           "preceding instruction");
5892
86
      else if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs)
5893
10
        mismatch_detail->error = _("source register differs from "
5894
76
           "preceding instruction");
5895
76
      else
5896
76
        mismatch_detail->error = _("size register differs from "
5897
256
           "preceding instruction");
5898
256
      mismatch_detail->index = i;
5899
256
      mismatch_detail->non_fatal = true;
5900
256
      return false;
5901
256
    }
5902
266
    }
5903
5904
155k
  return true;
5905
157k
}
5906
5907
/*  This function verifies that the instruction INST adheres to its specified
5908
    constraints.  If it does then ERR_OK is returned, if not then ERR_VFI is
5909
    returned and MISMATCH_DETAIL contains the reason why verification failed.
5910
5911
    The function is called both during assembly and disassembly.  If assembling
5912
    then ENCODING will be TRUE, else FALSE.  If dissassembling PC will be set
5913
    and will contain the PC of the current instruction w.r.t to the section.
5914
5915
    If ENCODING and PC=0 then you are at a start of a section.  The constraints
5916
    are verified against the given state insn_sequence which is updated as it
5917
    transitions through the verification.  */
5918
5919
enum err_type
5920
verify_constraints (const struct aarch64_inst *inst,
5921
        const aarch64_insn insn ATTRIBUTE_UNUSED,
5922
        bfd_vma pc,
5923
        bool encoding,
5924
        aarch64_operand_error *mismatch_detail,
5925
        aarch64_instr_sequence *insn_sequence)
5926
4.47M
{
5927
4.47M
  assert (inst);
5928
4.47M
  assert (inst->opcode);
5929
5930
4.47M
  const struct aarch64_opcode *opcode = inst->opcode;
5931
4.47M
  if (!opcode->constraints && !insn_sequence->instr)
5932
4.30M
    return ERR_OK;
5933
5934
4.47M
  assert (insn_sequence);
5935
5936
166k
  enum err_type res = ERR_OK;
5937
5938
  /* This instruction puts a constraint on the insn_sequence.  */
5939
166k
  if (opcode->flags & F_SCAN)
5940
5.97k
    {
5941
5.97k
      if (insn_sequence->instr)
5942
422
  {
5943
422
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5944
422
    mismatch_detail->error = _("instruction opens new dependency "
5945
422
             "sequence without ending previous one");
5946
422
    mismatch_detail->index = -1;
5947
422
    mismatch_detail->non_fatal = true;
5948
422
    res = ERR_VFI;
5949
422
  }
5950
5951
5.97k
      init_insn_sequence (inst, insn_sequence);
5952
5.97k
      return res;
5953
5.97k
    }
5954
5955
166k
  bool is_new_section = (!encoding && pc == 0);
5956
160k
  if (!verify_mops_pme_sequence (inst, is_new_section, mismatch_detail,
5957
160k
         insn_sequence))
5958
5.38k
    {
5959
5.38k
      res = ERR_VFI;
5960
5.38k
      if ((opcode->constraints & C_SCAN_MOPS_PME) != C_SCAN_MOPS_M)
5961
4.13k
  init_insn_sequence (NULL, insn_sequence);
5962
5.38k
    }
5963
5964
  /* Verify constraints on an existing sequence.  */
5965
160k
  if (insn_sequence->instr)
5966
2.74k
    {
5967
2.74k
      const struct aarch64_opcode* inst_opcode = insn_sequence->instr->opcode;
5968
      /* If we're decoding and we hit PC=0 with an open sequence then we haven't
5969
   closed a previous one that we should have.  */
5970
2.74k
      if (is_new_section && res == ERR_OK)
5971
0
  {
5972
0
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
5973
0
    mismatch_detail->error = _("previous `movprfx' sequence not closed");
5974
0
    mismatch_detail->index = -1;
5975
0
    mismatch_detail->non_fatal = true;
5976
0
    res = ERR_VFI;
5977
    /* Reset the sequence.  */
5978
0
    init_insn_sequence (NULL, insn_sequence);
5979
0
    return res;
5980
0
  }
5981
5982
      /* Validate C_SCAN_MOVPRFX constraints.  Move this to a lookup table.  */
5983
2.74k
      if (inst_opcode->constraints & C_SCAN_MOVPRFX)
5984
2.47k
  {
5985
    /* Check to see if the MOVPRFX SVE instruction is followed by an SVE
5986
       instruction for better error messages.  */
5987
2.47k
    bool sve_operand_p = false;
5988
8.22k
    for (int i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
5989
7.41k
      {
5990
7.41k
        enum aarch64_operand_class op_class
5991
7.41k
    = aarch64_get_operand_class (opcode->operands[i]);
5992
7.41k
        if (op_class == AARCH64_OPND_CLASS_SVE_REG
5993
6.44k
      || op_class == AARCH64_OPND_CLASS_SVE_REGLIST
5994
5.96k
      || op_class == AARCH64_OPND_CLASS_PRED_REG)
5995
1.65k
    {
5996
1.65k
      sve_operand_p = true;
5997
1.65k
      break;
5998
1.65k
    }
5999
7.41k
      }
6000
6001
2.47k
    if (!sve_operand_p)
6002
815
      {
6003
815
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6004
815
        mismatch_detail->error = _("SVE instruction expected after "
6005
815
           "`movprfx'");
6006
815
        mismatch_detail->index = -1;
6007
815
        mismatch_detail->non_fatal = true;
6008
815
        res = ERR_VFI;
6009
815
        goto done;
6010
815
      }
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.65k
    if (!(opcode->constraints & C_SCAN_MOVPRFX))
6015
768
      {
6016
768
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6017
768
        mismatch_detail->error = _("SVE `movprfx' compatible instruction "
6018
768
           "expected");
6019
768
        mismatch_detail->index = -1;
6020
768
        mismatch_detail->non_fatal = true;
6021
768
        res = ERR_VFI;
6022
768
        goto done;
6023
768
      }
6024
6025
    /* Next check for usage of the predicate register.  */
6026
891
    aarch64_opnd_info blk_dest = insn_sequence->instr->operands[0];
6027
891
    aarch64_opnd_info blk_pred, inst_pred;
6028
891
    memset (&blk_pred, 0, sizeof (aarch64_opnd_info));
6029
891
    memset (&inst_pred, 0, sizeof (aarch64_opnd_info));
6030
891
    bool predicated = false;
6031
891
    assert (blk_dest.type == AARCH64_OPND_SVE_Zd);
6032
6033
    /* Determine if the movprfx instruction used is predicated or not.  */
6034
891
    if (insn_sequence->instr->operands[1].type == AARCH64_OPND_SVE_Pg3)
6035
827
      {
6036
827
        predicated = true;
6037
827
        blk_pred = insn_sequence->instr->operands[1];
6038
827
      }
6039
6040
891
    unsigned char max_elem_size = 0;
6041
891
    unsigned char current_elem_size;
6042
891
    int num_op_used = 0, last_op_usage = 0;
6043
891
    int i, inst_pred_idx = -1;
6044
891
    int num_ops = aarch64_num_of_operands (opcode);
6045
4.08k
    for (i = 0; i < num_ops; i++)
6046
3.19k
      {
6047
3.19k
        aarch64_opnd_info inst_op = inst->operands[i];
6048
3.19k
        switch (inst_op.type)
6049
3.19k
    {
6050
1.15k
      case AARCH64_OPND_SVE_Zd:
6051
1.57k
      case AARCH64_OPND_SVE_Zm_5:
6052
1.67k
      case AARCH64_OPND_SVE_Zm_16:
6053
1.98k
      case AARCH64_OPND_SVE_Zn:
6054
1.98k
      case AARCH64_OPND_SVE_Zt:
6055
2.01k
      case AARCH64_OPND_SVE_Vm:
6056
2.02k
      case AARCH64_OPND_SVE_Vn:
6057
2.02k
      case AARCH64_OPND_Va:
6058
2.02k
      case AARCH64_OPND_Vn:
6059
2.02k
      case AARCH64_OPND_Vm:
6060
2.02k
      case AARCH64_OPND_Sn:
6061
2.02k
      case AARCH64_OPND_Sm:
6062
2.02k
        if (inst_op.reg.regno == blk_dest.reg.regno)
6063
679
          {
6064
679
      num_op_used++;
6065
679
      last_op_usage = i;
6066
679
          }
6067
2.02k
        current_elem_size
6068
2.02k
          = aarch64_get_qualifier_esize (inst_op.qualifier);
6069
2.02k
        if (current_elem_size > max_elem_size)
6070
891
          max_elem_size = current_elem_size;
6071
2.02k
        break;
6072
0
      case AARCH64_OPND_SVE_Pd:
6073
627
      case AARCH64_OPND_SVE_Pg3:
6074
627
      case AARCH64_OPND_SVE_Pg4_5:
6075
627
      case AARCH64_OPND_SVE_Pg4_10:
6076
713
      case AARCH64_OPND_SVE_Pg4_16:
6077
713
      case AARCH64_OPND_SVE_Pm:
6078
713
      case AARCH64_OPND_SVE_Pn:
6079
713
      case AARCH64_OPND_SVE_Pt:
6080
713
      case AARCH64_OPND_SME_Pm:
6081
713
        inst_pred = inst_op;
6082
713
        inst_pred_idx = i;
6083
713
        break;
6084
450
      default:
6085
450
        break;
6086
3.19k
    }
6087
3.19k
      }
6088
6089
891
     assert (max_elem_size != 0);
6090
891
     aarch64_opnd_info inst_dest = inst->operands[0];
6091
     /* Determine the size that should be used to compare against the
6092
        movprfx size.  */
6093
891
     current_elem_size
6094
891
       = opcode->constraints & C_MAX_ELEM
6095
891
         ? max_elem_size
6096
891
         : aarch64_get_qualifier_esize (inst_dest.qualifier);
6097
6098
    /* If movprfx is predicated do some extra checks.  */
6099
891
    if (predicated)
6100
827
      {
6101
        /* The instruction must be predicated.  */
6102
827
        if (inst_pred_idx < 0)
6103
178
    {
6104
178
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6105
178
      mismatch_detail->error = _("predicated instruction expected "
6106
178
               "after `movprfx'");
6107
178
      mismatch_detail->index = -1;
6108
178
      mismatch_detail->non_fatal = true;
6109
178
      res = ERR_VFI;
6110
178
      goto done;
6111
178
    }
6112
6113
        /* The instruction must have a merging predicate.  */
6114
649
        if (inst_pred.qualifier != AARCH64_OPND_QLF_P_M)
6115
16
    {
6116
16
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6117
16
      mismatch_detail->error = _("merging predicate expected due "
6118
16
               "to preceding `movprfx'");
6119
16
      mismatch_detail->index = inst_pred_idx;
6120
16
      mismatch_detail->non_fatal = true;
6121
16
      res = ERR_VFI;
6122
16
      goto done;
6123
16
    }
6124
6125
        /* The same register must be used in instruction.  */
6126
633
        if (blk_pred.reg.regno != inst_pred.reg.regno)
6127
319
    {
6128
319
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6129
319
      mismatch_detail->error = _("predicate register differs "
6130
319
               "from that in preceding "
6131
319
               "`movprfx'");
6132
319
      mismatch_detail->index = inst_pred_idx;
6133
319
      mismatch_detail->non_fatal = true;
6134
319
      res = ERR_VFI;
6135
319
      goto done;
6136
319
    }
6137
633
      }
6138
6139
    /* Destructive operations by definition must allow one usage of the
6140
       same register.  */
6141
378
    int allowed_usage
6142
378
      = aarch64_is_destructive_by_operands (opcode) ? 2 : 1;
6143
6144
    /* Operand is not used at all.  */
6145
378
    if (num_op_used == 0)
6146
54
      {
6147
54
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6148
54
        mismatch_detail->error = _("output register of preceding "
6149
54
           "`movprfx' not used in current "
6150
54
           "instruction");
6151
54
        mismatch_detail->index = 0;
6152
54
        mismatch_detail->non_fatal = true;
6153
54
        res = ERR_VFI;
6154
54
        goto done;
6155
54
      }
6156
6157
    /* We now know it's used, now determine exactly where it's used.  */
6158
324
    if (blk_dest.reg.regno != inst_dest.reg.regno)
6159
49
      {
6160
49
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6161
49
        mismatch_detail->error = _("output register of preceding "
6162
49
           "`movprfx' expected as output");
6163
49
        mismatch_detail->index = 0;
6164
49
        mismatch_detail->non_fatal = true;
6165
49
        res = ERR_VFI;
6166
49
        goto done;
6167
49
      }
6168
6169
    /* Operand used more than allowed for the specific opcode type.  */
6170
275
    if (num_op_used > allowed_usage)
6171
141
      {
6172
141
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6173
141
        mismatch_detail->error = _("output register of preceding "
6174
141
           "`movprfx' used as input");
6175
141
        mismatch_detail->index = last_op_usage;
6176
141
        mismatch_detail->non_fatal = true;
6177
141
        res = ERR_VFI;
6178
141
        goto done;
6179
141
      }
6180
6181
    /* Now the only thing left is the qualifiers checks.  The register
6182
       must have the same maximum element size.  */
6183
134
    if (inst_dest.qualifier
6184
134
        && blk_dest.qualifier
6185
73
        && current_elem_size
6186
73
     != aarch64_get_qualifier_esize (blk_dest.qualifier))
6187
6
      {
6188
6
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6189
6
        mismatch_detail->error = _("register size not compatible with "
6190
6
           "previous `movprfx'");
6191
6
        mismatch_detail->index = 0;
6192
6
        mismatch_detail->non_fatal = true;
6193
6
        res = ERR_VFI;
6194
6
        goto done;
6195
6
      }
6196
134
  }
6197
6198
2.74k
    done:
6199
2.74k
      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.47k
  init_insn_sequence (NULL, insn_sequence);
6203
268
      else
6204
268
  add_insn_to_sequence (inst, insn_sequence);
6205
2.74k
    }
6206
6207
160k
  return res;
6208
160k
}
6209
6210
6211
/* Return true if VALUE cannot be moved into an SVE register using DUP
6212
   (with any element size, not just ESIZE) and if using DUPM would
6213
   therefore be OK.  ESIZE is the number of bytes in the immediate.  */
6214
6215
bool
6216
aarch64_sve_dupm_mov_immediate_p (uint64_t uvalue, int esize)
6217
4.93k
{
6218
4.93k
  int64_t svalue = uvalue;
6219
4.93k
  uint64_t upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
6220
6221
4.93k
  if ((uvalue & ~upper) != uvalue && (uvalue | upper) != uvalue)
6222
0
    return false;
6223
4.93k
  if (esize <= 4 || (uint32_t) uvalue == (uint32_t) (uvalue >> 32))
6224
4.40k
    {
6225
4.40k
      svalue = (int32_t) uvalue;
6226
4.40k
      if (esize <= 2 || (uint16_t) uvalue == (uint16_t) (uvalue >> 16))
6227
1.08k
  {
6228
1.08k
    svalue = (int16_t) uvalue;
6229
1.08k
    if (esize == 1 || (uint8_t) uvalue == (uint8_t) (uvalue >> 8))
6230
495
      return false;
6231
1.08k
  }
6232
4.40k
    }
6233
4.43k
  if ((svalue & 0xff) == 0)
6234
1.81k
    svalue /= 256;
6235
4.43k
  return svalue < -128 || svalue >= 128;
6236
4.93k
}
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"