2 * ARM translation: AArch32 Neon instructions
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2005-2007 CodeSourcery
6 * Copyright (c) 2007 OpenedHand, Ltd.
7 * Copyright (c) 2020 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 "tcg/tcg-op.h"
25 #include "tcg/tcg-op-gvec.h"
26 #include "exec/exec-all.h"
27 #include "exec/gen-icount.h"
28 #include "translate.h"
29 #include "translate-a32.h"
31 /* Include the generated Neon decoder */
32 #include "decode-neon-dp.c.inc"
33 #include "decode-neon-ls.c.inc"
34 #include "decode-neon-shared.c.inc"
36 static TCGv_ptr
vfp_reg_ptr(bool dp
, int reg
)
38 TCGv_ptr ret
= tcg_temp_new_ptr();
39 tcg_gen_addi_ptr(ret
, cpu_env
, vfp_reg_offset(dp
, reg
));
43 static void neon_load_element(TCGv_i32 var
, int reg
, int ele
, MemOp mop
)
45 long offset
= neon_element_offset(reg
, ele
, mop
& MO_SIZE
);
49 tcg_gen_ld8u_i32(var
, cpu_env
, offset
);
52 tcg_gen_ld16u_i32(var
, cpu_env
, offset
);
55 tcg_gen_ld_i32(var
, cpu_env
, offset
);
58 g_assert_not_reached();
62 static void neon_load_element64(TCGv_i64 var
, int reg
, int ele
, MemOp mop
)
64 long offset
= neon_element_offset(reg
, ele
, mop
& MO_SIZE
);
68 tcg_gen_ld8u_i64(var
, cpu_env
, offset
);
71 tcg_gen_ld16u_i64(var
, cpu_env
, offset
);
74 tcg_gen_ld32u_i64(var
, cpu_env
, offset
);
77 tcg_gen_ld_i64(var
, cpu_env
, offset
);
80 g_assert_not_reached();
84 static void neon_store_element(int reg
, int ele
, MemOp size
, TCGv_i32 var
)
86 long offset
= neon_element_offset(reg
, ele
, size
);
90 tcg_gen_st8_i32(var
, cpu_env
, offset
);
93 tcg_gen_st16_i32(var
, cpu_env
, offset
);
96 tcg_gen_st_i32(var
, cpu_env
, offset
);
99 g_assert_not_reached();
103 static void neon_store_element64(int reg
, int ele
, MemOp size
, TCGv_i64 var
)
105 long offset
= neon_element_offset(reg
, ele
, size
);
109 tcg_gen_st8_i64(var
, cpu_env
, offset
);
112 tcg_gen_st16_i64(var
, cpu_env
, offset
);
115 tcg_gen_st32_i64(var
, cpu_env
, offset
);
118 tcg_gen_st_i64(var
, cpu_env
, offset
);
121 g_assert_not_reached();
125 static bool do_neon_ddda(DisasContext
*s
, int q
, int vd
, int vn
, int vm
,
126 int data
, gen_helper_gvec_4
*fn_gvec
)
128 /* UNDEF accesses to D16-D31 if they don't exist. */
129 if (((vd
| vn
| vm
) & 0x10) && !dc_isar_feature(aa32_simd_r32
, s
)) {
134 * UNDEF accesses to odd registers for each bit of Q.
135 * Q will be 0b111 for all Q-reg instructions, otherwise
136 * when we have mixed Q- and D-reg inputs.
138 if (((vd
& 1) * 4 | (vn
& 1) * 2 | (vm
& 1)) & q
) {
142 if (!vfp_access_check(s
)) {
146 int opr_sz
= q
? 16 : 8;
147 tcg_gen_gvec_4_ool(vfp_reg_offset(1, vd
),
148 vfp_reg_offset(1, vn
),
149 vfp_reg_offset(1, vm
),
150 vfp_reg_offset(1, vd
),
151 opr_sz
, opr_sz
, data
, fn_gvec
);
155 static bool do_neon_ddda_fpst(DisasContext
*s
, int q
, int vd
, int vn
, int vm
,
156 int data
, ARMFPStatusFlavour fp_flavour
,
157 gen_helper_gvec_4_ptr
*fn_gvec_ptr
)
159 /* UNDEF accesses to D16-D31 if they don't exist. */
160 if (((vd
| vn
| vm
) & 0x10) && !dc_isar_feature(aa32_simd_r32
, s
)) {
165 * UNDEF accesses to odd registers for each bit of Q.
166 * Q will be 0b111 for all Q-reg instructions, otherwise
167 * when we have mixed Q- and D-reg inputs.
169 if (((vd
& 1) * 4 | (vn
& 1) * 2 | (vm
& 1)) & q
) {
173 if (!vfp_access_check(s
)) {
177 int opr_sz
= q
? 16 : 8;
178 TCGv_ptr fpst
= fpstatus_ptr(fp_flavour
);
180 tcg_gen_gvec_4_ptr(vfp_reg_offset(1, vd
),
181 vfp_reg_offset(1, vn
),
182 vfp_reg_offset(1, vm
),
183 vfp_reg_offset(1, vd
),
184 fpst
, opr_sz
, opr_sz
, data
, fn_gvec_ptr
);
185 tcg_temp_free_ptr(fpst
);
189 static bool trans_VCMLA(DisasContext
*s
, arg_VCMLA
*a
)
191 if (!dc_isar_feature(aa32_vcma
, s
)) {
194 if (a
->size
== MO_16
) {
195 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
198 return do_neon_ddda_fpst(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, a
->rot
,
199 FPST_STD_F16
, gen_helper_gvec_fcmlah
);
201 return do_neon_ddda_fpst(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, a
->rot
,
202 FPST_STD
, gen_helper_gvec_fcmlas
);
205 static bool trans_VCADD(DisasContext
*s
, arg_VCADD
*a
)
209 gen_helper_gvec_3_ptr
*fn_gvec_ptr
;
211 if (!dc_isar_feature(aa32_vcma
, s
)
212 || (a
->size
== MO_16
&& !dc_isar_feature(aa32_fp16_arith
, s
))) {
216 /* UNDEF accesses to D16-D31 if they don't exist. */
217 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
218 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
222 if ((a
->vn
| a
->vm
| a
->vd
) & a
->q
) {
226 if (!vfp_access_check(s
)) {
230 opr_sz
= (1 + a
->q
) * 8;
231 fpst
= fpstatus_ptr(a
->size
== MO_16
? FPST_STD_F16
: FPST_STD
);
232 fn_gvec_ptr
= (a
->size
== MO_16
) ?
233 gen_helper_gvec_fcaddh
: gen_helper_gvec_fcadds
;
234 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
235 vfp_reg_offset(1, a
->vn
),
236 vfp_reg_offset(1, a
->vm
),
237 fpst
, opr_sz
, opr_sz
, a
->rot
,
239 tcg_temp_free_ptr(fpst
);
243 static bool trans_VSDOT(DisasContext
*s
, arg_VSDOT
*a
)
245 if (!dc_isar_feature(aa32_dp
, s
)) {
248 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
249 gen_helper_gvec_sdot_b
);
252 static bool trans_VUDOT(DisasContext
*s
, arg_VUDOT
*a
)
254 if (!dc_isar_feature(aa32_dp
, s
)) {
257 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
258 gen_helper_gvec_udot_b
);
261 static bool trans_VUSDOT(DisasContext
*s
, arg_VUSDOT
*a
)
263 if (!dc_isar_feature(aa32_i8mm
, s
)) {
266 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
267 gen_helper_gvec_usdot_b
);
270 static bool trans_VDOT_b16(DisasContext
*s
, arg_VDOT_b16
*a
)
272 if (!dc_isar_feature(aa32_bf16
, s
)) {
275 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
276 gen_helper_gvec_bfdot
);
279 static bool trans_VFML(DisasContext
*s
, arg_VFML
*a
)
283 if (!dc_isar_feature(aa32_fhm
, s
)) {
287 /* UNDEF accesses to D16-D31 if they don't exist. */
288 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
297 if (!vfp_access_check(s
)) {
301 opr_sz
= (1 + a
->q
) * 8;
302 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
303 vfp_reg_offset(a
->q
, a
->vn
),
304 vfp_reg_offset(a
->q
, a
->vm
),
305 cpu_env
, opr_sz
, opr_sz
, a
->s
, /* is_2 == 0 */
306 gen_helper_gvec_fmlal_a32
);
310 static bool trans_VCMLA_scalar(DisasContext
*s
, arg_VCMLA_scalar
*a
)
312 int data
= (a
->index
<< 2) | a
->rot
;
314 if (!dc_isar_feature(aa32_vcma
, s
)) {
317 if (a
->size
== MO_16
) {
318 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
321 return do_neon_ddda_fpst(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, data
,
322 FPST_STD_F16
, gen_helper_gvec_fcmlah_idx
);
324 return do_neon_ddda_fpst(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, data
,
325 FPST_STD
, gen_helper_gvec_fcmlas_idx
);
328 static bool trans_VSDOT_scalar(DisasContext
*s
, arg_VSDOT_scalar
*a
)
330 if (!dc_isar_feature(aa32_dp
, s
)) {
333 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
334 gen_helper_gvec_sdot_idx_b
);
337 static bool trans_VUDOT_scalar(DisasContext
*s
, arg_VUDOT_scalar
*a
)
339 if (!dc_isar_feature(aa32_dp
, s
)) {
342 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
343 gen_helper_gvec_udot_idx_b
);
346 static bool trans_VUSDOT_scalar(DisasContext
*s
, arg_VUSDOT_scalar
*a
)
348 if (!dc_isar_feature(aa32_i8mm
, s
)) {
351 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
352 gen_helper_gvec_usdot_idx_b
);
355 static bool trans_VSUDOT_scalar(DisasContext
*s
, arg_VSUDOT_scalar
*a
)
357 if (!dc_isar_feature(aa32_i8mm
, s
)) {
360 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
361 gen_helper_gvec_sudot_idx_b
);
364 static bool trans_VDOT_b16_scal(DisasContext
*s
, arg_VDOT_b16_scal
*a
)
366 if (!dc_isar_feature(aa32_bf16
, s
)) {
369 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
370 gen_helper_gvec_bfdot_idx
);
373 static bool trans_VFML_scalar(DisasContext
*s
, arg_VFML_scalar
*a
)
377 if (!dc_isar_feature(aa32_fhm
, s
)) {
381 /* UNDEF accesses to D16-D31 if they don't exist. */
382 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
383 ((a
->vd
& 0x10) || (a
->q
&& (a
->vn
& 0x10)))) {
391 if (!vfp_access_check(s
)) {
395 opr_sz
= (1 + a
->q
) * 8;
396 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
397 vfp_reg_offset(a
->q
, a
->vn
),
398 vfp_reg_offset(a
->q
, a
->rm
),
399 cpu_env
, opr_sz
, opr_sz
,
400 (a
->index
<< 2) | a
->s
, /* is_2 == 0 */
401 gen_helper_gvec_fmlal_idx_a32
);
409 } const neon_ls_element_type
[11] = {
423 static void gen_neon_ldst_base_update(DisasContext
*s
, int rm
, int rn
,
429 base
= load_reg(s
, rn
);
431 tcg_gen_addi_i32(base
, base
, stride
);
434 index
= load_reg(s
, rm
);
435 tcg_gen_add_i32(base
, base
, index
);
436 tcg_temp_free_i32(index
);
438 store_reg(s
, rn
, base
);
442 static bool trans_VLDST_multiple(DisasContext
*s
, arg_VLDST_multiple
*a
)
444 /* Neon load/store multiple structures */
445 int nregs
, interleave
, spacing
, reg
, n
;
446 MemOp mop
, align
, endian
;
447 int mmu_idx
= get_mem_index(s
);
452 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
456 /* UNDEF accesses to D16-D31 if they don't exist */
457 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
463 /* Catch UNDEF cases for bad values of align field */
464 switch (a
->itype
& 0xc) {
478 nregs
= neon_ls_element_type
[a
->itype
].nregs
;
479 interleave
= neon_ls_element_type
[a
->itype
].interleave
;
480 spacing
= neon_ls_element_type
[a
->itype
].spacing
;
481 if (size
== 3 && (interleave
| spacing
) != 1) {
485 if (!vfp_access_check(s
)) {
489 /* For our purposes, bytes are always little-endian. */
495 /* Enforce alignment requested by the instruction */
497 align
= pow2_align(a
->align
+ 2); /* 4 ** a->align */
499 align
= s
->align_mem
? MO_ALIGN
: 0;
503 * Consecutive little-endian elements from a single register
504 * can be promoted to a larger little-endian operation.
506 if (interleave
== 1 && endian
== MO_LE
) {
507 /* Retain any natural alignment. */
508 if (align
== MO_ALIGN
) {
509 align
= pow2_align(size
);
514 tmp64
= tcg_temp_new_i64();
515 addr
= tcg_temp_new_i32();
516 load_reg_var(s
, addr
, a
->rn
);
518 mop
= endian
| size
| align
;
519 for (reg
= 0; reg
< nregs
; reg
++) {
520 for (n
= 0; n
< 8 >> size
; n
++) {
522 for (xs
= 0; xs
< interleave
; xs
++) {
523 int tt
= a
->vd
+ reg
+ spacing
* xs
;
526 gen_aa32_ld_internal_i64(s
, tmp64
, addr
, mmu_idx
, mop
);
527 neon_store_element64(tt
, n
, size
, tmp64
);
529 neon_load_element64(tmp64
, tt
, n
, size
);
530 gen_aa32_st_internal_i64(s
, tmp64
, addr
, mmu_idx
, mop
);
532 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
534 /* Subsequent memory operations inherit alignment */
539 tcg_temp_free_i32(addr
);
540 tcg_temp_free_i64(tmp64
);
542 gen_neon_ldst_base_update(s
, a
->rm
, a
->rn
, nregs
* interleave
* 8);
546 static bool trans_VLD_all_lanes(DisasContext
*s
, arg_VLD_all_lanes
*a
)
548 /* Neon load single structure to all lanes */
549 int reg
, stride
, vec_size
;
552 int nregs
= a
->n
+ 1;
556 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
560 /* UNDEF accesses to D16-D31 if they don't exist */
561 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
567 if (nregs
!= 4 || a
->a
== 0) {
570 /* For VLD4 size == 3 a == 1 means 32 bits at 16 byte alignment */
582 align
= pow2_align(size
+ 1);
588 align
= pow2_align(3);
590 align
= pow2_align(size
+ 2);
594 g_assert_not_reached();
598 if (!vfp_access_check(s
)) {
603 * VLD1 to all lanes: T bit indicates how many Dregs to write.
604 * VLD2/3/4 to all lanes: T bit indicates register stride.
606 stride
= a
->t
? 2 : 1;
607 vec_size
= nregs
== 1 ? stride
* 8 : 8;
609 tmp
= tcg_temp_new_i32();
610 addr
= tcg_temp_new_i32();
611 load_reg_var(s
, addr
, a
->rn
);
612 for (reg
= 0; reg
< nregs
; reg
++) {
613 gen_aa32_ld_i32(s
, tmp
, addr
, get_mem_index(s
), mop
);
614 if ((vd
& 1) && vec_size
== 16) {
616 * We cannot write 16 bytes at once because the
617 * destination is unaligned.
619 tcg_gen_gvec_dup_i32(size
, neon_full_reg_offset(vd
),
621 tcg_gen_gvec_mov(0, neon_full_reg_offset(vd
+ 1),
622 neon_full_reg_offset(vd
), 8, 8);
624 tcg_gen_gvec_dup_i32(size
, neon_full_reg_offset(vd
),
625 vec_size
, vec_size
, tmp
);
627 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
630 /* Subsequent memory operations inherit alignment */
633 tcg_temp_free_i32(tmp
);
634 tcg_temp_free_i32(addr
);
636 gen_neon_ldst_base_update(s
, a
->rm
, a
->rn
, (1 << size
) * nregs
);
641 static bool trans_VLDST_single(DisasContext
*s
, arg_VLDST_single
*a
)
643 /* Neon load/store single structure to one lane */
645 int nregs
= a
->n
+ 1;
650 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
654 /* UNDEF accesses to D16-D31 if they don't exist */
655 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
659 /* Catch the UNDEF cases. This is unavoidably a bit messy. */
662 if (a
->stride
!= 1) {
665 if (((a
->align
& (1 << a
->size
)) != 0) ||
666 (a
->size
== 2 && (a
->align
== 1 || a
->align
== 2))) {
671 if (a
->size
== 2 && (a
->align
& 2) != 0) {
681 if (a
->size
== 2 && a
->align
== 3) {
686 g_assert_not_reached();
688 if ((vd
+ a
->stride
* (nregs
- 1)) > 31) {
690 * Attempts to write off the end of the register file are
691 * UNPREDICTABLE; we choose to UNDEF because otherwise we would
692 * access off the end of the array that holds the register data.
697 if (!vfp_access_check(s
)) {
701 /* Pick up SCTLR settings */
702 mop
= finalize_memop(s
, a
->size
);
709 /* For VLD1, use natural alignment. */
713 /* For VLD2, use double alignment. */
714 align_op
= pow2_align(a
->size
+ 1);
717 if (a
->size
== MO_32
) {
719 * For VLD4.32, align = 1 is double alignment, align = 2 is
720 * quad alignment; align = 3 is rejected above.
722 align_op
= pow2_align(a
->size
+ a
->align
);
724 /* For VLD4.8 and VLD.16, we want quad alignment. */
725 align_op
= pow2_align(a
->size
+ 2);
729 /* For VLD3, the alignment field is zero and rejected above. */
730 g_assert_not_reached();
733 mop
= (mop
& ~MO_AMASK
) | align_op
;
736 tmp
= tcg_temp_new_i32();
737 addr
= tcg_temp_new_i32();
738 load_reg_var(s
, addr
, a
->rn
);
740 for (reg
= 0; reg
< nregs
; reg
++) {
742 gen_aa32_ld_internal_i32(s
, tmp
, addr
, get_mem_index(s
), mop
);
743 neon_store_element(vd
, a
->reg_idx
, a
->size
, tmp
);
745 neon_load_element(tmp
, vd
, a
->reg_idx
, a
->size
);
746 gen_aa32_st_internal_i32(s
, tmp
, addr
, get_mem_index(s
), mop
);
749 tcg_gen_addi_i32(addr
, addr
, 1 << a
->size
);
751 /* Subsequent memory operations inherit alignment */
754 tcg_temp_free_i32(addr
);
755 tcg_temp_free_i32(tmp
);
757 gen_neon_ldst_base_update(s
, a
->rm
, a
->rn
, (1 << a
->size
) * nregs
);
762 static bool do_3same(DisasContext
*s
, arg_3same
*a
, GVecGen3Fn fn
)
764 int vec_size
= a
->q
? 16 : 8;
765 int rd_ofs
= neon_full_reg_offset(a
->vd
);
766 int rn_ofs
= neon_full_reg_offset(a
->vn
);
767 int rm_ofs
= neon_full_reg_offset(a
->vm
);
769 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
773 /* UNDEF accesses to D16-D31 if they don't exist. */
774 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
775 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
779 if ((a
->vn
| a
->vm
| a
->vd
) & a
->q
) {
783 if (!vfp_access_check(s
)) {
787 fn(a
->size
, rd_ofs
, rn_ofs
, rm_ofs
, vec_size
, vec_size
);
791 #define DO_3SAME(INSN, FUNC) \
792 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
794 return do_3same(s, a, FUNC); \
797 DO_3SAME(VADD
, tcg_gen_gvec_add
)
798 DO_3SAME(VSUB
, tcg_gen_gvec_sub
)
799 DO_3SAME(VAND
, tcg_gen_gvec_and
)
800 DO_3SAME(VBIC
, tcg_gen_gvec_andc
)
801 DO_3SAME(VORR
, tcg_gen_gvec_or
)
802 DO_3SAME(VORN
, tcg_gen_gvec_orc
)
803 DO_3SAME(VEOR
, tcg_gen_gvec_xor
)
804 DO_3SAME(VSHL_S
, gen_gvec_sshl
)
805 DO_3SAME(VSHL_U
, gen_gvec_ushl
)
806 DO_3SAME(VQADD_S
, gen_gvec_sqadd_qc
)
807 DO_3SAME(VQADD_U
, gen_gvec_uqadd_qc
)
808 DO_3SAME(VQSUB_S
, gen_gvec_sqsub_qc
)
809 DO_3SAME(VQSUB_U
, gen_gvec_uqsub_qc
)
811 /* These insns are all gvec_bitsel but with the inputs in various orders. */
812 #define DO_3SAME_BITSEL(INSN, O1, O2, O3) \
813 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
814 uint32_t rn_ofs, uint32_t rm_ofs, \
815 uint32_t oprsz, uint32_t maxsz) \
817 tcg_gen_gvec_bitsel(vece, rd_ofs, O1, O2, O3, oprsz, maxsz); \
819 DO_3SAME(INSN, gen_##INSN##_3s)
821 DO_3SAME_BITSEL(VBSL
, rd_ofs
, rn_ofs
, rm_ofs
)
822 DO_3SAME_BITSEL(VBIT
, rm_ofs
, rn_ofs
, rd_ofs
)
823 DO_3SAME_BITSEL(VBIF
, rm_ofs
, rd_ofs
, rn_ofs
)
825 #define DO_3SAME_NO_SZ_3(INSN, FUNC) \
826 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
828 if (a->size == 3) { \
831 return do_3same(s, a, FUNC); \
834 DO_3SAME_NO_SZ_3(VMAX_S
, tcg_gen_gvec_smax
)
835 DO_3SAME_NO_SZ_3(VMAX_U
, tcg_gen_gvec_umax
)
836 DO_3SAME_NO_SZ_3(VMIN_S
, tcg_gen_gvec_smin
)
837 DO_3SAME_NO_SZ_3(VMIN_U
, tcg_gen_gvec_umin
)
838 DO_3SAME_NO_SZ_3(VMUL
, tcg_gen_gvec_mul
)
839 DO_3SAME_NO_SZ_3(VMLA
, gen_gvec_mla
)
840 DO_3SAME_NO_SZ_3(VMLS
, gen_gvec_mls
)
841 DO_3SAME_NO_SZ_3(VTST
, gen_gvec_cmtst
)
842 DO_3SAME_NO_SZ_3(VABD_S
, gen_gvec_sabd
)
843 DO_3SAME_NO_SZ_3(VABA_S
, gen_gvec_saba
)
844 DO_3SAME_NO_SZ_3(VABD_U
, gen_gvec_uabd
)
845 DO_3SAME_NO_SZ_3(VABA_U
, gen_gvec_uaba
)
847 #define DO_3SAME_CMP(INSN, COND) \
848 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
849 uint32_t rn_ofs, uint32_t rm_ofs, \
850 uint32_t oprsz, uint32_t maxsz) \
852 tcg_gen_gvec_cmp(COND, vece, rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz); \
854 DO_3SAME_NO_SZ_3(INSN, gen_##INSN##_3s)
856 DO_3SAME_CMP(VCGT_S
, TCG_COND_GT
)
857 DO_3SAME_CMP(VCGT_U
, TCG_COND_GTU
)
858 DO_3SAME_CMP(VCGE_S
, TCG_COND_GE
)
859 DO_3SAME_CMP(VCGE_U
, TCG_COND_GEU
)
860 DO_3SAME_CMP(VCEQ
, TCG_COND_EQ
)
862 #define WRAP_OOL_FN(WRAPNAME, FUNC) \
863 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs, \
864 uint32_t rm_ofs, uint32_t oprsz, uint32_t maxsz) \
866 tcg_gen_gvec_3_ool(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, 0, FUNC); \
869 WRAP_OOL_FN(gen_VMUL_p_3s
, gen_helper_gvec_pmul_b
)
871 static bool trans_VMUL_p_3s(DisasContext
*s
, arg_3same
*a
)
876 return do_3same(s
, a
, gen_VMUL_p_3s
);
879 #define DO_VQRDMLAH(INSN, FUNC) \
880 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
882 if (!dc_isar_feature(aa32_rdm, s)) { \
885 if (a->size != 1 && a->size != 2) { \
888 return do_3same(s, a, FUNC); \
891 DO_VQRDMLAH(VQRDMLAH
, gen_gvec_sqrdmlah_qc
)
892 DO_VQRDMLAH(VQRDMLSH
, gen_gvec_sqrdmlsh_qc
)
894 #define DO_SHA1(NAME, FUNC) \
895 WRAP_OOL_FN(gen_##NAME##_3s, FUNC) \
896 static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a) \
898 if (!dc_isar_feature(aa32_sha1, s)) { \
901 return do_3same(s, a, gen_##NAME##_3s); \
904 DO_SHA1(SHA1C
, gen_helper_crypto_sha1c
)
905 DO_SHA1(SHA1P
, gen_helper_crypto_sha1p
)
906 DO_SHA1(SHA1M
, gen_helper_crypto_sha1m
)
907 DO_SHA1(SHA1SU0
, gen_helper_crypto_sha1su0
)
909 #define DO_SHA2(NAME, FUNC) \
910 WRAP_OOL_FN(gen_##NAME##_3s, FUNC) \
911 static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a) \
913 if (!dc_isar_feature(aa32_sha2, s)) { \
916 return do_3same(s, a, gen_##NAME##_3s); \
919 DO_SHA2(SHA256H
, gen_helper_crypto_sha256h
)
920 DO_SHA2(SHA256H2
, gen_helper_crypto_sha256h2
)
921 DO_SHA2(SHA256SU1
, gen_helper_crypto_sha256su1
)
923 #define DO_3SAME_64(INSN, FUNC) \
924 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
925 uint32_t rn_ofs, uint32_t rm_ofs, \
926 uint32_t oprsz, uint32_t maxsz) \
928 static const GVecGen3 op = { .fni8 = FUNC }; \
929 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &op); \
931 DO_3SAME(INSN, gen_##INSN##_3s)
933 #define DO_3SAME_64_ENV(INSN, FUNC) \
934 static void gen_##INSN##_elt(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m) \
936 FUNC(d, cpu_env, n, m); \
938 DO_3SAME_64(INSN, gen_##INSN##_elt)
940 DO_3SAME_64(VRSHL_S64
, gen_helper_neon_rshl_s64
)
941 DO_3SAME_64(VRSHL_U64
, gen_helper_neon_rshl_u64
)
942 DO_3SAME_64_ENV(VQSHL_S64
, gen_helper_neon_qshl_s64
)
943 DO_3SAME_64_ENV(VQSHL_U64
, gen_helper_neon_qshl_u64
)
944 DO_3SAME_64_ENV(VQRSHL_S64
, gen_helper_neon_qrshl_s64
)
945 DO_3SAME_64_ENV(VQRSHL_U64
, gen_helper_neon_qrshl_u64
)
947 #define DO_3SAME_32(INSN, FUNC) \
948 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
949 uint32_t rn_ofs, uint32_t rm_ofs, \
950 uint32_t oprsz, uint32_t maxsz) \
952 static const GVecGen3 ops[4] = { \
953 { .fni4 = gen_helper_neon_##FUNC##8 }, \
954 { .fni4 = gen_helper_neon_##FUNC##16 }, \
955 { .fni4 = gen_helper_neon_##FUNC##32 }, \
958 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops[vece]); \
960 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
965 return do_3same(s, a, gen_##INSN##_3s); \
969 * Some helper functions need to be passed the cpu_env. In order
970 * to use those with the gvec APIs like tcg_gen_gvec_3() we need
971 * to create wrapper functions whose prototype is a NeonGenTwoOpFn()
972 * and which call a NeonGenTwoOpEnvFn().
974 #define WRAP_ENV_FN(WRAPNAME, FUNC) \
975 static void WRAPNAME(TCGv_i32 d, TCGv_i32 n, TCGv_i32 m) \
977 FUNC(d, cpu_env, n, m); \
980 #define DO_3SAME_32_ENV(INSN, FUNC) \
981 WRAP_ENV_FN(gen_##INSN##_tramp8, gen_helper_neon_##FUNC##8); \
982 WRAP_ENV_FN(gen_##INSN##_tramp16, gen_helper_neon_##FUNC##16); \
983 WRAP_ENV_FN(gen_##INSN##_tramp32, gen_helper_neon_##FUNC##32); \
984 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
985 uint32_t rn_ofs, uint32_t rm_ofs, \
986 uint32_t oprsz, uint32_t maxsz) \
988 static const GVecGen3 ops[4] = { \
989 { .fni4 = gen_##INSN##_tramp8 }, \
990 { .fni4 = gen_##INSN##_tramp16 }, \
991 { .fni4 = gen_##INSN##_tramp32 }, \
994 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops[vece]); \
996 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
1001 return do_3same(s, a, gen_##INSN##_3s); \
1004 DO_3SAME_32(VHADD_S
, hadd_s
)
1005 DO_3SAME_32(VHADD_U
, hadd_u
)
1006 DO_3SAME_32(VHSUB_S
, hsub_s
)
1007 DO_3SAME_32(VHSUB_U
, hsub_u
)
1008 DO_3SAME_32(VRHADD_S
, rhadd_s
)
1009 DO_3SAME_32(VRHADD_U
, rhadd_u
)
1010 DO_3SAME_32(VRSHL_S
, rshl_s
)
1011 DO_3SAME_32(VRSHL_U
, rshl_u
)
1013 DO_3SAME_32_ENV(VQSHL_S
, qshl_s
)
1014 DO_3SAME_32_ENV(VQSHL_U
, qshl_u
)
1015 DO_3SAME_32_ENV(VQRSHL_S
, qrshl_s
)
1016 DO_3SAME_32_ENV(VQRSHL_U
, qrshl_u
)
1018 static bool do_3same_pair(DisasContext
*s
, arg_3same
*a
, NeonGenTwoOpFn
*fn
)
1020 /* Operations handled pairwise 32 bits at a time */
1021 TCGv_i32 tmp
, tmp2
, tmp3
;
1023 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1027 /* UNDEF accesses to D16-D31 if they don't exist. */
1028 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1029 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1037 if (!vfp_access_check(s
)) {
1041 assert(a
->q
== 0); /* enforced by decode patterns */
1044 * Note that we have to be careful not to clobber the source operands
1045 * in the "vm == vd" case by storing the result of the first pass too
1046 * early. Since Q is 0 there are always just two passes, so instead
1047 * of a complicated loop over each pass we just unroll.
1049 tmp
= tcg_temp_new_i32();
1050 tmp2
= tcg_temp_new_i32();
1051 tmp3
= tcg_temp_new_i32();
1053 read_neon_element32(tmp
, a
->vn
, 0, MO_32
);
1054 read_neon_element32(tmp2
, a
->vn
, 1, MO_32
);
1057 read_neon_element32(tmp3
, a
->vm
, 0, MO_32
);
1058 read_neon_element32(tmp2
, a
->vm
, 1, MO_32
);
1059 fn(tmp3
, tmp3
, tmp2
);
1061 write_neon_element32(tmp
, a
->vd
, 0, MO_32
);
1062 write_neon_element32(tmp3
, a
->vd
, 1, MO_32
);
1064 tcg_temp_free_i32(tmp
);
1065 tcg_temp_free_i32(tmp2
);
1066 tcg_temp_free_i32(tmp3
);
1070 #define DO_3SAME_PAIR(INSN, func) \
1071 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
1073 static NeonGenTwoOpFn * const fns[] = { \
1074 gen_helper_neon_##func##8, \
1075 gen_helper_neon_##func##16, \
1076 gen_helper_neon_##func##32, \
1078 if (a->size > 2) { \
1081 return do_3same_pair(s, a, fns[a->size]); \
1084 /* 32-bit pairwise ops end up the same as the elementwise versions. */
1085 #define gen_helper_neon_pmax_s32 tcg_gen_smax_i32
1086 #define gen_helper_neon_pmax_u32 tcg_gen_umax_i32
1087 #define gen_helper_neon_pmin_s32 tcg_gen_smin_i32
1088 #define gen_helper_neon_pmin_u32 tcg_gen_umin_i32
1089 #define gen_helper_neon_padd_u32 tcg_gen_add_i32
1091 DO_3SAME_PAIR(VPMAX_S
, pmax_s
)
1092 DO_3SAME_PAIR(VPMIN_S
, pmin_s
)
1093 DO_3SAME_PAIR(VPMAX_U
, pmax_u
)
1094 DO_3SAME_PAIR(VPMIN_U
, pmin_u
)
1095 DO_3SAME_PAIR(VPADD
, padd_u
)
1097 #define DO_3SAME_VQDMULH(INSN, FUNC) \
1098 WRAP_ENV_FN(gen_##INSN##_tramp16, gen_helper_neon_##FUNC##_s16); \
1099 WRAP_ENV_FN(gen_##INSN##_tramp32, gen_helper_neon_##FUNC##_s32); \
1100 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
1101 uint32_t rn_ofs, uint32_t rm_ofs, \
1102 uint32_t oprsz, uint32_t maxsz) \
1104 static const GVecGen3 ops[2] = { \
1105 { .fni4 = gen_##INSN##_tramp16 }, \
1106 { .fni4 = gen_##INSN##_tramp32 }, \
1108 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops[vece - 1]); \
1110 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
1112 if (a->size != 1 && a->size != 2) { \
1115 return do_3same(s, a, gen_##INSN##_3s); \
1118 DO_3SAME_VQDMULH(VQDMULH
, qdmulh
)
1119 DO_3SAME_VQDMULH(VQRDMULH
, qrdmulh
)
1121 #define WRAP_FP_GVEC(WRAPNAME, FPST, FUNC) \
1122 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \
1123 uint32_t rn_ofs, uint32_t rm_ofs, \
1124 uint32_t oprsz, uint32_t maxsz) \
1126 TCGv_ptr fpst = fpstatus_ptr(FPST); \
1127 tcg_gen_gvec_3_ptr(rd_ofs, rn_ofs, rm_ofs, fpst, \
1128 oprsz, maxsz, 0, FUNC); \
1129 tcg_temp_free_ptr(fpst); \
1132 #define DO_3S_FP_GVEC(INSN,SFUNC,HFUNC) \
1133 WRAP_FP_GVEC(gen_##INSN##_fp32_3s, FPST_STD, SFUNC) \
1134 WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC) \
1135 static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
1137 if (a->size == MO_16) { \
1138 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
1141 return do_3same(s, a, gen_##INSN##_fp16_3s); \
1143 return do_3same(s, a, gen_##INSN##_fp32_3s); \
1147 DO_3S_FP_GVEC(VADD
, gen_helper_gvec_fadd_s
, gen_helper_gvec_fadd_h
)
1148 DO_3S_FP_GVEC(VSUB
, gen_helper_gvec_fsub_s
, gen_helper_gvec_fsub_h
)
1149 DO_3S_FP_GVEC(VABD
, gen_helper_gvec_fabd_s
, gen_helper_gvec_fabd_h
)
1150 DO_3S_FP_GVEC(VMUL
, gen_helper_gvec_fmul_s
, gen_helper_gvec_fmul_h
)
1151 DO_3S_FP_GVEC(VCEQ
, gen_helper_gvec_fceq_s
, gen_helper_gvec_fceq_h
)
1152 DO_3S_FP_GVEC(VCGE
, gen_helper_gvec_fcge_s
, gen_helper_gvec_fcge_h
)
1153 DO_3S_FP_GVEC(VCGT
, gen_helper_gvec_fcgt_s
, gen_helper_gvec_fcgt_h
)
1154 DO_3S_FP_GVEC(VACGE
, gen_helper_gvec_facge_s
, gen_helper_gvec_facge_h
)
1155 DO_3S_FP_GVEC(VACGT
, gen_helper_gvec_facgt_s
, gen_helper_gvec_facgt_h
)
1156 DO_3S_FP_GVEC(VMAX
, gen_helper_gvec_fmax_s
, gen_helper_gvec_fmax_h
)
1157 DO_3S_FP_GVEC(VMIN
, gen_helper_gvec_fmin_s
, gen_helper_gvec_fmin_h
)
1158 DO_3S_FP_GVEC(VMLA
, gen_helper_gvec_fmla_s
, gen_helper_gvec_fmla_h
)
1159 DO_3S_FP_GVEC(VMLS
, gen_helper_gvec_fmls_s
, gen_helper_gvec_fmls_h
)
1160 DO_3S_FP_GVEC(VFMA
, gen_helper_gvec_vfma_s
, gen_helper_gvec_vfma_h
)
1161 DO_3S_FP_GVEC(VFMS
, gen_helper_gvec_vfms_s
, gen_helper_gvec_vfms_h
)
1162 DO_3S_FP_GVEC(VRECPS
, gen_helper_gvec_recps_nf_s
, gen_helper_gvec_recps_nf_h
)
1163 DO_3S_FP_GVEC(VRSQRTS
, gen_helper_gvec_rsqrts_nf_s
, gen_helper_gvec_rsqrts_nf_h
)
1165 WRAP_FP_GVEC(gen_VMAXNM_fp32_3s
, FPST_STD
, gen_helper_gvec_fmaxnum_s
)
1166 WRAP_FP_GVEC(gen_VMAXNM_fp16_3s
, FPST_STD_F16
, gen_helper_gvec_fmaxnum_h
)
1167 WRAP_FP_GVEC(gen_VMINNM_fp32_3s
, FPST_STD
, gen_helper_gvec_fminnum_s
)
1168 WRAP_FP_GVEC(gen_VMINNM_fp16_3s
, FPST_STD_F16
, gen_helper_gvec_fminnum_h
)
1170 static bool trans_VMAXNM_fp_3s(DisasContext
*s
, arg_3same
*a
)
1172 if (!arm_dc_feature(s
, ARM_FEATURE_V8
)) {
1176 if (a
->size
== MO_16
) {
1177 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
1180 return do_3same(s
, a
, gen_VMAXNM_fp16_3s
);
1182 return do_3same(s
, a
, gen_VMAXNM_fp32_3s
);
1185 static bool trans_VMINNM_fp_3s(DisasContext
*s
, arg_3same
*a
)
1187 if (!arm_dc_feature(s
, ARM_FEATURE_V8
)) {
1191 if (a
->size
== MO_16
) {
1192 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
1195 return do_3same(s
, a
, gen_VMINNM_fp16_3s
);
1197 return do_3same(s
, a
, gen_VMINNM_fp32_3s
);
1200 static bool do_3same_fp_pair(DisasContext
*s
, arg_3same
*a
,
1201 gen_helper_gvec_3_ptr
*fn
)
1203 /* FP pairwise operations */
1206 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1210 /* UNDEF accesses to D16-D31 if they don't exist. */
1211 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1212 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1216 if (!vfp_access_check(s
)) {
1220 assert(a
->q
== 0); /* enforced by decode patterns */
1223 fpstatus
= fpstatus_ptr(a
->size
== MO_16
? FPST_STD_F16
: FPST_STD
);
1224 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
1225 vfp_reg_offset(1, a
->vn
),
1226 vfp_reg_offset(1, a
->vm
),
1227 fpstatus
, 8, 8, 0, fn
);
1228 tcg_temp_free_ptr(fpstatus
);
1234 * For all the functions using this macro, size == 1 means fp16,
1235 * which is an architecture extension we don't implement yet.
1237 #define DO_3S_FP_PAIR(INSN,FUNC) \
1238 static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
1240 if (a->size == MO_16) { \
1241 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
1244 return do_3same_fp_pair(s, a, FUNC##h); \
1246 return do_3same_fp_pair(s, a, FUNC##s); \
1249 DO_3S_FP_PAIR(VPADD
, gen_helper_neon_padd
)
1250 DO_3S_FP_PAIR(VPMAX
, gen_helper_neon_pmax
)
1251 DO_3S_FP_PAIR(VPMIN
, gen_helper_neon_pmin
)
1253 static bool do_vector_2sh(DisasContext
*s
, arg_2reg_shift
*a
, GVecGen2iFn
*fn
)
1255 /* Handle a 2-reg-shift insn which can be vectorized. */
1256 int vec_size
= a
->q
? 16 : 8;
1257 int rd_ofs
= neon_full_reg_offset(a
->vd
);
1258 int rm_ofs
= neon_full_reg_offset(a
->vm
);
1260 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1264 /* UNDEF accesses to D16-D31 if they don't exist. */
1265 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1266 ((a
->vd
| a
->vm
) & 0x10)) {
1270 if ((a
->vm
| a
->vd
) & a
->q
) {
1274 if (!vfp_access_check(s
)) {
1278 fn(a
->size
, rd_ofs
, rm_ofs
, a
->shift
, vec_size
, vec_size
);
1282 #define DO_2SH(INSN, FUNC) \
1283 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1285 return do_vector_2sh(s, a, FUNC); \
1288 DO_2SH(VSHL, tcg_gen_gvec_shli)
1289 DO_2SH(VSLI
, gen_gvec_sli
)
1290 DO_2SH(VSRI
, gen_gvec_sri
)
1291 DO_2SH(VSRA_S
, gen_gvec_ssra
)
1292 DO_2SH(VSRA_U
, gen_gvec_usra
)
1293 DO_2SH(VRSHR_S
, gen_gvec_srshr
)
1294 DO_2SH(VRSHR_U
, gen_gvec_urshr
)
1295 DO_2SH(VRSRA_S
, gen_gvec_srsra
)
1296 DO_2SH(VRSRA_U
, gen_gvec_ursra
)
1298 static bool trans_VSHR_S_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1300 /* Signed shift out of range results in all-sign-bits */
1301 a
->shift
= MIN(a
->shift
, (8 << a
->size
) - 1);
1302 return do_vector_2sh(s
, a
, tcg_gen_gvec_sari
);
1305 static void gen_zero_rd_2sh(unsigned vece
, uint32_t rd_ofs
, uint32_t rm_ofs
,
1306 int64_t shift
, uint32_t oprsz
, uint32_t maxsz
)
1308 tcg_gen_gvec_dup_imm(vece
, rd_ofs
, oprsz
, maxsz
, 0);
1311 static bool trans_VSHR_U_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1313 /* Shift out of range is architecturally valid and results in zero. */
1314 if (a
->shift
>= (8 << a
->size
)) {
1315 return do_vector_2sh(s
, a
, gen_zero_rd_2sh
);
1317 return do_vector_2sh(s
, a
, tcg_gen_gvec_shri
);
1321 static bool do_2shift_env_64(DisasContext
*s
, arg_2reg_shift
*a
,
1322 NeonGenTwo64OpEnvFn
*fn
)
1325 * 2-reg-and-shift operations, size == 3 case, where the
1326 * function needs to be passed cpu_env.
1331 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1335 /* UNDEF accesses to D16-D31 if they don't exist. */
1336 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1337 ((a
->vd
| a
->vm
) & 0x10)) {
1341 if ((a
->vm
| a
->vd
) & a
->q
) {
1345 if (!vfp_access_check(s
)) {
1350 * To avoid excessive duplication of ops we implement shift
1351 * by immediate using the variable shift operations.
1353 constimm
= tcg_constant_i64(dup_const(a
->size
, a
->shift
));
1355 for (pass
= 0; pass
< a
->q
+ 1; pass
++) {
1356 TCGv_i64 tmp
= tcg_temp_new_i64();
1358 read_neon_element64(tmp
, a
->vm
, pass
, MO_64
);
1359 fn(tmp
, cpu_env
, tmp
, constimm
);
1360 write_neon_element64(tmp
, a
->vd
, pass
, MO_64
);
1361 tcg_temp_free_i64(tmp
);
1366 static bool do_2shift_env_32(DisasContext
*s
, arg_2reg_shift
*a
,
1367 NeonGenTwoOpEnvFn
*fn
)
1370 * 2-reg-and-shift operations, size < 3 case, where the
1371 * helper needs to be passed cpu_env.
1373 TCGv_i32 constimm
, tmp
;
1376 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1380 /* UNDEF accesses to D16-D31 if they don't exist. */
1381 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1382 ((a
->vd
| a
->vm
) & 0x10)) {
1386 if ((a
->vm
| a
->vd
) & a
->q
) {
1390 if (!vfp_access_check(s
)) {
1395 * To avoid excessive duplication of ops we implement shift
1396 * by immediate using the variable shift operations.
1398 constimm
= tcg_constant_i32(dup_const(a
->size
, a
->shift
));
1399 tmp
= tcg_temp_new_i32();
1401 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
1402 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
1403 fn(tmp
, cpu_env
, tmp
, constimm
);
1404 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
1406 tcg_temp_free_i32(tmp
);
1410 #define DO_2SHIFT_ENV(INSN, FUNC) \
1411 static bool trans_##INSN##_64_2sh(DisasContext *s, arg_2reg_shift *a) \
1413 return do_2shift_env_64(s, a, gen_helper_neon_##FUNC##64); \
1415 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1417 static NeonGenTwoOpEnvFn * const fns[] = { \
1418 gen_helper_neon_##FUNC##8, \
1419 gen_helper_neon_##FUNC##16, \
1420 gen_helper_neon_##FUNC##32, \
1422 assert(a->size < ARRAY_SIZE(fns)); \
1423 return do_2shift_env_32(s, a, fns[a->size]); \
1426 DO_2SHIFT_ENV(VQSHLU
, qshlu_s
)
1427 DO_2SHIFT_ENV(VQSHL_U
, qshl_u
)
1428 DO_2SHIFT_ENV(VQSHL_S
, qshl_s
)
1430 static bool do_2shift_narrow_64(DisasContext
*s
, arg_2reg_shift
*a
,
1431 NeonGenTwo64OpFn
*shiftfn
,
1432 NeonGenNarrowEnvFn
*narrowfn
)
1434 /* 2-reg-and-shift narrowing-shift operations, size == 3 case */
1435 TCGv_i64 constimm
, rm1
, rm2
;
1438 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1442 /* UNDEF accesses to D16-D31 if they don't exist. */
1443 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1444 ((a
->vd
| a
->vm
) & 0x10)) {
1452 if (!vfp_access_check(s
)) {
1457 * This is always a right shift, and the shiftfn is always a
1458 * left-shift helper, which thus needs the negated shift count.
1460 constimm
= tcg_constant_i64(-a
->shift
);
1461 rm1
= tcg_temp_new_i64();
1462 rm2
= tcg_temp_new_i64();
1463 rd
= tcg_temp_new_i32();
1465 /* Load both inputs first to avoid potential overwrite if rm == rd */
1466 read_neon_element64(rm1
, a
->vm
, 0, MO_64
);
1467 read_neon_element64(rm2
, a
->vm
, 1, MO_64
);
1469 shiftfn(rm1
, rm1
, constimm
);
1470 narrowfn(rd
, cpu_env
, rm1
);
1471 write_neon_element32(rd
, a
->vd
, 0, MO_32
);
1473 shiftfn(rm2
, rm2
, constimm
);
1474 narrowfn(rd
, cpu_env
, rm2
);
1475 write_neon_element32(rd
, a
->vd
, 1, MO_32
);
1477 tcg_temp_free_i32(rd
);
1478 tcg_temp_free_i64(rm1
);
1479 tcg_temp_free_i64(rm2
);
1484 static bool do_2shift_narrow_32(DisasContext
*s
, arg_2reg_shift
*a
,
1485 NeonGenTwoOpFn
*shiftfn
,
1486 NeonGenNarrowEnvFn
*narrowfn
)
1488 /* 2-reg-and-shift narrowing-shift operations, size < 3 case */
1489 TCGv_i32 constimm
, rm1
, rm2
, rm3
, rm4
;
1493 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1497 /* UNDEF accesses to D16-D31 if they don't exist. */
1498 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1499 ((a
->vd
| a
->vm
) & 0x10)) {
1507 if (!vfp_access_check(s
)) {
1512 * This is always a right shift, and the shiftfn is always a
1513 * left-shift helper, which thus needs the negated shift count
1514 * duplicated into each lane of the immediate value.
1517 imm
= (uint16_t)(-a
->shift
);
1523 constimm
= tcg_constant_i32(imm
);
1525 /* Load all inputs first to avoid potential overwrite */
1526 rm1
= tcg_temp_new_i32();
1527 rm2
= tcg_temp_new_i32();
1528 rm3
= tcg_temp_new_i32();
1529 rm4
= tcg_temp_new_i32();
1530 read_neon_element32(rm1
, a
->vm
, 0, MO_32
);
1531 read_neon_element32(rm2
, a
->vm
, 1, MO_32
);
1532 read_neon_element32(rm3
, a
->vm
, 2, MO_32
);
1533 read_neon_element32(rm4
, a
->vm
, 3, MO_32
);
1534 rtmp
= tcg_temp_new_i64();
1536 shiftfn(rm1
, rm1
, constimm
);
1537 shiftfn(rm2
, rm2
, constimm
);
1539 tcg_gen_concat_i32_i64(rtmp
, rm1
, rm2
);
1540 tcg_temp_free_i32(rm2
);
1542 narrowfn(rm1
, cpu_env
, rtmp
);
1543 write_neon_element32(rm1
, a
->vd
, 0, MO_32
);
1544 tcg_temp_free_i32(rm1
);
1546 shiftfn(rm3
, rm3
, constimm
);
1547 shiftfn(rm4
, rm4
, constimm
);
1549 tcg_gen_concat_i32_i64(rtmp
, rm3
, rm4
);
1550 tcg_temp_free_i32(rm4
);
1552 narrowfn(rm3
, cpu_env
, rtmp
);
1553 tcg_temp_free_i64(rtmp
);
1554 write_neon_element32(rm3
, a
->vd
, 1, MO_32
);
1555 tcg_temp_free_i32(rm3
);
1559 #define DO_2SN_64(INSN, FUNC, NARROWFUNC) \
1560 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1562 return do_2shift_narrow_64(s, a, FUNC, NARROWFUNC); \
1564 #define DO_2SN_32(INSN, FUNC, NARROWFUNC) \
1565 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1567 return do_2shift_narrow_32(s, a, FUNC, NARROWFUNC); \
1570 static void gen_neon_narrow_u32(TCGv_i32 dest
, TCGv_ptr env
, TCGv_i64 src
)
1572 tcg_gen_extrl_i64_i32(dest
, src
);
1575 static void gen_neon_narrow_u16(TCGv_i32 dest
, TCGv_ptr env
, TCGv_i64 src
)
1577 gen_helper_neon_narrow_u16(dest
, src
);
1580 static void gen_neon_narrow_u8(TCGv_i32 dest
, TCGv_ptr env
, TCGv_i64 src
)
1582 gen_helper_neon_narrow_u8(dest
, src
);
1585 DO_2SN_64(VSHRN_64
, gen_ushl_i64
, gen_neon_narrow_u32
)
1586 DO_2SN_32(VSHRN_32
, gen_ushl_i32
, gen_neon_narrow_u16
)
1587 DO_2SN_32(VSHRN_16
, gen_helper_neon_shl_u16
, gen_neon_narrow_u8
)
1589 DO_2SN_64(VRSHRN_64
, gen_helper_neon_rshl_u64
, gen_neon_narrow_u32
)
1590 DO_2SN_32(VRSHRN_32
, gen_helper_neon_rshl_u32
, gen_neon_narrow_u16
)
1591 DO_2SN_32(VRSHRN_16
, gen_helper_neon_rshl_u16
, gen_neon_narrow_u8
)
1593 DO_2SN_64(VQSHRUN_64
, gen_sshl_i64
, gen_helper_neon_unarrow_sat32
)
1594 DO_2SN_32(VQSHRUN_32
, gen_sshl_i32
, gen_helper_neon_unarrow_sat16
)
1595 DO_2SN_32(VQSHRUN_16
, gen_helper_neon_shl_s16
, gen_helper_neon_unarrow_sat8
)
1597 DO_2SN_64(VQRSHRUN_64
, gen_helper_neon_rshl_s64
, gen_helper_neon_unarrow_sat32
)
1598 DO_2SN_32(VQRSHRUN_32
, gen_helper_neon_rshl_s32
, gen_helper_neon_unarrow_sat16
)
1599 DO_2SN_32(VQRSHRUN_16
, gen_helper_neon_rshl_s16
, gen_helper_neon_unarrow_sat8
)
1600 DO_2SN_64(VQSHRN_S64
, gen_sshl_i64
, gen_helper_neon_narrow_sat_s32
)
1601 DO_2SN_32(VQSHRN_S32
, gen_sshl_i32
, gen_helper_neon_narrow_sat_s16
)
1602 DO_2SN_32(VQSHRN_S16
, gen_helper_neon_shl_s16
, gen_helper_neon_narrow_sat_s8
)
1604 DO_2SN_64(VQRSHRN_S64
, gen_helper_neon_rshl_s64
, gen_helper_neon_narrow_sat_s32
)
1605 DO_2SN_32(VQRSHRN_S32
, gen_helper_neon_rshl_s32
, gen_helper_neon_narrow_sat_s16
)
1606 DO_2SN_32(VQRSHRN_S16
, gen_helper_neon_rshl_s16
, gen_helper_neon_narrow_sat_s8
)
1608 DO_2SN_64(VQSHRN_U64
, gen_ushl_i64
, gen_helper_neon_narrow_sat_u32
)
1609 DO_2SN_32(VQSHRN_U32
, gen_ushl_i32
, gen_helper_neon_narrow_sat_u16
)
1610 DO_2SN_32(VQSHRN_U16
, gen_helper_neon_shl_u16
, gen_helper_neon_narrow_sat_u8
)
1612 DO_2SN_64(VQRSHRN_U64
, gen_helper_neon_rshl_u64
, gen_helper_neon_narrow_sat_u32
)
1613 DO_2SN_32(VQRSHRN_U32
, gen_helper_neon_rshl_u32
, gen_helper_neon_narrow_sat_u16
)
1614 DO_2SN_32(VQRSHRN_U16
, gen_helper_neon_rshl_u16
, gen_helper_neon_narrow_sat_u8
)
1616 static bool do_vshll_2sh(DisasContext
*s
, arg_2reg_shift
*a
,
1617 NeonGenWidenFn
*widenfn
, bool u
)
1621 uint64_t widen_mask
= 0;
1623 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1627 /* UNDEF accesses to D16-D31 if they don't exist. */
1628 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1629 ((a
->vd
| a
->vm
) & 0x10)) {
1637 if (!vfp_access_check(s
)) {
1642 * This is a widen-and-shift operation. The shift is always less
1643 * than the width of the source type, so after widening the input
1644 * vector we can simply shift the whole 64-bit widened register,
1645 * and then clear the potential overflow bits resulting from left
1646 * bits of the narrow input appearing as right bits of the left
1647 * neighbour narrow input. Calculate a mask of bits to clear.
1649 if ((a
->shift
!= 0) && (a
->size
< 2 || u
)) {
1650 int esize
= 8 << a
->size
;
1651 widen_mask
= MAKE_64BIT_MASK(0, esize
);
1652 widen_mask
>>= esize
- a
->shift
;
1653 widen_mask
= dup_const(a
->size
+ 1, widen_mask
);
1656 rm0
= tcg_temp_new_i32();
1657 rm1
= tcg_temp_new_i32();
1658 read_neon_element32(rm0
, a
->vm
, 0, MO_32
);
1659 read_neon_element32(rm1
, a
->vm
, 1, MO_32
);
1660 tmp
= tcg_temp_new_i64();
1663 tcg_temp_free_i32(rm0
);
1664 if (a
->shift
!= 0) {
1665 tcg_gen_shli_i64(tmp
, tmp
, a
->shift
);
1666 tcg_gen_andi_i64(tmp
, tmp
, ~widen_mask
);
1668 write_neon_element64(tmp
, a
->vd
, 0, MO_64
);
1671 tcg_temp_free_i32(rm1
);
1672 if (a
->shift
!= 0) {
1673 tcg_gen_shli_i64(tmp
, tmp
, a
->shift
);
1674 tcg_gen_andi_i64(tmp
, tmp
, ~widen_mask
);
1676 write_neon_element64(tmp
, a
->vd
, 1, MO_64
);
1677 tcg_temp_free_i64(tmp
);
1681 static bool trans_VSHLL_S_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1683 static NeonGenWidenFn
* const widenfn
[] = {
1684 gen_helper_neon_widen_s8
,
1685 gen_helper_neon_widen_s16
,
1686 tcg_gen_ext_i32_i64
,
1688 return do_vshll_2sh(s
, a
, widenfn
[a
->size
], false);
1691 static bool trans_VSHLL_U_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1693 static NeonGenWidenFn
* const widenfn
[] = {
1694 gen_helper_neon_widen_u8
,
1695 gen_helper_neon_widen_u16
,
1696 tcg_gen_extu_i32_i64
,
1698 return do_vshll_2sh(s
, a
, widenfn
[a
->size
], true);
1701 static bool do_fp_2sh(DisasContext
*s
, arg_2reg_shift
*a
,
1702 gen_helper_gvec_2_ptr
*fn
)
1704 /* FP operations in 2-reg-and-shift group */
1705 int vec_size
= a
->q
? 16 : 8;
1706 int rd_ofs
= neon_full_reg_offset(a
->vd
);
1707 int rm_ofs
= neon_full_reg_offset(a
->vm
);
1710 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1714 if (a
->size
== MO_16
) {
1715 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
1720 /* UNDEF accesses to D16-D31 if they don't exist. */
1721 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1722 ((a
->vd
| a
->vm
) & 0x10)) {
1726 if ((a
->vm
| a
->vd
) & a
->q
) {
1730 if (!vfp_access_check(s
)) {
1734 fpst
= fpstatus_ptr(a
->size
== MO_16
? FPST_STD_F16
: FPST_STD
);
1735 tcg_gen_gvec_2_ptr(rd_ofs
, rm_ofs
, fpst
, vec_size
, vec_size
, a
->shift
, fn
);
1736 tcg_temp_free_ptr(fpst
);
1740 #define DO_FP_2SH(INSN, FUNC) \
1741 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1743 return do_fp_2sh(s, a, FUNC); \
1746 DO_FP_2SH(VCVT_SF
, gen_helper_gvec_vcvt_sf
)
1747 DO_FP_2SH(VCVT_UF
, gen_helper_gvec_vcvt_uf
)
1748 DO_FP_2SH(VCVT_FS
, gen_helper_gvec_vcvt_fs
)
1749 DO_FP_2SH(VCVT_FU
, gen_helper_gvec_vcvt_fu
)
1751 DO_FP_2SH(VCVT_SH
, gen_helper_gvec_vcvt_sh
)
1752 DO_FP_2SH(VCVT_UH
, gen_helper_gvec_vcvt_uh
)
1753 DO_FP_2SH(VCVT_HS
, gen_helper_gvec_vcvt_hs
)
1754 DO_FP_2SH(VCVT_HU
, gen_helper_gvec_vcvt_hu
)
1756 static bool do_1reg_imm(DisasContext
*s
, arg_1reg_imm
*a
,
1760 int reg_ofs
, vec_size
;
1762 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1766 /* UNDEF accesses to D16-D31 if they don't exist. */
1767 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
1775 if (!vfp_access_check(s
)) {
1779 reg_ofs
= neon_full_reg_offset(a
->vd
);
1780 vec_size
= a
->q
? 16 : 8;
1781 imm
= asimd_imm_const(a
->imm
, a
->cmode
, a
->op
);
1783 fn(MO_64
, reg_ofs
, reg_ofs
, imm
, vec_size
, vec_size
);
1787 static void gen_VMOV_1r(unsigned vece
, uint32_t dofs
, uint32_t aofs
,
1788 int64_t c
, uint32_t oprsz
, uint32_t maxsz
)
1790 tcg_gen_gvec_dup_imm(MO_64
, dofs
, oprsz
, maxsz
, c
);
1793 static bool trans_Vimm_1r(DisasContext
*s
, arg_1reg_imm
*a
)
1795 /* Handle decode of cmode/op here between VORR/VBIC/VMOV */
1798 if ((a
->cmode
& 1) && a
->cmode
< 12) {
1799 /* for op=1, the imm will be inverted, so BIC becomes AND. */
1800 fn
= a
->op
? tcg_gen_gvec_andi
: tcg_gen_gvec_ori
;
1802 /* There is one unallocated cmode/op combination in this space */
1803 if (a
->cmode
== 15 && a
->op
== 1) {
1808 return do_1reg_imm(s
, a
, fn
);
1811 static bool do_prewiden_3d(DisasContext
*s
, arg_3diff
*a
,
1812 NeonGenWidenFn
*widenfn
,
1813 NeonGenTwo64OpFn
*opfn
,
1814 int src1_mop
, int src2_mop
)
1816 /* 3-regs different lengths, prewidening case (VADDL/VSUBL/VAADW/VSUBW) */
1817 TCGv_i64 rn0_64
, rn1_64
, rm_64
;
1819 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1823 /* UNDEF accesses to D16-D31 if they don't exist. */
1824 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1825 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1830 /* size == 3 case, which is an entirely different insn group */
1834 if ((a
->vd
& 1) || (src1_mop
== MO_UQ
&& (a
->vn
& 1))) {
1838 if (!vfp_access_check(s
)) {
1842 rn0_64
= tcg_temp_new_i64();
1843 rn1_64
= tcg_temp_new_i64();
1844 rm_64
= tcg_temp_new_i64();
1846 if (src1_mop
>= 0) {
1847 read_neon_element64(rn0_64
, a
->vn
, 0, src1_mop
);
1849 TCGv_i32 tmp
= tcg_temp_new_i32();
1850 read_neon_element32(tmp
, a
->vn
, 0, MO_32
);
1851 widenfn(rn0_64
, tmp
);
1852 tcg_temp_free_i32(tmp
);
1854 if (src2_mop
>= 0) {
1855 read_neon_element64(rm_64
, a
->vm
, 0, src2_mop
);
1857 TCGv_i32 tmp
= tcg_temp_new_i32();
1858 read_neon_element32(tmp
, a
->vm
, 0, MO_32
);
1859 widenfn(rm_64
, tmp
);
1860 tcg_temp_free_i32(tmp
);
1863 opfn(rn0_64
, rn0_64
, rm_64
);
1866 * Load second pass inputs before storing the first pass result, to
1867 * avoid incorrect results if a narrow input overlaps with the result.
1869 if (src1_mop
>= 0) {
1870 read_neon_element64(rn1_64
, a
->vn
, 1, src1_mop
);
1872 TCGv_i32 tmp
= tcg_temp_new_i32();
1873 read_neon_element32(tmp
, a
->vn
, 1, MO_32
);
1874 widenfn(rn1_64
, tmp
);
1875 tcg_temp_free_i32(tmp
);
1877 if (src2_mop
>= 0) {
1878 read_neon_element64(rm_64
, a
->vm
, 1, src2_mop
);
1880 TCGv_i32 tmp
= tcg_temp_new_i32();
1881 read_neon_element32(tmp
, a
->vm
, 1, MO_32
);
1882 widenfn(rm_64
, tmp
);
1883 tcg_temp_free_i32(tmp
);
1886 write_neon_element64(rn0_64
, a
->vd
, 0, MO_64
);
1888 opfn(rn1_64
, rn1_64
, rm_64
);
1889 write_neon_element64(rn1_64
, a
->vd
, 1, MO_64
);
1891 tcg_temp_free_i64(rn0_64
);
1892 tcg_temp_free_i64(rn1_64
);
1893 tcg_temp_free_i64(rm_64
);
1898 #define DO_PREWIDEN(INSN, S, OP, SRC1WIDE, SIGN) \
1899 static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a) \
1901 static NeonGenWidenFn * const widenfn[] = { \
1902 gen_helper_neon_widen_##S##8, \
1903 gen_helper_neon_widen_##S##16, \
1906 static NeonGenTwo64OpFn * const addfn[] = { \
1907 gen_helper_neon_##OP##l_u16, \
1908 gen_helper_neon_##OP##l_u32, \
1909 tcg_gen_##OP##_i64, \
1912 int narrow_mop = a->size == MO_32 ? MO_32 | SIGN : -1; \
1913 return do_prewiden_3d(s, a, widenfn[a->size], addfn[a->size], \
1914 SRC1WIDE ? MO_UQ : narrow_mop, \
1918 DO_PREWIDEN(VADDL_S
, s
, add
, false, MO_SIGN
)
1919 DO_PREWIDEN(VADDL_U
, u
, add
, false, 0)
1920 DO_PREWIDEN(VSUBL_S
, s
, sub
, false, MO_SIGN
)
1921 DO_PREWIDEN(VSUBL_U
, u
, sub
, false, 0)
1922 DO_PREWIDEN(VADDW_S
, s
, add
, true, MO_SIGN
)
1923 DO_PREWIDEN(VADDW_U
, u
, add
, true, 0)
1924 DO_PREWIDEN(VSUBW_S
, s
, sub
, true, MO_SIGN
)
1925 DO_PREWIDEN(VSUBW_U
, u
, sub
, true, 0)
1927 static bool do_narrow_3d(DisasContext
*s
, arg_3diff
*a
,
1928 NeonGenTwo64OpFn
*opfn
, NeonGenNarrowFn
*narrowfn
)
1930 /* 3-regs different lengths, narrowing (VADDHN/VSUBHN/VRADDHN/VRSUBHN) */
1931 TCGv_i64 rn_64
, rm_64
;
1934 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1938 /* UNDEF accesses to D16-D31 if they don't exist. */
1939 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1940 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1944 if (!opfn
|| !narrowfn
) {
1945 /* size == 3 case, which is an entirely different insn group */
1949 if ((a
->vn
| a
->vm
) & 1) {
1953 if (!vfp_access_check(s
)) {
1957 rn_64
= tcg_temp_new_i64();
1958 rm_64
= tcg_temp_new_i64();
1959 rd0
= tcg_temp_new_i32();
1960 rd1
= tcg_temp_new_i32();
1962 read_neon_element64(rn_64
, a
->vn
, 0, MO_64
);
1963 read_neon_element64(rm_64
, a
->vm
, 0, MO_64
);
1965 opfn(rn_64
, rn_64
, rm_64
);
1967 narrowfn(rd0
, rn_64
);
1969 read_neon_element64(rn_64
, a
->vn
, 1, MO_64
);
1970 read_neon_element64(rm_64
, a
->vm
, 1, MO_64
);
1972 opfn(rn_64
, rn_64
, rm_64
);
1974 narrowfn(rd1
, rn_64
);
1976 write_neon_element32(rd0
, a
->vd
, 0, MO_32
);
1977 write_neon_element32(rd1
, a
->vd
, 1, MO_32
);
1979 tcg_temp_free_i32(rd0
);
1980 tcg_temp_free_i32(rd1
);
1981 tcg_temp_free_i64(rn_64
);
1982 tcg_temp_free_i64(rm_64
);
1987 #define DO_NARROW_3D(INSN, OP, NARROWTYPE, EXTOP) \
1988 static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a) \
1990 static NeonGenTwo64OpFn * const addfn[] = { \
1991 gen_helper_neon_##OP##l_u16, \
1992 gen_helper_neon_##OP##l_u32, \
1993 tcg_gen_##OP##_i64, \
1996 static NeonGenNarrowFn * const narrowfn[] = { \
1997 gen_helper_neon_##NARROWTYPE##_high_u8, \
1998 gen_helper_neon_##NARROWTYPE##_high_u16, \
2002 return do_narrow_3d(s, a, addfn[a->size], narrowfn[a->size]); \
2005 static void gen_narrow_round_high_u32(TCGv_i32 rd
, TCGv_i64 rn
)
2007 tcg_gen_addi_i64(rn
, rn
, 1u << 31);
2008 tcg_gen_extrh_i64_i32(rd
, rn
);
2011 DO_NARROW_3D(VADDHN
, add
, narrow
, tcg_gen_extrh_i64_i32
)
2012 DO_NARROW_3D(VSUBHN
, sub
, narrow
, tcg_gen_extrh_i64_i32
)
2013 DO_NARROW_3D(VRADDHN
, add
, narrow_round
, gen_narrow_round_high_u32
)
2014 DO_NARROW_3D(VRSUBHN
, sub
, narrow_round
, gen_narrow_round_high_u32
)
2016 static bool do_long_3d(DisasContext
*s
, arg_3diff
*a
,
2017 NeonGenTwoOpWidenFn
*opfn
,
2018 NeonGenTwo64OpFn
*accfn
)
2021 * 3-regs different lengths, long operations.
2022 * These perform an operation on two inputs that returns a double-width
2023 * result, and then possibly perform an accumulation operation of
2024 * that result into the double-width destination.
2026 TCGv_i64 rd0
, rd1
, tmp
;
2029 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2033 /* UNDEF accesses to D16-D31 if they don't exist. */
2034 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2035 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2040 /* size == 3 case, which is an entirely different insn group */
2048 if (!vfp_access_check(s
)) {
2052 rd0
= tcg_temp_new_i64();
2053 rd1
= tcg_temp_new_i64();
2055 rn
= tcg_temp_new_i32();
2056 rm
= tcg_temp_new_i32();
2057 read_neon_element32(rn
, a
->vn
, 0, MO_32
);
2058 read_neon_element32(rm
, a
->vm
, 0, MO_32
);
2061 read_neon_element32(rn
, a
->vn
, 1, MO_32
);
2062 read_neon_element32(rm
, a
->vm
, 1, MO_32
);
2064 tcg_temp_free_i32(rn
);
2065 tcg_temp_free_i32(rm
);
2067 /* Don't store results until after all loads: they might overlap */
2069 tmp
= tcg_temp_new_i64();
2070 read_neon_element64(tmp
, a
->vd
, 0, MO_64
);
2071 accfn(rd0
, tmp
, rd0
);
2072 read_neon_element64(tmp
, a
->vd
, 1, MO_64
);
2073 accfn(rd1
, tmp
, rd1
);
2074 tcg_temp_free_i64(tmp
);
2077 write_neon_element64(rd0
, a
->vd
, 0, MO_64
);
2078 write_neon_element64(rd1
, a
->vd
, 1, MO_64
);
2079 tcg_temp_free_i64(rd0
);
2080 tcg_temp_free_i64(rd1
);
2085 static bool trans_VABDL_S_3d(DisasContext
*s
, arg_3diff
*a
)
2087 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2088 gen_helper_neon_abdl_s16
,
2089 gen_helper_neon_abdl_s32
,
2090 gen_helper_neon_abdl_s64
,
2094 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2097 static bool trans_VABDL_U_3d(DisasContext
*s
, arg_3diff
*a
)
2099 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2100 gen_helper_neon_abdl_u16
,
2101 gen_helper_neon_abdl_u32
,
2102 gen_helper_neon_abdl_u64
,
2106 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2109 static bool trans_VABAL_S_3d(DisasContext
*s
, arg_3diff
*a
)
2111 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2112 gen_helper_neon_abdl_s16
,
2113 gen_helper_neon_abdl_s32
,
2114 gen_helper_neon_abdl_s64
,
2117 static NeonGenTwo64OpFn
* const addfn
[] = {
2118 gen_helper_neon_addl_u16
,
2119 gen_helper_neon_addl_u32
,
2124 return do_long_3d(s
, a
, opfn
[a
->size
], addfn
[a
->size
]);
2127 static bool trans_VABAL_U_3d(DisasContext
*s
, arg_3diff
*a
)
2129 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2130 gen_helper_neon_abdl_u16
,
2131 gen_helper_neon_abdl_u32
,
2132 gen_helper_neon_abdl_u64
,
2135 static NeonGenTwo64OpFn
* const addfn
[] = {
2136 gen_helper_neon_addl_u16
,
2137 gen_helper_neon_addl_u32
,
2142 return do_long_3d(s
, a
, opfn
[a
->size
], addfn
[a
->size
]);
2145 static void gen_mull_s32(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2147 TCGv_i32 lo
= tcg_temp_new_i32();
2148 TCGv_i32 hi
= tcg_temp_new_i32();
2150 tcg_gen_muls2_i32(lo
, hi
, rn
, rm
);
2151 tcg_gen_concat_i32_i64(rd
, lo
, hi
);
2153 tcg_temp_free_i32(lo
);
2154 tcg_temp_free_i32(hi
);
2157 static void gen_mull_u32(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2159 TCGv_i32 lo
= tcg_temp_new_i32();
2160 TCGv_i32 hi
= tcg_temp_new_i32();
2162 tcg_gen_mulu2_i32(lo
, hi
, rn
, rm
);
2163 tcg_gen_concat_i32_i64(rd
, lo
, hi
);
2165 tcg_temp_free_i32(lo
);
2166 tcg_temp_free_i32(hi
);
2169 static bool trans_VMULL_S_3d(DisasContext
*s
, arg_3diff
*a
)
2171 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2172 gen_helper_neon_mull_s8
,
2173 gen_helper_neon_mull_s16
,
2178 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2181 static bool trans_VMULL_U_3d(DisasContext
*s
, arg_3diff
*a
)
2183 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2184 gen_helper_neon_mull_u8
,
2185 gen_helper_neon_mull_u16
,
2190 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2193 #define DO_VMLAL(INSN,MULL,ACC) \
2194 static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a) \
2196 static NeonGenTwoOpWidenFn * const opfn[] = { \
2197 gen_helper_neon_##MULL##8, \
2198 gen_helper_neon_##MULL##16, \
2202 static NeonGenTwo64OpFn * const accfn[] = { \
2203 gen_helper_neon_##ACC##l_u16, \
2204 gen_helper_neon_##ACC##l_u32, \
2205 tcg_gen_##ACC##_i64, \
2208 return do_long_3d(s, a, opfn[a->size], accfn[a->size]); \
2211 DO_VMLAL(VMLAL_S
,mull_s
,add
)
2212 DO_VMLAL(VMLAL_U
,mull_u
,add
)
2213 DO_VMLAL(VMLSL_S
,mull_s
,sub
)
2214 DO_VMLAL(VMLSL_U
,mull_u
,sub
)
2216 static void gen_VQDMULL_16(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2218 gen_helper_neon_mull_s16(rd
, rn
, rm
);
2219 gen_helper_neon_addl_saturate_s32(rd
, cpu_env
, rd
, rd
);
2222 static void gen_VQDMULL_32(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2224 gen_mull_s32(rd
, rn
, rm
);
2225 gen_helper_neon_addl_saturate_s64(rd
, cpu_env
, rd
, rd
);
2228 static bool trans_VQDMULL_3d(DisasContext
*s
, arg_3diff
*a
)
2230 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2237 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2240 static void gen_VQDMLAL_acc_16(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2242 gen_helper_neon_addl_saturate_s32(rd
, cpu_env
, rn
, rm
);
2245 static void gen_VQDMLAL_acc_32(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2247 gen_helper_neon_addl_saturate_s64(rd
, cpu_env
, rn
, rm
);
2250 static bool trans_VQDMLAL_3d(DisasContext
*s
, arg_3diff
*a
)
2252 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2258 static NeonGenTwo64OpFn
* const accfn
[] = {
2265 return do_long_3d(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2268 static void gen_VQDMLSL_acc_16(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2270 gen_helper_neon_negl_u32(rm
, rm
);
2271 gen_helper_neon_addl_saturate_s32(rd
, cpu_env
, rn
, rm
);
2274 static void gen_VQDMLSL_acc_32(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2276 tcg_gen_neg_i64(rm
, rm
);
2277 gen_helper_neon_addl_saturate_s64(rd
, cpu_env
, rn
, rm
);
2280 static bool trans_VQDMLSL_3d(DisasContext
*s
, arg_3diff
*a
)
2282 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2288 static NeonGenTwo64OpFn
* const accfn
[] = {
2295 return do_long_3d(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2298 static bool trans_VMULL_P_3d(DisasContext
*s
, arg_3diff
*a
)
2300 gen_helper_gvec_3
*fn_gvec
;
2302 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2306 /* UNDEF accesses to D16-D31 if they don't exist. */
2307 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2308 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2318 fn_gvec
= gen_helper_neon_pmull_h
;
2321 if (!dc_isar_feature(aa32_pmull
, s
)) {
2324 fn_gvec
= gen_helper_gvec_pmull_q
;
2330 if (!vfp_access_check(s
)) {
2334 tcg_gen_gvec_3_ool(neon_full_reg_offset(a
->vd
),
2335 neon_full_reg_offset(a
->vn
),
2336 neon_full_reg_offset(a
->vm
),
2337 16, 16, 0, fn_gvec
);
2341 static void gen_neon_dup_low16(TCGv_i32 var
)
2343 TCGv_i32 tmp
= tcg_temp_new_i32();
2344 tcg_gen_ext16u_i32(var
, var
);
2345 tcg_gen_shli_i32(tmp
, var
, 16);
2346 tcg_gen_or_i32(var
, var
, tmp
);
2347 tcg_temp_free_i32(tmp
);
2350 static void gen_neon_dup_high16(TCGv_i32 var
)
2352 TCGv_i32 tmp
= tcg_temp_new_i32();
2353 tcg_gen_andi_i32(var
, var
, 0xffff0000);
2354 tcg_gen_shri_i32(tmp
, var
, 16);
2355 tcg_gen_or_i32(var
, var
, tmp
);
2356 tcg_temp_free_i32(tmp
);
2359 static inline TCGv_i32
neon_get_scalar(int size
, int reg
)
2361 TCGv_i32 tmp
= tcg_temp_new_i32();
2362 if (size
== MO_16
) {
2363 read_neon_element32(tmp
, reg
& 7, reg
>> 4, MO_32
);
2365 gen_neon_dup_high16(tmp
);
2367 gen_neon_dup_low16(tmp
);
2370 read_neon_element32(tmp
, reg
& 15, reg
>> 4, MO_32
);
2375 static bool do_2scalar(DisasContext
*s
, arg_2scalar
*a
,
2376 NeonGenTwoOpFn
*opfn
, NeonGenTwoOpFn
*accfn
)
2379 * Two registers and a scalar: perform an operation between
2380 * the input elements and the scalar, and then possibly
2381 * perform an accumulation operation of that result into the
2384 TCGv_i32 scalar
, tmp
;
2387 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2391 /* UNDEF accesses to D16-D31 if they don't exist. */
2392 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2393 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2398 /* Bad size (including size == 3, which is a different insn group) */
2402 if (a
->q
&& ((a
->vd
| a
->vn
) & 1)) {
2406 if (!vfp_access_check(s
)) {
2410 scalar
= neon_get_scalar(a
->size
, a
->vm
);
2411 tmp
= tcg_temp_new_i32();
2413 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
2414 read_neon_element32(tmp
, a
->vn
, pass
, MO_32
);
2415 opfn(tmp
, tmp
, scalar
);
2417 TCGv_i32 rd
= tcg_temp_new_i32();
2418 read_neon_element32(rd
, a
->vd
, pass
, MO_32
);
2419 accfn(tmp
, rd
, tmp
);
2420 tcg_temp_free_i32(rd
);
2422 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
2424 tcg_temp_free_i32(tmp
);
2425 tcg_temp_free_i32(scalar
);
2429 static bool trans_VMUL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2431 static NeonGenTwoOpFn
* const opfn
[] = {
2433 gen_helper_neon_mul_u16
,
2438 return do_2scalar(s
, a
, opfn
[a
->size
], NULL
);
2441 static bool trans_VMLA_2sc(DisasContext
*s
, arg_2scalar
*a
)
2443 static NeonGenTwoOpFn
* const opfn
[] = {
2445 gen_helper_neon_mul_u16
,
2449 static NeonGenTwoOpFn
* const accfn
[] = {
2451 gen_helper_neon_add_u16
,
2456 return do_2scalar(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2459 static bool trans_VMLS_2sc(DisasContext
*s
, arg_2scalar
*a
)
2461 static NeonGenTwoOpFn
* const opfn
[] = {
2463 gen_helper_neon_mul_u16
,
2467 static NeonGenTwoOpFn
* const accfn
[] = {
2469 gen_helper_neon_sub_u16
,
2474 return do_2scalar(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2477 static bool do_2scalar_fp_vec(DisasContext
*s
, arg_2scalar
*a
,
2478 gen_helper_gvec_3_ptr
*fn
)
2480 /* Two registers and a scalar, using gvec */
2481 int vec_size
= a
->q
? 16 : 8;
2482 int rd_ofs
= neon_full_reg_offset(a
->vd
);
2483 int rn_ofs
= neon_full_reg_offset(a
->vn
);
2488 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2492 /* UNDEF accesses to D16-D31 if they don't exist. */
2493 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2494 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2499 /* Bad size (including size == 3, which is a different insn group) */
2503 if (a
->q
&& ((a
->vd
| a
->vn
) & 1)) {
2507 if (!vfp_access_check(s
)) {
2511 /* a->vm is M:Vm, which encodes both register and index */
2512 idx
= extract32(a
->vm
, a
->size
+ 2, 2);
2513 a
->vm
= extract32(a
->vm
, 0, a
->size
+ 2);
2514 rm_ofs
= neon_full_reg_offset(a
->vm
);
2516 fpstatus
= fpstatus_ptr(a
->size
== 1 ? FPST_STD_F16
: FPST_STD
);
2517 tcg_gen_gvec_3_ptr(rd_ofs
, rn_ofs
, rm_ofs
, fpstatus
,
2518 vec_size
, vec_size
, idx
, fn
);
2519 tcg_temp_free_ptr(fpstatus
);
2523 #define DO_VMUL_F_2sc(NAME, FUNC) \
2524 static bool trans_##NAME##_F_2sc(DisasContext *s, arg_2scalar *a) \
2526 static gen_helper_gvec_3_ptr * const opfn[] = { \
2528 gen_helper_##FUNC##_h, \
2529 gen_helper_##FUNC##_s, \
2532 if (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s)) { \
2535 return do_2scalar_fp_vec(s, a, opfn[a->size]); \
2538 DO_VMUL_F_2sc(VMUL
, gvec_fmul_idx
)
2539 DO_VMUL_F_2sc(VMLA
, gvec_fmla_nf_idx
)
2540 DO_VMUL_F_2sc(VMLS
, gvec_fmls_nf_idx
)
2542 WRAP_ENV_FN(gen_VQDMULH_16
, gen_helper_neon_qdmulh_s16
)
2543 WRAP_ENV_FN(gen_VQDMULH_32
, gen_helper_neon_qdmulh_s32
)
2544 WRAP_ENV_FN(gen_VQRDMULH_16
, gen_helper_neon_qrdmulh_s16
)
2545 WRAP_ENV_FN(gen_VQRDMULH_32
, gen_helper_neon_qrdmulh_s32
)
2547 static bool trans_VQDMULH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2549 static NeonGenTwoOpFn
* const opfn
[] = {
2556 return do_2scalar(s
, a
, opfn
[a
->size
], NULL
);
2559 static bool trans_VQRDMULH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2561 static NeonGenTwoOpFn
* const opfn
[] = {
2568 return do_2scalar(s
, a
, opfn
[a
->size
], NULL
);
2571 static bool do_vqrdmlah_2sc(DisasContext
*s
, arg_2scalar
*a
,
2572 NeonGenThreeOpEnvFn
*opfn
)
2575 * VQRDMLAH/VQRDMLSH: this is like do_2scalar, but the opfn
2576 * performs a kind of fused op-then-accumulate using a helper
2577 * function that takes all of rd, rn and the scalar at once.
2579 TCGv_i32 scalar
, rn
, rd
;
2582 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2586 if (!dc_isar_feature(aa32_rdm
, s
)) {
2590 /* UNDEF accesses to D16-D31 if they don't exist. */
2591 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2592 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2597 /* Bad size (including size == 3, which is a different insn group) */
2601 if (a
->q
&& ((a
->vd
| a
->vn
) & 1)) {
2605 if (!vfp_access_check(s
)) {
2609 scalar
= neon_get_scalar(a
->size
, a
->vm
);
2610 rn
= tcg_temp_new_i32();
2611 rd
= tcg_temp_new_i32();
2613 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
2614 read_neon_element32(rn
, a
->vn
, pass
, MO_32
);
2615 read_neon_element32(rd
, a
->vd
, pass
, MO_32
);
2616 opfn(rd
, cpu_env
, rn
, scalar
, rd
);
2617 write_neon_element32(rd
, a
->vd
, pass
, MO_32
);
2619 tcg_temp_free_i32(rn
);
2620 tcg_temp_free_i32(rd
);
2621 tcg_temp_free_i32(scalar
);
2626 static bool trans_VQRDMLAH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2628 static NeonGenThreeOpEnvFn
*opfn
[] = {
2630 gen_helper_neon_qrdmlah_s16
,
2631 gen_helper_neon_qrdmlah_s32
,
2634 return do_vqrdmlah_2sc(s
, a
, opfn
[a
->size
]);
2637 static bool trans_VQRDMLSH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2639 static NeonGenThreeOpEnvFn
*opfn
[] = {
2641 gen_helper_neon_qrdmlsh_s16
,
2642 gen_helper_neon_qrdmlsh_s32
,
2645 return do_vqrdmlah_2sc(s
, a
, opfn
[a
->size
]);
2648 static bool do_2scalar_long(DisasContext
*s
, arg_2scalar
*a
,
2649 NeonGenTwoOpWidenFn
*opfn
,
2650 NeonGenTwo64OpFn
*accfn
)
2653 * Two registers and a scalar, long operations: perform an
2654 * operation on the input elements and the scalar which produces
2655 * a double-width result, and then possibly perform an accumulation
2656 * operation of that result into the destination.
2658 TCGv_i32 scalar
, rn
;
2659 TCGv_i64 rn0_64
, rn1_64
;
2661 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2665 /* UNDEF accesses to D16-D31 if they don't exist. */
2666 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2667 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2672 /* Bad size (including size == 3, which is a different insn group) */
2680 if (!vfp_access_check(s
)) {
2684 scalar
= neon_get_scalar(a
->size
, a
->vm
);
2686 /* Load all inputs before writing any outputs, in case of overlap */
2687 rn
= tcg_temp_new_i32();
2688 read_neon_element32(rn
, a
->vn
, 0, MO_32
);
2689 rn0_64
= tcg_temp_new_i64();
2690 opfn(rn0_64
, rn
, scalar
);
2692 read_neon_element32(rn
, a
->vn
, 1, MO_32
);
2693 rn1_64
= tcg_temp_new_i64();
2694 opfn(rn1_64
, rn
, scalar
);
2695 tcg_temp_free_i32(rn
);
2696 tcg_temp_free_i32(scalar
);
2699 TCGv_i64 t64
= tcg_temp_new_i64();
2700 read_neon_element64(t64
, a
->vd
, 0, MO_64
);
2701 accfn(rn0_64
, t64
, rn0_64
);
2702 read_neon_element64(t64
, a
->vd
, 1, MO_64
);
2703 accfn(rn1_64
, t64
, rn1_64
);
2704 tcg_temp_free_i64(t64
);
2707 write_neon_element64(rn0_64
, a
->vd
, 0, MO_64
);
2708 write_neon_element64(rn1_64
, a
->vd
, 1, MO_64
);
2709 tcg_temp_free_i64(rn0_64
);
2710 tcg_temp_free_i64(rn1_64
);
2714 static bool trans_VMULL_S_2sc(DisasContext
*s
, arg_2scalar
*a
)
2716 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2718 gen_helper_neon_mull_s16
,
2723 return do_2scalar_long(s
, a
, opfn
[a
->size
], NULL
);
2726 static bool trans_VMULL_U_2sc(DisasContext
*s
, arg_2scalar
*a
)
2728 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2730 gen_helper_neon_mull_u16
,
2735 return do_2scalar_long(s
, a
, opfn
[a
->size
], NULL
);
2738 #define DO_VMLAL_2SC(INSN, MULL, ACC) \
2739 static bool trans_##INSN##_2sc(DisasContext *s, arg_2scalar *a) \
2741 static NeonGenTwoOpWidenFn * const opfn[] = { \
2743 gen_helper_neon_##MULL##16, \
2747 static NeonGenTwo64OpFn * const accfn[] = { \
2749 gen_helper_neon_##ACC##l_u32, \
2750 tcg_gen_##ACC##_i64, \
2753 return do_2scalar_long(s, a, opfn[a->size], accfn[a->size]); \
2756 DO_VMLAL_2SC(VMLAL_S
, mull_s
, add
)
2757 DO_VMLAL_2SC(VMLAL_U
, mull_u
, add
)
2758 DO_VMLAL_2SC(VMLSL_S
, mull_s
, sub
)
2759 DO_VMLAL_2SC(VMLSL_U
, mull_u
, sub
)
2761 static bool trans_VQDMULL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2763 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2770 return do_2scalar_long(s
, a
, opfn
[a
->size
], NULL
);
2773 static bool trans_VQDMLAL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2775 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2781 static NeonGenTwo64OpFn
* const accfn
[] = {
2788 return do_2scalar_long(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2791 static bool trans_VQDMLSL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2793 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2799 static NeonGenTwo64OpFn
* const accfn
[] = {
2806 return do_2scalar_long(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2809 static bool trans_VEXT(DisasContext
*s
, arg_VEXT
*a
)
2811 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2815 /* UNDEF accesses to D16-D31 if they don't exist. */
2816 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2817 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2821 if ((a
->vn
| a
->vm
| a
->vd
) & a
->q
) {
2825 if (a
->imm
> 7 && !a
->q
) {
2829 if (!vfp_access_check(s
)) {
2834 /* Extract 64 bits from <Vm:Vn> */
2835 TCGv_i64 left
, right
, dest
;
2837 left
= tcg_temp_new_i64();
2838 right
= tcg_temp_new_i64();
2839 dest
= tcg_temp_new_i64();
2841 read_neon_element64(right
, a
->vn
, 0, MO_64
);
2842 read_neon_element64(left
, a
->vm
, 0, MO_64
);
2843 tcg_gen_extract2_i64(dest
, right
, left
, a
->imm
* 8);
2844 write_neon_element64(dest
, a
->vd
, 0, MO_64
);
2846 tcg_temp_free_i64(left
);
2847 tcg_temp_free_i64(right
);
2848 tcg_temp_free_i64(dest
);
2850 /* Extract 128 bits from <Vm+1:Vm:Vn+1:Vn> */
2851 TCGv_i64 left
, middle
, right
, destleft
, destright
;
2853 left
= tcg_temp_new_i64();
2854 middle
= tcg_temp_new_i64();
2855 right
= tcg_temp_new_i64();
2856 destleft
= tcg_temp_new_i64();
2857 destright
= tcg_temp_new_i64();
2860 read_neon_element64(right
, a
->vn
, 0, MO_64
);
2861 read_neon_element64(middle
, a
->vn
, 1, MO_64
);
2862 tcg_gen_extract2_i64(destright
, right
, middle
, a
->imm
* 8);
2863 read_neon_element64(left
, a
->vm
, 0, MO_64
);
2864 tcg_gen_extract2_i64(destleft
, middle
, left
, a
->imm
* 8);
2866 read_neon_element64(right
, a
->vn
, 1, MO_64
);
2867 read_neon_element64(middle
, a
->vm
, 0, MO_64
);
2868 tcg_gen_extract2_i64(destright
, right
, middle
, (a
->imm
- 8) * 8);
2869 read_neon_element64(left
, a
->vm
, 1, MO_64
);
2870 tcg_gen_extract2_i64(destleft
, middle
, left
, (a
->imm
- 8) * 8);
2873 write_neon_element64(destright
, a
->vd
, 0, MO_64
);
2874 write_neon_element64(destleft
, a
->vd
, 1, MO_64
);
2876 tcg_temp_free_i64(destright
);
2877 tcg_temp_free_i64(destleft
);
2878 tcg_temp_free_i64(right
);
2879 tcg_temp_free_i64(middle
);
2880 tcg_temp_free_i64(left
);
2885 static bool trans_VTBL(DisasContext
*s
, arg_VTBL
*a
)
2890 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2894 /* UNDEF accesses to D16-D31 if they don't exist. */
2895 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2896 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2900 if ((a
->vn
+ a
->len
+ 1) > 32) {
2902 * This is UNPREDICTABLE; we choose to UNDEF to avoid the
2903 * helper function running off the end of the register file.
2908 if (!vfp_access_check(s
)) {
2912 desc
= tcg_constant_i32((a
->vn
<< 2) | a
->len
);
2913 def
= tcg_temp_new_i64();
2915 read_neon_element64(def
, a
->vd
, 0, MO_64
);
2917 tcg_gen_movi_i64(def
, 0);
2919 val
= tcg_temp_new_i64();
2920 read_neon_element64(val
, a
->vm
, 0, MO_64
);
2922 gen_helper_neon_tbl(val
, cpu_env
, desc
, val
, def
);
2923 write_neon_element64(val
, a
->vd
, 0, MO_64
);
2925 tcg_temp_free_i64(def
);
2926 tcg_temp_free_i64(val
);
2930 static bool trans_VDUP_scalar(DisasContext
*s
, arg_VDUP_scalar
*a
)
2932 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2936 /* UNDEF accesses to D16-D31 if they don't exist. */
2937 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2938 ((a
->vd
| a
->vm
) & 0x10)) {
2946 if (!vfp_access_check(s
)) {
2950 tcg_gen_gvec_dup_mem(a
->size
, neon_full_reg_offset(a
->vd
),
2951 neon_element_offset(a
->vm
, a
->index
, a
->size
),
2952 a
->q
? 16 : 8, a
->q
? 16 : 8);
2956 static bool trans_VREV64(DisasContext
*s
, arg_VREV64
*a
)
2961 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2965 /* UNDEF accesses to D16-D31 if they don't exist. */
2966 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2967 ((a
->vd
| a
->vm
) & 0x10)) {
2971 if ((a
->vd
| a
->vm
) & a
->q
) {
2979 if (!vfp_access_check(s
)) {
2983 tmp
[0] = tcg_temp_new_i32();
2984 tmp
[1] = tcg_temp_new_i32();
2986 for (pass
= 0; pass
< (a
->q
? 2 : 1); pass
++) {
2987 for (half
= 0; half
< 2; half
++) {
2988 read_neon_element32(tmp
[half
], a
->vm
, pass
* 2 + half
, MO_32
);
2991 tcg_gen_bswap32_i32(tmp
[half
], tmp
[half
]);
2994 gen_swap_half(tmp
[half
], tmp
[half
]);
2999 g_assert_not_reached();
3002 write_neon_element32(tmp
[1], a
->vd
, pass
* 2, MO_32
);
3003 write_neon_element32(tmp
[0], a
->vd
, pass
* 2 + 1, MO_32
);
3006 tcg_temp_free_i32(tmp
[0]);
3007 tcg_temp_free_i32(tmp
[1]);
3011 static bool do_2misc_pairwise(DisasContext
*s
, arg_2misc
*a
,
3012 NeonGenWidenFn
*widenfn
,
3013 NeonGenTwo64OpFn
*opfn
,
3014 NeonGenTwo64OpFn
*accfn
)
3017 * Pairwise long operations: widen both halves of the pair,
3018 * combine the pairs with the opfn, and then possibly accumulate
3019 * into the destination with the accfn.
3023 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3027 /* UNDEF accesses to D16-D31 if they don't exist. */
3028 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3029 ((a
->vd
| a
->vm
) & 0x10)) {
3033 if ((a
->vd
| a
->vm
) & a
->q
) {
3041 if (!vfp_access_check(s
)) {
3045 for (pass
= 0; pass
< a
->q
+ 1; pass
++) {
3047 TCGv_i64 rm0_64
, rm1_64
, rd_64
;
3049 rm0_64
= tcg_temp_new_i64();
3050 rm1_64
= tcg_temp_new_i64();
3051 rd_64
= tcg_temp_new_i64();
3053 tmp
= tcg_temp_new_i32();
3054 read_neon_element32(tmp
, a
->vm
, pass
* 2, MO_32
);
3055 widenfn(rm0_64
, tmp
);
3056 read_neon_element32(tmp
, a
->vm
, pass
* 2 + 1, MO_32
);
3057 widenfn(rm1_64
, tmp
);
3058 tcg_temp_free_i32(tmp
);
3060 opfn(rd_64
, rm0_64
, rm1_64
);
3061 tcg_temp_free_i64(rm0_64
);
3062 tcg_temp_free_i64(rm1_64
);
3065 TCGv_i64 tmp64
= tcg_temp_new_i64();
3066 read_neon_element64(tmp64
, a
->vd
, pass
, MO_64
);
3067 accfn(rd_64
, tmp64
, rd_64
);
3068 tcg_temp_free_i64(tmp64
);
3070 write_neon_element64(rd_64
, a
->vd
, pass
, MO_64
);
3071 tcg_temp_free_i64(rd_64
);
3076 static bool trans_VPADDL_S(DisasContext
*s
, arg_2misc
*a
)
3078 static NeonGenWidenFn
* const widenfn
[] = {
3079 gen_helper_neon_widen_s8
,
3080 gen_helper_neon_widen_s16
,
3081 tcg_gen_ext_i32_i64
,
3084 static NeonGenTwo64OpFn
* const opfn
[] = {
3085 gen_helper_neon_paddl_u16
,
3086 gen_helper_neon_paddl_u32
,
3091 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
], NULL
);
3094 static bool trans_VPADDL_U(DisasContext
*s
, arg_2misc
*a
)
3096 static NeonGenWidenFn
* const widenfn
[] = {
3097 gen_helper_neon_widen_u8
,
3098 gen_helper_neon_widen_u16
,
3099 tcg_gen_extu_i32_i64
,
3102 static NeonGenTwo64OpFn
* const opfn
[] = {
3103 gen_helper_neon_paddl_u16
,
3104 gen_helper_neon_paddl_u32
,
3109 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
], NULL
);
3112 static bool trans_VPADAL_S(DisasContext
*s
, arg_2misc
*a
)
3114 static NeonGenWidenFn
* const widenfn
[] = {
3115 gen_helper_neon_widen_s8
,
3116 gen_helper_neon_widen_s16
,
3117 tcg_gen_ext_i32_i64
,
3120 static NeonGenTwo64OpFn
* const opfn
[] = {
3121 gen_helper_neon_paddl_u16
,
3122 gen_helper_neon_paddl_u32
,
3126 static NeonGenTwo64OpFn
* const accfn
[] = {
3127 gen_helper_neon_addl_u16
,
3128 gen_helper_neon_addl_u32
,
3133 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
],
3137 static bool trans_VPADAL_U(DisasContext
*s
, arg_2misc
*a
)
3139 static NeonGenWidenFn
* const widenfn
[] = {
3140 gen_helper_neon_widen_u8
,
3141 gen_helper_neon_widen_u16
,
3142 tcg_gen_extu_i32_i64
,
3145 static NeonGenTwo64OpFn
* const opfn
[] = {
3146 gen_helper_neon_paddl_u16
,
3147 gen_helper_neon_paddl_u32
,
3151 static NeonGenTwo64OpFn
* const accfn
[] = {
3152 gen_helper_neon_addl_u16
,
3153 gen_helper_neon_addl_u32
,
3158 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
],
3162 typedef void ZipFn(TCGv_ptr
, TCGv_ptr
);
3164 static bool do_zip_uzp(DisasContext
*s
, arg_2misc
*a
,
3169 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3173 /* UNDEF accesses to D16-D31 if they don't exist. */
3174 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3175 ((a
->vd
| a
->vm
) & 0x10)) {
3179 if ((a
->vd
| a
->vm
) & a
->q
) {
3184 /* Bad size or size/q combination */
3188 if (!vfp_access_check(s
)) {
3192 pd
= vfp_reg_ptr(true, a
->vd
);
3193 pm
= vfp_reg_ptr(true, a
->vm
);
3195 tcg_temp_free_ptr(pd
);
3196 tcg_temp_free_ptr(pm
);
3200 static bool trans_VUZP(DisasContext
*s
, arg_2misc
*a
)
3202 static ZipFn
* const fn
[2][4] = {
3204 gen_helper_neon_unzip8
,
3205 gen_helper_neon_unzip16
,
3209 gen_helper_neon_qunzip8
,
3210 gen_helper_neon_qunzip16
,
3211 gen_helper_neon_qunzip32
,
3215 return do_zip_uzp(s
, a
, fn
[a
->q
][a
->size
]);
3218 static bool trans_VZIP(DisasContext
*s
, arg_2misc
*a
)
3220 static ZipFn
* const fn
[2][4] = {
3222 gen_helper_neon_zip8
,
3223 gen_helper_neon_zip16
,
3227 gen_helper_neon_qzip8
,
3228 gen_helper_neon_qzip16
,
3229 gen_helper_neon_qzip32
,
3233 return do_zip_uzp(s
, a
, fn
[a
->q
][a
->size
]);
3236 static bool do_vmovn(DisasContext
*s
, arg_2misc
*a
,
3237 NeonGenNarrowEnvFn
*narrowfn
)
3242 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3246 /* UNDEF accesses to D16-D31 if they don't exist. */
3247 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3248 ((a
->vd
| a
->vm
) & 0x10)) {
3260 if (!vfp_access_check(s
)) {
3264 rm
= tcg_temp_new_i64();
3265 rd0
= tcg_temp_new_i32();
3266 rd1
= tcg_temp_new_i32();
3268 read_neon_element64(rm
, a
->vm
, 0, MO_64
);
3269 narrowfn(rd0
, cpu_env
, rm
);
3270 read_neon_element64(rm
, a
->vm
, 1, MO_64
);
3271 narrowfn(rd1
, cpu_env
, rm
);
3272 write_neon_element32(rd0
, a
->vd
, 0, MO_32
);
3273 write_neon_element32(rd1
, a
->vd
, 1, MO_32
);
3274 tcg_temp_free_i32(rd0
);
3275 tcg_temp_free_i32(rd1
);
3276 tcg_temp_free_i64(rm
);
3280 #define DO_VMOVN(INSN, FUNC) \
3281 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3283 static NeonGenNarrowEnvFn * const narrowfn[] = { \
3289 return do_vmovn(s, a, narrowfn[a->size]); \
3292 DO_VMOVN(VMOVN
, gen_neon_narrow_u
)
3293 DO_VMOVN(VQMOVUN
, gen_helper_neon_unarrow_sat
)
3294 DO_VMOVN(VQMOVN_S
, gen_helper_neon_narrow_sat_s
)
3295 DO_VMOVN(VQMOVN_U
, gen_helper_neon_narrow_sat_u
)
3297 static bool trans_VSHLL(DisasContext
*s
, arg_2misc
*a
)
3301 static NeonGenWidenFn
* const widenfns
[] = {
3302 gen_helper_neon_widen_u8
,
3303 gen_helper_neon_widen_u16
,
3304 tcg_gen_extu_i32_i64
,
3307 NeonGenWidenFn
*widenfn
= widenfns
[a
->size
];
3309 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3313 /* UNDEF accesses to D16-D31 if they don't exist. */
3314 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3315 ((a
->vd
| a
->vm
) & 0x10)) {
3327 if (!vfp_access_check(s
)) {
3331 rd
= tcg_temp_new_i64();
3332 rm0
= tcg_temp_new_i32();
3333 rm1
= tcg_temp_new_i32();
3335 read_neon_element32(rm0
, a
->vm
, 0, MO_32
);
3336 read_neon_element32(rm1
, a
->vm
, 1, MO_32
);
3339 tcg_gen_shli_i64(rd
, rd
, 8 << a
->size
);
3340 write_neon_element64(rd
, a
->vd
, 0, MO_64
);
3342 tcg_gen_shli_i64(rd
, rd
, 8 << a
->size
);
3343 write_neon_element64(rd
, a
->vd
, 1, MO_64
);
3345 tcg_temp_free_i64(rd
);
3346 tcg_temp_free_i32(rm0
);
3347 tcg_temp_free_i32(rm1
);
3351 static bool trans_VCVT_B16_F32(DisasContext
*s
, arg_2misc
*a
)
3355 TCGv_i32 dst0
, dst1
;
3357 if (!dc_isar_feature(aa32_bf16
, s
)) {
3361 /* UNDEF accesses to D16-D31 if they don't exist. */
3362 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3363 ((a
->vd
| a
->vm
) & 0x10)) {
3367 if ((a
->vm
& 1) || (a
->size
!= 1)) {
3371 if (!vfp_access_check(s
)) {
3375 fpst
= fpstatus_ptr(FPST_STD
);
3376 tmp
= tcg_temp_new_i64();
3377 dst0
= tcg_temp_new_i32();
3378 dst1
= tcg_temp_new_i32();
3380 read_neon_element64(tmp
, a
->vm
, 0, MO_64
);
3381 gen_helper_bfcvt_pair(dst0
, tmp
, fpst
);
3383 read_neon_element64(tmp
, a
->vm
, 1, MO_64
);
3384 gen_helper_bfcvt_pair(dst1
, tmp
, fpst
);
3386 write_neon_element32(dst0
, a
->vd
, 0, MO_32
);
3387 write_neon_element32(dst1
, a
->vd
, 1, MO_32
);
3389 tcg_temp_free_i64(tmp
);
3390 tcg_temp_free_i32(dst0
);
3391 tcg_temp_free_i32(dst1
);
3392 tcg_temp_free_ptr(fpst
);
3396 static bool trans_VCVT_F16_F32(DisasContext
*s
, arg_2misc
*a
)
3399 TCGv_i32 ahp
, tmp
, tmp2
, tmp3
;
3401 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
) ||
3402 !dc_isar_feature(aa32_fp16_spconv
, s
)) {
3406 /* UNDEF accesses to D16-D31 if they don't exist. */
3407 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3408 ((a
->vd
| a
->vm
) & 0x10)) {
3412 if ((a
->vm
& 1) || (a
->size
!= 1)) {
3416 if (!vfp_access_check(s
)) {
3420 fpst
= fpstatus_ptr(FPST_STD
);
3421 ahp
= get_ahp_flag();
3422 tmp
= tcg_temp_new_i32();
3423 read_neon_element32(tmp
, a
->vm
, 0, MO_32
);
3424 gen_helper_vfp_fcvt_f32_to_f16(tmp
, tmp
, fpst
, ahp
);
3425 tmp2
= tcg_temp_new_i32();
3426 read_neon_element32(tmp2
, a
->vm
, 1, MO_32
);
3427 gen_helper_vfp_fcvt_f32_to_f16(tmp2
, tmp2
, fpst
, ahp
);
3428 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
3429 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
3430 read_neon_element32(tmp
, a
->vm
, 2, MO_32
);
3431 gen_helper_vfp_fcvt_f32_to_f16(tmp
, tmp
, fpst
, ahp
);
3432 tmp3
= tcg_temp_new_i32();
3433 read_neon_element32(tmp3
, a
->vm
, 3, MO_32
);
3434 write_neon_element32(tmp2
, a
->vd
, 0, MO_32
);
3435 tcg_temp_free_i32(tmp2
);
3436 gen_helper_vfp_fcvt_f32_to_f16(tmp3
, tmp3
, fpst
, ahp
);
3437 tcg_gen_shli_i32(tmp3
, tmp3
, 16);
3438 tcg_gen_or_i32(tmp3
, tmp3
, tmp
);
3439 write_neon_element32(tmp3
, a
->vd
, 1, MO_32
);
3440 tcg_temp_free_i32(tmp3
);
3441 tcg_temp_free_i32(tmp
);
3442 tcg_temp_free_i32(ahp
);
3443 tcg_temp_free_ptr(fpst
);
3448 static bool trans_VCVT_F32_F16(DisasContext
*s
, arg_2misc
*a
)
3451 TCGv_i32 ahp
, tmp
, tmp2
, tmp3
;
3453 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
) ||
3454 !dc_isar_feature(aa32_fp16_spconv
, s
)) {
3458 /* UNDEF accesses to D16-D31 if they don't exist. */
3459 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3460 ((a
->vd
| a
->vm
) & 0x10)) {
3464 if ((a
->vd
& 1) || (a
->size
!= 1)) {
3468 if (!vfp_access_check(s
)) {
3472 fpst
= fpstatus_ptr(FPST_STD
);
3473 ahp
= get_ahp_flag();
3474 tmp3
= tcg_temp_new_i32();
3475 tmp2
= tcg_temp_new_i32();
3476 tmp
= tcg_temp_new_i32();
3477 read_neon_element32(tmp
, a
->vm
, 0, MO_32
);
3478 read_neon_element32(tmp2
, a
->vm
, 1, MO_32
);
3479 tcg_gen_ext16u_i32(tmp3
, tmp
);
3480 gen_helper_vfp_fcvt_f16_to_f32(tmp3
, tmp3
, fpst
, ahp
);
3481 write_neon_element32(tmp3
, a
->vd
, 0, MO_32
);
3482 tcg_gen_shri_i32(tmp
, tmp
, 16);
3483 gen_helper_vfp_fcvt_f16_to_f32(tmp
, tmp
, fpst
, ahp
);
3484 write_neon_element32(tmp
, a
->vd
, 1, MO_32
);
3485 tcg_temp_free_i32(tmp
);
3486 tcg_gen_ext16u_i32(tmp3
, tmp2
);
3487 gen_helper_vfp_fcvt_f16_to_f32(tmp3
, tmp3
, fpst
, ahp
);
3488 write_neon_element32(tmp3
, a
->vd
, 2, MO_32
);
3489 tcg_temp_free_i32(tmp3
);
3490 tcg_gen_shri_i32(tmp2
, tmp2
, 16);
3491 gen_helper_vfp_fcvt_f16_to_f32(tmp2
, tmp2
, fpst
, ahp
);
3492 write_neon_element32(tmp2
, a
->vd
, 3, MO_32
);
3493 tcg_temp_free_i32(tmp2
);
3494 tcg_temp_free_i32(ahp
);
3495 tcg_temp_free_ptr(fpst
);
3500 static bool do_2misc_vec(DisasContext
*s
, arg_2misc
*a
, GVecGen2Fn
*fn
)
3502 int vec_size
= a
->q
? 16 : 8;
3503 int rd_ofs
= neon_full_reg_offset(a
->vd
);
3504 int rm_ofs
= neon_full_reg_offset(a
->vm
);
3506 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3510 /* UNDEF accesses to D16-D31 if they don't exist. */
3511 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3512 ((a
->vd
| a
->vm
) & 0x10)) {
3520 if ((a
->vd
| a
->vm
) & a
->q
) {
3524 if (!vfp_access_check(s
)) {
3528 fn(a
->size
, rd_ofs
, rm_ofs
, vec_size
, vec_size
);
3533 #define DO_2MISC_VEC(INSN, FN) \
3534 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3536 return do_2misc_vec(s, a, FN); \
3539 DO_2MISC_VEC(VNEG
, tcg_gen_gvec_neg
)
3540 DO_2MISC_VEC(VABS
, tcg_gen_gvec_abs
)
3541 DO_2MISC_VEC(VCEQ0
, gen_gvec_ceq0
)
3542 DO_2MISC_VEC(VCGT0
, gen_gvec_cgt0
)
3543 DO_2MISC_VEC(VCLE0
, gen_gvec_cle0
)
3544 DO_2MISC_VEC(VCGE0
, gen_gvec_cge0
)
3545 DO_2MISC_VEC(VCLT0
, gen_gvec_clt0
)
3547 static bool trans_VMVN(DisasContext
*s
, arg_2misc
*a
)
3552 return do_2misc_vec(s
, a
, tcg_gen_gvec_not
);
3555 #define WRAP_2M_3_OOL_FN(WRAPNAME, FUNC, DATA) \
3556 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \
3557 uint32_t rm_ofs, uint32_t oprsz, \
3560 tcg_gen_gvec_3_ool(rd_ofs, rd_ofs, rm_ofs, oprsz, maxsz, \
3564 #define WRAP_2M_2_OOL_FN(WRAPNAME, FUNC, DATA) \
3565 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \
3566 uint32_t rm_ofs, uint32_t oprsz, \
3569 tcg_gen_gvec_2_ool(rd_ofs, rm_ofs, oprsz, maxsz, DATA, FUNC); \
3572 WRAP_2M_3_OOL_FN(gen_AESE
, gen_helper_crypto_aese
, 0)
3573 WRAP_2M_3_OOL_FN(gen_AESD
, gen_helper_crypto_aese
, 1)
3574 WRAP_2M_2_OOL_FN(gen_AESMC
, gen_helper_crypto_aesmc
, 0)
3575 WRAP_2M_2_OOL_FN(gen_AESIMC
, gen_helper_crypto_aesmc
, 1)
3576 WRAP_2M_2_OOL_FN(gen_SHA1H
, gen_helper_crypto_sha1h
, 0)
3577 WRAP_2M_2_OOL_FN(gen_SHA1SU1
, gen_helper_crypto_sha1su1
, 0)
3578 WRAP_2M_2_OOL_FN(gen_SHA256SU0
, gen_helper_crypto_sha256su0
, 0)
3580 #define DO_2M_CRYPTO(INSN, FEATURE, SIZE) \
3581 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3583 if (!dc_isar_feature(FEATURE, s) || a->size != SIZE) { \
3586 return do_2misc_vec(s, a, gen_##INSN); \
3589 DO_2M_CRYPTO(AESE
, aa32_aes
, 0)
3590 DO_2M_CRYPTO(AESD
, aa32_aes
, 0)
3591 DO_2M_CRYPTO(AESMC
, aa32_aes
, 0)
3592 DO_2M_CRYPTO(AESIMC
, aa32_aes
, 0)
3593 DO_2M_CRYPTO(SHA1H
, aa32_sha1
, 2)
3594 DO_2M_CRYPTO(SHA1SU1
, aa32_sha1
, 2)
3595 DO_2M_CRYPTO(SHA256SU0
, aa32_sha2
, 2)
3597 static bool do_2misc(DisasContext
*s
, arg_2misc
*a
, NeonGenOneOpFn
*fn
)
3602 /* Handle a 2-reg-misc operation by iterating 32 bits at a time */
3603 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3607 /* UNDEF accesses to D16-D31 if they don't exist. */
3608 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3609 ((a
->vd
| a
->vm
) & 0x10)) {
3617 if ((a
->vd
| a
->vm
) & a
->q
) {
3621 if (!vfp_access_check(s
)) {
3625 tmp
= tcg_temp_new_i32();
3626 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
3627 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
3629 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
3631 tcg_temp_free_i32(tmp
);
3636 static bool trans_VREV32(DisasContext
*s
, arg_2misc
*a
)
3638 static NeonGenOneOpFn
* const fn
[] = {
3639 tcg_gen_bswap32_i32
,
3644 return do_2misc(s
, a
, fn
[a
->size
]);
3647 static bool trans_VREV16(DisasContext
*s
, arg_2misc
*a
)
3652 return do_2misc(s
, a
, gen_rev16
);
3655 static bool trans_VCLS(DisasContext
*s
, arg_2misc
*a
)
3657 static NeonGenOneOpFn
* const fn
[] = {
3658 gen_helper_neon_cls_s8
,
3659 gen_helper_neon_cls_s16
,
3660 gen_helper_neon_cls_s32
,
3663 return do_2misc(s
, a
, fn
[a
->size
]);
3666 static void do_VCLZ_32(TCGv_i32 rd
, TCGv_i32 rm
)
3668 tcg_gen_clzi_i32(rd
, rm
, 32);
3671 static bool trans_VCLZ(DisasContext
*s
, arg_2misc
*a
)
3673 static NeonGenOneOpFn
* const fn
[] = {
3674 gen_helper_neon_clz_u8
,
3675 gen_helper_neon_clz_u16
,
3679 return do_2misc(s
, a
, fn
[a
->size
]);
3682 static bool trans_VCNT(DisasContext
*s
, arg_2misc
*a
)
3687 return do_2misc(s
, a
, gen_helper_neon_cnt_u8
);
3690 static void gen_VABS_F(unsigned vece
, uint32_t rd_ofs
, uint32_t rm_ofs
,
3691 uint32_t oprsz
, uint32_t maxsz
)
3693 tcg_gen_gvec_andi(vece
, rd_ofs
, rm_ofs
,
3694 vece
== MO_16
? 0x7fff : 0x7fffffff,
3698 static bool trans_VABS_F(DisasContext
*s
, arg_2misc
*a
)
3700 if (a
->size
== MO_16
) {
3701 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
3704 } else if (a
->size
!= MO_32
) {
3707 return do_2misc_vec(s
, a
, gen_VABS_F
);
3710 static void gen_VNEG_F(unsigned vece
, uint32_t rd_ofs
, uint32_t rm_ofs
,
3711 uint32_t oprsz
, uint32_t maxsz
)
3713 tcg_gen_gvec_xori(vece
, rd_ofs
, rm_ofs
,
3714 vece
== MO_16
? 0x8000 : 0x80000000,
3718 static bool trans_VNEG_F(DisasContext
*s
, arg_2misc
*a
)
3720 if (a
->size
== MO_16
) {
3721 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
3724 } else if (a
->size
!= MO_32
) {
3727 return do_2misc_vec(s
, a
, gen_VNEG_F
);
3730 static bool trans_VRECPE(DisasContext
*s
, arg_2misc
*a
)
3735 return do_2misc(s
, a
, gen_helper_recpe_u32
);
3738 static bool trans_VRSQRTE(DisasContext
*s
, arg_2misc
*a
)
3743 return do_2misc(s
, a
, gen_helper_rsqrte_u32
);
3746 #define WRAP_1OP_ENV_FN(WRAPNAME, FUNC) \
3747 static void WRAPNAME(TCGv_i32 d, TCGv_i32 m) \
3749 FUNC(d, cpu_env, m); \
3752 WRAP_1OP_ENV_FN(gen_VQABS_s8
, gen_helper_neon_qabs_s8
)
3753 WRAP_1OP_ENV_FN(gen_VQABS_s16
, gen_helper_neon_qabs_s16
)
3754 WRAP_1OP_ENV_FN(gen_VQABS_s32
, gen_helper_neon_qabs_s32
)
3755 WRAP_1OP_ENV_FN(gen_VQNEG_s8
, gen_helper_neon_qneg_s8
)
3756 WRAP_1OP_ENV_FN(gen_VQNEG_s16
, gen_helper_neon_qneg_s16
)
3757 WRAP_1OP_ENV_FN(gen_VQNEG_s32
, gen_helper_neon_qneg_s32
)
3759 static bool trans_VQABS(DisasContext
*s
, arg_2misc
*a
)
3761 static NeonGenOneOpFn
* const fn
[] = {
3767 return do_2misc(s
, a
, fn
[a
->size
]);
3770 static bool trans_VQNEG(DisasContext
*s
, arg_2misc
*a
)
3772 static NeonGenOneOpFn
* const fn
[] = {
3778 return do_2misc(s
, a
, fn
[a
->size
]);
3781 #define DO_2MISC_FP_VEC(INSN, HFUNC, SFUNC) \
3782 static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \
3784 uint32_t oprsz, uint32_t maxsz) \
3786 static gen_helper_gvec_2_ptr * const fns[4] = { \
3787 NULL, HFUNC, SFUNC, NULL, \
3790 fpst = fpstatus_ptr(vece == MO_16 ? FPST_STD_F16 : FPST_STD); \
3791 tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz, 0, \
3793 tcg_temp_free_ptr(fpst); \
3795 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3797 if (a->size == MO_16) { \
3798 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
3801 } else if (a->size != MO_32) { \
3804 return do_2misc_vec(s, a, gen_##INSN); \
3807 DO_2MISC_FP_VEC(VRECPE_F
, gen_helper_gvec_frecpe_h
, gen_helper_gvec_frecpe_s
)
3808 DO_2MISC_FP_VEC(VRSQRTE_F
, gen_helper_gvec_frsqrte_h
, gen_helper_gvec_frsqrte_s
)
3809 DO_2MISC_FP_VEC(VCGT0_F
, gen_helper_gvec_fcgt0_h
, gen_helper_gvec_fcgt0_s
)
3810 DO_2MISC_FP_VEC(VCGE0_F
, gen_helper_gvec_fcge0_h
, gen_helper_gvec_fcge0_s
)
3811 DO_2MISC_FP_VEC(VCEQ0_F
, gen_helper_gvec_fceq0_h
, gen_helper_gvec_fceq0_s
)
3812 DO_2MISC_FP_VEC(VCLT0_F
, gen_helper_gvec_fclt0_h
, gen_helper_gvec_fclt0_s
)
3813 DO_2MISC_FP_VEC(VCLE0_F
, gen_helper_gvec_fcle0_h
, gen_helper_gvec_fcle0_s
)
3814 DO_2MISC_FP_VEC(VCVT_FS
, gen_helper_gvec_sstoh
, gen_helper_gvec_sitos
)
3815 DO_2MISC_FP_VEC(VCVT_FU
, gen_helper_gvec_ustoh
, gen_helper_gvec_uitos
)
3816 DO_2MISC_FP_VEC(VCVT_SF
, gen_helper_gvec_tosszh
, gen_helper_gvec_tosizs
)
3817 DO_2MISC_FP_VEC(VCVT_UF
, gen_helper_gvec_touszh
, gen_helper_gvec_touizs
)
3819 DO_2MISC_FP_VEC(VRINTX_impl
, gen_helper_gvec_vrintx_h
, gen_helper_gvec_vrintx_s
)
3821 static bool trans_VRINTX(DisasContext
*s
, arg_2misc
*a
)
3823 if (!arm_dc_feature(s
, ARM_FEATURE_V8
)) {
3826 return trans_VRINTX_impl(s
, a
);
3829 #define DO_VEC_RMODE(INSN, RMODE, OP) \
3830 static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \
3832 uint32_t oprsz, uint32_t maxsz) \
3834 static gen_helper_gvec_2_ptr * const fns[4] = { \
3836 gen_helper_gvec_##OP##h, \
3837 gen_helper_gvec_##OP##s, \
3841 fpst = fpstatus_ptr(vece == 1 ? FPST_STD_F16 : FPST_STD); \
3842 tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz, \
3843 arm_rmode_to_sf(RMODE), fns[vece]); \
3844 tcg_temp_free_ptr(fpst); \
3846 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3848 if (!arm_dc_feature(s, ARM_FEATURE_V8)) { \
3851 if (a->size == MO_16) { \
3852 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
3855 } else if (a->size != MO_32) { \
3858 return do_2misc_vec(s, a, gen_##INSN); \
3861 DO_VEC_RMODE(VCVTAU
, FPROUNDING_TIEAWAY
, vcvt_rm_u
)
3862 DO_VEC_RMODE(VCVTAS
, FPROUNDING_TIEAWAY
, vcvt_rm_s
)
3863 DO_VEC_RMODE(VCVTNU
, FPROUNDING_TIEEVEN
, vcvt_rm_u
)
3864 DO_VEC_RMODE(VCVTNS
, FPROUNDING_TIEEVEN
, vcvt_rm_s
)
3865 DO_VEC_RMODE(VCVTPU
, FPROUNDING_POSINF
, vcvt_rm_u
)
3866 DO_VEC_RMODE(VCVTPS
, FPROUNDING_POSINF
, vcvt_rm_s
)
3867 DO_VEC_RMODE(VCVTMU
, FPROUNDING_NEGINF
, vcvt_rm_u
)
3868 DO_VEC_RMODE(VCVTMS
, FPROUNDING_NEGINF
, vcvt_rm_s
)
3870 DO_VEC_RMODE(VRINTN
, FPROUNDING_TIEEVEN
, vrint_rm_
)
3871 DO_VEC_RMODE(VRINTA
, FPROUNDING_TIEAWAY
, vrint_rm_
)
3872 DO_VEC_RMODE(VRINTZ
, FPROUNDING_ZERO
, vrint_rm_
)
3873 DO_VEC_RMODE(VRINTM
, FPROUNDING_NEGINF
, vrint_rm_
)
3874 DO_VEC_RMODE(VRINTP
, FPROUNDING_POSINF
, vrint_rm_
)
3876 static bool trans_VSWP(DisasContext
*s
, arg_2misc
*a
)
3881 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3885 /* UNDEF accesses to D16-D31 if they don't exist. */
3886 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3887 ((a
->vd
| a
->vm
) & 0x10)) {
3895 if ((a
->vd
| a
->vm
) & a
->q
) {
3899 if (!vfp_access_check(s
)) {
3903 rm
= tcg_temp_new_i64();
3904 rd
= tcg_temp_new_i64();
3905 for (pass
= 0; pass
< (a
->q
? 2 : 1); pass
++) {
3906 read_neon_element64(rm
, a
->vm
, pass
, MO_64
);
3907 read_neon_element64(rd
, a
->vd
, pass
, MO_64
);
3908 write_neon_element64(rm
, a
->vd
, pass
, MO_64
);
3909 write_neon_element64(rd
, a
->vm
, pass
, MO_64
);
3911 tcg_temp_free_i64(rm
);
3912 tcg_temp_free_i64(rd
);
3916 static void gen_neon_trn_u8(TCGv_i32 t0
, TCGv_i32 t1
)
3920 rd
= tcg_temp_new_i32();
3921 tmp
= tcg_temp_new_i32();
3923 tcg_gen_shli_i32(rd
, t0
, 8);
3924 tcg_gen_andi_i32(rd
, rd
, 0xff00ff00);
3925 tcg_gen_andi_i32(tmp
, t1
, 0x00ff00ff);
3926 tcg_gen_or_i32(rd
, rd
, tmp
);
3928 tcg_gen_shri_i32(t1
, t1
, 8);
3929 tcg_gen_andi_i32(t1
, t1
, 0x00ff00ff);
3930 tcg_gen_andi_i32(tmp
, t0
, 0xff00ff00);
3931 tcg_gen_or_i32(t1
, t1
, tmp
);
3932 tcg_gen_mov_i32(t0
, rd
);
3934 tcg_temp_free_i32(tmp
);
3935 tcg_temp_free_i32(rd
);
3938 static void gen_neon_trn_u16(TCGv_i32 t0
, TCGv_i32 t1
)
3942 rd
= tcg_temp_new_i32();
3943 tmp
= tcg_temp_new_i32();
3945 tcg_gen_shli_i32(rd
, t0
, 16);
3946 tcg_gen_andi_i32(tmp
, t1
, 0xffff);
3947 tcg_gen_or_i32(rd
, rd
, tmp
);
3948 tcg_gen_shri_i32(t1
, t1
, 16);
3949 tcg_gen_andi_i32(tmp
, t0
, 0xffff0000);
3950 tcg_gen_or_i32(t1
, t1
, tmp
);
3951 tcg_gen_mov_i32(t0
, rd
);
3953 tcg_temp_free_i32(tmp
);
3954 tcg_temp_free_i32(rd
);
3957 static bool trans_VTRN(DisasContext
*s
, arg_2misc
*a
)
3962 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3966 /* UNDEF accesses to D16-D31 if they don't exist. */
3967 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3968 ((a
->vd
| a
->vm
) & 0x10)) {
3972 if ((a
->vd
| a
->vm
) & a
->q
) {
3980 if (!vfp_access_check(s
)) {
3984 tmp
= tcg_temp_new_i32();
3985 tmp2
= tcg_temp_new_i32();
3986 if (a
->size
== MO_32
) {
3987 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
+= 2) {
3988 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
3989 read_neon_element32(tmp2
, a
->vd
, pass
+ 1, MO_32
);
3990 write_neon_element32(tmp2
, a
->vm
, pass
, MO_32
);
3991 write_neon_element32(tmp
, a
->vd
, pass
+ 1, MO_32
);
3994 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
3995 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
3996 read_neon_element32(tmp2
, a
->vd
, pass
, MO_32
);
3997 if (a
->size
== MO_8
) {
3998 gen_neon_trn_u8(tmp
, tmp2
);
4000 gen_neon_trn_u16(tmp
, tmp2
);
4002 write_neon_element32(tmp2
, a
->vm
, pass
, MO_32
);
4003 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
4006 tcg_temp_free_i32(tmp
);
4007 tcg_temp_free_i32(tmp2
);
4011 static bool trans_VSMMLA(DisasContext
*s
, arg_VSMMLA
*a
)
4013 if (!dc_isar_feature(aa32_i8mm
, s
)) {
4016 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
4017 gen_helper_gvec_smmla_b
);
4020 static bool trans_VUMMLA(DisasContext
*s
, arg_VUMMLA
*a
)
4022 if (!dc_isar_feature(aa32_i8mm
, s
)) {
4025 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
4026 gen_helper_gvec_ummla_b
);
4029 static bool trans_VUSMMLA(DisasContext
*s
, arg_VUSMMLA
*a
)
4031 if (!dc_isar_feature(aa32_i8mm
, s
)) {
4034 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
4035 gen_helper_gvec_usmmla_b
);
4038 static bool trans_VMMLA_b16(DisasContext
*s
, arg_VMMLA_b16
*a
)
4040 if (!dc_isar_feature(aa32_bf16
, s
)) {
4043 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
4044 gen_helper_gvec_bfmmla
);
4047 static bool trans_VFMA_b16(DisasContext
*s
, arg_VFMA_b16
*a
)
4049 if (!dc_isar_feature(aa32_bf16
, s
)) {
4052 return do_neon_ddda_fpst(s
, 7, a
->vd
, a
->vn
, a
->vm
, a
->q
, FPST_STD
,
4053 gen_helper_gvec_bfmlal
);
4056 static bool trans_VFMA_b16_scal(DisasContext
*s
, arg_VFMA_b16_scal
*a
)
4058 if (!dc_isar_feature(aa32_bf16
, s
)) {
4061 return do_neon_ddda_fpst(s
, 6, a
->vd
, a
->vn
, a
->vm
,
4062 (a
->index
<< 1) | a
->q
, FPST_STD
,
4063 gen_helper_gvec_bfmlal_idx
);