]> git.proxmox.com Git - mirror_qemu.git/blame - target/arm/translate-sve.c
target/arm: Use TRANS_FEAT for gen_gvec_ool_arg_zpz
[mirror_qemu.git] / target / arm / translate-sve.c
CommitLineData
38388f7e
RH
1/*
2 * AArch64 SVE translation
3 *
4 * Copyright (c) 2018 Linaro, Ltd
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
50f57e09 9 * version 2.1 of the License, or (at your option) any later version.
38388f7e
RH
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "qemu/osdep.h"
21#include "cpu.h"
22#include "exec/exec-all.h"
dcb32f1d
PMD
23#include "tcg/tcg-op.h"
24#include "tcg/tcg-op-gvec.h"
25#include "tcg/tcg-gvec-desc.h"
38388f7e
RH
26#include "qemu/log.h"
27#include "arm_ldst.h"
28#include "translate.h"
29#include "internals.h"
30#include "exec/helper-proto.h"
31#include "exec/helper-gen.h"
32#include "exec/log.h"
38388f7e 33#include "translate-a64.h"
cc48affe 34#include "fpu/softfloat.h"
38388f7e 35
757f9cff 36
9ee3a611
RH
37typedef void GVecGen2sFn(unsigned, uint32_t, uint32_t,
38 TCGv_i64, uint32_t, uint32_t);
39
38cadeba
RH
40typedef void gen_helper_gvec_flags_3(TCGv_i32, TCGv_ptr, TCGv_ptr,
41 TCGv_ptr, TCGv_i32);
757f9cff
RH
42typedef void gen_helper_gvec_flags_4(TCGv_i32, TCGv_ptr, TCGv_ptr,
43 TCGv_ptr, TCGv_ptr, TCGv_i32);
44
c4e7c493 45typedef void gen_helper_gvec_mem(TCGv_env, TCGv_ptr, TCGv_i64, TCGv_i32);
f6dbf62a
RH
46typedef void gen_helper_gvec_mem_scatter(TCGv_env, TCGv_ptr, TCGv_ptr,
47 TCGv_ptr, TCGv_i64, TCGv_i32);
c4e7c493 48
ccd841c3
RH
49/*
50 * Helpers for extracting complex instruction fields.
51 */
52
53/* See e.g. ASR (immediate, predicated).
54 * Returns -1 for unallocated encoding; diagnose later.
55 */
451e4ffd 56static int tszimm_esz(DisasContext *s, int x)
ccd841c3
RH
57{
58 x >>= 3; /* discard imm3 */
59 return 31 - clz32(x);
60}
61
451e4ffd 62static int tszimm_shr(DisasContext *s, int x)
ccd841c3 63{
451e4ffd 64 return (16 << tszimm_esz(s, x)) - x;
ccd841c3
RH
65}
66
67/* See e.g. LSL (immediate, predicated). */
451e4ffd 68static int tszimm_shl(DisasContext *s, int x)
ccd841c3 69{
451e4ffd 70 return x - (8 << tszimm_esz(s, x));
ccd841c3
RH
71}
72
f25a2361 73/* The SH bit is in bit 8. Extract the low 8 and shift. */
451e4ffd 74static inline int expand_imm_sh8s(DisasContext *s, int x)
f25a2361
RH
75{
76 return (int8_t)x << (x & 0x100 ? 8 : 0);
77}
78
451e4ffd 79static inline int expand_imm_sh8u(DisasContext *s, int x)
6e6a157d
RH
80{
81 return (uint8_t)x << (x & 0x100 ? 8 : 0);
82}
83
c4e7c493
RH
84/* Convert a 2-bit memory size (msz) to a 4-bit data type (dtype)
85 * with unsigned data. C.f. SVE Memory Contiguous Load Group.
86 */
451e4ffd 87static inline int msz_dtype(DisasContext *s, int msz)
c4e7c493
RH
88{
89 static const uint8_t dtype[4] = { 0, 5, 10, 15 };
90 return dtype[msz];
91}
92
38388f7e
RH
93/*
94 * Include the generated decoder.
95 */
96
139c1837 97#include "decode-sve.c.inc"
38388f7e
RH
98
99/*
100 * Implement all of the translator functions referenced by the decoder.
101 */
102
d1822297
RH
103/* Return the offset info CPUARMState of the predicate vector register Pn.
104 * Note for this purpose, FFR is P16.
105 */
106static inline int pred_full_reg_offset(DisasContext *s, int regno)
107{
108 return offsetof(CPUARMState, vfp.pregs[regno]);
109}
110
111/* Return the byte size of the whole predicate register, VL / 64. */
112static inline int pred_full_reg_size(DisasContext *s)
113{
114 return s->sve_len >> 3;
115}
116
516e246a
RH
117/* Round up the size of a register to a size allowed by
118 * the tcg vector infrastructure. Any operation which uses this
119 * size may assume that the bits above pred_full_reg_size are zero,
120 * and must leave them the same way.
121 *
122 * Note that this is not needed for the vector registers as they
123 * are always properly sized for tcg vectors.
124 */
125static int size_for_gvec(int size)
126{
127 if (size <= 8) {
128 return 8;
129 } else {
130 return QEMU_ALIGN_UP(size, 16);
131 }
132}
133
134static int pred_gvec_reg_size(DisasContext *s)
135{
136 return size_for_gvec(pred_full_reg_size(s));
137}
138
40e32e5a 139/* Invoke an out-of-line helper on 2 Zregs. */
c5edf07d 140static bool gen_gvec_ool_zz(DisasContext *s, gen_helper_gvec_2 *fn,
40e32e5a
RH
141 int rd, int rn, int data)
142{
c5edf07d
RH
143 if (fn == NULL) {
144 return false;
145 }
146 if (sve_access_check(s)) {
147 unsigned vsz = vec_full_reg_size(s);
148 tcg_gen_gvec_2_ool(vec_full_reg_offset(s, rd),
149 vec_full_reg_offset(s, rn),
150 vsz, vsz, data, fn);
151 }
152 return true;
40e32e5a
RH
153}
154
e645d1a1 155/* Invoke an out-of-line helper on 3 Zregs. */
913a8a00 156static bool gen_gvec_ool_zzz(DisasContext *s, gen_helper_gvec_3 *fn,
e645d1a1
RH
157 int rd, int rn, int rm, int data)
158{
913a8a00
RH
159 if (fn == NULL) {
160 return false;
161 }
162 if (sve_access_check(s)) {
163 unsigned vsz = vec_full_reg_size(s);
164 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, rd),
165 vec_full_reg_offset(s, rn),
166 vec_full_reg_offset(s, rm),
167 vsz, vsz, data, fn);
168 }
169 return true;
e645d1a1
RH
170}
171
84a272f5
RH
172static bool gen_gvec_ool_arg_zzz(DisasContext *s, gen_helper_gvec_3 *fn,
173 arg_rrr_esz *a, int data)
174{
175 return gen_gvec_ool_zzz(s, fn, a->rd, a->rn, a->rm, data);
176}
177
38650638 178/* Invoke an out-of-line helper on 4 Zregs. */
7ad416b1 179static bool gen_gvec_ool_zzzz(DisasContext *s, gen_helper_gvec_4 *fn,
38650638
RH
180 int rd, int rn, int rm, int ra, int data)
181{
7ad416b1
RH
182 if (fn == NULL) {
183 return false;
184 }
185 if (sve_access_check(s)) {
186 unsigned vsz = vec_full_reg_size(s);
187 tcg_gen_gvec_4_ool(vec_full_reg_offset(s, rd),
188 vec_full_reg_offset(s, rn),
189 vec_full_reg_offset(s, rm),
190 vec_full_reg_offset(s, ra),
191 vsz, vsz, data, fn);
192 }
193 return true;
38650638
RH
194}
195
cab79ac9
RH
196static bool gen_gvec_ool_arg_zzzz(DisasContext *s, gen_helper_gvec_4 *fn,
197 arg_rrrr_esz *a, int data)
198{
199 return gen_gvec_ool_zzzz(s, fn, a->rd, a->rn, a->rm, a->ra, data);
200}
201
e82d3536
RH
202static bool gen_gvec_ool_arg_zzxz(DisasContext *s, gen_helper_gvec_4 *fn,
203 arg_rrxr_esz *a)
204{
205 return gen_gvec_ool_zzzz(s, fn, a->rd, a->rn, a->rm, a->ra, a->index);
206}
207
96a461f7 208/* Invoke an out-of-line helper on 2 Zregs and a predicate. */
8fb27a21 209static bool gen_gvec_ool_zzp(DisasContext *s, gen_helper_gvec_3 *fn,
96a461f7
RH
210 int rd, int rn, int pg, int data)
211{
8fb27a21
RH
212 if (fn == NULL) {
213 return false;
214 }
215 if (sve_access_check(s)) {
216 unsigned vsz = vec_full_reg_size(s);
217 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, rd),
218 vec_full_reg_offset(s, rn),
219 pred_full_reg_offset(s, pg),
220 vsz, vsz, data, fn);
221 }
222 return true;
96a461f7
RH
223}
224
b051809a
RH
225static bool gen_gvec_ool_arg_zpz(DisasContext *s, gen_helper_gvec_3 *fn,
226 arg_rpr_esz *a, int data)
227{
228 return gen_gvec_ool_zzp(s, fn, a->rd, a->rn, a->pg, data);
229}
230
231
36cbb7a8
RH
232/* Invoke an out-of-line helper on 3 Zregs and a predicate. */
233static void gen_gvec_ool_zzzp(DisasContext *s, gen_helper_gvec_4 *fn,
234 int rd, int rn, int rm, int pg, int data)
235{
236 unsigned vsz = vec_full_reg_size(s);
237 tcg_gen_gvec_4_ool(vec_full_reg_offset(s, rd),
238 vec_full_reg_offset(s, rn),
239 vec_full_reg_offset(s, rm),
240 pred_full_reg_offset(s, pg),
241 vsz, vsz, data, fn);
242}
f7d79c41 243
36cbb7a8 244/* Invoke a vector expander on two Zregs. */
f7d79c41
RH
245static void gen_gvec_fn_zz(DisasContext *s, GVecGen2Fn *gvec_fn,
246 int esz, int rd, int rn)
38388f7e 247{
f7d79c41
RH
248 unsigned vsz = vec_full_reg_size(s);
249 gvec_fn(esz, vec_full_reg_offset(s, rd),
250 vec_full_reg_offset(s, rn), vsz, vsz);
38388f7e
RH
251}
252
39eea561 253/* Invoke a vector expander on three Zregs. */
28c4da31
RH
254static void gen_gvec_fn_zzz(DisasContext *s, GVecGen3Fn *gvec_fn,
255 int esz, int rd, int rn, int rm)
38388f7e 256{
28c4da31
RH
257 unsigned vsz = vec_full_reg_size(s);
258 gvec_fn(esz, vec_full_reg_offset(s, rd),
259 vec_full_reg_offset(s, rn),
260 vec_full_reg_offset(s, rm), vsz, vsz);
38388f7e
RH
261}
262
911cdc6d
RH
263/* Invoke a vector expander on four Zregs. */
264static void gen_gvec_fn_zzzz(DisasContext *s, GVecGen4Fn *gvec_fn,
265 int esz, int rd, int rn, int rm, int ra)
266{
267 unsigned vsz = vec_full_reg_size(s);
268 gvec_fn(esz, vec_full_reg_offset(s, rd),
269 vec_full_reg_offset(s, rn),
270 vec_full_reg_offset(s, rm),
271 vec_full_reg_offset(s, ra), vsz, vsz);
272}
273
39eea561
RH
274/* Invoke a vector move on two Zregs. */
275static bool do_mov_z(DisasContext *s, int rd, int rn)
38388f7e 276{
f7d79c41
RH
277 if (sve_access_check(s)) {
278 gen_gvec_fn_zz(s, tcg_gen_gvec_mov, MO_8, rd, rn);
279 }
280 return true;
38388f7e
RH
281}
282
d9d78dcc
RH
283/* Initialize a Zreg with replications of a 64-bit immediate. */
284static void do_dupi_z(DisasContext *s, int rd, uint64_t word)
285{
286 unsigned vsz = vec_full_reg_size(s);
8711e71f 287 tcg_gen_gvec_dup_imm(MO_64, vec_full_reg_offset(s, rd), vsz, vsz, word);
d9d78dcc
RH
288}
289
516e246a 290/* Invoke a vector expander on three Pregs. */
dd81a8d7
RH
291static void gen_gvec_fn_ppp(DisasContext *s, GVecGen3Fn *gvec_fn,
292 int rd, int rn, int rm)
516e246a 293{
dd81a8d7
RH
294 unsigned psz = pred_gvec_reg_size(s);
295 gvec_fn(MO_64, pred_full_reg_offset(s, rd),
296 pred_full_reg_offset(s, rn),
297 pred_full_reg_offset(s, rm), psz, psz);
516e246a
RH
298}
299
300/* Invoke a vector move on two Pregs. */
301static bool do_mov_p(DisasContext *s, int rd, int rn)
302{
d0b2df5a
RH
303 if (sve_access_check(s)) {
304 unsigned psz = pred_gvec_reg_size(s);
305 tcg_gen_gvec_mov(MO_8, pred_full_reg_offset(s, rd),
306 pred_full_reg_offset(s, rn), psz, psz);
307 }
308 return true;
516e246a
RH
309}
310
9e18d7a6
RH
311/* Set the cpu flags as per a return from an SVE helper. */
312static void do_pred_flags(TCGv_i32 t)
313{
314 tcg_gen_mov_i32(cpu_NF, t);
315 tcg_gen_andi_i32(cpu_ZF, t, 2);
316 tcg_gen_andi_i32(cpu_CF, t, 1);
317 tcg_gen_movi_i32(cpu_VF, 0);
318}
319
320/* Subroutines computing the ARM PredTest psuedofunction. */
321static void do_predtest1(TCGv_i64 d, TCGv_i64 g)
322{
323 TCGv_i32 t = tcg_temp_new_i32();
324
325 gen_helper_sve_predtest1(t, d, g);
326 do_pred_flags(t);
327 tcg_temp_free_i32(t);
328}
329
330static void do_predtest(DisasContext *s, int dofs, int gofs, int words)
331{
332 TCGv_ptr dptr = tcg_temp_new_ptr();
333 TCGv_ptr gptr = tcg_temp_new_ptr();
392acacc 334 TCGv_i32 t = tcg_temp_new_i32();
9e18d7a6
RH
335
336 tcg_gen_addi_ptr(dptr, cpu_env, dofs);
337 tcg_gen_addi_ptr(gptr, cpu_env, gofs);
9e18d7a6 338
392acacc 339 gen_helper_sve_predtest(t, dptr, gptr, tcg_constant_i32(words));
9e18d7a6
RH
340 tcg_temp_free_ptr(dptr);
341 tcg_temp_free_ptr(gptr);
342
343 do_pred_flags(t);
344 tcg_temp_free_i32(t);
345}
346
028e2a7b
RH
347/* For each element size, the bits within a predicate word that are active. */
348const uint64_t pred_esz_masks[4] = {
349 0xffffffffffffffffull, 0x5555555555555555ull,
350 0x1111111111111111ull, 0x0101010101010101ull
351};
352
39eea561
RH
353/*
354 *** SVE Logical - Unpredicated Group
355 */
356
28c4da31
RH
357static bool do_zzz_fn(DisasContext *s, arg_rrr_esz *a, GVecGen3Fn *gvec_fn)
358{
359 if (sve_access_check(s)) {
360 gen_gvec_fn_zzz(s, gvec_fn, a->esz, a->rd, a->rn, a->rm);
361 }
362 return true;
363}
364
3a7be554 365static bool trans_AND_zzz(DisasContext *s, arg_rrr_esz *a)
39eea561 366{
28c4da31 367 return do_zzz_fn(s, a, tcg_gen_gvec_and);
39eea561
RH
368}
369
3a7be554 370static bool trans_ORR_zzz(DisasContext *s, arg_rrr_esz *a)
39eea561 371{
28c4da31 372 return do_zzz_fn(s, a, tcg_gen_gvec_or);
39eea561
RH
373}
374
3a7be554 375static bool trans_EOR_zzz(DisasContext *s, arg_rrr_esz *a)
39eea561 376{
28c4da31 377 return do_zzz_fn(s, a, tcg_gen_gvec_xor);
39eea561
RH
378}
379
3a7be554 380static bool trans_BIC_zzz(DisasContext *s, arg_rrr_esz *a)
38388f7e 381{
28c4da31 382 return do_zzz_fn(s, a, tcg_gen_gvec_andc);
38388f7e 383}
d1822297 384
e6eba6e5
RH
385static void gen_xar8_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, int64_t sh)
386{
387 TCGv_i64 t = tcg_temp_new_i64();
388 uint64_t mask = dup_const(MO_8, 0xff >> sh);
389
390 tcg_gen_xor_i64(t, n, m);
391 tcg_gen_shri_i64(d, t, sh);
392 tcg_gen_shli_i64(t, t, 8 - sh);
393 tcg_gen_andi_i64(d, d, mask);
394 tcg_gen_andi_i64(t, t, ~mask);
395 tcg_gen_or_i64(d, d, t);
396 tcg_temp_free_i64(t);
397}
398
399static void gen_xar16_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, int64_t sh)
400{
401 TCGv_i64 t = tcg_temp_new_i64();
402 uint64_t mask = dup_const(MO_16, 0xffff >> sh);
403
404 tcg_gen_xor_i64(t, n, m);
405 tcg_gen_shri_i64(d, t, sh);
406 tcg_gen_shli_i64(t, t, 16 - sh);
407 tcg_gen_andi_i64(d, d, mask);
408 tcg_gen_andi_i64(t, t, ~mask);
409 tcg_gen_or_i64(d, d, t);
410 tcg_temp_free_i64(t);
411}
412
413static void gen_xar_i32(TCGv_i32 d, TCGv_i32 n, TCGv_i32 m, int32_t sh)
414{
415 tcg_gen_xor_i32(d, n, m);
416 tcg_gen_rotri_i32(d, d, sh);
417}
418
419static void gen_xar_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, int64_t sh)
420{
421 tcg_gen_xor_i64(d, n, m);
422 tcg_gen_rotri_i64(d, d, sh);
423}
424
425static void gen_xar_vec(unsigned vece, TCGv_vec d, TCGv_vec n,
426 TCGv_vec m, int64_t sh)
427{
428 tcg_gen_xor_vec(vece, d, n, m);
429 tcg_gen_rotri_vec(vece, d, d, sh);
430}
431
432void gen_gvec_xar(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,
433 uint32_t rm_ofs, int64_t shift,
434 uint32_t opr_sz, uint32_t max_sz)
435{
436 static const TCGOpcode vecop[] = { INDEX_op_rotli_vec, 0 };
437 static const GVecGen3i ops[4] = {
438 { .fni8 = gen_xar8_i64,
439 .fniv = gen_xar_vec,
440 .fno = gen_helper_sve2_xar_b,
441 .opt_opc = vecop,
442 .vece = MO_8 },
443 { .fni8 = gen_xar16_i64,
444 .fniv = gen_xar_vec,
445 .fno = gen_helper_sve2_xar_h,
446 .opt_opc = vecop,
447 .vece = MO_16 },
448 { .fni4 = gen_xar_i32,
449 .fniv = gen_xar_vec,
450 .fno = gen_helper_sve2_xar_s,
451 .opt_opc = vecop,
452 .vece = MO_32 },
453 { .fni8 = gen_xar_i64,
454 .fniv = gen_xar_vec,
455 .fno = gen_helper_gvec_xar_d,
456 .opt_opc = vecop,
457 .vece = MO_64 }
458 };
459 int esize = 8 << vece;
460
461 /* The SVE2 range is 1 .. esize; the AdvSIMD range is 0 .. esize-1. */
462 tcg_debug_assert(shift >= 0);
463 tcg_debug_assert(shift <= esize);
464 shift &= esize - 1;
465
466 if (shift == 0) {
467 /* xar with no rotate devolves to xor. */
468 tcg_gen_gvec_xor(vece, rd_ofs, rn_ofs, rm_ofs, opr_sz, max_sz);
469 } else {
470 tcg_gen_gvec_3i(rd_ofs, rn_ofs, rm_ofs, opr_sz, max_sz,
471 shift, &ops[vece]);
472 }
473}
474
475static bool trans_XAR(DisasContext *s, arg_rrri_esz *a)
476{
477 if (a->esz < 0 || !dc_isar_feature(aa64_sve2, s)) {
478 return false;
479 }
480 if (sve_access_check(s)) {
481 unsigned vsz = vec_full_reg_size(s);
482 gen_gvec_xar(a->esz, vec_full_reg_offset(s, a->rd),
483 vec_full_reg_offset(s, a->rn),
484 vec_full_reg_offset(s, a->rm), a->imm, vsz, vsz);
485 }
486 return true;
487}
488
911cdc6d
RH
489static bool do_sve2_zzzz_fn(DisasContext *s, arg_rrrr_esz *a, GVecGen4Fn *fn)
490{
491 if (!dc_isar_feature(aa64_sve2, s)) {
492 return false;
493 }
494 if (sve_access_check(s)) {
495 gen_gvec_fn_zzzz(s, fn, a->esz, a->rd, a->rn, a->rm, a->ra);
496 }
497 return true;
498}
499
500static void gen_eor3_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, TCGv_i64 k)
501{
502 tcg_gen_xor_i64(d, n, m);
503 tcg_gen_xor_i64(d, d, k);
504}
505
506static void gen_eor3_vec(unsigned vece, TCGv_vec d, TCGv_vec n,
507 TCGv_vec m, TCGv_vec k)
508{
509 tcg_gen_xor_vec(vece, d, n, m);
510 tcg_gen_xor_vec(vece, d, d, k);
511}
512
513static void gen_eor3(unsigned vece, uint32_t d, uint32_t n, uint32_t m,
514 uint32_t a, uint32_t oprsz, uint32_t maxsz)
515{
516 static const GVecGen4 op = {
517 .fni8 = gen_eor3_i64,
518 .fniv = gen_eor3_vec,
519 .fno = gen_helper_sve2_eor3,
520 .vece = MO_64,
521 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
522 };
523 tcg_gen_gvec_4(d, n, m, a, oprsz, maxsz, &op);
524}
525
526static bool trans_EOR3(DisasContext *s, arg_rrrr_esz *a)
527{
528 return do_sve2_zzzz_fn(s, a, gen_eor3);
529}
530
531static void gen_bcax_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, TCGv_i64 k)
532{
533 tcg_gen_andc_i64(d, m, k);
534 tcg_gen_xor_i64(d, d, n);
535}
536
537static void gen_bcax_vec(unsigned vece, TCGv_vec d, TCGv_vec n,
538 TCGv_vec m, TCGv_vec k)
539{
540 tcg_gen_andc_vec(vece, d, m, k);
541 tcg_gen_xor_vec(vece, d, d, n);
542}
543
544static void gen_bcax(unsigned vece, uint32_t d, uint32_t n, uint32_t m,
545 uint32_t a, uint32_t oprsz, uint32_t maxsz)
546{
547 static const GVecGen4 op = {
548 .fni8 = gen_bcax_i64,
549 .fniv = gen_bcax_vec,
550 .fno = gen_helper_sve2_bcax,
551 .vece = MO_64,
552 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
553 };
554 tcg_gen_gvec_4(d, n, m, a, oprsz, maxsz, &op);
555}
556
557static bool trans_BCAX(DisasContext *s, arg_rrrr_esz *a)
558{
559 return do_sve2_zzzz_fn(s, a, gen_bcax);
560}
561
562static void gen_bsl(unsigned vece, uint32_t d, uint32_t n, uint32_t m,
563 uint32_t a, uint32_t oprsz, uint32_t maxsz)
564{
565 /* BSL differs from the generic bitsel in argument ordering. */
566 tcg_gen_gvec_bitsel(vece, d, a, n, m, oprsz, maxsz);
567}
568
569static bool trans_BSL(DisasContext *s, arg_rrrr_esz *a)
570{
571 return do_sve2_zzzz_fn(s, a, gen_bsl);
572}
573
574static void gen_bsl1n_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, TCGv_i64 k)
575{
576 tcg_gen_andc_i64(n, k, n);
577 tcg_gen_andc_i64(m, m, k);
578 tcg_gen_or_i64(d, n, m);
579}
580
581static void gen_bsl1n_vec(unsigned vece, TCGv_vec d, TCGv_vec n,
582 TCGv_vec m, TCGv_vec k)
583{
584 if (TCG_TARGET_HAS_bitsel_vec) {
585 tcg_gen_not_vec(vece, n, n);
586 tcg_gen_bitsel_vec(vece, d, k, n, m);
587 } else {
588 tcg_gen_andc_vec(vece, n, k, n);
589 tcg_gen_andc_vec(vece, m, m, k);
590 tcg_gen_or_vec(vece, d, n, m);
591 }
592}
593
594static void gen_bsl1n(unsigned vece, uint32_t d, uint32_t n, uint32_t m,
595 uint32_t a, uint32_t oprsz, uint32_t maxsz)
596{
597 static const GVecGen4 op = {
598 .fni8 = gen_bsl1n_i64,
599 .fniv = gen_bsl1n_vec,
600 .fno = gen_helper_sve2_bsl1n,
601 .vece = MO_64,
602 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
603 };
604 tcg_gen_gvec_4(d, n, m, a, oprsz, maxsz, &op);
605}
606
607static bool trans_BSL1N(DisasContext *s, arg_rrrr_esz *a)
608{
609 return do_sve2_zzzz_fn(s, a, gen_bsl1n);
610}
611
612static void gen_bsl2n_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, TCGv_i64 k)
613{
614 /*
615 * Z[dn] = (n & k) | (~m & ~k)
616 * = | ~(m | k)
617 */
618 tcg_gen_and_i64(n, n, k);
619 if (TCG_TARGET_HAS_orc_i64) {
620 tcg_gen_or_i64(m, m, k);
621 tcg_gen_orc_i64(d, n, m);
622 } else {
623 tcg_gen_nor_i64(m, m, k);
624 tcg_gen_or_i64(d, n, m);
625 }
626}
627
628static void gen_bsl2n_vec(unsigned vece, TCGv_vec d, TCGv_vec n,
629 TCGv_vec m, TCGv_vec k)
630{
631 if (TCG_TARGET_HAS_bitsel_vec) {
632 tcg_gen_not_vec(vece, m, m);
633 tcg_gen_bitsel_vec(vece, d, k, n, m);
634 } else {
635 tcg_gen_and_vec(vece, n, n, k);
636 tcg_gen_or_vec(vece, m, m, k);
637 tcg_gen_orc_vec(vece, d, n, m);
638 }
639}
640
641static void gen_bsl2n(unsigned vece, uint32_t d, uint32_t n, uint32_t m,
642 uint32_t a, uint32_t oprsz, uint32_t maxsz)
643{
644 static const GVecGen4 op = {
645 .fni8 = gen_bsl2n_i64,
646 .fniv = gen_bsl2n_vec,
647 .fno = gen_helper_sve2_bsl2n,
648 .vece = MO_64,
649 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
650 };
651 tcg_gen_gvec_4(d, n, m, a, oprsz, maxsz, &op);
652}
653
654static bool trans_BSL2N(DisasContext *s, arg_rrrr_esz *a)
655{
656 return do_sve2_zzzz_fn(s, a, gen_bsl2n);
657}
658
659static void gen_nbsl_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m, TCGv_i64 k)
660{
661 tcg_gen_and_i64(n, n, k);
662 tcg_gen_andc_i64(m, m, k);
663 tcg_gen_nor_i64(d, n, m);
664}
665
666static void gen_nbsl_vec(unsigned vece, TCGv_vec d, TCGv_vec n,
667 TCGv_vec m, TCGv_vec k)
668{
669 tcg_gen_bitsel_vec(vece, d, k, n, m);
670 tcg_gen_not_vec(vece, d, d);
671}
672
673static void gen_nbsl(unsigned vece, uint32_t d, uint32_t n, uint32_t m,
674 uint32_t a, uint32_t oprsz, uint32_t maxsz)
675{
676 static const GVecGen4 op = {
677 .fni8 = gen_nbsl_i64,
678 .fniv = gen_nbsl_vec,
679 .fno = gen_helper_sve2_nbsl,
680 .vece = MO_64,
681 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
682 };
683 tcg_gen_gvec_4(d, n, m, a, oprsz, maxsz, &op);
684}
685
686static bool trans_NBSL(DisasContext *s, arg_rrrr_esz *a)
687{
688 return do_sve2_zzzz_fn(s, a, gen_nbsl);
689}
690
fea98f9c
RH
691/*
692 *** SVE Integer Arithmetic - Unpredicated Group
693 */
694
3a7be554 695static bool trans_ADD_zzz(DisasContext *s, arg_rrr_esz *a)
fea98f9c 696{
28c4da31 697 return do_zzz_fn(s, a, tcg_gen_gvec_add);
fea98f9c
RH
698}
699
3a7be554 700static bool trans_SUB_zzz(DisasContext *s, arg_rrr_esz *a)
fea98f9c 701{
28c4da31 702 return do_zzz_fn(s, a, tcg_gen_gvec_sub);
fea98f9c
RH
703}
704
3a7be554 705static bool trans_SQADD_zzz(DisasContext *s, arg_rrr_esz *a)
fea98f9c 706{
28c4da31 707 return do_zzz_fn(s, a, tcg_gen_gvec_ssadd);
fea98f9c
RH
708}
709
3a7be554 710static bool trans_SQSUB_zzz(DisasContext *s, arg_rrr_esz *a)
fea98f9c 711{
28c4da31 712 return do_zzz_fn(s, a, tcg_gen_gvec_sssub);
fea98f9c
RH
713}
714
3a7be554 715static bool trans_UQADD_zzz(DisasContext *s, arg_rrr_esz *a)
fea98f9c 716{
28c4da31 717 return do_zzz_fn(s, a, tcg_gen_gvec_usadd);
fea98f9c
RH
718}
719
3a7be554 720static bool trans_UQSUB_zzz(DisasContext *s, arg_rrr_esz *a)
fea98f9c 721{
28c4da31 722 return do_zzz_fn(s, a, tcg_gen_gvec_ussub);
fea98f9c
RH
723}
724
f97cfd59
RH
725/*
726 *** SVE Integer Arithmetic - Binary Predicated Group
727 */
728
729static bool do_zpzz_ool(DisasContext *s, arg_rprr_esz *a, gen_helper_gvec_4 *fn)
730{
f97cfd59
RH
731 if (fn == NULL) {
732 return false;
733 }
734 if (sve_access_check(s)) {
36cbb7a8 735 gen_gvec_ool_zzzp(s, fn, a->rd, a->rn, a->rm, a->pg, 0);
f97cfd59
RH
736 }
737 return true;
738}
739
a2103582
RH
740/* Select active elememnts from Zn and inactive elements from Zm,
741 * storing the result in Zd.
742 */
743static void do_sel_z(DisasContext *s, int rd, int rn, int rm, int pg, int esz)
744{
745 static gen_helper_gvec_4 * const fns[4] = {
746 gen_helper_sve_sel_zpzz_b, gen_helper_sve_sel_zpzz_h,
747 gen_helper_sve_sel_zpzz_s, gen_helper_sve_sel_zpzz_d
748 };
36cbb7a8 749 gen_gvec_ool_zzzp(s, fns[esz], rd, rn, rm, pg, 0);
a2103582
RH
750}
751
f97cfd59 752#define DO_ZPZZ(NAME, name) \
3a7be554 753static bool trans_##NAME##_zpzz(DisasContext *s, arg_rprr_esz *a) \
f97cfd59
RH
754{ \
755 static gen_helper_gvec_4 * const fns[4] = { \
756 gen_helper_sve_##name##_zpzz_b, gen_helper_sve_##name##_zpzz_h, \
757 gen_helper_sve_##name##_zpzz_s, gen_helper_sve_##name##_zpzz_d, \
758 }; \
759 return do_zpzz_ool(s, a, fns[a->esz]); \
760}
761
762DO_ZPZZ(AND, and)
763DO_ZPZZ(EOR, eor)
764DO_ZPZZ(ORR, orr)
765DO_ZPZZ(BIC, bic)
766
767DO_ZPZZ(ADD, add)
768DO_ZPZZ(SUB, sub)
769
770DO_ZPZZ(SMAX, smax)
771DO_ZPZZ(UMAX, umax)
772DO_ZPZZ(SMIN, smin)
773DO_ZPZZ(UMIN, umin)
774DO_ZPZZ(SABD, sabd)
775DO_ZPZZ(UABD, uabd)
776
777DO_ZPZZ(MUL, mul)
778DO_ZPZZ(SMULH, smulh)
779DO_ZPZZ(UMULH, umulh)
780
27721dbb
RH
781DO_ZPZZ(ASR, asr)
782DO_ZPZZ(LSR, lsr)
783DO_ZPZZ(LSL, lsl)
784
3a7be554 785static bool trans_SDIV_zpzz(DisasContext *s, arg_rprr_esz *a)
f97cfd59
RH
786{
787 static gen_helper_gvec_4 * const fns[4] = {
788 NULL, NULL, gen_helper_sve_sdiv_zpzz_s, gen_helper_sve_sdiv_zpzz_d
789 };
790 return do_zpzz_ool(s, a, fns[a->esz]);
791}
792
3a7be554 793static bool trans_UDIV_zpzz(DisasContext *s, arg_rprr_esz *a)
f97cfd59
RH
794{
795 static gen_helper_gvec_4 * const fns[4] = {
796 NULL, NULL, gen_helper_sve_udiv_zpzz_s, gen_helper_sve_udiv_zpzz_d
797 };
798 return do_zpzz_ool(s, a, fns[a->esz]);
799}
800
3a7be554 801static bool trans_SEL_zpzz(DisasContext *s, arg_rprr_esz *a)
a2103582
RH
802{
803 if (sve_access_check(s)) {
804 do_sel_z(s, a->rd, a->rn, a->rm, a->pg, a->esz);
805 }
806 return true;
807}
d3fe4a29 808
f97cfd59
RH
809#undef DO_ZPZZ
810
afac6d04
RH
811/*
812 *** SVE Integer Arithmetic - Unary Predicated Group
813 */
814
817bd5c9
RH
815#define DO_ZPZ(NAME, FEAT, name) \
816 static gen_helper_gvec_3 * const name##_fns[4] = { \
817 gen_helper_##name##_b, gen_helper_##name##_h, \
818 gen_helper_##name##_s, gen_helper_##name##_d, \
afac6d04 819 }; \
817bd5c9
RH
820 TRANS_FEAT(NAME, FEAT, gen_gvec_ool_arg_zpz, name##_fns[a->esz], a, 0)
821
822DO_ZPZ(CLS, aa64_sve, sve_cls)
823DO_ZPZ(CLZ, aa64_sve, sve_clz)
824DO_ZPZ(CNT_zpz, aa64_sve, sve_cnt_zpz)
825DO_ZPZ(CNOT, aa64_sve, sve_cnot)
826DO_ZPZ(NOT_zpz, aa64_sve, sve_not_zpz)
827DO_ZPZ(ABS, aa64_sve, sve_abs)
828DO_ZPZ(NEG, aa64_sve, sve_neg)
829DO_ZPZ(RBIT, aa64_sve, sve_rbit)
830
831static gen_helper_gvec_3 * const fabs_fns[4] = {
832 NULL, gen_helper_sve_fabs_h,
833 gen_helper_sve_fabs_s, gen_helper_sve_fabs_d,
834};
835TRANS_FEAT(FABS, aa64_sve, gen_gvec_ool_arg_zpz, fabs_fns[a->esz], a, 0)
afac6d04 836
817bd5c9
RH
837static gen_helper_gvec_3 * const fneg_fns[4] = {
838 NULL, gen_helper_sve_fneg_h,
839 gen_helper_sve_fneg_s, gen_helper_sve_fneg_d,
840};
841TRANS_FEAT(FNEG, aa64_sve, gen_gvec_ool_arg_zpz, fneg_fns[a->esz], a, 0)
afac6d04 842
817bd5c9
RH
843static gen_helper_gvec_3 * const sxtb_fns[4] = {
844 NULL, gen_helper_sve_sxtb_h,
845 gen_helper_sve_sxtb_s, gen_helper_sve_sxtb_d,
846};
847TRANS_FEAT(SXTB, aa64_sve, gen_gvec_ool_arg_zpz, sxtb_fns[a->esz], a, 0)
afac6d04 848
817bd5c9
RH
849static gen_helper_gvec_3 * const uxtb_fns[4] = {
850 NULL, gen_helper_sve_uxtb_h,
851 gen_helper_sve_uxtb_s, gen_helper_sve_uxtb_d,
852};
853TRANS_FEAT(UXTB, aa64_sve, gen_gvec_ool_arg_zpz, uxtb_fns[a->esz], a, 0)
afac6d04 854
817bd5c9
RH
855static gen_helper_gvec_3 * const sxth_fns[4] = {
856 NULL, NULL, gen_helper_sve_sxth_s, gen_helper_sve_sxth_d
857};
858TRANS_FEAT(SXTH, aa64_sve, gen_gvec_ool_arg_zpz, sxth_fns[a->esz], a, 0)
afac6d04 859
817bd5c9
RH
860static gen_helper_gvec_3 * const uxth_fns[4] = {
861 NULL, NULL, gen_helper_sve_uxth_s, gen_helper_sve_uxth_d
862};
863TRANS_FEAT(UXTH, aa64_sve, gen_gvec_ool_arg_zpz, uxth_fns[a->esz], a, 0)
afac6d04 864
817bd5c9
RH
865TRANS_FEAT(SXTW, aa64_sve, gen_gvec_ool_arg_zpz,
866 a->esz == 3 ? gen_helper_sve_sxtw_d : NULL, a, 0)
867TRANS_FEAT(UXTW, aa64_sve, gen_gvec_ool_arg_zpz,
868 a->esz == 3 ? gen_helper_sve_uxtw_d : NULL, a, 0)
afac6d04 869
047cec97
RH
870/*
871 *** SVE Integer Reduction Group
872 */
873
874typedef void gen_helper_gvec_reduc(TCGv_i64, TCGv_ptr, TCGv_ptr, TCGv_i32);
875static bool do_vpz_ool(DisasContext *s, arg_rpr_esz *a,
876 gen_helper_gvec_reduc *fn)
877{
878 unsigned vsz = vec_full_reg_size(s);
879 TCGv_ptr t_zn, t_pg;
880 TCGv_i32 desc;
881 TCGv_i64 temp;
882
883 if (fn == NULL) {
884 return false;
885 }
886 if (!sve_access_check(s)) {
887 return true;
888 }
889
c6a59b55 890 desc = tcg_constant_i32(simd_desc(vsz, vsz, 0));
047cec97
RH
891 temp = tcg_temp_new_i64();
892 t_zn = tcg_temp_new_ptr();
893 t_pg = tcg_temp_new_ptr();
894
895 tcg_gen_addi_ptr(t_zn, cpu_env, vec_full_reg_offset(s, a->rn));
896 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, a->pg));
897 fn(temp, t_zn, t_pg, desc);
898 tcg_temp_free_ptr(t_zn);
899 tcg_temp_free_ptr(t_pg);
047cec97
RH
900
901 write_fp_dreg(s, a->rd, temp);
902 tcg_temp_free_i64(temp);
903 return true;
904}
905
906#define DO_VPZ(NAME, name) \
3a7be554 907static bool trans_##NAME(DisasContext *s, arg_rpr_esz *a) \
047cec97
RH
908{ \
909 static gen_helper_gvec_reduc * const fns[4] = { \
910 gen_helper_sve_##name##_b, gen_helper_sve_##name##_h, \
911 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d, \
912 }; \
913 return do_vpz_ool(s, a, fns[a->esz]); \
914}
915
916DO_VPZ(ORV, orv)
917DO_VPZ(ANDV, andv)
918DO_VPZ(EORV, eorv)
919
920DO_VPZ(UADDV, uaddv)
921DO_VPZ(SMAXV, smaxv)
922DO_VPZ(UMAXV, umaxv)
923DO_VPZ(SMINV, sminv)
924DO_VPZ(UMINV, uminv)
925
3a7be554 926static bool trans_SADDV(DisasContext *s, arg_rpr_esz *a)
047cec97
RH
927{
928 static gen_helper_gvec_reduc * const fns[4] = {
929 gen_helper_sve_saddv_b, gen_helper_sve_saddv_h,
930 gen_helper_sve_saddv_s, NULL
931 };
932 return do_vpz_ool(s, a, fns[a->esz]);
933}
934
935#undef DO_VPZ
936
ccd841c3
RH
937/*
938 *** SVE Shift by Immediate - Predicated Group
939 */
940
60245996
RH
941/*
942 * Copy Zn into Zd, storing zeros into inactive elements.
943 * If invert, store zeros into the active elements.
ccd841c3 944 */
60245996
RH
945static bool do_movz_zpz(DisasContext *s, int rd, int rn, int pg,
946 int esz, bool invert)
ccd841c3 947{
60245996
RH
948 static gen_helper_gvec_3 * const fns[4] = {
949 gen_helper_sve_movz_b, gen_helper_sve_movz_h,
950 gen_helper_sve_movz_s, gen_helper_sve_movz_d,
ccd841c3 951 };
8fb27a21 952 return gen_gvec_ool_zzp(s, fns[esz], rd, rn, pg, invert);
ccd841c3
RH
953}
954
955static bool do_zpzi_ool(DisasContext *s, arg_rpri_esz *a,
956 gen_helper_gvec_3 *fn)
957{
8fb27a21 958 return gen_gvec_ool_zzp(s, fn, a->rd, a->rn, a->pg, a->imm);
ccd841c3
RH
959}
960
3a7be554 961static bool trans_ASR_zpzi(DisasContext *s, arg_rpri_esz *a)
ccd841c3
RH
962{
963 static gen_helper_gvec_3 * const fns[4] = {
964 gen_helper_sve_asr_zpzi_b, gen_helper_sve_asr_zpzi_h,
965 gen_helper_sve_asr_zpzi_s, gen_helper_sve_asr_zpzi_d,
966 };
967 if (a->esz < 0) {
968 /* Invalid tsz encoding -- see tszimm_esz. */
969 return false;
970 }
971 /* Shift by element size is architecturally valid. For
972 arithmetic right-shift, it's the same as by one less. */
973 a->imm = MIN(a->imm, (8 << a->esz) - 1);
974 return do_zpzi_ool(s, a, fns[a->esz]);
975}
976
3a7be554 977static bool trans_LSR_zpzi(DisasContext *s, arg_rpri_esz *a)
ccd841c3
RH
978{
979 static gen_helper_gvec_3 * const fns[4] = {
980 gen_helper_sve_lsr_zpzi_b, gen_helper_sve_lsr_zpzi_h,
981 gen_helper_sve_lsr_zpzi_s, gen_helper_sve_lsr_zpzi_d,
982 };
983 if (a->esz < 0) {
984 return false;
985 }
986 /* Shift by element size is architecturally valid.
987 For logical shifts, it is a zeroing operation. */
988 if (a->imm >= (8 << a->esz)) {
60245996 989 return do_movz_zpz(s, a->rd, a->rd, a->pg, a->esz, true);
ccd841c3
RH
990 } else {
991 return do_zpzi_ool(s, a, fns[a->esz]);
992 }
993}
994
3a7be554 995static bool trans_LSL_zpzi(DisasContext *s, arg_rpri_esz *a)
ccd841c3
RH
996{
997 static gen_helper_gvec_3 * const fns[4] = {
998 gen_helper_sve_lsl_zpzi_b, gen_helper_sve_lsl_zpzi_h,
999 gen_helper_sve_lsl_zpzi_s, gen_helper_sve_lsl_zpzi_d,
1000 };
1001 if (a->esz < 0) {
1002 return false;
1003 }
1004 /* Shift by element size is architecturally valid.
1005 For logical shifts, it is a zeroing operation. */
1006 if (a->imm >= (8 << a->esz)) {
60245996 1007 return do_movz_zpz(s, a->rd, a->rd, a->pg, a->esz, true);
ccd841c3
RH
1008 } else {
1009 return do_zpzi_ool(s, a, fns[a->esz]);
1010 }
1011}
1012
3a7be554 1013static bool trans_ASRD(DisasContext *s, arg_rpri_esz *a)
ccd841c3
RH
1014{
1015 static gen_helper_gvec_3 * const fns[4] = {
1016 gen_helper_sve_asrd_b, gen_helper_sve_asrd_h,
1017 gen_helper_sve_asrd_s, gen_helper_sve_asrd_d,
1018 };
1019 if (a->esz < 0) {
1020 return false;
1021 }
1022 /* Shift by element size is architecturally valid. For arithmetic
1023 right shift for division, it is a zeroing operation. */
1024 if (a->imm >= (8 << a->esz)) {
60245996 1025 return do_movz_zpz(s, a->rd, a->rd, a->pg, a->esz, true);
ccd841c3
RH
1026 } else {
1027 return do_zpzi_ool(s, a, fns[a->esz]);
1028 }
1029}
1030
a5421b54
SL
1031static bool trans_SQSHL_zpzi(DisasContext *s, arg_rpri_esz *a)
1032{
1033 static gen_helper_gvec_3 * const fns[4] = {
1034 gen_helper_sve2_sqshl_zpzi_b, gen_helper_sve2_sqshl_zpzi_h,
1035 gen_helper_sve2_sqshl_zpzi_s, gen_helper_sve2_sqshl_zpzi_d,
1036 };
1037 if (a->esz < 0 || !dc_isar_feature(aa64_sve2, s)) {
1038 return false;
1039 }
1040 return do_zpzi_ool(s, a, fns[a->esz]);
1041}
1042
1043static bool trans_UQSHL_zpzi(DisasContext *s, arg_rpri_esz *a)
1044{
1045 static gen_helper_gvec_3 * const fns[4] = {
1046 gen_helper_sve2_uqshl_zpzi_b, gen_helper_sve2_uqshl_zpzi_h,
1047 gen_helper_sve2_uqshl_zpzi_s, gen_helper_sve2_uqshl_zpzi_d,
1048 };
1049 if (a->esz < 0 || !dc_isar_feature(aa64_sve2, s)) {
1050 return false;
1051 }
1052 return do_zpzi_ool(s, a, fns[a->esz]);
1053}
1054
1055static bool trans_SRSHR(DisasContext *s, arg_rpri_esz *a)
1056{
1057 static gen_helper_gvec_3 * const fns[4] = {
1058 gen_helper_sve2_srshr_b, gen_helper_sve2_srshr_h,
1059 gen_helper_sve2_srshr_s, gen_helper_sve2_srshr_d,
1060 };
1061 if (a->esz < 0 || !dc_isar_feature(aa64_sve2, s)) {
1062 return false;
1063 }
1064 return do_zpzi_ool(s, a, fns[a->esz]);
1065}
1066
1067static bool trans_URSHR(DisasContext *s, arg_rpri_esz *a)
1068{
1069 static gen_helper_gvec_3 * const fns[4] = {
1070 gen_helper_sve2_urshr_b, gen_helper_sve2_urshr_h,
1071 gen_helper_sve2_urshr_s, gen_helper_sve2_urshr_d,
1072 };
1073 if (a->esz < 0 || !dc_isar_feature(aa64_sve2, s)) {
1074 return false;
1075 }
1076 return do_zpzi_ool(s, a, fns[a->esz]);
1077}
1078
1079static bool trans_SQSHLU(DisasContext *s, arg_rpri_esz *a)
1080{
1081 static gen_helper_gvec_3 * const fns[4] = {
1082 gen_helper_sve2_sqshlu_b, gen_helper_sve2_sqshlu_h,
1083 gen_helper_sve2_sqshlu_s, gen_helper_sve2_sqshlu_d,
1084 };
1085 if (a->esz < 0 || !dc_isar_feature(aa64_sve2, s)) {
1086 return false;
1087 }
1088 return do_zpzi_ool(s, a, fns[a->esz]);
1089}
1090
fe7f8dfb
RH
1091/*
1092 *** SVE Bitwise Shift - Predicated Group
1093 */
1094
1095#define DO_ZPZW(NAME, name) \
3a7be554 1096static bool trans_##NAME##_zpzw(DisasContext *s, arg_rprr_esz *a) \
fe7f8dfb
RH
1097{ \
1098 static gen_helper_gvec_4 * const fns[3] = { \
1099 gen_helper_sve_##name##_zpzw_b, gen_helper_sve_##name##_zpzw_h, \
1100 gen_helper_sve_##name##_zpzw_s, \
1101 }; \
1102 if (a->esz < 0 || a->esz >= 3) { \
1103 return false; \
1104 } \
1105 return do_zpzz_ool(s, a, fns[a->esz]); \
1106}
1107
1108DO_ZPZW(ASR, asr)
1109DO_ZPZW(LSR, lsr)
1110DO_ZPZW(LSL, lsl)
1111
1112#undef DO_ZPZW
1113
d9d78dcc
RH
1114/*
1115 *** SVE Bitwise Shift - Unpredicated Group
1116 */
1117
1118static bool do_shift_imm(DisasContext *s, arg_rri_esz *a, bool asr,
1119 void (*gvec_fn)(unsigned, uint32_t, uint32_t,
1120 int64_t, uint32_t, uint32_t))
1121{
1122 if (a->esz < 0) {
1123 /* Invalid tsz encoding -- see tszimm_esz. */
1124 return false;
1125 }
1126 if (sve_access_check(s)) {
1127 unsigned vsz = vec_full_reg_size(s);
1128 /* Shift by element size is architecturally valid. For
1129 arithmetic right-shift, it's the same as by one less.
1130 Otherwise it is a zeroing operation. */
1131 if (a->imm >= 8 << a->esz) {
1132 if (asr) {
1133 a->imm = (8 << a->esz) - 1;
1134 } else {
1135 do_dupi_z(s, a->rd, 0);
1136 return true;
1137 }
1138 }
1139 gvec_fn(a->esz, vec_full_reg_offset(s, a->rd),
1140 vec_full_reg_offset(s, a->rn), a->imm, vsz, vsz);
1141 }
1142 return true;
1143}
1144
3a7be554 1145static bool trans_ASR_zzi(DisasContext *s, arg_rri_esz *a)
d9d78dcc
RH
1146{
1147 return do_shift_imm(s, a, true, tcg_gen_gvec_sari);
1148}
1149
3a7be554 1150static bool trans_LSR_zzi(DisasContext *s, arg_rri_esz *a)
d9d78dcc
RH
1151{
1152 return do_shift_imm(s, a, false, tcg_gen_gvec_shri);
1153}
1154
3a7be554 1155static bool trans_LSL_zzi(DisasContext *s, arg_rri_esz *a)
d9d78dcc
RH
1156{
1157 return do_shift_imm(s, a, false, tcg_gen_gvec_shli);
1158}
1159
d9d78dcc 1160#define DO_ZZW(NAME, name) \
32e2ad65 1161 static gen_helper_gvec_3 * const name##_zzw_fns[4] = { \
d9d78dcc
RH
1162 gen_helper_sve_##name##_zzw_b, gen_helper_sve_##name##_zzw_h, \
1163 gen_helper_sve_##name##_zzw_s, NULL \
1164 }; \
32e2ad65
RH
1165 TRANS_FEAT(NAME, aa64_sve, gen_gvec_ool_arg_zzz, \
1166 name##_zzw_fns[a->esz], a, 0)
d9d78dcc 1167
32e2ad65
RH
1168DO_ZZW(ASR_zzw, asr)
1169DO_ZZW(LSR_zzw, lsr)
1170DO_ZZW(LSL_zzw, lsl)
d9d78dcc
RH
1171
1172#undef DO_ZZW
1173
96a36e4a
RH
1174/*
1175 *** SVE Integer Multiply-Add Group
1176 */
1177
1178static bool do_zpzzz_ool(DisasContext *s, arg_rprrr_esz *a,
1179 gen_helper_gvec_5 *fn)
1180{
1181 if (sve_access_check(s)) {
1182 unsigned vsz = vec_full_reg_size(s);
1183 tcg_gen_gvec_5_ool(vec_full_reg_offset(s, a->rd),
1184 vec_full_reg_offset(s, a->ra),
1185 vec_full_reg_offset(s, a->rn),
1186 vec_full_reg_offset(s, a->rm),
1187 pred_full_reg_offset(s, a->pg),
1188 vsz, vsz, 0, fn);
1189 }
1190 return true;
1191}
1192
1193#define DO_ZPZZZ(NAME, name) \
3a7be554 1194static bool trans_##NAME(DisasContext *s, arg_rprrr_esz *a) \
96a36e4a
RH
1195{ \
1196 static gen_helper_gvec_5 * const fns[4] = { \
1197 gen_helper_sve_##name##_b, gen_helper_sve_##name##_h, \
1198 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d, \
1199 }; \
1200 return do_zpzzz_ool(s, a, fns[a->esz]); \
1201}
1202
1203DO_ZPZZZ(MLA, mla)
1204DO_ZPZZZ(MLS, mls)
1205
1206#undef DO_ZPZZZ
1207
9a56c9c3
RH
1208/*
1209 *** SVE Index Generation Group
1210 */
1211
1212static void do_index(DisasContext *s, int esz, int rd,
1213 TCGv_i64 start, TCGv_i64 incr)
1214{
1215 unsigned vsz = vec_full_reg_size(s);
c6a59b55 1216 TCGv_i32 desc = tcg_constant_i32(simd_desc(vsz, vsz, 0));
9a56c9c3
RH
1217 TCGv_ptr t_zd = tcg_temp_new_ptr();
1218
1219 tcg_gen_addi_ptr(t_zd, cpu_env, vec_full_reg_offset(s, rd));
1220 if (esz == 3) {
1221 gen_helper_sve_index_d(t_zd, start, incr, desc);
1222 } else {
1223 typedef void index_fn(TCGv_ptr, TCGv_i32, TCGv_i32, TCGv_i32);
1224 static index_fn * const fns[3] = {
1225 gen_helper_sve_index_b,
1226 gen_helper_sve_index_h,
1227 gen_helper_sve_index_s,
1228 };
1229 TCGv_i32 s32 = tcg_temp_new_i32();
1230 TCGv_i32 i32 = tcg_temp_new_i32();
1231
1232 tcg_gen_extrl_i64_i32(s32, start);
1233 tcg_gen_extrl_i64_i32(i32, incr);
1234 fns[esz](t_zd, s32, i32, desc);
1235
1236 tcg_temp_free_i32(s32);
1237 tcg_temp_free_i32(i32);
1238 }
1239 tcg_temp_free_ptr(t_zd);
9a56c9c3
RH
1240}
1241
3a7be554 1242static bool trans_INDEX_ii(DisasContext *s, arg_INDEX_ii *a)
9a56c9c3
RH
1243{
1244 if (sve_access_check(s)) {
b0c3aece
RH
1245 TCGv_i64 start = tcg_constant_i64(a->imm1);
1246 TCGv_i64 incr = tcg_constant_i64(a->imm2);
9a56c9c3 1247 do_index(s, a->esz, a->rd, start, incr);
9a56c9c3
RH
1248 }
1249 return true;
1250}
1251
3a7be554 1252static bool trans_INDEX_ir(DisasContext *s, arg_INDEX_ir *a)
9a56c9c3
RH
1253{
1254 if (sve_access_check(s)) {
b0c3aece 1255 TCGv_i64 start = tcg_constant_i64(a->imm);
9a56c9c3
RH
1256 TCGv_i64 incr = cpu_reg(s, a->rm);
1257 do_index(s, a->esz, a->rd, start, incr);
9a56c9c3
RH
1258 }
1259 return true;
1260}
1261
3a7be554 1262static bool trans_INDEX_ri(DisasContext *s, arg_INDEX_ri *a)
9a56c9c3
RH
1263{
1264 if (sve_access_check(s)) {
1265 TCGv_i64 start = cpu_reg(s, a->rn);
b0c3aece 1266 TCGv_i64 incr = tcg_constant_i64(a->imm);
9a56c9c3 1267 do_index(s, a->esz, a->rd, start, incr);
9a56c9c3
RH
1268 }
1269 return true;
1270}
1271
3a7be554 1272static bool trans_INDEX_rr(DisasContext *s, arg_INDEX_rr *a)
9a56c9c3
RH
1273{
1274 if (sve_access_check(s)) {
1275 TCGv_i64 start = cpu_reg(s, a->rn);
1276 TCGv_i64 incr = cpu_reg(s, a->rm);
1277 do_index(s, a->esz, a->rd, start, incr);
1278 }
1279 return true;
1280}
1281
96f922cc
RH
1282/*
1283 *** SVE Stack Allocation Group
1284 */
1285
3a7be554 1286static bool trans_ADDVL(DisasContext *s, arg_ADDVL *a)
96f922cc 1287{
5de56742
AC
1288 if (sve_access_check(s)) {
1289 TCGv_i64 rd = cpu_reg_sp(s, a->rd);
1290 TCGv_i64 rn = cpu_reg_sp(s, a->rn);
1291 tcg_gen_addi_i64(rd, rn, a->imm * vec_full_reg_size(s));
1292 }
96f922cc
RH
1293 return true;
1294}
1295
3a7be554 1296static bool trans_ADDPL(DisasContext *s, arg_ADDPL *a)
96f922cc 1297{
5de56742
AC
1298 if (sve_access_check(s)) {
1299 TCGv_i64 rd = cpu_reg_sp(s, a->rd);
1300 TCGv_i64 rn = cpu_reg_sp(s, a->rn);
1301 tcg_gen_addi_i64(rd, rn, a->imm * pred_full_reg_size(s));
1302 }
96f922cc
RH
1303 return true;
1304}
1305
3a7be554 1306static bool trans_RDVL(DisasContext *s, arg_RDVL *a)
96f922cc 1307{
5de56742
AC
1308 if (sve_access_check(s)) {
1309 TCGv_i64 reg = cpu_reg(s, a->rd);
1310 tcg_gen_movi_i64(reg, a->imm * vec_full_reg_size(s));
1311 }
96f922cc
RH
1312 return true;
1313}
1314
4b242d9c
RH
1315/*
1316 *** SVE Compute Vector Address Group
1317 */
1318
1319static bool do_adr(DisasContext *s, arg_rrri *a, gen_helper_gvec_3 *fn)
1320{
913a8a00 1321 return gen_gvec_ool_zzz(s, fn, a->rd, a->rn, a->rm, a->imm);
4b242d9c
RH
1322}
1323
3a7be554 1324static bool trans_ADR_p32(DisasContext *s, arg_rrri *a)
4b242d9c
RH
1325{
1326 return do_adr(s, a, gen_helper_sve_adr_p32);
1327}
1328
3a7be554 1329static bool trans_ADR_p64(DisasContext *s, arg_rrri *a)
4b242d9c
RH
1330{
1331 return do_adr(s, a, gen_helper_sve_adr_p64);
1332}
1333
3a7be554 1334static bool trans_ADR_s32(DisasContext *s, arg_rrri *a)
4b242d9c
RH
1335{
1336 return do_adr(s, a, gen_helper_sve_adr_s32);
1337}
1338
3a7be554 1339static bool trans_ADR_u32(DisasContext *s, arg_rrri *a)
4b242d9c
RH
1340{
1341 return do_adr(s, a, gen_helper_sve_adr_u32);
1342}
1343
0762cd42
RH
1344/*
1345 *** SVE Integer Misc - Unpredicated Group
1346 */
1347
0ea3cdbf
RH
1348static gen_helper_gvec_2 * const fexpa_fns[4] = {
1349 NULL, gen_helper_sve_fexpa_h,
1350 gen_helper_sve_fexpa_s, gen_helper_sve_fexpa_d,
1351};
1352TRANS_FEAT(FEXPA, aa64_sve, gen_gvec_ool_zz,
1353 fexpa_fns[a->esz], a->rd, a->rn, 0)
0762cd42 1354
32e2ad65
RH
1355static gen_helper_gvec_3 * const ftssel_fns[4] = {
1356 NULL, gen_helper_sve_ftssel_h,
1357 gen_helper_sve_ftssel_s, gen_helper_sve_ftssel_d,
1358};
1359TRANS_FEAT(FTSSEL, aa64_sve, gen_gvec_ool_arg_zzz, ftssel_fns[a->esz], a, 0)
a1f233f2 1360
516e246a
RH
1361/*
1362 *** SVE Predicate Logical Operations Group
1363 */
1364
1365static bool do_pppp_flags(DisasContext *s, arg_rprr_s *a,
1366 const GVecGen4 *gvec_op)
1367{
1368 if (!sve_access_check(s)) {
1369 return true;
1370 }
1371
1372 unsigned psz = pred_gvec_reg_size(s);
1373 int dofs = pred_full_reg_offset(s, a->rd);
1374 int nofs = pred_full_reg_offset(s, a->rn);
1375 int mofs = pred_full_reg_offset(s, a->rm);
1376 int gofs = pred_full_reg_offset(s, a->pg);
1377
dd81a8d7
RH
1378 if (!a->s) {
1379 tcg_gen_gvec_4(dofs, nofs, mofs, gofs, psz, psz, gvec_op);
1380 return true;
1381 }
1382
516e246a
RH
1383 if (psz == 8) {
1384 /* Do the operation and the flags generation in temps. */
1385 TCGv_i64 pd = tcg_temp_new_i64();
1386 TCGv_i64 pn = tcg_temp_new_i64();
1387 TCGv_i64 pm = tcg_temp_new_i64();
1388 TCGv_i64 pg = tcg_temp_new_i64();
1389
1390 tcg_gen_ld_i64(pn, cpu_env, nofs);
1391 tcg_gen_ld_i64(pm, cpu_env, mofs);
1392 tcg_gen_ld_i64(pg, cpu_env, gofs);
1393
1394 gvec_op->fni8(pd, pn, pm, pg);
1395 tcg_gen_st_i64(pd, cpu_env, dofs);
1396
1397 do_predtest1(pd, pg);
1398
1399 tcg_temp_free_i64(pd);
1400 tcg_temp_free_i64(pn);
1401 tcg_temp_free_i64(pm);
1402 tcg_temp_free_i64(pg);
1403 } else {
1404 /* The operation and flags generation is large. The computation
1405 * of the flags depends on the original contents of the guarding
1406 * predicate. If the destination overwrites the guarding predicate,
1407 * then the easiest way to get this right is to save a copy.
1408 */
1409 int tofs = gofs;
1410 if (a->rd == a->pg) {
1411 tofs = offsetof(CPUARMState, vfp.preg_tmp);
1412 tcg_gen_gvec_mov(0, tofs, gofs, psz, psz);
1413 }
1414
1415 tcg_gen_gvec_4(dofs, nofs, mofs, gofs, psz, psz, gvec_op);
1416 do_predtest(s, dofs, tofs, psz / 8);
1417 }
1418 return true;
1419}
1420
1421static void gen_and_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
1422{
1423 tcg_gen_and_i64(pd, pn, pm);
1424 tcg_gen_and_i64(pd, pd, pg);
1425}
1426
1427static void gen_and_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
1428 TCGv_vec pm, TCGv_vec pg)
1429{
1430 tcg_gen_and_vec(vece, pd, pn, pm);
1431 tcg_gen_and_vec(vece, pd, pd, pg);
1432}
1433
3a7be554 1434static bool trans_AND_pppp(DisasContext *s, arg_rprr_s *a)
516e246a
RH
1435{
1436 static const GVecGen4 op = {
1437 .fni8 = gen_and_pg_i64,
1438 .fniv = gen_and_pg_vec,
1439 .fno = gen_helper_sve_and_pppp,
1440 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1441 };
dd81a8d7
RH
1442
1443 if (!a->s) {
1444 if (!sve_access_check(s)) {
1445 return true;
1446 }
1447 if (a->rn == a->rm) {
1448 if (a->pg == a->rn) {
1449 do_mov_p(s, a->rd, a->rn);
1450 } else {
1451 gen_gvec_fn_ppp(s, tcg_gen_gvec_and, a->rd, a->rn, a->pg);
1452 }
1453 return true;
1454 } else if (a->pg == a->rn || a->pg == a->rm) {
1455 gen_gvec_fn_ppp(s, tcg_gen_gvec_and, a->rd, a->rn, a->rm);
1456 return true;
516e246a 1457 }
516e246a 1458 }
dd81a8d7 1459 return do_pppp_flags(s, a, &op);
516e246a
RH
1460}
1461
1462static void gen_bic_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
1463{
1464 tcg_gen_andc_i64(pd, pn, pm);
1465 tcg_gen_and_i64(pd, pd, pg);
1466}
1467
1468static void gen_bic_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
1469 TCGv_vec pm, TCGv_vec pg)
1470{
1471 tcg_gen_andc_vec(vece, pd, pn, pm);
1472 tcg_gen_and_vec(vece, pd, pd, pg);
1473}
1474
3a7be554 1475static bool trans_BIC_pppp(DisasContext *s, arg_rprr_s *a)
516e246a
RH
1476{
1477 static const GVecGen4 op = {
1478 .fni8 = gen_bic_pg_i64,
1479 .fniv = gen_bic_pg_vec,
1480 .fno = gen_helper_sve_bic_pppp,
1481 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1482 };
dd81a8d7
RH
1483
1484 if (!a->s && a->pg == a->rn) {
1485 if (sve_access_check(s)) {
1486 gen_gvec_fn_ppp(s, tcg_gen_gvec_andc, a->rd, a->rn, a->rm);
1487 }
1488 return true;
516e246a 1489 }
dd81a8d7 1490 return do_pppp_flags(s, a, &op);
516e246a
RH
1491}
1492
1493static void gen_eor_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
1494{
1495 tcg_gen_xor_i64(pd, pn, pm);
1496 tcg_gen_and_i64(pd, pd, pg);
1497}
1498
1499static void gen_eor_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
1500 TCGv_vec pm, TCGv_vec pg)
1501{
1502 tcg_gen_xor_vec(vece, pd, pn, pm);
1503 tcg_gen_and_vec(vece, pd, pd, pg);
1504}
1505
3a7be554 1506static bool trans_EOR_pppp(DisasContext *s, arg_rprr_s *a)
516e246a
RH
1507{
1508 static const GVecGen4 op = {
1509 .fni8 = gen_eor_pg_i64,
1510 .fniv = gen_eor_pg_vec,
1511 .fno = gen_helper_sve_eor_pppp,
1512 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1513 };
dd81a8d7 1514 return do_pppp_flags(s, a, &op);
516e246a
RH
1515}
1516
3a7be554 1517static bool trans_SEL_pppp(DisasContext *s, arg_rprr_s *a)
516e246a 1518{
516e246a
RH
1519 if (a->s) {
1520 return false;
516e246a 1521 }
d4bc6232
RH
1522 if (sve_access_check(s)) {
1523 unsigned psz = pred_gvec_reg_size(s);
1524 tcg_gen_gvec_bitsel(MO_8, pred_full_reg_offset(s, a->rd),
1525 pred_full_reg_offset(s, a->pg),
1526 pred_full_reg_offset(s, a->rn),
1527 pred_full_reg_offset(s, a->rm), psz, psz);
1528 }
1529 return true;
516e246a
RH
1530}
1531
1532static void gen_orr_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
1533{
1534 tcg_gen_or_i64(pd, pn, pm);
1535 tcg_gen_and_i64(pd, pd, pg);
1536}
1537
1538static void gen_orr_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
1539 TCGv_vec pm, TCGv_vec pg)
1540{
1541 tcg_gen_or_vec(vece, pd, pn, pm);
1542 tcg_gen_and_vec(vece, pd, pd, pg);
1543}
1544
3a7be554 1545static bool trans_ORR_pppp(DisasContext *s, arg_rprr_s *a)
516e246a
RH
1546{
1547 static const GVecGen4 op = {
1548 .fni8 = gen_orr_pg_i64,
1549 .fniv = gen_orr_pg_vec,
1550 .fno = gen_helper_sve_orr_pppp,
1551 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1552 };
dd81a8d7
RH
1553
1554 if (!a->s && a->pg == a->rn && a->rn == a->rm) {
516e246a 1555 return do_mov_p(s, a->rd, a->rn);
516e246a 1556 }
dd81a8d7 1557 return do_pppp_flags(s, a, &op);
516e246a
RH
1558}
1559
1560static void gen_orn_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
1561{
1562 tcg_gen_orc_i64(pd, pn, pm);
1563 tcg_gen_and_i64(pd, pd, pg);
1564}
1565
1566static void gen_orn_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
1567 TCGv_vec pm, TCGv_vec pg)
1568{
1569 tcg_gen_orc_vec(vece, pd, pn, pm);
1570 tcg_gen_and_vec(vece, pd, pd, pg);
1571}
1572
3a7be554 1573static bool trans_ORN_pppp(DisasContext *s, arg_rprr_s *a)
516e246a
RH
1574{
1575 static const GVecGen4 op = {
1576 .fni8 = gen_orn_pg_i64,
1577 .fniv = gen_orn_pg_vec,
1578 .fno = gen_helper_sve_orn_pppp,
1579 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1580 };
dd81a8d7 1581 return do_pppp_flags(s, a, &op);
516e246a
RH
1582}
1583
1584static void gen_nor_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
1585{
1586 tcg_gen_or_i64(pd, pn, pm);
1587 tcg_gen_andc_i64(pd, pg, pd);
1588}
1589
1590static void gen_nor_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
1591 TCGv_vec pm, TCGv_vec pg)
1592{
1593 tcg_gen_or_vec(vece, pd, pn, pm);
1594 tcg_gen_andc_vec(vece, pd, pg, pd);
1595}
1596
3a7be554 1597static bool trans_NOR_pppp(DisasContext *s, arg_rprr_s *a)
516e246a
RH
1598{
1599 static const GVecGen4 op = {
1600 .fni8 = gen_nor_pg_i64,
1601 .fniv = gen_nor_pg_vec,
1602 .fno = gen_helper_sve_nor_pppp,
1603 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1604 };
dd81a8d7 1605 return do_pppp_flags(s, a, &op);
516e246a
RH
1606}
1607
1608static void gen_nand_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
1609{
1610 tcg_gen_and_i64(pd, pn, pm);
1611 tcg_gen_andc_i64(pd, pg, pd);
1612}
1613
1614static void gen_nand_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
1615 TCGv_vec pm, TCGv_vec pg)
1616{
1617 tcg_gen_and_vec(vece, pd, pn, pm);
1618 tcg_gen_andc_vec(vece, pd, pg, pd);
1619}
1620
3a7be554 1621static bool trans_NAND_pppp(DisasContext *s, arg_rprr_s *a)
516e246a
RH
1622{
1623 static const GVecGen4 op = {
1624 .fni8 = gen_nand_pg_i64,
1625 .fniv = gen_nand_pg_vec,
1626 .fno = gen_helper_sve_nand_pppp,
1627 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1628 };
dd81a8d7 1629 return do_pppp_flags(s, a, &op);
516e246a
RH
1630}
1631
9e18d7a6
RH
1632/*
1633 *** SVE Predicate Misc Group
1634 */
1635
3a7be554 1636static bool trans_PTEST(DisasContext *s, arg_PTEST *a)
9e18d7a6
RH
1637{
1638 if (sve_access_check(s)) {
1639 int nofs = pred_full_reg_offset(s, a->rn);
1640 int gofs = pred_full_reg_offset(s, a->pg);
1641 int words = DIV_ROUND_UP(pred_full_reg_size(s), 8);
1642
1643 if (words == 1) {
1644 TCGv_i64 pn = tcg_temp_new_i64();
1645 TCGv_i64 pg = tcg_temp_new_i64();
1646
1647 tcg_gen_ld_i64(pn, cpu_env, nofs);
1648 tcg_gen_ld_i64(pg, cpu_env, gofs);
1649 do_predtest1(pn, pg);
1650
1651 tcg_temp_free_i64(pn);
1652 tcg_temp_free_i64(pg);
1653 } else {
1654 do_predtest(s, nofs, gofs, words);
1655 }
1656 }
1657 return true;
1658}
1659
028e2a7b
RH
1660/* See the ARM pseudocode DecodePredCount. */
1661static unsigned decode_pred_count(unsigned fullsz, int pattern, int esz)
1662{
1663 unsigned elements = fullsz >> esz;
1664 unsigned bound;
1665
1666 switch (pattern) {
1667 case 0x0: /* POW2 */
1668 return pow2floor(elements);
1669 case 0x1: /* VL1 */
1670 case 0x2: /* VL2 */
1671 case 0x3: /* VL3 */
1672 case 0x4: /* VL4 */
1673 case 0x5: /* VL5 */
1674 case 0x6: /* VL6 */
1675 case 0x7: /* VL7 */
1676 case 0x8: /* VL8 */
1677 bound = pattern;
1678 break;
1679 case 0x9: /* VL16 */
1680 case 0xa: /* VL32 */
1681 case 0xb: /* VL64 */
1682 case 0xc: /* VL128 */
1683 case 0xd: /* VL256 */
1684 bound = 16 << (pattern - 9);
1685 break;
1686 case 0x1d: /* MUL4 */
1687 return elements - elements % 4;
1688 case 0x1e: /* MUL3 */
1689 return elements - elements % 3;
1690 case 0x1f: /* ALL */
1691 return elements;
1692 default: /* #uimm5 */
1693 return 0;
1694 }
1695 return elements >= bound ? bound : 0;
1696}
1697
1698/* This handles all of the predicate initialization instructions,
1699 * PTRUE, PFALSE, SETFFR. For PFALSE, we will have set PAT == 32
1700 * so that decode_pred_count returns 0. For SETFFR, we will have
1701 * set RD == 16 == FFR.
1702 */
1703static bool do_predset(DisasContext *s, int esz, int rd, int pat, bool setflag)
1704{
1705 if (!sve_access_check(s)) {
1706 return true;
1707 }
1708
1709 unsigned fullsz = vec_full_reg_size(s);
1710 unsigned ofs = pred_full_reg_offset(s, rd);
1711 unsigned numelem, setsz, i;
1712 uint64_t word, lastword;
1713 TCGv_i64 t;
1714
1715 numelem = decode_pred_count(fullsz, pat, esz);
1716
1717 /* Determine what we must store into each bit, and how many. */
1718 if (numelem == 0) {
1719 lastword = word = 0;
1720 setsz = fullsz;
1721 } else {
1722 setsz = numelem << esz;
1723 lastword = word = pred_esz_masks[esz];
1724 if (setsz % 64) {
973558a3 1725 lastword &= MAKE_64BIT_MASK(0, setsz % 64);
028e2a7b
RH
1726 }
1727 }
1728
1729 t = tcg_temp_new_i64();
1730 if (fullsz <= 64) {
1731 tcg_gen_movi_i64(t, lastword);
1732 tcg_gen_st_i64(t, cpu_env, ofs);
1733 goto done;
1734 }
1735
1736 if (word == lastword) {
1737 unsigned maxsz = size_for_gvec(fullsz / 8);
1738 unsigned oprsz = size_for_gvec(setsz / 8);
1739
1740 if (oprsz * 8 == setsz) {
8711e71f 1741 tcg_gen_gvec_dup_imm(MO_64, ofs, oprsz, maxsz, word);
028e2a7b
RH
1742 goto done;
1743 }
028e2a7b
RH
1744 }
1745
1746 setsz /= 8;
1747 fullsz /= 8;
1748
1749 tcg_gen_movi_i64(t, word);
973558a3 1750 for (i = 0; i < QEMU_ALIGN_DOWN(setsz, 8); i += 8) {
028e2a7b
RH
1751 tcg_gen_st_i64(t, cpu_env, ofs + i);
1752 }
1753 if (lastword != word) {
1754 tcg_gen_movi_i64(t, lastword);
1755 tcg_gen_st_i64(t, cpu_env, ofs + i);
1756 i += 8;
1757 }
1758 if (i < fullsz) {
1759 tcg_gen_movi_i64(t, 0);
1760 for (; i < fullsz; i += 8) {
1761 tcg_gen_st_i64(t, cpu_env, ofs + i);
1762 }
1763 }
1764
1765 done:
1766 tcg_temp_free_i64(t);
1767
1768 /* PTRUES */
1769 if (setflag) {
1770 tcg_gen_movi_i32(cpu_NF, -(word != 0));
1771 tcg_gen_movi_i32(cpu_CF, word == 0);
1772 tcg_gen_movi_i32(cpu_VF, 0);
1773 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
1774 }
1775 return true;
1776}
1777
3a7be554 1778static bool trans_PTRUE(DisasContext *s, arg_PTRUE *a)
028e2a7b
RH
1779{
1780 return do_predset(s, a->esz, a->rd, a->pat, a->s);
1781}
1782
3a7be554 1783static bool trans_SETFFR(DisasContext *s, arg_SETFFR *a)
028e2a7b
RH
1784{
1785 /* Note pat == 31 is #all, to set all elements. */
1786 return do_predset(s, 0, FFR_PRED_NUM, 31, false);
1787}
1788
3a7be554 1789static bool trans_PFALSE(DisasContext *s, arg_PFALSE *a)
028e2a7b
RH
1790{
1791 /* Note pat == 32 is #unimp, to set no elements. */
1792 return do_predset(s, 0, a->rd, 32, false);
1793}
1794
3a7be554 1795static bool trans_RDFFR_p(DisasContext *s, arg_RDFFR_p *a)
028e2a7b
RH
1796{
1797 /* The path through do_pppp_flags is complicated enough to want to avoid
1798 * duplication. Frob the arguments into the form of a predicated AND.
1799 */
1800 arg_rprr_s alt_a = {
1801 .rd = a->rd, .pg = a->pg, .s = a->s,
1802 .rn = FFR_PRED_NUM, .rm = FFR_PRED_NUM,
1803 };
3a7be554 1804 return trans_AND_pppp(s, &alt_a);
028e2a7b
RH
1805}
1806
3a7be554 1807static bool trans_RDFFR(DisasContext *s, arg_RDFFR *a)
028e2a7b
RH
1808{
1809 return do_mov_p(s, a->rd, FFR_PRED_NUM);
1810}
1811
3a7be554 1812static bool trans_WRFFR(DisasContext *s, arg_WRFFR *a)
028e2a7b
RH
1813{
1814 return do_mov_p(s, FFR_PRED_NUM, a->rn);
1815}
1816
1817static bool do_pfirst_pnext(DisasContext *s, arg_rr_esz *a,
1818 void (*gen_fn)(TCGv_i32, TCGv_ptr,
1819 TCGv_ptr, TCGv_i32))
1820{
1821 if (!sve_access_check(s)) {
1822 return true;
1823 }
1824
1825 TCGv_ptr t_pd = tcg_temp_new_ptr();
1826 TCGv_ptr t_pg = tcg_temp_new_ptr();
1827 TCGv_i32 t;
86300b5d 1828 unsigned desc = 0;
028e2a7b 1829
86300b5d
RH
1830 desc = FIELD_DP32(desc, PREDDESC, OPRSZ, pred_full_reg_size(s));
1831 desc = FIELD_DP32(desc, PREDDESC, ESZ, a->esz);
028e2a7b
RH
1832
1833 tcg_gen_addi_ptr(t_pd, cpu_env, pred_full_reg_offset(s, a->rd));
1834 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, a->rn));
392acacc 1835 t = tcg_temp_new_i32();
028e2a7b 1836
392acacc 1837 gen_fn(t, t_pd, t_pg, tcg_constant_i32(desc));
028e2a7b
RH
1838 tcg_temp_free_ptr(t_pd);
1839 tcg_temp_free_ptr(t_pg);
1840
1841 do_pred_flags(t);
1842 tcg_temp_free_i32(t);
1843 return true;
1844}
1845
3a7be554 1846static bool trans_PFIRST(DisasContext *s, arg_rr_esz *a)
028e2a7b
RH
1847{
1848 return do_pfirst_pnext(s, a, gen_helper_sve_pfirst);
1849}
1850
3a7be554 1851static bool trans_PNEXT(DisasContext *s, arg_rr_esz *a)
028e2a7b
RH
1852{
1853 return do_pfirst_pnext(s, a, gen_helper_sve_pnext);
1854}
1855
24e82e68
RH
1856/*
1857 *** SVE Element Count Group
1858 */
1859
1860/* Perform an inline saturating addition of a 32-bit value within
1861 * a 64-bit register. The second operand is known to be positive,
1862 * which halves the comparisions we must perform to bound the result.
1863 */
1864static void do_sat_addsub_32(TCGv_i64 reg, TCGv_i64 val, bool u, bool d)
1865{
1866 int64_t ibound;
24e82e68
RH
1867
1868 /* Use normal 64-bit arithmetic to detect 32-bit overflow. */
1869 if (u) {
1870 tcg_gen_ext32u_i64(reg, reg);
1871 } else {
1872 tcg_gen_ext32s_i64(reg, reg);
1873 }
1874 if (d) {
1875 tcg_gen_sub_i64(reg, reg, val);
1876 ibound = (u ? 0 : INT32_MIN);
aa5b0b29 1877 tcg_gen_smax_i64(reg, reg, tcg_constant_i64(ibound));
24e82e68
RH
1878 } else {
1879 tcg_gen_add_i64(reg, reg, val);
1880 ibound = (u ? UINT32_MAX : INT32_MAX);
aa5b0b29 1881 tcg_gen_smin_i64(reg, reg, tcg_constant_i64(ibound));
24e82e68 1882 }
24e82e68
RH
1883}
1884
1885/* Similarly with 64-bit values. */
1886static void do_sat_addsub_64(TCGv_i64 reg, TCGv_i64 val, bool u, bool d)
1887{
1888 TCGv_i64 t0 = tcg_temp_new_i64();
24e82e68
RH
1889 TCGv_i64 t2;
1890
1891 if (u) {
1892 if (d) {
1893 tcg_gen_sub_i64(t0, reg, val);
35a1ec8e
PMD
1894 t2 = tcg_constant_i64(0);
1895 tcg_gen_movcond_i64(TCG_COND_LTU, reg, reg, val, t2, t0);
24e82e68
RH
1896 } else {
1897 tcg_gen_add_i64(t0, reg, val);
35a1ec8e
PMD
1898 t2 = tcg_constant_i64(-1);
1899 tcg_gen_movcond_i64(TCG_COND_LTU, reg, t0, reg, t2, t0);
24e82e68
RH
1900 }
1901 } else {
35a1ec8e 1902 TCGv_i64 t1 = tcg_temp_new_i64();
24e82e68
RH
1903 if (d) {
1904 /* Detect signed overflow for subtraction. */
1905 tcg_gen_xor_i64(t0, reg, val);
1906 tcg_gen_sub_i64(t1, reg, val);
7a31e0c6 1907 tcg_gen_xor_i64(reg, reg, t1);
24e82e68
RH
1908 tcg_gen_and_i64(t0, t0, reg);
1909
1910 /* Bound the result. */
1911 tcg_gen_movi_i64(reg, INT64_MIN);
35a1ec8e 1912 t2 = tcg_constant_i64(0);
24e82e68
RH
1913 tcg_gen_movcond_i64(TCG_COND_LT, reg, t0, t2, reg, t1);
1914 } else {
1915 /* Detect signed overflow for addition. */
1916 tcg_gen_xor_i64(t0, reg, val);
1917 tcg_gen_add_i64(reg, reg, val);
1918 tcg_gen_xor_i64(t1, reg, val);
1919 tcg_gen_andc_i64(t0, t1, t0);
1920
1921 /* Bound the result. */
1922 tcg_gen_movi_i64(t1, INT64_MAX);
35a1ec8e 1923 t2 = tcg_constant_i64(0);
24e82e68
RH
1924 tcg_gen_movcond_i64(TCG_COND_LT, reg, t0, t2, t1, reg);
1925 }
35a1ec8e 1926 tcg_temp_free_i64(t1);
24e82e68
RH
1927 }
1928 tcg_temp_free_i64(t0);
24e82e68
RH
1929}
1930
1931/* Similarly with a vector and a scalar operand. */
1932static void do_sat_addsub_vec(DisasContext *s, int esz, int rd, int rn,
1933 TCGv_i64 val, bool u, bool d)
1934{
1935 unsigned vsz = vec_full_reg_size(s);
1936 TCGv_ptr dptr, nptr;
1937 TCGv_i32 t32, desc;
1938 TCGv_i64 t64;
1939
1940 dptr = tcg_temp_new_ptr();
1941 nptr = tcg_temp_new_ptr();
1942 tcg_gen_addi_ptr(dptr, cpu_env, vec_full_reg_offset(s, rd));
1943 tcg_gen_addi_ptr(nptr, cpu_env, vec_full_reg_offset(s, rn));
c6a59b55 1944 desc = tcg_constant_i32(simd_desc(vsz, vsz, 0));
24e82e68
RH
1945
1946 switch (esz) {
1947 case MO_8:
1948 t32 = tcg_temp_new_i32();
1949 tcg_gen_extrl_i64_i32(t32, val);
1950 if (d) {
1951 tcg_gen_neg_i32(t32, t32);
1952 }
1953 if (u) {
1954 gen_helper_sve_uqaddi_b(dptr, nptr, t32, desc);
1955 } else {
1956 gen_helper_sve_sqaddi_b(dptr, nptr, t32, desc);
1957 }
1958 tcg_temp_free_i32(t32);
1959 break;
1960
1961 case MO_16:
1962 t32 = tcg_temp_new_i32();
1963 tcg_gen_extrl_i64_i32(t32, val);
1964 if (d) {
1965 tcg_gen_neg_i32(t32, t32);
1966 }
1967 if (u) {
1968 gen_helper_sve_uqaddi_h(dptr, nptr, t32, desc);
1969 } else {
1970 gen_helper_sve_sqaddi_h(dptr, nptr, t32, desc);
1971 }
1972 tcg_temp_free_i32(t32);
1973 break;
1974
1975 case MO_32:
1976 t64 = tcg_temp_new_i64();
1977 if (d) {
1978 tcg_gen_neg_i64(t64, val);
1979 } else {
1980 tcg_gen_mov_i64(t64, val);
1981 }
1982 if (u) {
1983 gen_helper_sve_uqaddi_s(dptr, nptr, t64, desc);
1984 } else {
1985 gen_helper_sve_sqaddi_s(dptr, nptr, t64, desc);
1986 }
1987 tcg_temp_free_i64(t64);
1988 break;
1989
1990 case MO_64:
1991 if (u) {
1992 if (d) {
1993 gen_helper_sve_uqsubi_d(dptr, nptr, val, desc);
1994 } else {
1995 gen_helper_sve_uqaddi_d(dptr, nptr, val, desc);
1996 }
1997 } else if (d) {
1998 t64 = tcg_temp_new_i64();
1999 tcg_gen_neg_i64(t64, val);
2000 gen_helper_sve_sqaddi_d(dptr, nptr, t64, desc);
2001 tcg_temp_free_i64(t64);
2002 } else {
2003 gen_helper_sve_sqaddi_d(dptr, nptr, val, desc);
2004 }
2005 break;
2006
2007 default:
2008 g_assert_not_reached();
2009 }
2010
2011 tcg_temp_free_ptr(dptr);
2012 tcg_temp_free_ptr(nptr);
24e82e68
RH
2013}
2014
3a7be554 2015static bool trans_CNT_r(DisasContext *s, arg_CNT_r *a)
24e82e68
RH
2016{
2017 if (sve_access_check(s)) {
2018 unsigned fullsz = vec_full_reg_size(s);
2019 unsigned numelem = decode_pred_count(fullsz, a->pat, a->esz);
2020 tcg_gen_movi_i64(cpu_reg(s, a->rd), numelem * a->imm);
2021 }
2022 return true;
2023}
2024
3a7be554 2025static bool trans_INCDEC_r(DisasContext *s, arg_incdec_cnt *a)
24e82e68
RH
2026{
2027 if (sve_access_check(s)) {
2028 unsigned fullsz = vec_full_reg_size(s);
2029 unsigned numelem = decode_pred_count(fullsz, a->pat, a->esz);
2030 int inc = numelem * a->imm * (a->d ? -1 : 1);
2031 TCGv_i64 reg = cpu_reg(s, a->rd);
2032
2033 tcg_gen_addi_i64(reg, reg, inc);
2034 }
2035 return true;
2036}
2037
3a7be554 2038static bool trans_SINCDEC_r_32(DisasContext *s, arg_incdec_cnt *a)
24e82e68
RH
2039{
2040 if (!sve_access_check(s)) {
2041 return true;
2042 }
2043
2044 unsigned fullsz = vec_full_reg_size(s);
2045 unsigned numelem = decode_pred_count(fullsz, a->pat, a->esz);
2046 int inc = numelem * a->imm;
2047 TCGv_i64 reg = cpu_reg(s, a->rd);
2048
2049 /* Use normal 64-bit arithmetic to detect 32-bit overflow. */
2050 if (inc == 0) {
2051 if (a->u) {
2052 tcg_gen_ext32u_i64(reg, reg);
2053 } else {
2054 tcg_gen_ext32s_i64(reg, reg);
2055 }
2056 } else {
d681f125 2057 do_sat_addsub_32(reg, tcg_constant_i64(inc), a->u, a->d);
24e82e68
RH
2058 }
2059 return true;
2060}
2061
3a7be554 2062static bool trans_SINCDEC_r_64(DisasContext *s, arg_incdec_cnt *a)
24e82e68
RH
2063{
2064 if (!sve_access_check(s)) {
2065 return true;
2066 }
2067
2068 unsigned fullsz = vec_full_reg_size(s);
2069 unsigned numelem = decode_pred_count(fullsz, a->pat, a->esz);
2070 int inc = numelem * a->imm;
2071 TCGv_i64 reg = cpu_reg(s, a->rd);
2072
2073 if (inc != 0) {
d681f125 2074 do_sat_addsub_64(reg, tcg_constant_i64(inc), a->u, a->d);
24e82e68
RH
2075 }
2076 return true;
2077}
2078
3a7be554 2079static bool trans_INCDEC_v(DisasContext *s, arg_incdec2_cnt *a)
24e82e68
RH
2080{
2081 if (a->esz == 0) {
2082 return false;
2083 }
2084
2085 unsigned fullsz = vec_full_reg_size(s);
2086 unsigned numelem = decode_pred_count(fullsz, a->pat, a->esz);
2087 int inc = numelem * a->imm;
2088
2089 if (inc != 0) {
2090 if (sve_access_check(s)) {
24e82e68
RH
2091 tcg_gen_gvec_adds(a->esz, vec_full_reg_offset(s, a->rd),
2092 vec_full_reg_offset(s, a->rn),
d681f125
RH
2093 tcg_constant_i64(a->d ? -inc : inc),
2094 fullsz, fullsz);
24e82e68
RH
2095 }
2096 } else {
2097 do_mov_z(s, a->rd, a->rn);
2098 }
2099 return true;
2100}
2101
3a7be554 2102static bool trans_SINCDEC_v(DisasContext *s, arg_incdec2_cnt *a)
24e82e68
RH
2103{
2104 if (a->esz == 0) {
2105 return false;
2106 }
2107
2108 unsigned fullsz = vec_full_reg_size(s);
2109 unsigned numelem = decode_pred_count(fullsz, a->pat, a->esz);
2110 int inc = numelem * a->imm;
2111
2112 if (inc != 0) {
2113 if (sve_access_check(s)) {
d681f125
RH
2114 do_sat_addsub_vec(s, a->esz, a->rd, a->rn,
2115 tcg_constant_i64(inc), a->u, a->d);
24e82e68
RH
2116 }
2117 } else {
2118 do_mov_z(s, a->rd, a->rn);
2119 }
2120 return true;
2121}
2122
e1fa1164
RH
2123/*
2124 *** SVE Bitwise Immediate Group
2125 */
2126
2127static bool do_zz_dbm(DisasContext *s, arg_rr_dbm *a, GVecGen2iFn *gvec_fn)
2128{
2129 uint64_t imm;
2130 if (!logic_imm_decode_wmask(&imm, extract32(a->dbm, 12, 1),
2131 extract32(a->dbm, 0, 6),
2132 extract32(a->dbm, 6, 6))) {
2133 return false;
2134 }
2135 if (sve_access_check(s)) {
2136 unsigned vsz = vec_full_reg_size(s);
2137 gvec_fn(MO_64, vec_full_reg_offset(s, a->rd),
2138 vec_full_reg_offset(s, a->rn), imm, vsz, vsz);
2139 }
2140 return true;
2141}
2142
3a7be554 2143static bool trans_AND_zzi(DisasContext *s, arg_rr_dbm *a)
e1fa1164
RH
2144{
2145 return do_zz_dbm(s, a, tcg_gen_gvec_andi);
2146}
2147
3a7be554 2148static bool trans_ORR_zzi(DisasContext *s, arg_rr_dbm *a)
e1fa1164
RH
2149{
2150 return do_zz_dbm(s, a, tcg_gen_gvec_ori);
2151}
2152
3a7be554 2153static bool trans_EOR_zzi(DisasContext *s, arg_rr_dbm *a)
e1fa1164
RH
2154{
2155 return do_zz_dbm(s, a, tcg_gen_gvec_xori);
2156}
2157
3a7be554 2158static bool trans_DUPM(DisasContext *s, arg_DUPM *a)
e1fa1164
RH
2159{
2160 uint64_t imm;
2161 if (!logic_imm_decode_wmask(&imm, extract32(a->dbm, 12, 1),
2162 extract32(a->dbm, 0, 6),
2163 extract32(a->dbm, 6, 6))) {
2164 return false;
2165 }
2166 if (sve_access_check(s)) {
2167 do_dupi_z(s, a->rd, imm);
2168 }
2169 return true;
2170}
2171
f25a2361
RH
2172/*
2173 *** SVE Integer Wide Immediate - Predicated Group
2174 */
2175
2176/* Implement all merging copies. This is used for CPY (immediate),
2177 * FCPY, CPY (scalar), CPY (SIMD&FP scalar).
2178 */
2179static void do_cpy_m(DisasContext *s, int esz, int rd, int rn, int pg,
2180 TCGv_i64 val)
2181{
2182 typedef void gen_cpy(TCGv_ptr, TCGv_ptr, TCGv_ptr, TCGv_i64, TCGv_i32);
2183 static gen_cpy * const fns[4] = {
2184 gen_helper_sve_cpy_m_b, gen_helper_sve_cpy_m_h,
2185 gen_helper_sve_cpy_m_s, gen_helper_sve_cpy_m_d,
2186 };
2187 unsigned vsz = vec_full_reg_size(s);
c6a59b55 2188 TCGv_i32 desc = tcg_constant_i32(simd_desc(vsz, vsz, 0));
f25a2361
RH
2189 TCGv_ptr t_zd = tcg_temp_new_ptr();
2190 TCGv_ptr t_zn = tcg_temp_new_ptr();
2191 TCGv_ptr t_pg = tcg_temp_new_ptr();
2192
2193 tcg_gen_addi_ptr(t_zd, cpu_env, vec_full_reg_offset(s, rd));
2194 tcg_gen_addi_ptr(t_zn, cpu_env, vec_full_reg_offset(s, rn));
2195 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, pg));
2196
2197 fns[esz](t_zd, t_zn, t_pg, val, desc);
2198
2199 tcg_temp_free_ptr(t_zd);
2200 tcg_temp_free_ptr(t_zn);
2201 tcg_temp_free_ptr(t_pg);
f25a2361
RH
2202}
2203
3a7be554 2204static bool trans_FCPY(DisasContext *s, arg_FCPY *a)
f25a2361
RH
2205{
2206 if (a->esz == 0) {
2207 return false;
2208 }
2209 if (sve_access_check(s)) {
2210 /* Decode the VFP immediate. */
2211 uint64_t imm = vfp_expand_imm(a->esz, a->imm);
e152b48b 2212 do_cpy_m(s, a->esz, a->rd, a->rn, a->pg, tcg_constant_i64(imm));
f25a2361
RH
2213 }
2214 return true;
2215}
2216
3a7be554 2217static bool trans_CPY_m_i(DisasContext *s, arg_rpri_esz *a)
f25a2361 2218{
3a7be554 2219 if (a->esz == 0 && extract32(s->insn, 13, 1)) {
f25a2361
RH
2220 return false;
2221 }
2222 if (sve_access_check(s)) {
e152b48b 2223 do_cpy_m(s, a->esz, a->rd, a->rn, a->pg, tcg_constant_i64(a->imm));
f25a2361
RH
2224 }
2225 return true;
2226}
2227
3a7be554 2228static bool trans_CPY_z_i(DisasContext *s, arg_CPY_z_i *a)
f25a2361
RH
2229{
2230 static gen_helper_gvec_2i * const fns[4] = {
2231 gen_helper_sve_cpy_z_b, gen_helper_sve_cpy_z_h,
2232 gen_helper_sve_cpy_z_s, gen_helper_sve_cpy_z_d,
2233 };
2234
3a7be554 2235 if (a->esz == 0 && extract32(s->insn, 13, 1)) {
f25a2361
RH
2236 return false;
2237 }
2238 if (sve_access_check(s)) {
2239 unsigned vsz = vec_full_reg_size(s);
f25a2361
RH
2240 tcg_gen_gvec_2i_ool(vec_full_reg_offset(s, a->rd),
2241 pred_full_reg_offset(s, a->pg),
e152b48b
RH
2242 tcg_constant_i64(a->imm),
2243 vsz, vsz, 0, fns[a->esz]);
f25a2361
RH
2244 }
2245 return true;
2246}
2247
b94f8f60
RH
2248/*
2249 *** SVE Permute Extract Group
2250 */
2251
75114792 2252static bool do_EXT(DisasContext *s, int rd, int rn, int rm, int imm)
b94f8f60
RH
2253{
2254 if (!sve_access_check(s)) {
2255 return true;
2256 }
2257
2258 unsigned vsz = vec_full_reg_size(s);
75114792 2259 unsigned n_ofs = imm >= vsz ? 0 : imm;
b94f8f60 2260 unsigned n_siz = vsz - n_ofs;
75114792
SL
2261 unsigned d = vec_full_reg_offset(s, rd);
2262 unsigned n = vec_full_reg_offset(s, rn);
2263 unsigned m = vec_full_reg_offset(s, rm);
b94f8f60
RH
2264
2265 /* Use host vector move insns if we have appropriate sizes
2266 * and no unfortunate overlap.
2267 */
2268 if (m != d
2269 && n_ofs == size_for_gvec(n_ofs)
2270 && n_siz == size_for_gvec(n_siz)
2271 && (d != n || n_siz <= n_ofs)) {
2272 tcg_gen_gvec_mov(0, d, n + n_ofs, n_siz, n_siz);
2273 if (n_ofs != 0) {
2274 tcg_gen_gvec_mov(0, d + n_siz, m, n_ofs, n_ofs);
2275 }
2276 } else {
2277 tcg_gen_gvec_3_ool(d, n, m, vsz, vsz, n_ofs, gen_helper_sve_ext);
2278 }
2279 return true;
2280}
2281
75114792
SL
2282static bool trans_EXT(DisasContext *s, arg_EXT *a)
2283{
2284 return do_EXT(s, a->rd, a->rn, a->rm, a->imm);
2285}
2286
2287static bool trans_EXT_sve2(DisasContext *s, arg_rri *a)
2288{
2289 if (!dc_isar_feature(aa64_sve2, s)) {
2290 return false;
2291 }
2292 return do_EXT(s, a->rd, a->rn, (a->rn + 1) % 32, a->imm);
2293}
2294
30562ab7
RH
2295/*
2296 *** SVE Permute - Unpredicated Group
2297 */
2298
3a7be554 2299static bool trans_DUP_s(DisasContext *s, arg_DUP_s *a)
30562ab7
RH
2300{
2301 if (sve_access_check(s)) {
2302 unsigned vsz = vec_full_reg_size(s);
2303 tcg_gen_gvec_dup_i64(a->esz, vec_full_reg_offset(s, a->rd),
2304 vsz, vsz, cpu_reg_sp(s, a->rn));
2305 }
2306 return true;
2307}
2308
3a7be554 2309static bool trans_DUP_x(DisasContext *s, arg_DUP_x *a)
30562ab7
RH
2310{
2311 if ((a->imm & 0x1f) == 0) {
2312 return false;
2313 }
2314 if (sve_access_check(s)) {
2315 unsigned vsz = vec_full_reg_size(s);
2316 unsigned dofs = vec_full_reg_offset(s, a->rd);
2317 unsigned esz, index;
2318
2319 esz = ctz32(a->imm);
2320 index = a->imm >> (esz + 1);
2321
2322 if ((index << esz) < vsz) {
2323 unsigned nofs = vec_reg_offset(s, a->rn, index, esz);
2324 tcg_gen_gvec_dup_mem(esz, dofs, nofs, vsz, vsz);
2325 } else {
7e17d50e
RH
2326 /*
2327 * While dup_mem handles 128-bit elements, dup_imm does not.
2328 * Thankfully element size doesn't matter for splatting zero.
2329 */
2330 tcg_gen_gvec_dup_imm(MO_64, dofs, vsz, vsz, 0);
30562ab7
RH
2331 }
2332 }
2333 return true;
2334}
2335
2336static void do_insr_i64(DisasContext *s, arg_rrr_esz *a, TCGv_i64 val)
2337{
2338 typedef void gen_insr(TCGv_ptr, TCGv_ptr, TCGv_i64, TCGv_i32);
2339 static gen_insr * const fns[4] = {
2340 gen_helper_sve_insr_b, gen_helper_sve_insr_h,
2341 gen_helper_sve_insr_s, gen_helper_sve_insr_d,
2342 };
2343 unsigned vsz = vec_full_reg_size(s);
c6a59b55 2344 TCGv_i32 desc = tcg_constant_i32(simd_desc(vsz, vsz, 0));
30562ab7
RH
2345 TCGv_ptr t_zd = tcg_temp_new_ptr();
2346 TCGv_ptr t_zn = tcg_temp_new_ptr();
2347
2348 tcg_gen_addi_ptr(t_zd, cpu_env, vec_full_reg_offset(s, a->rd));
2349 tcg_gen_addi_ptr(t_zn, cpu_env, vec_full_reg_offset(s, a->rn));
2350
2351 fns[a->esz](t_zd, t_zn, val, desc);
2352
2353 tcg_temp_free_ptr(t_zd);
2354 tcg_temp_free_ptr(t_zn);
30562ab7
RH
2355}
2356
3a7be554 2357static bool trans_INSR_f(DisasContext *s, arg_rrr_esz *a)
30562ab7
RH
2358{
2359 if (sve_access_check(s)) {
2360 TCGv_i64 t = tcg_temp_new_i64();
2361 tcg_gen_ld_i64(t, cpu_env, vec_reg_offset(s, a->rm, 0, MO_64));
2362 do_insr_i64(s, a, t);
2363 tcg_temp_free_i64(t);
2364 }
2365 return true;
2366}
2367
3a7be554 2368static bool trans_INSR_r(DisasContext *s, arg_rrr_esz *a)
30562ab7
RH
2369{
2370 if (sve_access_check(s)) {
2371 do_insr_i64(s, a, cpu_reg(s, a->rm));
2372 }
2373 return true;
2374}
2375
0ea3cdbf
RH
2376static gen_helper_gvec_2 * const rev_fns[4] = {
2377 gen_helper_sve_rev_b, gen_helper_sve_rev_h,
2378 gen_helper_sve_rev_s, gen_helper_sve_rev_d
2379};
2380TRANS_FEAT(REV_v, aa64_sve, gen_gvec_ool_zz, rev_fns[a->esz], a->rd, a->rn, 0)
30562ab7 2381
32e2ad65
RH
2382static gen_helper_gvec_3 * const sve_tbl_fns[4] = {
2383 gen_helper_sve_tbl_b, gen_helper_sve_tbl_h,
2384 gen_helper_sve_tbl_s, gen_helper_sve_tbl_d
2385};
2386TRANS_FEAT(TBL, aa64_sve, gen_gvec_ool_arg_zzz, sve_tbl_fns[a->esz], a, 0)
30562ab7 2387
5f425b92
RH
2388static gen_helper_gvec_4 * const sve2_tbl_fns[4] = {
2389 gen_helper_sve2_tbl_b, gen_helper_sve2_tbl_h,
2390 gen_helper_sve2_tbl_s, gen_helper_sve2_tbl_d
2391};
2392TRANS_FEAT(TBL_sve2, aa64_sve2, gen_gvec_ool_zzzz, sve2_tbl_fns[a->esz],
2393 a->rd, a->rn, (a->rn + 1) % 32, a->rm, 0)
80a712a2 2394
32e2ad65
RH
2395static gen_helper_gvec_3 * const tbx_fns[4] = {
2396 gen_helper_sve2_tbx_b, gen_helper_sve2_tbx_h,
2397 gen_helper_sve2_tbx_s, gen_helper_sve2_tbx_d
2398};
2399TRANS_FEAT(TBX, aa64_sve2, gen_gvec_ool_arg_zzz, tbx_fns[a->esz], a, 0)
80a712a2 2400
3a7be554 2401static bool trans_UNPK(DisasContext *s, arg_UNPK *a)
30562ab7
RH
2402{
2403 static gen_helper_gvec_2 * const fns[4][2] = {
2404 { NULL, NULL },
2405 { gen_helper_sve_sunpk_h, gen_helper_sve_uunpk_h },
2406 { gen_helper_sve_sunpk_s, gen_helper_sve_uunpk_s },
2407 { gen_helper_sve_sunpk_d, gen_helper_sve_uunpk_d },
2408 };
2409
2410 if (a->esz == 0) {
2411 return false;
2412 }
2413 if (sve_access_check(s)) {
2414 unsigned vsz = vec_full_reg_size(s);
2415 tcg_gen_gvec_2_ool(vec_full_reg_offset(s, a->rd),
2416 vec_full_reg_offset(s, a->rn)
2417 + (a->h ? vsz / 2 : 0),
2418 vsz, vsz, 0, fns[a->esz][a->u]);
2419 }
2420 return true;
2421}
2422
d731d8cb
RH
2423/*
2424 *** SVE Permute - Predicates Group
2425 */
2426
2427static bool do_perm_pred3(DisasContext *s, arg_rrr_esz *a, bool high_odd,
2428 gen_helper_gvec_3 *fn)
2429{
2430 if (!sve_access_check(s)) {
2431 return true;
2432 }
2433
2434 unsigned vsz = pred_full_reg_size(s);
2435
d731d8cb
RH
2436 TCGv_ptr t_d = tcg_temp_new_ptr();
2437 TCGv_ptr t_n = tcg_temp_new_ptr();
2438 TCGv_ptr t_m = tcg_temp_new_ptr();
f9b0fcce 2439 uint32_t desc = 0;
d731d8cb 2440
f9b0fcce
RH
2441 desc = FIELD_DP32(desc, PREDDESC, OPRSZ, vsz);
2442 desc = FIELD_DP32(desc, PREDDESC, ESZ, a->esz);
2443 desc = FIELD_DP32(desc, PREDDESC, DATA, high_odd);
d731d8cb
RH
2444
2445 tcg_gen_addi_ptr(t_d, cpu_env, pred_full_reg_offset(s, a->rd));
2446 tcg_gen_addi_ptr(t_n, cpu_env, pred_full_reg_offset(s, a->rn));
2447 tcg_gen_addi_ptr(t_m, cpu_env, pred_full_reg_offset(s, a->rm));
d731d8cb 2448
c6a59b55 2449 fn(t_d, t_n, t_m, tcg_constant_i32(desc));
d731d8cb
RH
2450
2451 tcg_temp_free_ptr(t_d);
2452 tcg_temp_free_ptr(t_n);
2453 tcg_temp_free_ptr(t_m);
d731d8cb
RH
2454 return true;
2455}
2456
2457static bool do_perm_pred2(DisasContext *s, arg_rr_esz *a, bool high_odd,
2458 gen_helper_gvec_2 *fn)
2459{
2460 if (!sve_access_check(s)) {
2461 return true;
2462 }
2463
2464 unsigned vsz = pred_full_reg_size(s);
2465 TCGv_ptr t_d = tcg_temp_new_ptr();
2466 TCGv_ptr t_n = tcg_temp_new_ptr();
70acaafe 2467 uint32_t desc = 0;
d731d8cb
RH
2468
2469 tcg_gen_addi_ptr(t_d, cpu_env, pred_full_reg_offset(s, a->rd));
2470 tcg_gen_addi_ptr(t_n, cpu_env, pred_full_reg_offset(s, a->rn));
2471
70acaafe
RH
2472 desc = FIELD_DP32(desc, PREDDESC, OPRSZ, vsz);
2473 desc = FIELD_DP32(desc, PREDDESC, ESZ, a->esz);
2474 desc = FIELD_DP32(desc, PREDDESC, DATA, high_odd);
d731d8cb 2475
c6a59b55 2476 fn(t_d, t_n, tcg_constant_i32(desc));
d731d8cb 2477
d731d8cb
RH
2478 tcg_temp_free_ptr(t_d);
2479 tcg_temp_free_ptr(t_n);
2480 return true;
2481}
2482
3a7be554 2483static bool trans_ZIP1_p(DisasContext *s, arg_rrr_esz *a)
d731d8cb
RH
2484{
2485 return do_perm_pred3(s, a, 0, gen_helper_sve_zip_p);
2486}
2487
3a7be554 2488static bool trans_ZIP2_p(DisasContext *s, arg_rrr_esz *a)
d731d8cb
RH
2489{
2490 return do_perm_pred3(s, a, 1, gen_helper_sve_zip_p);
2491}
2492
3a7be554 2493static bool trans_UZP1_p(DisasContext *s, arg_rrr_esz *a)
d731d8cb
RH
2494{
2495 return do_perm_pred3(s, a, 0, gen_helper_sve_uzp_p);
2496}
2497
3a7be554 2498static bool trans_UZP2_p(DisasContext *s, arg_rrr_esz *a)
d731d8cb
RH
2499{
2500 return do_perm_pred3(s, a, 1, gen_helper_sve_uzp_p);
2501}
2502
3a7be554 2503static bool trans_TRN1_p(DisasContext *s, arg_rrr_esz *a)
d731d8cb
RH
2504{
2505 return do_perm_pred3(s, a, 0, gen_helper_sve_trn_p);
2506}
2507
3a7be554 2508static bool trans_TRN2_p(DisasContext *s, arg_rrr_esz *a)
d731d8cb
RH
2509{
2510 return do_perm_pred3(s, a, 1, gen_helper_sve_trn_p);
2511}
2512
3a7be554 2513static bool trans_REV_p(DisasContext *s, arg_rr_esz *a)
d731d8cb
RH
2514{
2515 return do_perm_pred2(s, a, 0, gen_helper_sve_rev_p);
2516}
2517
3a7be554 2518static bool trans_PUNPKLO(DisasContext *s, arg_PUNPKLO *a)
d731d8cb
RH
2519{
2520 return do_perm_pred2(s, a, 0, gen_helper_sve_punpk_p);
2521}
2522
3a7be554 2523static bool trans_PUNPKHI(DisasContext *s, arg_PUNPKHI *a)
d731d8cb
RH
2524{
2525 return do_perm_pred2(s, a, 1, gen_helper_sve_punpk_p);
2526}
2527
234b48e9
RH
2528/*
2529 *** SVE Permute - Interleaving Group
2530 */
2531
2532static bool do_zip(DisasContext *s, arg_rrr_esz *a, bool high)
2533{
2534 static gen_helper_gvec_3 * const fns[4] = {
2535 gen_helper_sve_zip_b, gen_helper_sve_zip_h,
2536 gen_helper_sve_zip_s, gen_helper_sve_zip_d,
2537 };
2538
2539 if (sve_access_check(s)) {
2540 unsigned vsz = vec_full_reg_size(s);
2541 unsigned high_ofs = high ? vsz / 2 : 0;
2542 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, a->rd),
2543 vec_full_reg_offset(s, a->rn) + high_ofs,
2544 vec_full_reg_offset(s, a->rm) + high_ofs,
2545 vsz, vsz, 0, fns[a->esz]);
2546 }
2547 return true;
2548}
2549
3a7be554 2550static bool trans_ZIP1_z(DisasContext *s, arg_rrr_esz *a)
234b48e9
RH
2551{
2552 return do_zip(s, a, false);
2553}
2554
3a7be554 2555static bool trans_ZIP2_z(DisasContext *s, arg_rrr_esz *a)
234b48e9
RH
2556{
2557 return do_zip(s, a, true);
2558}
2559
74b64b25
RH
2560static bool do_zip_q(DisasContext *s, arg_rrr_esz *a, bool high)
2561{
2562 if (!dc_isar_feature(aa64_sve_f64mm, s)) {
2563 return false;
2564 }
2565 if (sve_access_check(s)) {
2566 unsigned vsz = vec_full_reg_size(s);
2567 unsigned high_ofs = high ? QEMU_ALIGN_DOWN(vsz, 32) / 2 : 0;
2568 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, a->rd),
2569 vec_full_reg_offset(s, a->rn) + high_ofs,
2570 vec_full_reg_offset(s, a->rm) + high_ofs,
2571 vsz, vsz, 0, gen_helper_sve2_zip_q);
2572 }
2573 return true;
2574}
2575
2576static bool trans_ZIP1_q(DisasContext *s, arg_rrr_esz *a)
2577{
2578 return do_zip_q(s, a, false);
2579}
2580
2581static bool trans_ZIP2_q(DisasContext *s, arg_rrr_esz *a)
2582{
2583 return do_zip_q(s, a, true);
2584}
2585
234b48e9
RH
2586static gen_helper_gvec_3 * const uzp_fns[4] = {
2587 gen_helper_sve_uzp_b, gen_helper_sve_uzp_h,
2588 gen_helper_sve_uzp_s, gen_helper_sve_uzp_d,
2589};
2590
32e2ad65
RH
2591TRANS_FEAT(UZP1_z, aa64_sve, gen_gvec_ool_arg_zzz,
2592 uzp_fns[a->esz], a, 0)
2593TRANS_FEAT(UZP2_z, aa64_sve, gen_gvec_ool_arg_zzz,
2594 uzp_fns[a->esz], a, 1 << a->esz)
234b48e9 2595
32e2ad65
RH
2596TRANS_FEAT(UZP1_q, aa64_sve_f64mm, gen_gvec_ool_arg_zzz,
2597 gen_helper_sve2_uzp_q, a, 0)
2598TRANS_FEAT(UZP2_q, aa64_sve_f64mm, gen_gvec_ool_arg_zzz,
2599 gen_helper_sve2_uzp_q, a, 16)
74b64b25 2600
234b48e9
RH
2601static gen_helper_gvec_3 * const trn_fns[4] = {
2602 gen_helper_sve_trn_b, gen_helper_sve_trn_h,
2603 gen_helper_sve_trn_s, gen_helper_sve_trn_d,
2604};
2605
32e2ad65
RH
2606TRANS_FEAT(TRN1_z, aa64_sve, gen_gvec_ool_arg_zzz,
2607 trn_fns[a->esz], a, 0)
2608TRANS_FEAT(TRN2_z, aa64_sve, gen_gvec_ool_arg_zzz,
2609 trn_fns[a->esz], a, 1 << a->esz)
234b48e9 2610
32e2ad65
RH
2611TRANS_FEAT(TRN1_q, aa64_sve_f64mm, gen_gvec_ool_arg_zzz,
2612 gen_helper_sve2_trn_q, a, 0)
2613TRANS_FEAT(TRN2_q, aa64_sve_f64mm, gen_gvec_ool_arg_zzz,
2614 gen_helper_sve2_trn_q, a, 16)
74b64b25 2615
3ca879ae
RH
2616/*
2617 *** SVE Permute Vector - Predicated Group
2618 */
2619
817bd5c9
RH
2620static gen_helper_gvec_3 * const compact_fns[4] = {
2621 NULL, NULL, gen_helper_sve_compact_s, gen_helper_sve_compact_d
2622};
2623TRANS_FEAT(COMPACT, aa64_sve, gen_gvec_ool_arg_zpz, compact_fns[a->esz], a, 0)
3ca879ae 2624
ef23cb72
RH
2625/* Call the helper that computes the ARM LastActiveElement pseudocode
2626 * function, scaled by the element size. This includes the not found
2627 * indication; e.g. not found for esz=3 is -8.
2628 */
2629static void find_last_active(DisasContext *s, TCGv_i32 ret, int esz, int pg)
2630{
2631 /* Predicate sizes may be smaller and cannot use simd_desc. We cannot
2632 * round up, as we do elsewhere, because we need the exact size.
2633 */
2634 TCGv_ptr t_p = tcg_temp_new_ptr();
2acbfbe4 2635 unsigned desc = 0;
ef23cb72 2636
2acbfbe4
RH
2637 desc = FIELD_DP32(desc, PREDDESC, OPRSZ, pred_full_reg_size(s));
2638 desc = FIELD_DP32(desc, PREDDESC, ESZ, esz);
ef23cb72
RH
2639
2640 tcg_gen_addi_ptr(t_p, cpu_env, pred_full_reg_offset(s, pg));
ef23cb72 2641
c6a59b55 2642 gen_helper_sve_last_active_element(ret, t_p, tcg_constant_i32(desc));
ef23cb72 2643
ef23cb72
RH
2644 tcg_temp_free_ptr(t_p);
2645}
2646
2647/* Increment LAST to the offset of the next element in the vector,
2648 * wrapping around to 0.
2649 */
2650static void incr_last_active(DisasContext *s, TCGv_i32 last, int esz)
2651{
2652 unsigned vsz = vec_full_reg_size(s);
2653
2654 tcg_gen_addi_i32(last, last, 1 << esz);
2655 if (is_power_of_2(vsz)) {
2656 tcg_gen_andi_i32(last, last, vsz - 1);
2657 } else {
4b308bd5
RH
2658 TCGv_i32 max = tcg_constant_i32(vsz);
2659 TCGv_i32 zero = tcg_constant_i32(0);
ef23cb72 2660 tcg_gen_movcond_i32(TCG_COND_GEU, last, last, max, zero, last);
ef23cb72
RH
2661 }
2662}
2663
2664/* If LAST < 0, set LAST to the offset of the last element in the vector. */
2665static void wrap_last_active(DisasContext *s, TCGv_i32 last, int esz)
2666{
2667 unsigned vsz = vec_full_reg_size(s);
2668
2669 if (is_power_of_2(vsz)) {
2670 tcg_gen_andi_i32(last, last, vsz - 1);
2671 } else {
4b308bd5
RH
2672 TCGv_i32 max = tcg_constant_i32(vsz - (1 << esz));
2673 TCGv_i32 zero = tcg_constant_i32(0);
ef23cb72 2674 tcg_gen_movcond_i32(TCG_COND_LT, last, last, zero, max, last);
ef23cb72
RH
2675 }
2676}
2677
2678/* Load an unsigned element of ESZ from BASE+OFS. */
2679static TCGv_i64 load_esz(TCGv_ptr base, int ofs, int esz)
2680{
2681 TCGv_i64 r = tcg_temp_new_i64();
2682
2683 switch (esz) {
2684 case 0:
2685 tcg_gen_ld8u_i64(r, base, ofs);
2686 break;
2687 case 1:
2688 tcg_gen_ld16u_i64(r, base, ofs);
2689 break;
2690 case 2:
2691 tcg_gen_ld32u_i64(r, base, ofs);
2692 break;
2693 case 3:
2694 tcg_gen_ld_i64(r, base, ofs);
2695 break;
2696 default:
2697 g_assert_not_reached();
2698 }
2699 return r;
2700}
2701
2702/* Load an unsigned element of ESZ from RM[LAST]. */
2703static TCGv_i64 load_last_active(DisasContext *s, TCGv_i32 last,
2704 int rm, int esz)
2705{
2706 TCGv_ptr p = tcg_temp_new_ptr();
2707 TCGv_i64 r;
2708
2709 /* Convert offset into vector into offset into ENV.
2710 * The final adjustment for the vector register base
2711 * is added via constant offset to the load.
2712 */
e03b5686 2713#if HOST_BIG_ENDIAN
ef23cb72
RH
2714 /* Adjust for element ordering. See vec_reg_offset. */
2715 if (esz < 3) {
2716 tcg_gen_xori_i32(last, last, 8 - (1 << esz));
2717 }
2718#endif
2719 tcg_gen_ext_i32_ptr(p, last);
2720 tcg_gen_add_ptr(p, p, cpu_env);
2721
2722 r = load_esz(p, vec_full_reg_offset(s, rm), esz);
2723 tcg_temp_free_ptr(p);
2724
2725 return r;
2726}
2727
2728/* Compute CLAST for a Zreg. */
2729static bool do_clast_vector(DisasContext *s, arg_rprr_esz *a, bool before)
2730{
2731 TCGv_i32 last;
2732 TCGLabel *over;
2733 TCGv_i64 ele;
2734 unsigned vsz, esz = a->esz;
2735
2736 if (!sve_access_check(s)) {
2737 return true;
2738 }
2739
2740 last = tcg_temp_local_new_i32();
2741 over = gen_new_label();
2742
2743 find_last_active(s, last, esz, a->pg);
2744
2745 /* There is of course no movcond for a 2048-bit vector,
2746 * so we must branch over the actual store.
2747 */
2748 tcg_gen_brcondi_i32(TCG_COND_LT, last, 0, over);
2749
2750 if (!before) {
2751 incr_last_active(s, last, esz);
2752 }
2753
2754 ele = load_last_active(s, last, a->rm, esz);
2755 tcg_temp_free_i32(last);
2756
2757 vsz = vec_full_reg_size(s);
2758 tcg_gen_gvec_dup_i64(esz, vec_full_reg_offset(s, a->rd), vsz, vsz, ele);
2759 tcg_temp_free_i64(ele);
2760
2761 /* If this insn used MOVPRFX, we may need a second move. */
2762 if (a->rd != a->rn) {
2763 TCGLabel *done = gen_new_label();
2764 tcg_gen_br(done);
2765
2766 gen_set_label(over);
2767 do_mov_z(s, a->rd, a->rn);
2768
2769 gen_set_label(done);
2770 } else {
2771 gen_set_label(over);
2772 }
2773 return true;
2774}
2775
3a7be554 2776static bool trans_CLASTA_z(DisasContext *s, arg_rprr_esz *a)
ef23cb72
RH
2777{
2778 return do_clast_vector(s, a, false);
2779}
2780
3a7be554 2781static bool trans_CLASTB_z(DisasContext *s, arg_rprr_esz *a)
ef23cb72
RH
2782{
2783 return do_clast_vector(s, a, true);
2784}
2785
2786/* Compute CLAST for a scalar. */
2787static void do_clast_scalar(DisasContext *s, int esz, int pg, int rm,
2788 bool before, TCGv_i64 reg_val)
2789{
2790 TCGv_i32 last = tcg_temp_new_i32();
053552d3 2791 TCGv_i64 ele, cmp;
ef23cb72
RH
2792
2793 find_last_active(s, last, esz, pg);
2794
2795 /* Extend the original value of last prior to incrementing. */
2796 cmp = tcg_temp_new_i64();
2797 tcg_gen_ext_i32_i64(cmp, last);
2798
2799 if (!before) {
2800 incr_last_active(s, last, esz);
2801 }
2802
2803 /* The conceit here is that while last < 0 indicates not found, after
2804 * adjusting for cpu_env->vfp.zregs[rm], it is still a valid address
2805 * from which we can load garbage. We then discard the garbage with
2806 * a conditional move.
2807 */
2808 ele = load_last_active(s, last, rm, esz);
2809 tcg_temp_free_i32(last);
2810
053552d3
RH
2811 tcg_gen_movcond_i64(TCG_COND_GE, reg_val, cmp, tcg_constant_i64(0),
2812 ele, reg_val);
ef23cb72 2813
ef23cb72
RH
2814 tcg_temp_free_i64(cmp);
2815 tcg_temp_free_i64(ele);
2816}
2817
2818/* Compute CLAST for a Vreg. */
2819static bool do_clast_fp(DisasContext *s, arg_rpr_esz *a, bool before)
2820{
2821 if (sve_access_check(s)) {
2822 int esz = a->esz;
2823 int ofs = vec_reg_offset(s, a->rd, 0, esz);
2824 TCGv_i64 reg = load_esz(cpu_env, ofs, esz);
2825
2826 do_clast_scalar(s, esz, a->pg, a->rn, before, reg);
2827 write_fp_dreg(s, a->rd, reg);
2828 tcg_temp_free_i64(reg);
2829 }
2830 return true;
2831}
2832
3a7be554 2833static bool trans_CLASTA_v(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2834{
2835 return do_clast_fp(s, a, false);
2836}
2837
3a7be554 2838static bool trans_CLASTB_v(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2839{
2840 return do_clast_fp(s, a, true);
2841}
2842
2843/* Compute CLAST for a Xreg. */
2844static bool do_clast_general(DisasContext *s, arg_rpr_esz *a, bool before)
2845{
2846 TCGv_i64 reg;
2847
2848 if (!sve_access_check(s)) {
2849 return true;
2850 }
2851
2852 reg = cpu_reg(s, a->rd);
2853 switch (a->esz) {
2854 case 0:
2855 tcg_gen_ext8u_i64(reg, reg);
2856 break;
2857 case 1:
2858 tcg_gen_ext16u_i64(reg, reg);
2859 break;
2860 case 2:
2861 tcg_gen_ext32u_i64(reg, reg);
2862 break;
2863 case 3:
2864 break;
2865 default:
2866 g_assert_not_reached();
2867 }
2868
2869 do_clast_scalar(s, a->esz, a->pg, a->rn, before, reg);
2870 return true;
2871}
2872
3a7be554 2873static bool trans_CLASTA_r(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2874{
2875 return do_clast_general(s, a, false);
2876}
2877
3a7be554 2878static bool trans_CLASTB_r(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2879{
2880 return do_clast_general(s, a, true);
2881}
2882
2883/* Compute LAST for a scalar. */
2884static TCGv_i64 do_last_scalar(DisasContext *s, int esz,
2885 int pg, int rm, bool before)
2886{
2887 TCGv_i32 last = tcg_temp_new_i32();
2888 TCGv_i64 ret;
2889
2890 find_last_active(s, last, esz, pg);
2891 if (before) {
2892 wrap_last_active(s, last, esz);
2893 } else {
2894 incr_last_active(s, last, esz);
2895 }
2896
2897 ret = load_last_active(s, last, rm, esz);
2898 tcg_temp_free_i32(last);
2899 return ret;
2900}
2901
2902/* Compute LAST for a Vreg. */
2903static bool do_last_fp(DisasContext *s, arg_rpr_esz *a, bool before)
2904{
2905 if (sve_access_check(s)) {
2906 TCGv_i64 val = do_last_scalar(s, a->esz, a->pg, a->rn, before);
2907 write_fp_dreg(s, a->rd, val);
2908 tcg_temp_free_i64(val);
2909 }
2910 return true;
2911}
2912
3a7be554 2913static bool trans_LASTA_v(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2914{
2915 return do_last_fp(s, a, false);
2916}
2917
3a7be554 2918static bool trans_LASTB_v(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2919{
2920 return do_last_fp(s, a, true);
2921}
2922
2923/* Compute LAST for a Xreg. */
2924static bool do_last_general(DisasContext *s, arg_rpr_esz *a, bool before)
2925{
2926 if (sve_access_check(s)) {
2927 TCGv_i64 val = do_last_scalar(s, a->esz, a->pg, a->rn, before);
2928 tcg_gen_mov_i64(cpu_reg(s, a->rd), val);
2929 tcg_temp_free_i64(val);
2930 }
2931 return true;
2932}
2933
3a7be554 2934static bool trans_LASTA_r(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2935{
2936 return do_last_general(s, a, false);
2937}
2938
3a7be554 2939static bool trans_LASTB_r(DisasContext *s, arg_rpr_esz *a)
ef23cb72
RH
2940{
2941 return do_last_general(s, a, true);
2942}
2943
3a7be554 2944static bool trans_CPY_m_r(DisasContext *s, arg_rpr_esz *a)
792a5578
RH
2945{
2946 if (sve_access_check(s)) {
2947 do_cpy_m(s, a->esz, a->rd, a->rd, a->pg, cpu_reg_sp(s, a->rn));
2948 }
2949 return true;
2950}
2951
3a7be554 2952static bool trans_CPY_m_v(DisasContext *s, arg_rpr_esz *a)
792a5578
RH
2953{
2954 if (sve_access_check(s)) {
2955 int ofs = vec_reg_offset(s, a->rn, 0, a->esz);
2956 TCGv_i64 t = load_esz(cpu_env, ofs, a->esz);
2957 do_cpy_m(s, a->esz, a->rd, a->rd, a->pg, t);
2958 tcg_temp_free_i64(t);
2959 }
2960 return true;
2961}
2962
817bd5c9
RH
2963static gen_helper_gvec_3 * const revb_fns[4] = {
2964 NULL, gen_helper_sve_revb_h,
2965 gen_helper_sve_revb_s, gen_helper_sve_revb_d,
2966};
2967TRANS_FEAT(REVB, aa64_sve, gen_gvec_ool_arg_zpz, revb_fns[a->esz], a, 0)
dae8fb90 2968
817bd5c9
RH
2969static gen_helper_gvec_3 * const revh_fns[4] = {
2970 NULL, NULL, gen_helper_sve_revh_s, gen_helper_sve_revh_d,
2971};
2972TRANS_FEAT(REVH, aa64_sve, gen_gvec_ool_arg_zpz, revh_fns[a->esz], a, 0)
dae8fb90 2973
817bd5c9
RH
2974TRANS_FEAT(REVW, aa64_sve, gen_gvec_ool_arg_zpz,
2975 a->esz == 3 ? gen_helper_sve_revw_d : NULL, a, 0)
dae8fb90 2976
3a7be554 2977static bool trans_SPLICE(DisasContext *s, arg_rprr_esz *a)
b48ff240
RH
2978{
2979 if (sve_access_check(s)) {
36cbb7a8 2980 gen_gvec_ool_zzzp(s, gen_helper_sve_splice,
dd701faf 2981 a->rd, a->rn, a->rm, a->pg, a->esz);
b48ff240
RH
2982 }
2983 return true;
2984}
2985
75114792
SL
2986static bool trans_SPLICE_sve2(DisasContext *s, arg_rpr_esz *a)
2987{
2988 if (!dc_isar_feature(aa64_sve2, s)) {
2989 return false;
2990 }
2991 if (sve_access_check(s)) {
2992 gen_gvec_ool_zzzp(s, gen_helper_sve_splice,
2993 a->rd, a->rn, (a->rn + 1) % 32, a->pg, a->esz);
2994 }
2995 return true;
2996}
2997
757f9cff
RH
2998/*
2999 *** SVE Integer Compare - Vectors Group
3000 */
3001
3002static bool do_ppzz_flags(DisasContext *s, arg_rprr_esz *a,
3003 gen_helper_gvec_flags_4 *gen_fn)
3004{
3005 TCGv_ptr pd, zn, zm, pg;
3006 unsigned vsz;
3007 TCGv_i32 t;
3008
3009 if (gen_fn == NULL) {
3010 return false;
3011 }
3012 if (!sve_access_check(s)) {
3013 return true;
3014 }
3015
3016 vsz = vec_full_reg_size(s);
392acacc 3017 t = tcg_temp_new_i32();
757f9cff
RH
3018 pd = tcg_temp_new_ptr();
3019 zn = tcg_temp_new_ptr();
3020 zm = tcg_temp_new_ptr();
3021 pg = tcg_temp_new_ptr();
3022
3023 tcg_gen_addi_ptr(pd, cpu_env, pred_full_reg_offset(s, a->rd));
3024 tcg_gen_addi_ptr(zn, cpu_env, vec_full_reg_offset(s, a->rn));
3025 tcg_gen_addi_ptr(zm, cpu_env, vec_full_reg_offset(s, a->rm));
3026 tcg_gen_addi_ptr(pg, cpu_env, pred_full_reg_offset(s, a->pg));
3027
392acacc 3028 gen_fn(t, pd, zn, zm, pg, tcg_constant_i32(simd_desc(vsz, vsz, 0)));
757f9cff
RH
3029
3030 tcg_temp_free_ptr(pd);
3031 tcg_temp_free_ptr(zn);
3032 tcg_temp_free_ptr(zm);
3033 tcg_temp_free_ptr(pg);
3034
3035 do_pred_flags(t);
3036
3037 tcg_temp_free_i32(t);
3038 return true;
3039}
3040
3041#define DO_PPZZ(NAME, name) \
3a7be554 3042static bool trans_##NAME##_ppzz(DisasContext *s, arg_rprr_esz *a) \
757f9cff
RH
3043{ \
3044 static gen_helper_gvec_flags_4 * const fns[4] = { \
3045 gen_helper_sve_##name##_ppzz_b, gen_helper_sve_##name##_ppzz_h, \
3046 gen_helper_sve_##name##_ppzz_s, gen_helper_sve_##name##_ppzz_d, \
3047 }; \
3048 return do_ppzz_flags(s, a, fns[a->esz]); \
3049}
3050
3051DO_PPZZ(CMPEQ, cmpeq)
3052DO_PPZZ(CMPNE, cmpne)
3053DO_PPZZ(CMPGT, cmpgt)
3054DO_PPZZ(CMPGE, cmpge)
3055DO_PPZZ(CMPHI, cmphi)
3056DO_PPZZ(CMPHS, cmphs)
3057
3058#undef DO_PPZZ
3059
3060#define DO_PPZW(NAME, name) \
3a7be554 3061static bool trans_##NAME##_ppzw(DisasContext *s, arg_rprr_esz *a) \
757f9cff
RH
3062{ \
3063 static gen_helper_gvec_flags_4 * const fns[4] = { \
3064 gen_helper_sve_##name##_ppzw_b, gen_helper_sve_##name##_ppzw_h, \
3065 gen_helper_sve_##name##_ppzw_s, NULL \
3066 }; \
3067 return do_ppzz_flags(s, a, fns[a->esz]); \
3068}
3069
3070DO_PPZW(CMPEQ, cmpeq)
3071DO_PPZW(CMPNE, cmpne)
3072DO_PPZW(CMPGT, cmpgt)
3073DO_PPZW(CMPGE, cmpge)
3074DO_PPZW(CMPHI, cmphi)
3075DO_PPZW(CMPHS, cmphs)
3076DO_PPZW(CMPLT, cmplt)
3077DO_PPZW(CMPLE, cmple)
3078DO_PPZW(CMPLO, cmplo)
3079DO_PPZW(CMPLS, cmpls)
3080
3081#undef DO_PPZW
3082
38cadeba
RH
3083/*
3084 *** SVE Integer Compare - Immediate Groups
3085 */
3086
3087static bool do_ppzi_flags(DisasContext *s, arg_rpri_esz *a,
3088 gen_helper_gvec_flags_3 *gen_fn)
3089{
3090 TCGv_ptr pd, zn, pg;
3091 unsigned vsz;
3092 TCGv_i32 t;
3093
3094 if (gen_fn == NULL) {
3095 return false;
3096 }
3097 if (!sve_access_check(s)) {
3098 return true;
3099 }
3100
3101 vsz = vec_full_reg_size(s);
392acacc 3102 t = tcg_temp_new_i32();
38cadeba
RH
3103 pd = tcg_temp_new_ptr();
3104 zn = tcg_temp_new_ptr();
3105 pg = tcg_temp_new_ptr();
3106
3107 tcg_gen_addi_ptr(pd, cpu_env, pred_full_reg_offset(s, a->rd));
3108 tcg_gen_addi_ptr(zn, cpu_env, vec_full_reg_offset(s, a->rn));
3109 tcg_gen_addi_ptr(pg, cpu_env, pred_full_reg_offset(s, a->pg));
3110
392acacc 3111 gen_fn(t, pd, zn, pg, tcg_constant_i32(simd_desc(vsz, vsz, a->imm)));
38cadeba
RH
3112
3113 tcg_temp_free_ptr(pd);
3114 tcg_temp_free_ptr(zn);
3115 tcg_temp_free_ptr(pg);
3116
3117 do_pred_flags(t);
3118
3119 tcg_temp_free_i32(t);
3120 return true;
3121}
3122
3123#define DO_PPZI(NAME, name) \
3a7be554 3124static bool trans_##NAME##_ppzi(DisasContext *s, arg_rpri_esz *a) \
38cadeba
RH
3125{ \
3126 static gen_helper_gvec_flags_3 * const fns[4] = { \
3127 gen_helper_sve_##name##_ppzi_b, gen_helper_sve_##name##_ppzi_h, \
3128 gen_helper_sve_##name##_ppzi_s, gen_helper_sve_##name##_ppzi_d, \
3129 }; \
3130 return do_ppzi_flags(s, a, fns[a->esz]); \
3131}
3132
3133DO_PPZI(CMPEQ, cmpeq)
3134DO_PPZI(CMPNE, cmpne)
3135DO_PPZI(CMPGT, cmpgt)
3136DO_PPZI(CMPGE, cmpge)
3137DO_PPZI(CMPHI, cmphi)
3138DO_PPZI(CMPHS, cmphs)
3139DO_PPZI(CMPLT, cmplt)
3140DO_PPZI(CMPLE, cmple)
3141DO_PPZI(CMPLO, cmplo)
3142DO_PPZI(CMPLS, cmpls)
3143
3144#undef DO_PPZI
3145
35da316f
RH
3146/*
3147 *** SVE Partition Break Group
3148 */
3149
3150static bool do_brk3(DisasContext *s, arg_rprr_s *a,
3151 gen_helper_gvec_4 *fn, gen_helper_gvec_flags_4 *fn_s)
3152{
3153 if (!sve_access_check(s)) {
3154 return true;
3155 }
3156
3157 unsigned vsz = pred_full_reg_size(s);
3158
3159 /* Predicate sizes may be smaller and cannot use simd_desc. */
3160 TCGv_ptr d = tcg_temp_new_ptr();
3161 TCGv_ptr n = tcg_temp_new_ptr();
3162 TCGv_ptr m = tcg_temp_new_ptr();
3163 TCGv_ptr g = tcg_temp_new_ptr();
93418f1c 3164 TCGv_i32 desc = tcg_constant_i32(FIELD_DP32(0, PREDDESC, OPRSZ, vsz));
35da316f
RH
3165
3166 tcg_gen_addi_ptr(d, cpu_env, pred_full_reg_offset(s, a->rd));
3167 tcg_gen_addi_ptr(n, cpu_env, pred_full_reg_offset(s, a->rn));
3168 tcg_gen_addi_ptr(m, cpu_env, pred_full_reg_offset(s, a->rm));
3169 tcg_gen_addi_ptr(g, cpu_env, pred_full_reg_offset(s, a->pg));
3170
3171 if (a->s) {
93418f1c
RH
3172 TCGv_i32 t = tcg_temp_new_i32();
3173 fn_s(t, d, n, m, g, desc);
35da316f 3174 do_pred_flags(t);
93418f1c 3175 tcg_temp_free_i32(t);
35da316f 3176 } else {
93418f1c 3177 fn(d, n, m, g, desc);
35da316f
RH
3178 }
3179 tcg_temp_free_ptr(d);
3180 tcg_temp_free_ptr(n);
3181 tcg_temp_free_ptr(m);
3182 tcg_temp_free_ptr(g);
35da316f
RH
3183 return true;
3184}
3185
3186static bool do_brk2(DisasContext *s, arg_rpr_s *a,
3187 gen_helper_gvec_3 *fn, gen_helper_gvec_flags_3 *fn_s)
3188{
3189 if (!sve_access_check(s)) {
3190 return true;
3191 }
3192
3193 unsigned vsz = pred_full_reg_size(s);
3194
3195 /* Predicate sizes may be smaller and cannot use simd_desc. */
3196 TCGv_ptr d = tcg_temp_new_ptr();
3197 TCGv_ptr n = tcg_temp_new_ptr();
3198 TCGv_ptr g = tcg_temp_new_ptr();
93418f1c 3199 TCGv_i32 desc = tcg_constant_i32(FIELD_DP32(0, PREDDESC, OPRSZ, vsz));
35da316f
RH
3200
3201 tcg_gen_addi_ptr(d, cpu_env, pred_full_reg_offset(s, a->rd));
3202 tcg_gen_addi_ptr(n, cpu_env, pred_full_reg_offset(s, a->rn));
3203 tcg_gen_addi_ptr(g, cpu_env, pred_full_reg_offset(s, a->pg));
3204
3205 if (a->s) {
93418f1c
RH
3206 TCGv_i32 t = tcg_temp_new_i32();
3207 fn_s(t, d, n, g, desc);
35da316f 3208 do_pred_flags(t);
93418f1c 3209 tcg_temp_free_i32(t);
35da316f 3210 } else {
93418f1c 3211 fn(d, n, g, desc);
35da316f
RH
3212 }
3213 tcg_temp_free_ptr(d);
3214 tcg_temp_free_ptr(n);
3215 tcg_temp_free_ptr(g);
35da316f
RH
3216 return true;
3217}
3218
3a7be554 3219static bool trans_BRKPA(DisasContext *s, arg_rprr_s *a)
35da316f
RH
3220{
3221 return do_brk3(s, a, gen_helper_sve_brkpa, gen_helper_sve_brkpas);
3222}
3223
3a7be554 3224static bool trans_BRKPB(DisasContext *s, arg_rprr_s *a)
35da316f
RH
3225{
3226 return do_brk3(s, a, gen_helper_sve_brkpb, gen_helper_sve_brkpbs);
3227}
3228
3a7be554 3229static bool trans_BRKA_m(DisasContext *s, arg_rpr_s *a)
35da316f
RH
3230{
3231 return do_brk2(s, a, gen_helper_sve_brka_m, gen_helper_sve_brkas_m);
3232}
3233
3a7be554 3234static bool trans_BRKB_m(DisasContext *s, arg_rpr_s *a)
35da316f
RH
3235{
3236 return do_brk2(s, a, gen_helper_sve_brkb_m, gen_helper_sve_brkbs_m);
3237}
3238
3a7be554 3239static bool trans_BRKA_z(DisasContext *s, arg_rpr_s *a)
35da316f
RH
3240{
3241 return do_brk2(s, a, gen_helper_sve_brka_z, gen_helper_sve_brkas_z);
3242}
3243
3a7be554 3244static bool trans_BRKB_z(DisasContext *s, arg_rpr_s *a)
35da316f
RH
3245{
3246 return do_brk2(s, a, gen_helper_sve_brkb_z, gen_helper_sve_brkbs_z);
3247}
3248
3a7be554 3249static bool trans_BRKN(DisasContext *s, arg_rpr_s *a)
35da316f
RH
3250{
3251 return do_brk2(s, a, gen_helper_sve_brkn, gen_helper_sve_brkns);
3252}
3253
9ee3a611
RH
3254/*
3255 *** SVE Predicate Count Group
3256 */
3257
3258static void do_cntp(DisasContext *s, TCGv_i64 val, int esz, int pn, int pg)
3259{
3260 unsigned psz = pred_full_reg_size(s);
3261
3262 if (psz <= 8) {
3263 uint64_t psz_mask;
3264
3265 tcg_gen_ld_i64(val, cpu_env, pred_full_reg_offset(s, pn));
3266 if (pn != pg) {
3267 TCGv_i64 g = tcg_temp_new_i64();
3268 tcg_gen_ld_i64(g, cpu_env, pred_full_reg_offset(s, pg));
3269 tcg_gen_and_i64(val, val, g);
3270 tcg_temp_free_i64(g);
3271 }
3272
3273 /* Reduce the pred_esz_masks value simply to reduce the
3274 * size of the code generated here.
3275 */
3276 psz_mask = MAKE_64BIT_MASK(0, psz * 8);
3277 tcg_gen_andi_i64(val, val, pred_esz_masks[esz] & psz_mask);
3278
3279 tcg_gen_ctpop_i64(val, val);
3280 } else {
3281 TCGv_ptr t_pn = tcg_temp_new_ptr();
3282 TCGv_ptr t_pg = tcg_temp_new_ptr();
f556a201 3283 unsigned desc = 0;
9ee3a611 3284
f556a201
RH
3285 desc = FIELD_DP32(desc, PREDDESC, OPRSZ, psz);
3286 desc = FIELD_DP32(desc, PREDDESC, ESZ, esz);
9ee3a611
RH
3287
3288 tcg_gen_addi_ptr(t_pn, cpu_env, pred_full_reg_offset(s, pn));
3289 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, pg));
9ee3a611 3290
c6a59b55 3291 gen_helper_sve_cntp(val, t_pn, t_pg, tcg_constant_i32(desc));
9ee3a611
RH
3292 tcg_temp_free_ptr(t_pn);
3293 tcg_temp_free_ptr(t_pg);
9ee3a611
RH
3294 }
3295}
3296
3a7be554 3297static bool trans_CNTP(DisasContext *s, arg_CNTP *a)
9ee3a611
RH
3298{
3299 if (sve_access_check(s)) {
3300 do_cntp(s, cpu_reg(s, a->rd), a->esz, a->rn, a->pg);
3301 }
3302 return true;
3303}
3304
3a7be554 3305static bool trans_INCDECP_r(DisasContext *s, arg_incdec_pred *a)
9ee3a611
RH
3306{
3307 if (sve_access_check(s)) {
3308 TCGv_i64 reg = cpu_reg(s, a->rd);
3309 TCGv_i64 val = tcg_temp_new_i64();
3310
3311 do_cntp(s, val, a->esz, a->pg, a->pg);
3312 if (a->d) {
3313 tcg_gen_sub_i64(reg, reg, val);
3314 } else {
3315 tcg_gen_add_i64(reg, reg, val);
3316 }
3317 tcg_temp_free_i64(val);
3318 }
3319 return true;
3320}
3321
3a7be554 3322static bool trans_INCDECP_z(DisasContext *s, arg_incdec2_pred *a)
9ee3a611
RH
3323{
3324 if (a->esz == 0) {
3325 return false;
3326 }
3327 if (sve_access_check(s)) {
3328 unsigned vsz = vec_full_reg_size(s);
3329 TCGv_i64 val = tcg_temp_new_i64();
3330 GVecGen2sFn *gvec_fn = a->d ? tcg_gen_gvec_subs : tcg_gen_gvec_adds;
3331
3332 do_cntp(s, val, a->esz, a->pg, a->pg);
3333 gvec_fn(a->esz, vec_full_reg_offset(s, a->rd),
3334 vec_full_reg_offset(s, a->rn), val, vsz, vsz);
3335 }
3336 return true;
3337}
3338
3a7be554 3339static bool trans_SINCDECP_r_32(DisasContext *s, arg_incdec_pred *a)
9ee3a611
RH
3340{
3341 if (sve_access_check(s)) {
3342 TCGv_i64 reg = cpu_reg(s, a->rd);
3343 TCGv_i64 val = tcg_temp_new_i64();
3344
3345 do_cntp(s, val, a->esz, a->pg, a->pg);
3346 do_sat_addsub_32(reg, val, a->u, a->d);
3347 }
3348 return true;
3349}
3350
3a7be554 3351static bool trans_SINCDECP_r_64(DisasContext *s, arg_incdec_pred *a)
9ee3a611
RH
3352{
3353 if (sve_access_check(s)) {
3354 TCGv_i64 reg = cpu_reg(s, a->rd);
3355 TCGv_i64 val = tcg_temp_new_i64();
3356
3357 do_cntp(s, val, a->esz, a->pg, a->pg);
3358 do_sat_addsub_64(reg, val, a->u, a->d);
3359 }
3360 return true;
3361}
3362
3a7be554 3363static bool trans_SINCDECP_z(DisasContext *s, arg_incdec2_pred *a)
9ee3a611
RH
3364{
3365 if (a->esz == 0) {
3366 return false;
3367 }
3368 if (sve_access_check(s)) {
3369 TCGv_i64 val = tcg_temp_new_i64();
3370 do_cntp(s, val, a->esz, a->pg, a->pg);
3371 do_sat_addsub_vec(s, a->esz, a->rd, a->rn, val, a->u, a->d);
3372 }
3373 return true;
3374}
3375
caf1cefc
RH
3376/*
3377 *** SVE Integer Compare Scalars Group
3378 */
3379
3a7be554 3380static bool trans_CTERM(DisasContext *s, arg_CTERM *a)
caf1cefc
RH
3381{
3382 if (!sve_access_check(s)) {
3383 return true;
3384 }
3385
3386 TCGCond cond = (a->ne ? TCG_COND_NE : TCG_COND_EQ);
3387 TCGv_i64 rn = read_cpu_reg(s, a->rn, a->sf);
3388 TCGv_i64 rm = read_cpu_reg(s, a->rm, a->sf);
3389 TCGv_i64 cmp = tcg_temp_new_i64();
3390
3391 tcg_gen_setcond_i64(cond, cmp, rn, rm);
3392 tcg_gen_extrl_i64_i32(cpu_NF, cmp);
3393 tcg_temp_free_i64(cmp);
3394
3395 /* VF = !NF & !CF. */
3396 tcg_gen_xori_i32(cpu_VF, cpu_NF, 1);
3397 tcg_gen_andc_i32(cpu_VF, cpu_VF, cpu_CF);
3398
3399 /* Both NF and VF actually look at bit 31. */
3400 tcg_gen_neg_i32(cpu_NF, cpu_NF);
3401 tcg_gen_neg_i32(cpu_VF, cpu_VF);
3402 return true;
3403}
3404
3a7be554 3405static bool trans_WHILE(DisasContext *s, arg_WHILE *a)
caf1cefc 3406{
bbd0968c 3407 TCGv_i64 op0, op1, t0, t1, tmax;
4481bbf2 3408 TCGv_i32 t2;
caf1cefc 3409 TCGv_ptr ptr;
e610906c
RH
3410 unsigned vsz = vec_full_reg_size(s);
3411 unsigned desc = 0;
caf1cefc 3412 TCGCond cond;
34688dbc
RH
3413 uint64_t maxval;
3414 /* Note that GE/HS has a->eq == 0 and GT/HI has a->eq == 1. */
3415 bool eq = a->eq == a->lt;
caf1cefc 3416
34688dbc
RH
3417 /* The greater-than conditions are all SVE2. */
3418 if (!a->lt && !dc_isar_feature(aa64_sve2, s)) {
3419 return false;
3420 }
bbd0968c
RH
3421 if (!sve_access_check(s)) {
3422 return true;
3423 }
3424
3425 op0 = read_cpu_reg(s, a->rn, 1);
3426 op1 = read_cpu_reg(s, a->rm, 1);
3427
caf1cefc
RH
3428 if (!a->sf) {
3429 if (a->u) {
3430 tcg_gen_ext32u_i64(op0, op0);
3431 tcg_gen_ext32u_i64(op1, op1);
3432 } else {
3433 tcg_gen_ext32s_i64(op0, op0);
3434 tcg_gen_ext32s_i64(op1, op1);
3435 }
3436 }
3437
3438 /* For the helper, compress the different conditions into a computation
3439 * of how many iterations for which the condition is true.
caf1cefc 3440 */
bbd0968c
RH
3441 t0 = tcg_temp_new_i64();
3442 t1 = tcg_temp_new_i64();
34688dbc
RH
3443
3444 if (a->lt) {
3445 tcg_gen_sub_i64(t0, op1, op0);
3446 if (a->u) {
3447 maxval = a->sf ? UINT64_MAX : UINT32_MAX;
3448 cond = eq ? TCG_COND_LEU : TCG_COND_LTU;
3449 } else {
3450 maxval = a->sf ? INT64_MAX : INT32_MAX;
3451 cond = eq ? TCG_COND_LE : TCG_COND_LT;
3452 }
3453 } else {
3454 tcg_gen_sub_i64(t0, op0, op1);
3455 if (a->u) {
3456 maxval = 0;
3457 cond = eq ? TCG_COND_GEU : TCG_COND_GTU;
3458 } else {
3459 maxval = a->sf ? INT64_MIN : INT32_MIN;
3460 cond = eq ? TCG_COND_GE : TCG_COND_GT;
3461 }
3462 }
caf1cefc 3463
4481bbf2 3464 tmax = tcg_constant_i64(vsz >> a->esz);
34688dbc 3465 if (eq) {
caf1cefc
RH
3466 /* Equality means one more iteration. */
3467 tcg_gen_addi_i64(t0, t0, 1);
bbd0968c 3468
34688dbc
RH
3469 /*
3470 * For the less-than while, if op1 is maxval (and the only time
3471 * the addition above could overflow), then we produce an all-true
3472 * predicate by setting the count to the vector length. This is
3473 * because the pseudocode is described as an increment + compare
3474 * loop, and the maximum integer would always compare true.
3475 * Similarly, the greater-than while has the same issue with the
3476 * minimum integer due to the decrement + compare loop.
bbd0968c 3477 */
34688dbc 3478 tcg_gen_movi_i64(t1, maxval);
bbd0968c 3479 tcg_gen_movcond_i64(TCG_COND_EQ, t0, op1, t1, tmax, t0);
caf1cefc
RH
3480 }
3481
bbd0968c
RH
3482 /* Bound to the maximum. */
3483 tcg_gen_umin_i64(t0, t0, tmax);
bbd0968c
RH
3484
3485 /* Set the count to zero if the condition is false. */
caf1cefc
RH
3486 tcg_gen_movi_i64(t1, 0);
3487 tcg_gen_movcond_i64(cond, t0, op0, op1, t0, t1);
bbd0968c 3488 tcg_temp_free_i64(t1);
caf1cefc 3489
bbd0968c 3490 /* Since we're bounded, pass as a 32-bit type. */
caf1cefc
RH
3491 t2 = tcg_temp_new_i32();
3492 tcg_gen_extrl_i64_i32(t2, t0);
3493 tcg_temp_free_i64(t0);
bbd0968c
RH
3494
3495 /* Scale elements to bits. */
3496 tcg_gen_shli_i32(t2, t2, a->esz);
caf1cefc 3497
e610906c
RH
3498 desc = FIELD_DP32(desc, PREDDESC, OPRSZ, vsz / 8);
3499 desc = FIELD_DP32(desc, PREDDESC, ESZ, a->esz);
caf1cefc
RH
3500
3501 ptr = tcg_temp_new_ptr();
3502 tcg_gen_addi_ptr(ptr, cpu_env, pred_full_reg_offset(s, a->rd));
3503
34688dbc 3504 if (a->lt) {
4481bbf2 3505 gen_helper_sve_whilel(t2, ptr, t2, tcg_constant_i32(desc));
34688dbc 3506 } else {
4481bbf2 3507 gen_helper_sve_whileg(t2, ptr, t2, tcg_constant_i32(desc));
34688dbc 3508 }
caf1cefc
RH
3509 do_pred_flags(t2);
3510
3511 tcg_temp_free_ptr(ptr);
3512 tcg_temp_free_i32(t2);
caf1cefc
RH
3513 return true;
3514}
3515
14f6dad1
RH
3516static bool trans_WHILE_ptr(DisasContext *s, arg_WHILE_ptr *a)
3517{
3518 TCGv_i64 op0, op1, diff, t1, tmax;
4481bbf2 3519 TCGv_i32 t2;
14f6dad1
RH
3520 TCGv_ptr ptr;
3521 unsigned vsz = vec_full_reg_size(s);
3522 unsigned desc = 0;
3523
3524 if (!dc_isar_feature(aa64_sve2, s)) {
3525 return false;
3526 }
3527 if (!sve_access_check(s)) {
3528 return true;
3529 }
3530
3531 op0 = read_cpu_reg(s, a->rn, 1);
3532 op1 = read_cpu_reg(s, a->rm, 1);
3533
4481bbf2 3534 tmax = tcg_constant_i64(vsz);
14f6dad1
RH
3535 diff = tcg_temp_new_i64();
3536
3537 if (a->rw) {
3538 /* WHILERW */
3539 /* diff = abs(op1 - op0), noting that op0/1 are unsigned. */
3540 t1 = tcg_temp_new_i64();
3541 tcg_gen_sub_i64(diff, op0, op1);
3542 tcg_gen_sub_i64(t1, op1, op0);
3543 tcg_gen_movcond_i64(TCG_COND_GEU, diff, op0, op1, diff, t1);
3544 tcg_temp_free_i64(t1);
3545 /* Round down to a multiple of ESIZE. */
3546 tcg_gen_andi_i64(diff, diff, -1 << a->esz);
3547 /* If op1 == op0, diff == 0, and the condition is always true. */
3548 tcg_gen_movcond_i64(TCG_COND_EQ, diff, op0, op1, tmax, diff);
3549 } else {
3550 /* WHILEWR */
3551 tcg_gen_sub_i64(diff, op1, op0);
3552 /* Round down to a multiple of ESIZE. */
3553 tcg_gen_andi_i64(diff, diff, -1 << a->esz);
3554 /* If op0 >= op1, diff <= 0, the condition is always true. */
3555 tcg_gen_movcond_i64(TCG_COND_GEU, diff, op0, op1, tmax, diff);
3556 }
3557
3558 /* Bound to the maximum. */
3559 tcg_gen_umin_i64(diff, diff, tmax);
14f6dad1
RH
3560
3561 /* Since we're bounded, pass as a 32-bit type. */
3562 t2 = tcg_temp_new_i32();
3563 tcg_gen_extrl_i64_i32(t2, diff);
3564 tcg_temp_free_i64(diff);
3565
3566 desc = FIELD_DP32(desc, PREDDESC, OPRSZ, vsz / 8);
3567 desc = FIELD_DP32(desc, PREDDESC, ESZ, a->esz);
14f6dad1
RH
3568
3569 ptr = tcg_temp_new_ptr();
3570 tcg_gen_addi_ptr(ptr, cpu_env, pred_full_reg_offset(s, a->rd));
3571
4481bbf2 3572 gen_helper_sve_whilel(t2, ptr, t2, tcg_constant_i32(desc));
14f6dad1
RH
3573 do_pred_flags(t2);
3574
3575 tcg_temp_free_ptr(ptr);
3576 tcg_temp_free_i32(t2);
14f6dad1
RH
3577 return true;
3578}
3579
ed491961
RH
3580/*
3581 *** SVE Integer Wide Immediate - Unpredicated Group
3582 */
3583
3a7be554 3584static bool trans_FDUP(DisasContext *s, arg_FDUP *a)
ed491961
RH
3585{
3586 if (a->esz == 0) {
3587 return false;
3588 }
3589 if (sve_access_check(s)) {
3590 unsigned vsz = vec_full_reg_size(s);
3591 int dofs = vec_full_reg_offset(s, a->rd);
3592 uint64_t imm;
3593
3594 /* Decode the VFP immediate. */
3595 imm = vfp_expand_imm(a->esz, a->imm);
8711e71f 3596 tcg_gen_gvec_dup_imm(a->esz, dofs, vsz, vsz, imm);
ed491961
RH
3597 }
3598 return true;
3599}
3600
3a7be554 3601static bool trans_DUP_i(DisasContext *s, arg_DUP_i *a)
ed491961 3602{
3a7be554 3603 if (a->esz == 0 && extract32(s->insn, 13, 1)) {
ed491961
RH
3604 return false;
3605 }
3606 if (sve_access_check(s)) {
3607 unsigned vsz = vec_full_reg_size(s);
3608 int dofs = vec_full_reg_offset(s, a->rd);
3609
8711e71f 3610 tcg_gen_gvec_dup_imm(a->esz, dofs, vsz, vsz, a->imm);
ed491961
RH
3611 }
3612 return true;
3613}
3614
3a7be554 3615static bool trans_ADD_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d 3616{
3a7be554 3617 if (a->esz == 0 && extract32(s->insn, 13, 1)) {
6e6a157d
RH
3618 return false;
3619 }
3620 if (sve_access_check(s)) {
3621 unsigned vsz = vec_full_reg_size(s);
3622 tcg_gen_gvec_addi(a->esz, vec_full_reg_offset(s, a->rd),
3623 vec_full_reg_offset(s, a->rn), a->imm, vsz, vsz);
3624 }
3625 return true;
3626}
3627
3a7be554 3628static bool trans_SUB_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d
RH
3629{
3630 a->imm = -a->imm;
3a7be554 3631 return trans_ADD_zzi(s, a);
6e6a157d
RH
3632}
3633
3a7be554 3634static bool trans_SUBR_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d 3635{
53229a77 3636 static const TCGOpcode vecop_list[] = { INDEX_op_sub_vec, 0 };
6e6a157d
RH
3637 static const GVecGen2s op[4] = {
3638 { .fni8 = tcg_gen_vec_sub8_i64,
3639 .fniv = tcg_gen_sub_vec,
3640 .fno = gen_helper_sve_subri_b,
53229a77 3641 .opt_opc = vecop_list,
6e6a157d
RH
3642 .vece = MO_8,
3643 .scalar_first = true },
3644 { .fni8 = tcg_gen_vec_sub16_i64,
3645 .fniv = tcg_gen_sub_vec,
3646 .fno = gen_helper_sve_subri_h,
53229a77 3647 .opt_opc = vecop_list,
6e6a157d
RH
3648 .vece = MO_16,
3649 .scalar_first = true },
3650 { .fni4 = tcg_gen_sub_i32,
3651 .fniv = tcg_gen_sub_vec,
3652 .fno = gen_helper_sve_subri_s,
53229a77 3653 .opt_opc = vecop_list,
6e6a157d
RH
3654 .vece = MO_32,
3655 .scalar_first = true },
3656 { .fni8 = tcg_gen_sub_i64,
3657 .fniv = tcg_gen_sub_vec,
3658 .fno = gen_helper_sve_subri_d,
53229a77 3659 .opt_opc = vecop_list,
6e6a157d
RH
3660 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3661 .vece = MO_64,
3662 .scalar_first = true }
3663 };
3664
3a7be554 3665 if (a->esz == 0 && extract32(s->insn, 13, 1)) {
6e6a157d
RH
3666 return false;
3667 }
3668 if (sve_access_check(s)) {
3669 unsigned vsz = vec_full_reg_size(s);
6e6a157d
RH
3670 tcg_gen_gvec_2s(vec_full_reg_offset(s, a->rd),
3671 vec_full_reg_offset(s, a->rn),
9fff3fcc 3672 vsz, vsz, tcg_constant_i64(a->imm), &op[a->esz]);
6e6a157d
RH
3673 }
3674 return true;
3675}
3676
3a7be554 3677static bool trans_MUL_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d
RH
3678{
3679 if (sve_access_check(s)) {
3680 unsigned vsz = vec_full_reg_size(s);
3681 tcg_gen_gvec_muli(a->esz, vec_full_reg_offset(s, a->rd),
3682 vec_full_reg_offset(s, a->rn), a->imm, vsz, vsz);
3683 }
3684 return true;
3685}
3686
3a7be554 3687static bool do_zzi_sat(DisasContext *s, arg_rri_esz *a, bool u, bool d)
6e6a157d 3688{
3a7be554 3689 if (a->esz == 0 && extract32(s->insn, 13, 1)) {
6e6a157d
RH
3690 return false;
3691 }
3692 if (sve_access_check(s)) {
138a1f7b
RH
3693 do_sat_addsub_vec(s, a->esz, a->rd, a->rn,
3694 tcg_constant_i64(a->imm), u, d);
6e6a157d
RH
3695 }
3696 return true;
3697}
3698
3a7be554 3699static bool trans_SQADD_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d 3700{
3a7be554 3701 return do_zzi_sat(s, a, false, false);
6e6a157d
RH
3702}
3703
3a7be554 3704static bool trans_UQADD_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d 3705{
3a7be554 3706 return do_zzi_sat(s, a, true, false);
6e6a157d
RH
3707}
3708
3a7be554 3709static bool trans_SQSUB_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d 3710{
3a7be554 3711 return do_zzi_sat(s, a, false, true);
6e6a157d
RH
3712}
3713
3a7be554 3714static bool trans_UQSUB_zzi(DisasContext *s, arg_rri_esz *a)
6e6a157d 3715{
3a7be554 3716 return do_zzi_sat(s, a, true, true);
6e6a157d
RH
3717}
3718
3719static bool do_zzi_ool(DisasContext *s, arg_rri_esz *a, gen_helper_gvec_2i *fn)
3720{
3721 if (sve_access_check(s)) {
3722 unsigned vsz = vec_full_reg_size(s);
6e6a157d
RH
3723 tcg_gen_gvec_2i_ool(vec_full_reg_offset(s, a->rd),
3724 vec_full_reg_offset(s, a->rn),
138a1f7b 3725 tcg_constant_i64(a->imm), vsz, vsz, 0, fn);
6e6a157d
RH
3726 }
3727 return true;
3728}
3729
3730#define DO_ZZI(NAME, name) \
3a7be554 3731static bool trans_##NAME##_zzi(DisasContext *s, arg_rri_esz *a) \
6e6a157d
RH
3732{ \
3733 static gen_helper_gvec_2i * const fns[4] = { \
3734 gen_helper_sve_##name##i_b, gen_helper_sve_##name##i_h, \
3735 gen_helper_sve_##name##i_s, gen_helper_sve_##name##i_d, \
3736 }; \
3737 return do_zzi_ool(s, a, fns[a->esz]); \
3738}
3739
3740DO_ZZI(SMAX, smax)
3741DO_ZZI(UMAX, umax)
3742DO_ZZI(SMIN, smin)
3743DO_ZZI(UMIN, umin)
3744
3745#undef DO_ZZI
3746
5f425b92
RH
3747static gen_helper_gvec_4 * const dot_fns[2][2] = {
3748 { gen_helper_gvec_sdot_b, gen_helper_gvec_sdot_h },
3749 { gen_helper_gvec_udot_b, gen_helper_gvec_udot_h }
3750};
3751TRANS_FEAT(DOT_zzzz, aa64_sve, gen_gvec_ool_zzzz,
3752 dot_fns[a->u][a->sz], a->rd, a->rn, a->rm, a->ra, 0)
d730ecaa 3753
814d4c52
RH
3754/*
3755 * SVE Multiply - Indexed
3756 */
3757
f3500a25
RH
3758TRANS_FEAT(SDOT_zzxw_s, aa64_sve, gen_gvec_ool_arg_zzxz,
3759 gen_helper_gvec_sdot_idx_b, a)
3760TRANS_FEAT(SDOT_zzxw_d, aa64_sve, gen_gvec_ool_arg_zzxz,
3761 gen_helper_gvec_sdot_idx_h, a)
3762TRANS_FEAT(UDOT_zzxw_s, aa64_sve, gen_gvec_ool_arg_zzxz,
3763 gen_helper_gvec_udot_idx_b, a)
3764TRANS_FEAT(UDOT_zzxw_d, aa64_sve, gen_gvec_ool_arg_zzxz,
3765 gen_helper_gvec_udot_idx_h, a)
3766
3767TRANS_FEAT(SUDOT_zzxw_s, aa64_sve_i8mm, gen_gvec_ool_arg_zzxz,
3768 gen_helper_gvec_sudot_idx_b, a)
3769TRANS_FEAT(USDOT_zzxw_s, aa64_sve_i8mm, gen_gvec_ool_arg_zzxz,
3770 gen_helper_gvec_usdot_idx_b, a)
16fcfdc7 3771
814d4c52 3772#define DO_SVE2_RRX(NAME, FUNC) \
af031f64
RH
3773 TRANS_FEAT(NAME, aa64_sve, gen_gvec_ool_zzz, FUNC, \
3774 a->rd, a->rn, a->rm, a->index)
814d4c52 3775
af031f64
RH
3776DO_SVE2_RRX(MUL_zzx_h, gen_helper_gvec_mul_idx_h)
3777DO_SVE2_RRX(MUL_zzx_s, gen_helper_gvec_mul_idx_s)
3778DO_SVE2_RRX(MUL_zzx_d, gen_helper_gvec_mul_idx_d)
814d4c52 3779
af031f64
RH
3780DO_SVE2_RRX(SQDMULH_zzx_h, gen_helper_sve2_sqdmulh_idx_h)
3781DO_SVE2_RRX(SQDMULH_zzx_s, gen_helper_sve2_sqdmulh_idx_s)
3782DO_SVE2_RRX(SQDMULH_zzx_d, gen_helper_sve2_sqdmulh_idx_d)
1aee2d70 3783
af031f64
RH
3784DO_SVE2_RRX(SQRDMULH_zzx_h, gen_helper_sve2_sqrdmulh_idx_h)
3785DO_SVE2_RRX(SQRDMULH_zzx_s, gen_helper_sve2_sqrdmulh_idx_s)
3786DO_SVE2_RRX(SQRDMULH_zzx_d, gen_helper_sve2_sqrdmulh_idx_d)
1aee2d70 3787
814d4c52
RH
3788#undef DO_SVE2_RRX
3789
b95f5eeb 3790#define DO_SVE2_RRX_TB(NAME, FUNC, TOP) \
af031f64
RH
3791 TRANS_FEAT(NAME, aa64_sve, gen_gvec_ool_zzz, FUNC, \
3792 a->rd, a->rn, a->rm, (a->index << 1) | TOP)
3793
3794DO_SVE2_RRX_TB(SQDMULLB_zzx_s, gen_helper_sve2_sqdmull_idx_s, false)
3795DO_SVE2_RRX_TB(SQDMULLB_zzx_d, gen_helper_sve2_sqdmull_idx_d, false)
3796DO_SVE2_RRX_TB(SQDMULLT_zzx_s, gen_helper_sve2_sqdmull_idx_s, true)
3797DO_SVE2_RRX_TB(SQDMULLT_zzx_d, gen_helper_sve2_sqdmull_idx_d, true)
3798
3799DO_SVE2_RRX_TB(SMULLB_zzx_s, gen_helper_sve2_smull_idx_s, false)
3800DO_SVE2_RRX_TB(SMULLB_zzx_d, gen_helper_sve2_smull_idx_d, false)
3801DO_SVE2_RRX_TB(SMULLT_zzx_s, gen_helper_sve2_smull_idx_s, true)
3802DO_SVE2_RRX_TB(SMULLT_zzx_d, gen_helper_sve2_smull_idx_d, true)
3803
3804DO_SVE2_RRX_TB(UMULLB_zzx_s, gen_helper_sve2_umull_idx_s, false)
3805DO_SVE2_RRX_TB(UMULLB_zzx_d, gen_helper_sve2_umull_idx_d, false)
3806DO_SVE2_RRX_TB(UMULLT_zzx_s, gen_helper_sve2_umull_idx_s, true)
3807DO_SVE2_RRX_TB(UMULLT_zzx_d, gen_helper_sve2_umull_idx_d, true)
d3949c4c 3808
b95f5eeb
RH
3809#undef DO_SVE2_RRX_TB
3810
8a02aac7 3811#define DO_SVE2_RRXR(NAME, FUNC) \
8681eb76 3812 TRANS_FEAT(NAME, aa64_sve2, gen_gvec_ool_arg_zzxz, FUNC, a)
8a02aac7 3813
8681eb76
RH
3814DO_SVE2_RRXR(MLA_zzxz_h, gen_helper_gvec_mla_idx_h)
3815DO_SVE2_RRXR(MLA_zzxz_s, gen_helper_gvec_mla_idx_s)
3816DO_SVE2_RRXR(MLA_zzxz_d, gen_helper_gvec_mla_idx_d)
8a02aac7 3817
8681eb76
RH
3818DO_SVE2_RRXR(MLS_zzxz_h, gen_helper_gvec_mls_idx_h)
3819DO_SVE2_RRXR(MLS_zzxz_s, gen_helper_gvec_mls_idx_s)
3820DO_SVE2_RRXR(MLS_zzxz_d, gen_helper_gvec_mls_idx_d)
8a02aac7 3821
8681eb76
RH
3822DO_SVE2_RRXR(SQRDMLAH_zzxz_h, gen_helper_sve2_sqrdmlah_idx_h)
3823DO_SVE2_RRXR(SQRDMLAH_zzxz_s, gen_helper_sve2_sqrdmlah_idx_s)
3824DO_SVE2_RRXR(SQRDMLAH_zzxz_d, gen_helper_sve2_sqrdmlah_idx_d)
75d6d5fc 3825
8681eb76
RH
3826DO_SVE2_RRXR(SQRDMLSH_zzxz_h, gen_helper_sve2_sqrdmlsh_idx_h)
3827DO_SVE2_RRXR(SQRDMLSH_zzxz_s, gen_helper_sve2_sqrdmlsh_idx_s)
3828DO_SVE2_RRXR(SQRDMLSH_zzxz_d, gen_helper_sve2_sqrdmlsh_idx_d)
75d6d5fc 3829
8a02aac7
RH
3830#undef DO_SVE2_RRXR
3831
c5c455d7 3832#define DO_SVE2_RRXR_TB(NAME, FUNC, TOP) \
8681eb76
RH
3833 TRANS_FEAT(NAME, aa64_sve2, gen_gvec_ool_zzzz, FUNC, \
3834 a->rd, a->rn, a->rm, a->ra, (a->index << 1) | TOP)
3835
3836DO_SVE2_RRXR_TB(SQDMLALB_zzxw_s, gen_helper_sve2_sqdmlal_idx_s, false)
3837DO_SVE2_RRXR_TB(SQDMLALB_zzxw_d, gen_helper_sve2_sqdmlal_idx_d, false)
3838DO_SVE2_RRXR_TB(SQDMLALT_zzxw_s, gen_helper_sve2_sqdmlal_idx_s, true)
3839DO_SVE2_RRXR_TB(SQDMLALT_zzxw_d, gen_helper_sve2_sqdmlal_idx_d, true)
3840
3841DO_SVE2_RRXR_TB(SQDMLSLB_zzxw_s, gen_helper_sve2_sqdmlsl_idx_s, false)
3842DO_SVE2_RRXR_TB(SQDMLSLB_zzxw_d, gen_helper_sve2_sqdmlsl_idx_d, false)
3843DO_SVE2_RRXR_TB(SQDMLSLT_zzxw_s, gen_helper_sve2_sqdmlsl_idx_s, true)
3844DO_SVE2_RRXR_TB(SQDMLSLT_zzxw_d, gen_helper_sve2_sqdmlsl_idx_d, true)
3845
3846DO_SVE2_RRXR_TB(SMLALB_zzxw_s, gen_helper_sve2_smlal_idx_s, false)
3847DO_SVE2_RRXR_TB(SMLALB_zzxw_d, gen_helper_sve2_smlal_idx_d, false)
3848DO_SVE2_RRXR_TB(SMLALT_zzxw_s, gen_helper_sve2_smlal_idx_s, true)
3849DO_SVE2_RRXR_TB(SMLALT_zzxw_d, gen_helper_sve2_smlal_idx_d, true)
3850
3851DO_SVE2_RRXR_TB(UMLALB_zzxw_s, gen_helper_sve2_umlal_idx_s, false)
3852DO_SVE2_RRXR_TB(UMLALB_zzxw_d, gen_helper_sve2_umlal_idx_d, false)
3853DO_SVE2_RRXR_TB(UMLALT_zzxw_s, gen_helper_sve2_umlal_idx_s, true)
3854DO_SVE2_RRXR_TB(UMLALT_zzxw_d, gen_helper_sve2_umlal_idx_d, true)
3855
3856DO_SVE2_RRXR_TB(SMLSLB_zzxw_s, gen_helper_sve2_smlsl_idx_s, false)
3857DO_SVE2_RRXR_TB(SMLSLB_zzxw_d, gen_helper_sve2_smlsl_idx_d, false)
3858DO_SVE2_RRXR_TB(SMLSLT_zzxw_s, gen_helper_sve2_smlsl_idx_s, true)
3859DO_SVE2_RRXR_TB(SMLSLT_zzxw_d, gen_helper_sve2_smlsl_idx_d, true)
3860
3861DO_SVE2_RRXR_TB(UMLSLB_zzxw_s, gen_helper_sve2_umlsl_idx_s, false)
3862DO_SVE2_RRXR_TB(UMLSLB_zzxw_d, gen_helper_sve2_umlsl_idx_d, false)
3863DO_SVE2_RRXR_TB(UMLSLT_zzxw_s, gen_helper_sve2_umlsl_idx_s, true)
3864DO_SVE2_RRXR_TB(UMLSLT_zzxw_d, gen_helper_sve2_umlsl_idx_d, true)
c5c455d7
RH
3865
3866#undef DO_SVE2_RRXR_TB
3867
3b787ed8 3868#define DO_SVE2_RRXR_ROT(NAME, FUNC) \
8681eb76
RH
3869 TRANS_FEAT(NAME, aa64_sve2, gen_gvec_ool_zzzz, FUNC, \
3870 a->rd, a->rn, a->rm, a->ra, (a->index << 2) | a->rot)
3b787ed8
RH
3871
3872DO_SVE2_RRXR_ROT(CMLA_zzxz_h, gen_helper_sve2_cmla_idx_h)
3873DO_SVE2_RRXR_ROT(CMLA_zzxz_s, gen_helper_sve2_cmla_idx_s)
3874
3875DO_SVE2_RRXR_ROT(SQRDCMLAH_zzxz_h, gen_helper_sve2_sqrdcmlah_idx_h)
3876DO_SVE2_RRXR_ROT(SQRDCMLAH_zzxz_s, gen_helper_sve2_sqrdcmlah_idx_s)
3877
21068f39
RH
3878DO_SVE2_RRXR_ROT(CDOT_zzxw_s, gen_helper_sve2_cdot_idx_s)
3879DO_SVE2_RRXR_ROT(CDOT_zzxw_d, gen_helper_sve2_cdot_idx_d)
3880
3b787ed8
RH
3881#undef DO_SVE2_RRXR_ROT
3882
ca40a6e6
RH
3883/*
3884 *** SVE Floating Point Multiply-Add Indexed Group
3885 */
3886
0a82d963 3887static bool do_FMLA_zzxz(DisasContext *s, arg_rrxr_esz *a, bool sub)
ca40a6e6
RH
3888{
3889 static gen_helper_gvec_4_ptr * const fns[3] = {
3890 gen_helper_gvec_fmla_idx_h,
3891 gen_helper_gvec_fmla_idx_s,
3892 gen_helper_gvec_fmla_idx_d,
3893 };
3894
3895 if (sve_access_check(s)) {
3896 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 3897 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
ca40a6e6
RH
3898 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
3899 vec_full_reg_offset(s, a->rn),
3900 vec_full_reg_offset(s, a->rm),
3901 vec_full_reg_offset(s, a->ra),
0a82d963 3902 status, vsz, vsz, (a->index << 1) | sub,
ca40a6e6
RH
3903 fns[a->esz - 1]);
3904 tcg_temp_free_ptr(status);
3905 }
3906 return true;
3907}
3908
0a82d963
RH
3909static bool trans_FMLA_zzxz(DisasContext *s, arg_FMLA_zzxz *a)
3910{
3911 return do_FMLA_zzxz(s, a, false);
3912}
3913
3914static bool trans_FMLS_zzxz(DisasContext *s, arg_FMLA_zzxz *a)
3915{
3916 return do_FMLA_zzxz(s, a, true);
3917}
3918
ca40a6e6
RH
3919/*
3920 *** SVE Floating Point Multiply Indexed Group
3921 */
3922
3a7be554 3923static bool trans_FMUL_zzx(DisasContext *s, arg_FMUL_zzx *a)
ca40a6e6
RH
3924{
3925 static gen_helper_gvec_3_ptr * const fns[3] = {
3926 gen_helper_gvec_fmul_idx_h,
3927 gen_helper_gvec_fmul_idx_s,
3928 gen_helper_gvec_fmul_idx_d,
3929 };
3930
3931 if (sve_access_check(s)) {
3932 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 3933 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
ca40a6e6
RH
3934 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd),
3935 vec_full_reg_offset(s, a->rn),
3936 vec_full_reg_offset(s, a->rm),
3937 status, vsz, vsz, a->index, fns[a->esz - 1]);
3938 tcg_temp_free_ptr(status);
3939 }
3940 return true;
3941}
3942
23fbe79f
RH
3943/*
3944 *** SVE Floating Point Fast Reduction Group
3945 */
3946
3947typedef void gen_helper_fp_reduce(TCGv_i64, TCGv_ptr, TCGv_ptr,
3948 TCGv_ptr, TCGv_i32);
3949
3950static void do_reduce(DisasContext *s, arg_rpr_esz *a,
3951 gen_helper_fp_reduce *fn)
3952{
3953 unsigned vsz = vec_full_reg_size(s);
3954 unsigned p2vsz = pow2ceil(vsz);
c6a59b55 3955 TCGv_i32 t_desc = tcg_constant_i32(simd_desc(vsz, vsz, p2vsz));
23fbe79f
RH
3956 TCGv_ptr t_zn, t_pg, status;
3957 TCGv_i64 temp;
3958
3959 temp = tcg_temp_new_i64();
3960 t_zn = tcg_temp_new_ptr();
3961 t_pg = tcg_temp_new_ptr();
3962
3963 tcg_gen_addi_ptr(t_zn, cpu_env, vec_full_reg_offset(s, a->rn));
3964 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, a->pg));
cdfb22bb 3965 status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
23fbe79f
RH
3966
3967 fn(temp, t_zn, t_pg, status, t_desc);
3968 tcg_temp_free_ptr(t_zn);
3969 tcg_temp_free_ptr(t_pg);
3970 tcg_temp_free_ptr(status);
23fbe79f
RH
3971
3972 write_fp_dreg(s, a->rd, temp);
3973 tcg_temp_free_i64(temp);
3974}
3975
3976#define DO_VPZ(NAME, name) \
3a7be554 3977static bool trans_##NAME(DisasContext *s, arg_rpr_esz *a) \
23fbe79f
RH
3978{ \
3979 static gen_helper_fp_reduce * const fns[3] = { \
3980 gen_helper_sve_##name##_h, \
3981 gen_helper_sve_##name##_s, \
3982 gen_helper_sve_##name##_d, \
3983 }; \
3984 if (a->esz == 0) { \
3985 return false; \
3986 } \
3987 if (sve_access_check(s)) { \
3988 do_reduce(s, a, fns[a->esz - 1]); \
3989 } \
3990 return true; \
3991}
3992
3993DO_VPZ(FADDV, faddv)
3994DO_VPZ(FMINNMV, fminnmv)
3995DO_VPZ(FMAXNMV, fmaxnmv)
3996DO_VPZ(FMINV, fminv)
3997DO_VPZ(FMAXV, fmaxv)
3998
3887c038
RH
3999/*
4000 *** SVE Floating Point Unary Operations - Unpredicated Group
4001 */
4002
4003static void do_zz_fp(DisasContext *s, arg_rr_esz *a, gen_helper_gvec_2_ptr *fn)
4004{
4005 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4006 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
3887c038
RH
4007
4008 tcg_gen_gvec_2_ptr(vec_full_reg_offset(s, a->rd),
4009 vec_full_reg_offset(s, a->rn),
4010 status, vsz, vsz, 0, fn);
4011 tcg_temp_free_ptr(status);
4012}
4013
3a7be554 4014static bool trans_FRECPE(DisasContext *s, arg_rr_esz *a)
3887c038
RH
4015{
4016 static gen_helper_gvec_2_ptr * const fns[3] = {
4017 gen_helper_gvec_frecpe_h,
4018 gen_helper_gvec_frecpe_s,
4019 gen_helper_gvec_frecpe_d,
4020 };
4021 if (a->esz == 0) {
4022 return false;
4023 }
4024 if (sve_access_check(s)) {
4025 do_zz_fp(s, a, fns[a->esz - 1]);
4026 }
4027 return true;
4028}
4029
3a7be554 4030static bool trans_FRSQRTE(DisasContext *s, arg_rr_esz *a)
3887c038
RH
4031{
4032 static gen_helper_gvec_2_ptr * const fns[3] = {
4033 gen_helper_gvec_frsqrte_h,
4034 gen_helper_gvec_frsqrte_s,
4035 gen_helper_gvec_frsqrte_d,
4036 };
4037 if (a->esz == 0) {
4038 return false;
4039 }
4040 if (sve_access_check(s)) {
4041 do_zz_fp(s, a, fns[a->esz - 1]);
4042 }
4043 return true;
4044}
4045
4d2e2a03
RH
4046/*
4047 *** SVE Floating Point Compare with Zero Group
4048 */
4049
4050static void do_ppz_fp(DisasContext *s, arg_rpr_esz *a,
4051 gen_helper_gvec_3_ptr *fn)
4052{
4053 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4054 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
4d2e2a03
RH
4055
4056 tcg_gen_gvec_3_ptr(pred_full_reg_offset(s, a->rd),
4057 vec_full_reg_offset(s, a->rn),
4058 pred_full_reg_offset(s, a->pg),
4059 status, vsz, vsz, 0, fn);
4060 tcg_temp_free_ptr(status);
4061}
4062
4063#define DO_PPZ(NAME, name) \
3a7be554 4064static bool trans_##NAME(DisasContext *s, arg_rpr_esz *a) \
4d2e2a03
RH
4065{ \
4066 static gen_helper_gvec_3_ptr * const fns[3] = { \
4067 gen_helper_sve_##name##_h, \
4068 gen_helper_sve_##name##_s, \
4069 gen_helper_sve_##name##_d, \
4070 }; \
4071 if (a->esz == 0) { \
4072 return false; \
4073 } \
4074 if (sve_access_check(s)) { \
4075 do_ppz_fp(s, a, fns[a->esz - 1]); \
4076 } \
4077 return true; \
4078}
4079
4080DO_PPZ(FCMGE_ppz0, fcmge0)
4081DO_PPZ(FCMGT_ppz0, fcmgt0)
4082DO_PPZ(FCMLE_ppz0, fcmle0)
4083DO_PPZ(FCMLT_ppz0, fcmlt0)
4084DO_PPZ(FCMEQ_ppz0, fcmeq0)
4085DO_PPZ(FCMNE_ppz0, fcmne0)
4086
4087#undef DO_PPZ
4088
67fcd9ad
RH
4089/*
4090 *** SVE floating-point trig multiply-add coefficient
4091 */
4092
3a7be554 4093static bool trans_FTMAD(DisasContext *s, arg_FTMAD *a)
67fcd9ad
RH
4094{
4095 static gen_helper_gvec_3_ptr * const fns[3] = {
4096 gen_helper_sve_ftmad_h,
4097 gen_helper_sve_ftmad_s,
4098 gen_helper_sve_ftmad_d,
4099 };
4100
4101 if (a->esz == 0) {
4102 return false;
4103 }
4104 if (sve_access_check(s)) {
4105 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4106 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
67fcd9ad
RH
4107 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd),
4108 vec_full_reg_offset(s, a->rn),
4109 vec_full_reg_offset(s, a->rm),
4110 status, vsz, vsz, a->imm, fns[a->esz - 1]);
4111 tcg_temp_free_ptr(status);
4112 }
4113 return true;
4114}
4115
7f9ddf64
RH
4116/*
4117 *** SVE Floating Point Accumulating Reduction Group
4118 */
4119
3a7be554 4120static bool trans_FADDA(DisasContext *s, arg_rprr_esz *a)
7f9ddf64
RH
4121{
4122 typedef void fadda_fn(TCGv_i64, TCGv_i64, TCGv_ptr,
4123 TCGv_ptr, TCGv_ptr, TCGv_i32);
4124 static fadda_fn * const fns[3] = {
4125 gen_helper_sve_fadda_h,
4126 gen_helper_sve_fadda_s,
4127 gen_helper_sve_fadda_d,
4128 };
4129 unsigned vsz = vec_full_reg_size(s);
4130 TCGv_ptr t_rm, t_pg, t_fpst;
4131 TCGv_i64 t_val;
4132 TCGv_i32 t_desc;
4133
4134 if (a->esz == 0) {
4135 return false;
4136 }
4137 if (!sve_access_check(s)) {
4138 return true;
4139 }
4140
4141 t_val = load_esz(cpu_env, vec_reg_offset(s, a->rn, 0, a->esz), a->esz);
4142 t_rm = tcg_temp_new_ptr();
4143 t_pg = tcg_temp_new_ptr();
4144 tcg_gen_addi_ptr(t_rm, cpu_env, vec_full_reg_offset(s, a->rm));
4145 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, a->pg));
cdfb22bb 4146 t_fpst = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
c6a59b55 4147 t_desc = tcg_constant_i32(simd_desc(vsz, vsz, 0));
7f9ddf64
RH
4148
4149 fns[a->esz - 1](t_val, t_val, t_rm, t_pg, t_fpst, t_desc);
4150
7f9ddf64
RH
4151 tcg_temp_free_ptr(t_fpst);
4152 tcg_temp_free_ptr(t_pg);
4153 tcg_temp_free_ptr(t_rm);
4154
4155 write_fp_dreg(s, a->rd, t_val);
4156 tcg_temp_free_i64(t_val);
4157 return true;
4158}
4159
29b80469
RH
4160/*
4161 *** SVE Floating Point Arithmetic - Unpredicated Group
4162 */
4163
4164static bool do_zzz_fp(DisasContext *s, arg_rrr_esz *a,
4165 gen_helper_gvec_3_ptr *fn)
4166{
4167 if (fn == NULL) {
4168 return false;
4169 }
4170 if (sve_access_check(s)) {
4171 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4172 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
29b80469
RH
4173 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd),
4174 vec_full_reg_offset(s, a->rn),
4175 vec_full_reg_offset(s, a->rm),
4176 status, vsz, vsz, 0, fn);
4177 tcg_temp_free_ptr(status);
4178 }
4179 return true;
4180}
4181
4182
4183#define DO_FP3(NAME, name) \
3a7be554 4184static bool trans_##NAME(DisasContext *s, arg_rrr_esz *a) \
29b80469
RH
4185{ \
4186 static gen_helper_gvec_3_ptr * const fns[4] = { \
4187 NULL, gen_helper_gvec_##name##_h, \
4188 gen_helper_gvec_##name##_s, gen_helper_gvec_##name##_d \
4189 }; \
4190 return do_zzz_fp(s, a, fns[a->esz]); \
4191}
4192
4193DO_FP3(FADD_zzz, fadd)
4194DO_FP3(FSUB_zzz, fsub)
4195DO_FP3(FMUL_zzz, fmul)
4196DO_FP3(FTSMUL, ftsmul)
4197DO_FP3(FRECPS, recps)
4198DO_FP3(FRSQRTS, rsqrts)
4199
4200#undef DO_FP3
4201
ec3b87c2
RH
4202/*
4203 *** SVE Floating Point Arithmetic - Predicated Group
4204 */
4205
4206static bool do_zpzz_fp(DisasContext *s, arg_rprr_esz *a,
4207 gen_helper_gvec_4_ptr *fn)
4208{
4209 if (fn == NULL) {
4210 return false;
4211 }
4212 if (sve_access_check(s)) {
4213 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4214 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
ec3b87c2
RH
4215 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
4216 vec_full_reg_offset(s, a->rn),
4217 vec_full_reg_offset(s, a->rm),
4218 pred_full_reg_offset(s, a->pg),
4219 status, vsz, vsz, 0, fn);
4220 tcg_temp_free_ptr(status);
4221 }
4222 return true;
4223}
4224
4225#define DO_FP3(NAME, name) \
3a7be554 4226static bool trans_##NAME(DisasContext *s, arg_rprr_esz *a) \
ec3b87c2
RH
4227{ \
4228 static gen_helper_gvec_4_ptr * const fns[4] = { \
4229 NULL, gen_helper_sve_##name##_h, \
4230 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d \
4231 }; \
4232 return do_zpzz_fp(s, a, fns[a->esz]); \
4233}
4234
4235DO_FP3(FADD_zpzz, fadd)
4236DO_FP3(FSUB_zpzz, fsub)
4237DO_FP3(FMUL_zpzz, fmul)
4238DO_FP3(FMIN_zpzz, fmin)
4239DO_FP3(FMAX_zpzz, fmax)
4240DO_FP3(FMINNM_zpzz, fminnum)
4241DO_FP3(FMAXNM_zpzz, fmaxnum)
4242DO_FP3(FABD, fabd)
4243DO_FP3(FSCALE, fscalbn)
4244DO_FP3(FDIV, fdiv)
4245DO_FP3(FMULX, fmulx)
4246
4247#undef DO_FP3
8092c6a3 4248
cc48affe
RH
4249typedef void gen_helper_sve_fp2scalar(TCGv_ptr, TCGv_ptr, TCGv_ptr,
4250 TCGv_i64, TCGv_ptr, TCGv_i32);
4251
4252static void do_fp_scalar(DisasContext *s, int zd, int zn, int pg, bool is_fp16,
4253 TCGv_i64 scalar, gen_helper_sve_fp2scalar *fn)
4254{
4255 unsigned vsz = vec_full_reg_size(s);
4256 TCGv_ptr t_zd, t_zn, t_pg, status;
4257 TCGv_i32 desc;
4258
4259 t_zd = tcg_temp_new_ptr();
4260 t_zn = tcg_temp_new_ptr();
4261 t_pg = tcg_temp_new_ptr();
4262 tcg_gen_addi_ptr(t_zd, cpu_env, vec_full_reg_offset(s, zd));
4263 tcg_gen_addi_ptr(t_zn, cpu_env, vec_full_reg_offset(s, zn));
4264 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, pg));
4265
cdfb22bb 4266 status = fpstatus_ptr(is_fp16 ? FPST_FPCR_F16 : FPST_FPCR);
c6a59b55 4267 desc = tcg_constant_i32(simd_desc(vsz, vsz, 0));
cc48affe
RH
4268 fn(t_zd, t_zn, t_pg, scalar, status, desc);
4269
cc48affe
RH
4270 tcg_temp_free_ptr(status);
4271 tcg_temp_free_ptr(t_pg);
4272 tcg_temp_free_ptr(t_zn);
4273 tcg_temp_free_ptr(t_zd);
4274}
4275
4276static void do_fp_imm(DisasContext *s, arg_rpri_esz *a, uint64_t imm,
4277 gen_helper_sve_fp2scalar *fn)
4278{
138a1f7b
RH
4279 do_fp_scalar(s, a->rd, a->rn, a->pg, a->esz == MO_16,
4280 tcg_constant_i64(imm), fn);
cc48affe
RH
4281}
4282
4283#define DO_FP_IMM(NAME, name, const0, const1) \
3a7be554 4284static bool trans_##NAME##_zpzi(DisasContext *s, arg_rpri_esz *a) \
cc48affe
RH
4285{ \
4286 static gen_helper_sve_fp2scalar * const fns[3] = { \
4287 gen_helper_sve_##name##_h, \
4288 gen_helper_sve_##name##_s, \
4289 gen_helper_sve_##name##_d \
4290 }; \
4291 static uint64_t const val[3][2] = { \
4292 { float16_##const0, float16_##const1 }, \
4293 { float32_##const0, float32_##const1 }, \
4294 { float64_##const0, float64_##const1 }, \
4295 }; \
4296 if (a->esz == 0) { \
4297 return false; \
4298 } \
4299 if (sve_access_check(s)) { \
4300 do_fp_imm(s, a, val[a->esz - 1][a->imm], fns[a->esz - 1]); \
4301 } \
4302 return true; \
4303}
4304
cc48affe
RH
4305DO_FP_IMM(FADD, fadds, half, one)
4306DO_FP_IMM(FSUB, fsubs, half, one)
4307DO_FP_IMM(FMUL, fmuls, half, two)
4308DO_FP_IMM(FSUBR, fsubrs, half, one)
4309DO_FP_IMM(FMAXNM, fmaxnms, zero, one)
4310DO_FP_IMM(FMINNM, fminnms, zero, one)
4311DO_FP_IMM(FMAX, fmaxs, zero, one)
4312DO_FP_IMM(FMIN, fmins, zero, one)
4313
4314#undef DO_FP_IMM
4315
abfdefd5
RH
4316static bool do_fp_cmp(DisasContext *s, arg_rprr_esz *a,
4317 gen_helper_gvec_4_ptr *fn)
4318{
4319 if (fn == NULL) {
4320 return false;
4321 }
4322 if (sve_access_check(s)) {
4323 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4324 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
abfdefd5
RH
4325 tcg_gen_gvec_4_ptr(pred_full_reg_offset(s, a->rd),
4326 vec_full_reg_offset(s, a->rn),
4327 vec_full_reg_offset(s, a->rm),
4328 pred_full_reg_offset(s, a->pg),
4329 status, vsz, vsz, 0, fn);
4330 tcg_temp_free_ptr(status);
4331 }
4332 return true;
4333}
4334
4335#define DO_FPCMP(NAME, name) \
3a7be554 4336static bool trans_##NAME##_ppzz(DisasContext *s, arg_rprr_esz *a) \
abfdefd5
RH
4337{ \
4338 static gen_helper_gvec_4_ptr * const fns[4] = { \
4339 NULL, gen_helper_sve_##name##_h, \
4340 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d \
4341 }; \
4342 return do_fp_cmp(s, a, fns[a->esz]); \
4343}
4344
4345DO_FPCMP(FCMGE, fcmge)
4346DO_FPCMP(FCMGT, fcmgt)
4347DO_FPCMP(FCMEQ, fcmeq)
4348DO_FPCMP(FCMNE, fcmne)
4349DO_FPCMP(FCMUO, fcmuo)
4350DO_FPCMP(FACGE, facge)
4351DO_FPCMP(FACGT, facgt)
4352
4353#undef DO_FPCMP
4354
3a7be554 4355static bool trans_FCADD(DisasContext *s, arg_FCADD *a)
76a9d9cd
RH
4356{
4357 static gen_helper_gvec_4_ptr * const fns[3] = {
4358 gen_helper_sve_fcadd_h,
4359 gen_helper_sve_fcadd_s,
4360 gen_helper_sve_fcadd_d
4361 };
4362
4363 if (a->esz == 0) {
4364 return false;
4365 }
4366 if (sve_access_check(s)) {
4367 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4368 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
76a9d9cd
RH
4369 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
4370 vec_full_reg_offset(s, a->rn),
4371 vec_full_reg_offset(s, a->rm),
4372 pred_full_reg_offset(s, a->pg),
4373 status, vsz, vsz, a->rot, fns[a->esz - 1]);
4374 tcg_temp_free_ptr(status);
4375 }
4376 return true;
4377}
4378
08975da9
RH
4379static bool do_fmla(DisasContext *s, arg_rprrr_esz *a,
4380 gen_helper_gvec_5_ptr *fn)
6ceabaad 4381{
08975da9 4382 if (a->esz == 0) {
6ceabaad
RH
4383 return false;
4384 }
08975da9
RH
4385 if (sve_access_check(s)) {
4386 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4387 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
08975da9
RH
4388 tcg_gen_gvec_5_ptr(vec_full_reg_offset(s, a->rd),
4389 vec_full_reg_offset(s, a->rn),
4390 vec_full_reg_offset(s, a->rm),
4391 vec_full_reg_offset(s, a->ra),
4392 pred_full_reg_offset(s, a->pg),
4393 status, vsz, vsz, 0, fn);
4394 tcg_temp_free_ptr(status);
6ceabaad 4395 }
6ceabaad
RH
4396 return true;
4397}
4398
4399#define DO_FMLA(NAME, name) \
3a7be554 4400static bool trans_##NAME(DisasContext *s, arg_rprrr_esz *a) \
6ceabaad 4401{ \
08975da9 4402 static gen_helper_gvec_5_ptr * const fns[4] = { \
6ceabaad
RH
4403 NULL, gen_helper_sve_##name##_h, \
4404 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d \
4405 }; \
4406 return do_fmla(s, a, fns[a->esz]); \
4407}
4408
4409DO_FMLA(FMLA_zpzzz, fmla_zpzzz)
4410DO_FMLA(FMLS_zpzzz, fmls_zpzzz)
4411DO_FMLA(FNMLA_zpzzz, fnmla_zpzzz)
4412DO_FMLA(FNMLS_zpzzz, fnmls_zpzzz)
4413
4414#undef DO_FMLA
4415
3a7be554 4416static bool trans_FCMLA_zpzzz(DisasContext *s, arg_FCMLA_zpzzz *a)
05f48bab 4417{
08975da9
RH
4418 static gen_helper_gvec_5_ptr * const fns[4] = {
4419 NULL,
05f48bab
RH
4420 gen_helper_sve_fcmla_zpzzz_h,
4421 gen_helper_sve_fcmla_zpzzz_s,
4422 gen_helper_sve_fcmla_zpzzz_d,
4423 };
4424
4425 if (a->esz == 0) {
4426 return false;
4427 }
4428 if (sve_access_check(s)) {
4429 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4430 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
08975da9
RH
4431 tcg_gen_gvec_5_ptr(vec_full_reg_offset(s, a->rd),
4432 vec_full_reg_offset(s, a->rn),
4433 vec_full_reg_offset(s, a->rm),
4434 vec_full_reg_offset(s, a->ra),
4435 pred_full_reg_offset(s, a->pg),
4436 status, vsz, vsz, a->rot, fns[a->esz]);
4437 tcg_temp_free_ptr(status);
05f48bab
RH
4438 }
4439 return true;
4440}
4441
3a7be554 4442static bool trans_FCMLA_zzxz(DisasContext *s, arg_FCMLA_zzxz *a)
18fc2405 4443{
636ddeb1 4444 static gen_helper_gvec_4_ptr * const fns[2] = {
18fc2405
RH
4445 gen_helper_gvec_fcmlah_idx,
4446 gen_helper_gvec_fcmlas_idx,
4447 };
4448
4449 tcg_debug_assert(a->esz == 1 || a->esz == 2);
4450 tcg_debug_assert(a->rd == a->ra);
4451 if (sve_access_check(s)) {
4452 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4453 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
636ddeb1 4454 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
18fc2405
RH
4455 vec_full_reg_offset(s, a->rn),
4456 vec_full_reg_offset(s, a->rm),
636ddeb1 4457 vec_full_reg_offset(s, a->ra),
18fc2405
RH
4458 status, vsz, vsz,
4459 a->index * 4 + a->rot,
4460 fns[a->esz - 1]);
4461 tcg_temp_free_ptr(status);
4462 }
4463 return true;
4464}
4465
8092c6a3
RH
4466/*
4467 *** SVE Floating Point Unary Operations Predicated Group
4468 */
4469
4470static bool do_zpz_ptr(DisasContext *s, int rd, int rn, int pg,
4471 bool is_fp16, gen_helper_gvec_3_ptr *fn)
4472{
4473 if (sve_access_check(s)) {
4474 unsigned vsz = vec_full_reg_size(s);
cdfb22bb 4475 TCGv_ptr status = fpstatus_ptr(is_fp16 ? FPST_FPCR_F16 : FPST_FPCR);
8092c6a3
RH
4476 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, rd),
4477 vec_full_reg_offset(s, rn),
4478 pred_full_reg_offset(s, pg),
4479 status, vsz, vsz, 0, fn);
4480 tcg_temp_free_ptr(status);
4481 }
4482 return true;
4483}
4484
3a7be554 4485static bool trans_FCVT_sh(DisasContext *s, arg_rpr_esz *a)
46d33d1e 4486{
e4ab5124 4487 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvt_sh);
46d33d1e
RH
4488}
4489
3a7be554 4490static bool trans_FCVT_hs(DisasContext *s, arg_rpr_esz *a)
46d33d1e
RH
4491{
4492 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvt_hs);
4493}
4494
d29b17ca
RH
4495static bool trans_BFCVT(DisasContext *s, arg_rpr_esz *a)
4496{
4497 if (!dc_isar_feature(aa64_sve_bf16, s)) {
4498 return false;
4499 }
4500 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_bfcvt);
4501}
4502
3a7be554 4503static bool trans_FCVT_dh(DisasContext *s, arg_rpr_esz *a)
46d33d1e 4504{
e4ab5124 4505 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvt_dh);
46d33d1e
RH
4506}
4507
3a7be554 4508static bool trans_FCVT_hd(DisasContext *s, arg_rpr_esz *a)
46d33d1e
RH
4509{
4510 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvt_hd);
4511}
4512
3a7be554 4513static bool trans_FCVT_ds(DisasContext *s, arg_rpr_esz *a)
46d33d1e
RH
4514{
4515 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvt_ds);
4516}
4517
3a7be554 4518static bool trans_FCVT_sd(DisasContext *s, arg_rpr_esz *a)
46d33d1e
RH
4519{
4520 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvt_sd);
4521}
4522
3a7be554 4523static bool trans_FCVTZS_hh(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4524{
4525 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_fcvtzs_hh);
4526}
4527
3a7be554 4528static bool trans_FCVTZU_hh(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4529{
4530 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_fcvtzu_hh);
4531}
4532
3a7be554 4533static bool trans_FCVTZS_hs(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4534{
4535 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_fcvtzs_hs);
4536}
4537
3a7be554 4538static bool trans_FCVTZU_hs(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4539{
4540 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_fcvtzu_hs);
4541}
4542
3a7be554 4543static bool trans_FCVTZS_hd(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4544{
4545 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_fcvtzs_hd);
4546}
4547
3a7be554 4548static bool trans_FCVTZU_hd(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4549{
4550 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_fcvtzu_hd);
4551}
4552
3a7be554 4553static bool trans_FCVTZS_ss(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4554{
4555 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzs_ss);
4556}
4557
3a7be554 4558static bool trans_FCVTZU_ss(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4559{
4560 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzu_ss);
4561}
4562
3a7be554 4563static bool trans_FCVTZS_sd(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4564{
4565 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzs_sd);
4566}
4567
3a7be554 4568static bool trans_FCVTZU_sd(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4569{
4570 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzu_sd);
4571}
4572
3a7be554 4573static bool trans_FCVTZS_ds(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4574{
4575 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzs_ds);
4576}
4577
3a7be554 4578static bool trans_FCVTZU_ds(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4579{
4580 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzu_ds);
4581}
4582
3a7be554 4583static bool trans_FCVTZS_dd(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4584{
4585 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzs_dd);
4586}
4587
3a7be554 4588static bool trans_FCVTZU_dd(DisasContext *s, arg_rpr_esz *a)
df4de1af
RH
4589{
4590 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_fcvtzu_dd);
4591}
4592
cda3c753
RH
4593static gen_helper_gvec_3_ptr * const frint_fns[3] = {
4594 gen_helper_sve_frint_h,
4595 gen_helper_sve_frint_s,
4596 gen_helper_sve_frint_d
4597};
4598
3a7be554 4599static bool trans_FRINTI(DisasContext *s, arg_rpr_esz *a)
cda3c753
RH
4600{
4601 if (a->esz == 0) {
4602 return false;
4603 }
4604 return do_zpz_ptr(s, a->rd, a->rn, a->pg, a->esz == MO_16,
4605 frint_fns[a->esz - 1]);
4606}
4607
3a7be554 4608static bool trans_FRINTX(DisasContext *s, arg_rpr_esz *a)
cda3c753
RH
4609{
4610 static gen_helper_gvec_3_ptr * const fns[3] = {
4611 gen_helper_sve_frintx_h,
4612 gen_helper_sve_frintx_s,
4613 gen_helper_sve_frintx_d
4614 };
4615 if (a->esz == 0) {
4616 return false;
4617 }
4618 return do_zpz_ptr(s, a->rd, a->rn, a->pg, a->esz == MO_16, fns[a->esz - 1]);
4619}
4620
95365277
SL
4621static bool do_frint_mode(DisasContext *s, arg_rpr_esz *a,
4622 int mode, gen_helper_gvec_3_ptr *fn)
cda3c753 4623{
cda3c753
RH
4624 if (sve_access_check(s)) {
4625 unsigned vsz = vec_full_reg_size(s);
4626 TCGv_i32 tmode = tcg_const_i32(mode);
cdfb22bb 4627 TCGv_ptr status = fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
cda3c753
RH
4628
4629 gen_helper_set_rmode(tmode, tmode, status);
4630
4631 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd),
4632 vec_full_reg_offset(s, a->rn),
4633 pred_full_reg_offset(s, a->pg),
95365277 4634 status, vsz, vsz, 0, fn);
cda3c753
RH
4635
4636 gen_helper_set_rmode(tmode, tmode, status);
4637 tcg_temp_free_i32(tmode);
4638 tcg_temp_free_ptr(status);
4639 }
4640 return true;
4641}
4642
3a7be554 4643static bool trans_FRINTN(DisasContext *s, arg_rpr_esz *a)
cda3c753 4644{
95365277
SL
4645 if (a->esz == 0) {
4646 return false;
4647 }
4648 return do_frint_mode(s, a, float_round_nearest_even, frint_fns[a->esz - 1]);
cda3c753
RH
4649}
4650
3a7be554 4651static bool trans_FRINTP(DisasContext *s, arg_rpr_esz *a)
cda3c753 4652{
95365277
SL
4653 if (a->esz == 0) {
4654 return false;
4655 }
4656 return do_frint_mode(s, a, float_round_up, frint_fns[a->esz - 1]);
cda3c753
RH
4657}
4658
3a7be554 4659static bool trans_FRINTM(DisasContext *s, arg_rpr_esz *a)
cda3c753 4660{
95365277
SL
4661 if (a->esz == 0) {
4662 return false;
4663 }
4664 return do_frint_mode(s, a, float_round_down, frint_fns[a->esz - 1]);
cda3c753
RH
4665}
4666
3a7be554 4667static bool trans_FRINTZ(DisasContext *s, arg_rpr_esz *a)
cda3c753 4668{
95365277
SL
4669 if (a->esz == 0) {
4670 return false;
4671 }
4672 return do_frint_mode(s, a, float_round_to_zero, frint_fns[a->esz - 1]);
cda3c753
RH
4673}
4674
3a7be554 4675static bool trans_FRINTA(DisasContext *s, arg_rpr_esz *a)
cda3c753 4676{
95365277
SL
4677 if (a->esz == 0) {
4678 return false;
4679 }
4680 return do_frint_mode(s, a, float_round_ties_away, frint_fns[a->esz - 1]);
cda3c753
RH
4681}
4682
3a7be554 4683static bool trans_FRECPX(DisasContext *s, arg_rpr_esz *a)
ec5b375b
RH
4684{
4685 static gen_helper_gvec_3_ptr * const fns[3] = {
4686 gen_helper_sve_frecpx_h,
4687 gen_helper_sve_frecpx_s,
4688 gen_helper_sve_frecpx_d
4689 };
4690 if (a->esz == 0) {
4691 return false;
4692 }
4693 return do_zpz_ptr(s, a->rd, a->rn, a->pg, a->esz == MO_16, fns[a->esz - 1]);
4694}
4695
3a7be554 4696static bool trans_FSQRT(DisasContext *s, arg_rpr_esz *a)
ec5b375b
RH
4697{
4698 static gen_helper_gvec_3_ptr * const fns[3] = {
4699 gen_helper_sve_fsqrt_h,
4700 gen_helper_sve_fsqrt_s,
4701 gen_helper_sve_fsqrt_d
4702 };
4703 if (a->esz == 0) {
4704 return false;
4705 }
4706 return do_zpz_ptr(s, a->rd, a->rn, a->pg, a->esz == MO_16, fns[a->esz - 1]);
4707}
4708
3a7be554 4709static bool trans_SCVTF_hh(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4710{
4711 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_scvt_hh);
4712}
4713
3a7be554 4714static bool trans_SCVTF_sh(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4715{
4716 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_scvt_sh);
4717}
4718
3a7be554 4719static bool trans_SCVTF_dh(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4720{
4721 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_scvt_dh);
4722}
4723
3a7be554 4724static bool trans_SCVTF_ss(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4725{
4726 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_scvt_ss);
4727}
4728
3a7be554 4729static bool trans_SCVTF_ds(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4730{
4731 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_scvt_ds);
4732}
4733
3a7be554 4734static bool trans_SCVTF_sd(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4735{
4736 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_scvt_sd);
4737}
4738
3a7be554 4739static bool trans_SCVTF_dd(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4740{
4741 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_scvt_dd);
4742}
4743
3a7be554 4744static bool trans_UCVTF_hh(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4745{
4746 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_ucvt_hh);
4747}
4748
3a7be554 4749static bool trans_UCVTF_sh(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4750{
4751 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_ucvt_sh);
4752}
4753
3a7be554 4754static bool trans_UCVTF_dh(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4755{
4756 return do_zpz_ptr(s, a->rd, a->rn, a->pg, true, gen_helper_sve_ucvt_dh);
4757}
4758
3a7be554 4759static bool trans_UCVTF_ss(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4760{
4761 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_ucvt_ss);
4762}
4763
3a7be554 4764static bool trans_UCVTF_ds(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4765{
4766 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_ucvt_ds);
4767}
4768
3a7be554 4769static bool trans_UCVTF_sd(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4770{
4771 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_ucvt_sd);
4772}
4773
3a7be554 4774static bool trans_UCVTF_dd(DisasContext *s, arg_rpr_esz *a)
8092c6a3
RH
4775{
4776 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_ucvt_dd);
4777}
4778
d1822297
RH
4779/*
4780 *** SVE Memory - 32-bit Gather and Unsized Contiguous Group
4781 */
4782
4783/* Subroutine loading a vector register at VOFS of LEN bytes.
4784 * The load should begin at the address Rn + IMM.
4785 */
4786
19f2acc9 4787static void do_ldr(DisasContext *s, uint32_t vofs, int len, int rn, int imm)
d1822297 4788{
19f2acc9
RH
4789 int len_align = QEMU_ALIGN_DOWN(len, 8);
4790 int len_remain = len % 8;
4791 int nparts = len / 8 + ctpop8(len_remain);
d1822297 4792 int midx = get_mem_index(s);
b2aa8879 4793 TCGv_i64 dirty_addr, clean_addr, t0, t1;
d1822297 4794
b2aa8879
RH
4795 dirty_addr = tcg_temp_new_i64();
4796 tcg_gen_addi_i64(dirty_addr, cpu_reg_sp(s, rn), imm);
33e74c31 4797 clean_addr = gen_mte_checkN(s, dirty_addr, false, rn != 31, len);
b2aa8879 4798 tcg_temp_free_i64(dirty_addr);
d1822297 4799
b2aa8879
RH
4800 /*
4801 * Note that unpredicated load/store of vector/predicate registers
d1822297 4802 * are defined as a stream of bytes, which equates to little-endian
b2aa8879 4803 * operations on larger quantities.
d1822297
RH
4804 * Attempt to keep code expansion to a minimum by limiting the
4805 * amount of unrolling done.
4806 */
4807 if (nparts <= 4) {
4808 int i;
4809
b2aa8879 4810 t0 = tcg_temp_new_i64();
d1822297 4811 for (i = 0; i < len_align; i += 8) {
fc313c64 4812 tcg_gen_qemu_ld_i64(t0, clean_addr, midx, MO_LEUQ);
d1822297 4813 tcg_gen_st_i64(t0, cpu_env, vofs + i);
d8227b09 4814 tcg_gen_addi_i64(clean_addr, clean_addr, 8);
d1822297 4815 }
b2aa8879 4816 tcg_temp_free_i64(t0);
d1822297
RH
4817 } else {
4818 TCGLabel *loop = gen_new_label();
4819 TCGv_ptr tp, i = tcg_const_local_ptr(0);
4820
b2aa8879
RH
4821 /* Copy the clean address into a local temp, live across the loop. */
4822 t0 = clean_addr;
4b4dc975 4823 clean_addr = new_tmp_a64_local(s);
b2aa8879 4824 tcg_gen_mov_i64(clean_addr, t0);
d1822297 4825
b2aa8879 4826 gen_set_label(loop);
d1822297 4827
b2aa8879 4828 t0 = tcg_temp_new_i64();
fc313c64 4829 tcg_gen_qemu_ld_i64(t0, clean_addr, midx, MO_LEUQ);
b2aa8879 4830 tcg_gen_addi_i64(clean_addr, clean_addr, 8);
d1822297 4831
b2aa8879 4832 tp = tcg_temp_new_ptr();
d1822297
RH
4833 tcg_gen_add_ptr(tp, cpu_env, i);
4834 tcg_gen_addi_ptr(i, i, 8);
4835 tcg_gen_st_i64(t0, tp, vofs);
4836 tcg_temp_free_ptr(tp);
b2aa8879 4837 tcg_temp_free_i64(t0);
d1822297
RH
4838
4839 tcg_gen_brcondi_ptr(TCG_COND_LTU, i, len_align, loop);
4840 tcg_temp_free_ptr(i);
4841 }
4842
b2aa8879
RH
4843 /*
4844 * Predicate register loads can be any multiple of 2.
d1822297
RH
4845 * Note that we still store the entire 64-bit unit into cpu_env.
4846 */
4847 if (len_remain) {
b2aa8879 4848 t0 = tcg_temp_new_i64();
d1822297
RH
4849 switch (len_remain) {
4850 case 2:
4851 case 4:
4852 case 8:
b2aa8879
RH
4853 tcg_gen_qemu_ld_i64(t0, clean_addr, midx,
4854 MO_LE | ctz32(len_remain));
d1822297
RH
4855 break;
4856
4857 case 6:
4858 t1 = tcg_temp_new_i64();
b2aa8879
RH
4859 tcg_gen_qemu_ld_i64(t0, clean_addr, midx, MO_LEUL);
4860 tcg_gen_addi_i64(clean_addr, clean_addr, 4);
4861 tcg_gen_qemu_ld_i64(t1, clean_addr, midx, MO_LEUW);
d1822297
RH
4862 tcg_gen_deposit_i64(t0, t0, t1, 32, 32);
4863 tcg_temp_free_i64(t1);
4864 break;
4865
4866 default:
4867 g_assert_not_reached();
4868 }
4869 tcg_gen_st_i64(t0, cpu_env, vofs + len_align);
b2aa8879 4870 tcg_temp_free_i64(t0);
d1822297 4871 }
d1822297
RH
4872}
4873
5047c204 4874/* Similarly for stores. */
19f2acc9 4875static void do_str(DisasContext *s, uint32_t vofs, int len, int rn, int imm)
5047c204 4876{
19f2acc9
RH
4877 int len_align = QEMU_ALIGN_DOWN(len, 8);
4878 int len_remain = len % 8;
4879 int nparts = len / 8 + ctpop8(len_remain);
5047c204 4880 int midx = get_mem_index(s);
bba87d0a 4881 TCGv_i64 dirty_addr, clean_addr, t0;
5047c204 4882
bba87d0a
RH
4883 dirty_addr = tcg_temp_new_i64();
4884 tcg_gen_addi_i64(dirty_addr, cpu_reg_sp(s, rn), imm);
33e74c31 4885 clean_addr = gen_mte_checkN(s, dirty_addr, false, rn != 31, len);
bba87d0a 4886 tcg_temp_free_i64(dirty_addr);
5047c204
RH
4887
4888 /* Note that unpredicated load/store of vector/predicate registers
4889 * are defined as a stream of bytes, which equates to little-endian
4890 * operations on larger quantities. There is no nice way to force
4891 * a little-endian store for aarch64_be-linux-user out of line.
4892 *
4893 * Attempt to keep code expansion to a minimum by limiting the
4894 * amount of unrolling done.
4895 */
4896 if (nparts <= 4) {
4897 int i;
4898
bba87d0a 4899 t0 = tcg_temp_new_i64();
5047c204
RH
4900 for (i = 0; i < len_align; i += 8) {
4901 tcg_gen_ld_i64(t0, cpu_env, vofs + i);
fc313c64 4902 tcg_gen_qemu_st_i64(t0, clean_addr, midx, MO_LEUQ);
d8227b09 4903 tcg_gen_addi_i64(clean_addr, clean_addr, 8);
5047c204 4904 }
bba87d0a 4905 tcg_temp_free_i64(t0);
5047c204
RH
4906 } else {
4907 TCGLabel *loop = gen_new_label();
bba87d0a 4908 TCGv_ptr tp, i = tcg_const_local_ptr(0);
5047c204 4909
bba87d0a
RH
4910 /* Copy the clean address into a local temp, live across the loop. */
4911 t0 = clean_addr;
4b4dc975 4912 clean_addr = new_tmp_a64_local(s);
bba87d0a 4913 tcg_gen_mov_i64(clean_addr, t0);
5047c204 4914
bba87d0a 4915 gen_set_label(loop);
5047c204 4916
bba87d0a
RH
4917 t0 = tcg_temp_new_i64();
4918 tp = tcg_temp_new_ptr();
4919 tcg_gen_add_ptr(tp, cpu_env, i);
4920 tcg_gen_ld_i64(t0, tp, vofs);
5047c204 4921 tcg_gen_addi_ptr(i, i, 8);
bba87d0a
RH
4922 tcg_temp_free_ptr(tp);
4923
fc313c64 4924 tcg_gen_qemu_st_i64(t0, clean_addr, midx, MO_LEUQ);
bba87d0a
RH
4925 tcg_gen_addi_i64(clean_addr, clean_addr, 8);
4926 tcg_temp_free_i64(t0);
5047c204
RH
4927
4928 tcg_gen_brcondi_ptr(TCG_COND_LTU, i, len_align, loop);
4929 tcg_temp_free_ptr(i);
4930 }
4931
4932 /* Predicate register stores can be any multiple of 2. */
4933 if (len_remain) {
bba87d0a 4934 t0 = tcg_temp_new_i64();
5047c204 4935 tcg_gen_ld_i64(t0, cpu_env, vofs + len_align);
5047c204
RH
4936
4937 switch (len_remain) {
4938 case 2:
4939 case 4:
4940 case 8:
bba87d0a
RH
4941 tcg_gen_qemu_st_i64(t0, clean_addr, midx,
4942 MO_LE | ctz32(len_remain));
5047c204
RH
4943 break;
4944
4945 case 6:
bba87d0a
RH
4946 tcg_gen_qemu_st_i64(t0, clean_addr, midx, MO_LEUL);
4947 tcg_gen_addi_i64(clean_addr, clean_addr, 4);
5047c204 4948 tcg_gen_shri_i64(t0, t0, 32);
bba87d0a 4949 tcg_gen_qemu_st_i64(t0, clean_addr, midx, MO_LEUW);
5047c204
RH
4950 break;
4951
4952 default:
4953 g_assert_not_reached();
4954 }
bba87d0a 4955 tcg_temp_free_i64(t0);
5047c204 4956 }
5047c204
RH
4957}
4958
3a7be554 4959static bool trans_LDR_zri(DisasContext *s, arg_rri *a)
d1822297
RH
4960{
4961 if (sve_access_check(s)) {
4962 int size = vec_full_reg_size(s);
4963 int off = vec_full_reg_offset(s, a->rd);
4964 do_ldr(s, off, size, a->rn, a->imm * size);
4965 }
4966 return true;
4967}
4968
3a7be554 4969static bool trans_LDR_pri(DisasContext *s, arg_rri *a)
d1822297
RH
4970{
4971 if (sve_access_check(s)) {
4972 int size = pred_full_reg_size(s);
4973 int off = pred_full_reg_offset(s, a->rd);
4974 do_ldr(s, off, size, a->rn, a->imm * size);
4975 }
4976 return true;
4977}
c4e7c493 4978
3a7be554 4979static bool trans_STR_zri(DisasContext *s, arg_rri *a)
5047c204
RH
4980{
4981 if (sve_access_check(s)) {
4982 int size = vec_full_reg_size(s);
4983 int off = vec_full_reg_offset(s, a->rd);
4984 do_str(s, off, size, a->rn, a->imm * size);
4985 }
4986 return true;
4987}
4988
3a7be554 4989static bool trans_STR_pri(DisasContext *s, arg_rri *a)
5047c204
RH
4990{
4991 if (sve_access_check(s)) {
4992 int size = pred_full_reg_size(s);
4993 int off = pred_full_reg_offset(s, a->rd);
4994 do_str(s, off, size, a->rn, a->imm * size);
4995 }
4996 return true;
4997}
4998
c4e7c493
RH
4999/*
5000 *** SVE Memory - Contiguous Load Group
5001 */
5002
5003/* The memory mode of the dtype. */
14776ab5 5004static const MemOp dtype_mop[16] = {
c4e7c493
RH
5005 MO_UB, MO_UB, MO_UB, MO_UB,
5006 MO_SL, MO_UW, MO_UW, MO_UW,
5007 MO_SW, MO_SW, MO_UL, MO_UL,
fc313c64 5008 MO_SB, MO_SB, MO_SB, MO_UQ
c4e7c493
RH
5009};
5010
5011#define dtype_msz(x) (dtype_mop[x] & MO_SIZE)
5012
5013/* The vector element size of dtype. */
5014static const uint8_t dtype_esz[16] = {
5015 0, 1, 2, 3,
5016 3, 1, 2, 3,
5017 3, 2, 2, 3,
5018 3, 2, 1, 3
5019};
5020
5021static void do_mem_zpa(DisasContext *s, int zt, int pg, TCGv_i64 addr,
206adacf
RH
5022 int dtype, uint32_t mte_n, bool is_write,
5023 gen_helper_gvec_mem *fn)
c4e7c493
RH
5024{
5025 unsigned vsz = vec_full_reg_size(s);
5026 TCGv_ptr t_pg;
206adacf 5027 int desc = 0;
c4e7c493 5028
206adacf
RH
5029 /*
5030 * For e.g. LD4, there are not enough arguments to pass all 4
c4e7c493
RH
5031 * registers as pointers, so encode the regno into the data field.
5032 * For consistency, do this even for LD1.
5033 */
9473d0ec 5034 if (s->mte_active[0]) {
206adacf
RH
5035 int msz = dtype_msz(dtype);
5036
5037 desc = FIELD_DP32(desc, MTEDESC, MIDX, get_mem_index(s));
5038 desc = FIELD_DP32(desc, MTEDESC, TBI, s->tbid);
5039 desc = FIELD_DP32(desc, MTEDESC, TCMA, s->tcma);
5040 desc = FIELD_DP32(desc, MTEDESC, WRITE, is_write);
28f32503 5041 desc = FIELD_DP32(desc, MTEDESC, SIZEM1, (mte_n << msz) - 1);
206adacf 5042 desc <<= SVE_MTEDESC_SHIFT;
9473d0ec
RH
5043 } else {
5044 addr = clean_data_tbi(s, addr);
206adacf 5045 }
9473d0ec 5046
206adacf 5047 desc = simd_desc(vsz, vsz, zt | desc);
c4e7c493
RH
5048 t_pg = tcg_temp_new_ptr();
5049
5050 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, pg));
c6a59b55 5051 fn(cpu_env, t_pg, addr, tcg_constant_i32(desc));
c4e7c493
RH
5052
5053 tcg_temp_free_ptr(t_pg);
c4e7c493
RH
5054}
5055
c182c6db
RH
5056/* Indexed by [mte][be][dtype][nreg] */
5057static gen_helper_gvec_mem * const ldr_fns[2][2][16][4] = {
5058 { /* mte inactive, little-endian */
5059 { { gen_helper_sve_ld1bb_r, gen_helper_sve_ld2bb_r,
5060 gen_helper_sve_ld3bb_r, gen_helper_sve_ld4bb_r },
5061 { gen_helper_sve_ld1bhu_r, NULL, NULL, NULL },
5062 { gen_helper_sve_ld1bsu_r, NULL, NULL, NULL },
5063 { gen_helper_sve_ld1bdu_r, NULL, NULL, NULL },
5064
5065 { gen_helper_sve_ld1sds_le_r, NULL, NULL, NULL },
5066 { gen_helper_sve_ld1hh_le_r, gen_helper_sve_ld2hh_le_r,
5067 gen_helper_sve_ld3hh_le_r, gen_helper_sve_ld4hh_le_r },
5068 { gen_helper_sve_ld1hsu_le_r, NULL, NULL, NULL },
5069 { gen_helper_sve_ld1hdu_le_r, NULL, NULL, NULL },
5070
5071 { gen_helper_sve_ld1hds_le_r, NULL, NULL, NULL },
5072 { gen_helper_sve_ld1hss_le_r, NULL, NULL, NULL },
5073 { gen_helper_sve_ld1ss_le_r, gen_helper_sve_ld2ss_le_r,
5074 gen_helper_sve_ld3ss_le_r, gen_helper_sve_ld4ss_le_r },
5075 { gen_helper_sve_ld1sdu_le_r, NULL, NULL, NULL },
5076
5077 { gen_helper_sve_ld1bds_r, NULL, NULL, NULL },
5078 { gen_helper_sve_ld1bss_r, NULL, NULL, NULL },
5079 { gen_helper_sve_ld1bhs_r, NULL, NULL, NULL },
5080 { gen_helper_sve_ld1dd_le_r, gen_helper_sve_ld2dd_le_r,
5081 gen_helper_sve_ld3dd_le_r, gen_helper_sve_ld4dd_le_r } },
5082
5083 /* mte inactive, big-endian */
5084 { { gen_helper_sve_ld1bb_r, gen_helper_sve_ld2bb_r,
5085 gen_helper_sve_ld3bb_r, gen_helper_sve_ld4bb_r },
5086 { gen_helper_sve_ld1bhu_r, NULL, NULL, NULL },
5087 { gen_helper_sve_ld1bsu_r, NULL, NULL, NULL },
5088 { gen_helper_sve_ld1bdu_r, NULL, NULL, NULL },
5089
5090 { gen_helper_sve_ld1sds_be_r, NULL, NULL, NULL },
5091 { gen_helper_sve_ld1hh_be_r, gen_helper_sve_ld2hh_be_r,
5092 gen_helper_sve_ld3hh_be_r, gen_helper_sve_ld4hh_be_r },
5093 { gen_helper_sve_ld1hsu_be_r, NULL, NULL, NULL },
5094 { gen_helper_sve_ld1hdu_be_r, NULL, NULL, NULL },
5095
5096 { gen_helper_sve_ld1hds_be_r, NULL, NULL, NULL },
5097 { gen_helper_sve_ld1hss_be_r, NULL, NULL, NULL },
5098 { gen_helper_sve_ld1ss_be_r, gen_helper_sve_ld2ss_be_r,
5099 gen_helper_sve_ld3ss_be_r, gen_helper_sve_ld4ss_be_r },
5100 { gen_helper_sve_ld1sdu_be_r, NULL, NULL, NULL },
5101
5102 { gen_helper_sve_ld1bds_r, NULL, NULL, NULL },
5103 { gen_helper_sve_ld1bss_r, NULL, NULL, NULL },
5104 { gen_helper_sve_ld1bhs_r, NULL, NULL, NULL },
5105 { gen_helper_sve_ld1dd_be_r, gen_helper_sve_ld2dd_be_r,
5106 gen_helper_sve_ld3dd_be_r, gen_helper_sve_ld4dd_be_r } } },
5107
5108 { /* mte active, little-endian */
5109 { { gen_helper_sve_ld1bb_r_mte,
5110 gen_helper_sve_ld2bb_r_mte,
5111 gen_helper_sve_ld3bb_r_mte,
5112 gen_helper_sve_ld4bb_r_mte },
5113 { gen_helper_sve_ld1bhu_r_mte, NULL, NULL, NULL },
5114 { gen_helper_sve_ld1bsu_r_mte, NULL, NULL, NULL },
5115 { gen_helper_sve_ld1bdu_r_mte, NULL, NULL, NULL },
5116
5117 { gen_helper_sve_ld1sds_le_r_mte, NULL, NULL, NULL },
5118 { gen_helper_sve_ld1hh_le_r_mte,
5119 gen_helper_sve_ld2hh_le_r_mte,
5120 gen_helper_sve_ld3hh_le_r_mte,
5121 gen_helper_sve_ld4hh_le_r_mte },
5122 { gen_helper_sve_ld1hsu_le_r_mte, NULL, NULL, NULL },
5123 { gen_helper_sve_ld1hdu_le_r_mte, NULL, NULL, NULL },
5124
5125 { gen_helper_sve_ld1hds_le_r_mte, NULL, NULL, NULL },
5126 { gen_helper_sve_ld1hss_le_r_mte, NULL, NULL, NULL },
5127 { gen_helper_sve_ld1ss_le_r_mte,
5128 gen_helper_sve_ld2ss_le_r_mte,
5129 gen_helper_sve_ld3ss_le_r_mte,
5130 gen_helper_sve_ld4ss_le_r_mte },
5131 { gen_helper_sve_ld1sdu_le_r_mte, NULL, NULL, NULL },
5132
5133 { gen_helper_sve_ld1bds_r_mte, NULL, NULL, NULL },
5134 { gen_helper_sve_ld1bss_r_mte, NULL, NULL, NULL },
5135 { gen_helper_sve_ld1bhs_r_mte, NULL, NULL, NULL },
5136 { gen_helper_sve_ld1dd_le_r_mte,
5137 gen_helper_sve_ld2dd_le_r_mte,
5138 gen_helper_sve_ld3dd_le_r_mte,
5139 gen_helper_sve_ld4dd_le_r_mte } },
5140
5141 /* mte active, big-endian */
5142 { { gen_helper_sve_ld1bb_r_mte,
5143 gen_helper_sve_ld2bb_r_mte,
5144 gen_helper_sve_ld3bb_r_mte,
5145 gen_helper_sve_ld4bb_r_mte },
5146 { gen_helper_sve_ld1bhu_r_mte, NULL, NULL, NULL },
5147 { gen_helper_sve_ld1bsu_r_mte, NULL, NULL, NULL },
5148 { gen_helper_sve_ld1bdu_r_mte, NULL, NULL, NULL },
5149
5150 { gen_helper_sve_ld1sds_be_r_mte, NULL, NULL, NULL },
5151 { gen_helper_sve_ld1hh_be_r_mte,
5152 gen_helper_sve_ld2hh_be_r_mte,
5153 gen_helper_sve_ld3hh_be_r_mte,
5154 gen_helper_sve_ld4hh_be_r_mte },
5155 { gen_helper_sve_ld1hsu_be_r_mte, NULL, NULL, NULL },
5156 { gen_helper_sve_ld1hdu_be_r_mte, NULL, NULL, NULL },
5157
5158 { gen_helper_sve_ld1hds_be_r_mte, NULL, NULL, NULL },
5159 { gen_helper_sve_ld1hss_be_r_mte, NULL, NULL, NULL },
5160 { gen_helper_sve_ld1ss_be_r_mte,
5161 gen_helper_sve_ld2ss_be_r_mte,
5162 gen_helper_sve_ld3ss_be_r_mte,
5163 gen_helper_sve_ld4ss_be_r_mte },
5164 { gen_helper_sve_ld1sdu_be_r_mte, NULL, NULL, NULL },
5165
5166 { gen_helper_sve_ld1bds_r_mte, NULL, NULL, NULL },
5167 { gen_helper_sve_ld1bss_r_mte, NULL, NULL, NULL },
5168 { gen_helper_sve_ld1bhs_r_mte, NULL, NULL, NULL },
5169 { gen_helper_sve_ld1dd_be_r_mte,
5170 gen_helper_sve_ld2dd_be_r_mte,
5171 gen_helper_sve_ld3dd_be_r_mte,
5172 gen_helper_sve_ld4dd_be_r_mte } } },
5173};
5174
c4e7c493
RH
5175static void do_ld_zpa(DisasContext *s, int zt, int pg,
5176 TCGv_i64 addr, int dtype, int nreg)
5177{
206adacf 5178 gen_helper_gvec_mem *fn
c182c6db 5179 = ldr_fns[s->mte_active[0]][s->be_data == MO_BE][dtype][nreg];
c4e7c493 5180
206adacf
RH
5181 /*
5182 * While there are holes in the table, they are not
c4e7c493
RH
5183 * accessible via the instruction encoding.
5184 */
5185 assert(fn != NULL);
206adacf 5186 do_mem_zpa(s, zt, pg, addr, dtype, nreg, false, fn);
c4e7c493
RH
5187}
5188
3a7be554 5189static bool trans_LD_zprr(DisasContext *s, arg_rprr_load *a)
c4e7c493
RH
5190{
5191 if (a->rm == 31) {
5192 return false;
5193 }
5194 if (sve_access_check(s)) {
5195 TCGv_i64 addr = new_tmp_a64(s);
50ef1cbf 5196 tcg_gen_shli_i64(addr, cpu_reg(s, a->rm), dtype_msz(a->dtype));
c4e7c493
RH
5197 tcg_gen_add_i64(addr, addr, cpu_reg_sp(s, a->rn));
5198 do_ld_zpa(s, a->rd, a->pg, addr, a->dtype, a->nreg);
5199 }
5200 return true;
5201}
5202
3a7be554 5203static bool trans_LD_zpri(DisasContext *s, arg_rpri_load *a)
c4e7c493
RH
5204{
5205 if (sve_access_check(s)) {
5206 int vsz = vec_full_reg_size(s);
5207 int elements = vsz >> dtype_esz[a->dtype];
5208 TCGv_i64 addr = new_tmp_a64(s);
5209
5210 tcg_gen_addi_i64(addr, cpu_reg_sp(s, a->rn),
5211 (a->imm * elements * (a->nreg + 1))
5212 << dtype_msz(a->dtype));
5213 do_ld_zpa(s, a->rd, a->pg, addr, a->dtype, a->nreg);
5214 }
5215 return true;
5216}
e2654d75 5217
3a7be554 5218static bool trans_LDFF1_zprr(DisasContext *s, arg_rprr_load *a)
e2654d75 5219{
aa13f7c3
RH
5220 static gen_helper_gvec_mem * const fns[2][2][16] = {
5221 { /* mte inactive, little-endian */
5222 { gen_helper_sve_ldff1bb_r,
5223 gen_helper_sve_ldff1bhu_r,
5224 gen_helper_sve_ldff1bsu_r,
5225 gen_helper_sve_ldff1bdu_r,
5226
5227 gen_helper_sve_ldff1sds_le_r,
5228 gen_helper_sve_ldff1hh_le_r,
5229 gen_helper_sve_ldff1hsu_le_r,
5230 gen_helper_sve_ldff1hdu_le_r,
5231
5232 gen_helper_sve_ldff1hds_le_r,
5233 gen_helper_sve_ldff1hss_le_r,
5234 gen_helper_sve_ldff1ss_le_r,
5235 gen_helper_sve_ldff1sdu_le_r,
5236
5237 gen_helper_sve_ldff1bds_r,
5238 gen_helper_sve_ldff1bss_r,
5239 gen_helper_sve_ldff1bhs_r,
5240 gen_helper_sve_ldff1dd_le_r },
5241
5242 /* mte inactive, big-endian */
5243 { gen_helper_sve_ldff1bb_r,
5244 gen_helper_sve_ldff1bhu_r,
5245 gen_helper_sve_ldff1bsu_r,
5246 gen_helper_sve_ldff1bdu_r,
5247
5248 gen_helper_sve_ldff1sds_be_r,
5249 gen_helper_sve_ldff1hh_be_r,
5250 gen_helper_sve_ldff1hsu_be_r,
5251 gen_helper_sve_ldff1hdu_be_r,
5252
5253 gen_helper_sve_ldff1hds_be_r,
5254 gen_helper_sve_ldff1hss_be_r,
5255 gen_helper_sve_ldff1ss_be_r,
5256 gen_helper_sve_ldff1sdu_be_r,
5257
5258 gen_helper_sve_ldff1bds_r,
5259 gen_helper_sve_ldff1bss_r,
5260 gen_helper_sve_ldff1bhs_r,
5261 gen_helper_sve_ldff1dd_be_r } },
5262
5263 { /* mte active, little-endian */
5264 { gen_helper_sve_ldff1bb_r_mte,
5265 gen_helper_sve_ldff1bhu_r_mte,
5266 gen_helper_sve_ldff1bsu_r_mte,
5267 gen_helper_sve_ldff1bdu_r_mte,
5268
5269 gen_helper_sve_ldff1sds_le_r_mte,
5270 gen_helper_sve_ldff1hh_le_r_mte,
5271 gen_helper_sve_ldff1hsu_le_r_mte,
5272 gen_helper_sve_ldff1hdu_le_r_mte,
5273
5274 gen_helper_sve_ldff1hds_le_r_mte,
5275 gen_helper_sve_ldff1hss_le_r_mte,
5276 gen_helper_sve_ldff1ss_le_r_mte,
5277 gen_helper_sve_ldff1sdu_le_r_mte,
5278
5279 gen_helper_sve_ldff1bds_r_mte,
5280 gen_helper_sve_ldff1bss_r_mte,
5281 gen_helper_sve_ldff1bhs_r_mte,
5282 gen_helper_sve_ldff1dd_le_r_mte },
5283
5284 /* mte active, big-endian */
5285 { gen_helper_sve_ldff1bb_r_mte,
5286 gen_helper_sve_ldff1bhu_r_mte,
5287 gen_helper_sve_ldff1bsu_r_mte,
5288 gen_helper_sve_ldff1bdu_r_mte,
5289
5290 gen_helper_sve_ldff1sds_be_r_mte,
5291 gen_helper_sve_ldff1hh_be_r_mte,
5292 gen_helper_sve_ldff1hsu_be_r_mte,
5293 gen_helper_sve_ldff1hdu_be_r_mte,
5294
5295 gen_helper_sve_ldff1hds_be_r_mte,
5296 gen_helper_sve_ldff1hss_be_r_mte,
5297 gen_helper_sve_ldff1ss_be_r_mte,
5298 gen_helper_sve_ldff1sdu_be_r_mte,
5299
5300 gen_helper_sve_ldff1bds_r_mte,
5301 gen_helper_sve_ldff1bss_r_mte,
5302 gen_helper_sve_ldff1bhs_r_mte,
5303 gen_helper_sve_ldff1dd_be_r_mte } },
e2654d75
RH
5304 };
5305
5306 if (sve_access_check(s)) {
5307 TCGv_i64 addr = new_tmp_a64(s);
5308 tcg_gen_shli_i64(addr, cpu_reg(s, a->rm), dtype_msz(a->dtype));
5309 tcg_gen_add_i64(addr, addr, cpu_reg_sp(s, a->rn));
aa13f7c3
RH
5310 do_mem_zpa(s, a->rd, a->pg, addr, a->dtype, 1, false,
5311 fns[s->mte_active[0]][s->be_data == MO_BE][a->dtype]);
e2654d75
RH
5312 }
5313 return true;
5314}
5315
3a7be554 5316static bool trans_LDNF1_zpri(DisasContext *s, arg_rpri_load *a)
e2654d75 5317{
aa13f7c3
RH
5318 static gen_helper_gvec_mem * const fns[2][2][16] = {
5319 { /* mte inactive, little-endian */
5320 { gen_helper_sve_ldnf1bb_r,
5321 gen_helper_sve_ldnf1bhu_r,
5322 gen_helper_sve_ldnf1bsu_r,
5323 gen_helper_sve_ldnf1bdu_r,
5324
5325 gen_helper_sve_ldnf1sds_le_r,
5326 gen_helper_sve_ldnf1hh_le_r,
5327 gen_helper_sve_ldnf1hsu_le_r,
5328 gen_helper_sve_ldnf1hdu_le_r,
5329
5330 gen_helper_sve_ldnf1hds_le_r,
5331 gen_helper_sve_ldnf1hss_le_r,
5332 gen_helper_sve_ldnf1ss_le_r,
5333 gen_helper_sve_ldnf1sdu_le_r,
5334
5335 gen_helper_sve_ldnf1bds_r,
5336 gen_helper_sve_ldnf1bss_r,
5337 gen_helper_sve_ldnf1bhs_r,
5338 gen_helper_sve_ldnf1dd_le_r },
5339
5340 /* mte inactive, big-endian */
5341 { gen_helper_sve_ldnf1bb_r,
5342 gen_helper_sve_ldnf1bhu_r,
5343 gen_helper_sve_ldnf1bsu_r,
5344 gen_helper_sve_ldnf1bdu_r,
5345
5346 gen_helper_sve_ldnf1sds_be_r,
5347 gen_helper_sve_ldnf1hh_be_r,
5348 gen_helper_sve_ldnf1hsu_be_r,
5349 gen_helper_sve_ldnf1hdu_be_r,
5350
5351 gen_helper_sve_ldnf1hds_be_r,
5352 gen_helper_sve_ldnf1hss_be_r,
5353 gen_helper_sve_ldnf1ss_be_r,
5354 gen_helper_sve_ldnf1sdu_be_r,
5355
5356 gen_helper_sve_ldnf1bds_r,
5357 gen_helper_sve_ldnf1bss_r,
5358 gen_helper_sve_ldnf1bhs_r,
5359 gen_helper_sve_ldnf1dd_be_r } },
5360
5361 { /* mte inactive, little-endian */
5362 { gen_helper_sve_ldnf1bb_r_mte,
5363 gen_helper_sve_ldnf1bhu_r_mte,
5364 gen_helper_sve_ldnf1bsu_r_mte,
5365 gen_helper_sve_ldnf1bdu_r_mte,
5366
5367 gen_helper_sve_ldnf1sds_le_r_mte,
5368 gen_helper_sve_ldnf1hh_le_r_mte,
5369 gen_helper_sve_ldnf1hsu_le_r_mte,
5370 gen_helper_sve_ldnf1hdu_le_r_mte,
5371
5372 gen_helper_sve_ldnf1hds_le_r_mte,
5373 gen_helper_sve_ldnf1hss_le_r_mte,
5374 gen_helper_sve_ldnf1ss_le_r_mte,
5375 gen_helper_sve_ldnf1sdu_le_r_mte,
5376
5377 gen_helper_sve_ldnf1bds_r_mte,
5378 gen_helper_sve_ldnf1bss_r_mte,
5379 gen_helper_sve_ldnf1bhs_r_mte,
5380 gen_helper_sve_ldnf1dd_le_r_mte },
5381
5382 /* mte inactive, big-endian */
5383 { gen_helper_sve_ldnf1bb_r_mte,
5384 gen_helper_sve_ldnf1bhu_r_mte,
5385 gen_helper_sve_ldnf1bsu_r_mte,
5386 gen_helper_sve_ldnf1bdu_r_mte,
5387
5388 gen_helper_sve_ldnf1sds_be_r_mte,
5389 gen_helper_sve_ldnf1hh_be_r_mte,
5390 gen_helper_sve_ldnf1hsu_be_r_mte,
5391 gen_helper_sve_ldnf1hdu_be_r_mte,
5392
5393 gen_helper_sve_ldnf1hds_be_r_mte,
5394 gen_helper_sve_ldnf1hss_be_r_mte,
5395 gen_helper_sve_ldnf1ss_be_r_mte,
5396 gen_helper_sve_ldnf1sdu_be_r_mte,
5397
5398 gen_helper_sve_ldnf1bds_r_mte,
5399 gen_helper_sve_ldnf1bss_r_mte,
5400 gen_helper_sve_ldnf1bhs_r_mte,
5401 gen_helper_sve_ldnf1dd_be_r_mte } },
e2654d75
RH
5402 };
5403
5404 if (sve_access_check(s)) {
5405 int vsz = vec_full_reg_size(s);
5406 int elements = vsz >> dtype_esz[a->dtype];
5407 int off = (a->imm * elements) << dtype_msz(a->dtype);
5408 TCGv_i64 addr = new_tmp_a64(s);
5409
5410 tcg_gen_addi_i64(addr, cpu_reg_sp(s, a->rn), off);
aa13f7c3
RH
5411 do_mem_zpa(s, a->rd, a->pg, addr, a->dtype, 1, false,
5412 fns[s->mte_active[0]][s->be_data == MO_BE][a->dtype]);
e2654d75
RH
5413 }
5414 return true;
5415}
1a039c7e 5416
c182c6db 5417static void do_ldrq(DisasContext *s, int zt, int pg, TCGv_i64 addr, int dtype)
05abe304 5418{
05abe304
RH
5419 unsigned vsz = vec_full_reg_size(s);
5420 TCGv_ptr t_pg;
7924d239 5421 int poff;
05abe304
RH
5422
5423 /* Load the first quadword using the normal predicated load helpers. */
2a99ab2b
RH
5424 poff = pred_full_reg_offset(s, pg);
5425 if (vsz > 16) {
5426 /*
5427 * Zero-extend the first 16 bits of the predicate into a temporary.
5428 * This avoids triggering an assert making sure we don't have bits
5429 * set within a predicate beyond VQ, but we have lowered VQ to 1
5430 * for this load operation.
5431 */
5432 TCGv_i64 tmp = tcg_temp_new_i64();
e03b5686 5433#if HOST_BIG_ENDIAN
2a99ab2b
RH
5434 poff += 6;
5435#endif
5436 tcg_gen_ld16u_i64(tmp, cpu_env, poff);
5437
5438 poff = offsetof(CPUARMState, vfp.preg_tmp);
5439 tcg_gen_st_i64(tmp, cpu_env, poff);
5440 tcg_temp_free_i64(tmp);
5441 }
5442
05abe304 5443 t_pg = tcg_temp_new_ptr();
2a99ab2b 5444 tcg_gen_addi_ptr(t_pg, cpu_env, poff);
05abe304 5445
c182c6db
RH
5446 gen_helper_gvec_mem *fn
5447 = ldr_fns[s->mte_active[0]][s->be_data == MO_BE][dtype][0];
7924d239 5448 fn(cpu_env, t_pg, addr, tcg_constant_i32(simd_desc(16, 16, zt)));
05abe304
RH
5449
5450 tcg_temp_free_ptr(t_pg);
05abe304
RH
5451
5452 /* Replicate that first quadword. */
5453 if (vsz > 16) {
7924d239
RH
5454 int doff = vec_full_reg_offset(s, zt);
5455 tcg_gen_gvec_dup_mem(4, doff + 16, doff, vsz - 16, vsz - 16);
05abe304
RH
5456 }
5457}
5458
3a7be554 5459static bool trans_LD1RQ_zprr(DisasContext *s, arg_rprr_load *a)
05abe304
RH
5460{
5461 if (a->rm == 31) {
5462 return false;
5463 }
5464 if (sve_access_check(s)) {
5465 int msz = dtype_msz(a->dtype);
5466 TCGv_i64 addr = new_tmp_a64(s);
5467 tcg_gen_shli_i64(addr, cpu_reg(s, a->rm), msz);
5468 tcg_gen_add_i64(addr, addr, cpu_reg_sp(s, a->rn));
c182c6db 5469 do_ldrq(s, a->rd, a->pg, addr, a->dtype);
05abe304
RH
5470 }
5471 return true;
5472}
5473
3a7be554 5474static bool trans_LD1RQ_zpri(DisasContext *s, arg_rpri_load *a)
05abe304
RH
5475{
5476 if (sve_access_check(s)) {
5477 TCGv_i64 addr = new_tmp_a64(s);
5478 tcg_gen_addi_i64(addr, cpu_reg_sp(s, a->rn), a->imm * 16);
c182c6db 5479 do_ldrq(s, a->rd, a->pg, addr, a->dtype);
05abe304
RH
5480 }
5481 return true;
5482}
5483
12c563f6
RH
5484static void do_ldro(DisasContext *s, int zt, int pg, TCGv_i64 addr, int dtype)
5485{
5486 unsigned vsz = vec_full_reg_size(s);
5487 unsigned vsz_r32;
5488 TCGv_ptr t_pg;
5489 int poff, doff;
5490
5491 if (vsz < 32) {
5492 /*
5493 * Note that this UNDEFINED check comes after CheckSVEEnabled()
5494 * in the ARM pseudocode, which is the sve_access_check() done
5495 * in our caller. We should not now return false from the caller.
5496 */
5497 unallocated_encoding(s);
5498 return;
5499 }
5500
5501 /* Load the first octaword using the normal predicated load helpers. */
5502
5503 poff = pred_full_reg_offset(s, pg);
5504 if (vsz > 32) {
5505 /*
5506 * Zero-extend the first 32 bits of the predicate into a temporary.
5507 * This avoids triggering an assert making sure we don't have bits
5508 * set within a predicate beyond VQ, but we have lowered VQ to 2
5509 * for this load operation.
5510 */
5511 TCGv_i64 tmp = tcg_temp_new_i64();
e03b5686 5512#if HOST_BIG_ENDIAN
12c563f6
RH
5513 poff += 4;
5514#endif
5515 tcg_gen_ld32u_i64(tmp, cpu_env, poff);
5516
5517 poff = offsetof(CPUARMState, vfp.preg_tmp);
5518 tcg_gen_st_i64(tmp, cpu_env, poff);
5519 tcg_temp_free_i64(tmp);
5520 }
5521
5522 t_pg = tcg_temp_new_ptr();
5523 tcg_gen_addi_ptr(t_pg, cpu_env, poff);
5524
5525 gen_helper_gvec_mem *fn
5526 = ldr_fns[s->mte_active[0]][s->be_data == MO_BE][dtype][0];
5527 fn(cpu_env, t_pg, addr, tcg_constant_i32(simd_desc(32, 32, zt)));
5528
5529 tcg_temp_free_ptr(t_pg);
5530
5531 /*
5532 * Replicate that first octaword.
5533 * The replication happens in units of 32; if the full vector size
5534 * is not a multiple of 32, the final bits are zeroed.
5535 */
5536 doff = vec_full_reg_offset(s, zt);
5537 vsz_r32 = QEMU_ALIGN_DOWN(vsz, 32);
5538 if (vsz >= 64) {
5539 tcg_gen_gvec_dup_mem(5, doff + 32, doff, vsz_r32 - 32, vsz_r32 - 32);
5540 }
5541 vsz -= vsz_r32;
5542 if (vsz) {
5543 tcg_gen_gvec_dup_imm(MO_64, doff + vsz_r32, vsz, vsz, 0);
5544 }
5545}
5546
5547static bool trans_LD1RO_zprr(DisasContext *s, arg_rprr_load *a)
5548{
5549 if (!dc_isar_feature(aa64_sve_f64mm, s)) {
5550 return false;
5551 }
5552 if (a->rm == 31) {
5553 return false;
5554 }
5555 if (sve_access_check(s)) {
5556 TCGv_i64 addr = new_tmp_a64(s);
5557 tcg_gen_shli_i64(addr, cpu_reg(s, a->rm), dtype_msz(a->dtype));
5558 tcg_gen_add_i64(addr, addr, cpu_reg_sp(s, a->rn));
5559 do_ldro(s, a->rd, a->pg, addr, a->dtype);
5560 }
5561 return true;
5562}
5563
5564static bool trans_LD1RO_zpri(DisasContext *s, arg_rpri_load *a)
5565{
5566 if (!dc_isar_feature(aa64_sve_f64mm, s)) {
5567 return false;
5568 }
5569 if (sve_access_check(s)) {
5570 TCGv_i64 addr = new_tmp_a64(s);
5571 tcg_gen_addi_i64(addr, cpu_reg_sp(s, a->rn), a->imm * 32);
5572 do_ldro(s, a->rd, a->pg, addr, a->dtype);
5573 }
5574 return true;
5575}
5576
68459864 5577/* Load and broadcast element. */
3a7be554 5578static bool trans_LD1R_zpri(DisasContext *s, arg_rpri_load *a)
68459864 5579{
68459864
RH
5580 unsigned vsz = vec_full_reg_size(s);
5581 unsigned psz = pred_full_reg_size(s);
5582 unsigned esz = dtype_esz[a->dtype];
d0e372b0 5583 unsigned msz = dtype_msz(a->dtype);
c0ed9166 5584 TCGLabel *over;
4ac430e1 5585 TCGv_i64 temp, clean_addr;
68459864 5586
c0ed9166
RH
5587 if (!sve_access_check(s)) {
5588 return true;
5589 }
5590
5591 over = gen_new_label();
5592
68459864
RH
5593 /* If the guarding predicate has no bits set, no load occurs. */
5594 if (psz <= 8) {
5595 /* Reduce the pred_esz_masks value simply to reduce the
5596 * size of the code generated here.
5597 */
5598 uint64_t psz_mask = MAKE_64BIT_MASK(0, psz * 8);
5599 temp = tcg_temp_new_i64();
5600 tcg_gen_ld_i64(temp, cpu_env, pred_full_reg_offset(s, a->pg));
5601 tcg_gen_andi_i64(temp, temp, pred_esz_masks[esz] & psz_mask);
5602 tcg_gen_brcondi_i64(TCG_COND_EQ, temp, 0, over);
5603 tcg_temp_free_i64(temp);
5604 } else {
5605 TCGv_i32 t32 = tcg_temp_new_i32();
5606 find_last_active(s, t32, esz, a->pg);
5607 tcg_gen_brcondi_i32(TCG_COND_LT, t32, 0, over);
5608 tcg_temp_free_i32(t32);
5609 }
5610
5611 /* Load the data. */
5612 temp = tcg_temp_new_i64();
d0e372b0 5613 tcg_gen_addi_i64(temp, cpu_reg_sp(s, a->rn), a->imm << msz);
4ac430e1
RH
5614 clean_addr = gen_mte_check1(s, temp, false, true, msz);
5615
5616 tcg_gen_qemu_ld_i64(temp, clean_addr, get_mem_index(s),
0ca0f872 5617 finalize_memop(s, dtype_mop[a->dtype]));
68459864
RH
5618
5619 /* Broadcast to *all* elements. */
5620 tcg_gen_gvec_dup_i64(esz, vec_full_reg_offset(s, a->rd),
5621 vsz, vsz, temp);
5622 tcg_temp_free_i64(temp);
5623
5624 /* Zero the inactive elements. */
5625 gen_set_label(over);
60245996 5626 return do_movz_zpz(s, a->rd, a->rd, a->pg, esz, false);
68459864
RH
5627}
5628
1a039c7e
RH
5629static void do_st_zpa(DisasContext *s, int zt, int pg, TCGv_i64 addr,
5630 int msz, int esz, int nreg)
5631{
71b9f394
RH
5632 static gen_helper_gvec_mem * const fn_single[2][2][4][4] = {
5633 { { { gen_helper_sve_st1bb_r,
5634 gen_helper_sve_st1bh_r,
5635 gen_helper_sve_st1bs_r,
5636 gen_helper_sve_st1bd_r },
5637 { NULL,
5638 gen_helper_sve_st1hh_le_r,
5639 gen_helper_sve_st1hs_le_r,
5640 gen_helper_sve_st1hd_le_r },
5641 { NULL, NULL,
5642 gen_helper_sve_st1ss_le_r,
5643 gen_helper_sve_st1sd_le_r },
5644 { NULL, NULL, NULL,
5645 gen_helper_sve_st1dd_le_r } },
5646 { { gen_helper_sve_st1bb_r,
5647 gen_helper_sve_st1bh_r,
5648 gen_helper_sve_st1bs_r,
5649 gen_helper_sve_st1bd_r },
5650 { NULL,
5651 gen_helper_sve_st1hh_be_r,
5652 gen_helper_sve_st1hs_be_r,
5653 gen_helper_sve_st1hd_be_r },
5654 { NULL, NULL,
5655 gen_helper_sve_st1ss_be_r,
5656 gen_helper_sve_st1sd_be_r },
5657 { NULL, NULL, NULL,
5658 gen_helper_sve_st1dd_be_r } } },
5659
5660 { { { gen_helper_sve_st1bb_r_mte,
5661 gen_helper_sve_st1bh_r_mte,
5662 gen_helper_sve_st1bs_r_mte,
5663 gen_helper_sve_st1bd_r_mte },
5664 { NULL,
5665 gen_helper_sve_st1hh_le_r_mte,
5666 gen_helper_sve_st1hs_le_r_mte,
5667 gen_helper_sve_st1hd_le_r_mte },
5668 { NULL, NULL,
5669 gen_helper_sve_st1ss_le_r_mte,
5670 gen_helper_sve_st1sd_le_r_mte },
5671 { NULL, NULL, NULL,
5672 gen_helper_sve_st1dd_le_r_mte } },
5673 { { gen_helper_sve_st1bb_r_mte,
5674 gen_helper_sve_st1bh_r_mte,
5675 gen_helper_sve_st1bs_r_mte,
5676 gen_helper_sve_st1bd_r_mte },
5677 { NULL,
5678 gen_helper_sve_st1hh_be_r_mte,
5679 gen_helper_sve_st1hs_be_r_mte,
5680 gen_helper_sve_st1hd_be_r_mte },
5681 { NULL, NULL,
5682 gen_helper_sve_st1ss_be_r_mte,
5683 gen_helper_sve_st1sd_be_r_mte },
5684 { NULL, NULL, NULL,
5685 gen_helper_sve_st1dd_be_r_mte } } },
1a039c7e 5686 };
71b9f394
RH
5687 static gen_helper_gvec_mem * const fn_multiple[2][2][3][4] = {
5688 { { { gen_helper_sve_st2bb_r,
5689 gen_helper_sve_st2hh_le_r,
5690 gen_helper_sve_st2ss_le_r,
5691 gen_helper_sve_st2dd_le_r },
5692 { gen_helper_sve_st3bb_r,
5693 gen_helper_sve_st3hh_le_r,
5694 gen_helper_sve_st3ss_le_r,
5695 gen_helper_sve_st3dd_le_r },
5696 { gen_helper_sve_st4bb_r,
5697 gen_helper_sve_st4hh_le_r,
5698 gen_helper_sve_st4ss_le_r,
5699 gen_helper_sve_st4dd_le_r } },
5700 { { gen_helper_sve_st2bb_r,
5701 gen_helper_sve_st2hh_be_r,
5702 gen_helper_sve_st2ss_be_r,
5703 gen_helper_sve_st2dd_be_r },
5704 { gen_helper_sve_st3bb_r,
5705 gen_helper_sve_st3hh_be_r,
5706 gen_helper_sve_st3ss_be_r,
5707 gen_helper_sve_st3dd_be_r },
5708 { gen_helper_sve_st4bb_r,
5709 gen_helper_sve_st4hh_be_r,
5710 gen_helper_sve_st4ss_be_r,
5711 gen_helper_sve_st4dd_be_r } } },
5712 { { { gen_helper_sve_st2bb_r_mte,
5713 gen_helper_sve_st2hh_le_r_mte,
5714 gen_helper_sve_st2ss_le_r_mte,
5715 gen_helper_sve_st2dd_le_r_mte },
5716 { gen_helper_sve_st3bb_r_mte,
5717 gen_helper_sve_st3hh_le_r_mte,
5718 gen_helper_sve_st3ss_le_r_mte,
5719 gen_helper_sve_st3dd_le_r_mte },
5720 { gen_helper_sve_st4bb_r_mte,
5721 gen_helper_sve_st4hh_le_r_mte,
5722 gen_helper_sve_st4ss_le_r_mte,
5723 gen_helper_sve_st4dd_le_r_mte } },
5724 { { gen_helper_sve_st2bb_r_mte,
5725 gen_helper_sve_st2hh_be_r_mte,
5726 gen_helper_sve_st2ss_be_r_mte,
5727 gen_helper_sve_st2dd_be_r_mte },
5728 { gen_helper_sve_st3bb_r_mte,
5729 gen_helper_sve_st3hh_be_r_mte,
5730 gen_helper_sve_st3ss_be_r_mte,
5731 gen_helper_sve_st3dd_be_r_mte },
5732 { gen_helper_sve_st4bb_r_mte,
5733 gen_helper_sve_st4hh_be_r_mte,
5734 gen_helper_sve_st4ss_be_r_mte,
5735 gen_helper_sve_st4dd_be_r_mte } } },
1a039c7e
RH
5736 };
5737 gen_helper_gvec_mem *fn;
28d57f2d 5738 int be = s->be_data == MO_BE;
1a039c7e
RH
5739
5740 if (nreg == 0) {
5741 /* ST1 */
71b9f394
RH
5742 fn = fn_single[s->mte_active[0]][be][msz][esz];
5743 nreg = 1;
1a039c7e
RH
5744 } else {
5745 /* ST2, ST3, ST4 -- msz == esz, enforced by encoding */
5746 assert(msz == esz);
71b9f394 5747 fn = fn_multiple[s->mte_active[0]][be][nreg - 1][msz];
1a039c7e
RH
5748 }
5749 assert(fn != NULL);
71b9f394 5750 do_mem_zpa(s, zt, pg, addr, msz_dtype(s, msz), nreg, true, fn);
1a039c7e
RH
5751}
5752
3a7be554 5753static bool trans_ST_zprr(DisasContext *s, arg_rprr_store *a)
1a039c7e
RH
5754{
5755 if (a->rm == 31 || a->msz > a->esz) {
5756 return false;
5757 }
5758 if (sve_access_check(s)) {
5759 TCGv_i64 addr = new_tmp_a64(s);
50ef1cbf 5760 tcg_gen_shli_i64(addr, cpu_reg(s, a->rm), a->msz);
1a039c7e
RH
5761 tcg_gen_add_i64(addr, addr, cpu_reg_sp(s, a->rn));
5762 do_st_zpa(s, a->rd, a->pg, addr, a->msz, a->esz, a->nreg);
5763 }
5764 return true;
5765}
5766
3a7be554 5767static bool trans_ST_zpri(DisasContext *s, arg_rpri_store *a)
1a039c7e
RH
5768{
5769 if (a->msz > a->esz) {
5770 return false;
5771 }
5772 if (sve_access_check(s)) {
5773 int vsz = vec_full_reg_size(s);
5774 int elements = vsz >> a->esz;
5775 TCGv_i64 addr = new_tmp_a64(s);
5776
5777 tcg_gen_addi_i64(addr, cpu_reg_sp(s, a->rn),
5778 (a->imm * elements * (a->nreg + 1)) << a->msz);
5779 do_st_zpa(s, a->rd, a->pg, addr, a->msz, a->esz, a->nreg);
5780 }
5781 return true;
5782}
f6dbf62a
RH
5783
5784/*
5785 *** SVE gather loads / scatter stores
5786 */
5787
500d0484 5788static void do_mem_zpz(DisasContext *s, int zt, int pg, int zm,
d28d12f0 5789 int scale, TCGv_i64 scalar, int msz, bool is_write,
500d0484 5790 gen_helper_gvec_mem_scatter *fn)
f6dbf62a
RH
5791{
5792 unsigned vsz = vec_full_reg_size(s);
f6dbf62a
RH
5793 TCGv_ptr t_zm = tcg_temp_new_ptr();
5794 TCGv_ptr t_pg = tcg_temp_new_ptr();
5795 TCGv_ptr t_zt = tcg_temp_new_ptr();
d28d12f0 5796 int desc = 0;
500d0484 5797
d28d12f0
RH
5798 if (s->mte_active[0]) {
5799 desc = FIELD_DP32(desc, MTEDESC, MIDX, get_mem_index(s));
5800 desc = FIELD_DP32(desc, MTEDESC, TBI, s->tbid);
5801 desc = FIELD_DP32(desc, MTEDESC, TCMA, s->tcma);
5802 desc = FIELD_DP32(desc, MTEDESC, WRITE, is_write);
28f32503 5803 desc = FIELD_DP32(desc, MTEDESC, SIZEM1, (1 << msz) - 1);
d28d12f0
RH
5804 desc <<= SVE_MTEDESC_SHIFT;
5805 }
cdecb3fc 5806 desc = simd_desc(vsz, vsz, desc | scale);
f6dbf62a
RH
5807
5808 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, pg));
5809 tcg_gen_addi_ptr(t_zm, cpu_env, vec_full_reg_offset(s, zm));
5810 tcg_gen_addi_ptr(t_zt, cpu_env, vec_full_reg_offset(s, zt));
c6a59b55 5811 fn(cpu_env, t_zt, t_pg, t_zm, scalar, tcg_constant_i32(desc));
f6dbf62a
RH
5812
5813 tcg_temp_free_ptr(t_zt);
5814 tcg_temp_free_ptr(t_zm);
5815 tcg_temp_free_ptr(t_pg);
f6dbf62a
RH
5816}
5817
d28d12f0
RH
5818/* Indexed by [mte][be][ff][xs][u][msz]. */
5819static gen_helper_gvec_mem_scatter * const
5820gather_load_fn32[2][2][2][2][2][3] = {
5821 { /* MTE Inactive */
5822 { /* Little-endian */
5823 { { { gen_helper_sve_ldbss_zsu,
5824 gen_helper_sve_ldhss_le_zsu,
5825 NULL, },
5826 { gen_helper_sve_ldbsu_zsu,
5827 gen_helper_sve_ldhsu_le_zsu,
5828 gen_helper_sve_ldss_le_zsu, } },
5829 { { gen_helper_sve_ldbss_zss,
5830 gen_helper_sve_ldhss_le_zss,
5831 NULL, },
5832 { gen_helper_sve_ldbsu_zss,
5833 gen_helper_sve_ldhsu_le_zss,
5834 gen_helper_sve_ldss_le_zss, } } },
5835
5836 /* First-fault */
5837 { { { gen_helper_sve_ldffbss_zsu,
5838 gen_helper_sve_ldffhss_le_zsu,
5839 NULL, },
5840 { gen_helper_sve_ldffbsu_zsu,
5841 gen_helper_sve_ldffhsu_le_zsu,
5842 gen_helper_sve_ldffss_le_zsu, } },
5843 { { gen_helper_sve_ldffbss_zss,
5844 gen_helper_sve_ldffhss_le_zss,
5845 NULL, },
5846 { gen_helper_sve_ldffbsu_zss,
5847 gen_helper_sve_ldffhsu_le_zss,
5848 gen_helper_sve_ldffss_le_zss, } } } },
5849
5850 { /* Big-endian */
5851 { { { gen_helper_sve_ldbss_zsu,
5852 gen_helper_sve_ldhss_be_zsu,
5853 NULL, },
5854 { gen_helper_sve_ldbsu_zsu,
5855 gen_helper_sve_ldhsu_be_zsu,
5856 gen_helper_sve_ldss_be_zsu, } },
5857 { { gen_helper_sve_ldbss_zss,
5858 gen_helper_sve_ldhss_be_zss,
5859 NULL, },
5860 { gen_helper_sve_ldbsu_zss,
5861 gen_helper_sve_ldhsu_be_zss,
5862 gen_helper_sve_ldss_be_zss, } } },
5863
5864 /* First-fault */
5865 { { { gen_helper_sve_ldffbss_zsu,
5866 gen_helper_sve_ldffhss_be_zsu,
5867 NULL, },
5868 { gen_helper_sve_ldffbsu_zsu,
5869 gen_helper_sve_ldffhsu_be_zsu,
5870 gen_helper_sve_ldffss_be_zsu, } },
5871 { { gen_helper_sve_ldffbss_zss,
5872 gen_helper_sve_ldffhss_be_zss,
5873 NULL, },
5874 { gen_helper_sve_ldffbsu_zss,
5875 gen_helper_sve_ldffhsu_be_zss,
5876 gen_helper_sve_ldffss_be_zss, } } } } },
5877 { /* MTE Active */
5878 { /* Little-endian */
5879 { { { gen_helper_sve_ldbss_zsu_mte,
5880 gen_helper_sve_ldhss_le_zsu_mte,
5881 NULL, },
5882 { gen_helper_sve_ldbsu_zsu_mte,
5883 gen_helper_sve_ldhsu_le_zsu_mte,
5884 gen_helper_sve_ldss_le_zsu_mte, } },
5885 { { gen_helper_sve_ldbss_zss_mte,
5886 gen_helper_sve_ldhss_le_zss_mte,
5887 NULL, },
5888 { gen_helper_sve_ldbsu_zss_mte,
5889 gen_helper_sve_ldhsu_le_zss_mte,
5890 gen_helper_sve_ldss_le_zss_mte, } } },
5891
5892 /* First-fault */
5893 { { { gen_helper_sve_ldffbss_zsu_mte,
5894 gen_helper_sve_ldffhss_le_zsu_mte,
5895 NULL, },
5896 { gen_helper_sve_ldffbsu_zsu_mte,
5897 gen_helper_sve_ldffhsu_le_zsu_mte,
5898 gen_helper_sve_ldffss_le_zsu_mte, } },
5899 { { gen_helper_sve_ldffbss_zss_mte,
5900 gen_helper_sve_ldffhss_le_zss_mte,
5901 NULL, },
5902 { gen_helper_sve_ldffbsu_zss_mte,
5903 gen_helper_sve_ldffhsu_le_zss_mte,
5904 gen_helper_sve_ldffss_le_zss_mte, } } } },
5905
5906 { /* Big-endian */
5907 { { { gen_helper_sve_ldbss_zsu_mte,
5908 gen_helper_sve_ldhss_be_zsu_mte,
5909 NULL, },
5910 { gen_helper_sve_ldbsu_zsu_mte,
5911 gen_helper_sve_ldhsu_be_zsu_mte,
5912 gen_helper_sve_ldss_be_zsu_mte, } },
5913 { { gen_helper_sve_ldbss_zss_mte,
5914 gen_helper_sve_ldhss_be_zss_mte,
5915 NULL, },
5916 { gen_helper_sve_ldbsu_zss_mte,
5917 gen_helper_sve_ldhsu_be_zss_mte,
5918 gen_helper_sve_ldss_be_zss_mte, } } },
5919
5920 /* First-fault */
5921 { { { gen_helper_sve_ldffbss_zsu_mte,
5922 gen_helper_sve_ldffhss_be_zsu_mte,
5923 NULL, },
5924 { gen_helper_sve_ldffbsu_zsu_mte,
5925 gen_helper_sve_ldffhsu_be_zsu_mte,
5926 gen_helper_sve_ldffss_be_zsu_mte, } },
5927 { { gen_helper_sve_ldffbss_zss_mte,
5928 gen_helper_sve_ldffhss_be_zss_mte,
5929 NULL, },
5930 { gen_helper_sve_ldffbsu_zss_mte,
5931 gen_helper_sve_ldffhsu_be_zss_mte,
5932 gen_helper_sve_ldffss_be_zss_mte, } } } } },
673e9fa6
RH
5933};
5934
5935/* Note that we overload xs=2 to indicate 64-bit offset. */
d28d12f0
RH
5936static gen_helper_gvec_mem_scatter * const
5937gather_load_fn64[2][2][2][3][2][4] = {
5938 { /* MTE Inactive */
5939 { /* Little-endian */
5940 { { { gen_helper_sve_ldbds_zsu,
5941 gen_helper_sve_ldhds_le_zsu,
5942 gen_helper_sve_ldsds_le_zsu,
5943 NULL, },
5944 { gen_helper_sve_ldbdu_zsu,
5945 gen_helper_sve_ldhdu_le_zsu,
5946 gen_helper_sve_ldsdu_le_zsu,
5947 gen_helper_sve_lddd_le_zsu, } },
5948 { { gen_helper_sve_ldbds_zss,
5949 gen_helper_sve_ldhds_le_zss,
5950 gen_helper_sve_ldsds_le_zss,
5951 NULL, },
5952 { gen_helper_sve_ldbdu_zss,
5953 gen_helper_sve_ldhdu_le_zss,
5954 gen_helper_sve_ldsdu_le_zss,
5955 gen_helper_sve_lddd_le_zss, } },
5956 { { gen_helper_sve_ldbds_zd,
5957 gen_helper_sve_ldhds_le_zd,
5958 gen_helper_sve_ldsds_le_zd,
5959 NULL, },
5960 { gen_helper_sve_ldbdu_zd,
5961 gen_helper_sve_ldhdu_le_zd,
5962 gen_helper_sve_ldsdu_le_zd,
5963 gen_helper_sve_lddd_le_zd, } } },
5964
5965 /* First-fault */
5966 { { { gen_helper_sve_ldffbds_zsu,
5967 gen_helper_sve_ldffhds_le_zsu,
5968 gen_helper_sve_ldffsds_le_zsu,
5969 NULL, },
5970 { gen_helper_sve_ldffbdu_zsu,
5971 gen_helper_sve_ldffhdu_le_zsu,
5972 gen_helper_sve_ldffsdu_le_zsu,
5973 gen_helper_sve_ldffdd_le_zsu, } },
5974 { { gen_helper_sve_ldffbds_zss,
5975 gen_helper_sve_ldffhds_le_zss,
5976 gen_helper_sve_ldffsds_le_zss,
5977 NULL, },
5978 { gen_helper_sve_ldffbdu_zss,
5979 gen_helper_sve_ldffhdu_le_zss,
5980 gen_helper_sve_ldffsdu_le_zss,
5981 gen_helper_sve_ldffdd_le_zss, } },
5982 { { gen_helper_sve_ldffbds_zd,
5983 gen_helper_sve_ldffhds_le_zd,
5984 gen_helper_sve_ldffsds_le_zd,
5985 NULL, },
5986 { gen_helper_sve_ldffbdu_zd,
5987 gen_helper_sve_ldffhdu_le_zd,
5988 gen_helper_sve_ldffsdu_le_zd,
5989 gen_helper_sve_ldffdd_le_zd, } } } },
5990 { /* Big-endian */
5991 { { { gen_helper_sve_ldbds_zsu,
5992 gen_helper_sve_ldhds_be_zsu,
5993 gen_helper_sve_ldsds_be_zsu,
5994 NULL, },
5995 { gen_helper_sve_ldbdu_zsu,
5996 gen_helper_sve_ldhdu_be_zsu,
5997 gen_helper_sve_ldsdu_be_zsu,
5998 gen_helper_sve_lddd_be_zsu, } },
5999 { { gen_helper_sve_ldbds_zss,
6000 gen_helper_sve_ldhds_be_zss,
6001 gen_helper_sve_ldsds_be_zss,
6002 NULL, },
6003 { gen_helper_sve_ldbdu_zss,
6004 gen_helper_sve_ldhdu_be_zss,
6005 gen_helper_sve_ldsdu_be_zss,
6006 gen_helper_sve_lddd_be_zss, } },
6007 { { gen_helper_sve_ldbds_zd,
6008 gen_helper_sve_ldhds_be_zd,
6009 gen_helper_sve_ldsds_be_zd,
6010 NULL, },
6011 { gen_helper_sve_ldbdu_zd,
6012 gen_helper_sve_ldhdu_be_zd,
6013 gen_helper_sve_ldsdu_be_zd,
6014 gen_helper_sve_lddd_be_zd, } } },
6015
6016 /* First-fault */
6017 { { { gen_helper_sve_ldffbds_zsu,
6018 gen_helper_sve_ldffhds_be_zsu,
6019 gen_helper_sve_ldffsds_be_zsu,
6020 NULL, },
6021 { gen_helper_sve_ldffbdu_zsu,
6022 gen_helper_sve_ldffhdu_be_zsu,
6023 gen_helper_sve_ldffsdu_be_zsu,
6024 gen_helper_sve_ldffdd_be_zsu, } },
6025 { { gen_helper_sve_ldffbds_zss,
6026 gen_helper_sve_ldffhds_be_zss,
6027 gen_helper_sve_ldffsds_be_zss,
6028 NULL, },
6029 { gen_helper_sve_ldffbdu_zss,
6030 gen_helper_sve_ldffhdu_be_zss,
6031 gen_helper_sve_ldffsdu_be_zss,
6032 gen_helper_sve_ldffdd_be_zss, } },
6033 { { gen_helper_sve_ldffbds_zd,
6034 gen_helper_sve_ldffhds_be_zd,
6035 gen_helper_sve_ldffsds_be_zd,
6036 NULL, },
6037 { gen_helper_sve_ldffbdu_zd,
6038 gen_helper_sve_ldffhdu_be_zd,
6039 gen_helper_sve_ldffsdu_be_zd,
6040 gen_helper_sve_ldffdd_be_zd, } } } } },
6041 { /* MTE Active */
6042 { /* Little-endian */
6043 { { { gen_helper_sve_ldbds_zsu_mte,
6044 gen_helper_sve_ldhds_le_zsu_mte,
6045 gen_helper_sve_ldsds_le_zsu_mte,
6046 NULL, },
6047 { gen_helper_sve_ldbdu_zsu_mte,
6048 gen_helper_sve_ldhdu_le_zsu_mte,
6049 gen_helper_sve_ldsdu_le_zsu_mte,
6050 gen_helper_sve_lddd_le_zsu_mte, } },
6051 { { gen_helper_sve_ldbds_zss_mte,
6052 gen_helper_sve_ldhds_le_zss_mte,
6053 gen_helper_sve_ldsds_le_zss_mte,
6054 NULL, },
6055 { gen_helper_sve_ldbdu_zss_mte,
6056 gen_helper_sve_ldhdu_le_zss_mte,
6057 gen_helper_sve_ldsdu_le_zss_mte,
6058 gen_helper_sve_lddd_le_zss_mte, } },
6059 { { gen_helper_sve_ldbds_zd_mte,
6060 gen_helper_sve_ldhds_le_zd_mte,
6061 gen_helper_sve_ldsds_le_zd_mte,
6062 NULL, },
6063 { gen_helper_sve_ldbdu_zd_mte,
6064 gen_helper_sve_ldhdu_le_zd_mte,
6065 gen_helper_sve_ldsdu_le_zd_mte,
6066 gen_helper_sve_lddd_le_zd_mte, } } },
6067
6068 /* First-fault */
6069 { { { gen_helper_sve_ldffbds_zsu_mte,
6070 gen_helper_sve_ldffhds_le_zsu_mte,
6071 gen_helper_sve_ldffsds_le_zsu_mte,
6072 NULL, },
6073 { gen_helper_sve_ldffbdu_zsu_mte,
6074 gen_helper_sve_ldffhdu_le_zsu_mte,
6075 gen_helper_sve_ldffsdu_le_zsu_mte,
6076 gen_helper_sve_ldffdd_le_zsu_mte, } },
6077 { { gen_helper_sve_ldffbds_zss_mte,
6078 gen_helper_sve_ldffhds_le_zss_mte,
6079 gen_helper_sve_ldffsds_le_zss_mte,
6080 NULL, },
6081 { gen_helper_sve_ldffbdu_zss_mte,
6082 gen_helper_sve_ldffhdu_le_zss_mte,
6083 gen_helper_sve_ldffsdu_le_zss_mte,
6084 gen_helper_sve_ldffdd_le_zss_mte, } },
6085 { { gen_helper_sve_ldffbds_zd_mte,
6086 gen_helper_sve_ldffhds_le_zd_mte,
6087 gen_helper_sve_ldffsds_le_zd_mte,
6088 NULL, },
6089 { gen_helper_sve_ldffbdu_zd_mte,
6090 gen_helper_sve_ldffhdu_le_zd_mte,
6091 gen_helper_sve_ldffsdu_le_zd_mte,
6092 gen_helper_sve_ldffdd_le_zd_mte, } } } },
6093 { /* Big-endian */
6094 { { { gen_helper_sve_ldbds_zsu_mte,
6095 gen_helper_sve_ldhds_be_zsu_mte,
6096 gen_helper_sve_ldsds_be_zsu_mte,
6097 NULL, },
6098 { gen_helper_sve_ldbdu_zsu_mte,
6099 gen_helper_sve_ldhdu_be_zsu_mte,
6100 gen_helper_sve_ldsdu_be_zsu_mte,
6101 gen_helper_sve_lddd_be_zsu_mte, } },
6102 { { gen_helper_sve_ldbds_zss_mte,
6103 gen_helper_sve_ldhds_be_zss_mte,
6104 gen_helper_sve_ldsds_be_zss_mte,
6105 NULL, },
6106 { gen_helper_sve_ldbdu_zss_mte,
6107 gen_helper_sve_ldhdu_be_zss_mte,
6108 gen_helper_sve_ldsdu_be_zss_mte,
6109 gen_helper_sve_lddd_be_zss_mte, } },
6110 { { gen_helper_sve_ldbds_zd_mte,
6111 gen_helper_sve_ldhds_be_zd_mte,
6112 gen_helper_sve_ldsds_be_zd_mte,
6113 NULL, },
6114 { gen_helper_sve_ldbdu_zd_mte,
6115 gen_helper_sve_ldhdu_be_zd_mte,
6116 gen_helper_sve_ldsdu_be_zd_mte,
6117 gen_helper_sve_lddd_be_zd_mte, } } },
6118
6119 /* First-fault */
6120 { { { gen_helper_sve_ldffbds_zsu_mte,
6121 gen_helper_sve_ldffhds_be_zsu_mte,
6122 gen_helper_sve_ldffsds_be_zsu_mte,
6123 NULL, },
6124 { gen_helper_sve_ldffbdu_zsu_mte,
6125 gen_helper_sve_ldffhdu_be_zsu_mte,
6126 gen_helper_sve_ldffsdu_be_zsu_mte,
6127 gen_helper_sve_ldffdd_be_zsu_mte, } },
6128 { { gen_helper_sve_ldffbds_zss_mte,
6129 gen_helper_sve_ldffhds_be_zss_mte,
6130 gen_helper_sve_ldffsds_be_zss_mte,
6131 NULL, },
6132 { gen_helper_sve_ldffbdu_zss_mte,
6133 gen_helper_sve_ldffhdu_be_zss_mte,
6134 gen_helper_sve_ldffsdu_be_zss_mte,
6135 gen_helper_sve_ldffdd_be_zss_mte, } },
6136 { { gen_helper_sve_ldffbds_zd_mte,
6137 gen_helper_sve_ldffhds_be_zd_mte,
6138 gen_helper_sve_ldffsds_be_zd_mte,
6139 NULL, },
6140 { gen_helper_sve_ldffbdu_zd_mte,
6141 gen_helper_sve_ldffhdu_be_zd_mte,
6142 gen_helper_sve_ldffsdu_be_zd_mte,
6143 gen_helper_sve_ldffdd_be_zd_mte, } } } } },
673e9fa6
RH
6144};
6145
3a7be554 6146static bool trans_LD1_zprz(DisasContext *s, arg_LD1_zprz *a)
673e9fa6
RH
6147{
6148 gen_helper_gvec_mem_scatter *fn = NULL;
d28d12f0
RH
6149 bool be = s->be_data == MO_BE;
6150 bool mte = s->mte_active[0];
673e9fa6
RH
6151
6152 if (!sve_access_check(s)) {
6153 return true;
6154 }
6155
6156 switch (a->esz) {
6157 case MO_32:
d28d12f0 6158 fn = gather_load_fn32[mte][be][a->ff][a->xs][a->u][a->msz];
673e9fa6
RH
6159 break;
6160 case MO_64:
d28d12f0 6161 fn = gather_load_fn64[mte][be][a->ff][a->xs][a->u][a->msz];
673e9fa6
RH
6162 break;
6163 }
6164 assert(fn != NULL);
6165
6166 do_mem_zpz(s, a->rd, a->pg, a->rm, a->scale * a->msz,
d28d12f0 6167 cpu_reg_sp(s, a->rn), a->msz, false, fn);
673e9fa6
RH
6168 return true;
6169}
6170
3a7be554 6171static bool trans_LD1_zpiz(DisasContext *s, arg_LD1_zpiz *a)
673e9fa6
RH
6172{
6173 gen_helper_gvec_mem_scatter *fn = NULL;
d28d12f0
RH
6174 bool be = s->be_data == MO_BE;
6175 bool mte = s->mte_active[0];
673e9fa6
RH
6176
6177 if (a->esz < a->msz || (a->esz == a->msz && !a->u)) {
6178 return false;
6179 }
6180 if (!sve_access_check(s)) {
6181 return true;
6182 }
6183
6184 switch (a->esz) {
6185 case MO_32:
d28d12f0 6186 fn = gather_load_fn32[mte][be][a->ff][0][a->u][a->msz];
673e9fa6
RH
6187 break;
6188 case MO_64:
d28d12f0 6189 fn = gather_load_fn64[mte][be][a->ff][2][a->u][a->msz];
673e9fa6
RH
6190 break;
6191 }
6192 assert(fn != NULL);
6193
6194 /* Treat LD1_zpiz (zn[x] + imm) the same way as LD1_zprz (rn + zm[x])
6195 * by loading the immediate into the scalar parameter.
6196 */
2ccdf94f
RH
6197 do_mem_zpz(s, a->rd, a->pg, a->rn, 0,
6198 tcg_constant_i64(a->imm << a->msz), a->msz, false, fn);
673e9fa6
RH
6199 return true;
6200}
6201
cf327449
SL
6202static bool trans_LDNT1_zprz(DisasContext *s, arg_LD1_zprz *a)
6203{
b17ab470
RH
6204 gen_helper_gvec_mem_scatter *fn = NULL;
6205 bool be = s->be_data == MO_BE;
6206 bool mte = s->mte_active[0];
6207
6208 if (a->esz < a->msz + !a->u) {
6209 return false;
6210 }
cf327449
SL
6211 if (!dc_isar_feature(aa64_sve2, s)) {
6212 return false;
6213 }
b17ab470
RH
6214 if (!sve_access_check(s)) {
6215 return true;
6216 }
6217
6218 switch (a->esz) {
6219 case MO_32:
6220 fn = gather_load_fn32[mte][be][0][0][a->u][a->msz];
6221 break;
6222 case MO_64:
6223 fn = gather_load_fn64[mte][be][0][2][a->u][a->msz];
6224 break;
6225 }
6226 assert(fn != NULL);
6227
6228 do_mem_zpz(s, a->rd, a->pg, a->rn, 0,
6229 cpu_reg(s, a->rm), a->msz, false, fn);
6230 return true;
cf327449
SL
6231}
6232
d28d12f0
RH
6233/* Indexed by [mte][be][xs][msz]. */
6234static gen_helper_gvec_mem_scatter * const scatter_store_fn32[2][2][2][3] = {
6235 { /* MTE Inactive */
6236 { /* Little-endian */
6237 { gen_helper_sve_stbs_zsu,
6238 gen_helper_sve_sths_le_zsu,
6239 gen_helper_sve_stss_le_zsu, },
6240 { gen_helper_sve_stbs_zss,
6241 gen_helper_sve_sths_le_zss,
6242 gen_helper_sve_stss_le_zss, } },
6243 { /* Big-endian */
6244 { gen_helper_sve_stbs_zsu,
6245 gen_helper_sve_sths_be_zsu,
6246 gen_helper_sve_stss_be_zsu, },
6247 { gen_helper_sve_stbs_zss,
6248 gen_helper_sve_sths_be_zss,
6249 gen_helper_sve_stss_be_zss, } } },
6250 { /* MTE Active */
6251 { /* Little-endian */
6252 { gen_helper_sve_stbs_zsu_mte,
6253 gen_helper_sve_sths_le_zsu_mte,
6254 gen_helper_sve_stss_le_zsu_mte, },
6255 { gen_helper_sve_stbs_zss_mte,
6256 gen_helper_sve_sths_le_zss_mte,
6257 gen_helper_sve_stss_le_zss_mte, } },
6258 { /* Big-endian */
6259 { gen_helper_sve_stbs_zsu_mte,
6260 gen_helper_sve_sths_be_zsu_mte,
6261 gen_helper_sve_stss_be_zsu_mte, },
6262 { gen_helper_sve_stbs_zss_mte,
6263 gen_helper_sve_sths_be_zss_mte,
6264 gen_helper_sve_stss_be_zss_mte, } } },
408ecde9
RH
6265};
6266
6267/* Note that we overload xs=2 to indicate 64-bit offset. */
d28d12f0
RH
6268static gen_helper_gvec_mem_scatter * const scatter_store_fn64[2][2][3][4] = {
6269 { /* MTE Inactive */
6270 { /* Little-endian */
6271 { gen_helper_sve_stbd_zsu,
6272 gen_helper_sve_sthd_le_zsu,
6273 gen_helper_sve_stsd_le_zsu,
6274 gen_helper_sve_stdd_le_zsu, },
6275 { gen_helper_sve_stbd_zss,
6276 gen_helper_sve_sthd_le_zss,
6277 gen_helper_sve_stsd_le_zss,
6278 gen_helper_sve_stdd_le_zss, },
6279 { gen_helper_sve_stbd_zd,
6280 gen_helper_sve_sthd_le_zd,
6281 gen_helper_sve_stsd_le_zd,
6282 gen_helper_sve_stdd_le_zd, } },
6283 { /* Big-endian */
6284 { gen_helper_sve_stbd_zsu,
6285 gen_helper_sve_sthd_be_zsu,
6286 gen_helper_sve_stsd_be_zsu,
6287 gen_helper_sve_stdd_be_zsu, },
6288 { gen_helper_sve_stbd_zss,
6289 gen_helper_sve_sthd_be_zss,
6290 gen_helper_sve_stsd_be_zss,
6291 gen_helper_sve_stdd_be_zss, },
6292 { gen_helper_sve_stbd_zd,
6293 gen_helper_sve_sthd_be_zd,
6294 gen_helper_sve_stsd_be_zd,
6295 gen_helper_sve_stdd_be_zd, } } },
6296 { /* MTE Inactive */
6297 { /* Little-endian */
6298 { gen_helper_sve_stbd_zsu_mte,
6299 gen_helper_sve_sthd_le_zsu_mte,
6300 gen_helper_sve_stsd_le_zsu_mte,
6301 gen_helper_sve_stdd_le_zsu_mte, },
6302 { gen_helper_sve_stbd_zss_mte,
6303 gen_helper_sve_sthd_le_zss_mte,
6304 gen_helper_sve_stsd_le_zss_mte,
6305 gen_helper_sve_stdd_le_zss_mte, },
6306 { gen_helper_sve_stbd_zd_mte,
6307 gen_helper_sve_sthd_le_zd_mte,
6308 gen_helper_sve_stsd_le_zd_mte,
6309 gen_helper_sve_stdd_le_zd_mte, } },
6310 { /* Big-endian */
6311 { gen_helper_sve_stbd_zsu_mte,
6312 gen_helper_sve_sthd_be_zsu_mte,
6313 gen_helper_sve_stsd_be_zsu_mte,
6314 gen_helper_sve_stdd_be_zsu_mte, },
6315 { gen_helper_sve_stbd_zss_mte,
6316 gen_helper_sve_sthd_be_zss_mte,
6317 gen_helper_sve_stsd_be_zss_mte,
6318 gen_helper_sve_stdd_be_zss_mte, },
6319 { gen_helper_sve_stbd_zd_mte,
6320 gen_helper_sve_sthd_be_zd_mte,
6321 gen_helper_sve_stsd_be_zd_mte,
6322 gen_helper_sve_stdd_be_zd_mte, } } },
408ecde9
RH
6323};
6324
3a7be554 6325static bool trans_ST1_zprz(DisasContext *s, arg_ST1_zprz *a)
f6dbf62a 6326{
f6dbf62a 6327 gen_helper_gvec_mem_scatter *fn;
d28d12f0
RH
6328 bool be = s->be_data == MO_BE;
6329 bool mte = s->mte_active[0];
f6dbf62a
RH
6330
6331 if (a->esz < a->msz || (a->msz == 0 && a->scale)) {
6332 return false;
6333 }
6334 if (!sve_access_check(s)) {
6335 return true;
6336 }
6337 switch (a->esz) {
6338 case MO_32:
d28d12f0 6339 fn = scatter_store_fn32[mte][be][a->xs][a->msz];
f6dbf62a
RH
6340 break;
6341 case MO_64:
d28d12f0 6342 fn = scatter_store_fn64[mte][be][a->xs][a->msz];
f6dbf62a
RH
6343 break;
6344 default:
6345 g_assert_not_reached();
6346 }
6347 do_mem_zpz(s, a->rd, a->pg, a->rm, a->scale * a->msz,
d28d12f0 6348 cpu_reg_sp(s, a->rn), a->msz, true, fn);
f6dbf62a
RH
6349 return true;
6350}
dec6cf6b 6351
3a7be554 6352static bool trans_ST1_zpiz(DisasContext *s, arg_ST1_zpiz *a)
408ecde9
RH
6353{
6354 gen_helper_gvec_mem_scatter *fn = NULL;
d28d12f0
RH
6355 bool be = s->be_data == MO_BE;
6356 bool mte = s->mte_active[0];
408ecde9
RH
6357
6358 if (a->esz < a->msz) {
6359 return false;
6360 }
6361 if (!sve_access_check(s)) {
6362 return true;
6363 }
6364
6365 switch (a->esz) {
6366 case MO_32:
d28d12f0 6367 fn = scatter_store_fn32[mte][be][0][a->msz];
408ecde9
RH
6368 break;
6369 case MO_64:
d28d12f0 6370 fn = scatter_store_fn64[mte][be][2][a->msz];
408ecde9
RH
6371 break;
6372 }
6373 assert(fn != NULL);
6374
6375 /* Treat ST1_zpiz (zn[x] + imm) the same way as ST1_zprz (rn + zm[x])
6376 * by loading the immediate into the scalar parameter.
6377 */
2ccdf94f
RH
6378 do_mem_zpz(s, a->rd, a->pg, a->rn, 0,
6379 tcg_constant_i64(a->imm << a->msz), a->msz, true, fn);
408ecde9
RH
6380 return true;
6381}
6382
6ebca45f
SL
6383static bool trans_STNT1_zprz(DisasContext *s, arg_ST1_zprz *a)
6384{
b17ab470
RH
6385 gen_helper_gvec_mem_scatter *fn;
6386 bool be = s->be_data == MO_BE;
6387 bool mte = s->mte_active[0];
6388
6389 if (a->esz < a->msz) {
6390 return false;
6391 }
6ebca45f
SL
6392 if (!dc_isar_feature(aa64_sve2, s)) {
6393 return false;
6394 }
b17ab470
RH
6395 if (!sve_access_check(s)) {
6396 return true;
6397 }
6398
6399 switch (a->esz) {
6400 case MO_32:
6401 fn = scatter_store_fn32[mte][be][0][a->msz];
6402 break;
6403 case MO_64:
6404 fn = scatter_store_fn64[mte][be][2][a->msz];
6405 break;
6406 default:
6407 g_assert_not_reached();
6408 }
6409
6410 do_mem_zpz(s, a->rd, a->pg, a->rn, 0,
6411 cpu_reg(s, a->rm), a->msz, true, fn);
6412 return true;
6ebca45f
SL
6413}
6414
dec6cf6b
RH
6415/*
6416 * Prefetches
6417 */
6418
3a7be554 6419static bool trans_PRF(DisasContext *s, arg_PRF *a)
dec6cf6b
RH
6420{
6421 /* Prefetch is a nop within QEMU. */
2f95a3b0 6422 (void)sve_access_check(s);
dec6cf6b
RH
6423 return true;
6424}
6425
3a7be554 6426static bool trans_PRF_rr(DisasContext *s, arg_PRF_rr *a)
dec6cf6b
RH
6427{
6428 if (a->rm == 31) {
6429 return false;
6430 }
6431 /* Prefetch is a nop within QEMU. */
2f95a3b0 6432 (void)sve_access_check(s);
dec6cf6b
RH
6433 return true;
6434}
a2103582
RH
6435
6436/*
6437 * Move Prefix
6438 *
6439 * TODO: The implementation so far could handle predicated merging movprfx.
6440 * The helper functions as written take an extra source register to
6441 * use in the operation, but the result is only written when predication
6442 * succeeds. For unpredicated movprfx, we need to rearrange the helpers
6443 * to allow the final write back to the destination to be unconditional.
6444 * For predicated zeroing movprfx, we need to rearrange the helpers to
6445 * allow the final write back to zero inactives.
6446 *
6447 * In the meantime, just emit the moves.
6448 */
6449
3a7be554 6450static bool trans_MOVPRFX(DisasContext *s, arg_MOVPRFX *a)
a2103582
RH
6451{
6452 return do_mov_z(s, a->rd, a->rn);
6453}
6454
3a7be554 6455static bool trans_MOVPRFX_m(DisasContext *s, arg_rpr_esz *a)
a2103582
RH
6456{
6457 if (sve_access_check(s)) {
6458 do_sel_z(s, a->rd, a->rn, a->rd, a->pg, a->esz);
6459 }
6460 return true;
6461}
6462
3a7be554 6463static bool trans_MOVPRFX_z(DisasContext *s, arg_rpr_esz *a)
a2103582 6464{
60245996 6465 return do_movz_zpz(s, a->rd, a->rn, a->pg, a->esz, false);
a2103582 6466}
5dad1ba5
RH
6467
6468/*
6469 * SVE2 Integer Multiply - Unpredicated
6470 */
6471
6472static bool trans_MUL_zzz(DisasContext *s, arg_rrr_esz *a)
6473{
6474 if (!dc_isar_feature(aa64_sve2, s)) {
6475 return false;
6476 }
6477 if (sve_access_check(s)) {
6478 gen_gvec_fn_zzz(s, tcg_gen_gvec_mul, a->esz, a->rd, a->rn, a->rm);
6479 }
6480 return true;
6481}
6482
bd394cf5
RH
6483static gen_helper_gvec_3 * const smulh_zzz_fns[4] = {
6484 gen_helper_gvec_smulh_b, gen_helper_gvec_smulh_h,
6485 gen_helper_gvec_smulh_s, gen_helper_gvec_smulh_d,
6486};
6487TRANS_FEAT(SMULH_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6488 smulh_zzz_fns[a->esz], a, 0)
5dad1ba5 6489
bd394cf5
RH
6490static gen_helper_gvec_3 * const umulh_zzz_fns[4] = {
6491 gen_helper_gvec_umulh_b, gen_helper_gvec_umulh_h,
6492 gen_helper_gvec_umulh_s, gen_helper_gvec_umulh_d,
6493};
6494TRANS_FEAT(UMULH_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6495 umulh_zzz_fns[a->esz], a, 0)
5dad1ba5 6496
bd394cf5
RH
6497TRANS_FEAT(PMUL_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6498 gen_helper_gvec_pmul_b, a, 0)
5dad1ba5 6499
bd394cf5
RH
6500static gen_helper_gvec_3 * const sqdmulh_zzz_fns[4] = {
6501 gen_helper_sve2_sqdmulh_b, gen_helper_sve2_sqdmulh_h,
6502 gen_helper_sve2_sqdmulh_s, gen_helper_sve2_sqdmulh_d,
6503};
6504TRANS_FEAT(SQDMULH_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6505 sqdmulh_zzz_fns[a->esz], a, 0)
169d7c58 6506
bd394cf5
RH
6507static gen_helper_gvec_3 * const sqrdmulh_zzz_fns[4] = {
6508 gen_helper_sve2_sqrdmulh_b, gen_helper_sve2_sqrdmulh_h,
6509 gen_helper_sve2_sqrdmulh_s, gen_helper_sve2_sqrdmulh_d,
6510};
6511TRANS_FEAT(SQRDMULH_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6512 sqrdmulh_zzz_fns[a->esz], a, 0)
169d7c58 6513
d4b1e59d
RH
6514/*
6515 * SVE2 Integer - Predicated
6516 */
6517
6518static bool do_sve2_zpzz_ool(DisasContext *s, arg_rprr_esz *a,
6519 gen_helper_gvec_4 *fn)
6520{
6521 if (!dc_isar_feature(aa64_sve2, s)) {
6522 return false;
6523 }
6524 return do_zpzz_ool(s, a, fn);
6525}
6526
6527static bool trans_SADALP_zpzz(DisasContext *s, arg_rprr_esz *a)
6528{
6529 static gen_helper_gvec_4 * const fns[3] = {
6530 gen_helper_sve2_sadalp_zpzz_h,
6531 gen_helper_sve2_sadalp_zpzz_s,
6532 gen_helper_sve2_sadalp_zpzz_d,
6533 };
6534 if (a->esz == 0) {
6535 return false;
6536 }
6537 return do_sve2_zpzz_ool(s, a, fns[a->esz - 1]);
6538}
6539
6540static bool trans_UADALP_zpzz(DisasContext *s, arg_rprr_esz *a)
6541{
6542 static gen_helper_gvec_4 * const fns[3] = {
6543 gen_helper_sve2_uadalp_zpzz_h,
6544 gen_helper_sve2_uadalp_zpzz_s,
6545 gen_helper_sve2_uadalp_zpzz_d,
6546 };
6547 if (a->esz == 0) {
6548 return false;
6549 }
6550 return do_sve2_zpzz_ool(s, a, fns[a->esz - 1]);
6551}
db366da8
RH
6552
6553/*
6554 * SVE2 integer unary operations (predicated)
6555 */
6556
6557static bool do_sve2_zpz_ool(DisasContext *s, arg_rpr_esz *a,
6558 gen_helper_gvec_3 *fn)
6559{
6560 if (!dc_isar_feature(aa64_sve2, s)) {
6561 return false;
6562 }
b051809a 6563 return gen_gvec_ool_arg_zpz(s, fn, a, 0);
db366da8
RH
6564}
6565
6566static bool trans_URECPE(DisasContext *s, arg_rpr_esz *a)
6567{
6568 if (a->esz != 2) {
6569 return false;
6570 }
6571 return do_sve2_zpz_ool(s, a, gen_helper_sve2_urecpe_s);
6572}
6573
6574static bool trans_URSQRTE(DisasContext *s, arg_rpr_esz *a)
6575{
6576 if (a->esz != 2) {
6577 return false;
6578 }
6579 return do_sve2_zpz_ool(s, a, gen_helper_sve2_ursqrte_s);
6580}
6581
6582static bool trans_SQABS(DisasContext *s, arg_rpr_esz *a)
6583{
6584 static gen_helper_gvec_3 * const fns[4] = {
6585 gen_helper_sve2_sqabs_b, gen_helper_sve2_sqabs_h,
6586 gen_helper_sve2_sqabs_s, gen_helper_sve2_sqabs_d,
6587 };
6588 return do_sve2_zpz_ool(s, a, fns[a->esz]);
6589}
6590
6591static bool trans_SQNEG(DisasContext *s, arg_rpr_esz *a)
6592{
6593 static gen_helper_gvec_3 * const fns[4] = {
6594 gen_helper_sve2_sqneg_b, gen_helper_sve2_sqneg_h,
6595 gen_helper_sve2_sqneg_s, gen_helper_sve2_sqneg_d,
6596 };
6597 return do_sve2_zpz_ool(s, a, fns[a->esz]);
6598}
45d9503d
RH
6599
6600#define DO_SVE2_ZPZZ(NAME, name) \
6601static bool trans_##NAME(DisasContext *s, arg_rprr_esz *a) \
6602{ \
6603 static gen_helper_gvec_4 * const fns[4] = { \
6604 gen_helper_sve2_##name##_zpzz_b, gen_helper_sve2_##name##_zpzz_h, \
6605 gen_helper_sve2_##name##_zpzz_s, gen_helper_sve2_##name##_zpzz_d, \
6606 }; \
6607 return do_sve2_zpzz_ool(s, a, fns[a->esz]); \
6608}
6609
6610DO_SVE2_ZPZZ(SQSHL, sqshl)
6611DO_SVE2_ZPZZ(SQRSHL, sqrshl)
6612DO_SVE2_ZPZZ(SRSHL, srshl)
6613
6614DO_SVE2_ZPZZ(UQSHL, uqshl)
6615DO_SVE2_ZPZZ(UQRSHL, uqrshl)
6616DO_SVE2_ZPZZ(URSHL, urshl)
a47dc220
RH
6617
6618DO_SVE2_ZPZZ(SHADD, shadd)
6619DO_SVE2_ZPZZ(SRHADD, srhadd)
6620DO_SVE2_ZPZZ(SHSUB, shsub)
6621
6622DO_SVE2_ZPZZ(UHADD, uhadd)
6623DO_SVE2_ZPZZ(URHADD, urhadd)
6624DO_SVE2_ZPZZ(UHSUB, uhsub)
8597dc8b
RH
6625
6626DO_SVE2_ZPZZ(ADDP, addp)
6627DO_SVE2_ZPZZ(SMAXP, smaxp)
6628DO_SVE2_ZPZZ(UMAXP, umaxp)
6629DO_SVE2_ZPZZ(SMINP, sminp)
6630DO_SVE2_ZPZZ(UMINP, uminp)
4f07fbeb
RH
6631
6632DO_SVE2_ZPZZ(SQADD_zpzz, sqadd)
6633DO_SVE2_ZPZZ(UQADD_zpzz, uqadd)
6634DO_SVE2_ZPZZ(SQSUB_zpzz, sqsub)
6635DO_SVE2_ZPZZ(UQSUB_zpzz, uqsub)
6636DO_SVE2_ZPZZ(SUQADD, suqadd)
6637DO_SVE2_ZPZZ(USQADD, usqadd)
0ce1dda8
RH
6638
6639/*
6640 * SVE2 Widening Integer Arithmetic
6641 */
6642
615f19fe
RH
6643static gen_helper_gvec_3 * const saddl_fns[4] = {
6644 NULL, gen_helper_sve2_saddl_h,
6645 gen_helper_sve2_saddl_s, gen_helper_sve2_saddl_d,
6646};
6647TRANS_FEAT(SADDLB, aa64_sve2, gen_gvec_ool_arg_zzz,
6648 saddl_fns[a->esz], a, 0)
6649TRANS_FEAT(SADDLT, aa64_sve2, gen_gvec_ool_arg_zzz,
6650 saddl_fns[a->esz], a, 3)
6651TRANS_FEAT(SADDLBT, aa64_sve2, gen_gvec_ool_arg_zzz,
6652 saddl_fns[a->esz], a, 2)
6653
6654static gen_helper_gvec_3 * const ssubl_fns[4] = {
6655 NULL, gen_helper_sve2_ssubl_h,
6656 gen_helper_sve2_ssubl_s, gen_helper_sve2_ssubl_d,
6657};
6658TRANS_FEAT(SSUBLB, aa64_sve2, gen_gvec_ool_arg_zzz,
6659 ssubl_fns[a->esz], a, 0)
6660TRANS_FEAT(SSUBLT, aa64_sve2, gen_gvec_ool_arg_zzz,
6661 ssubl_fns[a->esz], a, 3)
6662TRANS_FEAT(SSUBLBT, aa64_sve2, gen_gvec_ool_arg_zzz,
6663 ssubl_fns[a->esz], a, 2)
6664TRANS_FEAT(SSUBLTB, aa64_sve2, gen_gvec_ool_arg_zzz,
6665 ssubl_fns[a->esz], a, 1)
6666
6667static gen_helper_gvec_3 * const sabdl_fns[4] = {
6668 NULL, gen_helper_sve2_sabdl_h,
6669 gen_helper_sve2_sabdl_s, gen_helper_sve2_sabdl_d,
6670};
6671TRANS_FEAT(SABDLB, aa64_sve2, gen_gvec_ool_arg_zzz,
6672 sabdl_fns[a->esz], a, 0)
6673TRANS_FEAT(SABDLT, aa64_sve2, gen_gvec_ool_arg_zzz,
6674 sabdl_fns[a->esz], a, 3)
6675
6676static gen_helper_gvec_3 * const uaddl_fns[4] = {
6677 NULL, gen_helper_sve2_uaddl_h,
6678 gen_helper_sve2_uaddl_s, gen_helper_sve2_uaddl_d,
6679};
6680TRANS_FEAT(UADDLB, aa64_sve2, gen_gvec_ool_arg_zzz,
6681 uaddl_fns[a->esz], a, 0)
6682TRANS_FEAT(UADDLT, aa64_sve2, gen_gvec_ool_arg_zzz,
6683 uaddl_fns[a->esz], a, 3)
6684
6685static gen_helper_gvec_3 * const usubl_fns[4] = {
6686 NULL, gen_helper_sve2_usubl_h,
6687 gen_helper_sve2_usubl_s, gen_helper_sve2_usubl_d,
6688};
6689TRANS_FEAT(USUBLB, aa64_sve2, gen_gvec_ool_arg_zzz,
6690 usubl_fns[a->esz], a, 0)
6691TRANS_FEAT(USUBLT, aa64_sve2, gen_gvec_ool_arg_zzz,
6692 usubl_fns[a->esz], a, 3)
6693
6694static gen_helper_gvec_3 * const uabdl_fns[4] = {
6695 NULL, gen_helper_sve2_uabdl_h,
6696 gen_helper_sve2_uabdl_s, gen_helper_sve2_uabdl_d,
6697};
6698TRANS_FEAT(UABDLB, aa64_sve2, gen_gvec_ool_arg_zzz,
6699 uabdl_fns[a->esz], a, 0)
6700TRANS_FEAT(UABDLT, aa64_sve2, gen_gvec_ool_arg_zzz,
6701 uabdl_fns[a->esz], a, 3)
6702
6703static gen_helper_gvec_3 * const sqdmull_fns[4] = {
6704 NULL, gen_helper_sve2_sqdmull_zzz_h,
6705 gen_helper_sve2_sqdmull_zzz_s, gen_helper_sve2_sqdmull_zzz_d,
6706};
6707TRANS_FEAT(SQDMULLB_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6708 sqdmull_fns[a->esz], a, 0)
6709TRANS_FEAT(SQDMULLT_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6710 sqdmull_fns[a->esz], a, 3)
6711
6712static gen_helper_gvec_3 * const smull_fns[4] = {
6713 NULL, gen_helper_sve2_smull_zzz_h,
6714 gen_helper_sve2_smull_zzz_s, gen_helper_sve2_smull_zzz_d,
6715};
6716TRANS_FEAT(SMULLB_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6717 smull_fns[a->esz], a, 0)
6718TRANS_FEAT(SMULLT_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6719 smull_fns[a->esz], a, 3)
6720
6721static gen_helper_gvec_3 * const umull_fns[4] = {
6722 NULL, gen_helper_sve2_umull_zzz_h,
6723 gen_helper_sve2_umull_zzz_s, gen_helper_sve2_umull_zzz_d,
6724};
6725TRANS_FEAT(UMULLB_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6726 umull_fns[a->esz], a, 0)
6727TRANS_FEAT(UMULLT_zzz, aa64_sve2, gen_gvec_ool_arg_zzz,
6728 umull_fns[a->esz], a, 3)
6729
6730static gen_helper_gvec_3 * const eoril_fns[4] = {
6731 gen_helper_sve2_eoril_b, gen_helper_sve2_eoril_h,
6732 gen_helper_sve2_eoril_s, gen_helper_sve2_eoril_d,
6733};
6734TRANS_FEAT(EORBT, aa64_sve2, gen_gvec_ool_arg_zzz, eoril_fns[a->esz], a, 2)
6735TRANS_FEAT(EORTB, aa64_sve2, gen_gvec_ool_arg_zzz, eoril_fns[a->esz], a, 1)
2df3ca55 6736
e3a56131
RH
6737static bool do_trans_pmull(DisasContext *s, arg_rrr_esz *a, bool sel)
6738{
6739 static gen_helper_gvec_3 * const fns[4] = {
6740 gen_helper_gvec_pmull_q, gen_helper_sve2_pmull_h,
6741 NULL, gen_helper_sve2_pmull_d,
6742 };
6743 if (a->esz == 0 && !dc_isar_feature(aa64_sve2_pmull128, s)) {
6744 return false;
6745 }
615f19fe 6746 return gen_gvec_ool_arg_zzz(s, fns[a->esz], a, sel);
e3a56131
RH
6747}
6748
615f19fe
RH
6749TRANS_FEAT(PMULLB, aa64_sve2, do_trans_pmull, a, false)
6750TRANS_FEAT(PMULLT, aa64_sve2, do_trans_pmull, a, true)
e3a56131 6751
615f19fe
RH
6752static gen_helper_gvec_3 * const saddw_fns[4] = {
6753 NULL, gen_helper_sve2_saddw_h,
6754 gen_helper_sve2_saddw_s, gen_helper_sve2_saddw_d,
6755};
6756TRANS_FEAT(SADDWB, aa64_sve2, gen_gvec_ool_arg_zzz, saddw_fns[a->esz], a, 0)
6757TRANS_FEAT(SADDWT, aa64_sve2, gen_gvec_ool_arg_zzz, saddw_fns[a->esz], a, 1)
e3a56131 6758
615f19fe
RH
6759static gen_helper_gvec_3 * const ssubw_fns[4] = {
6760 NULL, gen_helper_sve2_ssubw_h,
6761 gen_helper_sve2_ssubw_s, gen_helper_sve2_ssubw_d,
6762};
6763TRANS_FEAT(SSUBWB, aa64_sve2, gen_gvec_ool_arg_zzz, ssubw_fns[a->esz], a, 0)
6764TRANS_FEAT(SSUBWT, aa64_sve2, gen_gvec_ool_arg_zzz, ssubw_fns[a->esz], a, 1)
81fccf09 6765
615f19fe
RH
6766static gen_helper_gvec_3 * const uaddw_fns[4] = {
6767 NULL, gen_helper_sve2_uaddw_h,
6768 gen_helper_sve2_uaddw_s, gen_helper_sve2_uaddw_d,
6769};
6770TRANS_FEAT(UADDWB, aa64_sve2, gen_gvec_ool_arg_zzz, uaddw_fns[a->esz], a, 0)
6771TRANS_FEAT(UADDWT, aa64_sve2, gen_gvec_ool_arg_zzz, uaddw_fns[a->esz], a, 1)
81fccf09 6772
615f19fe
RH
6773static gen_helper_gvec_3 * const usubw_fns[4] = {
6774 NULL, gen_helper_sve2_usubw_h,
6775 gen_helper_sve2_usubw_s, gen_helper_sve2_usubw_d,
6776};
6777TRANS_FEAT(USUBWB, aa64_sve2, gen_gvec_ool_arg_zzz, usubw_fns[a->esz], a, 0)
6778TRANS_FEAT(USUBWT, aa64_sve2, gen_gvec_ool_arg_zzz, usubw_fns[a->esz], a, 1)
4269fef1
RH
6779
6780static void gen_sshll_vec(unsigned vece, TCGv_vec d, TCGv_vec n, int64_t imm)
6781{
6782 int top = imm & 1;
6783 int shl = imm >> 1;
6784 int halfbits = 4 << vece;
6785
6786 if (top) {
6787 if (shl == halfbits) {
6788 TCGv_vec t = tcg_temp_new_vec_matching(d);
6789 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(halfbits, halfbits));
6790 tcg_gen_and_vec(vece, d, n, t);
6791 tcg_temp_free_vec(t);
6792 } else {
6793 tcg_gen_sari_vec(vece, d, n, halfbits);
6794 tcg_gen_shli_vec(vece, d, d, shl);
6795 }
6796 } else {
6797 tcg_gen_shli_vec(vece, d, n, halfbits);
6798 tcg_gen_sari_vec(vece, d, d, halfbits - shl);
6799 }
6800}
6801
6802static void gen_ushll_i64(unsigned vece, TCGv_i64 d, TCGv_i64 n, int imm)
6803{
6804 int halfbits = 4 << vece;
6805 int top = imm & 1;
6806 int shl = (imm >> 1);
6807 int shift;
6808 uint64_t mask;
6809
6810 mask = MAKE_64BIT_MASK(0, halfbits);
6811 mask <<= shl;
6812 mask = dup_const(vece, mask);
6813
6814 shift = shl - top * halfbits;
6815 if (shift < 0) {
6816 tcg_gen_shri_i64(d, n, -shift);
6817 } else {
6818 tcg_gen_shli_i64(d, n, shift);
6819 }
6820 tcg_gen_andi_i64(d, d, mask);
6821}
6822
6823static void gen_ushll16_i64(TCGv_i64 d, TCGv_i64 n, int64_t imm)
6824{
6825 gen_ushll_i64(MO_16, d, n, imm);
6826}
6827
6828static void gen_ushll32_i64(TCGv_i64 d, TCGv_i64 n, int64_t imm)
6829{
6830 gen_ushll_i64(MO_32, d, n, imm);
6831}
6832
6833static void gen_ushll64_i64(TCGv_i64 d, TCGv_i64 n, int64_t imm)
6834{
6835 gen_ushll_i64(MO_64, d, n, imm);
6836}
6837
6838static void gen_ushll_vec(unsigned vece, TCGv_vec d, TCGv_vec n, int64_t imm)
6839{
6840 int halfbits = 4 << vece;
6841 int top = imm & 1;
6842 int shl = imm >> 1;
6843
6844 if (top) {
6845 if (shl == halfbits) {
6846 TCGv_vec t = tcg_temp_new_vec_matching(d);
6847 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(halfbits, halfbits));
6848 tcg_gen_and_vec(vece, d, n, t);
6849 tcg_temp_free_vec(t);
6850 } else {
6851 tcg_gen_shri_vec(vece, d, n, halfbits);
6852 tcg_gen_shli_vec(vece, d, d, shl);
6853 }
6854 } else {
6855 if (shl == 0) {
6856 TCGv_vec t = tcg_temp_new_vec_matching(d);
6857 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(0, halfbits));
6858 tcg_gen_and_vec(vece, d, n, t);
6859 tcg_temp_free_vec(t);
6860 } else {
6861 tcg_gen_shli_vec(vece, d, n, halfbits);
6862 tcg_gen_shri_vec(vece, d, d, halfbits - shl);
6863 }
6864 }
6865}
6866
6867static bool do_sve2_shll_tb(DisasContext *s, arg_rri_esz *a,
6868 bool sel, bool uns)
6869{
6870 static const TCGOpcode sshll_list[] = {
6871 INDEX_op_shli_vec, INDEX_op_sari_vec, 0
6872 };
6873 static const TCGOpcode ushll_list[] = {
6874 INDEX_op_shli_vec, INDEX_op_shri_vec, 0
6875 };
6876 static const GVecGen2i ops[2][3] = {
6877 { { .fniv = gen_sshll_vec,
6878 .opt_opc = sshll_list,
6879 .fno = gen_helper_sve2_sshll_h,
6880 .vece = MO_16 },
6881 { .fniv = gen_sshll_vec,
6882 .opt_opc = sshll_list,
6883 .fno = gen_helper_sve2_sshll_s,
6884 .vece = MO_32 },
6885 { .fniv = gen_sshll_vec,
6886 .opt_opc = sshll_list,
6887 .fno = gen_helper_sve2_sshll_d,
6888 .vece = MO_64 } },
6889 { { .fni8 = gen_ushll16_i64,
6890 .fniv = gen_ushll_vec,
6891 .opt_opc = ushll_list,
6892 .fno = gen_helper_sve2_ushll_h,
6893 .vece = MO_16 },
6894 { .fni8 = gen_ushll32_i64,
6895 .fniv = gen_ushll_vec,
6896 .opt_opc = ushll_list,
6897 .fno = gen_helper_sve2_ushll_s,
6898 .vece = MO_32 },
6899 { .fni8 = gen_ushll64_i64,
6900 .fniv = gen_ushll_vec,
6901 .opt_opc = ushll_list,
6902 .fno = gen_helper_sve2_ushll_d,
6903 .vece = MO_64 } },
6904 };
6905
6906 if (a->esz < 0 || a->esz > 2 || !dc_isar_feature(aa64_sve2, s)) {
6907 return false;
6908 }
6909 if (sve_access_check(s)) {
6910 unsigned vsz = vec_full_reg_size(s);
6911 tcg_gen_gvec_2i(vec_full_reg_offset(s, a->rd),
6912 vec_full_reg_offset(s, a->rn),
6913 vsz, vsz, (a->imm << 1) | sel,
6914 &ops[uns][a->esz]);
6915 }
6916 return true;
6917}
6918
6919static bool trans_SSHLLB(DisasContext *s, arg_rri_esz *a)
6920{
6921 return do_sve2_shll_tb(s, a, false, false);
6922}
6923
6924static bool trans_SSHLLT(DisasContext *s, arg_rri_esz *a)
6925{
6926 return do_sve2_shll_tb(s, a, true, false);
6927}
6928
6929static bool trans_USHLLB(DisasContext *s, arg_rri_esz *a)
6930{
6931 return do_sve2_shll_tb(s, a, false, true);
6932}
6933
6934static bool trans_USHLLT(DisasContext *s, arg_rri_esz *a)
6935{
6936 return do_sve2_shll_tb(s, a, true, true);
6937}
cb9c33b8 6938
615f19fe
RH
6939static gen_helper_gvec_3 * const bext_fns[4] = {
6940 gen_helper_sve2_bext_b, gen_helper_sve2_bext_h,
6941 gen_helper_sve2_bext_s, gen_helper_sve2_bext_d,
6942};
6943TRANS_FEAT(BEXT, aa64_sve2_bitperm, gen_gvec_ool_arg_zzz,
6944 bext_fns[a->esz], a, 0)
ed4a6387 6945
615f19fe
RH
6946static gen_helper_gvec_3 * const bdep_fns[4] = {
6947 gen_helper_sve2_bdep_b, gen_helper_sve2_bdep_h,
6948 gen_helper_sve2_bdep_s, gen_helper_sve2_bdep_d,
6949};
6950TRANS_FEAT(BDEP, aa64_sve2_bitperm, gen_gvec_ool_arg_zzz,
6951 bdep_fns[a->esz], a, 0)
ed4a6387 6952
615f19fe
RH
6953static gen_helper_gvec_3 * const bgrp_fns[4] = {
6954 gen_helper_sve2_bgrp_b, gen_helper_sve2_bgrp_h,
6955 gen_helper_sve2_bgrp_s, gen_helper_sve2_bgrp_d,
6956};
6957TRANS_FEAT(BGRP, aa64_sve2_bitperm, gen_gvec_ool_arg_zzz,
6958 bgrp_fns[a->esz], a, 0)
ed4a6387 6959
615f19fe
RH
6960static gen_helper_gvec_3 * const cadd_fns[4] = {
6961 gen_helper_sve2_cadd_b, gen_helper_sve2_cadd_h,
6962 gen_helper_sve2_cadd_s, gen_helper_sve2_cadd_d,
6963};
6964TRANS_FEAT(CADD_rot90, aa64_sve2, gen_gvec_ool_arg_zzz,
6965 cadd_fns[a->esz], a, 0)
6966TRANS_FEAT(CADD_rot270, aa64_sve2, gen_gvec_ool_arg_zzz,
6967 cadd_fns[a->esz], a, 1)
6968
6969static gen_helper_gvec_3 * const sqcadd_fns[4] = {
6970 gen_helper_sve2_sqcadd_b, gen_helper_sve2_sqcadd_h,
6971 gen_helper_sve2_sqcadd_s, gen_helper_sve2_sqcadd_d,
6972};
6973TRANS_FEAT(SQCADD_rot90, aa64_sve2, gen_gvec_ool_arg_zzz,
6974 sqcadd_fns[a->esz], a, 0)
6975TRANS_FEAT(SQCADD_rot270, aa64_sve2, gen_gvec_ool_arg_zzz,
6976 sqcadd_fns[a->esz], a, 1)
38650638 6977
eeb4e84d
RH
6978static gen_helper_gvec_4 * const sabal_fns[4] = {
6979 NULL, gen_helper_sve2_sabal_h,
6980 gen_helper_sve2_sabal_s, gen_helper_sve2_sabal_d,
6981};
6982TRANS_FEAT(SABALB, aa64_sve2, gen_gvec_ool_arg_zzzz, sabal_fns[a->esz], a, 0)
6983TRANS_FEAT(SABALT, aa64_sve2, gen_gvec_ool_arg_zzzz, sabal_fns[a->esz], a, 1)
38650638 6984
eeb4e84d
RH
6985static gen_helper_gvec_4 * const uabal_fns[4] = {
6986 NULL, gen_helper_sve2_uabal_h,
6987 gen_helper_sve2_uabal_s, gen_helper_sve2_uabal_d,
6988};
6989TRANS_FEAT(UABALB, aa64_sve2, gen_gvec_ool_arg_zzzz, uabal_fns[a->esz], a, 0)
6990TRANS_FEAT(UABALT, aa64_sve2, gen_gvec_ool_arg_zzzz, uabal_fns[a->esz], a, 1)
b8295dfb
RH
6991
6992static bool do_adcl(DisasContext *s, arg_rrrr_esz *a, bool sel)
6993{
6994 static gen_helper_gvec_4 * const fns[2] = {
6995 gen_helper_sve2_adcl_s,
6996 gen_helper_sve2_adcl_d,
6997 };
6998 /*
6999 * Note that in this case the ESZ field encodes both size and sign.
7000 * Split out 'subtract' into bit 1 of the data field for the helper.
7001 */
eeb4e84d 7002 return gen_gvec_ool_arg_zzzz(s, fns[a->esz & 1], a, (a->esz & 2) | sel);
b8295dfb
RH
7003}
7004
eeb4e84d
RH
7005TRANS_FEAT(ADCLB, aa64_sve2, do_adcl, a, false)
7006TRANS_FEAT(ADCLT, aa64_sve2, do_adcl, a, true)
a7e3a90e
RH
7007
7008static bool do_sve2_fn2i(DisasContext *s, arg_rri_esz *a, GVecGen2iFn *fn)
7009{
7010 if (a->esz < 0 || !dc_isar_feature(aa64_sve2, s)) {
7011 return false;
7012 }
7013 if (sve_access_check(s)) {
7014 unsigned vsz = vec_full_reg_size(s);
7015 unsigned rd_ofs = vec_full_reg_offset(s, a->rd);
7016 unsigned rn_ofs = vec_full_reg_offset(s, a->rn);
7017 fn(a->esz, rd_ofs, rn_ofs, a->imm, vsz, vsz);
7018 }
7019 return true;
7020}
7021
7022static bool trans_SSRA(DisasContext *s, arg_rri_esz *a)
7023{
7024 return do_sve2_fn2i(s, a, gen_gvec_ssra);
7025}
7026
7027static bool trans_USRA(DisasContext *s, arg_rri_esz *a)
7028{
7029 return do_sve2_fn2i(s, a, gen_gvec_usra);
7030}
7031
7032static bool trans_SRSRA(DisasContext *s, arg_rri_esz *a)
7033{
7034 return do_sve2_fn2i(s, a, gen_gvec_srsra);
7035}
7036
7037static bool trans_URSRA(DisasContext *s, arg_rri_esz *a)
7038{
7039 return do_sve2_fn2i(s, a, gen_gvec_ursra);
7040}
fc12b46a
RH
7041
7042static bool trans_SRI(DisasContext *s, arg_rri_esz *a)
7043{
7044 return do_sve2_fn2i(s, a, gen_gvec_sri);
7045}
7046
7047static bool trans_SLI(DisasContext *s, arg_rri_esz *a)
7048{
7049 return do_sve2_fn2i(s, a, gen_gvec_sli);
7050}
289a1797
RH
7051
7052static bool do_sve2_fn_zzz(DisasContext *s, arg_rrr_esz *a, GVecGen3Fn *fn)
7053{
7054 if (!dc_isar_feature(aa64_sve2, s)) {
7055 return false;
7056 }
7057 if (sve_access_check(s)) {
7058 gen_gvec_fn_zzz(s, fn, a->esz, a->rd, a->rn, a->rm);
7059 }
7060 return true;
7061}
7062
7063static bool trans_SABA(DisasContext *s, arg_rrr_esz *a)
7064{
7065 return do_sve2_fn_zzz(s, a, gen_gvec_saba);
7066}
7067
7068static bool trans_UABA(DisasContext *s, arg_rrr_esz *a)
7069{
7070 return do_sve2_fn_zzz(s, a, gen_gvec_uaba);
7071}
5ff2838d
RH
7072
7073static bool do_sve2_narrow_extract(DisasContext *s, arg_rri_esz *a,
7074 const GVecGen2 ops[3])
7075{
7076 if (a->esz < 0 || a->esz > MO_32 || a->imm != 0 ||
7077 !dc_isar_feature(aa64_sve2, s)) {
7078 return false;
7079 }
7080 if (sve_access_check(s)) {
7081 unsigned vsz = vec_full_reg_size(s);
7082 tcg_gen_gvec_2(vec_full_reg_offset(s, a->rd),
7083 vec_full_reg_offset(s, a->rn),
7084 vsz, vsz, &ops[a->esz]);
7085 }
7086 return true;
7087}
7088
7089static const TCGOpcode sqxtn_list[] = {
7090 INDEX_op_shli_vec, INDEX_op_smin_vec, INDEX_op_smax_vec, 0
7091};
7092
7093static void gen_sqxtnb_vec(unsigned vece, TCGv_vec d, TCGv_vec n)
7094{
7095 TCGv_vec t = tcg_temp_new_vec_matching(d);
7096 int halfbits = 4 << vece;
7097 int64_t mask = (1ull << halfbits) - 1;
7098 int64_t min = -1ull << (halfbits - 1);
7099 int64_t max = -min - 1;
7100
7101 tcg_gen_dupi_vec(vece, t, min);
7102 tcg_gen_smax_vec(vece, d, n, t);
7103 tcg_gen_dupi_vec(vece, t, max);
7104 tcg_gen_smin_vec(vece, d, d, t);
7105 tcg_gen_dupi_vec(vece, t, mask);
7106 tcg_gen_and_vec(vece, d, d, t);
7107 tcg_temp_free_vec(t);
7108}
7109
7110static bool trans_SQXTNB(DisasContext *s, arg_rri_esz *a)
7111{
7112 static const GVecGen2 ops[3] = {
7113 { .fniv = gen_sqxtnb_vec,
7114 .opt_opc = sqxtn_list,
7115 .fno = gen_helper_sve2_sqxtnb_h,
7116 .vece = MO_16 },
7117 { .fniv = gen_sqxtnb_vec,
7118 .opt_opc = sqxtn_list,
7119 .fno = gen_helper_sve2_sqxtnb_s,
7120 .vece = MO_32 },
7121 { .fniv = gen_sqxtnb_vec,
7122 .opt_opc = sqxtn_list,
7123 .fno = gen_helper_sve2_sqxtnb_d,
7124 .vece = MO_64 },
7125 };
7126 return do_sve2_narrow_extract(s, a, ops);
7127}
7128
7129static void gen_sqxtnt_vec(unsigned vece, TCGv_vec d, TCGv_vec n)
7130{
7131 TCGv_vec t = tcg_temp_new_vec_matching(d);
7132 int halfbits = 4 << vece;
7133 int64_t mask = (1ull << halfbits) - 1;
7134 int64_t min = -1ull << (halfbits - 1);
7135 int64_t max = -min - 1;
7136
7137 tcg_gen_dupi_vec(vece, t, min);
7138 tcg_gen_smax_vec(vece, n, n, t);
7139 tcg_gen_dupi_vec(vece, t, max);
7140 tcg_gen_smin_vec(vece, n, n, t);
7141 tcg_gen_shli_vec(vece, n, n, halfbits);
7142 tcg_gen_dupi_vec(vece, t, mask);
7143 tcg_gen_bitsel_vec(vece, d, t, d, n);
7144 tcg_temp_free_vec(t);
7145}
7146
7147static bool trans_SQXTNT(DisasContext *s, arg_rri_esz *a)
7148{
7149 static const GVecGen2 ops[3] = {
7150 { .fniv = gen_sqxtnt_vec,
7151 .opt_opc = sqxtn_list,
7152 .load_dest = true,
7153 .fno = gen_helper_sve2_sqxtnt_h,
7154 .vece = MO_16 },
7155 { .fniv = gen_sqxtnt_vec,
7156 .opt_opc = sqxtn_list,
7157 .load_dest = true,
7158 .fno = gen_helper_sve2_sqxtnt_s,
7159 .vece = MO_32 },
7160 { .fniv = gen_sqxtnt_vec,
7161 .opt_opc = sqxtn_list,
7162 .load_dest = true,
7163 .fno = gen_helper_sve2_sqxtnt_d,
7164 .vece = MO_64 },
7165 };
7166 return do_sve2_narrow_extract(s, a, ops);
7167}
7168
7169static const TCGOpcode uqxtn_list[] = {
7170 INDEX_op_shli_vec, INDEX_op_umin_vec, 0
7171};
7172
7173static void gen_uqxtnb_vec(unsigned vece, TCGv_vec d, TCGv_vec n)
7174{
7175 TCGv_vec t = tcg_temp_new_vec_matching(d);
7176 int halfbits = 4 << vece;
7177 int64_t max = (1ull << halfbits) - 1;
7178
7179 tcg_gen_dupi_vec(vece, t, max);
7180 tcg_gen_umin_vec(vece, d, n, t);
7181 tcg_temp_free_vec(t);
7182}
7183
7184static bool trans_UQXTNB(DisasContext *s, arg_rri_esz *a)
7185{
7186 static const GVecGen2 ops[3] = {
7187 { .fniv = gen_uqxtnb_vec,
7188 .opt_opc = uqxtn_list,
7189 .fno = gen_helper_sve2_uqxtnb_h,
7190 .vece = MO_16 },
7191 { .fniv = gen_uqxtnb_vec,
7192 .opt_opc = uqxtn_list,
7193 .fno = gen_helper_sve2_uqxtnb_s,
7194 .vece = MO_32 },
7195 { .fniv = gen_uqxtnb_vec,
7196 .opt_opc = uqxtn_list,
7197 .fno = gen_helper_sve2_uqxtnb_d,
7198 .vece = MO_64 },
7199 };
7200 return do_sve2_narrow_extract(s, a, ops);
7201}
7202
7203static void gen_uqxtnt_vec(unsigned vece, TCGv_vec d, TCGv_vec n)
7204{
7205 TCGv_vec t = tcg_temp_new_vec_matching(d);
7206 int halfbits = 4 << vece;
7207 int64_t max = (1ull << halfbits) - 1;
7208
7209 tcg_gen_dupi_vec(vece, t, max);
7210 tcg_gen_umin_vec(vece, n, n, t);
7211 tcg_gen_shli_vec(vece, n, n, halfbits);
7212 tcg_gen_bitsel_vec(vece, d, t, d, n);
7213 tcg_temp_free_vec(t);
7214}
7215
7216static bool trans_UQXTNT(DisasContext *s, arg_rri_esz *a)
7217{
7218 static const GVecGen2 ops[3] = {
7219 { .fniv = gen_uqxtnt_vec,
7220 .opt_opc = uqxtn_list,
7221 .load_dest = true,
7222 .fno = gen_helper_sve2_uqxtnt_h,
7223 .vece = MO_16 },
7224 { .fniv = gen_uqxtnt_vec,
7225 .opt_opc = uqxtn_list,
7226 .load_dest = true,
7227 .fno = gen_helper_sve2_uqxtnt_s,
7228 .vece = MO_32 },
7229 { .fniv = gen_uqxtnt_vec,
7230 .opt_opc = uqxtn_list,
7231 .load_dest = true,
7232 .fno = gen_helper_sve2_uqxtnt_d,
7233 .vece = MO_64 },
7234 };
7235 return do_sve2_narrow_extract(s, a, ops);
7236}
7237
7238static const TCGOpcode sqxtun_list[] = {
7239 INDEX_op_shli_vec, INDEX_op_umin_vec, INDEX_op_smax_vec, 0
7240};
7241
7242static void gen_sqxtunb_vec(unsigned vece, TCGv_vec d, TCGv_vec n)
7243{
7244 TCGv_vec t = tcg_temp_new_vec_matching(d);
7245 int halfbits = 4 << vece;
7246 int64_t max = (1ull << halfbits) - 1;
7247
7248 tcg_gen_dupi_vec(vece, t, 0);
7249 tcg_gen_smax_vec(vece, d, n, t);
7250 tcg_gen_dupi_vec(vece, t, max);
7251 tcg_gen_umin_vec(vece, d, d, t);
7252 tcg_temp_free_vec(t);
7253}
7254
7255static bool trans_SQXTUNB(DisasContext *s, arg_rri_esz *a)
7256{
7257 static const GVecGen2 ops[3] = {
7258 { .fniv = gen_sqxtunb_vec,
7259 .opt_opc = sqxtun_list,
7260 .fno = gen_helper_sve2_sqxtunb_h,
7261 .vece = MO_16 },
7262 { .fniv = gen_sqxtunb_vec,
7263 .opt_opc = sqxtun_list,
7264 .fno = gen_helper_sve2_sqxtunb_s,
7265 .vece = MO_32 },
7266 { .fniv = gen_sqxtunb_vec,
7267 .opt_opc = sqxtun_list,
7268 .fno = gen_helper_sve2_sqxtunb_d,
7269 .vece = MO_64 },
7270 };
7271 return do_sve2_narrow_extract(s, a, ops);
7272}
7273
7274static void gen_sqxtunt_vec(unsigned vece, TCGv_vec d, TCGv_vec n)
7275{
7276 TCGv_vec t = tcg_temp_new_vec_matching(d);
7277 int halfbits = 4 << vece;
7278 int64_t max = (1ull << halfbits) - 1;
7279
7280 tcg_gen_dupi_vec(vece, t, 0);
7281 tcg_gen_smax_vec(vece, n, n, t);
7282 tcg_gen_dupi_vec(vece, t, max);
7283 tcg_gen_umin_vec(vece, n, n, t);
7284 tcg_gen_shli_vec(vece, n, n, halfbits);
7285 tcg_gen_bitsel_vec(vece, d, t, d, n);
7286 tcg_temp_free_vec(t);
7287}
7288
7289static bool trans_SQXTUNT(DisasContext *s, arg_rri_esz *a)
7290{
7291 static const GVecGen2 ops[3] = {
7292 { .fniv = gen_sqxtunt_vec,
7293 .opt_opc = sqxtun_list,
7294 .load_dest = true,
7295 .fno = gen_helper_sve2_sqxtunt_h,
7296 .vece = MO_16 },
7297 { .fniv = gen_sqxtunt_vec,
7298 .opt_opc = sqxtun_list,
7299 .load_dest = true,
7300 .fno = gen_helper_sve2_sqxtunt_s,
7301 .vece = MO_32 },
7302 { .fniv = gen_sqxtunt_vec,
7303 .opt_opc = sqxtun_list,
7304 .load_dest = true,
7305 .fno = gen_helper_sve2_sqxtunt_d,
7306 .vece = MO_64 },
7307 };
7308 return do_sve2_narrow_extract(s, a, ops);
46d111b2
RH
7309}
7310
7311static bool do_sve2_shr_narrow(DisasContext *s, arg_rri_esz *a,
7312 const GVecGen2i ops[3])
7313{
7314 if (a->esz < 0 || a->esz > MO_32 || !dc_isar_feature(aa64_sve2, s)) {
7315 return false;
7316 }
7317 assert(a->imm > 0 && a->imm <= (8 << a->esz));
7318 if (sve_access_check(s)) {
7319 unsigned vsz = vec_full_reg_size(s);
7320 tcg_gen_gvec_2i(vec_full_reg_offset(s, a->rd),
7321 vec_full_reg_offset(s, a->rn),
7322 vsz, vsz, a->imm, &ops[a->esz]);
7323 }
7324 return true;
7325}
7326
7327static void gen_shrnb_i64(unsigned vece, TCGv_i64 d, TCGv_i64 n, int shr)
7328{
7329 int halfbits = 4 << vece;
7330 uint64_t mask = dup_const(vece, MAKE_64BIT_MASK(0, halfbits));
7331
7332 tcg_gen_shri_i64(d, n, shr);
7333 tcg_gen_andi_i64(d, d, mask);
7334}
7335
7336static void gen_shrnb16_i64(TCGv_i64 d, TCGv_i64 n, int64_t shr)
7337{
7338 gen_shrnb_i64(MO_16, d, n, shr);
7339}
7340
7341static void gen_shrnb32_i64(TCGv_i64 d, TCGv_i64 n, int64_t shr)
7342{
7343 gen_shrnb_i64(MO_32, d, n, shr);
7344}
7345
7346static void gen_shrnb64_i64(TCGv_i64 d, TCGv_i64 n, int64_t shr)
7347{
7348 gen_shrnb_i64(MO_64, d, n, shr);
7349}
7350
7351static void gen_shrnb_vec(unsigned vece, TCGv_vec d, TCGv_vec n, int64_t shr)
7352{
7353 TCGv_vec t = tcg_temp_new_vec_matching(d);
7354 int halfbits = 4 << vece;
7355 uint64_t mask = MAKE_64BIT_MASK(0, halfbits);
7356
7357 tcg_gen_shri_vec(vece, n, n, shr);
7358 tcg_gen_dupi_vec(vece, t, mask);
7359 tcg_gen_and_vec(vece, d, n, t);
7360 tcg_temp_free_vec(t);
7361}
7362
7363static bool trans_SHRNB(DisasContext *s, arg_rri_esz *a)
7364{
7365 static const TCGOpcode vec_list[] = { INDEX_op_shri_vec, 0 };
7366 static const GVecGen2i ops[3] = {
7367 { .fni8 = gen_shrnb16_i64,
7368 .fniv = gen_shrnb_vec,
7369 .opt_opc = vec_list,
7370 .fno = gen_helper_sve2_shrnb_h,
7371 .vece = MO_16 },
7372 { .fni8 = gen_shrnb32_i64,
7373 .fniv = gen_shrnb_vec,
7374 .opt_opc = vec_list,
7375 .fno = gen_helper_sve2_shrnb_s,
7376 .vece = MO_32 },
7377 { .fni8 = gen_shrnb64_i64,
7378 .fniv = gen_shrnb_vec,
7379 .opt_opc = vec_list,
7380 .fno = gen_helper_sve2_shrnb_d,
7381 .vece = MO_64 },
7382 };
7383 return do_sve2_shr_narrow(s, a, ops);
7384}
7385
7386static void gen_shrnt_i64(unsigned vece, TCGv_i64 d, TCGv_i64 n, int shr)
7387{
7388 int halfbits = 4 << vece;
7389 uint64_t mask = dup_const(vece, MAKE_64BIT_MASK(0, halfbits));
7390
7391 tcg_gen_shli_i64(n, n, halfbits - shr);
7392 tcg_gen_andi_i64(n, n, ~mask);
7393 tcg_gen_andi_i64(d, d, mask);
7394 tcg_gen_or_i64(d, d, n);
7395}
7396
7397static void gen_shrnt16_i64(TCGv_i64 d, TCGv_i64 n, int64_t shr)
7398{
7399 gen_shrnt_i64(MO_16, d, n, shr);
7400}
7401
7402static void gen_shrnt32_i64(TCGv_i64 d, TCGv_i64 n, int64_t shr)
7403{
7404 gen_shrnt_i64(MO_32, d, n, shr);
7405}
7406
7407static void gen_shrnt64_i64(TCGv_i64 d, TCGv_i64 n, int64_t shr)
7408{
7409 tcg_gen_shri_i64(n, n, shr);
7410 tcg_gen_deposit_i64(d, d, n, 32, 32);
7411}
7412
7413static void gen_shrnt_vec(unsigned vece, TCGv_vec d, TCGv_vec n, int64_t shr)
7414{
7415 TCGv_vec t = tcg_temp_new_vec_matching(d);
7416 int halfbits = 4 << vece;
7417 uint64_t mask = MAKE_64BIT_MASK(0, halfbits);
7418
7419 tcg_gen_shli_vec(vece, n, n, halfbits - shr);
7420 tcg_gen_dupi_vec(vece, t, mask);
7421 tcg_gen_bitsel_vec(vece, d, t, d, n);
7422 tcg_temp_free_vec(t);
7423}
7424
7425static bool trans_SHRNT(DisasContext *s, arg_rri_esz *a)
7426{
7427 static const TCGOpcode vec_list[] = { INDEX_op_shli_vec, 0 };
7428 static const GVecGen2i ops[3] = {
7429 { .fni8 = gen_shrnt16_i64,
7430 .fniv = gen_shrnt_vec,
7431 .opt_opc = vec_list,
7432 .load_dest = true,
7433 .fno = gen_helper_sve2_shrnt_h,
7434 .vece = MO_16 },
7435 { .fni8 = gen_shrnt32_i64,
7436 .fniv = gen_shrnt_vec,
7437 .opt_opc = vec_list,
7438 .load_dest = true,
7439 .fno = gen_helper_sve2_shrnt_s,
7440 .vece = MO_32 },
7441 { .fni8 = gen_shrnt64_i64,
7442 .fniv = gen_shrnt_vec,
7443 .opt_opc = vec_list,
7444 .load_dest = true,
7445 .fno = gen_helper_sve2_shrnt_d,
7446 .vece = MO_64 },
7447 };
7448 return do_sve2_shr_narrow(s, a, ops);
7449}
7450
7451static bool trans_RSHRNB(DisasContext *s, arg_rri_esz *a)
7452{
7453 static const GVecGen2i ops[3] = {
7454 { .fno = gen_helper_sve2_rshrnb_h },
7455 { .fno = gen_helper_sve2_rshrnb_s },
7456 { .fno = gen_helper_sve2_rshrnb_d },
7457 };
7458 return do_sve2_shr_narrow(s, a, ops);
7459}
7460
7461static bool trans_RSHRNT(DisasContext *s, arg_rri_esz *a)
7462{
7463 static const GVecGen2i ops[3] = {
7464 { .fno = gen_helper_sve2_rshrnt_h },
7465 { .fno = gen_helper_sve2_rshrnt_s },
7466 { .fno = gen_helper_sve2_rshrnt_d },
7467 };
7468 return do_sve2_shr_narrow(s, a, ops);
81fd3e6e
RH
7469}
7470
7471static void gen_sqshrunb_vec(unsigned vece, TCGv_vec d,
7472 TCGv_vec n, int64_t shr)
7473{
7474 TCGv_vec t = tcg_temp_new_vec_matching(d);
7475 int halfbits = 4 << vece;
7476
7477 tcg_gen_sari_vec(vece, n, n, shr);
7478 tcg_gen_dupi_vec(vece, t, 0);
7479 tcg_gen_smax_vec(vece, n, n, t);
7480 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(0, halfbits));
7481 tcg_gen_umin_vec(vece, d, n, t);
7482 tcg_temp_free_vec(t);
7483}
7484
7485static bool trans_SQSHRUNB(DisasContext *s, arg_rri_esz *a)
7486{
7487 static const TCGOpcode vec_list[] = {
7488 INDEX_op_sari_vec, INDEX_op_smax_vec, INDEX_op_umin_vec, 0
7489 };
7490 static const GVecGen2i ops[3] = {
7491 { .fniv = gen_sqshrunb_vec,
7492 .opt_opc = vec_list,
7493 .fno = gen_helper_sve2_sqshrunb_h,
7494 .vece = MO_16 },
7495 { .fniv = gen_sqshrunb_vec,
7496 .opt_opc = vec_list,
7497 .fno = gen_helper_sve2_sqshrunb_s,
7498 .vece = MO_32 },
7499 { .fniv = gen_sqshrunb_vec,
7500 .opt_opc = vec_list,
7501 .fno = gen_helper_sve2_sqshrunb_d,
7502 .vece = MO_64 },
7503 };
7504 return do_sve2_shr_narrow(s, a, ops);
7505}
7506
7507static void gen_sqshrunt_vec(unsigned vece, TCGv_vec d,
7508 TCGv_vec n, int64_t shr)
7509{
7510 TCGv_vec t = tcg_temp_new_vec_matching(d);
7511 int halfbits = 4 << vece;
7512
7513 tcg_gen_sari_vec(vece, n, n, shr);
7514 tcg_gen_dupi_vec(vece, t, 0);
7515 tcg_gen_smax_vec(vece, n, n, t);
7516 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(0, halfbits));
7517 tcg_gen_umin_vec(vece, n, n, t);
7518 tcg_gen_shli_vec(vece, n, n, halfbits);
7519 tcg_gen_bitsel_vec(vece, d, t, d, n);
7520 tcg_temp_free_vec(t);
7521}
7522
7523static bool trans_SQSHRUNT(DisasContext *s, arg_rri_esz *a)
7524{
7525 static const TCGOpcode vec_list[] = {
7526 INDEX_op_shli_vec, INDEX_op_sari_vec,
7527 INDEX_op_smax_vec, INDEX_op_umin_vec, 0
7528 };
7529 static const GVecGen2i ops[3] = {
7530 { .fniv = gen_sqshrunt_vec,
7531 .opt_opc = vec_list,
7532 .load_dest = true,
7533 .fno = gen_helper_sve2_sqshrunt_h,
7534 .vece = MO_16 },
7535 { .fniv = gen_sqshrunt_vec,
7536 .opt_opc = vec_list,
7537 .load_dest = true,
7538 .fno = gen_helper_sve2_sqshrunt_s,
7539 .vece = MO_32 },
7540 { .fniv = gen_sqshrunt_vec,
7541 .opt_opc = vec_list,
7542 .load_dest = true,
7543 .fno = gen_helper_sve2_sqshrunt_d,
7544 .vece = MO_64 },
7545 };
7546 return do_sve2_shr_narrow(s, a, ops);
7547}
7548
7549static bool trans_SQRSHRUNB(DisasContext *s, arg_rri_esz *a)
7550{
7551 static const GVecGen2i ops[3] = {
7552 { .fno = gen_helper_sve2_sqrshrunb_h },
7553 { .fno = gen_helper_sve2_sqrshrunb_s },
7554 { .fno = gen_helper_sve2_sqrshrunb_d },
7555 };
7556 return do_sve2_shr_narrow(s, a, ops);
7557}
7558
7559static bool trans_SQRSHRUNT(DisasContext *s, arg_rri_esz *a)
7560{
7561 static const GVecGen2i ops[3] = {
7562 { .fno = gen_helper_sve2_sqrshrunt_h },
7563 { .fno = gen_helper_sve2_sqrshrunt_s },
7564 { .fno = gen_helper_sve2_sqrshrunt_d },
7565 };
7566 return do_sve2_shr_narrow(s, a, ops);
c13418da
RH
7567}
7568
743bb147
RH
7569static void gen_sqshrnb_vec(unsigned vece, TCGv_vec d,
7570 TCGv_vec n, int64_t shr)
7571{
7572 TCGv_vec t = tcg_temp_new_vec_matching(d);
7573 int halfbits = 4 << vece;
7574 int64_t max = MAKE_64BIT_MASK(0, halfbits - 1);
7575 int64_t min = -max - 1;
7576
7577 tcg_gen_sari_vec(vece, n, n, shr);
7578 tcg_gen_dupi_vec(vece, t, min);
7579 tcg_gen_smax_vec(vece, n, n, t);
7580 tcg_gen_dupi_vec(vece, t, max);
7581 tcg_gen_smin_vec(vece, n, n, t);
7582 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(0, halfbits));
7583 tcg_gen_and_vec(vece, d, n, t);
7584 tcg_temp_free_vec(t);
7585}
7586
7587static bool trans_SQSHRNB(DisasContext *s, arg_rri_esz *a)
7588{
7589 static const TCGOpcode vec_list[] = {
7590 INDEX_op_sari_vec, INDEX_op_smax_vec, INDEX_op_smin_vec, 0
7591 };
7592 static const GVecGen2i ops[3] = {
7593 { .fniv = gen_sqshrnb_vec,
7594 .opt_opc = vec_list,
7595 .fno = gen_helper_sve2_sqshrnb_h,
7596 .vece = MO_16 },
7597 { .fniv = gen_sqshrnb_vec,
7598 .opt_opc = vec_list,
7599 .fno = gen_helper_sve2_sqshrnb_s,
7600 .vece = MO_32 },
7601 { .fniv = gen_sqshrnb_vec,
7602 .opt_opc = vec_list,
7603 .fno = gen_helper_sve2_sqshrnb_d,
7604 .vece = MO_64 },
7605 };
7606 return do_sve2_shr_narrow(s, a, ops);
7607}
7608
7609static void gen_sqshrnt_vec(unsigned vece, TCGv_vec d,
7610 TCGv_vec n, int64_t shr)
7611{
7612 TCGv_vec t = tcg_temp_new_vec_matching(d);
7613 int halfbits = 4 << vece;
7614 int64_t max = MAKE_64BIT_MASK(0, halfbits - 1);
7615 int64_t min = -max - 1;
7616
7617 tcg_gen_sari_vec(vece, n, n, shr);
7618 tcg_gen_dupi_vec(vece, t, min);
7619 tcg_gen_smax_vec(vece, n, n, t);
7620 tcg_gen_dupi_vec(vece, t, max);
7621 tcg_gen_smin_vec(vece, n, n, t);
7622 tcg_gen_shli_vec(vece, n, n, halfbits);
7623 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(0, halfbits));
7624 tcg_gen_bitsel_vec(vece, d, t, d, n);
7625 tcg_temp_free_vec(t);
7626}
7627
7628static bool trans_SQSHRNT(DisasContext *s, arg_rri_esz *a)
7629{
7630 static const TCGOpcode vec_list[] = {
7631 INDEX_op_shli_vec, INDEX_op_sari_vec,
7632 INDEX_op_smax_vec, INDEX_op_smin_vec, 0
7633 };
7634 static const GVecGen2i ops[3] = {
7635 { .fniv = gen_sqshrnt_vec,
7636 .opt_opc = vec_list,
7637 .load_dest = true,
7638 .fno = gen_helper_sve2_sqshrnt_h,
7639 .vece = MO_16 },
7640 { .fniv = gen_sqshrnt_vec,
7641 .opt_opc = vec_list,
7642 .load_dest = true,
7643 .fno = gen_helper_sve2_sqshrnt_s,
7644 .vece = MO_32 },
7645 { .fniv = gen_sqshrnt_vec,
7646 .opt_opc = vec_list,
7647 .load_dest = true,
7648 .fno = gen_helper_sve2_sqshrnt_d,
7649 .vece = MO_64 },
7650 };
7651 return do_sve2_shr_narrow(s, a, ops);
7652}
7653
7654static bool trans_SQRSHRNB(DisasContext *s, arg_rri_esz *a)
7655{
7656 static const GVecGen2i ops[3] = {
7657 { .fno = gen_helper_sve2_sqrshrnb_h },
7658 { .fno = gen_helper_sve2_sqrshrnb_s },
7659 { .fno = gen_helper_sve2_sqrshrnb_d },
7660 };
7661 return do_sve2_shr_narrow(s, a, ops);
7662}
7663
7664static bool trans_SQRSHRNT(DisasContext *s, arg_rri_esz *a)
7665{
7666 static const GVecGen2i ops[3] = {
7667 { .fno = gen_helper_sve2_sqrshrnt_h },
7668 { .fno = gen_helper_sve2_sqrshrnt_s },
7669 { .fno = gen_helper_sve2_sqrshrnt_d },
7670 };
7671 return do_sve2_shr_narrow(s, a, ops);
7672}
7673
c13418da
RH
7674static void gen_uqshrnb_vec(unsigned vece, TCGv_vec d,
7675 TCGv_vec n, int64_t shr)
7676{
7677 TCGv_vec t = tcg_temp_new_vec_matching(d);
7678 int halfbits = 4 << vece;
7679
7680 tcg_gen_shri_vec(vece, n, n, shr);
7681 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(0, halfbits));
7682 tcg_gen_umin_vec(vece, d, n, t);
7683 tcg_temp_free_vec(t);
7684}
7685
7686static bool trans_UQSHRNB(DisasContext *s, arg_rri_esz *a)
7687{
7688 static const TCGOpcode vec_list[] = {
7689 INDEX_op_shri_vec, INDEX_op_umin_vec, 0
7690 };
7691 static const GVecGen2i ops[3] = {
7692 { .fniv = gen_uqshrnb_vec,
7693 .opt_opc = vec_list,
7694 .fno = gen_helper_sve2_uqshrnb_h,
7695 .vece = MO_16 },
7696 { .fniv = gen_uqshrnb_vec,
7697 .opt_opc = vec_list,
7698 .fno = gen_helper_sve2_uqshrnb_s,
7699 .vece = MO_32 },
7700 { .fniv = gen_uqshrnb_vec,
7701 .opt_opc = vec_list,
7702 .fno = gen_helper_sve2_uqshrnb_d,
7703 .vece = MO_64 },
7704 };
7705 return do_sve2_shr_narrow(s, a, ops);
7706}
7707
7708static void gen_uqshrnt_vec(unsigned vece, TCGv_vec d,
7709 TCGv_vec n, int64_t shr)
7710{
7711 TCGv_vec t = tcg_temp_new_vec_matching(d);
7712 int halfbits = 4 << vece;
7713
7714 tcg_gen_shri_vec(vece, n, n, shr);
7715 tcg_gen_dupi_vec(vece, t, MAKE_64BIT_MASK(0, halfbits));
7716 tcg_gen_umin_vec(vece, n, n, t);
7717 tcg_gen_shli_vec(vece, n, n, halfbits);
7718 tcg_gen_bitsel_vec(vece, d, t, d, n);
7719 tcg_temp_free_vec(t);
7720}
7721
7722static bool trans_UQSHRNT(DisasContext *s, arg_rri_esz *a)
7723{
7724 static const TCGOpcode vec_list[] = {
7725 INDEX_op_shli_vec, INDEX_op_shri_vec, INDEX_op_umin_vec, 0
7726 };
7727 static const GVecGen2i ops[3] = {
7728 { .fniv = gen_uqshrnt_vec,
7729 .opt_opc = vec_list,
7730 .load_dest = true,
7731 .fno = gen_helper_sve2_uqshrnt_h,
7732 .vece = MO_16 },
7733 { .fniv = gen_uqshrnt_vec,
7734 .opt_opc = vec_list,
7735 .load_dest = true,
7736 .fno = gen_helper_sve2_uqshrnt_s,
7737 .vece = MO_32 },
7738 { .fniv = gen_uqshrnt_vec,
7739 .opt_opc = vec_list,
7740 .load_dest = true,
7741 .fno = gen_helper_sve2_uqshrnt_d,
7742 .vece = MO_64 },
7743 };
7744 return do_sve2_shr_narrow(s, a, ops);
7745}
7746
7747static bool trans_UQRSHRNB(DisasContext *s, arg_rri_esz *a)
7748{
7749 static const GVecGen2i ops[3] = {
7750 { .fno = gen_helper_sve2_uqrshrnb_h },
7751 { .fno = gen_helper_sve2_uqrshrnb_s },
7752 { .fno = gen_helper_sve2_uqrshrnb_d },
7753 };
7754 return do_sve2_shr_narrow(s, a, ops);
7755}
7756
7757static bool trans_UQRSHRNT(DisasContext *s, arg_rri_esz *a)
7758{
7759 static const GVecGen2i ops[3] = {
7760 { .fno = gen_helper_sve2_uqrshrnt_h },
7761 { .fno = gen_helper_sve2_uqrshrnt_s },
7762 { .fno = gen_helper_sve2_uqrshrnt_d },
7763 };
7764 return do_sve2_shr_narrow(s, a, ops);
5ff2838d 7765}
b87dbeeb 7766
40d5ea50 7767#define DO_SVE2_ZZZ_NARROW(NAME, name) \
bd394cf5 7768 static gen_helper_gvec_3 * const name##_fns[4] = { \
40d5ea50
SL
7769 NULL, gen_helper_sve2_##name##_h, \
7770 gen_helper_sve2_##name##_s, gen_helper_sve2_##name##_d, \
7771 }; \
bd394cf5
RH
7772 TRANS_FEAT(NAME, aa64_sve2, gen_gvec_ool_arg_zzz, \
7773 name##_fns[a->esz], a, 0)
40d5ea50
SL
7774
7775DO_SVE2_ZZZ_NARROW(ADDHNB, addhnb)
7776DO_SVE2_ZZZ_NARROW(ADDHNT, addhnt)
0ea3ff02
SL
7777DO_SVE2_ZZZ_NARROW(RADDHNB, raddhnb)
7778DO_SVE2_ZZZ_NARROW(RADDHNT, raddhnt)
40d5ea50 7779
c3cd6766
SL
7780DO_SVE2_ZZZ_NARROW(SUBHNB, subhnb)
7781DO_SVE2_ZZZ_NARROW(SUBHNT, subhnt)
e9443d10
SL
7782DO_SVE2_ZZZ_NARROW(RSUBHNB, rsubhnb)
7783DO_SVE2_ZZZ_NARROW(RSUBHNT, rsubhnt)
c3cd6766 7784
e0ae6ec3
SL
7785static bool do_sve2_ppzz_flags(DisasContext *s, arg_rprr_esz *a,
7786 gen_helper_gvec_flags_4 *fn)
7787{
7788 if (!dc_isar_feature(aa64_sve2, s)) {
7789 return false;
7790 }
7791 return do_ppzz_flags(s, a, fn);
7792}
7793
7794#define DO_SVE2_PPZZ_MATCH(NAME, name) \
7795static bool trans_##NAME(DisasContext *s, arg_rprr_esz *a) \
7796{ \
7797 static gen_helper_gvec_flags_4 * const fns[4] = { \
7798 gen_helper_sve2_##name##_ppzz_b, gen_helper_sve2_##name##_ppzz_h, \
7799 NULL, NULL \
7800 }; \
7801 return do_sve2_ppzz_flags(s, a, fns[a->esz]); \
7802}
7803
7804DO_SVE2_PPZZ_MATCH(MATCH, match)
7805DO_SVE2_PPZZ_MATCH(NMATCH, nmatch)
7806
7d47ac94
SL
7807static bool trans_HISTCNT(DisasContext *s, arg_rprr_esz *a)
7808{
7809 static gen_helper_gvec_4 * const fns[2] = {
7810 gen_helper_sve2_histcnt_s, gen_helper_sve2_histcnt_d
7811 };
7812 if (a->esz < 2) {
7813 return false;
7814 }
7815 return do_sve2_zpzz_ool(s, a, fns[a->esz - 2]);
7816}
7817
bd394cf5
RH
7818TRANS_FEAT(HISTSEG, aa64_sve2, gen_gvec_ool_arg_zzz,
7819 a->esz == 0 ? gen_helper_sve2_histseg : NULL, a, 0)
7d47ac94 7820
b87dbeeb
SL
7821static bool do_sve2_zpzz_fp(DisasContext *s, arg_rprr_esz *a,
7822 gen_helper_gvec_4_ptr *fn)
7823{
7824 if (!dc_isar_feature(aa64_sve2, s)) {
7825 return false;
7826 }
7827 return do_zpzz_fp(s, a, fn);
7828}
7829
7830#define DO_SVE2_ZPZZ_FP(NAME, name) \
7831static bool trans_##NAME(DisasContext *s, arg_rprr_esz *a) \
7832{ \
7833 static gen_helper_gvec_4_ptr * const fns[4] = { \
7834 NULL, gen_helper_sve2_##name##_zpzz_h, \
7835 gen_helper_sve2_##name##_zpzz_s, gen_helper_sve2_##name##_zpzz_d \
7836 }; \
7837 return do_sve2_zpzz_fp(s, a, fns[a->esz]); \
7838}
7839
7840DO_SVE2_ZPZZ_FP(FADDP, faddp)
7841DO_SVE2_ZPZZ_FP(FMAXNMP, fmaxnmp)
7842DO_SVE2_ZPZZ_FP(FMINNMP, fminnmp)
7843DO_SVE2_ZPZZ_FP(FMAXP, fmaxp)
7844DO_SVE2_ZPZZ_FP(FMINP, fminp)
bfc9307e
RH
7845
7846/*
7847 * SVE Integer Multiply-Add (unpredicated)
7848 */
7849
4f26756b
SL
7850static bool trans_FMMLA(DisasContext *s, arg_rrrr_esz *a)
7851{
7852 gen_helper_gvec_4_ptr *fn;
7853
7854 switch (a->esz) {
7855 case MO_32:
7856 if (!dc_isar_feature(aa64_sve_f32mm, s)) {
7857 return false;
7858 }
7859 fn = gen_helper_fmmla_s;
7860 break;
7861 case MO_64:
7862 if (!dc_isar_feature(aa64_sve_f64mm, s)) {
7863 return false;
7864 }
7865 fn = gen_helper_fmmla_d;
7866 break;
7867 default:
7868 return false;
7869 }
7870
7871 if (sve_access_check(s)) {
7872 unsigned vsz = vec_full_reg_size(s);
7873 TCGv_ptr status = fpstatus_ptr(FPST_FPCR);
7874 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
7875 vec_full_reg_offset(s, a->rn),
7876 vec_full_reg_offset(s, a->rm),
7877 vec_full_reg_offset(s, a->ra),
7878 status, vsz, vsz, 0, fn);
7879 tcg_temp_free_ptr(status);
7880 }
7881 return true;
7882}
7883
eeb4e84d
RH
7884static gen_helper_gvec_4 * const sqdmlal_zzzw_fns[] = {
7885 NULL, gen_helper_sve2_sqdmlal_zzzw_h,
7886 gen_helper_sve2_sqdmlal_zzzw_s, gen_helper_sve2_sqdmlal_zzzw_d,
7887};
7888TRANS_FEAT(SQDMLALB_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7889 sqdmlal_zzzw_fns[a->esz], a, 0)
7890TRANS_FEAT(SQDMLALT_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7891 sqdmlal_zzzw_fns[a->esz], a, 3)
7892TRANS_FEAT(SQDMLALBT, aa64_sve2, gen_gvec_ool_arg_zzzz,
7893 sqdmlal_zzzw_fns[a->esz], a, 2)
7894
7895static gen_helper_gvec_4 * const sqdmlsl_zzzw_fns[] = {
7896 NULL, gen_helper_sve2_sqdmlsl_zzzw_h,
7897 gen_helper_sve2_sqdmlsl_zzzw_s, gen_helper_sve2_sqdmlsl_zzzw_d,
7898};
7899TRANS_FEAT(SQDMLSLB_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7900 sqdmlsl_zzzw_fns[a->esz], a, 0)
7901TRANS_FEAT(SQDMLSLT_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7902 sqdmlsl_zzzw_fns[a->esz], a, 3)
7903TRANS_FEAT(SQDMLSLBT, aa64_sve2, gen_gvec_ool_arg_zzzz,
7904 sqdmlsl_zzzw_fns[a->esz], a, 2)
7905
7906static gen_helper_gvec_4 * const sqrdmlah_fns[] = {
7907 gen_helper_sve2_sqrdmlah_b, gen_helper_sve2_sqrdmlah_h,
7908 gen_helper_sve2_sqrdmlah_s, gen_helper_sve2_sqrdmlah_d,
7909};
7910TRANS_FEAT(SQRDMLAH_zzzz, aa64_sve2, gen_gvec_ool_arg_zzzz,
7911 sqrdmlah_fns[a->esz], a, 0)
45a32e80 7912
eeb4e84d
RH
7913static gen_helper_gvec_4 * const sqrdmlsh_fns[] = {
7914 gen_helper_sve2_sqrdmlsh_b, gen_helper_sve2_sqrdmlsh_h,
7915 gen_helper_sve2_sqrdmlsh_s, gen_helper_sve2_sqrdmlsh_d,
7916};
7917TRANS_FEAT(SQRDMLSH_zzzz, aa64_sve2, gen_gvec_ool_arg_zzzz,
7918 sqrdmlsh_fns[a->esz], a, 0)
45a32e80 7919
eeb4e84d
RH
7920static gen_helper_gvec_4 * const smlal_zzzw_fns[] = {
7921 NULL, gen_helper_sve2_smlal_zzzw_h,
7922 gen_helper_sve2_smlal_zzzw_s, gen_helper_sve2_smlal_zzzw_d,
7923};
7924TRANS_FEAT(SMLALB_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7925 smlal_zzzw_fns[a->esz], a, 0)
7926TRANS_FEAT(SMLALT_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7927 smlal_zzzw_fns[a->esz], a, 1)
7928
7929static gen_helper_gvec_4 * const umlal_zzzw_fns[] = {
7930 NULL, gen_helper_sve2_umlal_zzzw_h,
7931 gen_helper_sve2_umlal_zzzw_s, gen_helper_sve2_umlal_zzzw_d,
7932};
7933TRANS_FEAT(UMLALB_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7934 umlal_zzzw_fns[a->esz], a, 0)
7935TRANS_FEAT(UMLALT_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7936 umlal_zzzw_fns[a->esz], a, 1)
7937
7938static gen_helper_gvec_4 * const smlsl_zzzw_fns[] = {
7939 NULL, gen_helper_sve2_smlsl_zzzw_h,
7940 gen_helper_sve2_smlsl_zzzw_s, gen_helper_sve2_smlsl_zzzw_d,
7941};
7942TRANS_FEAT(SMLSLB_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7943 smlsl_zzzw_fns[a->esz], a, 0)
7944TRANS_FEAT(SMLSLT_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7945 smlsl_zzzw_fns[a->esz], a, 1)
7946
7947static gen_helper_gvec_4 * const umlsl_zzzw_fns[] = {
7948 NULL, gen_helper_sve2_umlsl_zzzw_h,
7949 gen_helper_sve2_umlsl_zzzw_s, gen_helper_sve2_umlsl_zzzw_d,
7950};
7951TRANS_FEAT(UMLSLB_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7952 umlsl_zzzw_fns[a->esz], a, 0)
7953TRANS_FEAT(UMLSLT_zzzw, aa64_sve2, gen_gvec_ool_arg_zzzz,
7954 umlsl_zzzw_fns[a->esz], a, 1)
d782d3ca 7955
5f425b92
RH
7956static gen_helper_gvec_4 * const cmla_fns[] = {
7957 gen_helper_sve2_cmla_zzzz_b, gen_helper_sve2_cmla_zzzz_h,
7958 gen_helper_sve2_cmla_zzzz_s, gen_helper_sve2_cmla_zzzz_d,
7959};
7960TRANS_FEAT(CMLA_zzzz, aa64_sve2, gen_gvec_ool_zzzz,
7961 cmla_fns[a->esz], a->rd, a->rn, a->rm, a->ra, a->rot)
21068f39 7962
5f425b92
RH
7963static gen_helper_gvec_4 * const cdot_fns[] = {
7964 NULL, NULL, gen_helper_sve2_cdot_zzzz_s, gen_helper_sve2_cdot_zzzz_d
7965};
7966TRANS_FEAT(CDOT_zzzz, aa64_sve2, gen_gvec_ool_zzzz,
7967 cdot_fns[a->esz], a->rd, a->rn, a->rm, a->ra, a->rot)
d782d3ca 7968
5f425b92
RH
7969static gen_helper_gvec_4 * const sqrdcmlah_fns[] = {
7970 gen_helper_sve2_sqrdcmlah_zzzz_b, gen_helper_sve2_sqrdcmlah_zzzz_h,
7971 gen_helper_sve2_sqrdcmlah_zzzz_s, gen_helper_sve2_sqrdcmlah_zzzz_d,
7972};
7973TRANS_FEAT(SQRDCMLAH_zzzz, aa64_sve2, gen_gvec_ool_zzzz,
7974 sqrdcmlah_fns[a->esz], a->rd, a->rn, a->rm, a->ra, a->rot)
6a98cb2a 7975
8740d694
RH
7976TRANS_FEAT(USDOT_zzzz, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz,
7977 a->esz == 2 ? gen_helper_gvec_usdot_b : NULL, a, 0)
b2bcd1be 7978
0ea3cdbf
RH
7979TRANS_FEAT(AESMC, aa64_sve2_aes, gen_gvec_ool_zz,
7980 gen_helper_crypto_aesmc, a->rd, a->rd, a->decrypt)
3cc7a88e 7981
32e2ad65
RH
7982TRANS_FEAT(AESE, aa64_sve2_aes, gen_gvec_ool_arg_zzz,
7983 gen_helper_crypto_aese, a, false)
7984TRANS_FEAT(AESD, aa64_sve2_aes, gen_gvec_ool_arg_zzz,
7985 gen_helper_crypto_aese, a, true)
3cc7a88e 7986
32e2ad65
RH
7987TRANS_FEAT(SM4E, aa64_sve2_sm4, gen_gvec_ool_arg_zzz,
7988 gen_helper_crypto_sm4e, a, 0)
7989TRANS_FEAT(SM4EKEY, aa64_sve2_sm4, gen_gvec_ool_arg_zzz,
7990 gen_helper_crypto_sm4ekey, a, 0)
3358eb3f
RH
7991
7992static bool trans_RAX1(DisasContext *s, arg_rrr_esz *a)
7993{
7994 if (!dc_isar_feature(aa64_sve2_sha3, s)) {
7995 return false;
7996 }
7997 if (sve_access_check(s)) {
7998 gen_gvec_fn_zzz(s, gen_gvec_rax1, MO_64, a->rd, a->rn, a->rm);
7999 }
8000 return true;
8001}
5c1b7226
RH
8002
8003static bool trans_FCVTNT_sh(DisasContext *s, arg_rpr_esz *a)
8004{
8005 if (!dc_isar_feature(aa64_sve2, s)) {
8006 return false;
8007 }
8008 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve2_fcvtnt_sh);
8009}
8010
d29b17ca
RH
8011static bool trans_BFCVTNT(DisasContext *s, arg_rpr_esz *a)
8012{
8013 if (!dc_isar_feature(aa64_sve_bf16, s)) {
8014 return false;
8015 }
8016 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve_bfcvtnt);
8017}
8018
5c1b7226
RH
8019static bool trans_FCVTNT_ds(DisasContext *s, arg_rpr_esz *a)
8020{
8021 if (!dc_isar_feature(aa64_sve2, s)) {
8022 return false;
8023 }
8024 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve2_fcvtnt_ds);
8025}
83c2523f
SL
8026
8027static bool trans_FCVTLT_hs(DisasContext *s, arg_rpr_esz *a)
8028{
8029 if (!dc_isar_feature(aa64_sve2, s)) {
8030 return false;
8031 }
8032 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve2_fcvtlt_hs);
8033}
8034
8035static bool trans_FCVTLT_sd(DisasContext *s, arg_rpr_esz *a)
8036{
8037 if (!dc_isar_feature(aa64_sve2, s)) {
8038 return false;
8039 }
8040 return do_zpz_ptr(s, a->rd, a->rn, a->pg, false, gen_helper_sve2_fcvtlt_sd);
8041}
95365277
SL
8042
8043static bool trans_FCVTX_ds(DisasContext *s, arg_rpr_esz *a)
8044{
8045 if (!dc_isar_feature(aa64_sve2, s)) {
8046 return false;
8047 }
8048 return do_frint_mode(s, a, float_round_to_odd, gen_helper_sve_fcvt_ds);
8049}
8050
8051static bool trans_FCVTXNT_ds(DisasContext *s, arg_rpr_esz *a)
8052{
8053 if (!dc_isar_feature(aa64_sve2, s)) {
8054 return false;
8055 }
8056 return do_frint_mode(s, a, float_round_to_odd, gen_helper_sve2_fcvtnt_ds);
8057}
631be02e
SL
8058
8059static bool trans_FLOGB(DisasContext *s, arg_rpr_esz *a)
8060{
8061 static gen_helper_gvec_3_ptr * const fns[] = {
8062 NULL, gen_helper_flogb_h,
8063 gen_helper_flogb_s, gen_helper_flogb_d
8064 };
8065
8066 if (!dc_isar_feature(aa64_sve2, s) || fns[a->esz] == NULL) {
8067 return false;
8068 }
8069 if (sve_access_check(s)) {
8070 TCGv_ptr status =
8071 fpstatus_ptr(a->esz == MO_16 ? FPST_FPCR_F16 : FPST_FPCR);
8072 unsigned vsz = vec_full_reg_size(s);
8073
8074 tcg_gen_gvec_3_ptr(vec_full_reg_offset(s, a->rd),
8075 vec_full_reg_offset(s, a->rn),
8076 pred_full_reg_offset(s, a->pg),
8077 status, vsz, vsz, 0, fns[a->esz]);
8078 tcg_temp_free_ptr(status);
8079 }
8080 return true;
8081}
50d102bd
SL
8082
8083static bool do_FMLAL_zzzw(DisasContext *s, arg_rrrr_esz *a, bool sub, bool sel)
8084{
8085 if (!dc_isar_feature(aa64_sve2, s)) {
8086 return false;
8087 }
8088 if (sve_access_check(s)) {
8089 unsigned vsz = vec_full_reg_size(s);
8090 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
8091 vec_full_reg_offset(s, a->rn),
8092 vec_full_reg_offset(s, a->rm),
8093 vec_full_reg_offset(s, a->ra),
8094 cpu_env, vsz, vsz, (sel << 1) | sub,
8095 gen_helper_sve2_fmlal_zzzw_s);
8096 }
8097 return true;
8098}
8099
8100static bool trans_FMLALB_zzzw(DisasContext *s, arg_rrrr_esz *a)
8101{
8102 return do_FMLAL_zzzw(s, a, false, false);
8103}
8104
8105static bool trans_FMLALT_zzzw(DisasContext *s, arg_rrrr_esz *a)
8106{
8107 return do_FMLAL_zzzw(s, a, false, true);
8108}
8109
8110static bool trans_FMLSLB_zzzw(DisasContext *s, arg_rrrr_esz *a)
8111{
8112 return do_FMLAL_zzzw(s, a, true, false);
8113}
8114
8115static bool trans_FMLSLT_zzzw(DisasContext *s, arg_rrrr_esz *a)
8116{
8117 return do_FMLAL_zzzw(s, a, true, true);
8118}
8119
8120static bool do_FMLAL_zzxw(DisasContext *s, arg_rrxr_esz *a, bool sub, bool sel)
8121{
8122 if (!dc_isar_feature(aa64_sve2, s)) {
8123 return false;
8124 }
8125 if (sve_access_check(s)) {
8126 unsigned vsz = vec_full_reg_size(s);
8127 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
8128 vec_full_reg_offset(s, a->rn),
8129 vec_full_reg_offset(s, a->rm),
8130 vec_full_reg_offset(s, a->ra),
8131 cpu_env, vsz, vsz,
8132 (a->index << 2) | (sel << 1) | sub,
8133 gen_helper_sve2_fmlal_zzxw_s);
8134 }
8135 return true;
8136}
8137
8138static bool trans_FMLALB_zzxw(DisasContext *s, arg_rrxr_esz *a)
8139{
8140 return do_FMLAL_zzxw(s, a, false, false);
8141}
8142
8143static bool trans_FMLALT_zzxw(DisasContext *s, arg_rrxr_esz *a)
8144{
8145 return do_FMLAL_zzxw(s, a, false, true);
8146}
8147
8148static bool trans_FMLSLB_zzxw(DisasContext *s, arg_rrxr_esz *a)
8149{
8150 return do_FMLAL_zzxw(s, a, true, false);
8151}
8152
8153static bool trans_FMLSLT_zzxw(DisasContext *s, arg_rrxr_esz *a)
8154{
8155 return do_FMLAL_zzxw(s, a, true, true);
8156}
2323c5ff 8157
eec05e4e
RH
8158TRANS_FEAT(SMMLA, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz,
8159 gen_helper_gvec_smmla_b, a, 0)
8160TRANS_FEAT(USMMLA, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz,
8161 gen_helper_gvec_usmmla_b, a, 0)
8162TRANS_FEAT(UMMLA, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz,
8163 gen_helper_gvec_ummla_b, a, 0)
cb8657f7 8164
eec05e4e
RH
8165TRANS_FEAT(BFDOT_zzzz, aa64_sve_bf16, gen_gvec_ool_arg_zzzz,
8166 gen_helper_gvec_bfdot, a, 0)
f3500a25
RH
8167TRANS_FEAT(BFDOT_zzxz, aa64_sve_bf16, gen_gvec_ool_arg_zzxz,
8168 gen_helper_gvec_bfdot_idx, a)
81266a1f 8169
eec05e4e
RH
8170TRANS_FEAT(BFMMLA, aa64_sve_bf16, gen_gvec_ool_arg_zzzz,
8171 gen_helper_gvec_bfmmla, a, 0)
5693887f
RH
8172
8173static bool do_BFMLAL_zzzw(DisasContext *s, arg_rrrr_esz *a, bool sel)
8174{
8175 if (!dc_isar_feature(aa64_sve_bf16, s)) {
8176 return false;
8177 }
8178 if (sve_access_check(s)) {
8179 TCGv_ptr status = fpstatus_ptr(FPST_FPCR);
8180 unsigned vsz = vec_full_reg_size(s);
8181
8182 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
8183 vec_full_reg_offset(s, a->rn),
8184 vec_full_reg_offset(s, a->rm),
8185 vec_full_reg_offset(s, a->ra),
8186 status, vsz, vsz, sel,
8187 gen_helper_gvec_bfmlal);
8188 tcg_temp_free_ptr(status);
8189 }
8190 return true;
8191}
8192
8193static bool trans_BFMLALB_zzzw(DisasContext *s, arg_rrrr_esz *a)
8194{
8195 return do_BFMLAL_zzzw(s, a, false);
8196}
8197
8198static bool trans_BFMLALT_zzzw(DisasContext *s, arg_rrrr_esz *a)
8199{
8200 return do_BFMLAL_zzzw(s, a, true);
8201}
458d0ab6
RH
8202
8203static bool do_BFMLAL_zzxw(DisasContext *s, arg_rrxr_esz *a, bool sel)
8204{
8205 if (!dc_isar_feature(aa64_sve_bf16, s)) {
8206 return false;
8207 }
8208 if (sve_access_check(s)) {
8209 TCGv_ptr status = fpstatus_ptr(FPST_FPCR);
8210 unsigned vsz = vec_full_reg_size(s);
8211
8212 tcg_gen_gvec_4_ptr(vec_full_reg_offset(s, a->rd),
8213 vec_full_reg_offset(s, a->rn),
8214 vec_full_reg_offset(s, a->rm),
8215 vec_full_reg_offset(s, a->ra),
8216 status, vsz, vsz, (a->index << 1) | sel,
8217 gen_helper_gvec_bfmlal_idx);
8218 tcg_temp_free_ptr(status);
8219 }
8220 return true;
8221}
8222
8223static bool trans_BFMLALB_zzxw(DisasContext *s, arg_rrxr_esz *a)
8224{
8225 return do_BFMLAL_zzxw(s, a, false);
8226}
8227
8228static bool trans_BFMLALT_zzxw(DisasContext *s, arg_rrxr_esz *a)
8229{
8230 return do_BFMLAL_zzxw(s, a, true);
8231}