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