]> git.proxmox.com Git - mirror_qemu.git/blame - target/arm/translate-sve.c
target/arm: Implement SVE Integer Multiply-Add Group
[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
9 * version 2 of the License, or (at your option) any later version.
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"
23#include "tcg-op.h"
24#include "tcg-op-gvec.h"
028e2a7b 25#include "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"
35
ccd841c3
RH
36/*
37 * Helpers for extracting complex instruction fields.
38 */
39
40/* See e.g. ASR (immediate, predicated).
41 * Returns -1 for unallocated encoding; diagnose later.
42 */
43static int tszimm_esz(int x)
44{
45 x >>= 3; /* discard imm3 */
46 return 31 - clz32(x);
47}
48
49static int tszimm_shr(int x)
50{
51 return (16 << tszimm_esz(x)) - x;
52}
53
54/* See e.g. LSL (immediate, predicated). */
55static int tszimm_shl(int x)
56{
57 return x - (8 << tszimm_esz(x));
58}
59
38388f7e
RH
60/*
61 * Include the generated decoder.
62 */
63
64#include "decode-sve.inc.c"
65
66/*
67 * Implement all of the translator functions referenced by the decoder.
68 */
69
d1822297
RH
70/* Return the offset info CPUARMState of the predicate vector register Pn.
71 * Note for this purpose, FFR is P16.
72 */
73static inline int pred_full_reg_offset(DisasContext *s, int regno)
74{
75 return offsetof(CPUARMState, vfp.pregs[regno]);
76}
77
78/* Return the byte size of the whole predicate register, VL / 64. */
79static inline int pred_full_reg_size(DisasContext *s)
80{
81 return s->sve_len >> 3;
82}
83
516e246a
RH
84/* Round up the size of a register to a size allowed by
85 * the tcg vector infrastructure. Any operation which uses this
86 * size may assume that the bits above pred_full_reg_size are zero,
87 * and must leave them the same way.
88 *
89 * Note that this is not needed for the vector registers as they
90 * are always properly sized for tcg vectors.
91 */
92static int size_for_gvec(int size)
93{
94 if (size <= 8) {
95 return 8;
96 } else {
97 return QEMU_ALIGN_UP(size, 16);
98 }
99}
100
101static int pred_gvec_reg_size(DisasContext *s)
102{
103 return size_for_gvec(pred_full_reg_size(s));
104}
105
39eea561
RH
106/* Invoke a vector expander on two Zregs. */
107static bool do_vector2_z(DisasContext *s, GVecGen2Fn *gvec_fn,
108 int esz, int rd, int rn)
38388f7e 109{
39eea561
RH
110 if (sve_access_check(s)) {
111 unsigned vsz = vec_full_reg_size(s);
112 gvec_fn(esz, vec_full_reg_offset(s, rd),
113 vec_full_reg_offset(s, rn), vsz, vsz);
114 }
115 return true;
38388f7e
RH
116}
117
39eea561
RH
118/* Invoke a vector expander on three Zregs. */
119static bool do_vector3_z(DisasContext *s, GVecGen3Fn *gvec_fn,
120 int esz, int rd, int rn, int rm)
38388f7e 121{
39eea561
RH
122 if (sve_access_check(s)) {
123 unsigned vsz = vec_full_reg_size(s);
124 gvec_fn(esz, vec_full_reg_offset(s, rd),
125 vec_full_reg_offset(s, rn),
126 vec_full_reg_offset(s, rm), vsz, vsz);
127 }
128 return true;
38388f7e
RH
129}
130
39eea561
RH
131/* Invoke a vector move on two Zregs. */
132static bool do_mov_z(DisasContext *s, int rd, int rn)
38388f7e 133{
39eea561 134 return do_vector2_z(s, tcg_gen_gvec_mov, 0, rd, rn);
38388f7e
RH
135}
136
516e246a
RH
137/* Invoke a vector expander on two Pregs. */
138static bool do_vector2_p(DisasContext *s, GVecGen2Fn *gvec_fn,
139 int esz, int rd, int rn)
140{
141 if (sve_access_check(s)) {
142 unsigned psz = pred_gvec_reg_size(s);
143 gvec_fn(esz, pred_full_reg_offset(s, rd),
144 pred_full_reg_offset(s, rn), psz, psz);
145 }
146 return true;
147}
148
149/* Invoke a vector expander on three Pregs. */
150static bool do_vector3_p(DisasContext *s, GVecGen3Fn *gvec_fn,
151 int esz, int rd, int rn, int rm)
152{
153 if (sve_access_check(s)) {
154 unsigned psz = pred_gvec_reg_size(s);
155 gvec_fn(esz, pred_full_reg_offset(s, rd),
156 pred_full_reg_offset(s, rn),
157 pred_full_reg_offset(s, rm), psz, psz);
158 }
159 return true;
160}
161
162/* Invoke a vector operation on four Pregs. */
163static bool do_vecop4_p(DisasContext *s, const GVecGen4 *gvec_op,
164 int rd, int rn, int rm, int rg)
165{
166 if (sve_access_check(s)) {
167 unsigned psz = pred_gvec_reg_size(s);
168 tcg_gen_gvec_4(pred_full_reg_offset(s, rd),
169 pred_full_reg_offset(s, rn),
170 pred_full_reg_offset(s, rm),
171 pred_full_reg_offset(s, rg),
172 psz, psz, gvec_op);
173 }
174 return true;
175}
176
177/* Invoke a vector move on two Pregs. */
178static bool do_mov_p(DisasContext *s, int rd, int rn)
179{
180 return do_vector2_p(s, tcg_gen_gvec_mov, 0, rd, rn);
181}
182
9e18d7a6
RH
183/* Set the cpu flags as per a return from an SVE helper. */
184static void do_pred_flags(TCGv_i32 t)
185{
186 tcg_gen_mov_i32(cpu_NF, t);
187 tcg_gen_andi_i32(cpu_ZF, t, 2);
188 tcg_gen_andi_i32(cpu_CF, t, 1);
189 tcg_gen_movi_i32(cpu_VF, 0);
190}
191
192/* Subroutines computing the ARM PredTest psuedofunction. */
193static void do_predtest1(TCGv_i64 d, TCGv_i64 g)
194{
195 TCGv_i32 t = tcg_temp_new_i32();
196
197 gen_helper_sve_predtest1(t, d, g);
198 do_pred_flags(t);
199 tcg_temp_free_i32(t);
200}
201
202static void do_predtest(DisasContext *s, int dofs, int gofs, int words)
203{
204 TCGv_ptr dptr = tcg_temp_new_ptr();
205 TCGv_ptr gptr = tcg_temp_new_ptr();
206 TCGv_i32 t;
207
208 tcg_gen_addi_ptr(dptr, cpu_env, dofs);
209 tcg_gen_addi_ptr(gptr, cpu_env, gofs);
210 t = tcg_const_i32(words);
211
212 gen_helper_sve_predtest(t, dptr, gptr, t);
213 tcg_temp_free_ptr(dptr);
214 tcg_temp_free_ptr(gptr);
215
216 do_pred_flags(t);
217 tcg_temp_free_i32(t);
218}
219
028e2a7b
RH
220/* For each element size, the bits within a predicate word that are active. */
221const uint64_t pred_esz_masks[4] = {
222 0xffffffffffffffffull, 0x5555555555555555ull,
223 0x1111111111111111ull, 0x0101010101010101ull
224};
225
39eea561
RH
226/*
227 *** SVE Logical - Unpredicated Group
228 */
229
230static bool trans_AND_zzz(DisasContext *s, arg_rrr_esz *a, uint32_t insn)
231{
232 return do_vector3_z(s, tcg_gen_gvec_and, 0, a->rd, a->rn, a->rm);
233}
234
235static bool trans_ORR_zzz(DisasContext *s, arg_rrr_esz *a, uint32_t insn)
236{
237 if (a->rn == a->rm) { /* MOV */
238 return do_mov_z(s, a->rd, a->rn);
239 } else {
240 return do_vector3_z(s, tcg_gen_gvec_or, 0, a->rd, a->rn, a->rm);
241 }
242}
243
244static bool trans_EOR_zzz(DisasContext *s, arg_rrr_esz *a, uint32_t insn)
245{
246 return do_vector3_z(s, tcg_gen_gvec_xor, 0, a->rd, a->rn, a->rm);
247}
248
249static bool trans_BIC_zzz(DisasContext *s, arg_rrr_esz *a, uint32_t insn)
38388f7e 250{
39eea561 251 return do_vector3_z(s, tcg_gen_gvec_andc, 0, a->rd, a->rn, a->rm);
38388f7e 252}
d1822297 253
f97cfd59
RH
254/*
255 *** SVE Integer Arithmetic - Binary Predicated Group
256 */
257
258static bool do_zpzz_ool(DisasContext *s, arg_rprr_esz *a, gen_helper_gvec_4 *fn)
259{
260 unsigned vsz = vec_full_reg_size(s);
261 if (fn == NULL) {
262 return false;
263 }
264 if (sve_access_check(s)) {
265 tcg_gen_gvec_4_ool(vec_full_reg_offset(s, a->rd),
266 vec_full_reg_offset(s, a->rn),
267 vec_full_reg_offset(s, a->rm),
268 pred_full_reg_offset(s, a->pg),
269 vsz, vsz, 0, fn);
270 }
271 return true;
272}
273
274#define DO_ZPZZ(NAME, name) \
275static bool trans_##NAME##_zpzz(DisasContext *s, arg_rprr_esz *a, \
276 uint32_t insn) \
277{ \
278 static gen_helper_gvec_4 * const fns[4] = { \
279 gen_helper_sve_##name##_zpzz_b, gen_helper_sve_##name##_zpzz_h, \
280 gen_helper_sve_##name##_zpzz_s, gen_helper_sve_##name##_zpzz_d, \
281 }; \
282 return do_zpzz_ool(s, a, fns[a->esz]); \
283}
284
285DO_ZPZZ(AND, and)
286DO_ZPZZ(EOR, eor)
287DO_ZPZZ(ORR, orr)
288DO_ZPZZ(BIC, bic)
289
290DO_ZPZZ(ADD, add)
291DO_ZPZZ(SUB, sub)
292
293DO_ZPZZ(SMAX, smax)
294DO_ZPZZ(UMAX, umax)
295DO_ZPZZ(SMIN, smin)
296DO_ZPZZ(UMIN, umin)
297DO_ZPZZ(SABD, sabd)
298DO_ZPZZ(UABD, uabd)
299
300DO_ZPZZ(MUL, mul)
301DO_ZPZZ(SMULH, smulh)
302DO_ZPZZ(UMULH, umulh)
303
27721dbb
RH
304DO_ZPZZ(ASR, asr)
305DO_ZPZZ(LSR, lsr)
306DO_ZPZZ(LSL, lsl)
307
f97cfd59
RH
308static bool trans_SDIV_zpzz(DisasContext *s, arg_rprr_esz *a, uint32_t insn)
309{
310 static gen_helper_gvec_4 * const fns[4] = {
311 NULL, NULL, gen_helper_sve_sdiv_zpzz_s, gen_helper_sve_sdiv_zpzz_d
312 };
313 return do_zpzz_ool(s, a, fns[a->esz]);
314}
315
316static bool trans_UDIV_zpzz(DisasContext *s, arg_rprr_esz *a, uint32_t insn)
317{
318 static gen_helper_gvec_4 * const fns[4] = {
319 NULL, NULL, gen_helper_sve_udiv_zpzz_s, gen_helper_sve_udiv_zpzz_d
320 };
321 return do_zpzz_ool(s, a, fns[a->esz]);
322}
323
324#undef DO_ZPZZ
325
afac6d04
RH
326/*
327 *** SVE Integer Arithmetic - Unary Predicated Group
328 */
329
330static bool do_zpz_ool(DisasContext *s, arg_rpr_esz *a, gen_helper_gvec_3 *fn)
331{
332 if (fn == NULL) {
333 return false;
334 }
335 if (sve_access_check(s)) {
336 unsigned vsz = vec_full_reg_size(s);
337 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, a->rd),
338 vec_full_reg_offset(s, a->rn),
339 pred_full_reg_offset(s, a->pg),
340 vsz, vsz, 0, fn);
341 }
342 return true;
343}
344
345#define DO_ZPZ(NAME, name) \
346static bool trans_##NAME(DisasContext *s, arg_rpr_esz *a, uint32_t insn) \
347{ \
348 static gen_helper_gvec_3 * const fns[4] = { \
349 gen_helper_sve_##name##_b, gen_helper_sve_##name##_h, \
350 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d, \
351 }; \
352 return do_zpz_ool(s, a, fns[a->esz]); \
353}
354
355DO_ZPZ(CLS, cls)
356DO_ZPZ(CLZ, clz)
357DO_ZPZ(CNT_zpz, cnt_zpz)
358DO_ZPZ(CNOT, cnot)
359DO_ZPZ(NOT_zpz, not_zpz)
360DO_ZPZ(ABS, abs)
361DO_ZPZ(NEG, neg)
362
363static bool trans_FABS(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
364{
365 static gen_helper_gvec_3 * const fns[4] = {
366 NULL,
367 gen_helper_sve_fabs_h,
368 gen_helper_sve_fabs_s,
369 gen_helper_sve_fabs_d
370 };
371 return do_zpz_ool(s, a, fns[a->esz]);
372}
373
374static bool trans_FNEG(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
375{
376 static gen_helper_gvec_3 * const fns[4] = {
377 NULL,
378 gen_helper_sve_fneg_h,
379 gen_helper_sve_fneg_s,
380 gen_helper_sve_fneg_d
381 };
382 return do_zpz_ool(s, a, fns[a->esz]);
383}
384
385static bool trans_SXTB(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
386{
387 static gen_helper_gvec_3 * const fns[4] = {
388 NULL,
389 gen_helper_sve_sxtb_h,
390 gen_helper_sve_sxtb_s,
391 gen_helper_sve_sxtb_d
392 };
393 return do_zpz_ool(s, a, fns[a->esz]);
394}
395
396static bool trans_UXTB(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
397{
398 static gen_helper_gvec_3 * const fns[4] = {
399 NULL,
400 gen_helper_sve_uxtb_h,
401 gen_helper_sve_uxtb_s,
402 gen_helper_sve_uxtb_d
403 };
404 return do_zpz_ool(s, a, fns[a->esz]);
405}
406
407static bool trans_SXTH(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
408{
409 static gen_helper_gvec_3 * const fns[4] = {
410 NULL, NULL,
411 gen_helper_sve_sxth_s,
412 gen_helper_sve_sxth_d
413 };
414 return do_zpz_ool(s, a, fns[a->esz]);
415}
416
417static bool trans_UXTH(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
418{
419 static gen_helper_gvec_3 * const fns[4] = {
420 NULL, NULL,
421 gen_helper_sve_uxth_s,
422 gen_helper_sve_uxth_d
423 };
424 return do_zpz_ool(s, a, fns[a->esz]);
425}
426
427static bool trans_SXTW(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
428{
429 return do_zpz_ool(s, a, a->esz == 3 ? gen_helper_sve_sxtw_d : NULL);
430}
431
432static bool trans_UXTW(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
433{
434 return do_zpz_ool(s, a, a->esz == 3 ? gen_helper_sve_uxtw_d : NULL);
435}
436
437#undef DO_ZPZ
438
047cec97
RH
439/*
440 *** SVE Integer Reduction Group
441 */
442
443typedef void gen_helper_gvec_reduc(TCGv_i64, TCGv_ptr, TCGv_ptr, TCGv_i32);
444static bool do_vpz_ool(DisasContext *s, arg_rpr_esz *a,
445 gen_helper_gvec_reduc *fn)
446{
447 unsigned vsz = vec_full_reg_size(s);
448 TCGv_ptr t_zn, t_pg;
449 TCGv_i32 desc;
450 TCGv_i64 temp;
451
452 if (fn == NULL) {
453 return false;
454 }
455 if (!sve_access_check(s)) {
456 return true;
457 }
458
459 desc = tcg_const_i32(simd_desc(vsz, vsz, 0));
460 temp = tcg_temp_new_i64();
461 t_zn = tcg_temp_new_ptr();
462 t_pg = tcg_temp_new_ptr();
463
464 tcg_gen_addi_ptr(t_zn, cpu_env, vec_full_reg_offset(s, a->rn));
465 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, a->pg));
466 fn(temp, t_zn, t_pg, desc);
467 tcg_temp_free_ptr(t_zn);
468 tcg_temp_free_ptr(t_pg);
469 tcg_temp_free_i32(desc);
470
471 write_fp_dreg(s, a->rd, temp);
472 tcg_temp_free_i64(temp);
473 return true;
474}
475
476#define DO_VPZ(NAME, name) \
477static bool trans_##NAME(DisasContext *s, arg_rpr_esz *a, uint32_t insn) \
478{ \
479 static gen_helper_gvec_reduc * const fns[4] = { \
480 gen_helper_sve_##name##_b, gen_helper_sve_##name##_h, \
481 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d, \
482 }; \
483 return do_vpz_ool(s, a, fns[a->esz]); \
484}
485
486DO_VPZ(ORV, orv)
487DO_VPZ(ANDV, andv)
488DO_VPZ(EORV, eorv)
489
490DO_VPZ(UADDV, uaddv)
491DO_VPZ(SMAXV, smaxv)
492DO_VPZ(UMAXV, umaxv)
493DO_VPZ(SMINV, sminv)
494DO_VPZ(UMINV, uminv)
495
496static bool trans_SADDV(DisasContext *s, arg_rpr_esz *a, uint32_t insn)
497{
498 static gen_helper_gvec_reduc * const fns[4] = {
499 gen_helper_sve_saddv_b, gen_helper_sve_saddv_h,
500 gen_helper_sve_saddv_s, NULL
501 };
502 return do_vpz_ool(s, a, fns[a->esz]);
503}
504
505#undef DO_VPZ
506
ccd841c3
RH
507/*
508 *** SVE Shift by Immediate - Predicated Group
509 */
510
511/* Store zero into every active element of Zd. We will use this for two
512 * and three-operand predicated instructions for which logic dictates a
513 * zero result.
514 */
515static bool do_clr_zp(DisasContext *s, int rd, int pg, int esz)
516{
517 static gen_helper_gvec_2 * const fns[4] = {
518 gen_helper_sve_clr_b, gen_helper_sve_clr_h,
519 gen_helper_sve_clr_s, gen_helper_sve_clr_d,
520 };
521 if (sve_access_check(s)) {
522 unsigned vsz = vec_full_reg_size(s);
523 tcg_gen_gvec_2_ool(vec_full_reg_offset(s, rd),
524 pred_full_reg_offset(s, pg),
525 vsz, vsz, 0, fns[esz]);
526 }
527 return true;
528}
529
530static bool do_zpzi_ool(DisasContext *s, arg_rpri_esz *a,
531 gen_helper_gvec_3 *fn)
532{
533 if (sve_access_check(s)) {
534 unsigned vsz = vec_full_reg_size(s);
535 tcg_gen_gvec_3_ool(vec_full_reg_offset(s, a->rd),
536 vec_full_reg_offset(s, a->rn),
537 pred_full_reg_offset(s, a->pg),
538 vsz, vsz, a->imm, fn);
539 }
540 return true;
541}
542
543static bool trans_ASR_zpzi(DisasContext *s, arg_rpri_esz *a, uint32_t insn)
544{
545 static gen_helper_gvec_3 * const fns[4] = {
546 gen_helper_sve_asr_zpzi_b, gen_helper_sve_asr_zpzi_h,
547 gen_helper_sve_asr_zpzi_s, gen_helper_sve_asr_zpzi_d,
548 };
549 if (a->esz < 0) {
550 /* Invalid tsz encoding -- see tszimm_esz. */
551 return false;
552 }
553 /* Shift by element size is architecturally valid. For
554 arithmetic right-shift, it's the same as by one less. */
555 a->imm = MIN(a->imm, (8 << a->esz) - 1);
556 return do_zpzi_ool(s, a, fns[a->esz]);
557}
558
559static bool trans_LSR_zpzi(DisasContext *s, arg_rpri_esz *a, uint32_t insn)
560{
561 static gen_helper_gvec_3 * const fns[4] = {
562 gen_helper_sve_lsr_zpzi_b, gen_helper_sve_lsr_zpzi_h,
563 gen_helper_sve_lsr_zpzi_s, gen_helper_sve_lsr_zpzi_d,
564 };
565 if (a->esz < 0) {
566 return false;
567 }
568 /* Shift by element size is architecturally valid.
569 For logical shifts, it is a zeroing operation. */
570 if (a->imm >= (8 << a->esz)) {
571 return do_clr_zp(s, a->rd, a->pg, a->esz);
572 } else {
573 return do_zpzi_ool(s, a, fns[a->esz]);
574 }
575}
576
577static bool trans_LSL_zpzi(DisasContext *s, arg_rpri_esz *a, uint32_t insn)
578{
579 static gen_helper_gvec_3 * const fns[4] = {
580 gen_helper_sve_lsl_zpzi_b, gen_helper_sve_lsl_zpzi_h,
581 gen_helper_sve_lsl_zpzi_s, gen_helper_sve_lsl_zpzi_d,
582 };
583 if (a->esz < 0) {
584 return false;
585 }
586 /* Shift by element size is architecturally valid.
587 For logical shifts, it is a zeroing operation. */
588 if (a->imm >= (8 << a->esz)) {
589 return do_clr_zp(s, a->rd, a->pg, a->esz);
590 } else {
591 return do_zpzi_ool(s, a, fns[a->esz]);
592 }
593}
594
595static bool trans_ASRD(DisasContext *s, arg_rpri_esz *a, uint32_t insn)
596{
597 static gen_helper_gvec_3 * const fns[4] = {
598 gen_helper_sve_asrd_b, gen_helper_sve_asrd_h,
599 gen_helper_sve_asrd_s, gen_helper_sve_asrd_d,
600 };
601 if (a->esz < 0) {
602 return false;
603 }
604 /* Shift by element size is architecturally valid. For arithmetic
605 right shift for division, it is a zeroing operation. */
606 if (a->imm >= (8 << a->esz)) {
607 return do_clr_zp(s, a->rd, a->pg, a->esz);
608 } else {
609 return do_zpzi_ool(s, a, fns[a->esz]);
610 }
611}
612
fe7f8dfb
RH
613/*
614 *** SVE Bitwise Shift - Predicated Group
615 */
616
617#define DO_ZPZW(NAME, name) \
618static bool trans_##NAME##_zpzw(DisasContext *s, arg_rprr_esz *a, \
619 uint32_t insn) \
620{ \
621 static gen_helper_gvec_4 * const fns[3] = { \
622 gen_helper_sve_##name##_zpzw_b, gen_helper_sve_##name##_zpzw_h, \
623 gen_helper_sve_##name##_zpzw_s, \
624 }; \
625 if (a->esz < 0 || a->esz >= 3) { \
626 return false; \
627 } \
628 return do_zpzz_ool(s, a, fns[a->esz]); \
629}
630
631DO_ZPZW(ASR, asr)
632DO_ZPZW(LSR, lsr)
633DO_ZPZW(LSL, lsl)
634
635#undef DO_ZPZW
636
96a36e4a
RH
637/*
638 *** SVE Integer Multiply-Add Group
639 */
640
641static bool do_zpzzz_ool(DisasContext *s, arg_rprrr_esz *a,
642 gen_helper_gvec_5 *fn)
643{
644 if (sve_access_check(s)) {
645 unsigned vsz = vec_full_reg_size(s);
646 tcg_gen_gvec_5_ool(vec_full_reg_offset(s, a->rd),
647 vec_full_reg_offset(s, a->ra),
648 vec_full_reg_offset(s, a->rn),
649 vec_full_reg_offset(s, a->rm),
650 pred_full_reg_offset(s, a->pg),
651 vsz, vsz, 0, fn);
652 }
653 return true;
654}
655
656#define DO_ZPZZZ(NAME, name) \
657static bool trans_##NAME(DisasContext *s, arg_rprrr_esz *a, uint32_t insn) \
658{ \
659 static gen_helper_gvec_5 * const fns[4] = { \
660 gen_helper_sve_##name##_b, gen_helper_sve_##name##_h, \
661 gen_helper_sve_##name##_s, gen_helper_sve_##name##_d, \
662 }; \
663 return do_zpzzz_ool(s, a, fns[a->esz]); \
664}
665
666DO_ZPZZZ(MLA, mla)
667DO_ZPZZZ(MLS, mls)
668
669#undef DO_ZPZZZ
670
516e246a
RH
671/*
672 *** SVE Predicate Logical Operations Group
673 */
674
675static bool do_pppp_flags(DisasContext *s, arg_rprr_s *a,
676 const GVecGen4 *gvec_op)
677{
678 if (!sve_access_check(s)) {
679 return true;
680 }
681
682 unsigned psz = pred_gvec_reg_size(s);
683 int dofs = pred_full_reg_offset(s, a->rd);
684 int nofs = pred_full_reg_offset(s, a->rn);
685 int mofs = pred_full_reg_offset(s, a->rm);
686 int gofs = pred_full_reg_offset(s, a->pg);
687
688 if (psz == 8) {
689 /* Do the operation and the flags generation in temps. */
690 TCGv_i64 pd = tcg_temp_new_i64();
691 TCGv_i64 pn = tcg_temp_new_i64();
692 TCGv_i64 pm = tcg_temp_new_i64();
693 TCGv_i64 pg = tcg_temp_new_i64();
694
695 tcg_gen_ld_i64(pn, cpu_env, nofs);
696 tcg_gen_ld_i64(pm, cpu_env, mofs);
697 tcg_gen_ld_i64(pg, cpu_env, gofs);
698
699 gvec_op->fni8(pd, pn, pm, pg);
700 tcg_gen_st_i64(pd, cpu_env, dofs);
701
702 do_predtest1(pd, pg);
703
704 tcg_temp_free_i64(pd);
705 tcg_temp_free_i64(pn);
706 tcg_temp_free_i64(pm);
707 tcg_temp_free_i64(pg);
708 } else {
709 /* The operation and flags generation is large. The computation
710 * of the flags depends on the original contents of the guarding
711 * predicate. If the destination overwrites the guarding predicate,
712 * then the easiest way to get this right is to save a copy.
713 */
714 int tofs = gofs;
715 if (a->rd == a->pg) {
716 tofs = offsetof(CPUARMState, vfp.preg_tmp);
717 tcg_gen_gvec_mov(0, tofs, gofs, psz, psz);
718 }
719
720 tcg_gen_gvec_4(dofs, nofs, mofs, gofs, psz, psz, gvec_op);
721 do_predtest(s, dofs, tofs, psz / 8);
722 }
723 return true;
724}
725
726static void gen_and_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
727{
728 tcg_gen_and_i64(pd, pn, pm);
729 tcg_gen_and_i64(pd, pd, pg);
730}
731
732static void gen_and_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
733 TCGv_vec pm, TCGv_vec pg)
734{
735 tcg_gen_and_vec(vece, pd, pn, pm);
736 tcg_gen_and_vec(vece, pd, pd, pg);
737}
738
739static bool trans_AND_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
740{
741 static const GVecGen4 op = {
742 .fni8 = gen_and_pg_i64,
743 .fniv = gen_and_pg_vec,
744 .fno = gen_helper_sve_and_pppp,
745 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
746 };
747 if (a->s) {
748 return do_pppp_flags(s, a, &op);
749 } else if (a->rn == a->rm) {
750 if (a->pg == a->rn) {
751 return do_mov_p(s, a->rd, a->rn);
752 } else {
753 return do_vector3_p(s, tcg_gen_gvec_and, 0, a->rd, a->rn, a->pg);
754 }
755 } else if (a->pg == a->rn || a->pg == a->rm) {
756 return do_vector3_p(s, tcg_gen_gvec_and, 0, a->rd, a->rn, a->rm);
757 } else {
758 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
759 }
760}
761
762static void gen_bic_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
763{
764 tcg_gen_andc_i64(pd, pn, pm);
765 tcg_gen_and_i64(pd, pd, pg);
766}
767
768static void gen_bic_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
769 TCGv_vec pm, TCGv_vec pg)
770{
771 tcg_gen_andc_vec(vece, pd, pn, pm);
772 tcg_gen_and_vec(vece, pd, pd, pg);
773}
774
775static bool trans_BIC_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
776{
777 static const GVecGen4 op = {
778 .fni8 = gen_bic_pg_i64,
779 .fniv = gen_bic_pg_vec,
780 .fno = gen_helper_sve_bic_pppp,
781 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
782 };
783 if (a->s) {
784 return do_pppp_flags(s, a, &op);
785 } else if (a->pg == a->rn) {
786 return do_vector3_p(s, tcg_gen_gvec_andc, 0, a->rd, a->rn, a->rm);
787 } else {
788 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
789 }
790}
791
792static void gen_eor_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
793{
794 tcg_gen_xor_i64(pd, pn, pm);
795 tcg_gen_and_i64(pd, pd, pg);
796}
797
798static void gen_eor_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
799 TCGv_vec pm, TCGv_vec pg)
800{
801 tcg_gen_xor_vec(vece, pd, pn, pm);
802 tcg_gen_and_vec(vece, pd, pd, pg);
803}
804
805static bool trans_EOR_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
806{
807 static const GVecGen4 op = {
808 .fni8 = gen_eor_pg_i64,
809 .fniv = gen_eor_pg_vec,
810 .fno = gen_helper_sve_eor_pppp,
811 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
812 };
813 if (a->s) {
814 return do_pppp_flags(s, a, &op);
815 } else {
816 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
817 }
818}
819
820static void gen_sel_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
821{
822 tcg_gen_and_i64(pn, pn, pg);
823 tcg_gen_andc_i64(pm, pm, pg);
824 tcg_gen_or_i64(pd, pn, pm);
825}
826
827static void gen_sel_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
828 TCGv_vec pm, TCGv_vec pg)
829{
830 tcg_gen_and_vec(vece, pn, pn, pg);
831 tcg_gen_andc_vec(vece, pm, pm, pg);
832 tcg_gen_or_vec(vece, pd, pn, pm);
833}
834
835static bool trans_SEL_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
836{
837 static const GVecGen4 op = {
838 .fni8 = gen_sel_pg_i64,
839 .fniv = gen_sel_pg_vec,
840 .fno = gen_helper_sve_sel_pppp,
841 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
842 };
843 if (a->s) {
844 return false;
845 } else {
846 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
847 }
848}
849
850static void gen_orr_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
851{
852 tcg_gen_or_i64(pd, pn, pm);
853 tcg_gen_and_i64(pd, pd, pg);
854}
855
856static void gen_orr_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
857 TCGv_vec pm, TCGv_vec pg)
858{
859 tcg_gen_or_vec(vece, pd, pn, pm);
860 tcg_gen_and_vec(vece, pd, pd, pg);
861}
862
863static bool trans_ORR_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
864{
865 static const GVecGen4 op = {
866 .fni8 = gen_orr_pg_i64,
867 .fniv = gen_orr_pg_vec,
868 .fno = gen_helper_sve_orr_pppp,
869 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
870 };
871 if (a->s) {
872 return do_pppp_flags(s, a, &op);
873 } else if (a->pg == a->rn && a->rn == a->rm) {
874 return do_mov_p(s, a->rd, a->rn);
875 } else {
876 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
877 }
878}
879
880static void gen_orn_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
881{
882 tcg_gen_orc_i64(pd, pn, pm);
883 tcg_gen_and_i64(pd, pd, pg);
884}
885
886static void gen_orn_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
887 TCGv_vec pm, TCGv_vec pg)
888{
889 tcg_gen_orc_vec(vece, pd, pn, pm);
890 tcg_gen_and_vec(vece, pd, pd, pg);
891}
892
893static bool trans_ORN_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
894{
895 static const GVecGen4 op = {
896 .fni8 = gen_orn_pg_i64,
897 .fniv = gen_orn_pg_vec,
898 .fno = gen_helper_sve_orn_pppp,
899 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
900 };
901 if (a->s) {
902 return do_pppp_flags(s, a, &op);
903 } else {
904 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
905 }
906}
907
908static void gen_nor_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
909{
910 tcg_gen_or_i64(pd, pn, pm);
911 tcg_gen_andc_i64(pd, pg, pd);
912}
913
914static void gen_nor_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
915 TCGv_vec pm, TCGv_vec pg)
916{
917 tcg_gen_or_vec(vece, pd, pn, pm);
918 tcg_gen_andc_vec(vece, pd, pg, pd);
919}
920
921static bool trans_NOR_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
922{
923 static const GVecGen4 op = {
924 .fni8 = gen_nor_pg_i64,
925 .fniv = gen_nor_pg_vec,
926 .fno = gen_helper_sve_nor_pppp,
927 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
928 };
929 if (a->s) {
930 return do_pppp_flags(s, a, &op);
931 } else {
932 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
933 }
934}
935
936static void gen_nand_pg_i64(TCGv_i64 pd, TCGv_i64 pn, TCGv_i64 pm, TCGv_i64 pg)
937{
938 tcg_gen_and_i64(pd, pn, pm);
939 tcg_gen_andc_i64(pd, pg, pd);
940}
941
942static void gen_nand_pg_vec(unsigned vece, TCGv_vec pd, TCGv_vec pn,
943 TCGv_vec pm, TCGv_vec pg)
944{
945 tcg_gen_and_vec(vece, pd, pn, pm);
946 tcg_gen_andc_vec(vece, pd, pg, pd);
947}
948
949static bool trans_NAND_pppp(DisasContext *s, arg_rprr_s *a, uint32_t insn)
950{
951 static const GVecGen4 op = {
952 .fni8 = gen_nand_pg_i64,
953 .fniv = gen_nand_pg_vec,
954 .fno = gen_helper_sve_nand_pppp,
955 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
956 };
957 if (a->s) {
958 return do_pppp_flags(s, a, &op);
959 } else {
960 return do_vecop4_p(s, &op, a->rd, a->rn, a->rm, a->pg);
961 }
962}
963
9e18d7a6
RH
964/*
965 *** SVE Predicate Misc Group
966 */
967
968static bool trans_PTEST(DisasContext *s, arg_PTEST *a, uint32_t insn)
969{
970 if (sve_access_check(s)) {
971 int nofs = pred_full_reg_offset(s, a->rn);
972 int gofs = pred_full_reg_offset(s, a->pg);
973 int words = DIV_ROUND_UP(pred_full_reg_size(s), 8);
974
975 if (words == 1) {
976 TCGv_i64 pn = tcg_temp_new_i64();
977 TCGv_i64 pg = tcg_temp_new_i64();
978
979 tcg_gen_ld_i64(pn, cpu_env, nofs);
980 tcg_gen_ld_i64(pg, cpu_env, gofs);
981 do_predtest1(pn, pg);
982
983 tcg_temp_free_i64(pn);
984 tcg_temp_free_i64(pg);
985 } else {
986 do_predtest(s, nofs, gofs, words);
987 }
988 }
989 return true;
990}
991
028e2a7b
RH
992/* See the ARM pseudocode DecodePredCount. */
993static unsigned decode_pred_count(unsigned fullsz, int pattern, int esz)
994{
995 unsigned elements = fullsz >> esz;
996 unsigned bound;
997
998 switch (pattern) {
999 case 0x0: /* POW2 */
1000 return pow2floor(elements);
1001 case 0x1: /* VL1 */
1002 case 0x2: /* VL2 */
1003 case 0x3: /* VL3 */
1004 case 0x4: /* VL4 */
1005 case 0x5: /* VL5 */
1006 case 0x6: /* VL6 */
1007 case 0x7: /* VL7 */
1008 case 0x8: /* VL8 */
1009 bound = pattern;
1010 break;
1011 case 0x9: /* VL16 */
1012 case 0xa: /* VL32 */
1013 case 0xb: /* VL64 */
1014 case 0xc: /* VL128 */
1015 case 0xd: /* VL256 */
1016 bound = 16 << (pattern - 9);
1017 break;
1018 case 0x1d: /* MUL4 */
1019 return elements - elements % 4;
1020 case 0x1e: /* MUL3 */
1021 return elements - elements % 3;
1022 case 0x1f: /* ALL */
1023 return elements;
1024 default: /* #uimm5 */
1025 return 0;
1026 }
1027 return elements >= bound ? bound : 0;
1028}
1029
1030/* This handles all of the predicate initialization instructions,
1031 * PTRUE, PFALSE, SETFFR. For PFALSE, we will have set PAT == 32
1032 * so that decode_pred_count returns 0. For SETFFR, we will have
1033 * set RD == 16 == FFR.
1034 */
1035static bool do_predset(DisasContext *s, int esz, int rd, int pat, bool setflag)
1036{
1037 if (!sve_access_check(s)) {
1038 return true;
1039 }
1040
1041 unsigned fullsz = vec_full_reg_size(s);
1042 unsigned ofs = pred_full_reg_offset(s, rd);
1043 unsigned numelem, setsz, i;
1044 uint64_t word, lastword;
1045 TCGv_i64 t;
1046
1047 numelem = decode_pred_count(fullsz, pat, esz);
1048
1049 /* Determine what we must store into each bit, and how many. */
1050 if (numelem == 0) {
1051 lastword = word = 0;
1052 setsz = fullsz;
1053 } else {
1054 setsz = numelem << esz;
1055 lastword = word = pred_esz_masks[esz];
1056 if (setsz % 64) {
1057 lastword &= ~(-1ull << (setsz % 64));
1058 }
1059 }
1060
1061 t = tcg_temp_new_i64();
1062 if (fullsz <= 64) {
1063 tcg_gen_movi_i64(t, lastword);
1064 tcg_gen_st_i64(t, cpu_env, ofs);
1065 goto done;
1066 }
1067
1068 if (word == lastword) {
1069 unsigned maxsz = size_for_gvec(fullsz / 8);
1070 unsigned oprsz = size_for_gvec(setsz / 8);
1071
1072 if (oprsz * 8 == setsz) {
1073 tcg_gen_gvec_dup64i(ofs, oprsz, maxsz, word);
1074 goto done;
1075 }
1076 if (oprsz * 8 == setsz + 8) {
1077 tcg_gen_gvec_dup64i(ofs, oprsz, maxsz, word);
1078 tcg_gen_movi_i64(t, 0);
1079 tcg_gen_st_i64(t, cpu_env, ofs + oprsz - 8);
1080 goto done;
1081 }
1082 }
1083
1084 setsz /= 8;
1085 fullsz /= 8;
1086
1087 tcg_gen_movi_i64(t, word);
1088 for (i = 0; i < setsz; i += 8) {
1089 tcg_gen_st_i64(t, cpu_env, ofs + i);
1090 }
1091 if (lastword != word) {
1092 tcg_gen_movi_i64(t, lastword);
1093 tcg_gen_st_i64(t, cpu_env, ofs + i);
1094 i += 8;
1095 }
1096 if (i < fullsz) {
1097 tcg_gen_movi_i64(t, 0);
1098 for (; i < fullsz; i += 8) {
1099 tcg_gen_st_i64(t, cpu_env, ofs + i);
1100 }
1101 }
1102
1103 done:
1104 tcg_temp_free_i64(t);
1105
1106 /* PTRUES */
1107 if (setflag) {
1108 tcg_gen_movi_i32(cpu_NF, -(word != 0));
1109 tcg_gen_movi_i32(cpu_CF, word == 0);
1110 tcg_gen_movi_i32(cpu_VF, 0);
1111 tcg_gen_mov_i32(cpu_ZF, cpu_NF);
1112 }
1113 return true;
1114}
1115
1116static bool trans_PTRUE(DisasContext *s, arg_PTRUE *a, uint32_t insn)
1117{
1118 return do_predset(s, a->esz, a->rd, a->pat, a->s);
1119}
1120
1121static bool trans_SETFFR(DisasContext *s, arg_SETFFR *a, uint32_t insn)
1122{
1123 /* Note pat == 31 is #all, to set all elements. */
1124 return do_predset(s, 0, FFR_PRED_NUM, 31, false);
1125}
1126
1127static bool trans_PFALSE(DisasContext *s, arg_PFALSE *a, uint32_t insn)
1128{
1129 /* Note pat == 32 is #unimp, to set no elements. */
1130 return do_predset(s, 0, a->rd, 32, false);
1131}
1132
1133static bool trans_RDFFR_p(DisasContext *s, arg_RDFFR_p *a, uint32_t insn)
1134{
1135 /* The path through do_pppp_flags is complicated enough to want to avoid
1136 * duplication. Frob the arguments into the form of a predicated AND.
1137 */
1138 arg_rprr_s alt_a = {
1139 .rd = a->rd, .pg = a->pg, .s = a->s,
1140 .rn = FFR_PRED_NUM, .rm = FFR_PRED_NUM,
1141 };
1142 return trans_AND_pppp(s, &alt_a, insn);
1143}
1144
1145static bool trans_RDFFR(DisasContext *s, arg_RDFFR *a, uint32_t insn)
1146{
1147 return do_mov_p(s, a->rd, FFR_PRED_NUM);
1148}
1149
1150static bool trans_WRFFR(DisasContext *s, arg_WRFFR *a, uint32_t insn)
1151{
1152 return do_mov_p(s, FFR_PRED_NUM, a->rn);
1153}
1154
1155static bool do_pfirst_pnext(DisasContext *s, arg_rr_esz *a,
1156 void (*gen_fn)(TCGv_i32, TCGv_ptr,
1157 TCGv_ptr, TCGv_i32))
1158{
1159 if (!sve_access_check(s)) {
1160 return true;
1161 }
1162
1163 TCGv_ptr t_pd = tcg_temp_new_ptr();
1164 TCGv_ptr t_pg = tcg_temp_new_ptr();
1165 TCGv_i32 t;
1166 unsigned desc;
1167
1168 desc = DIV_ROUND_UP(pred_full_reg_size(s), 8);
1169 desc = deposit32(desc, SIMD_DATA_SHIFT, 2, a->esz);
1170
1171 tcg_gen_addi_ptr(t_pd, cpu_env, pred_full_reg_offset(s, a->rd));
1172 tcg_gen_addi_ptr(t_pg, cpu_env, pred_full_reg_offset(s, a->rn));
1173 t = tcg_const_i32(desc);
1174
1175 gen_fn(t, t_pd, t_pg, t);
1176 tcg_temp_free_ptr(t_pd);
1177 tcg_temp_free_ptr(t_pg);
1178
1179 do_pred_flags(t);
1180 tcg_temp_free_i32(t);
1181 return true;
1182}
1183
1184static bool trans_PFIRST(DisasContext *s, arg_rr_esz *a, uint32_t insn)
1185{
1186 return do_pfirst_pnext(s, a, gen_helper_sve_pfirst);
1187}
1188
1189static bool trans_PNEXT(DisasContext *s, arg_rr_esz *a, uint32_t insn)
1190{
1191 return do_pfirst_pnext(s, a, gen_helper_sve_pnext);
1192}
1193
d1822297
RH
1194/*
1195 *** SVE Memory - 32-bit Gather and Unsized Contiguous Group
1196 */
1197
1198/* Subroutine loading a vector register at VOFS of LEN bytes.
1199 * The load should begin at the address Rn + IMM.
1200 */
1201
1202static void do_ldr(DisasContext *s, uint32_t vofs, uint32_t len,
1203 int rn, int imm)
1204{
1205 uint32_t len_align = QEMU_ALIGN_DOWN(len, 8);
1206 uint32_t len_remain = len % 8;
1207 uint32_t nparts = len / 8 + ctpop8(len_remain);
1208 int midx = get_mem_index(s);
1209 TCGv_i64 addr, t0, t1;
1210
1211 addr = tcg_temp_new_i64();
1212 t0 = tcg_temp_new_i64();
1213
1214 /* Note that unpredicated load/store of vector/predicate registers
1215 * are defined as a stream of bytes, which equates to little-endian
1216 * operations on larger quantities. There is no nice way to force
1217 * a little-endian load for aarch64_be-linux-user out of line.
1218 *
1219 * Attempt to keep code expansion to a minimum by limiting the
1220 * amount of unrolling done.
1221 */
1222 if (nparts <= 4) {
1223 int i;
1224
1225 for (i = 0; i < len_align; i += 8) {
1226 tcg_gen_addi_i64(addr, cpu_reg_sp(s, rn), imm + i);
1227 tcg_gen_qemu_ld_i64(t0, addr, midx, MO_LEQ);
1228 tcg_gen_st_i64(t0, cpu_env, vofs + i);
1229 }
1230 } else {
1231 TCGLabel *loop = gen_new_label();
1232 TCGv_ptr tp, i = tcg_const_local_ptr(0);
1233
1234 gen_set_label(loop);
1235
1236 /* Minimize the number of local temps that must be re-read from
1237 * the stack each iteration. Instead, re-compute values other
1238 * than the loop counter.
1239 */
1240 tp = tcg_temp_new_ptr();
1241 tcg_gen_addi_ptr(tp, i, imm);
1242 tcg_gen_extu_ptr_i64(addr, tp);
1243 tcg_gen_add_i64(addr, addr, cpu_reg_sp(s, rn));
1244
1245 tcg_gen_qemu_ld_i64(t0, addr, midx, MO_LEQ);
1246
1247 tcg_gen_add_ptr(tp, cpu_env, i);
1248 tcg_gen_addi_ptr(i, i, 8);
1249 tcg_gen_st_i64(t0, tp, vofs);
1250 tcg_temp_free_ptr(tp);
1251
1252 tcg_gen_brcondi_ptr(TCG_COND_LTU, i, len_align, loop);
1253 tcg_temp_free_ptr(i);
1254 }
1255
1256 /* Predicate register loads can be any multiple of 2.
1257 * Note that we still store the entire 64-bit unit into cpu_env.
1258 */
1259 if (len_remain) {
1260 tcg_gen_addi_i64(addr, cpu_reg_sp(s, rn), imm + len_align);
1261
1262 switch (len_remain) {
1263 case 2:
1264 case 4:
1265 case 8:
1266 tcg_gen_qemu_ld_i64(t0, addr, midx, MO_LE | ctz32(len_remain));
1267 break;
1268
1269 case 6:
1270 t1 = tcg_temp_new_i64();
1271 tcg_gen_qemu_ld_i64(t0, addr, midx, MO_LEUL);
1272 tcg_gen_addi_i64(addr, addr, 4);
1273 tcg_gen_qemu_ld_i64(t1, addr, midx, MO_LEUW);
1274 tcg_gen_deposit_i64(t0, t0, t1, 32, 32);
1275 tcg_temp_free_i64(t1);
1276 break;
1277
1278 default:
1279 g_assert_not_reached();
1280 }
1281 tcg_gen_st_i64(t0, cpu_env, vofs + len_align);
1282 }
1283 tcg_temp_free_i64(addr);
1284 tcg_temp_free_i64(t0);
1285}
1286
1287static bool trans_LDR_zri(DisasContext *s, arg_rri *a, uint32_t insn)
1288{
1289 if (sve_access_check(s)) {
1290 int size = vec_full_reg_size(s);
1291 int off = vec_full_reg_offset(s, a->rd);
1292 do_ldr(s, off, size, a->rn, a->imm * size);
1293 }
1294 return true;
1295}
1296
1297static bool trans_LDR_pri(DisasContext *s, arg_rri *a, uint32_t insn)
1298{
1299 if (sve_access_check(s)) {
1300 int size = pred_full_reg_size(s);
1301 int off = pred_full_reg_offset(s, a->rd);
1302 do_ldr(s, off, size, a->rn, a->imm * size);
1303 }
1304 return true;
1305}