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