Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / target / arm / tcg / translate-vfp.c
blobb6fa28a7bf61be4ab5330b273a353a5640fee04d
1 /*
2 * ARM translation: AArch32 VFP instructions
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2005-2007 CodeSourcery
6 * Copyright (c) 2007 OpenedHand, Ltd.
7 * Copyright (c) 2019 Linaro, Ltd.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 #include "qemu/osdep.h"
24 #include "translate.h"
25 #include "translate-a32.h"
27 /* Include the generated VFP decoder */
28 #include "decode-vfp.c.inc"
29 #include "decode-vfp-uncond.c.inc"
31 static inline void vfp_load_reg64(TCGv_i64 var, int reg)
33 tcg_gen_ld_i64(var, tcg_env, vfp_reg_offset(true, reg));
36 static inline void vfp_store_reg64(TCGv_i64 var, int reg)
38 tcg_gen_st_i64(var, tcg_env, vfp_reg_offset(true, reg));
41 static inline void vfp_load_reg32(TCGv_i32 var, int reg)
43 tcg_gen_ld_i32(var, tcg_env, vfp_reg_offset(false, reg));
46 static inline void vfp_store_reg32(TCGv_i32 var, int reg)
48 tcg_gen_st_i32(var, tcg_env, vfp_reg_offset(false, reg));
51 static inline void vfp_load_reg16(TCGv_i32 var, int reg)
53 tcg_gen_ld16u_i32(var, tcg_env,
54 vfp_reg_offset(false, reg) + HOST_BIG_ENDIAN * 2);
58 * The imm8 encodes the sign bit, enough bits to represent an exponent in
59 * the range 01....1xx to 10....0xx, and the most significant 4 bits of
60 * the mantissa; see VFPExpandImm() in the v8 ARM ARM.
62 uint64_t vfp_expand_imm(int size, uint8_t imm8)
64 uint64_t imm;
66 switch (size) {
67 case MO_64:
68 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
69 (extract32(imm8, 6, 1) ? 0x3fc0 : 0x4000) |
70 extract32(imm8, 0, 6);
71 imm <<= 48;
72 break;
73 case MO_32:
74 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
75 (extract32(imm8, 6, 1) ? 0x3e00 : 0x4000) |
76 (extract32(imm8, 0, 6) << 3);
77 imm <<= 16;
78 break;
79 case MO_16:
80 imm = (extract32(imm8, 7, 1) ? 0x8000 : 0) |
81 (extract32(imm8, 6, 1) ? 0x3000 : 0x4000) |
82 (extract32(imm8, 0, 6) << 6);
83 break;
84 default:
85 g_assert_not_reached();
87 return imm;
91 * Return the offset of a 16-bit half of the specified VFP single-precision
92 * register. If top is true, returns the top 16 bits; otherwise the bottom
93 * 16 bits.
95 static inline long vfp_f16_offset(unsigned reg, bool top)
97 long offs = vfp_reg_offset(false, reg);
98 #if HOST_BIG_ENDIAN
99 if (!top) {
100 offs += 2;
102 #else
103 if (top) {
104 offs += 2;
106 #endif
107 return offs;
111 * Generate code for M-profile lazy FP state preservation if needed;
112 * this corresponds to the pseudocode PreserveFPState() function.
114 static void gen_preserve_fp_state(DisasContext *s, bool skip_context_update)
116 if (s->v7m_lspact) {
118 * Lazy state saving affects external memory and also the NVIC,
119 * so we must mark it as an IO operation for icount (and cause
120 * this to be the last insn in the TB).
122 if (translator_io_start(&s->base)) {
123 s->base.is_jmp = DISAS_UPDATE_EXIT;
125 gen_helper_v7m_preserve_fp_state(tcg_env);
127 * If the preserve_fp_state helper doesn't throw an exception
128 * then it will clear LSPACT; we don't need to repeat this for
129 * any further FP insns in this TB.
131 s->v7m_lspact = false;
133 * The helper might have zeroed VPR, so we do not know the
134 * correct value for the MVE_NO_PRED TB flag any more.
135 * If we're about to create a new fp context then that
136 * will precisely determine the MVE_NO_PRED value (see
137 * gen_update_fp_context()). Otherwise, we must:
138 * - set s->mve_no_pred to false, so this instruction
139 * is generated to use helper functions
140 * - end the TB now, without chaining to the next TB
142 if (skip_context_update || !s->v7m_new_fp_ctxt_needed) {
143 s->mve_no_pred = false;
144 s->base.is_jmp = DISAS_UPDATE_NOCHAIN;
150 * Generate code for M-profile FP context handling: update the
151 * ownership of the FP context, and create a new context if
152 * necessary. This corresponds to the parts of the pseudocode
153 * ExecuteFPCheck() after the initial PreserveFPState() call.
155 static void gen_update_fp_context(DisasContext *s)
157 /* Update ownership of FP context: set FPCCR.S to match current state */
158 if (s->v8m_fpccr_s_wrong) {
159 TCGv_i32 tmp;
161 tmp = load_cpu_field(v7m.fpccr[M_REG_S]);
162 if (s->v8m_secure) {
163 tcg_gen_ori_i32(tmp, tmp, R_V7M_FPCCR_S_MASK);
164 } else {
165 tcg_gen_andi_i32(tmp, tmp, ~R_V7M_FPCCR_S_MASK);
167 store_cpu_field(tmp, v7m.fpccr[M_REG_S]);
168 /* Don't need to do this for any further FP insns in this TB */
169 s->v8m_fpccr_s_wrong = false;
172 if (s->v7m_new_fp_ctxt_needed) {
174 * Create new FP context by updating CONTROL.FPCA, CONTROL.SFPA,
175 * the FPSCR, and VPR.
177 TCGv_i32 control, fpscr;
178 uint32_t bits = R_V7M_CONTROL_FPCA_MASK;
180 fpscr = load_cpu_field(v7m.fpdscr[s->v8m_secure]);
181 gen_helper_vfp_set_fpscr(tcg_env, fpscr);
182 if (dc_isar_feature(aa32_mve, s)) {
183 store_cpu_field(tcg_constant_i32(0), v7m.vpr);
186 * We just updated the FPSCR and VPR. Some of this state is cached
187 * in the MVE_NO_PRED TB flag. We want to avoid having to end the
188 * TB here, which means we need the new value of the MVE_NO_PRED
189 * flag to be exactly known here and the same for all executions.
190 * Luckily FPDSCR.LTPSIZE is always constant 4 and the VPR is
191 * always set to 0, so the new MVE_NO_PRED flag is always 1
192 * if and only if we have MVE.
194 * (The other FPSCR state cached in TB flags is VECLEN and VECSTRIDE,
195 * but those do not exist for M-profile, so are not relevant here.)
197 s->mve_no_pred = dc_isar_feature(aa32_mve, s);
199 if (s->v8m_secure) {
200 bits |= R_V7M_CONTROL_SFPA_MASK;
202 control = load_cpu_field(v7m.control[M_REG_S]);
203 tcg_gen_ori_i32(control, control, bits);
204 store_cpu_field(control, v7m.control[M_REG_S]);
205 /* Don't need to do this for any further FP insns in this TB */
206 s->v7m_new_fp_ctxt_needed = false;
211 * Check that VFP access is enabled, A-profile specific version.
213 * If VFP is enabled, return true. If not, emit code to generate an
214 * appropriate exception and return false.
215 * The ignore_vfp_enabled argument specifies that we should ignore
216 * whether VFP is enabled via FPEXC.EN: this should be true for FMXR/FMRX
217 * accesses to FPSID, FPEXC, MVFR0, MVFR1, MVFR2, and false for all other insns.
219 static bool vfp_access_check_a(DisasContext *s, bool ignore_vfp_enabled)
221 if (s->fp_excp_el) {
223 * The full syndrome is only used for HSR when HCPTR traps:
224 * For v8, when TA==0, coproc is RES0.
225 * For v7, any use of a Floating-point instruction or access
226 * to a Floating-point Extension register that is trapped to
227 * Hyp mode because of a trap configured in the HCPTR sets
228 * this field to 0xA.
230 int coproc = arm_dc_feature(s, ARM_FEATURE_V8) ? 0 : 0xa;
231 uint32_t syn = syn_fp_access_trap(1, 0xe, false, coproc);
233 gen_exception_insn_el(s, 0, EXCP_UDEF, syn, s->fp_excp_el);
234 return false;
238 * Note that rebuild_hflags_a32 has already accounted for being in EL0
239 * and the higher EL in A64 mode, etc. Unlike A64 mode, there do not
240 * appear to be any insns which touch VFP which are allowed.
242 if (s->sme_trap_nonstreaming) {
243 gen_exception_insn(s, 0, EXCP_UDEF,
244 syn_smetrap(SME_ET_Streaming,
245 curr_insn_len(s) == 2));
246 return false;
249 if (!s->vfp_enabled && !ignore_vfp_enabled) {
250 assert(!arm_dc_feature(s, ARM_FEATURE_M));
251 unallocated_encoding(s);
252 return false;
254 return true;
258 * Check that VFP access is enabled, M-profile specific version.
260 * If VFP is enabled, do the necessary M-profile lazy-FP handling and then
261 * return true. If not, emit code to generate an appropriate exception and
262 * return false.
263 * skip_context_update is true to skip the "update FP context" part of this.
265 bool vfp_access_check_m(DisasContext *s, bool skip_context_update)
267 if (s->fp_excp_el) {
269 * M-profile mostly catches the "FPU disabled" case early, in
270 * disas_m_nocp(), but a few insns (eg LCTP, WLSTP, DLSTP)
271 * which do coprocessor-checks are outside the large ranges of
272 * the encoding space handled by the patterns in m-nocp.decode,
273 * and for them we may need to raise NOCP here.
275 gen_exception_insn_el(s, 0, EXCP_NOCP,
276 syn_uncategorized(), s->fp_excp_el);
277 return false;
280 /* Handle M-profile lazy FP state mechanics */
282 /* Trigger lazy-state preservation if necessary */
283 gen_preserve_fp_state(s, skip_context_update);
285 if (!skip_context_update) {
286 /* Update ownership of FP context and create new FP context if needed */
287 gen_update_fp_context(s);
290 return true;
294 * The most usual kind of VFP access check, for everything except
295 * FMXR/FMRX to the always-available special registers.
297 bool vfp_access_check(DisasContext *s)
299 if (arm_dc_feature(s, ARM_FEATURE_M)) {
300 return vfp_access_check_m(s, false);
301 } else {
302 return vfp_access_check_a(s, false);
306 static bool trans_VSEL(DisasContext *s, arg_VSEL *a)
308 uint32_t rd, rn, rm;
309 int sz = a->sz;
311 if (!dc_isar_feature(aa32_vsel, s)) {
312 return false;
315 if (sz == 3 && !dc_isar_feature(aa32_fpdp_v2, s)) {
316 return false;
319 if (sz == 1 && !dc_isar_feature(aa32_fp16_arith, s)) {
320 return false;
323 /* UNDEF accesses to D16-D31 if they don't exist */
324 if (sz == 3 && !dc_isar_feature(aa32_simd_r32, s) &&
325 ((a->vm | a->vn | a->vd) & 0x10)) {
326 return false;
329 rd = a->vd;
330 rn = a->vn;
331 rm = a->vm;
333 if (!vfp_access_check(s)) {
334 return true;
337 if (sz == 3) {
338 TCGv_i64 frn, frm, dest;
339 TCGv_i64 tmp, zero, zf, nf, vf;
341 zero = tcg_constant_i64(0);
343 frn = tcg_temp_new_i64();
344 frm = tcg_temp_new_i64();
345 dest = tcg_temp_new_i64();
347 zf = tcg_temp_new_i64();
348 nf = tcg_temp_new_i64();
349 vf = tcg_temp_new_i64();
351 tcg_gen_extu_i32_i64(zf, cpu_ZF);
352 tcg_gen_ext_i32_i64(nf, cpu_NF);
353 tcg_gen_ext_i32_i64(vf, cpu_VF);
355 vfp_load_reg64(frn, rn);
356 vfp_load_reg64(frm, rm);
357 switch (a->cc) {
358 case 0: /* eq: Z */
359 tcg_gen_movcond_i64(TCG_COND_EQ, dest, zf, zero, frn, frm);
360 break;
361 case 1: /* vs: V */
362 tcg_gen_movcond_i64(TCG_COND_LT, dest, vf, zero, frn, frm);
363 break;
364 case 2: /* ge: N == V -> N ^ V == 0 */
365 tmp = tcg_temp_new_i64();
366 tcg_gen_xor_i64(tmp, vf, nf);
367 tcg_gen_movcond_i64(TCG_COND_GE, dest, tmp, zero, frn, frm);
368 break;
369 case 3: /* gt: !Z && N == V */
370 tcg_gen_movcond_i64(TCG_COND_NE, dest, zf, zero, frn, frm);
371 tmp = tcg_temp_new_i64();
372 tcg_gen_xor_i64(tmp, vf, nf);
373 tcg_gen_movcond_i64(TCG_COND_GE, dest, tmp, zero, dest, frm);
374 break;
376 vfp_store_reg64(dest, rd);
377 } else {
378 TCGv_i32 frn, frm, dest;
379 TCGv_i32 tmp, zero;
381 zero = tcg_constant_i32(0);
383 frn = tcg_temp_new_i32();
384 frm = tcg_temp_new_i32();
385 dest = tcg_temp_new_i32();
386 vfp_load_reg32(frn, rn);
387 vfp_load_reg32(frm, rm);
388 switch (a->cc) {
389 case 0: /* eq: Z */
390 tcg_gen_movcond_i32(TCG_COND_EQ, dest, cpu_ZF, zero, frn, frm);
391 break;
392 case 1: /* vs: V */
393 tcg_gen_movcond_i32(TCG_COND_LT, dest, cpu_VF, zero, frn, frm);
394 break;
395 case 2: /* ge: N == V -> N ^ V == 0 */
396 tmp = tcg_temp_new_i32();
397 tcg_gen_xor_i32(tmp, cpu_VF, cpu_NF);
398 tcg_gen_movcond_i32(TCG_COND_GE, dest, tmp, zero, frn, frm);
399 break;
400 case 3: /* gt: !Z && N == V */
401 tcg_gen_movcond_i32(TCG_COND_NE, dest, cpu_ZF, zero, frn, frm);
402 tmp = tcg_temp_new_i32();
403 tcg_gen_xor_i32(tmp, cpu_VF, cpu_NF);
404 tcg_gen_movcond_i32(TCG_COND_GE, dest, tmp, zero, dest, frm);
405 break;
407 /* For fp16 the top half is always zeroes */
408 if (sz == 1) {
409 tcg_gen_andi_i32(dest, dest, 0xffff);
411 vfp_store_reg32(dest, rd);
414 return true;
418 * Table for converting the most common AArch32 encoding of
419 * rounding mode to arm_fprounding order (which matches the
420 * common AArch64 order); see ARM ARM pseudocode FPDecodeRM().
422 static const uint8_t fp_decode_rm[] = {
423 FPROUNDING_TIEAWAY,
424 FPROUNDING_TIEEVEN,
425 FPROUNDING_POSINF,
426 FPROUNDING_NEGINF,
429 static bool trans_VRINT(DisasContext *s, arg_VRINT *a)
431 uint32_t rd, rm;
432 int sz = a->sz;
433 TCGv_ptr fpst;
434 TCGv_i32 tcg_rmode;
435 int rounding = fp_decode_rm[a->rm];
437 if (!dc_isar_feature(aa32_vrint, s)) {
438 return false;
441 if (sz == 3 && !dc_isar_feature(aa32_fpdp_v2, s)) {
442 return false;
445 if (sz == 1 && !dc_isar_feature(aa32_fp16_arith, s)) {
446 return false;
449 /* UNDEF accesses to D16-D31 if they don't exist */
450 if (sz == 3 && !dc_isar_feature(aa32_simd_r32, s) &&
451 ((a->vm | a->vd) & 0x10)) {
452 return false;
455 rd = a->vd;
456 rm = a->vm;
458 if (!vfp_access_check(s)) {
459 return true;
462 if (sz == 1) {
463 fpst = fpstatus_ptr(FPST_FPCR_F16);
464 } else {
465 fpst = fpstatus_ptr(FPST_FPCR);
468 tcg_rmode = gen_set_rmode(rounding, fpst);
470 if (sz == 3) {
471 TCGv_i64 tcg_op;
472 TCGv_i64 tcg_res;
473 tcg_op = tcg_temp_new_i64();
474 tcg_res = tcg_temp_new_i64();
475 vfp_load_reg64(tcg_op, rm);
476 gen_helper_rintd(tcg_res, tcg_op, fpst);
477 vfp_store_reg64(tcg_res, rd);
478 } else {
479 TCGv_i32 tcg_op;
480 TCGv_i32 tcg_res;
481 tcg_op = tcg_temp_new_i32();
482 tcg_res = tcg_temp_new_i32();
483 vfp_load_reg32(tcg_op, rm);
484 if (sz == 1) {
485 gen_helper_rinth(tcg_res, tcg_op, fpst);
486 } else {
487 gen_helper_rints(tcg_res, tcg_op, fpst);
489 vfp_store_reg32(tcg_res, rd);
492 gen_restore_rmode(tcg_rmode, fpst);
493 return true;
496 static bool trans_VCVT(DisasContext *s, arg_VCVT *a)
498 uint32_t rd, rm;
499 int sz = a->sz;
500 TCGv_ptr fpst;
501 TCGv_i32 tcg_rmode, tcg_shift;
502 int rounding = fp_decode_rm[a->rm];
503 bool is_signed = a->op;
505 if (!dc_isar_feature(aa32_vcvt_dr, s)) {
506 return false;
509 if (sz == 3 && !dc_isar_feature(aa32_fpdp_v2, s)) {
510 return false;
513 if (sz == 1 && !dc_isar_feature(aa32_fp16_arith, s)) {
514 return false;
517 /* UNDEF accesses to D16-D31 if they don't exist */
518 if (sz == 3 && !dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) {
519 return false;
522 rd = a->vd;
523 rm = a->vm;
525 if (!vfp_access_check(s)) {
526 return true;
529 if (sz == 1) {
530 fpst = fpstatus_ptr(FPST_FPCR_F16);
531 } else {
532 fpst = fpstatus_ptr(FPST_FPCR);
535 tcg_shift = tcg_constant_i32(0);
536 tcg_rmode = gen_set_rmode(rounding, fpst);
538 if (sz == 3) {
539 TCGv_i64 tcg_double, tcg_res;
540 TCGv_i32 tcg_tmp;
541 tcg_double = tcg_temp_new_i64();
542 tcg_res = tcg_temp_new_i64();
543 tcg_tmp = tcg_temp_new_i32();
544 vfp_load_reg64(tcg_double, rm);
545 if (is_signed) {
546 gen_helper_vfp_tosld(tcg_res, tcg_double, tcg_shift, fpst);
547 } else {
548 gen_helper_vfp_tould(tcg_res, tcg_double, tcg_shift, fpst);
550 tcg_gen_extrl_i64_i32(tcg_tmp, tcg_res);
551 vfp_store_reg32(tcg_tmp, rd);
552 } else {
553 TCGv_i32 tcg_single, tcg_res;
554 tcg_single = tcg_temp_new_i32();
555 tcg_res = tcg_temp_new_i32();
556 vfp_load_reg32(tcg_single, rm);
557 if (sz == 1) {
558 if (is_signed) {
559 gen_helper_vfp_toslh(tcg_res, tcg_single, tcg_shift, fpst);
560 } else {
561 gen_helper_vfp_toulh(tcg_res, tcg_single, tcg_shift, fpst);
563 } else {
564 if (is_signed) {
565 gen_helper_vfp_tosls(tcg_res, tcg_single, tcg_shift, fpst);
566 } else {
567 gen_helper_vfp_touls(tcg_res, tcg_single, tcg_shift, fpst);
570 vfp_store_reg32(tcg_res, rd);
573 gen_restore_rmode(tcg_rmode, fpst);
574 return true;
577 bool mve_skip_vmov(DisasContext *s, int vn, int index, int size)
580 * In a CPU with MVE, the VMOV (vector lane to general-purpose register)
581 * and VMOV (general-purpose register to vector lane) insns are not
582 * predicated, but they are subject to beatwise execution if they are
583 * not in an IT block.
585 * Since our implementation always executes all 4 beats in one tick,
586 * this means only that if PSR.ECI says we should not be executing
587 * the beat corresponding to the lane of the vector register being
588 * accessed then we should skip performing the move, and that we need
589 * to do the usual check for bad ECI state and advance of ECI state.
591 * Note that if PSR.ECI is non-zero then we cannot be in an IT block.
593 * Return true if this VMOV scalar <-> gpreg should be skipped because
594 * the MVE PSR.ECI state says we skip the beat where the store happens.
597 /* Calculate the byte offset into Qn which we're going to access */
598 int ofs = (index << size) + ((vn & 1) * 8);
600 if (!dc_isar_feature(aa32_mve, s)) {
601 return false;
604 switch (s->eci) {
605 case ECI_NONE:
606 return false;
607 case ECI_A0:
608 return ofs < 4;
609 case ECI_A0A1:
610 return ofs < 8;
611 case ECI_A0A1A2:
612 case ECI_A0A1A2B0:
613 return ofs < 12;
614 default:
615 g_assert_not_reached();
619 static bool trans_VMOV_to_gp(DisasContext *s, arg_VMOV_to_gp *a)
621 /* VMOV scalar to general purpose register */
622 TCGv_i32 tmp;
625 * SIZE == MO_32 is a VFP instruction; otherwise NEON. MVE has
626 * all sizes, whether the CPU has fp or not.
628 if (!dc_isar_feature(aa32_mve, s)) {
629 if (a->size == MO_32
630 ? !dc_isar_feature(aa32_fpsp_v2, s)
631 : !arm_dc_feature(s, ARM_FEATURE_NEON)) {
632 return false;
636 /* UNDEF accesses to D16-D31 if they don't exist */
637 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vn & 0x10)) {
638 return false;
641 if (dc_isar_feature(aa32_mve, s)) {
642 if (!mve_eci_check(s)) {
643 return true;
647 if (!vfp_access_check(s)) {
648 return true;
651 if (!mve_skip_vmov(s, a->vn, a->index, a->size)) {
652 tmp = tcg_temp_new_i32();
653 read_neon_element32(tmp, a->vn, a->index,
654 a->size | (a->u ? 0 : MO_SIGN));
655 store_reg(s, a->rt, tmp);
658 if (dc_isar_feature(aa32_mve, s)) {
659 mve_update_and_store_eci(s);
661 return true;
664 static bool trans_VMOV_from_gp(DisasContext *s, arg_VMOV_from_gp *a)
666 /* VMOV general purpose register to scalar */
667 TCGv_i32 tmp;
670 * SIZE == MO_32 is a VFP instruction; otherwise NEON. MVE has
671 * all sizes, whether the CPU has fp or not.
673 if (!dc_isar_feature(aa32_mve, s)) {
674 if (a->size == MO_32
675 ? !dc_isar_feature(aa32_fpsp_v2, s)
676 : !arm_dc_feature(s, ARM_FEATURE_NEON)) {
677 return false;
681 /* UNDEF accesses to D16-D31 if they don't exist */
682 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vn & 0x10)) {
683 return false;
686 if (dc_isar_feature(aa32_mve, s)) {
687 if (!mve_eci_check(s)) {
688 return true;
692 if (!vfp_access_check(s)) {
693 return true;
696 if (!mve_skip_vmov(s, a->vn, a->index, a->size)) {
697 tmp = load_reg(s, a->rt);
698 write_neon_element32(tmp, a->vn, a->index, a->size);
701 if (dc_isar_feature(aa32_mve, s)) {
702 mve_update_and_store_eci(s);
704 return true;
707 static bool trans_VDUP(DisasContext *s, arg_VDUP *a)
709 /* VDUP (general purpose register) */
710 TCGv_i32 tmp;
711 int size, vec_size;
713 if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
714 return false;
717 /* UNDEF accesses to D16-D31 if they don't exist */
718 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vn & 0x10)) {
719 return false;
722 if (a->b && a->e) {
723 return false;
726 if (a->q && (a->vn & 1)) {
727 return false;
730 vec_size = a->q ? 16 : 8;
731 if (a->b) {
732 size = 0;
733 } else if (a->e) {
734 size = 1;
735 } else {
736 size = 2;
739 if (!vfp_access_check(s)) {
740 return true;
743 tmp = load_reg(s, a->rt);
744 tcg_gen_gvec_dup_i32(size, neon_full_reg_offset(a->vn),
745 vec_size, vec_size, tmp);
746 return true;
749 static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a)
751 TCGv_i32 tmp;
752 bool ignore_vfp_enabled = false;
754 if (arm_dc_feature(s, ARM_FEATURE_M)) {
755 /* M profile version was already handled in m-nocp.decode */
756 return false;
759 if (!dc_isar_feature(aa32_fpsp_v2, s)) {
760 return false;
763 switch (a->reg) {
764 case ARM_VFP_FPSID:
766 * VFPv2 allows access to FPSID from userspace; VFPv3 restricts
767 * all ID registers to privileged access only.
769 if (IS_USER(s) && dc_isar_feature(aa32_fpsp_v3, s)) {
770 return false;
772 ignore_vfp_enabled = true;
773 break;
774 case ARM_VFP_MVFR0:
775 case ARM_VFP_MVFR1:
776 if (IS_USER(s) || !arm_dc_feature(s, ARM_FEATURE_MVFR)) {
777 return false;
779 ignore_vfp_enabled = true;
780 break;
781 case ARM_VFP_MVFR2:
782 if (IS_USER(s) || !arm_dc_feature(s, ARM_FEATURE_V8)) {
783 return false;
785 ignore_vfp_enabled = true;
786 break;
787 case ARM_VFP_FPSCR:
788 break;
789 case ARM_VFP_FPEXC:
790 if (IS_USER(s)) {
791 return false;
793 ignore_vfp_enabled = true;
794 break;
795 case ARM_VFP_FPINST:
796 case ARM_VFP_FPINST2:
797 /* Not present in VFPv3 */
798 if (IS_USER(s) || dc_isar_feature(aa32_fpsp_v3, s)) {
799 return false;
801 break;
802 default:
803 return false;
807 * Call vfp_access_check_a() directly, because we need to tell
808 * it to ignore FPEXC.EN for some register accesses.
810 if (!vfp_access_check_a(s, ignore_vfp_enabled)) {
811 return true;
814 if (a->l) {
815 /* VMRS, move VFP special register to gp register */
816 switch (a->reg) {
817 case ARM_VFP_MVFR0:
818 case ARM_VFP_MVFR1:
819 case ARM_VFP_MVFR2:
820 case ARM_VFP_FPSID:
821 if (s->current_el == 1) {
822 gen_set_condexec(s);
823 gen_update_pc(s, 0);
824 gen_helper_check_hcr_el2_trap(tcg_env,
825 tcg_constant_i32(a->rt),
826 tcg_constant_i32(a->reg));
828 /* fall through */
829 case ARM_VFP_FPEXC:
830 case ARM_VFP_FPINST:
831 case ARM_VFP_FPINST2:
832 tmp = load_cpu_field(vfp.xregs[a->reg]);
833 break;
834 case ARM_VFP_FPSCR:
835 if (a->rt == 15) {
836 tmp = load_cpu_field_low32(vfp.fpsr);
837 tcg_gen_andi_i32(tmp, tmp, FPSR_NZCV_MASK);
838 } else {
839 tmp = tcg_temp_new_i32();
840 gen_helper_vfp_get_fpscr(tmp, tcg_env);
842 break;
843 default:
844 g_assert_not_reached();
847 if (a->rt == 15) {
848 /* Set the 4 flag bits in the CPSR. */
849 gen_set_nzcv(tmp);
850 } else {
851 store_reg(s, a->rt, tmp);
853 } else {
854 /* VMSR, move gp register to VFP special register */
855 switch (a->reg) {
856 case ARM_VFP_FPSID:
857 case ARM_VFP_MVFR0:
858 case ARM_VFP_MVFR1:
859 case ARM_VFP_MVFR2:
860 /* Writes are ignored. */
861 break;
862 case ARM_VFP_FPSCR:
863 tmp = load_reg(s, a->rt);
864 gen_helper_vfp_set_fpscr(tcg_env, tmp);
865 gen_lookup_tb(s);
866 break;
867 case ARM_VFP_FPEXC:
869 * TODO: VFP subarchitecture support.
870 * For now, keep the EN bit only
872 tmp = load_reg(s, a->rt);
873 tcg_gen_andi_i32(tmp, tmp, 1 << 30);
874 store_cpu_field(tmp, vfp.xregs[a->reg]);
875 gen_lookup_tb(s);
876 break;
877 case ARM_VFP_FPINST:
878 case ARM_VFP_FPINST2:
879 tmp = load_reg(s, a->rt);
880 store_cpu_field(tmp, vfp.xregs[a->reg]);
881 break;
882 default:
883 g_assert_not_reached();
887 return true;
891 static bool trans_VMOV_half(DisasContext *s, arg_VMOV_single *a)
893 TCGv_i32 tmp;
895 if (!dc_isar_feature(aa32_fp16_arith, s)) {
896 return false;
899 if (a->rt == 15) {
900 /* UNPREDICTABLE; we choose to UNDEF */
901 return false;
904 if (!vfp_access_check(s)) {
905 return true;
908 if (a->l) {
909 /* VFP to general purpose register */
910 tmp = tcg_temp_new_i32();
911 vfp_load_reg16(tmp, a->vn);
912 store_reg(s, a->rt, tmp);
913 } else {
914 /* general purpose register to VFP */
915 tmp = load_reg(s, a->rt);
916 tcg_gen_andi_i32(tmp, tmp, 0xffff);
917 vfp_store_reg32(tmp, a->vn);
920 return true;
923 static bool trans_VMOV_single(DisasContext *s, arg_VMOV_single *a)
925 TCGv_i32 tmp;
927 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
928 return false;
931 if (!vfp_access_check(s)) {
932 return true;
935 if (a->l) {
936 /* VFP to general purpose register */
937 tmp = tcg_temp_new_i32();
938 vfp_load_reg32(tmp, a->vn);
939 if (a->rt == 15) {
940 /* Set the 4 flag bits in the CPSR. */
941 gen_set_nzcv(tmp);
942 } else {
943 store_reg(s, a->rt, tmp);
945 } else {
946 /* general purpose register to VFP */
947 tmp = load_reg(s, a->rt);
948 vfp_store_reg32(tmp, a->vn);
951 return true;
954 static bool trans_VMOV_64_sp(DisasContext *s, arg_VMOV_64_sp *a)
956 TCGv_i32 tmp;
958 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
959 return false;
963 * VMOV between two general-purpose registers and two single precision
964 * floating point registers
966 if (!vfp_access_check(s)) {
967 return true;
970 if (a->op) {
971 /* fpreg to gpreg */
972 tmp = tcg_temp_new_i32();
973 vfp_load_reg32(tmp, a->vm);
974 store_reg(s, a->rt, tmp);
975 tmp = tcg_temp_new_i32();
976 vfp_load_reg32(tmp, a->vm + 1);
977 store_reg(s, a->rt2, tmp);
978 } else {
979 /* gpreg to fpreg */
980 tmp = load_reg(s, a->rt);
981 vfp_store_reg32(tmp, a->vm);
982 tmp = load_reg(s, a->rt2);
983 vfp_store_reg32(tmp, a->vm + 1);
986 return true;
989 static bool trans_VMOV_64_dp(DisasContext *s, arg_VMOV_64_dp *a)
991 TCGv_i32 tmp;
994 * VMOV between two general-purpose registers and one double precision
995 * floating point register. Note that this does not require support
996 * for double precision arithmetic.
998 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
999 return false;
1002 /* UNDEF accesses to D16-D31 if they don't exist */
1003 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) {
1004 return false;
1007 if (!vfp_access_check(s)) {
1008 return true;
1011 if (a->op) {
1012 /* fpreg to gpreg */
1013 tmp = tcg_temp_new_i32();
1014 vfp_load_reg32(tmp, a->vm * 2);
1015 store_reg(s, a->rt, tmp);
1016 tmp = tcg_temp_new_i32();
1017 vfp_load_reg32(tmp, a->vm * 2 + 1);
1018 store_reg(s, a->rt2, tmp);
1019 } else {
1020 /* gpreg to fpreg */
1021 tmp = load_reg(s, a->rt);
1022 vfp_store_reg32(tmp, a->vm * 2);
1023 tmp = load_reg(s, a->rt2);
1024 vfp_store_reg32(tmp, a->vm * 2 + 1);
1027 return true;
1030 static bool trans_VLDR_VSTR_hp(DisasContext *s, arg_VLDR_VSTR_sp *a)
1032 uint32_t offset;
1033 TCGv_i32 addr, tmp;
1035 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
1036 return false;
1039 if (!vfp_access_check(s)) {
1040 return true;
1043 /* imm8 field is offset/2 for fp16, unlike fp32 and fp64 */
1044 offset = a->imm << 1;
1045 if (!a->u) {
1046 offset = -offset;
1049 /* For thumb, use of PC is UNPREDICTABLE. */
1050 addr = add_reg_for_lit(s, a->rn, offset);
1051 tmp = tcg_temp_new_i32();
1052 if (a->l) {
1053 gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), MO_UW | MO_ALIGN);
1054 vfp_store_reg32(tmp, a->vd);
1055 } else {
1056 vfp_load_reg32(tmp, a->vd);
1057 gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), MO_UW | MO_ALIGN);
1059 return true;
1062 static bool trans_VLDR_VSTR_sp(DisasContext *s, arg_VLDR_VSTR_sp *a)
1064 uint32_t offset;
1065 TCGv_i32 addr, tmp;
1067 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
1068 return false;
1071 if (!vfp_access_check(s)) {
1072 return true;
1075 offset = a->imm << 2;
1076 if (!a->u) {
1077 offset = -offset;
1080 /* For thumb, use of PC is UNPREDICTABLE. */
1081 addr = add_reg_for_lit(s, a->rn, offset);
1082 tmp = tcg_temp_new_i32();
1083 if (a->l) {
1084 gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN);
1085 vfp_store_reg32(tmp, a->vd);
1086 } else {
1087 vfp_load_reg32(tmp, a->vd);
1088 gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN);
1090 return true;
1093 static bool trans_VLDR_VSTR_dp(DisasContext *s, arg_VLDR_VSTR_dp *a)
1095 uint32_t offset;
1096 TCGv_i32 addr;
1097 TCGv_i64 tmp;
1099 /* Note that this does not require support for double arithmetic. */
1100 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
1101 return false;
1104 /* UNDEF accesses to D16-D31 if they don't exist */
1105 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
1106 return false;
1109 if (!vfp_access_check(s)) {
1110 return true;
1113 offset = a->imm << 2;
1114 if (!a->u) {
1115 offset = -offset;
1118 /* For thumb, use of PC is UNPREDICTABLE. */
1119 addr = add_reg_for_lit(s, a->rn, offset);
1120 tmp = tcg_temp_new_i64();
1121 if (a->l) {
1122 gen_aa32_ld_i64(s, tmp, addr, get_mem_index(s), MO_UQ | MO_ALIGN_4);
1123 vfp_store_reg64(tmp, a->vd);
1124 } else {
1125 vfp_load_reg64(tmp, a->vd);
1126 gen_aa32_st_i64(s, tmp, addr, get_mem_index(s), MO_UQ | MO_ALIGN_4);
1128 return true;
1131 static bool trans_VLDM_VSTM_sp(DisasContext *s, arg_VLDM_VSTM_sp *a)
1133 uint32_t offset;
1134 TCGv_i32 addr, tmp;
1135 int i, n;
1137 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
1138 return false;
1141 n = a->imm;
1143 if (n == 0 || (a->vd + n) > 32) {
1145 * UNPREDICTABLE cases for bad immediates: we choose to
1146 * UNDEF to avoid generating huge numbers of TCG ops
1148 return false;
1150 if (a->rn == 15 && a->w) {
1151 /* writeback to PC is UNPREDICTABLE, we choose to UNDEF */
1152 return false;
1155 s->eci_handled = true;
1157 if (!vfp_access_check(s)) {
1158 return true;
1161 /* For thumb, use of PC is UNPREDICTABLE. */
1162 addr = add_reg_for_lit(s, a->rn, 0);
1163 if (a->p) {
1164 /* pre-decrement */
1165 tcg_gen_addi_i32(addr, addr, -(a->imm << 2));
1168 if (s->v8m_stackcheck && a->rn == 13 && a->w) {
1170 * Here 'addr' is the lowest address we will store to,
1171 * and is either the old SP (if post-increment) or
1172 * the new SP (if pre-decrement). For post-increment
1173 * where the old value is below the limit and the new
1174 * value is above, it is UNKNOWN whether the limit check
1175 * triggers; we choose to trigger.
1177 gen_helper_v8m_stackcheck(tcg_env, addr);
1180 offset = 4;
1181 tmp = tcg_temp_new_i32();
1182 for (i = 0; i < n; i++) {
1183 if (a->l) {
1184 /* load */
1185 gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN);
1186 vfp_store_reg32(tmp, a->vd + i);
1187 } else {
1188 /* store */
1189 vfp_load_reg32(tmp, a->vd + i);
1190 gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), MO_UL | MO_ALIGN);
1192 tcg_gen_addi_i32(addr, addr, offset);
1194 if (a->w) {
1195 /* writeback */
1196 if (a->p) {
1197 offset = -offset * n;
1198 tcg_gen_addi_i32(addr, addr, offset);
1200 store_reg(s, a->rn, addr);
1203 clear_eci_state(s);
1204 return true;
1207 static bool trans_VLDM_VSTM_dp(DisasContext *s, arg_VLDM_VSTM_dp *a)
1209 uint32_t offset;
1210 TCGv_i32 addr;
1211 TCGv_i64 tmp;
1212 int i, n;
1214 /* Note that this does not require support for double arithmetic. */
1215 if (!dc_isar_feature(aa32_fpsp_v2, s) && !dc_isar_feature(aa32_mve, s)) {
1216 return false;
1219 n = a->imm >> 1;
1221 if (n == 0 || (a->vd + n) > 32 || n > 16) {
1223 * UNPREDICTABLE cases for bad immediates: we choose to
1224 * UNDEF to avoid generating huge numbers of TCG ops
1226 return false;
1228 if (a->rn == 15 && a->w) {
1229 /* writeback to PC is UNPREDICTABLE, we choose to UNDEF */
1230 return false;
1233 /* UNDEF accesses to D16-D31 if they don't exist */
1234 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd + n) > 16) {
1235 return false;
1238 s->eci_handled = true;
1240 if (!vfp_access_check(s)) {
1241 return true;
1244 /* For thumb, use of PC is UNPREDICTABLE. */
1245 addr = add_reg_for_lit(s, a->rn, 0);
1246 if (a->p) {
1247 /* pre-decrement */
1248 tcg_gen_addi_i32(addr, addr, -(a->imm << 2));
1251 if (s->v8m_stackcheck && a->rn == 13 && a->w) {
1253 * Here 'addr' is the lowest address we will store to,
1254 * and is either the old SP (if post-increment) or
1255 * the new SP (if pre-decrement). For post-increment
1256 * where the old value is below the limit and the new
1257 * value is above, it is UNKNOWN whether the limit check
1258 * triggers; we choose to trigger.
1260 gen_helper_v8m_stackcheck(tcg_env, addr);
1263 offset = 8;
1264 tmp = tcg_temp_new_i64();
1265 for (i = 0; i < n; i++) {
1266 if (a->l) {
1267 /* load */
1268 gen_aa32_ld_i64(s, tmp, addr, get_mem_index(s), MO_UQ | MO_ALIGN_4);
1269 vfp_store_reg64(tmp, a->vd + i);
1270 } else {
1271 /* store */
1272 vfp_load_reg64(tmp, a->vd + i);
1273 gen_aa32_st_i64(s, tmp, addr, get_mem_index(s), MO_UQ | MO_ALIGN_4);
1275 tcg_gen_addi_i32(addr, addr, offset);
1277 if (a->w) {
1278 /* writeback */
1279 if (a->p) {
1280 offset = -offset * n;
1281 } else if (a->imm & 1) {
1282 offset = 4;
1283 } else {
1284 offset = 0;
1287 if (offset != 0) {
1288 tcg_gen_addi_i32(addr, addr, offset);
1290 store_reg(s, a->rn, addr);
1293 clear_eci_state(s);
1294 return true;
1298 * Types for callbacks for do_vfp_3op_sp() and do_vfp_3op_dp().
1299 * The callback should emit code to write a value to vd. If
1300 * do_vfp_3op_{sp,dp}() was passed reads_vd then the TCGv vd
1301 * will contain the old value of the relevant VFP register;
1302 * otherwise it must be written to only.
1304 typedef void VFPGen3OpSPFn(TCGv_i32 vd,
1305 TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst);
1306 typedef void VFPGen3OpDPFn(TCGv_i64 vd,
1307 TCGv_i64 vn, TCGv_i64 vm, TCGv_ptr fpst);
1310 * Types for callbacks for do_vfp_2op_sp() and do_vfp_2op_dp().
1311 * The callback should emit code to write a value to vd (which
1312 * should be written to only).
1314 typedef void VFPGen2OpSPFn(TCGv_i32 vd, TCGv_i32 vm);
1315 typedef void VFPGen2OpDPFn(TCGv_i64 vd, TCGv_i64 vm);
1318 * Return true if the specified S reg is in a scalar bank
1319 * (ie if it is s0..s7)
1321 static inline bool vfp_sreg_is_scalar(int reg)
1323 return (reg & 0x18) == 0;
1327 * Return true if the specified D reg is in a scalar bank
1328 * (ie if it is d0..d3 or d16..d19)
1330 static inline bool vfp_dreg_is_scalar(int reg)
1332 return (reg & 0xc) == 0;
1336 * Advance the S reg number forwards by delta within its bank
1337 * (ie increment the low 3 bits but leave the rest the same)
1339 static inline int vfp_advance_sreg(int reg, int delta)
1341 return ((reg + delta) & 0x7) | (reg & ~0x7);
1345 * Advance the D reg number forwards by delta within its bank
1346 * (ie increment the low 2 bits but leave the rest the same)
1348 static inline int vfp_advance_dreg(int reg, int delta)
1350 return ((reg + delta) & 0x3) | (reg & ~0x3);
1354 * Perform a 3-operand VFP data processing instruction. fn is the
1355 * callback to do the actual operation; this function deals with the
1356 * code to handle looping around for VFP vector processing.
1358 static bool do_vfp_3op_sp(DisasContext *s, VFPGen3OpSPFn *fn,
1359 int vd, int vn, int vm, bool reads_vd)
1361 uint32_t delta_m = 0;
1362 uint32_t delta_d = 0;
1363 int veclen = s->vec_len;
1364 TCGv_i32 f0, f1, fd;
1365 TCGv_ptr fpst;
1367 if (!dc_isar_feature(aa32_fpsp_v2, s)) {
1368 return false;
1371 if (!dc_isar_feature(aa32_fpshvec, s) &&
1372 (veclen != 0 || s->vec_stride != 0)) {
1373 return false;
1376 if (!vfp_access_check(s)) {
1377 return true;
1380 if (veclen > 0) {
1381 /* Figure out what type of vector operation this is. */
1382 if (vfp_sreg_is_scalar(vd)) {
1383 /* scalar */
1384 veclen = 0;
1385 } else {
1386 delta_d = s->vec_stride + 1;
1388 if (vfp_sreg_is_scalar(vm)) {
1389 /* mixed scalar/vector */
1390 delta_m = 0;
1391 } else {
1392 /* vector */
1393 delta_m = delta_d;
1398 f0 = tcg_temp_new_i32();
1399 f1 = tcg_temp_new_i32();
1400 fd = tcg_temp_new_i32();
1401 fpst = fpstatus_ptr(FPST_FPCR);
1403 vfp_load_reg32(f0, vn);
1404 vfp_load_reg32(f1, vm);
1406 for (;;) {
1407 if (reads_vd) {
1408 vfp_load_reg32(fd, vd);
1410 fn(fd, f0, f1, fpst);
1411 vfp_store_reg32(fd, vd);
1413 if (veclen == 0) {
1414 break;
1417 /* Set up the operands for the next iteration */
1418 veclen--;
1419 vd = vfp_advance_sreg(vd, delta_d);
1420 vn = vfp_advance_sreg(vn, delta_d);
1421 vfp_load_reg32(f0, vn);
1422 if (delta_m) {
1423 vm = vfp_advance_sreg(vm, delta_m);
1424 vfp_load_reg32(f1, vm);
1427 return true;
1430 static bool do_vfp_3op_hp(DisasContext *s, VFPGen3OpSPFn *fn,
1431 int vd, int vn, int vm, bool reads_vd)
1434 * Do a half-precision operation. Functionally this is
1435 * the same as do_vfp_3op_sp(), except:
1436 * - it uses the FPST_FPCR_F16
1437 * - it doesn't need the VFP vector handling (fp16 is a
1438 * v8 feature, and in v8 VFP vectors don't exist)
1439 * - it does the aa32_fp16_arith feature test
1441 TCGv_i32 f0, f1, fd;
1442 TCGv_ptr fpst;
1444 if (!dc_isar_feature(aa32_fp16_arith, s)) {
1445 return false;
1448 if (s->vec_len != 0 || s->vec_stride != 0) {
1449 return false;
1452 if (!vfp_access_check(s)) {
1453 return true;
1456 f0 = tcg_temp_new_i32();
1457 f1 = tcg_temp_new_i32();
1458 fd = tcg_temp_new_i32();
1459 fpst = fpstatus_ptr(FPST_FPCR_F16);
1461 vfp_load_reg16(f0, vn);
1462 vfp_load_reg16(f1, vm);
1464 if (reads_vd) {
1465 vfp_load_reg16(fd, vd);
1467 fn(fd, f0, f1, fpst);
1468 vfp_store_reg32(fd, vd);
1469 return true;
1472 static bool do_vfp_3op_dp(DisasContext *s, VFPGen3OpDPFn *fn,
1473 int vd, int vn, int vm, bool reads_vd)
1475 uint32_t delta_m = 0;
1476 uint32_t delta_d = 0;
1477 int veclen = s->vec_len;
1478 TCGv_i64 f0, f1, fd;
1479 TCGv_ptr fpst;
1481 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
1482 return false;
1485 /* UNDEF accesses to D16-D31 if they don't exist */
1486 if (!dc_isar_feature(aa32_simd_r32, s) && ((vd | vn | vm) & 0x10)) {
1487 return false;
1490 if (!dc_isar_feature(aa32_fpshvec, s) &&
1491 (veclen != 0 || s->vec_stride != 0)) {
1492 return false;
1495 if (!vfp_access_check(s)) {
1496 return true;
1499 if (veclen > 0) {
1500 /* Figure out what type of vector operation this is. */
1501 if (vfp_dreg_is_scalar(vd)) {
1502 /* scalar */
1503 veclen = 0;
1504 } else {
1505 delta_d = (s->vec_stride >> 1) + 1;
1507 if (vfp_dreg_is_scalar(vm)) {
1508 /* mixed scalar/vector */
1509 delta_m = 0;
1510 } else {
1511 /* vector */
1512 delta_m = delta_d;
1517 f0 = tcg_temp_new_i64();
1518 f1 = tcg_temp_new_i64();
1519 fd = tcg_temp_new_i64();
1520 fpst = fpstatus_ptr(FPST_FPCR);
1522 vfp_load_reg64(f0, vn);
1523 vfp_load_reg64(f1, vm);
1525 for (;;) {
1526 if (reads_vd) {
1527 vfp_load_reg64(fd, vd);
1529 fn(fd, f0, f1, fpst);
1530 vfp_store_reg64(fd, vd);
1532 if (veclen == 0) {
1533 break;
1535 /* Set up the operands for the next iteration */
1536 veclen--;
1537 vd = vfp_advance_dreg(vd, delta_d);
1538 vn = vfp_advance_dreg(vn, delta_d);
1539 vfp_load_reg64(f0, vn);
1540 if (delta_m) {
1541 vm = vfp_advance_dreg(vm, delta_m);
1542 vfp_load_reg64(f1, vm);
1545 return true;
1548 static bool do_vfp_2op_sp(DisasContext *s, VFPGen2OpSPFn *fn, int vd, int vm)
1550 uint32_t delta_m = 0;
1551 uint32_t delta_d = 0;
1552 int veclen = s->vec_len;
1553 TCGv_i32 f0, fd;
1555 /* Note that the caller must check the aa32_fpsp_v2 feature. */
1557 if (!dc_isar_feature(aa32_fpshvec, s) &&
1558 (veclen != 0 || s->vec_stride != 0)) {
1559 return false;
1562 if (!vfp_access_check(s)) {
1563 return true;
1566 if (veclen > 0) {
1567 /* Figure out what type of vector operation this is. */
1568 if (vfp_sreg_is_scalar(vd)) {
1569 /* scalar */
1570 veclen = 0;
1571 } else {
1572 delta_d = s->vec_stride + 1;
1574 if (vfp_sreg_is_scalar(vm)) {
1575 /* mixed scalar/vector */
1576 delta_m = 0;
1577 } else {
1578 /* vector */
1579 delta_m = delta_d;
1584 f0 = tcg_temp_new_i32();
1585 fd = tcg_temp_new_i32();
1587 vfp_load_reg32(f0, vm);
1589 for (;;) {
1590 fn(fd, f0);
1591 vfp_store_reg32(fd, vd);
1593 if (veclen == 0) {
1594 break;
1597 if (delta_m == 0) {
1598 /* single source one-many */
1599 while (veclen--) {
1600 vd = vfp_advance_sreg(vd, delta_d);
1601 vfp_store_reg32(fd, vd);
1603 break;
1606 /* Set up the operands for the next iteration */
1607 veclen--;
1608 vd = vfp_advance_sreg(vd, delta_d);
1609 vm = vfp_advance_sreg(vm, delta_m);
1610 vfp_load_reg32(f0, vm);
1612 return true;
1615 static bool do_vfp_2op_hp(DisasContext *s, VFPGen2OpSPFn *fn, int vd, int vm)
1618 * Do a half-precision operation. Functionally this is
1619 * the same as do_vfp_2op_sp(), except:
1620 * - it doesn't need the VFP vector handling (fp16 is a
1621 * v8 feature, and in v8 VFP vectors don't exist)
1622 * - it does the aa32_fp16_arith feature test
1624 TCGv_i32 f0;
1626 /* Note that the caller must check the aa32_fp16_arith feature */
1628 if (!dc_isar_feature(aa32_fp16_arith, s)) {
1629 return false;
1632 if (s->vec_len != 0 || s->vec_stride != 0) {
1633 return false;
1636 if (!vfp_access_check(s)) {
1637 return true;
1640 f0 = tcg_temp_new_i32();
1641 vfp_load_reg16(f0, vm);
1642 fn(f0, f0);
1643 vfp_store_reg32(f0, vd);
1645 return true;
1648 static bool do_vfp_2op_dp(DisasContext *s, VFPGen2OpDPFn *fn, int vd, int vm)
1650 uint32_t delta_m = 0;
1651 uint32_t delta_d = 0;
1652 int veclen = s->vec_len;
1653 TCGv_i64 f0, fd;
1655 /* Note that the caller must check the aa32_fpdp_v2 feature. */
1657 /* UNDEF accesses to D16-D31 if they don't exist */
1658 if (!dc_isar_feature(aa32_simd_r32, s) && ((vd | vm) & 0x10)) {
1659 return false;
1662 if (!dc_isar_feature(aa32_fpshvec, s) &&
1663 (veclen != 0 || s->vec_stride != 0)) {
1664 return false;
1667 if (!vfp_access_check(s)) {
1668 return true;
1671 if (veclen > 0) {
1672 /* Figure out what type of vector operation this is. */
1673 if (vfp_dreg_is_scalar(vd)) {
1674 /* scalar */
1675 veclen = 0;
1676 } else {
1677 delta_d = (s->vec_stride >> 1) + 1;
1679 if (vfp_dreg_is_scalar(vm)) {
1680 /* mixed scalar/vector */
1681 delta_m = 0;
1682 } else {
1683 /* vector */
1684 delta_m = delta_d;
1689 f0 = tcg_temp_new_i64();
1690 fd = tcg_temp_new_i64();
1692 vfp_load_reg64(f0, vm);
1694 for (;;) {
1695 fn(fd, f0);
1696 vfp_store_reg64(fd, vd);
1698 if (veclen == 0) {
1699 break;
1702 if (delta_m == 0) {
1703 /* single source one-many */
1704 while (veclen--) {
1705 vd = vfp_advance_dreg(vd, delta_d);
1706 vfp_store_reg64(fd, vd);
1708 break;
1711 /* Set up the operands for the next iteration */
1712 veclen--;
1713 vd = vfp_advance_dreg(vd, delta_d);
1714 vd = vfp_advance_dreg(vm, delta_m);
1715 vfp_load_reg64(f0, vm);
1717 return true;
1720 static void gen_VMLA_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1722 /* Note that order of inputs to the add matters for NaNs */
1723 TCGv_i32 tmp = tcg_temp_new_i32();
1725 gen_helper_vfp_mulh(tmp, vn, vm, fpst);
1726 gen_helper_vfp_addh(vd, vd, tmp, fpst);
1729 static bool trans_VMLA_hp(DisasContext *s, arg_VMLA_sp *a)
1731 return do_vfp_3op_hp(s, gen_VMLA_hp, a->vd, a->vn, a->vm, true);
1734 static void gen_VMLA_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1736 /* Note that order of inputs to the add matters for NaNs */
1737 TCGv_i32 tmp = tcg_temp_new_i32();
1739 gen_helper_vfp_muls(tmp, vn, vm, fpst);
1740 gen_helper_vfp_adds(vd, vd, tmp, fpst);
1743 static bool trans_VMLA_sp(DisasContext *s, arg_VMLA_sp *a)
1745 return do_vfp_3op_sp(s, gen_VMLA_sp, a->vd, a->vn, a->vm, true);
1748 static void gen_VMLA_dp(TCGv_i64 vd, TCGv_i64 vn, TCGv_i64 vm, TCGv_ptr fpst)
1750 /* Note that order of inputs to the add matters for NaNs */
1751 TCGv_i64 tmp = tcg_temp_new_i64();
1753 gen_helper_vfp_muld(tmp, vn, vm, fpst);
1754 gen_helper_vfp_addd(vd, vd, tmp, fpst);
1757 static bool trans_VMLA_dp(DisasContext *s, arg_VMLA_dp *a)
1759 return do_vfp_3op_dp(s, gen_VMLA_dp, a->vd, a->vn, a->vm, true);
1762 static void gen_VMLS_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1765 * VMLS: vd = vd + -(vn * vm)
1766 * Note that order of inputs to the add matters for NaNs.
1768 TCGv_i32 tmp = tcg_temp_new_i32();
1770 gen_helper_vfp_mulh(tmp, vn, vm, fpst);
1771 gen_vfp_negh(tmp, tmp);
1772 gen_helper_vfp_addh(vd, vd, tmp, fpst);
1775 static bool trans_VMLS_hp(DisasContext *s, arg_VMLS_sp *a)
1777 return do_vfp_3op_hp(s, gen_VMLS_hp, a->vd, a->vn, a->vm, true);
1780 static void gen_VMLS_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1783 * VMLS: vd = vd + -(vn * vm)
1784 * Note that order of inputs to the add matters for NaNs.
1786 TCGv_i32 tmp = tcg_temp_new_i32();
1788 gen_helper_vfp_muls(tmp, vn, vm, fpst);
1789 gen_vfp_negs(tmp, tmp);
1790 gen_helper_vfp_adds(vd, vd, tmp, fpst);
1793 static bool trans_VMLS_sp(DisasContext *s, arg_VMLS_sp *a)
1795 return do_vfp_3op_sp(s, gen_VMLS_sp, a->vd, a->vn, a->vm, true);
1798 static void gen_VMLS_dp(TCGv_i64 vd, TCGv_i64 vn, TCGv_i64 vm, TCGv_ptr fpst)
1801 * VMLS: vd = vd + -(vn * vm)
1802 * Note that order of inputs to the add matters for NaNs.
1804 TCGv_i64 tmp = tcg_temp_new_i64();
1806 gen_helper_vfp_muld(tmp, vn, vm, fpst);
1807 gen_vfp_negd(tmp, tmp);
1808 gen_helper_vfp_addd(vd, vd, tmp, fpst);
1811 static bool trans_VMLS_dp(DisasContext *s, arg_VMLS_dp *a)
1813 return do_vfp_3op_dp(s, gen_VMLS_dp, a->vd, a->vn, a->vm, true);
1816 static void gen_VNMLS_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1819 * VNMLS: -fd + (fn * fm)
1820 * Note that it isn't valid to replace (-A + B) with (B - A) or similar
1821 * plausible looking simplifications because this will give wrong results
1822 * for NaNs.
1824 TCGv_i32 tmp = tcg_temp_new_i32();
1826 gen_helper_vfp_mulh(tmp, vn, vm, fpst);
1827 gen_vfp_negh(vd, vd);
1828 gen_helper_vfp_addh(vd, vd, tmp, fpst);
1831 static bool trans_VNMLS_hp(DisasContext *s, arg_VNMLS_sp *a)
1833 return do_vfp_3op_hp(s, gen_VNMLS_hp, a->vd, a->vn, a->vm, true);
1836 static void gen_VNMLS_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1839 * VNMLS: -fd + (fn * fm)
1840 * Note that it isn't valid to replace (-A + B) with (B - A) or similar
1841 * plausible looking simplifications because this will give wrong results
1842 * for NaNs.
1844 TCGv_i32 tmp = tcg_temp_new_i32();
1846 gen_helper_vfp_muls(tmp, vn, vm, fpst);
1847 gen_vfp_negs(vd, vd);
1848 gen_helper_vfp_adds(vd, vd, tmp, fpst);
1851 static bool trans_VNMLS_sp(DisasContext *s, arg_VNMLS_sp *a)
1853 return do_vfp_3op_sp(s, gen_VNMLS_sp, a->vd, a->vn, a->vm, true);
1856 static void gen_VNMLS_dp(TCGv_i64 vd, TCGv_i64 vn, TCGv_i64 vm, TCGv_ptr fpst)
1859 * VNMLS: -fd + (fn * fm)
1860 * Note that it isn't valid to replace (-A + B) with (B - A) or similar
1861 * plausible looking simplifications because this will give wrong results
1862 * for NaNs.
1864 TCGv_i64 tmp = tcg_temp_new_i64();
1866 gen_helper_vfp_muld(tmp, vn, vm, fpst);
1867 gen_vfp_negd(vd, vd);
1868 gen_helper_vfp_addd(vd, vd, tmp, fpst);
1871 static bool trans_VNMLS_dp(DisasContext *s, arg_VNMLS_dp *a)
1873 return do_vfp_3op_dp(s, gen_VNMLS_dp, a->vd, a->vn, a->vm, true);
1876 static void gen_VNMLA_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1878 /* VNMLA: -fd + -(fn * fm) */
1879 TCGv_i32 tmp = tcg_temp_new_i32();
1881 gen_helper_vfp_mulh(tmp, vn, vm, fpst);
1882 gen_vfp_negh(tmp, tmp);
1883 gen_vfp_negh(vd, vd);
1884 gen_helper_vfp_addh(vd, vd, tmp, fpst);
1887 static bool trans_VNMLA_hp(DisasContext *s, arg_VNMLA_sp *a)
1889 return do_vfp_3op_hp(s, gen_VNMLA_hp, a->vd, a->vn, a->vm, true);
1892 static void gen_VNMLA_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1894 /* VNMLA: -fd + -(fn * fm) */
1895 TCGv_i32 tmp = tcg_temp_new_i32();
1897 gen_helper_vfp_muls(tmp, vn, vm, fpst);
1898 gen_vfp_negs(tmp, tmp);
1899 gen_vfp_negs(vd, vd);
1900 gen_helper_vfp_adds(vd, vd, tmp, fpst);
1903 static bool trans_VNMLA_sp(DisasContext *s, arg_VNMLA_sp *a)
1905 return do_vfp_3op_sp(s, gen_VNMLA_sp, a->vd, a->vn, a->vm, true);
1908 static void gen_VNMLA_dp(TCGv_i64 vd, TCGv_i64 vn, TCGv_i64 vm, TCGv_ptr fpst)
1910 /* VNMLA: -fd + (fn * fm) */
1911 TCGv_i64 tmp = tcg_temp_new_i64();
1913 gen_helper_vfp_muld(tmp, vn, vm, fpst);
1914 gen_vfp_negd(tmp, tmp);
1915 gen_vfp_negd(vd, vd);
1916 gen_helper_vfp_addd(vd, vd, tmp, fpst);
1919 static bool trans_VNMLA_dp(DisasContext *s, arg_VNMLA_dp *a)
1921 return do_vfp_3op_dp(s, gen_VNMLA_dp, a->vd, a->vn, a->vm, true);
1924 static bool trans_VMUL_hp(DisasContext *s, arg_VMUL_sp *a)
1926 return do_vfp_3op_hp(s, gen_helper_vfp_mulh, a->vd, a->vn, a->vm, false);
1929 static bool trans_VMUL_sp(DisasContext *s, arg_VMUL_sp *a)
1931 return do_vfp_3op_sp(s, gen_helper_vfp_muls, a->vd, a->vn, a->vm, false);
1934 static bool trans_VMUL_dp(DisasContext *s, arg_VMUL_dp *a)
1936 return do_vfp_3op_dp(s, gen_helper_vfp_muld, a->vd, a->vn, a->vm, false);
1939 static void gen_VNMUL_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1941 /* VNMUL: -(fn * fm) */
1942 gen_helper_vfp_mulh(vd, vn, vm, fpst);
1943 gen_vfp_negh(vd, vd);
1946 static bool trans_VNMUL_hp(DisasContext *s, arg_VNMUL_sp *a)
1948 return do_vfp_3op_hp(s, gen_VNMUL_hp, a->vd, a->vn, a->vm, false);
1951 static void gen_VNMUL_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst)
1953 /* VNMUL: -(fn * fm) */
1954 gen_helper_vfp_muls(vd, vn, vm, fpst);
1955 gen_vfp_negs(vd, vd);
1958 static bool trans_VNMUL_sp(DisasContext *s, arg_VNMUL_sp *a)
1960 return do_vfp_3op_sp(s, gen_VNMUL_sp, a->vd, a->vn, a->vm, false);
1963 static void gen_VNMUL_dp(TCGv_i64 vd, TCGv_i64 vn, TCGv_i64 vm, TCGv_ptr fpst)
1965 /* VNMUL: -(fn * fm) */
1966 gen_helper_vfp_muld(vd, vn, vm, fpst);
1967 gen_vfp_negd(vd, vd);
1970 static bool trans_VNMUL_dp(DisasContext *s, arg_VNMUL_dp *a)
1972 return do_vfp_3op_dp(s, gen_VNMUL_dp, a->vd, a->vn, a->vm, false);
1975 static bool trans_VADD_hp(DisasContext *s, arg_VADD_sp *a)
1977 return do_vfp_3op_hp(s, gen_helper_vfp_addh, a->vd, a->vn, a->vm, false);
1980 static bool trans_VADD_sp(DisasContext *s, arg_VADD_sp *a)
1982 return do_vfp_3op_sp(s, gen_helper_vfp_adds, a->vd, a->vn, a->vm, false);
1985 static bool trans_VADD_dp(DisasContext *s, arg_VADD_dp *a)
1987 return do_vfp_3op_dp(s, gen_helper_vfp_addd, a->vd, a->vn, a->vm, false);
1990 static bool trans_VSUB_hp(DisasContext *s, arg_VSUB_sp *a)
1992 return do_vfp_3op_hp(s, gen_helper_vfp_subh, a->vd, a->vn, a->vm, false);
1995 static bool trans_VSUB_sp(DisasContext *s, arg_VSUB_sp *a)
1997 return do_vfp_3op_sp(s, gen_helper_vfp_subs, a->vd, a->vn, a->vm, false);
2000 static bool trans_VSUB_dp(DisasContext *s, arg_VSUB_dp *a)
2002 return do_vfp_3op_dp(s, gen_helper_vfp_subd, a->vd, a->vn, a->vm, false);
2005 static bool trans_VDIV_hp(DisasContext *s, arg_VDIV_sp *a)
2007 return do_vfp_3op_hp(s, gen_helper_vfp_divh, a->vd, a->vn, a->vm, false);
2010 static bool trans_VDIV_sp(DisasContext *s, arg_VDIV_sp *a)
2012 return do_vfp_3op_sp(s, gen_helper_vfp_divs, a->vd, a->vn, a->vm, false);
2015 static bool trans_VDIV_dp(DisasContext *s, arg_VDIV_dp *a)
2017 return do_vfp_3op_dp(s, gen_helper_vfp_divd, a->vd, a->vn, a->vm, false);
2020 static bool trans_VMINNM_hp(DisasContext *s, arg_VMINNM_sp *a)
2022 if (!dc_isar_feature(aa32_vminmaxnm, s)) {
2023 return false;
2025 return do_vfp_3op_hp(s, gen_helper_vfp_minnumh,
2026 a->vd, a->vn, a->vm, false);
2029 static bool trans_VMAXNM_hp(DisasContext *s, arg_VMAXNM_sp *a)
2031 if (!dc_isar_feature(aa32_vminmaxnm, s)) {
2032 return false;
2034 return do_vfp_3op_hp(s, gen_helper_vfp_maxnumh,
2035 a->vd, a->vn, a->vm, false);
2038 static bool trans_VMINNM_sp(DisasContext *s, arg_VMINNM_sp *a)
2040 if (!dc_isar_feature(aa32_vminmaxnm, s)) {
2041 return false;
2043 return do_vfp_3op_sp(s, gen_helper_vfp_minnums,
2044 a->vd, a->vn, a->vm, false);
2047 static bool trans_VMAXNM_sp(DisasContext *s, arg_VMAXNM_sp *a)
2049 if (!dc_isar_feature(aa32_vminmaxnm, s)) {
2050 return false;
2052 return do_vfp_3op_sp(s, gen_helper_vfp_maxnums,
2053 a->vd, a->vn, a->vm, false);
2056 static bool trans_VMINNM_dp(DisasContext *s, arg_VMINNM_dp *a)
2058 if (!dc_isar_feature(aa32_vminmaxnm, s)) {
2059 return false;
2061 return do_vfp_3op_dp(s, gen_helper_vfp_minnumd,
2062 a->vd, a->vn, a->vm, false);
2065 static bool trans_VMAXNM_dp(DisasContext *s, arg_VMAXNM_dp *a)
2067 if (!dc_isar_feature(aa32_vminmaxnm, s)) {
2068 return false;
2070 return do_vfp_3op_dp(s, gen_helper_vfp_maxnumd,
2071 a->vd, a->vn, a->vm, false);
2074 static bool do_vfm_hp(DisasContext *s, arg_VFMA_sp *a, bool neg_n, bool neg_d)
2077 * VFNMA : fd = muladd(-fd, fn, fm)
2078 * VFNMS : fd = muladd(-fd, -fn, fm)
2079 * VFMA : fd = muladd( fd, fn, fm)
2080 * VFMS : fd = muladd( fd, -fn, fm)
2082 * These are fused multiply-add, and must be done as one floating
2083 * point operation with no rounding between the multiplication and
2084 * addition steps. NB that doing the negations here as separate
2085 * steps is correct : an input NaN should come out with its sign
2086 * bit flipped if it is a negated-input.
2088 TCGv_ptr fpst;
2089 TCGv_i32 vn, vm, vd;
2092 * Present in VFPv4 only, and only with the FP16 extension.
2093 * Note that we can't rely on the SIMDFMAC check alone, because
2094 * in a Neon-no-VFP core that ID register field will be non-zero.
2096 if (!dc_isar_feature(aa32_fp16_arith, s) ||
2097 !dc_isar_feature(aa32_simdfmac, s) ||
2098 !dc_isar_feature(aa32_fpsp_v2, s)) {
2099 return false;
2102 if (s->vec_len != 0 || s->vec_stride != 0) {
2103 return false;
2106 if (!vfp_access_check(s)) {
2107 return true;
2110 vn = tcg_temp_new_i32();
2111 vm = tcg_temp_new_i32();
2112 vd = tcg_temp_new_i32();
2114 vfp_load_reg16(vn, a->vn);
2115 vfp_load_reg16(vm, a->vm);
2116 if (neg_n) {
2117 /* VFNMS, VFMS */
2118 gen_vfp_negh(vn, vn);
2120 vfp_load_reg16(vd, a->vd);
2121 if (neg_d) {
2122 /* VFNMA, VFNMS */
2123 gen_vfp_negh(vd, vd);
2125 fpst = fpstatus_ptr(FPST_FPCR_F16);
2126 gen_helper_vfp_muladdh(vd, vn, vm, vd, fpst);
2127 vfp_store_reg32(vd, a->vd);
2128 return true;
2131 static bool do_vfm_sp(DisasContext *s, arg_VFMA_sp *a, bool neg_n, bool neg_d)
2134 * VFNMA : fd = muladd(-fd, fn, fm)
2135 * VFNMS : fd = muladd(-fd, -fn, fm)
2136 * VFMA : fd = muladd( fd, fn, fm)
2137 * VFMS : fd = muladd( fd, -fn, fm)
2139 * These are fused multiply-add, and must be done as one floating
2140 * point operation with no rounding between the multiplication and
2141 * addition steps. NB that doing the negations here as separate
2142 * steps is correct : an input NaN should come out with its sign
2143 * bit flipped if it is a negated-input.
2145 TCGv_ptr fpst;
2146 TCGv_i32 vn, vm, vd;
2149 * Present in VFPv4 only.
2150 * Note that we can't rely on the SIMDFMAC check alone, because
2151 * in a Neon-no-VFP core that ID register field will be non-zero.
2153 if (!dc_isar_feature(aa32_simdfmac, s) ||
2154 !dc_isar_feature(aa32_fpsp_v2, s)) {
2155 return false;
2158 * In v7A, UNPREDICTABLE with non-zero vector length/stride; from
2159 * v8A, must UNDEF. We choose to UNDEF for both v7A and v8A.
2161 if (s->vec_len != 0 || s->vec_stride != 0) {
2162 return false;
2165 if (!vfp_access_check(s)) {
2166 return true;
2169 vn = tcg_temp_new_i32();
2170 vm = tcg_temp_new_i32();
2171 vd = tcg_temp_new_i32();
2173 vfp_load_reg32(vn, a->vn);
2174 vfp_load_reg32(vm, a->vm);
2175 if (neg_n) {
2176 /* VFNMS, VFMS */
2177 gen_vfp_negs(vn, vn);
2179 vfp_load_reg32(vd, a->vd);
2180 if (neg_d) {
2181 /* VFNMA, VFNMS */
2182 gen_vfp_negs(vd, vd);
2184 fpst = fpstatus_ptr(FPST_FPCR);
2185 gen_helper_vfp_muladds(vd, vn, vm, vd, fpst);
2186 vfp_store_reg32(vd, a->vd);
2187 return true;
2190 static bool do_vfm_dp(DisasContext *s, arg_VFMA_dp *a, bool neg_n, bool neg_d)
2193 * VFNMA : fd = muladd(-fd, -fn, fm)
2194 * VFNMS : fd = muladd(-fd, fn, fm)
2195 * VFMA : fd = muladd( fd, fn, fm)
2196 * VFMS : fd = muladd( fd, -fn, fm)
2198 * These are fused multiply-add, and must be done as one floating
2199 * point operation with no rounding between the multiplication and
2200 * addition steps. NB that doing the negations here as separate
2201 * steps is correct : an input NaN should come out with its sign
2202 * bit flipped if it is a negated-input.
2204 TCGv_ptr fpst;
2205 TCGv_i64 vn, vm, vd;
2208 * Present in VFPv4 only.
2209 * Note that we can't rely on the SIMDFMAC check alone, because
2210 * in a Neon-no-VFP core that ID register field will be non-zero.
2212 if (!dc_isar_feature(aa32_simdfmac, s) ||
2213 !dc_isar_feature(aa32_fpdp_v2, s)) {
2214 return false;
2217 * In v7A, UNPREDICTABLE with non-zero vector length/stride; from
2218 * v8A, must UNDEF. We choose to UNDEF for both v7A and v8A.
2220 if (s->vec_len != 0 || s->vec_stride != 0) {
2221 return false;
2224 /* UNDEF accesses to D16-D31 if they don't exist. */
2225 if (!dc_isar_feature(aa32_simd_r32, s) &&
2226 ((a->vd | a->vn | a->vm) & 0x10)) {
2227 return false;
2230 if (!vfp_access_check(s)) {
2231 return true;
2234 vn = tcg_temp_new_i64();
2235 vm = tcg_temp_new_i64();
2236 vd = tcg_temp_new_i64();
2238 vfp_load_reg64(vn, a->vn);
2239 vfp_load_reg64(vm, a->vm);
2240 if (neg_n) {
2241 /* VFNMS, VFMS */
2242 gen_vfp_negd(vn, vn);
2244 vfp_load_reg64(vd, a->vd);
2245 if (neg_d) {
2246 /* VFNMA, VFNMS */
2247 gen_vfp_negd(vd, vd);
2249 fpst = fpstatus_ptr(FPST_FPCR);
2250 gen_helper_vfp_muladdd(vd, vn, vm, vd, fpst);
2251 vfp_store_reg64(vd, a->vd);
2252 return true;
2255 #define MAKE_ONE_VFM_TRANS_FN(INSN, PREC, NEGN, NEGD) \
2256 static bool trans_##INSN##_##PREC(DisasContext *s, \
2257 arg_##INSN##_##PREC *a) \
2259 return do_vfm_##PREC(s, a, NEGN, NEGD); \
2262 #define MAKE_VFM_TRANS_FNS(PREC) \
2263 MAKE_ONE_VFM_TRANS_FN(VFMA, PREC, false, false) \
2264 MAKE_ONE_VFM_TRANS_FN(VFMS, PREC, true, false) \
2265 MAKE_ONE_VFM_TRANS_FN(VFNMS, PREC, false, true) \
2266 MAKE_ONE_VFM_TRANS_FN(VFNMA, PREC, true, true)
2268 MAKE_VFM_TRANS_FNS(hp)
2269 MAKE_VFM_TRANS_FNS(sp)
2270 MAKE_VFM_TRANS_FNS(dp)
2272 static bool trans_VMOV_imm_hp(DisasContext *s, arg_VMOV_imm_sp *a)
2274 if (!dc_isar_feature(aa32_fp16_arith, s)) {
2275 return false;
2278 if (s->vec_len != 0 || s->vec_stride != 0) {
2279 return false;
2282 if (!vfp_access_check(s)) {
2283 return true;
2286 vfp_store_reg32(tcg_constant_i32(vfp_expand_imm(MO_16, a->imm)), a->vd);
2287 return true;
2290 static bool trans_VMOV_imm_sp(DisasContext *s, arg_VMOV_imm_sp *a)
2292 uint32_t delta_d = 0;
2293 int veclen = s->vec_len;
2294 TCGv_i32 fd;
2295 uint32_t vd;
2297 vd = a->vd;
2299 if (!dc_isar_feature(aa32_fpsp_v3, s)) {
2300 return false;
2303 if (!dc_isar_feature(aa32_fpshvec, s) &&
2304 (veclen != 0 || s->vec_stride != 0)) {
2305 return false;
2308 if (!vfp_access_check(s)) {
2309 return true;
2312 if (veclen > 0) {
2313 /* Figure out what type of vector operation this is. */
2314 if (vfp_sreg_is_scalar(vd)) {
2315 /* scalar */
2316 veclen = 0;
2317 } else {
2318 delta_d = s->vec_stride + 1;
2322 fd = tcg_constant_i32(vfp_expand_imm(MO_32, a->imm));
2324 for (;;) {
2325 vfp_store_reg32(fd, vd);
2327 if (veclen == 0) {
2328 break;
2331 /* Set up the operands for the next iteration */
2332 veclen--;
2333 vd = vfp_advance_sreg(vd, delta_d);
2336 return true;
2339 static bool trans_VMOV_imm_dp(DisasContext *s, arg_VMOV_imm_dp *a)
2341 uint32_t delta_d = 0;
2342 int veclen = s->vec_len;
2343 TCGv_i64 fd;
2344 uint32_t vd;
2346 vd = a->vd;
2348 if (!dc_isar_feature(aa32_fpdp_v3, s)) {
2349 return false;
2352 /* UNDEF accesses to D16-D31 if they don't exist. */
2353 if (!dc_isar_feature(aa32_simd_r32, s) && (vd & 0x10)) {
2354 return false;
2357 if (!dc_isar_feature(aa32_fpshvec, s) &&
2358 (veclen != 0 || s->vec_stride != 0)) {
2359 return false;
2362 if (!vfp_access_check(s)) {
2363 return true;
2366 if (veclen > 0) {
2367 /* Figure out what type of vector operation this is. */
2368 if (vfp_dreg_is_scalar(vd)) {
2369 /* scalar */
2370 veclen = 0;
2371 } else {
2372 delta_d = (s->vec_stride >> 1) + 1;
2376 fd = tcg_constant_i64(vfp_expand_imm(MO_64, a->imm));
2378 for (;;) {
2379 vfp_store_reg64(fd, vd);
2381 if (veclen == 0) {
2382 break;
2385 /* Set up the operands for the next iteration */
2386 veclen--;
2387 vd = vfp_advance_dreg(vd, delta_d);
2390 return true;
2393 #define DO_VFP_2OP(INSN, PREC, FN, CHECK) \
2394 static bool trans_##INSN##_##PREC(DisasContext *s, \
2395 arg_##INSN##_##PREC *a) \
2397 if (!dc_isar_feature(CHECK, s)) { \
2398 return false; \
2400 return do_vfp_2op_##PREC(s, FN, a->vd, a->vm); \
2403 #define DO_VFP_VMOV(INSN, PREC, FN) \
2404 static bool trans_##INSN##_##PREC(DisasContext *s, \
2405 arg_##INSN##_##PREC *a) \
2407 if (!dc_isar_feature(aa32_fp##PREC##_v2, s) && \
2408 !dc_isar_feature(aa32_mve, s)) { \
2409 return false; \
2411 return do_vfp_2op_##PREC(s, FN, a->vd, a->vm); \
2414 DO_VFP_VMOV(VMOV_reg, sp, tcg_gen_mov_i32)
2415 DO_VFP_VMOV(VMOV_reg, dp, tcg_gen_mov_i64)
2417 DO_VFP_2OP(VABS, hp, gen_vfp_absh, aa32_fp16_arith)
2418 DO_VFP_2OP(VABS, sp, gen_vfp_abss, aa32_fpsp_v2)
2419 DO_VFP_2OP(VABS, dp, gen_vfp_absd, aa32_fpdp_v2)
2421 DO_VFP_2OP(VNEG, hp, gen_vfp_negh, aa32_fp16_arith)
2422 DO_VFP_2OP(VNEG, sp, gen_vfp_negs, aa32_fpsp_v2)
2423 DO_VFP_2OP(VNEG, dp, gen_vfp_negd, aa32_fpdp_v2)
2425 static void gen_VSQRT_hp(TCGv_i32 vd, TCGv_i32 vm)
2427 gen_helper_vfp_sqrth(vd, vm, tcg_env);
2430 static void gen_VSQRT_sp(TCGv_i32 vd, TCGv_i32 vm)
2432 gen_helper_vfp_sqrts(vd, vm, tcg_env);
2435 static void gen_VSQRT_dp(TCGv_i64 vd, TCGv_i64 vm)
2437 gen_helper_vfp_sqrtd(vd, vm, tcg_env);
2440 DO_VFP_2OP(VSQRT, hp, gen_VSQRT_hp, aa32_fp16_arith)
2441 DO_VFP_2OP(VSQRT, sp, gen_VSQRT_sp, aa32_fpsp_v2)
2442 DO_VFP_2OP(VSQRT, dp, gen_VSQRT_dp, aa32_fpdp_v2)
2444 static bool trans_VCMP_hp(DisasContext *s, arg_VCMP_sp *a)
2446 TCGv_i32 vd, vm;
2448 if (!dc_isar_feature(aa32_fp16_arith, s)) {
2449 return false;
2452 /* Vm/M bits must be zero for the Z variant */
2453 if (a->z && a->vm != 0) {
2454 return false;
2457 if (!vfp_access_check(s)) {
2458 return true;
2461 vd = tcg_temp_new_i32();
2462 vm = tcg_temp_new_i32();
2464 vfp_load_reg16(vd, a->vd);
2465 if (a->z) {
2466 tcg_gen_movi_i32(vm, 0);
2467 } else {
2468 vfp_load_reg16(vm, a->vm);
2471 if (a->e) {
2472 gen_helper_vfp_cmpeh(vd, vm, tcg_env);
2473 } else {
2474 gen_helper_vfp_cmph(vd, vm, tcg_env);
2476 return true;
2479 static bool trans_VCMP_sp(DisasContext *s, arg_VCMP_sp *a)
2481 TCGv_i32 vd, vm;
2483 if (!dc_isar_feature(aa32_fpsp_v2, s)) {
2484 return false;
2487 /* Vm/M bits must be zero for the Z variant */
2488 if (a->z && a->vm != 0) {
2489 return false;
2492 if (!vfp_access_check(s)) {
2493 return true;
2496 vd = tcg_temp_new_i32();
2497 vm = tcg_temp_new_i32();
2499 vfp_load_reg32(vd, a->vd);
2500 if (a->z) {
2501 tcg_gen_movi_i32(vm, 0);
2502 } else {
2503 vfp_load_reg32(vm, a->vm);
2506 if (a->e) {
2507 gen_helper_vfp_cmpes(vd, vm, tcg_env);
2508 } else {
2509 gen_helper_vfp_cmps(vd, vm, tcg_env);
2511 return true;
2514 static bool trans_VCMP_dp(DisasContext *s, arg_VCMP_dp *a)
2516 TCGv_i64 vd, vm;
2518 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2519 return false;
2522 /* Vm/M bits must be zero for the Z variant */
2523 if (a->z && a->vm != 0) {
2524 return false;
2527 /* UNDEF accesses to D16-D31 if they don't exist. */
2528 if (!dc_isar_feature(aa32_simd_r32, s) && ((a->vd | a->vm) & 0x10)) {
2529 return false;
2532 if (!vfp_access_check(s)) {
2533 return true;
2536 vd = tcg_temp_new_i64();
2537 vm = tcg_temp_new_i64();
2539 vfp_load_reg64(vd, a->vd);
2540 if (a->z) {
2541 tcg_gen_movi_i64(vm, 0);
2542 } else {
2543 vfp_load_reg64(vm, a->vm);
2546 if (a->e) {
2547 gen_helper_vfp_cmped(vd, vm, tcg_env);
2548 } else {
2549 gen_helper_vfp_cmpd(vd, vm, tcg_env);
2551 return true;
2554 static bool trans_VCVT_f32_f16(DisasContext *s, arg_VCVT_f32_f16 *a)
2556 TCGv_ptr fpst;
2557 TCGv_i32 ahp_mode;
2558 TCGv_i32 tmp;
2560 if (!dc_isar_feature(aa32_fp16_spconv, s)) {
2561 return false;
2564 if (!vfp_access_check(s)) {
2565 return true;
2568 fpst = fpstatus_ptr(FPST_FPCR);
2569 ahp_mode = get_ahp_flag();
2570 tmp = tcg_temp_new_i32();
2571 /* The T bit tells us if we want the low or high 16 bits of Vm */
2572 tcg_gen_ld16u_i32(tmp, tcg_env, vfp_f16_offset(a->vm, a->t));
2573 gen_helper_vfp_fcvt_f16_to_f32(tmp, tmp, fpst, ahp_mode);
2574 vfp_store_reg32(tmp, a->vd);
2575 return true;
2578 static bool trans_VCVT_f64_f16(DisasContext *s, arg_VCVT_f64_f16 *a)
2580 TCGv_ptr fpst;
2581 TCGv_i32 ahp_mode;
2582 TCGv_i32 tmp;
2583 TCGv_i64 vd;
2585 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2586 return false;
2589 if (!dc_isar_feature(aa32_fp16_dpconv, s)) {
2590 return false;
2593 /* UNDEF accesses to D16-D31 if they don't exist. */
2594 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
2595 return false;
2598 if (!vfp_access_check(s)) {
2599 return true;
2602 fpst = fpstatus_ptr(FPST_FPCR);
2603 ahp_mode = get_ahp_flag();
2604 tmp = tcg_temp_new_i32();
2605 /* The T bit tells us if we want the low or high 16 bits of Vm */
2606 tcg_gen_ld16u_i32(tmp, tcg_env, vfp_f16_offset(a->vm, a->t));
2607 vd = tcg_temp_new_i64();
2608 gen_helper_vfp_fcvt_f16_to_f64(vd, tmp, fpst, ahp_mode);
2609 vfp_store_reg64(vd, a->vd);
2610 return true;
2613 static bool trans_VCVT_b16_f32(DisasContext *s, arg_VCVT_b16_f32 *a)
2615 TCGv_ptr fpst;
2616 TCGv_i32 tmp;
2618 if (!dc_isar_feature(aa32_bf16, s)) {
2619 return false;
2622 if (!vfp_access_check(s)) {
2623 return true;
2626 fpst = fpstatus_ptr(FPST_FPCR);
2627 tmp = tcg_temp_new_i32();
2629 vfp_load_reg32(tmp, a->vm);
2630 gen_helper_bfcvt(tmp, tmp, fpst);
2631 tcg_gen_st16_i32(tmp, tcg_env, vfp_f16_offset(a->vd, a->t));
2632 return true;
2635 static bool trans_VCVT_f16_f32(DisasContext *s, arg_VCVT_f16_f32 *a)
2637 TCGv_ptr fpst;
2638 TCGv_i32 ahp_mode;
2639 TCGv_i32 tmp;
2641 if (!dc_isar_feature(aa32_fp16_spconv, s)) {
2642 return false;
2645 if (!vfp_access_check(s)) {
2646 return true;
2649 fpst = fpstatus_ptr(FPST_FPCR);
2650 ahp_mode = get_ahp_flag();
2651 tmp = tcg_temp_new_i32();
2653 vfp_load_reg32(tmp, a->vm);
2654 gen_helper_vfp_fcvt_f32_to_f16(tmp, tmp, fpst, ahp_mode);
2655 tcg_gen_st16_i32(tmp, tcg_env, vfp_f16_offset(a->vd, a->t));
2656 return true;
2659 static bool trans_VCVT_f16_f64(DisasContext *s, arg_VCVT_f16_f64 *a)
2661 TCGv_ptr fpst;
2662 TCGv_i32 ahp_mode;
2663 TCGv_i32 tmp;
2664 TCGv_i64 vm;
2666 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2667 return false;
2670 if (!dc_isar_feature(aa32_fp16_dpconv, s)) {
2671 return false;
2674 /* UNDEF accesses to D16-D31 if they don't exist. */
2675 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) {
2676 return false;
2679 if (!vfp_access_check(s)) {
2680 return true;
2683 fpst = fpstatus_ptr(FPST_FPCR);
2684 ahp_mode = get_ahp_flag();
2685 tmp = tcg_temp_new_i32();
2686 vm = tcg_temp_new_i64();
2688 vfp_load_reg64(vm, a->vm);
2689 gen_helper_vfp_fcvt_f64_to_f16(tmp, vm, fpst, ahp_mode);
2690 tcg_gen_st16_i32(tmp, tcg_env, vfp_f16_offset(a->vd, a->t));
2691 return true;
2694 static bool trans_VRINTR_hp(DisasContext *s, arg_VRINTR_sp *a)
2696 TCGv_ptr fpst;
2697 TCGv_i32 tmp;
2699 if (!dc_isar_feature(aa32_fp16_arith, s)) {
2700 return false;
2703 if (!vfp_access_check(s)) {
2704 return true;
2707 tmp = tcg_temp_new_i32();
2708 vfp_load_reg16(tmp, a->vm);
2709 fpst = fpstatus_ptr(FPST_FPCR_F16);
2710 gen_helper_rinth(tmp, tmp, fpst);
2711 vfp_store_reg32(tmp, a->vd);
2712 return true;
2715 static bool trans_VRINTR_sp(DisasContext *s, arg_VRINTR_sp *a)
2717 TCGv_ptr fpst;
2718 TCGv_i32 tmp;
2720 if (!dc_isar_feature(aa32_vrint, s)) {
2721 return false;
2724 if (!vfp_access_check(s)) {
2725 return true;
2728 tmp = tcg_temp_new_i32();
2729 vfp_load_reg32(tmp, a->vm);
2730 fpst = fpstatus_ptr(FPST_FPCR);
2731 gen_helper_rints(tmp, tmp, fpst);
2732 vfp_store_reg32(tmp, a->vd);
2733 return true;
2736 static bool trans_VRINTR_dp(DisasContext *s, arg_VRINTR_dp *a)
2738 TCGv_ptr fpst;
2739 TCGv_i64 tmp;
2741 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2742 return false;
2745 if (!dc_isar_feature(aa32_vrint, s)) {
2746 return false;
2749 /* UNDEF accesses to D16-D31 if they don't exist. */
2750 if (!dc_isar_feature(aa32_simd_r32, s) && ((a->vd | a->vm) & 0x10)) {
2751 return false;
2754 if (!vfp_access_check(s)) {
2755 return true;
2758 tmp = tcg_temp_new_i64();
2759 vfp_load_reg64(tmp, a->vm);
2760 fpst = fpstatus_ptr(FPST_FPCR);
2761 gen_helper_rintd(tmp, tmp, fpst);
2762 vfp_store_reg64(tmp, a->vd);
2763 return true;
2766 static bool trans_VRINTZ_hp(DisasContext *s, arg_VRINTZ_sp *a)
2768 TCGv_ptr fpst;
2769 TCGv_i32 tmp;
2770 TCGv_i32 tcg_rmode;
2772 if (!dc_isar_feature(aa32_fp16_arith, s)) {
2773 return false;
2776 if (!vfp_access_check(s)) {
2777 return true;
2780 tmp = tcg_temp_new_i32();
2781 vfp_load_reg16(tmp, a->vm);
2782 fpst = fpstatus_ptr(FPST_FPCR_F16);
2783 tcg_rmode = gen_set_rmode(FPROUNDING_ZERO, fpst);
2784 gen_helper_rinth(tmp, tmp, fpst);
2785 gen_restore_rmode(tcg_rmode, fpst);
2786 vfp_store_reg32(tmp, a->vd);
2787 return true;
2790 static bool trans_VRINTZ_sp(DisasContext *s, arg_VRINTZ_sp *a)
2792 TCGv_ptr fpst;
2793 TCGv_i32 tmp;
2794 TCGv_i32 tcg_rmode;
2796 if (!dc_isar_feature(aa32_vrint, s)) {
2797 return false;
2800 if (!vfp_access_check(s)) {
2801 return true;
2804 tmp = tcg_temp_new_i32();
2805 vfp_load_reg32(tmp, a->vm);
2806 fpst = fpstatus_ptr(FPST_FPCR);
2807 tcg_rmode = gen_set_rmode(FPROUNDING_ZERO, fpst);
2808 gen_helper_rints(tmp, tmp, fpst);
2809 gen_restore_rmode(tcg_rmode, fpst);
2810 vfp_store_reg32(tmp, a->vd);
2811 return true;
2814 static bool trans_VRINTZ_dp(DisasContext *s, arg_VRINTZ_dp *a)
2816 TCGv_ptr fpst;
2817 TCGv_i64 tmp;
2818 TCGv_i32 tcg_rmode;
2820 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2821 return false;
2824 if (!dc_isar_feature(aa32_vrint, s)) {
2825 return false;
2828 /* UNDEF accesses to D16-D31 if they don't exist. */
2829 if (!dc_isar_feature(aa32_simd_r32, s) && ((a->vd | a->vm) & 0x10)) {
2830 return false;
2833 if (!vfp_access_check(s)) {
2834 return true;
2837 tmp = tcg_temp_new_i64();
2838 vfp_load_reg64(tmp, a->vm);
2839 fpst = fpstatus_ptr(FPST_FPCR);
2840 tcg_rmode = gen_set_rmode(FPROUNDING_ZERO, fpst);
2841 gen_helper_rintd(tmp, tmp, fpst);
2842 gen_restore_rmode(tcg_rmode, fpst);
2843 vfp_store_reg64(tmp, a->vd);
2844 return true;
2847 static bool trans_VRINTX_hp(DisasContext *s, arg_VRINTX_sp *a)
2849 TCGv_ptr fpst;
2850 TCGv_i32 tmp;
2852 if (!dc_isar_feature(aa32_fp16_arith, s)) {
2853 return false;
2856 if (!vfp_access_check(s)) {
2857 return true;
2860 tmp = tcg_temp_new_i32();
2861 vfp_load_reg16(tmp, a->vm);
2862 fpst = fpstatus_ptr(FPST_FPCR_F16);
2863 gen_helper_rinth_exact(tmp, tmp, fpst);
2864 vfp_store_reg32(tmp, a->vd);
2865 return true;
2868 static bool trans_VRINTX_sp(DisasContext *s, arg_VRINTX_sp *a)
2870 TCGv_ptr fpst;
2871 TCGv_i32 tmp;
2873 if (!dc_isar_feature(aa32_vrint, s)) {
2874 return false;
2877 if (!vfp_access_check(s)) {
2878 return true;
2881 tmp = tcg_temp_new_i32();
2882 vfp_load_reg32(tmp, a->vm);
2883 fpst = fpstatus_ptr(FPST_FPCR);
2884 gen_helper_rints_exact(tmp, tmp, fpst);
2885 vfp_store_reg32(tmp, a->vd);
2886 return true;
2889 static bool trans_VRINTX_dp(DisasContext *s, arg_VRINTX_dp *a)
2891 TCGv_ptr fpst;
2892 TCGv_i64 tmp;
2894 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2895 return false;
2898 if (!dc_isar_feature(aa32_vrint, s)) {
2899 return false;
2902 /* UNDEF accesses to D16-D31 if they don't exist. */
2903 if (!dc_isar_feature(aa32_simd_r32, s) && ((a->vd | a->vm) & 0x10)) {
2904 return false;
2907 if (!vfp_access_check(s)) {
2908 return true;
2911 tmp = tcg_temp_new_i64();
2912 vfp_load_reg64(tmp, a->vm);
2913 fpst = fpstatus_ptr(FPST_FPCR);
2914 gen_helper_rintd_exact(tmp, tmp, fpst);
2915 vfp_store_reg64(tmp, a->vd);
2916 return true;
2919 static bool trans_VCVT_sp(DisasContext *s, arg_VCVT_sp *a)
2921 TCGv_i64 vd;
2922 TCGv_i32 vm;
2924 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2925 return false;
2928 /* UNDEF accesses to D16-D31 if they don't exist. */
2929 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
2930 return false;
2933 if (!vfp_access_check(s)) {
2934 return true;
2937 vm = tcg_temp_new_i32();
2938 vd = tcg_temp_new_i64();
2939 vfp_load_reg32(vm, a->vm);
2940 gen_helper_vfp_fcvtds(vd, vm, tcg_env);
2941 vfp_store_reg64(vd, a->vd);
2942 return true;
2945 static bool trans_VCVT_dp(DisasContext *s, arg_VCVT_dp *a)
2947 TCGv_i64 vm;
2948 TCGv_i32 vd;
2950 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
2951 return false;
2954 /* UNDEF accesses to D16-D31 if they don't exist. */
2955 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) {
2956 return false;
2959 if (!vfp_access_check(s)) {
2960 return true;
2963 vd = tcg_temp_new_i32();
2964 vm = tcg_temp_new_i64();
2965 vfp_load_reg64(vm, a->vm);
2966 gen_helper_vfp_fcvtsd(vd, vm, tcg_env);
2967 vfp_store_reg32(vd, a->vd);
2968 return true;
2971 static bool trans_VCVT_int_hp(DisasContext *s, arg_VCVT_int_sp *a)
2973 TCGv_i32 vm;
2974 TCGv_ptr fpst;
2976 if (!dc_isar_feature(aa32_fp16_arith, s)) {
2977 return false;
2980 if (!vfp_access_check(s)) {
2981 return true;
2984 vm = tcg_temp_new_i32();
2985 vfp_load_reg32(vm, a->vm);
2986 fpst = fpstatus_ptr(FPST_FPCR_F16);
2987 if (a->s) {
2988 /* i32 -> f16 */
2989 gen_helper_vfp_sitoh(vm, vm, fpst);
2990 } else {
2991 /* u32 -> f16 */
2992 gen_helper_vfp_uitoh(vm, vm, fpst);
2994 vfp_store_reg32(vm, a->vd);
2995 return true;
2998 static bool trans_VCVT_int_sp(DisasContext *s, arg_VCVT_int_sp *a)
3000 TCGv_i32 vm;
3001 TCGv_ptr fpst;
3003 if (!dc_isar_feature(aa32_fpsp_v2, s)) {
3004 return false;
3007 if (!vfp_access_check(s)) {
3008 return true;
3011 vm = tcg_temp_new_i32();
3012 vfp_load_reg32(vm, a->vm);
3013 fpst = fpstatus_ptr(FPST_FPCR);
3014 if (a->s) {
3015 /* i32 -> f32 */
3016 gen_helper_vfp_sitos(vm, vm, fpst);
3017 } else {
3018 /* u32 -> f32 */
3019 gen_helper_vfp_uitos(vm, vm, fpst);
3021 vfp_store_reg32(vm, a->vd);
3022 return true;
3025 static bool trans_VCVT_int_dp(DisasContext *s, arg_VCVT_int_dp *a)
3027 TCGv_i32 vm;
3028 TCGv_i64 vd;
3029 TCGv_ptr fpst;
3031 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
3032 return false;
3035 /* UNDEF accesses to D16-D31 if they don't exist. */
3036 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
3037 return false;
3040 if (!vfp_access_check(s)) {
3041 return true;
3044 vm = tcg_temp_new_i32();
3045 vd = tcg_temp_new_i64();
3046 vfp_load_reg32(vm, a->vm);
3047 fpst = fpstatus_ptr(FPST_FPCR);
3048 if (a->s) {
3049 /* i32 -> f64 */
3050 gen_helper_vfp_sitod(vd, vm, fpst);
3051 } else {
3052 /* u32 -> f64 */
3053 gen_helper_vfp_uitod(vd, vm, fpst);
3055 vfp_store_reg64(vd, a->vd);
3056 return true;
3059 static bool trans_VJCVT(DisasContext *s, arg_VJCVT *a)
3061 TCGv_i32 vd;
3062 TCGv_i64 vm;
3064 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
3065 return false;
3068 if (!dc_isar_feature(aa32_jscvt, s)) {
3069 return false;
3072 /* UNDEF accesses to D16-D31 if they don't exist. */
3073 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) {
3074 return false;
3077 if (!vfp_access_check(s)) {
3078 return true;
3081 vm = tcg_temp_new_i64();
3082 vd = tcg_temp_new_i32();
3083 vfp_load_reg64(vm, a->vm);
3084 gen_helper_vjcvt(vd, vm, tcg_env);
3085 vfp_store_reg32(vd, a->vd);
3086 return true;
3089 static bool trans_VCVT_fix_hp(DisasContext *s, arg_VCVT_fix_sp *a)
3091 TCGv_i32 vd, shift;
3092 TCGv_ptr fpst;
3093 int frac_bits;
3095 if (!dc_isar_feature(aa32_fp16_arith, s)) {
3096 return false;
3099 if (!vfp_access_check(s)) {
3100 return true;
3103 frac_bits = (a->opc & 1) ? (32 - a->imm) : (16 - a->imm);
3105 vd = tcg_temp_new_i32();
3106 vfp_load_reg32(vd, a->vd);
3108 fpst = fpstatus_ptr(FPST_FPCR_F16);
3109 shift = tcg_constant_i32(frac_bits);
3111 /* Switch on op:U:sx bits */
3112 switch (a->opc) {
3113 case 0:
3114 gen_helper_vfp_shtoh_round_to_nearest(vd, vd, shift, fpst);
3115 break;
3116 case 1:
3117 gen_helper_vfp_sltoh_round_to_nearest(vd, vd, shift, fpst);
3118 break;
3119 case 2:
3120 gen_helper_vfp_uhtoh_round_to_nearest(vd, vd, shift, fpst);
3121 break;
3122 case 3:
3123 gen_helper_vfp_ultoh_round_to_nearest(vd, vd, shift, fpst);
3124 break;
3125 case 4:
3126 gen_helper_vfp_toshh_round_to_zero(vd, vd, shift, fpst);
3127 break;
3128 case 5:
3129 gen_helper_vfp_toslh_round_to_zero(vd, vd, shift, fpst);
3130 break;
3131 case 6:
3132 gen_helper_vfp_touhh_round_to_zero(vd, vd, shift, fpst);
3133 break;
3134 case 7:
3135 gen_helper_vfp_toulh_round_to_zero(vd, vd, shift, fpst);
3136 break;
3137 default:
3138 g_assert_not_reached();
3141 vfp_store_reg32(vd, a->vd);
3142 return true;
3145 static bool trans_VCVT_fix_sp(DisasContext *s, arg_VCVT_fix_sp *a)
3147 TCGv_i32 vd, shift;
3148 TCGv_ptr fpst;
3149 int frac_bits;
3151 if (!dc_isar_feature(aa32_fpsp_v3, s)) {
3152 return false;
3155 if (!vfp_access_check(s)) {
3156 return true;
3159 frac_bits = (a->opc & 1) ? (32 - a->imm) : (16 - a->imm);
3161 vd = tcg_temp_new_i32();
3162 vfp_load_reg32(vd, a->vd);
3164 fpst = fpstatus_ptr(FPST_FPCR);
3165 shift = tcg_constant_i32(frac_bits);
3167 /* Switch on op:U:sx bits */
3168 switch (a->opc) {
3169 case 0:
3170 gen_helper_vfp_shtos_round_to_nearest(vd, vd, shift, fpst);
3171 break;
3172 case 1:
3173 gen_helper_vfp_sltos_round_to_nearest(vd, vd, shift, fpst);
3174 break;
3175 case 2:
3176 gen_helper_vfp_uhtos_round_to_nearest(vd, vd, shift, fpst);
3177 break;
3178 case 3:
3179 gen_helper_vfp_ultos_round_to_nearest(vd, vd, shift, fpst);
3180 break;
3181 case 4:
3182 gen_helper_vfp_toshs_round_to_zero(vd, vd, shift, fpst);
3183 break;
3184 case 5:
3185 gen_helper_vfp_tosls_round_to_zero(vd, vd, shift, fpst);
3186 break;
3187 case 6:
3188 gen_helper_vfp_touhs_round_to_zero(vd, vd, shift, fpst);
3189 break;
3190 case 7:
3191 gen_helper_vfp_touls_round_to_zero(vd, vd, shift, fpst);
3192 break;
3193 default:
3194 g_assert_not_reached();
3197 vfp_store_reg32(vd, a->vd);
3198 return true;
3201 static bool trans_VCVT_fix_dp(DisasContext *s, arg_VCVT_fix_dp *a)
3203 TCGv_i64 vd;
3204 TCGv_i32 shift;
3205 TCGv_ptr fpst;
3206 int frac_bits;
3208 if (!dc_isar_feature(aa32_fpdp_v3, s)) {
3209 return false;
3212 /* UNDEF accesses to D16-D31 if they don't exist. */
3213 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
3214 return false;
3217 if (!vfp_access_check(s)) {
3218 return true;
3221 frac_bits = (a->opc & 1) ? (32 - a->imm) : (16 - a->imm);
3223 vd = tcg_temp_new_i64();
3224 vfp_load_reg64(vd, a->vd);
3226 fpst = fpstatus_ptr(FPST_FPCR);
3227 shift = tcg_constant_i32(frac_bits);
3229 /* Switch on op:U:sx bits */
3230 switch (a->opc) {
3231 case 0:
3232 gen_helper_vfp_shtod_round_to_nearest(vd, vd, shift, fpst);
3233 break;
3234 case 1:
3235 gen_helper_vfp_sltod_round_to_nearest(vd, vd, shift, fpst);
3236 break;
3237 case 2:
3238 gen_helper_vfp_uhtod_round_to_nearest(vd, vd, shift, fpst);
3239 break;
3240 case 3:
3241 gen_helper_vfp_ultod_round_to_nearest(vd, vd, shift, fpst);
3242 break;
3243 case 4:
3244 gen_helper_vfp_toshd_round_to_zero(vd, vd, shift, fpst);
3245 break;
3246 case 5:
3247 gen_helper_vfp_tosld_round_to_zero(vd, vd, shift, fpst);
3248 break;
3249 case 6:
3250 gen_helper_vfp_touhd_round_to_zero(vd, vd, shift, fpst);
3251 break;
3252 case 7:
3253 gen_helper_vfp_tould_round_to_zero(vd, vd, shift, fpst);
3254 break;
3255 default:
3256 g_assert_not_reached();
3259 vfp_store_reg64(vd, a->vd);
3260 return true;
3263 static bool trans_VCVT_hp_int(DisasContext *s, arg_VCVT_sp_int *a)
3265 TCGv_i32 vm;
3266 TCGv_ptr fpst;
3268 if (!dc_isar_feature(aa32_fp16_arith, s)) {
3269 return false;
3272 if (!vfp_access_check(s)) {
3273 return true;
3276 fpst = fpstatus_ptr(FPST_FPCR_F16);
3277 vm = tcg_temp_new_i32();
3278 vfp_load_reg16(vm, a->vm);
3280 if (a->s) {
3281 if (a->rz) {
3282 gen_helper_vfp_tosizh(vm, vm, fpst);
3283 } else {
3284 gen_helper_vfp_tosih(vm, vm, fpst);
3286 } else {
3287 if (a->rz) {
3288 gen_helper_vfp_touizh(vm, vm, fpst);
3289 } else {
3290 gen_helper_vfp_touih(vm, vm, fpst);
3293 vfp_store_reg32(vm, a->vd);
3294 return true;
3297 static bool trans_VCVT_sp_int(DisasContext *s, arg_VCVT_sp_int *a)
3299 TCGv_i32 vm;
3300 TCGv_ptr fpst;
3302 if (!dc_isar_feature(aa32_fpsp_v2, s)) {
3303 return false;
3306 if (!vfp_access_check(s)) {
3307 return true;
3310 fpst = fpstatus_ptr(FPST_FPCR);
3311 vm = tcg_temp_new_i32();
3312 vfp_load_reg32(vm, a->vm);
3314 if (a->s) {
3315 if (a->rz) {
3316 gen_helper_vfp_tosizs(vm, vm, fpst);
3317 } else {
3318 gen_helper_vfp_tosis(vm, vm, fpst);
3320 } else {
3321 if (a->rz) {
3322 gen_helper_vfp_touizs(vm, vm, fpst);
3323 } else {
3324 gen_helper_vfp_touis(vm, vm, fpst);
3327 vfp_store_reg32(vm, a->vd);
3328 return true;
3331 static bool trans_VCVT_dp_int(DisasContext *s, arg_VCVT_dp_int *a)
3333 TCGv_i32 vd;
3334 TCGv_i64 vm;
3335 TCGv_ptr fpst;
3337 if (!dc_isar_feature(aa32_fpdp_v2, s)) {
3338 return false;
3341 /* UNDEF accesses to D16-D31 if they don't exist. */
3342 if (!dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) {
3343 return false;
3346 if (!vfp_access_check(s)) {
3347 return true;
3350 fpst = fpstatus_ptr(FPST_FPCR);
3351 vm = tcg_temp_new_i64();
3352 vd = tcg_temp_new_i32();
3353 vfp_load_reg64(vm, a->vm);
3355 if (a->s) {
3356 if (a->rz) {
3357 gen_helper_vfp_tosizd(vd, vm, fpst);
3358 } else {
3359 gen_helper_vfp_tosid(vd, vm, fpst);
3361 } else {
3362 if (a->rz) {
3363 gen_helper_vfp_touizd(vd, vm, fpst);
3364 } else {
3365 gen_helper_vfp_touid(vd, vm, fpst);
3368 vfp_store_reg32(vd, a->vd);
3369 return true;
3372 static bool trans_VINS(DisasContext *s, arg_VINS *a)
3374 TCGv_i32 rd, rm;
3376 if (!dc_isar_feature(aa32_fp16_arith, s)) {
3377 return false;
3380 if (s->vec_len != 0 || s->vec_stride != 0) {
3381 return false;
3384 if (!vfp_access_check(s)) {
3385 return true;
3388 /* Insert low half of Vm into high half of Vd */
3389 rm = tcg_temp_new_i32();
3390 rd = tcg_temp_new_i32();
3391 vfp_load_reg16(rm, a->vm);
3392 vfp_load_reg16(rd, a->vd);
3393 tcg_gen_deposit_i32(rd, rd, rm, 16, 16);
3394 vfp_store_reg32(rd, a->vd);
3395 return true;
3398 static bool trans_VMOVX(DisasContext *s, arg_VINS *a)
3400 TCGv_i32 rm;
3402 if (!dc_isar_feature(aa32_fp16_arith, s)) {
3403 return false;
3406 if (s->vec_len != 0 || s->vec_stride != 0) {
3407 return false;
3410 if (!vfp_access_check(s)) {
3411 return true;
3414 /* Set Vd to high half of Vm */
3415 rm = tcg_temp_new_i32();
3416 vfp_load_reg32(rm, a->vm);
3417 tcg_gen_shri_i32(rm, rm, 16);
3418 vfp_store_reg32(rm, a->vd);
3419 return true;