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