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 "translate.h"
28 #include "translate-a32.h"
30 /* Include the generated Neon decoder */
31 #include "decode-neon-dp.c.inc"
32 #include "decode-neon-ls.c.inc"
33 #include "decode-neon-shared.c.inc"
35 static TCGv_ptr
vfp_reg_ptr(bool dp
, int reg
)
37 TCGv_ptr ret
= tcg_temp_new_ptr();
38 tcg_gen_addi_ptr(ret
, cpu_env
, vfp_reg_offset(dp
, reg
));
42 static void neon_load_element(TCGv_i32 var
, int reg
, int ele
, MemOp mop
)
44 long offset
= neon_element_offset(reg
, ele
, mop
& MO_SIZE
);
48 tcg_gen_ld8u_i32(var
, cpu_env
, offset
);
51 tcg_gen_ld16u_i32(var
, cpu_env
, offset
);
54 tcg_gen_ld_i32(var
, cpu_env
, offset
);
57 g_assert_not_reached();
61 static void neon_load_element64(TCGv_i64 var
, int reg
, int ele
, MemOp mop
)
63 long offset
= neon_element_offset(reg
, ele
, mop
& MO_SIZE
);
67 tcg_gen_ld8u_i64(var
, cpu_env
, offset
);
70 tcg_gen_ld16u_i64(var
, cpu_env
, offset
);
73 tcg_gen_ld32u_i64(var
, cpu_env
, offset
);
76 tcg_gen_ld_i64(var
, cpu_env
, offset
);
79 g_assert_not_reached();
83 static void neon_store_element(int reg
, int ele
, MemOp size
, TCGv_i32 var
)
85 long offset
= neon_element_offset(reg
, ele
, size
);
89 tcg_gen_st8_i32(var
, cpu_env
, offset
);
92 tcg_gen_st16_i32(var
, cpu_env
, offset
);
95 tcg_gen_st_i32(var
, cpu_env
, offset
);
98 g_assert_not_reached();
102 static void neon_store_element64(int reg
, int ele
, MemOp size
, TCGv_i64 var
)
104 long offset
= neon_element_offset(reg
, ele
, size
);
108 tcg_gen_st8_i64(var
, cpu_env
, offset
);
111 tcg_gen_st16_i64(var
, cpu_env
, offset
);
114 tcg_gen_st32_i64(var
, cpu_env
, offset
);
117 tcg_gen_st_i64(var
, cpu_env
, offset
);
120 g_assert_not_reached();
124 static bool do_neon_ddda(DisasContext
*s
, int q
, int vd
, int vn
, int vm
,
125 int data
, gen_helper_gvec_4
*fn_gvec
)
127 /* UNDEF accesses to D16-D31 if they don't exist. */
128 if (((vd
| vn
| vm
) & 0x10) && !dc_isar_feature(aa32_simd_r32
, s
)) {
133 * UNDEF accesses to odd registers for each bit of Q.
134 * Q will be 0b111 for all Q-reg instructions, otherwise
135 * when we have mixed Q- and D-reg inputs.
137 if (((vd
& 1) * 4 | (vn
& 1) * 2 | (vm
& 1)) & q
) {
141 if (!vfp_access_check(s
)) {
145 int opr_sz
= q
? 16 : 8;
146 tcg_gen_gvec_4_ool(vfp_reg_offset(1, vd
),
147 vfp_reg_offset(1, vn
),
148 vfp_reg_offset(1, vm
),
149 vfp_reg_offset(1, vd
),
150 opr_sz
, opr_sz
, data
, fn_gvec
);
154 static bool do_neon_ddda_fpst(DisasContext
*s
, int q
, int vd
, int vn
, int vm
,
155 int data
, ARMFPStatusFlavour fp_flavour
,
156 gen_helper_gvec_4_ptr
*fn_gvec_ptr
)
158 /* UNDEF accesses to D16-D31 if they don't exist. */
159 if (((vd
| vn
| vm
) & 0x10) && !dc_isar_feature(aa32_simd_r32
, s
)) {
164 * UNDEF accesses to odd registers for each bit of Q.
165 * Q will be 0b111 for all Q-reg instructions, otherwise
166 * when we have mixed Q- and D-reg inputs.
168 if (((vd
& 1) * 4 | (vn
& 1) * 2 | (vm
& 1)) & q
) {
172 if (!vfp_access_check(s
)) {
176 int opr_sz
= q
? 16 : 8;
177 TCGv_ptr fpst
= fpstatus_ptr(fp_flavour
);
179 tcg_gen_gvec_4_ptr(vfp_reg_offset(1, vd
),
180 vfp_reg_offset(1, vn
),
181 vfp_reg_offset(1, vm
),
182 vfp_reg_offset(1, vd
),
183 fpst
, opr_sz
, opr_sz
, data
, fn_gvec_ptr
);
187 static bool trans_VCMLA(DisasContext
*s
, arg_VCMLA
*a
)
189 if (!dc_isar_feature(aa32_vcma
, s
)) {
192 if (a
->size
== MO_16
) {
193 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
196 return do_neon_ddda_fpst(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, a
->rot
,
197 FPST_STD_F16
, gen_helper_gvec_fcmlah
);
199 return do_neon_ddda_fpst(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, a
->rot
,
200 FPST_STD
, gen_helper_gvec_fcmlas
);
203 static bool trans_VCADD(DisasContext
*s
, arg_VCADD
*a
)
207 gen_helper_gvec_3_ptr
*fn_gvec_ptr
;
209 if (!dc_isar_feature(aa32_vcma
, s
)
210 || (a
->size
== MO_16
&& !dc_isar_feature(aa32_fp16_arith
, s
))) {
214 /* UNDEF accesses to D16-D31 if they don't exist. */
215 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
216 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
220 if ((a
->vn
| a
->vm
| a
->vd
) & a
->q
) {
224 if (!vfp_access_check(s
)) {
228 opr_sz
= (1 + a
->q
) * 8;
229 fpst
= fpstatus_ptr(a
->size
== MO_16
? FPST_STD_F16
: FPST_STD
);
230 fn_gvec_ptr
= (a
->size
== MO_16
) ?
231 gen_helper_gvec_fcaddh
: gen_helper_gvec_fcadds
;
232 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
233 vfp_reg_offset(1, a
->vn
),
234 vfp_reg_offset(1, a
->vm
),
235 fpst
, opr_sz
, opr_sz
, a
->rot
,
240 static bool trans_VSDOT(DisasContext
*s
, arg_VSDOT
*a
)
242 if (!dc_isar_feature(aa32_dp
, s
)) {
245 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
246 gen_helper_gvec_sdot_b
);
249 static bool trans_VUDOT(DisasContext
*s
, arg_VUDOT
*a
)
251 if (!dc_isar_feature(aa32_dp
, s
)) {
254 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
255 gen_helper_gvec_udot_b
);
258 static bool trans_VUSDOT(DisasContext
*s
, arg_VUSDOT
*a
)
260 if (!dc_isar_feature(aa32_i8mm
, s
)) {
263 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
264 gen_helper_gvec_usdot_b
);
267 static bool trans_VDOT_b16(DisasContext
*s
, arg_VDOT_b16
*a
)
269 if (!dc_isar_feature(aa32_bf16
, s
)) {
272 return do_neon_ddda(s
, a
->q
* 7, a
->vd
, a
->vn
, a
->vm
, 0,
273 gen_helper_gvec_bfdot
);
276 static bool trans_VFML(DisasContext
*s
, arg_VFML
*a
)
280 if (!dc_isar_feature(aa32_fhm
, s
)) {
284 /* UNDEF accesses to D16-D31 if they don't exist. */
285 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
294 if (!vfp_access_check(s
)) {
298 opr_sz
= (1 + a
->q
) * 8;
299 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
300 vfp_reg_offset(a
->q
, a
->vn
),
301 vfp_reg_offset(a
->q
, a
->vm
),
302 cpu_env
, opr_sz
, opr_sz
, a
->s
, /* is_2 == 0 */
303 gen_helper_gvec_fmlal_a32
);
307 static bool trans_VCMLA_scalar(DisasContext
*s
, arg_VCMLA_scalar
*a
)
309 int data
= (a
->index
<< 2) | a
->rot
;
311 if (!dc_isar_feature(aa32_vcma
, s
)) {
314 if (a
->size
== MO_16
) {
315 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
318 return do_neon_ddda_fpst(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, data
,
319 FPST_STD_F16
, gen_helper_gvec_fcmlah_idx
);
321 return do_neon_ddda_fpst(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, data
,
322 FPST_STD
, gen_helper_gvec_fcmlas_idx
);
325 static bool trans_VSDOT_scalar(DisasContext
*s
, arg_VSDOT_scalar
*a
)
327 if (!dc_isar_feature(aa32_dp
, s
)) {
330 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
331 gen_helper_gvec_sdot_idx_b
);
334 static bool trans_VUDOT_scalar(DisasContext
*s
, arg_VUDOT_scalar
*a
)
336 if (!dc_isar_feature(aa32_dp
, s
)) {
339 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
340 gen_helper_gvec_udot_idx_b
);
343 static bool trans_VUSDOT_scalar(DisasContext
*s
, arg_VUSDOT_scalar
*a
)
345 if (!dc_isar_feature(aa32_i8mm
, s
)) {
348 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
349 gen_helper_gvec_usdot_idx_b
);
352 static bool trans_VSUDOT_scalar(DisasContext
*s
, arg_VSUDOT_scalar
*a
)
354 if (!dc_isar_feature(aa32_i8mm
, s
)) {
357 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
358 gen_helper_gvec_sudot_idx_b
);
361 static bool trans_VDOT_b16_scal(DisasContext
*s
, arg_VDOT_b16_scal
*a
)
363 if (!dc_isar_feature(aa32_bf16
, s
)) {
366 return do_neon_ddda(s
, a
->q
* 6, a
->vd
, a
->vn
, a
->vm
, a
->index
,
367 gen_helper_gvec_bfdot_idx
);
370 static bool trans_VFML_scalar(DisasContext
*s
, arg_VFML_scalar
*a
)
374 if (!dc_isar_feature(aa32_fhm
, s
)) {
378 /* UNDEF accesses to D16-D31 if they don't exist. */
379 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
380 ((a
->vd
& 0x10) || (a
->q
&& (a
->vn
& 0x10)))) {
388 if (!vfp_access_check(s
)) {
392 opr_sz
= (1 + a
->q
) * 8;
393 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
394 vfp_reg_offset(a
->q
, a
->vn
),
395 vfp_reg_offset(a
->q
, a
->rm
),
396 cpu_env
, opr_sz
, opr_sz
,
397 (a
->index
<< 2) | a
->s
, /* is_2 == 0 */
398 gen_helper_gvec_fmlal_idx_a32
);
406 } const neon_ls_element_type
[11] = {
420 static void gen_neon_ldst_base_update(DisasContext
*s
, int rm
, int rn
,
426 base
= load_reg(s
, rn
);
428 tcg_gen_addi_i32(base
, base
, stride
);
431 index
= load_reg(s
, rm
);
432 tcg_gen_add_i32(base
, base
, index
);
434 store_reg(s
, rn
, base
);
438 static bool trans_VLDST_multiple(DisasContext
*s
, arg_VLDST_multiple
*a
)
440 /* Neon load/store multiple structures */
441 int nregs
, interleave
, spacing
, reg
, n
;
442 MemOp mop
, align
, endian
;
443 int mmu_idx
= get_mem_index(s
);
448 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
452 /* UNDEF accesses to D16-D31 if they don't exist */
453 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
459 /* Catch UNDEF cases for bad values of align field */
460 switch (a
->itype
& 0xc) {
474 nregs
= neon_ls_element_type
[a
->itype
].nregs
;
475 interleave
= neon_ls_element_type
[a
->itype
].interleave
;
476 spacing
= neon_ls_element_type
[a
->itype
].spacing
;
477 if (size
== 3 && (interleave
| spacing
) != 1) {
481 if (!vfp_access_check(s
)) {
485 /* For our purposes, bytes are always little-endian. */
491 /* Enforce alignment requested by the instruction */
493 align
= pow2_align(a
->align
+ 2); /* 4 ** a->align */
495 align
= s
->align_mem
? MO_ALIGN
: 0;
499 * Consecutive little-endian elements from a single register
500 * can be promoted to a larger little-endian operation.
502 if (interleave
== 1 && endian
== MO_LE
) {
503 /* Retain any natural alignment. */
504 if (align
== MO_ALIGN
) {
505 align
= pow2_align(size
);
510 tmp64
= tcg_temp_new_i64();
511 addr
= tcg_temp_new_i32();
512 load_reg_var(s
, addr
, a
->rn
);
514 mop
= endian
| size
| align
;
515 for (reg
= 0; reg
< nregs
; reg
++) {
516 for (n
= 0; n
< 8 >> size
; n
++) {
518 for (xs
= 0; xs
< interleave
; xs
++) {
519 int tt
= a
->vd
+ reg
+ spacing
* xs
;
522 gen_aa32_ld_internal_i64(s
, tmp64
, addr
, mmu_idx
, mop
);
523 neon_store_element64(tt
, n
, size
, tmp64
);
525 neon_load_element64(tmp64
, tt
, n
, size
);
526 gen_aa32_st_internal_i64(s
, tmp64
, addr
, mmu_idx
, mop
);
528 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
530 /* Subsequent memory operations inherit alignment */
536 gen_neon_ldst_base_update(s
, a
->rm
, a
->rn
, nregs
* interleave
* 8);
540 static bool trans_VLD_all_lanes(DisasContext
*s
, arg_VLD_all_lanes
*a
)
542 /* Neon load single structure to all lanes */
543 int reg
, stride
, vec_size
;
546 int nregs
= a
->n
+ 1;
550 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
554 /* UNDEF accesses to D16-D31 if they don't exist */
555 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
561 if (nregs
!= 4 || a
->a
== 0) {
564 /* For VLD4 size == 3 a == 1 means 32 bits at 16 byte alignment */
576 align
= pow2_align(size
+ 1);
582 align
= pow2_align(3);
584 align
= pow2_align(size
+ 2);
588 g_assert_not_reached();
592 if (!vfp_access_check(s
)) {
597 * VLD1 to all lanes: T bit indicates how many Dregs to write.
598 * VLD2/3/4 to all lanes: T bit indicates register stride.
600 stride
= a
->t
? 2 : 1;
601 vec_size
= nregs
== 1 ? stride
* 8 : 8;
603 tmp
= tcg_temp_new_i32();
604 addr
= tcg_temp_new_i32();
605 load_reg_var(s
, addr
, a
->rn
);
606 for (reg
= 0; reg
< nregs
; reg
++) {
607 gen_aa32_ld_i32(s
, tmp
, addr
, get_mem_index(s
), mop
);
608 if ((vd
& 1) && vec_size
== 16) {
610 * We cannot write 16 bytes at once because the
611 * destination is unaligned.
613 tcg_gen_gvec_dup_i32(size
, neon_full_reg_offset(vd
),
615 tcg_gen_gvec_mov(0, neon_full_reg_offset(vd
+ 1),
616 neon_full_reg_offset(vd
), 8, 8);
618 tcg_gen_gvec_dup_i32(size
, neon_full_reg_offset(vd
),
619 vec_size
, vec_size
, tmp
);
621 tcg_gen_addi_i32(addr
, addr
, 1 << size
);
624 /* Subsequent memory operations inherit alignment */
628 gen_neon_ldst_base_update(s
, a
->rm
, a
->rn
, (1 << size
) * nregs
);
633 static bool trans_VLDST_single(DisasContext
*s
, arg_VLDST_single
*a
)
635 /* Neon load/store single structure to one lane */
637 int nregs
= a
->n
+ 1;
642 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
646 /* UNDEF accesses to D16-D31 if they don't exist */
647 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
651 /* Catch the UNDEF cases. This is unavoidably a bit messy. */
654 if (a
->stride
!= 1) {
657 if (((a
->align
& (1 << a
->size
)) != 0) ||
658 (a
->size
== 2 && (a
->align
== 1 || a
->align
== 2))) {
663 if (a
->size
== 2 && (a
->align
& 2) != 0) {
673 if (a
->size
== 2 && a
->align
== 3) {
678 g_assert_not_reached();
680 if ((vd
+ a
->stride
* (nregs
- 1)) > 31) {
682 * Attempts to write off the end of the register file are
683 * UNPREDICTABLE; we choose to UNDEF because otherwise we would
684 * access off the end of the array that holds the register data.
689 if (!vfp_access_check(s
)) {
693 /* Pick up SCTLR settings */
694 mop
= finalize_memop(s
, a
->size
);
701 /* For VLD1, use natural alignment. */
705 /* For VLD2, use double alignment. */
706 align_op
= pow2_align(a
->size
+ 1);
709 if (a
->size
== MO_32
) {
711 * For VLD4.32, align = 1 is double alignment, align = 2 is
712 * quad alignment; align = 3 is rejected above.
714 align_op
= pow2_align(a
->size
+ a
->align
);
716 /* For VLD4.8 and VLD.16, we want quad alignment. */
717 align_op
= pow2_align(a
->size
+ 2);
721 /* For VLD3, the alignment field is zero and rejected above. */
722 g_assert_not_reached();
725 mop
= (mop
& ~MO_AMASK
) | align_op
;
728 tmp
= tcg_temp_new_i32();
729 addr
= tcg_temp_new_i32();
730 load_reg_var(s
, addr
, a
->rn
);
732 for (reg
= 0; reg
< nregs
; reg
++) {
734 gen_aa32_ld_internal_i32(s
, tmp
, addr
, get_mem_index(s
), mop
);
735 neon_store_element(vd
, a
->reg_idx
, a
->size
, tmp
);
737 neon_load_element(tmp
, vd
, a
->reg_idx
, a
->size
);
738 gen_aa32_st_internal_i32(s
, tmp
, addr
, get_mem_index(s
), mop
);
741 tcg_gen_addi_i32(addr
, addr
, 1 << a
->size
);
743 /* Subsequent memory operations inherit alignment */
747 gen_neon_ldst_base_update(s
, a
->rm
, a
->rn
, (1 << a
->size
) * nregs
);
752 static bool do_3same(DisasContext
*s
, arg_3same
*a
, GVecGen3Fn fn
)
754 int vec_size
= a
->q
? 16 : 8;
755 int rd_ofs
= neon_full_reg_offset(a
->vd
);
756 int rn_ofs
= neon_full_reg_offset(a
->vn
);
757 int rm_ofs
= neon_full_reg_offset(a
->vm
);
759 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
763 /* UNDEF accesses to D16-D31 if they don't exist. */
764 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
765 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
769 if ((a
->vn
| a
->vm
| a
->vd
) & a
->q
) {
773 if (!vfp_access_check(s
)) {
777 fn(a
->size
, rd_ofs
, rn_ofs
, rm_ofs
, vec_size
, vec_size
);
781 #define DO_3SAME(INSN, FUNC) \
782 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
784 return do_3same(s, a, FUNC); \
787 DO_3SAME(VADD
, tcg_gen_gvec_add
)
788 DO_3SAME(VSUB
, tcg_gen_gvec_sub
)
789 DO_3SAME(VAND
, tcg_gen_gvec_and
)
790 DO_3SAME(VBIC
, tcg_gen_gvec_andc
)
791 DO_3SAME(VORR
, tcg_gen_gvec_or
)
792 DO_3SAME(VORN
, tcg_gen_gvec_orc
)
793 DO_3SAME(VEOR
, tcg_gen_gvec_xor
)
794 DO_3SAME(VSHL_S
, gen_gvec_sshl
)
795 DO_3SAME(VSHL_U
, gen_gvec_ushl
)
796 DO_3SAME(VQADD_S
, gen_gvec_sqadd_qc
)
797 DO_3SAME(VQADD_U
, gen_gvec_uqadd_qc
)
798 DO_3SAME(VQSUB_S
, gen_gvec_sqsub_qc
)
799 DO_3SAME(VQSUB_U
, gen_gvec_uqsub_qc
)
801 /* These insns are all gvec_bitsel but with the inputs in various orders. */
802 #define DO_3SAME_BITSEL(INSN, O1, O2, O3) \
803 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
804 uint32_t rn_ofs, uint32_t rm_ofs, \
805 uint32_t oprsz, uint32_t maxsz) \
807 tcg_gen_gvec_bitsel(vece, rd_ofs, O1, O2, O3, oprsz, maxsz); \
809 DO_3SAME(INSN, gen_##INSN##_3s)
811 DO_3SAME_BITSEL(VBSL
, rd_ofs
, rn_ofs
, rm_ofs
)
812 DO_3SAME_BITSEL(VBIT
, rm_ofs
, rn_ofs
, rd_ofs
)
813 DO_3SAME_BITSEL(VBIF
, rm_ofs
, rd_ofs
, rn_ofs
)
815 #define DO_3SAME_NO_SZ_3(INSN, FUNC) \
816 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
818 if (a->size == 3) { \
821 return do_3same(s, a, FUNC); \
824 DO_3SAME_NO_SZ_3(VMAX_S
, tcg_gen_gvec_smax
)
825 DO_3SAME_NO_SZ_3(VMAX_U
, tcg_gen_gvec_umax
)
826 DO_3SAME_NO_SZ_3(VMIN_S
, tcg_gen_gvec_smin
)
827 DO_3SAME_NO_SZ_3(VMIN_U
, tcg_gen_gvec_umin
)
828 DO_3SAME_NO_SZ_3(VMUL
, tcg_gen_gvec_mul
)
829 DO_3SAME_NO_SZ_3(VMLA
, gen_gvec_mla
)
830 DO_3SAME_NO_SZ_3(VMLS
, gen_gvec_mls
)
831 DO_3SAME_NO_SZ_3(VTST
, gen_gvec_cmtst
)
832 DO_3SAME_NO_SZ_3(VABD_S
, gen_gvec_sabd
)
833 DO_3SAME_NO_SZ_3(VABA_S
, gen_gvec_saba
)
834 DO_3SAME_NO_SZ_3(VABD_U
, gen_gvec_uabd
)
835 DO_3SAME_NO_SZ_3(VABA_U
, gen_gvec_uaba
)
837 #define DO_3SAME_CMP(INSN, COND) \
838 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
839 uint32_t rn_ofs, uint32_t rm_ofs, \
840 uint32_t oprsz, uint32_t maxsz) \
842 tcg_gen_gvec_cmp(COND, vece, rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz); \
844 DO_3SAME_NO_SZ_3(INSN, gen_##INSN##_3s)
846 DO_3SAME_CMP(VCGT_S
, TCG_COND_GT
)
847 DO_3SAME_CMP(VCGT_U
, TCG_COND_GTU
)
848 DO_3SAME_CMP(VCGE_S
, TCG_COND_GE
)
849 DO_3SAME_CMP(VCGE_U
, TCG_COND_GEU
)
850 DO_3SAME_CMP(VCEQ
, TCG_COND_EQ
)
852 #define WRAP_OOL_FN(WRAPNAME, FUNC) \
853 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs, \
854 uint32_t rm_ofs, uint32_t oprsz, uint32_t maxsz) \
856 tcg_gen_gvec_3_ool(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, 0, FUNC); \
859 WRAP_OOL_FN(gen_VMUL_p_3s
, gen_helper_gvec_pmul_b
)
861 static bool trans_VMUL_p_3s(DisasContext
*s
, arg_3same
*a
)
866 return do_3same(s
, a
, gen_VMUL_p_3s
);
869 #define DO_VQRDMLAH(INSN, FUNC) \
870 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
872 if (!dc_isar_feature(aa32_rdm, s)) { \
875 if (a->size != 1 && a->size != 2) { \
878 return do_3same(s, a, FUNC); \
881 DO_VQRDMLAH(VQRDMLAH
, gen_gvec_sqrdmlah_qc
)
882 DO_VQRDMLAH(VQRDMLSH
, gen_gvec_sqrdmlsh_qc
)
884 #define DO_SHA1(NAME, FUNC) \
885 WRAP_OOL_FN(gen_##NAME##_3s, FUNC) \
886 static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a) \
888 if (!dc_isar_feature(aa32_sha1, s)) { \
891 return do_3same(s, a, gen_##NAME##_3s); \
894 DO_SHA1(SHA1C
, gen_helper_crypto_sha1c
)
895 DO_SHA1(SHA1P
, gen_helper_crypto_sha1p
)
896 DO_SHA1(SHA1M
, gen_helper_crypto_sha1m
)
897 DO_SHA1(SHA1SU0
, gen_helper_crypto_sha1su0
)
899 #define DO_SHA2(NAME, FUNC) \
900 WRAP_OOL_FN(gen_##NAME##_3s, FUNC) \
901 static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a) \
903 if (!dc_isar_feature(aa32_sha2, s)) { \
906 return do_3same(s, a, gen_##NAME##_3s); \
909 DO_SHA2(SHA256H
, gen_helper_crypto_sha256h
)
910 DO_SHA2(SHA256H2
, gen_helper_crypto_sha256h2
)
911 DO_SHA2(SHA256SU1
, gen_helper_crypto_sha256su1
)
913 #define DO_3SAME_64(INSN, FUNC) \
914 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
915 uint32_t rn_ofs, uint32_t rm_ofs, \
916 uint32_t oprsz, uint32_t maxsz) \
918 static const GVecGen3 op = { .fni8 = FUNC }; \
919 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &op); \
921 DO_3SAME(INSN, gen_##INSN##_3s)
923 #define DO_3SAME_64_ENV(INSN, FUNC) \
924 static void gen_##INSN##_elt(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m) \
926 FUNC(d, cpu_env, n, m); \
928 DO_3SAME_64(INSN, gen_##INSN##_elt)
930 DO_3SAME_64(VRSHL_S64
, gen_helper_neon_rshl_s64
)
931 DO_3SAME_64(VRSHL_U64
, gen_helper_neon_rshl_u64
)
932 DO_3SAME_64_ENV(VQSHL_S64
, gen_helper_neon_qshl_s64
)
933 DO_3SAME_64_ENV(VQSHL_U64
, gen_helper_neon_qshl_u64
)
934 DO_3SAME_64_ENV(VQRSHL_S64
, gen_helper_neon_qrshl_s64
)
935 DO_3SAME_64_ENV(VQRSHL_U64
, gen_helper_neon_qrshl_u64
)
937 #define DO_3SAME_32(INSN, FUNC) \
938 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
939 uint32_t rn_ofs, uint32_t rm_ofs, \
940 uint32_t oprsz, uint32_t maxsz) \
942 static const GVecGen3 ops[4] = { \
943 { .fni4 = gen_helper_neon_##FUNC##8 }, \
944 { .fni4 = gen_helper_neon_##FUNC##16 }, \
945 { .fni4 = gen_helper_neon_##FUNC##32 }, \
948 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops[vece]); \
950 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
955 return do_3same(s, a, gen_##INSN##_3s); \
959 * Some helper functions need to be passed the cpu_env. In order
960 * to use those with the gvec APIs like tcg_gen_gvec_3() we need
961 * to create wrapper functions whose prototype is a NeonGenTwoOpFn()
962 * and which call a NeonGenTwoOpEnvFn().
964 #define WRAP_ENV_FN(WRAPNAME, FUNC) \
965 static void WRAPNAME(TCGv_i32 d, TCGv_i32 n, TCGv_i32 m) \
967 FUNC(d, cpu_env, n, m); \
970 #define DO_3SAME_32_ENV(INSN, FUNC) \
971 WRAP_ENV_FN(gen_##INSN##_tramp8, gen_helper_neon_##FUNC##8); \
972 WRAP_ENV_FN(gen_##INSN##_tramp16, gen_helper_neon_##FUNC##16); \
973 WRAP_ENV_FN(gen_##INSN##_tramp32, gen_helper_neon_##FUNC##32); \
974 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
975 uint32_t rn_ofs, uint32_t rm_ofs, \
976 uint32_t oprsz, uint32_t maxsz) \
978 static const GVecGen3 ops[4] = { \
979 { .fni4 = gen_##INSN##_tramp8 }, \
980 { .fni4 = gen_##INSN##_tramp16 }, \
981 { .fni4 = gen_##INSN##_tramp32 }, \
984 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops[vece]); \
986 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
991 return do_3same(s, a, gen_##INSN##_3s); \
994 DO_3SAME_32(VHADD_S
, hadd_s
)
995 DO_3SAME_32(VHADD_U
, hadd_u
)
996 DO_3SAME_32(VHSUB_S
, hsub_s
)
997 DO_3SAME_32(VHSUB_U
, hsub_u
)
998 DO_3SAME_32(VRHADD_S
, rhadd_s
)
999 DO_3SAME_32(VRHADD_U
, rhadd_u
)
1000 DO_3SAME_32(VRSHL_S
, rshl_s
)
1001 DO_3SAME_32(VRSHL_U
, rshl_u
)
1003 DO_3SAME_32_ENV(VQSHL_S
, qshl_s
)
1004 DO_3SAME_32_ENV(VQSHL_U
, qshl_u
)
1005 DO_3SAME_32_ENV(VQRSHL_S
, qrshl_s
)
1006 DO_3SAME_32_ENV(VQRSHL_U
, qrshl_u
)
1008 static bool do_3same_pair(DisasContext
*s
, arg_3same
*a
, NeonGenTwoOpFn
*fn
)
1010 /* Operations handled pairwise 32 bits at a time */
1011 TCGv_i32 tmp
, tmp2
, tmp3
;
1013 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1017 /* UNDEF accesses to D16-D31 if they don't exist. */
1018 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1019 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1027 if (!vfp_access_check(s
)) {
1031 assert(a
->q
== 0); /* enforced by decode patterns */
1034 * Note that we have to be careful not to clobber the source operands
1035 * in the "vm == vd" case by storing the result of the first pass too
1036 * early. Since Q is 0 there are always just two passes, so instead
1037 * of a complicated loop over each pass we just unroll.
1039 tmp
= tcg_temp_new_i32();
1040 tmp2
= tcg_temp_new_i32();
1041 tmp3
= tcg_temp_new_i32();
1043 read_neon_element32(tmp
, a
->vn
, 0, MO_32
);
1044 read_neon_element32(tmp2
, a
->vn
, 1, MO_32
);
1047 read_neon_element32(tmp3
, a
->vm
, 0, MO_32
);
1048 read_neon_element32(tmp2
, a
->vm
, 1, MO_32
);
1049 fn(tmp3
, tmp3
, tmp2
);
1051 write_neon_element32(tmp
, a
->vd
, 0, MO_32
);
1052 write_neon_element32(tmp3
, a
->vd
, 1, MO_32
);
1057 #define DO_3SAME_PAIR(INSN, func) \
1058 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
1060 static NeonGenTwoOpFn * const fns[] = { \
1061 gen_helper_neon_##func##8, \
1062 gen_helper_neon_##func##16, \
1063 gen_helper_neon_##func##32, \
1065 if (a->size > 2) { \
1068 return do_3same_pair(s, a, fns[a->size]); \
1071 /* 32-bit pairwise ops end up the same as the elementwise versions. */
1072 #define gen_helper_neon_pmax_s32 tcg_gen_smax_i32
1073 #define gen_helper_neon_pmax_u32 tcg_gen_umax_i32
1074 #define gen_helper_neon_pmin_s32 tcg_gen_smin_i32
1075 #define gen_helper_neon_pmin_u32 tcg_gen_umin_i32
1076 #define gen_helper_neon_padd_u32 tcg_gen_add_i32
1078 DO_3SAME_PAIR(VPMAX_S
, pmax_s
)
1079 DO_3SAME_PAIR(VPMIN_S
, pmin_s
)
1080 DO_3SAME_PAIR(VPMAX_U
, pmax_u
)
1081 DO_3SAME_PAIR(VPMIN_U
, pmin_u
)
1082 DO_3SAME_PAIR(VPADD
, padd_u
)
1084 #define DO_3SAME_VQDMULH(INSN, FUNC) \
1085 WRAP_ENV_FN(gen_##INSN##_tramp16, gen_helper_neon_##FUNC##_s16); \
1086 WRAP_ENV_FN(gen_##INSN##_tramp32, gen_helper_neon_##FUNC##_s32); \
1087 static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \
1088 uint32_t rn_ofs, uint32_t rm_ofs, \
1089 uint32_t oprsz, uint32_t maxsz) \
1091 static const GVecGen3 ops[2] = { \
1092 { .fni4 = gen_##INSN##_tramp16 }, \
1093 { .fni4 = gen_##INSN##_tramp32 }, \
1095 tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops[vece - 1]); \
1097 static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a) \
1099 if (a->size != 1 && a->size != 2) { \
1102 return do_3same(s, a, gen_##INSN##_3s); \
1105 DO_3SAME_VQDMULH(VQDMULH
, qdmulh
)
1106 DO_3SAME_VQDMULH(VQRDMULH
, qrdmulh
)
1108 #define WRAP_FP_GVEC(WRAPNAME, FPST, FUNC) \
1109 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \
1110 uint32_t rn_ofs, uint32_t rm_ofs, \
1111 uint32_t oprsz, uint32_t maxsz) \
1113 TCGv_ptr fpst = fpstatus_ptr(FPST); \
1114 tcg_gen_gvec_3_ptr(rd_ofs, rn_ofs, rm_ofs, fpst, \
1115 oprsz, maxsz, 0, FUNC); \
1118 #define DO_3S_FP_GVEC(INSN,SFUNC,HFUNC) \
1119 WRAP_FP_GVEC(gen_##INSN##_fp32_3s, FPST_STD, SFUNC) \
1120 WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC) \
1121 static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
1123 if (a->size == MO_16) { \
1124 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
1127 return do_3same(s, a, gen_##INSN##_fp16_3s); \
1129 return do_3same(s, a, gen_##INSN##_fp32_3s); \
1133 DO_3S_FP_GVEC(VADD
, gen_helper_gvec_fadd_s
, gen_helper_gvec_fadd_h
)
1134 DO_3S_FP_GVEC(VSUB
, gen_helper_gvec_fsub_s
, gen_helper_gvec_fsub_h
)
1135 DO_3S_FP_GVEC(VABD
, gen_helper_gvec_fabd_s
, gen_helper_gvec_fabd_h
)
1136 DO_3S_FP_GVEC(VMUL
, gen_helper_gvec_fmul_s
, gen_helper_gvec_fmul_h
)
1137 DO_3S_FP_GVEC(VCEQ
, gen_helper_gvec_fceq_s
, gen_helper_gvec_fceq_h
)
1138 DO_3S_FP_GVEC(VCGE
, gen_helper_gvec_fcge_s
, gen_helper_gvec_fcge_h
)
1139 DO_3S_FP_GVEC(VCGT
, gen_helper_gvec_fcgt_s
, gen_helper_gvec_fcgt_h
)
1140 DO_3S_FP_GVEC(VACGE
, gen_helper_gvec_facge_s
, gen_helper_gvec_facge_h
)
1141 DO_3S_FP_GVEC(VACGT
, gen_helper_gvec_facgt_s
, gen_helper_gvec_facgt_h
)
1142 DO_3S_FP_GVEC(VMAX
, gen_helper_gvec_fmax_s
, gen_helper_gvec_fmax_h
)
1143 DO_3S_FP_GVEC(VMIN
, gen_helper_gvec_fmin_s
, gen_helper_gvec_fmin_h
)
1144 DO_3S_FP_GVEC(VMLA
, gen_helper_gvec_fmla_s
, gen_helper_gvec_fmla_h
)
1145 DO_3S_FP_GVEC(VMLS
, gen_helper_gvec_fmls_s
, gen_helper_gvec_fmls_h
)
1146 DO_3S_FP_GVEC(VFMA
, gen_helper_gvec_vfma_s
, gen_helper_gvec_vfma_h
)
1147 DO_3S_FP_GVEC(VFMS
, gen_helper_gvec_vfms_s
, gen_helper_gvec_vfms_h
)
1148 DO_3S_FP_GVEC(VRECPS
, gen_helper_gvec_recps_nf_s
, gen_helper_gvec_recps_nf_h
)
1149 DO_3S_FP_GVEC(VRSQRTS
, gen_helper_gvec_rsqrts_nf_s
, gen_helper_gvec_rsqrts_nf_h
)
1151 WRAP_FP_GVEC(gen_VMAXNM_fp32_3s
, FPST_STD
, gen_helper_gvec_fmaxnum_s
)
1152 WRAP_FP_GVEC(gen_VMAXNM_fp16_3s
, FPST_STD_F16
, gen_helper_gvec_fmaxnum_h
)
1153 WRAP_FP_GVEC(gen_VMINNM_fp32_3s
, FPST_STD
, gen_helper_gvec_fminnum_s
)
1154 WRAP_FP_GVEC(gen_VMINNM_fp16_3s
, FPST_STD_F16
, gen_helper_gvec_fminnum_h
)
1156 static bool trans_VMAXNM_fp_3s(DisasContext
*s
, arg_3same
*a
)
1158 if (!arm_dc_feature(s
, ARM_FEATURE_V8
)) {
1162 if (a
->size
== MO_16
) {
1163 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
1166 return do_3same(s
, a
, gen_VMAXNM_fp16_3s
);
1168 return do_3same(s
, a
, gen_VMAXNM_fp32_3s
);
1171 static bool trans_VMINNM_fp_3s(DisasContext
*s
, arg_3same
*a
)
1173 if (!arm_dc_feature(s
, ARM_FEATURE_V8
)) {
1177 if (a
->size
== MO_16
) {
1178 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
1181 return do_3same(s
, a
, gen_VMINNM_fp16_3s
);
1183 return do_3same(s
, a
, gen_VMINNM_fp32_3s
);
1186 static bool do_3same_fp_pair(DisasContext
*s
, arg_3same
*a
,
1187 gen_helper_gvec_3_ptr
*fn
)
1189 /* FP pairwise operations */
1192 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1196 /* UNDEF accesses to D16-D31 if they don't exist. */
1197 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1198 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1202 if (!vfp_access_check(s
)) {
1206 assert(a
->q
== 0); /* enforced by decode patterns */
1209 fpstatus
= fpstatus_ptr(a
->size
== MO_16
? FPST_STD_F16
: FPST_STD
);
1210 tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a
->vd
),
1211 vfp_reg_offset(1, a
->vn
),
1212 vfp_reg_offset(1, a
->vm
),
1213 fpstatus
, 8, 8, 0, fn
);
1219 * For all the functions using this macro, size == 1 means fp16,
1220 * which is an architecture extension we don't implement yet.
1222 #define DO_3S_FP_PAIR(INSN,FUNC) \
1223 static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \
1225 if (a->size == MO_16) { \
1226 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
1229 return do_3same_fp_pair(s, a, FUNC##h); \
1231 return do_3same_fp_pair(s, a, FUNC##s); \
1234 DO_3S_FP_PAIR(VPADD
, gen_helper_neon_padd
)
1235 DO_3S_FP_PAIR(VPMAX
, gen_helper_neon_pmax
)
1236 DO_3S_FP_PAIR(VPMIN
, gen_helper_neon_pmin
)
1238 static bool do_vector_2sh(DisasContext
*s
, arg_2reg_shift
*a
, GVecGen2iFn
*fn
)
1240 /* Handle a 2-reg-shift insn which can be vectorized. */
1241 int vec_size
= a
->q
? 16 : 8;
1242 int rd_ofs
= neon_full_reg_offset(a
->vd
);
1243 int rm_ofs
= neon_full_reg_offset(a
->vm
);
1245 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1249 /* UNDEF accesses to D16-D31 if they don't exist. */
1250 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1251 ((a
->vd
| a
->vm
) & 0x10)) {
1255 if ((a
->vm
| a
->vd
) & a
->q
) {
1259 if (!vfp_access_check(s
)) {
1263 fn(a
->size
, rd_ofs
, rm_ofs
, a
->shift
, vec_size
, vec_size
);
1267 #define DO_2SH(INSN, FUNC) \
1268 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1270 return do_vector_2sh(s, a, FUNC); \
1273 DO_2SH(VSHL, tcg_gen_gvec_shli)
1274 DO_2SH(VSLI
, gen_gvec_sli
)
1275 DO_2SH(VSRI
, gen_gvec_sri
)
1276 DO_2SH(VSRA_S
, gen_gvec_ssra
)
1277 DO_2SH(VSRA_U
, gen_gvec_usra
)
1278 DO_2SH(VRSHR_S
, gen_gvec_srshr
)
1279 DO_2SH(VRSHR_U
, gen_gvec_urshr
)
1280 DO_2SH(VRSRA_S
, gen_gvec_srsra
)
1281 DO_2SH(VRSRA_U
, gen_gvec_ursra
)
1283 static bool trans_VSHR_S_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1285 /* Signed shift out of range results in all-sign-bits */
1286 a
->shift
= MIN(a
->shift
, (8 << a
->size
) - 1);
1287 return do_vector_2sh(s
, a
, tcg_gen_gvec_sari
);
1290 static void gen_zero_rd_2sh(unsigned vece
, uint32_t rd_ofs
, uint32_t rm_ofs
,
1291 int64_t shift
, uint32_t oprsz
, uint32_t maxsz
)
1293 tcg_gen_gvec_dup_imm(vece
, rd_ofs
, oprsz
, maxsz
, 0);
1296 static bool trans_VSHR_U_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1298 /* Shift out of range is architecturally valid and results in zero. */
1299 if (a
->shift
>= (8 << a
->size
)) {
1300 return do_vector_2sh(s
, a
, gen_zero_rd_2sh
);
1302 return do_vector_2sh(s
, a
, tcg_gen_gvec_shri
);
1306 static bool do_2shift_env_64(DisasContext
*s
, arg_2reg_shift
*a
,
1307 NeonGenTwo64OpEnvFn
*fn
)
1310 * 2-reg-and-shift operations, size == 3 case, where the
1311 * function needs to be passed cpu_env.
1316 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1320 /* UNDEF accesses to D16-D31 if they don't exist. */
1321 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1322 ((a
->vd
| a
->vm
) & 0x10)) {
1326 if ((a
->vm
| a
->vd
) & a
->q
) {
1330 if (!vfp_access_check(s
)) {
1335 * To avoid excessive duplication of ops we implement shift
1336 * by immediate using the variable shift operations.
1338 constimm
= tcg_constant_i64(dup_const(a
->size
, a
->shift
));
1340 for (pass
= 0; pass
< a
->q
+ 1; pass
++) {
1341 TCGv_i64 tmp
= tcg_temp_new_i64();
1343 read_neon_element64(tmp
, a
->vm
, pass
, MO_64
);
1344 fn(tmp
, cpu_env
, tmp
, constimm
);
1345 write_neon_element64(tmp
, a
->vd
, pass
, MO_64
);
1350 static bool do_2shift_env_32(DisasContext
*s
, arg_2reg_shift
*a
,
1351 NeonGenTwoOpEnvFn
*fn
)
1354 * 2-reg-and-shift operations, size < 3 case, where the
1355 * helper needs to be passed cpu_env.
1357 TCGv_i32 constimm
, tmp
;
1360 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1364 /* UNDEF accesses to D16-D31 if they don't exist. */
1365 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1366 ((a
->vd
| a
->vm
) & 0x10)) {
1370 if ((a
->vm
| a
->vd
) & a
->q
) {
1374 if (!vfp_access_check(s
)) {
1379 * To avoid excessive duplication of ops we implement shift
1380 * by immediate using the variable shift operations.
1382 constimm
= tcg_constant_i32(dup_const(a
->size
, a
->shift
));
1383 tmp
= tcg_temp_new_i32();
1385 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
1386 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
1387 fn(tmp
, cpu_env
, tmp
, constimm
);
1388 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
1393 #define DO_2SHIFT_ENV(INSN, FUNC) \
1394 static bool trans_##INSN##_64_2sh(DisasContext *s, arg_2reg_shift *a) \
1396 return do_2shift_env_64(s, a, gen_helper_neon_##FUNC##64); \
1398 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1400 static NeonGenTwoOpEnvFn * const fns[] = { \
1401 gen_helper_neon_##FUNC##8, \
1402 gen_helper_neon_##FUNC##16, \
1403 gen_helper_neon_##FUNC##32, \
1405 assert(a->size < ARRAY_SIZE(fns)); \
1406 return do_2shift_env_32(s, a, fns[a->size]); \
1409 DO_2SHIFT_ENV(VQSHLU
, qshlu_s
)
1410 DO_2SHIFT_ENV(VQSHL_U
, qshl_u
)
1411 DO_2SHIFT_ENV(VQSHL_S
, qshl_s
)
1413 static bool do_2shift_narrow_64(DisasContext
*s
, arg_2reg_shift
*a
,
1414 NeonGenTwo64OpFn
*shiftfn
,
1415 NeonGenNarrowEnvFn
*narrowfn
)
1417 /* 2-reg-and-shift narrowing-shift operations, size == 3 case */
1418 TCGv_i64 constimm
, rm1
, rm2
;
1421 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1425 /* UNDEF accesses to D16-D31 if they don't exist. */
1426 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1427 ((a
->vd
| a
->vm
) & 0x10)) {
1435 if (!vfp_access_check(s
)) {
1440 * This is always a right shift, and the shiftfn is always a
1441 * left-shift helper, which thus needs the negated shift count.
1443 constimm
= tcg_constant_i64(-a
->shift
);
1444 rm1
= tcg_temp_new_i64();
1445 rm2
= tcg_temp_new_i64();
1446 rd
= tcg_temp_new_i32();
1448 /* Load both inputs first to avoid potential overwrite if rm == rd */
1449 read_neon_element64(rm1
, a
->vm
, 0, MO_64
);
1450 read_neon_element64(rm2
, a
->vm
, 1, MO_64
);
1452 shiftfn(rm1
, rm1
, constimm
);
1453 narrowfn(rd
, cpu_env
, rm1
);
1454 write_neon_element32(rd
, a
->vd
, 0, MO_32
);
1456 shiftfn(rm2
, rm2
, constimm
);
1457 narrowfn(rd
, cpu_env
, rm2
);
1458 write_neon_element32(rd
, a
->vd
, 1, MO_32
);
1463 static bool do_2shift_narrow_32(DisasContext
*s
, arg_2reg_shift
*a
,
1464 NeonGenTwoOpFn
*shiftfn
,
1465 NeonGenNarrowEnvFn
*narrowfn
)
1467 /* 2-reg-and-shift narrowing-shift operations, size < 3 case */
1468 TCGv_i32 constimm
, rm1
, rm2
, rm3
, rm4
;
1472 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1476 /* UNDEF accesses to D16-D31 if they don't exist. */
1477 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1478 ((a
->vd
| a
->vm
) & 0x10)) {
1486 if (!vfp_access_check(s
)) {
1491 * This is always a right shift, and the shiftfn is always a
1492 * left-shift helper, which thus needs the negated shift count
1493 * duplicated into each lane of the immediate value.
1496 imm
= (uint16_t)(-a
->shift
);
1502 constimm
= tcg_constant_i32(imm
);
1504 /* Load all inputs first to avoid potential overwrite */
1505 rm1
= tcg_temp_new_i32();
1506 rm2
= tcg_temp_new_i32();
1507 rm3
= tcg_temp_new_i32();
1508 rm4
= tcg_temp_new_i32();
1509 read_neon_element32(rm1
, a
->vm
, 0, MO_32
);
1510 read_neon_element32(rm2
, a
->vm
, 1, MO_32
);
1511 read_neon_element32(rm3
, a
->vm
, 2, MO_32
);
1512 read_neon_element32(rm4
, a
->vm
, 3, MO_32
);
1513 rtmp
= tcg_temp_new_i64();
1515 shiftfn(rm1
, rm1
, constimm
);
1516 shiftfn(rm2
, rm2
, constimm
);
1518 tcg_gen_concat_i32_i64(rtmp
, rm1
, rm2
);
1520 narrowfn(rm1
, cpu_env
, rtmp
);
1521 write_neon_element32(rm1
, a
->vd
, 0, MO_32
);
1523 shiftfn(rm3
, rm3
, constimm
);
1524 shiftfn(rm4
, rm4
, constimm
);
1526 tcg_gen_concat_i32_i64(rtmp
, rm3
, rm4
);
1528 narrowfn(rm3
, cpu_env
, rtmp
);
1529 write_neon_element32(rm3
, a
->vd
, 1, MO_32
);
1533 #define DO_2SN_64(INSN, FUNC, NARROWFUNC) \
1534 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1536 return do_2shift_narrow_64(s, a, FUNC, NARROWFUNC); \
1538 #define DO_2SN_32(INSN, FUNC, NARROWFUNC) \
1539 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1541 return do_2shift_narrow_32(s, a, FUNC, NARROWFUNC); \
1544 static void gen_neon_narrow_u32(TCGv_i32 dest
, TCGv_ptr env
, TCGv_i64 src
)
1546 tcg_gen_extrl_i64_i32(dest
, src
);
1549 static void gen_neon_narrow_u16(TCGv_i32 dest
, TCGv_ptr env
, TCGv_i64 src
)
1551 gen_helper_neon_narrow_u16(dest
, src
);
1554 static void gen_neon_narrow_u8(TCGv_i32 dest
, TCGv_ptr env
, TCGv_i64 src
)
1556 gen_helper_neon_narrow_u8(dest
, src
);
1559 DO_2SN_64(VSHRN_64
, gen_ushl_i64
, gen_neon_narrow_u32
)
1560 DO_2SN_32(VSHRN_32
, gen_ushl_i32
, gen_neon_narrow_u16
)
1561 DO_2SN_32(VSHRN_16
, gen_helper_neon_shl_u16
, gen_neon_narrow_u8
)
1563 DO_2SN_64(VRSHRN_64
, gen_helper_neon_rshl_u64
, gen_neon_narrow_u32
)
1564 DO_2SN_32(VRSHRN_32
, gen_helper_neon_rshl_u32
, gen_neon_narrow_u16
)
1565 DO_2SN_32(VRSHRN_16
, gen_helper_neon_rshl_u16
, gen_neon_narrow_u8
)
1567 DO_2SN_64(VQSHRUN_64
, gen_sshl_i64
, gen_helper_neon_unarrow_sat32
)
1568 DO_2SN_32(VQSHRUN_32
, gen_sshl_i32
, gen_helper_neon_unarrow_sat16
)
1569 DO_2SN_32(VQSHRUN_16
, gen_helper_neon_shl_s16
, gen_helper_neon_unarrow_sat8
)
1571 DO_2SN_64(VQRSHRUN_64
, gen_helper_neon_rshl_s64
, gen_helper_neon_unarrow_sat32
)
1572 DO_2SN_32(VQRSHRUN_32
, gen_helper_neon_rshl_s32
, gen_helper_neon_unarrow_sat16
)
1573 DO_2SN_32(VQRSHRUN_16
, gen_helper_neon_rshl_s16
, gen_helper_neon_unarrow_sat8
)
1574 DO_2SN_64(VQSHRN_S64
, gen_sshl_i64
, gen_helper_neon_narrow_sat_s32
)
1575 DO_2SN_32(VQSHRN_S32
, gen_sshl_i32
, gen_helper_neon_narrow_sat_s16
)
1576 DO_2SN_32(VQSHRN_S16
, gen_helper_neon_shl_s16
, gen_helper_neon_narrow_sat_s8
)
1578 DO_2SN_64(VQRSHRN_S64
, gen_helper_neon_rshl_s64
, gen_helper_neon_narrow_sat_s32
)
1579 DO_2SN_32(VQRSHRN_S32
, gen_helper_neon_rshl_s32
, gen_helper_neon_narrow_sat_s16
)
1580 DO_2SN_32(VQRSHRN_S16
, gen_helper_neon_rshl_s16
, gen_helper_neon_narrow_sat_s8
)
1582 DO_2SN_64(VQSHRN_U64
, gen_ushl_i64
, gen_helper_neon_narrow_sat_u32
)
1583 DO_2SN_32(VQSHRN_U32
, gen_ushl_i32
, gen_helper_neon_narrow_sat_u16
)
1584 DO_2SN_32(VQSHRN_U16
, gen_helper_neon_shl_u16
, gen_helper_neon_narrow_sat_u8
)
1586 DO_2SN_64(VQRSHRN_U64
, gen_helper_neon_rshl_u64
, gen_helper_neon_narrow_sat_u32
)
1587 DO_2SN_32(VQRSHRN_U32
, gen_helper_neon_rshl_u32
, gen_helper_neon_narrow_sat_u16
)
1588 DO_2SN_32(VQRSHRN_U16
, gen_helper_neon_rshl_u16
, gen_helper_neon_narrow_sat_u8
)
1590 static bool do_vshll_2sh(DisasContext
*s
, arg_2reg_shift
*a
,
1591 NeonGenWidenFn
*widenfn
, bool u
)
1595 uint64_t widen_mask
= 0;
1597 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1601 /* UNDEF accesses to D16-D31 if they don't exist. */
1602 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1603 ((a
->vd
| a
->vm
) & 0x10)) {
1611 if (!vfp_access_check(s
)) {
1616 * This is a widen-and-shift operation. The shift is always less
1617 * than the width of the source type, so after widening the input
1618 * vector we can simply shift the whole 64-bit widened register,
1619 * and then clear the potential overflow bits resulting from left
1620 * bits of the narrow input appearing as right bits of the left
1621 * neighbour narrow input. Calculate a mask of bits to clear.
1623 if ((a
->shift
!= 0) && (a
->size
< 2 || u
)) {
1624 int esize
= 8 << a
->size
;
1625 widen_mask
= MAKE_64BIT_MASK(0, esize
);
1626 widen_mask
>>= esize
- a
->shift
;
1627 widen_mask
= dup_const(a
->size
+ 1, widen_mask
);
1630 rm0
= tcg_temp_new_i32();
1631 rm1
= tcg_temp_new_i32();
1632 read_neon_element32(rm0
, a
->vm
, 0, MO_32
);
1633 read_neon_element32(rm1
, a
->vm
, 1, MO_32
);
1634 tmp
= tcg_temp_new_i64();
1637 if (a
->shift
!= 0) {
1638 tcg_gen_shli_i64(tmp
, tmp
, a
->shift
);
1639 tcg_gen_andi_i64(tmp
, tmp
, ~widen_mask
);
1641 write_neon_element64(tmp
, a
->vd
, 0, MO_64
);
1644 if (a
->shift
!= 0) {
1645 tcg_gen_shli_i64(tmp
, tmp
, a
->shift
);
1646 tcg_gen_andi_i64(tmp
, tmp
, ~widen_mask
);
1648 write_neon_element64(tmp
, a
->vd
, 1, MO_64
);
1652 static bool trans_VSHLL_S_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1654 static NeonGenWidenFn
* const widenfn
[] = {
1655 gen_helper_neon_widen_s8
,
1656 gen_helper_neon_widen_s16
,
1657 tcg_gen_ext_i32_i64
,
1659 return do_vshll_2sh(s
, a
, widenfn
[a
->size
], false);
1662 static bool trans_VSHLL_U_2sh(DisasContext
*s
, arg_2reg_shift
*a
)
1664 static NeonGenWidenFn
* const widenfn
[] = {
1665 gen_helper_neon_widen_u8
,
1666 gen_helper_neon_widen_u16
,
1667 tcg_gen_extu_i32_i64
,
1669 return do_vshll_2sh(s
, a
, widenfn
[a
->size
], true);
1672 static bool do_fp_2sh(DisasContext
*s
, arg_2reg_shift
*a
,
1673 gen_helper_gvec_2_ptr
*fn
)
1675 /* FP operations in 2-reg-and-shift group */
1676 int vec_size
= a
->q
? 16 : 8;
1677 int rd_ofs
= neon_full_reg_offset(a
->vd
);
1678 int rm_ofs
= neon_full_reg_offset(a
->vm
);
1681 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1685 if (a
->size
== MO_16
) {
1686 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
1691 /* UNDEF accesses to D16-D31 if they don't exist. */
1692 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1693 ((a
->vd
| a
->vm
) & 0x10)) {
1697 if ((a
->vm
| a
->vd
) & a
->q
) {
1701 if (!vfp_access_check(s
)) {
1705 fpst
= fpstatus_ptr(a
->size
== MO_16
? FPST_STD_F16
: FPST_STD
);
1706 tcg_gen_gvec_2_ptr(rd_ofs
, rm_ofs
, fpst
, vec_size
, vec_size
, a
->shift
, fn
);
1710 #define DO_FP_2SH(INSN, FUNC) \
1711 static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \
1713 return do_fp_2sh(s, a, FUNC); \
1716 DO_FP_2SH(VCVT_SF
, gen_helper_gvec_vcvt_sf
)
1717 DO_FP_2SH(VCVT_UF
, gen_helper_gvec_vcvt_uf
)
1718 DO_FP_2SH(VCVT_FS
, gen_helper_gvec_vcvt_fs
)
1719 DO_FP_2SH(VCVT_FU
, gen_helper_gvec_vcvt_fu
)
1721 DO_FP_2SH(VCVT_SH
, gen_helper_gvec_vcvt_sh
)
1722 DO_FP_2SH(VCVT_UH
, gen_helper_gvec_vcvt_uh
)
1723 DO_FP_2SH(VCVT_HS
, gen_helper_gvec_vcvt_hs
)
1724 DO_FP_2SH(VCVT_HU
, gen_helper_gvec_vcvt_hu
)
1726 static bool do_1reg_imm(DisasContext
*s
, arg_1reg_imm
*a
,
1730 int reg_ofs
, vec_size
;
1732 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1736 /* UNDEF accesses to D16-D31 if they don't exist. */
1737 if (!dc_isar_feature(aa32_simd_r32
, s
) && (a
->vd
& 0x10)) {
1745 if (!vfp_access_check(s
)) {
1749 reg_ofs
= neon_full_reg_offset(a
->vd
);
1750 vec_size
= a
->q
? 16 : 8;
1751 imm
= asimd_imm_const(a
->imm
, a
->cmode
, a
->op
);
1753 fn(MO_64
, reg_ofs
, reg_ofs
, imm
, vec_size
, vec_size
);
1757 static void gen_VMOV_1r(unsigned vece
, uint32_t dofs
, uint32_t aofs
,
1758 int64_t c
, uint32_t oprsz
, uint32_t maxsz
)
1760 tcg_gen_gvec_dup_imm(MO_64
, dofs
, oprsz
, maxsz
, c
);
1763 static bool trans_Vimm_1r(DisasContext
*s
, arg_1reg_imm
*a
)
1765 /* Handle decode of cmode/op here between VORR/VBIC/VMOV */
1768 if ((a
->cmode
& 1) && a
->cmode
< 12) {
1769 /* for op=1, the imm will be inverted, so BIC becomes AND. */
1770 fn
= a
->op
? tcg_gen_gvec_andi
: tcg_gen_gvec_ori
;
1772 /* There is one unallocated cmode/op combination in this space */
1773 if (a
->cmode
== 15 && a
->op
== 1) {
1778 return do_1reg_imm(s
, a
, fn
);
1781 static bool do_prewiden_3d(DisasContext
*s
, arg_3diff
*a
,
1782 NeonGenWidenFn
*widenfn
,
1783 NeonGenTwo64OpFn
*opfn
,
1784 int src1_mop
, int src2_mop
)
1786 /* 3-regs different lengths, prewidening case (VADDL/VSUBL/VAADW/VSUBW) */
1787 TCGv_i64 rn0_64
, rn1_64
, rm_64
;
1789 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1793 /* UNDEF accesses to D16-D31 if they don't exist. */
1794 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1795 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1800 /* size == 3 case, which is an entirely different insn group */
1804 if ((a
->vd
& 1) || (src1_mop
== MO_UQ
&& (a
->vn
& 1))) {
1808 if (!vfp_access_check(s
)) {
1812 rn0_64
= tcg_temp_new_i64();
1813 rn1_64
= tcg_temp_new_i64();
1814 rm_64
= tcg_temp_new_i64();
1816 if (src1_mop
>= 0) {
1817 read_neon_element64(rn0_64
, a
->vn
, 0, src1_mop
);
1819 TCGv_i32 tmp
= tcg_temp_new_i32();
1820 read_neon_element32(tmp
, a
->vn
, 0, MO_32
);
1821 widenfn(rn0_64
, tmp
);
1823 if (src2_mop
>= 0) {
1824 read_neon_element64(rm_64
, a
->vm
, 0, src2_mop
);
1826 TCGv_i32 tmp
= tcg_temp_new_i32();
1827 read_neon_element32(tmp
, a
->vm
, 0, MO_32
);
1828 widenfn(rm_64
, tmp
);
1831 opfn(rn0_64
, rn0_64
, rm_64
);
1834 * Load second pass inputs before storing the first pass result, to
1835 * avoid incorrect results if a narrow input overlaps with the result.
1837 if (src1_mop
>= 0) {
1838 read_neon_element64(rn1_64
, a
->vn
, 1, src1_mop
);
1840 TCGv_i32 tmp
= tcg_temp_new_i32();
1841 read_neon_element32(tmp
, a
->vn
, 1, MO_32
);
1842 widenfn(rn1_64
, tmp
);
1844 if (src2_mop
>= 0) {
1845 read_neon_element64(rm_64
, a
->vm
, 1, src2_mop
);
1847 TCGv_i32 tmp
= tcg_temp_new_i32();
1848 read_neon_element32(tmp
, a
->vm
, 1, MO_32
);
1849 widenfn(rm_64
, tmp
);
1852 write_neon_element64(rn0_64
, a
->vd
, 0, MO_64
);
1854 opfn(rn1_64
, rn1_64
, rm_64
);
1855 write_neon_element64(rn1_64
, a
->vd
, 1, MO_64
);
1860 #define DO_PREWIDEN(INSN, S, OP, SRC1WIDE, SIGN) \
1861 static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a) \
1863 static NeonGenWidenFn * const widenfn[] = { \
1864 gen_helper_neon_widen_##S##8, \
1865 gen_helper_neon_widen_##S##16, \
1868 static NeonGenTwo64OpFn * const addfn[] = { \
1869 gen_helper_neon_##OP##l_u16, \
1870 gen_helper_neon_##OP##l_u32, \
1871 tcg_gen_##OP##_i64, \
1874 int narrow_mop = a->size == MO_32 ? MO_32 | SIGN : -1; \
1875 return do_prewiden_3d(s, a, widenfn[a->size], addfn[a->size], \
1876 SRC1WIDE ? MO_UQ : narrow_mop, \
1880 DO_PREWIDEN(VADDL_S
, s
, add
, false, MO_SIGN
)
1881 DO_PREWIDEN(VADDL_U
, u
, add
, false, 0)
1882 DO_PREWIDEN(VSUBL_S
, s
, sub
, false, MO_SIGN
)
1883 DO_PREWIDEN(VSUBL_U
, u
, sub
, false, 0)
1884 DO_PREWIDEN(VADDW_S
, s
, add
, true, MO_SIGN
)
1885 DO_PREWIDEN(VADDW_U
, u
, add
, true, 0)
1886 DO_PREWIDEN(VSUBW_S
, s
, sub
, true, MO_SIGN
)
1887 DO_PREWIDEN(VSUBW_U
, u
, sub
, true, 0)
1889 static bool do_narrow_3d(DisasContext
*s
, arg_3diff
*a
,
1890 NeonGenTwo64OpFn
*opfn
, NeonGenNarrowFn
*narrowfn
)
1892 /* 3-regs different lengths, narrowing (VADDHN/VSUBHN/VRADDHN/VRSUBHN) */
1893 TCGv_i64 rn_64
, rm_64
;
1896 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1900 /* UNDEF accesses to D16-D31 if they don't exist. */
1901 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1902 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1906 if (!opfn
|| !narrowfn
) {
1907 /* size == 3 case, which is an entirely different insn group */
1911 if ((a
->vn
| a
->vm
) & 1) {
1915 if (!vfp_access_check(s
)) {
1919 rn_64
= tcg_temp_new_i64();
1920 rm_64
= tcg_temp_new_i64();
1921 rd0
= tcg_temp_new_i32();
1922 rd1
= tcg_temp_new_i32();
1924 read_neon_element64(rn_64
, a
->vn
, 0, MO_64
);
1925 read_neon_element64(rm_64
, a
->vm
, 0, MO_64
);
1927 opfn(rn_64
, rn_64
, rm_64
);
1929 narrowfn(rd0
, rn_64
);
1931 read_neon_element64(rn_64
, a
->vn
, 1, MO_64
);
1932 read_neon_element64(rm_64
, a
->vm
, 1, MO_64
);
1934 opfn(rn_64
, rn_64
, rm_64
);
1936 narrowfn(rd1
, rn_64
);
1938 write_neon_element32(rd0
, a
->vd
, 0, MO_32
);
1939 write_neon_element32(rd1
, a
->vd
, 1, MO_32
);
1944 #define DO_NARROW_3D(INSN, OP, NARROWTYPE, EXTOP) \
1945 static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a) \
1947 static NeonGenTwo64OpFn * const addfn[] = { \
1948 gen_helper_neon_##OP##l_u16, \
1949 gen_helper_neon_##OP##l_u32, \
1950 tcg_gen_##OP##_i64, \
1953 static NeonGenNarrowFn * const narrowfn[] = { \
1954 gen_helper_neon_##NARROWTYPE##_high_u8, \
1955 gen_helper_neon_##NARROWTYPE##_high_u16, \
1959 return do_narrow_3d(s, a, addfn[a->size], narrowfn[a->size]); \
1962 static void gen_narrow_round_high_u32(TCGv_i32 rd
, TCGv_i64 rn
)
1964 tcg_gen_addi_i64(rn
, rn
, 1u << 31);
1965 tcg_gen_extrh_i64_i32(rd
, rn
);
1968 DO_NARROW_3D(VADDHN
, add
, narrow
, tcg_gen_extrh_i64_i32
)
1969 DO_NARROW_3D(VSUBHN
, sub
, narrow
, tcg_gen_extrh_i64_i32
)
1970 DO_NARROW_3D(VRADDHN
, add
, narrow_round
, gen_narrow_round_high_u32
)
1971 DO_NARROW_3D(VRSUBHN
, sub
, narrow_round
, gen_narrow_round_high_u32
)
1973 static bool do_long_3d(DisasContext
*s
, arg_3diff
*a
,
1974 NeonGenTwoOpWidenFn
*opfn
,
1975 NeonGenTwo64OpFn
*accfn
)
1978 * 3-regs different lengths, long operations.
1979 * These perform an operation on two inputs that returns a double-width
1980 * result, and then possibly perform an accumulation operation of
1981 * that result into the double-width destination.
1983 TCGv_i64 rd0
, rd1
, tmp
;
1986 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
1990 /* UNDEF accesses to D16-D31 if they don't exist. */
1991 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
1992 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
1997 /* size == 3 case, which is an entirely different insn group */
2005 if (!vfp_access_check(s
)) {
2009 rd0
= tcg_temp_new_i64();
2010 rd1
= tcg_temp_new_i64();
2012 rn
= tcg_temp_new_i32();
2013 rm
= tcg_temp_new_i32();
2014 read_neon_element32(rn
, a
->vn
, 0, MO_32
);
2015 read_neon_element32(rm
, a
->vm
, 0, MO_32
);
2018 read_neon_element32(rn
, a
->vn
, 1, MO_32
);
2019 read_neon_element32(rm
, a
->vm
, 1, MO_32
);
2022 /* Don't store results until after all loads: they might overlap */
2024 tmp
= tcg_temp_new_i64();
2025 read_neon_element64(tmp
, a
->vd
, 0, MO_64
);
2026 accfn(rd0
, tmp
, rd0
);
2027 read_neon_element64(tmp
, a
->vd
, 1, MO_64
);
2028 accfn(rd1
, tmp
, rd1
);
2031 write_neon_element64(rd0
, a
->vd
, 0, MO_64
);
2032 write_neon_element64(rd1
, a
->vd
, 1, MO_64
);
2037 static bool trans_VABDL_S_3d(DisasContext
*s
, arg_3diff
*a
)
2039 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2040 gen_helper_neon_abdl_s16
,
2041 gen_helper_neon_abdl_s32
,
2042 gen_helper_neon_abdl_s64
,
2046 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2049 static bool trans_VABDL_U_3d(DisasContext
*s
, arg_3diff
*a
)
2051 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2052 gen_helper_neon_abdl_u16
,
2053 gen_helper_neon_abdl_u32
,
2054 gen_helper_neon_abdl_u64
,
2058 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2061 static bool trans_VABAL_S_3d(DisasContext
*s
, arg_3diff
*a
)
2063 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2064 gen_helper_neon_abdl_s16
,
2065 gen_helper_neon_abdl_s32
,
2066 gen_helper_neon_abdl_s64
,
2069 static NeonGenTwo64OpFn
* const addfn
[] = {
2070 gen_helper_neon_addl_u16
,
2071 gen_helper_neon_addl_u32
,
2076 return do_long_3d(s
, a
, opfn
[a
->size
], addfn
[a
->size
]);
2079 static bool trans_VABAL_U_3d(DisasContext
*s
, arg_3diff
*a
)
2081 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2082 gen_helper_neon_abdl_u16
,
2083 gen_helper_neon_abdl_u32
,
2084 gen_helper_neon_abdl_u64
,
2087 static NeonGenTwo64OpFn
* const addfn
[] = {
2088 gen_helper_neon_addl_u16
,
2089 gen_helper_neon_addl_u32
,
2094 return do_long_3d(s
, a
, opfn
[a
->size
], addfn
[a
->size
]);
2097 static void gen_mull_s32(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2099 TCGv_i32 lo
= tcg_temp_new_i32();
2100 TCGv_i32 hi
= tcg_temp_new_i32();
2102 tcg_gen_muls2_i32(lo
, hi
, rn
, rm
);
2103 tcg_gen_concat_i32_i64(rd
, lo
, hi
);
2106 static void gen_mull_u32(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2108 TCGv_i32 lo
= tcg_temp_new_i32();
2109 TCGv_i32 hi
= tcg_temp_new_i32();
2111 tcg_gen_mulu2_i32(lo
, hi
, rn
, rm
);
2112 tcg_gen_concat_i32_i64(rd
, lo
, hi
);
2115 static bool trans_VMULL_S_3d(DisasContext
*s
, arg_3diff
*a
)
2117 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2118 gen_helper_neon_mull_s8
,
2119 gen_helper_neon_mull_s16
,
2124 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2127 static bool trans_VMULL_U_3d(DisasContext
*s
, arg_3diff
*a
)
2129 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2130 gen_helper_neon_mull_u8
,
2131 gen_helper_neon_mull_u16
,
2136 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2139 #define DO_VMLAL(INSN,MULL,ACC) \
2140 static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a) \
2142 static NeonGenTwoOpWidenFn * const opfn[] = { \
2143 gen_helper_neon_##MULL##8, \
2144 gen_helper_neon_##MULL##16, \
2148 static NeonGenTwo64OpFn * const accfn[] = { \
2149 gen_helper_neon_##ACC##l_u16, \
2150 gen_helper_neon_##ACC##l_u32, \
2151 tcg_gen_##ACC##_i64, \
2154 return do_long_3d(s, a, opfn[a->size], accfn[a->size]); \
2157 DO_VMLAL(VMLAL_S
,mull_s
,add
)
2158 DO_VMLAL(VMLAL_U
,mull_u
,add
)
2159 DO_VMLAL(VMLSL_S
,mull_s
,sub
)
2160 DO_VMLAL(VMLSL_U
,mull_u
,sub
)
2162 static void gen_VQDMULL_16(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2164 gen_helper_neon_mull_s16(rd
, rn
, rm
);
2165 gen_helper_neon_addl_saturate_s32(rd
, cpu_env
, rd
, rd
);
2168 static void gen_VQDMULL_32(TCGv_i64 rd
, TCGv_i32 rn
, TCGv_i32 rm
)
2170 gen_mull_s32(rd
, rn
, rm
);
2171 gen_helper_neon_addl_saturate_s64(rd
, cpu_env
, rd
, rd
);
2174 static bool trans_VQDMULL_3d(DisasContext
*s
, arg_3diff
*a
)
2176 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2183 return do_long_3d(s
, a
, opfn
[a
->size
], NULL
);
2186 static void gen_VQDMLAL_acc_16(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2188 gen_helper_neon_addl_saturate_s32(rd
, cpu_env
, rn
, rm
);
2191 static void gen_VQDMLAL_acc_32(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2193 gen_helper_neon_addl_saturate_s64(rd
, cpu_env
, rn
, rm
);
2196 static bool trans_VQDMLAL_3d(DisasContext
*s
, arg_3diff
*a
)
2198 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2204 static NeonGenTwo64OpFn
* const accfn
[] = {
2211 return do_long_3d(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2214 static void gen_VQDMLSL_acc_16(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2216 gen_helper_neon_negl_u32(rm
, rm
);
2217 gen_helper_neon_addl_saturate_s32(rd
, cpu_env
, rn
, rm
);
2220 static void gen_VQDMLSL_acc_32(TCGv_i64 rd
, TCGv_i64 rn
, TCGv_i64 rm
)
2222 tcg_gen_neg_i64(rm
, rm
);
2223 gen_helper_neon_addl_saturate_s64(rd
, cpu_env
, rn
, rm
);
2226 static bool trans_VQDMLSL_3d(DisasContext
*s
, arg_3diff
*a
)
2228 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2234 static NeonGenTwo64OpFn
* const accfn
[] = {
2241 return do_long_3d(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2244 static bool trans_VMULL_P_3d(DisasContext
*s
, arg_3diff
*a
)
2246 gen_helper_gvec_3
*fn_gvec
;
2248 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2252 /* UNDEF accesses to D16-D31 if they don't exist. */
2253 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2254 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2264 fn_gvec
= gen_helper_neon_pmull_h
;
2267 if (!dc_isar_feature(aa32_pmull
, s
)) {
2270 fn_gvec
= gen_helper_gvec_pmull_q
;
2276 if (!vfp_access_check(s
)) {
2280 tcg_gen_gvec_3_ool(neon_full_reg_offset(a
->vd
),
2281 neon_full_reg_offset(a
->vn
),
2282 neon_full_reg_offset(a
->vm
),
2283 16, 16, 0, fn_gvec
);
2287 static void gen_neon_dup_low16(TCGv_i32 var
)
2289 TCGv_i32 tmp
= tcg_temp_new_i32();
2290 tcg_gen_ext16u_i32(var
, var
);
2291 tcg_gen_shli_i32(tmp
, var
, 16);
2292 tcg_gen_or_i32(var
, var
, tmp
);
2295 static void gen_neon_dup_high16(TCGv_i32 var
)
2297 TCGv_i32 tmp
= tcg_temp_new_i32();
2298 tcg_gen_andi_i32(var
, var
, 0xffff0000);
2299 tcg_gen_shri_i32(tmp
, var
, 16);
2300 tcg_gen_or_i32(var
, var
, tmp
);
2303 static inline TCGv_i32
neon_get_scalar(int size
, int reg
)
2305 TCGv_i32 tmp
= tcg_temp_new_i32();
2306 if (size
== MO_16
) {
2307 read_neon_element32(tmp
, reg
& 7, reg
>> 4, MO_32
);
2309 gen_neon_dup_high16(tmp
);
2311 gen_neon_dup_low16(tmp
);
2314 read_neon_element32(tmp
, reg
& 15, reg
>> 4, MO_32
);
2319 static bool do_2scalar(DisasContext
*s
, arg_2scalar
*a
,
2320 NeonGenTwoOpFn
*opfn
, NeonGenTwoOpFn
*accfn
)
2323 * Two registers and a scalar: perform an operation between
2324 * the input elements and the scalar, and then possibly
2325 * perform an accumulation operation of that result into the
2328 TCGv_i32 scalar
, tmp
;
2331 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2335 /* UNDEF accesses to D16-D31 if they don't exist. */
2336 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2337 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2342 /* Bad size (including size == 3, which is a different insn group) */
2346 if (a
->q
&& ((a
->vd
| a
->vn
) & 1)) {
2350 if (!vfp_access_check(s
)) {
2354 scalar
= neon_get_scalar(a
->size
, a
->vm
);
2355 tmp
= tcg_temp_new_i32();
2357 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
2358 read_neon_element32(tmp
, a
->vn
, pass
, MO_32
);
2359 opfn(tmp
, tmp
, scalar
);
2361 TCGv_i32 rd
= tcg_temp_new_i32();
2362 read_neon_element32(rd
, a
->vd
, pass
, MO_32
);
2363 accfn(tmp
, rd
, tmp
);
2365 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
2370 static bool trans_VMUL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2372 static NeonGenTwoOpFn
* const opfn
[] = {
2374 gen_helper_neon_mul_u16
,
2379 return do_2scalar(s
, a
, opfn
[a
->size
], NULL
);
2382 static bool trans_VMLA_2sc(DisasContext
*s
, arg_2scalar
*a
)
2384 static NeonGenTwoOpFn
* const opfn
[] = {
2386 gen_helper_neon_mul_u16
,
2390 static NeonGenTwoOpFn
* const accfn
[] = {
2392 gen_helper_neon_add_u16
,
2397 return do_2scalar(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2400 static bool trans_VMLS_2sc(DisasContext
*s
, arg_2scalar
*a
)
2402 static NeonGenTwoOpFn
* const opfn
[] = {
2404 gen_helper_neon_mul_u16
,
2408 static NeonGenTwoOpFn
* const accfn
[] = {
2410 gen_helper_neon_sub_u16
,
2415 return do_2scalar(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2418 static bool do_2scalar_fp_vec(DisasContext
*s
, arg_2scalar
*a
,
2419 gen_helper_gvec_3_ptr
*fn
)
2421 /* Two registers and a scalar, using gvec */
2422 int vec_size
= a
->q
? 16 : 8;
2423 int rd_ofs
= neon_full_reg_offset(a
->vd
);
2424 int rn_ofs
= neon_full_reg_offset(a
->vn
);
2429 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2433 /* UNDEF accesses to D16-D31 if they don't exist. */
2434 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2435 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2440 /* Bad size (including size == 3, which is a different insn group) */
2444 if (a
->q
&& ((a
->vd
| a
->vn
) & 1)) {
2448 if (!vfp_access_check(s
)) {
2452 /* a->vm is M:Vm, which encodes both register and index */
2453 idx
= extract32(a
->vm
, a
->size
+ 2, 2);
2454 a
->vm
= extract32(a
->vm
, 0, a
->size
+ 2);
2455 rm_ofs
= neon_full_reg_offset(a
->vm
);
2457 fpstatus
= fpstatus_ptr(a
->size
== 1 ? FPST_STD_F16
: FPST_STD
);
2458 tcg_gen_gvec_3_ptr(rd_ofs
, rn_ofs
, rm_ofs
, fpstatus
,
2459 vec_size
, vec_size
, idx
, fn
);
2463 #define DO_VMUL_F_2sc(NAME, FUNC) \
2464 static bool trans_##NAME##_F_2sc(DisasContext *s, arg_2scalar *a) \
2466 static gen_helper_gvec_3_ptr * const opfn[] = { \
2468 gen_helper_##FUNC##_h, \
2469 gen_helper_##FUNC##_s, \
2472 if (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s)) { \
2475 return do_2scalar_fp_vec(s, a, opfn[a->size]); \
2478 DO_VMUL_F_2sc(VMUL
, gvec_fmul_idx
)
2479 DO_VMUL_F_2sc(VMLA
, gvec_fmla_nf_idx
)
2480 DO_VMUL_F_2sc(VMLS
, gvec_fmls_nf_idx
)
2482 WRAP_ENV_FN(gen_VQDMULH_16
, gen_helper_neon_qdmulh_s16
)
2483 WRAP_ENV_FN(gen_VQDMULH_32
, gen_helper_neon_qdmulh_s32
)
2484 WRAP_ENV_FN(gen_VQRDMULH_16
, gen_helper_neon_qrdmulh_s16
)
2485 WRAP_ENV_FN(gen_VQRDMULH_32
, gen_helper_neon_qrdmulh_s32
)
2487 static bool trans_VQDMULH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2489 static NeonGenTwoOpFn
* const opfn
[] = {
2496 return do_2scalar(s
, a
, opfn
[a
->size
], NULL
);
2499 static bool trans_VQRDMULH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2501 static NeonGenTwoOpFn
* const opfn
[] = {
2508 return do_2scalar(s
, a
, opfn
[a
->size
], NULL
);
2511 static bool do_vqrdmlah_2sc(DisasContext
*s
, arg_2scalar
*a
,
2512 NeonGenThreeOpEnvFn
*opfn
)
2515 * VQRDMLAH/VQRDMLSH: this is like do_2scalar, but the opfn
2516 * performs a kind of fused op-then-accumulate using a helper
2517 * function that takes all of rd, rn and the scalar at once.
2519 TCGv_i32 scalar
, rn
, rd
;
2522 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2526 if (!dc_isar_feature(aa32_rdm
, s
)) {
2530 /* UNDEF accesses to D16-D31 if they don't exist. */
2531 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2532 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2537 /* Bad size (including size == 3, which is a different insn group) */
2541 if (a
->q
&& ((a
->vd
| a
->vn
) & 1)) {
2545 if (!vfp_access_check(s
)) {
2549 scalar
= neon_get_scalar(a
->size
, a
->vm
);
2550 rn
= tcg_temp_new_i32();
2551 rd
= tcg_temp_new_i32();
2553 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
2554 read_neon_element32(rn
, a
->vn
, pass
, MO_32
);
2555 read_neon_element32(rd
, a
->vd
, pass
, MO_32
);
2556 opfn(rd
, cpu_env
, rn
, scalar
, rd
);
2557 write_neon_element32(rd
, a
->vd
, pass
, MO_32
);
2562 static bool trans_VQRDMLAH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2564 static NeonGenThreeOpEnvFn
*opfn
[] = {
2566 gen_helper_neon_qrdmlah_s16
,
2567 gen_helper_neon_qrdmlah_s32
,
2570 return do_vqrdmlah_2sc(s
, a
, opfn
[a
->size
]);
2573 static bool trans_VQRDMLSH_2sc(DisasContext
*s
, arg_2scalar
*a
)
2575 static NeonGenThreeOpEnvFn
*opfn
[] = {
2577 gen_helper_neon_qrdmlsh_s16
,
2578 gen_helper_neon_qrdmlsh_s32
,
2581 return do_vqrdmlah_2sc(s
, a
, opfn
[a
->size
]);
2584 static bool do_2scalar_long(DisasContext
*s
, arg_2scalar
*a
,
2585 NeonGenTwoOpWidenFn
*opfn
,
2586 NeonGenTwo64OpFn
*accfn
)
2589 * Two registers and a scalar, long operations: perform an
2590 * operation on the input elements and the scalar which produces
2591 * a double-width result, and then possibly perform an accumulation
2592 * operation of that result into the destination.
2594 TCGv_i32 scalar
, rn
;
2595 TCGv_i64 rn0_64
, rn1_64
;
2597 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2601 /* UNDEF accesses to D16-D31 if they don't exist. */
2602 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2603 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2608 /* Bad size (including size == 3, which is a different insn group) */
2616 if (!vfp_access_check(s
)) {
2620 scalar
= neon_get_scalar(a
->size
, a
->vm
);
2622 /* Load all inputs before writing any outputs, in case of overlap */
2623 rn
= tcg_temp_new_i32();
2624 read_neon_element32(rn
, a
->vn
, 0, MO_32
);
2625 rn0_64
= tcg_temp_new_i64();
2626 opfn(rn0_64
, rn
, scalar
);
2628 read_neon_element32(rn
, a
->vn
, 1, MO_32
);
2629 rn1_64
= tcg_temp_new_i64();
2630 opfn(rn1_64
, rn
, scalar
);
2633 TCGv_i64 t64
= tcg_temp_new_i64();
2634 read_neon_element64(t64
, a
->vd
, 0, MO_64
);
2635 accfn(rn0_64
, t64
, rn0_64
);
2636 read_neon_element64(t64
, a
->vd
, 1, MO_64
);
2637 accfn(rn1_64
, t64
, rn1_64
);
2640 write_neon_element64(rn0_64
, a
->vd
, 0, MO_64
);
2641 write_neon_element64(rn1_64
, a
->vd
, 1, MO_64
);
2645 static bool trans_VMULL_S_2sc(DisasContext
*s
, arg_2scalar
*a
)
2647 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2649 gen_helper_neon_mull_s16
,
2654 return do_2scalar_long(s
, a
, opfn
[a
->size
], NULL
);
2657 static bool trans_VMULL_U_2sc(DisasContext
*s
, arg_2scalar
*a
)
2659 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2661 gen_helper_neon_mull_u16
,
2666 return do_2scalar_long(s
, a
, opfn
[a
->size
], NULL
);
2669 #define DO_VMLAL_2SC(INSN, MULL, ACC) \
2670 static bool trans_##INSN##_2sc(DisasContext *s, arg_2scalar *a) \
2672 static NeonGenTwoOpWidenFn * const opfn[] = { \
2674 gen_helper_neon_##MULL##16, \
2678 static NeonGenTwo64OpFn * const accfn[] = { \
2680 gen_helper_neon_##ACC##l_u32, \
2681 tcg_gen_##ACC##_i64, \
2684 return do_2scalar_long(s, a, opfn[a->size], accfn[a->size]); \
2687 DO_VMLAL_2SC(VMLAL_S
, mull_s
, add
)
2688 DO_VMLAL_2SC(VMLAL_U
, mull_u
, add
)
2689 DO_VMLAL_2SC(VMLSL_S
, mull_s
, sub
)
2690 DO_VMLAL_2SC(VMLSL_U
, mull_u
, sub
)
2692 static bool trans_VQDMULL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2694 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2701 return do_2scalar_long(s
, a
, opfn
[a
->size
], NULL
);
2704 static bool trans_VQDMLAL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2706 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2712 static NeonGenTwo64OpFn
* const accfn
[] = {
2719 return do_2scalar_long(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2722 static bool trans_VQDMLSL_2sc(DisasContext
*s
, arg_2scalar
*a
)
2724 static NeonGenTwoOpWidenFn
* const opfn
[] = {
2730 static NeonGenTwo64OpFn
* const accfn
[] = {
2737 return do_2scalar_long(s
, a
, opfn
[a
->size
], accfn
[a
->size
]);
2740 static bool trans_VEXT(DisasContext
*s
, arg_VEXT
*a
)
2742 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2746 /* UNDEF accesses to D16-D31 if they don't exist. */
2747 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2748 ((a
->vd
| a
->vn
| a
->vm
) & 0x10)) {
2752 if ((a
->vn
| a
->vm
| a
->vd
) & a
->q
) {
2756 if (a
->imm
> 7 && !a
->q
) {
2760 if (!vfp_access_check(s
)) {
2765 /* Extract 64 bits from <Vm:Vn> */
2766 TCGv_i64 left
, right
, dest
;
2768 left
= tcg_temp_new_i64();
2769 right
= tcg_temp_new_i64();
2770 dest
= tcg_temp_new_i64();
2772 read_neon_element64(right
, a
->vn
, 0, MO_64
);
2773 read_neon_element64(left
, a
->vm
, 0, MO_64
);
2774 tcg_gen_extract2_i64(dest
, right
, left
, a
->imm
* 8);
2775 write_neon_element64(dest
, a
->vd
, 0, MO_64
);
2777 /* Extract 128 bits from <Vm+1:Vm:Vn+1:Vn> */
2778 TCGv_i64 left
, middle
, right
, destleft
, destright
;
2780 left
= tcg_temp_new_i64();
2781 middle
= tcg_temp_new_i64();
2782 right
= tcg_temp_new_i64();
2783 destleft
= tcg_temp_new_i64();
2784 destright
= tcg_temp_new_i64();
2787 read_neon_element64(right
, a
->vn
, 0, MO_64
);
2788 read_neon_element64(middle
, a
->vn
, 1, MO_64
);
2789 tcg_gen_extract2_i64(destright
, right
, middle
, a
->imm
* 8);
2790 read_neon_element64(left
, a
->vm
, 0, MO_64
);
2791 tcg_gen_extract2_i64(destleft
, middle
, left
, a
->imm
* 8);
2793 read_neon_element64(right
, a
->vn
, 1, MO_64
);
2794 read_neon_element64(middle
, a
->vm
, 0, MO_64
);
2795 tcg_gen_extract2_i64(destright
, right
, middle
, (a
->imm
- 8) * 8);
2796 read_neon_element64(left
, a
->vm
, 1, MO_64
);
2797 tcg_gen_extract2_i64(destleft
, middle
, left
, (a
->imm
- 8) * 8);
2800 write_neon_element64(destright
, a
->vd
, 0, MO_64
);
2801 write_neon_element64(destleft
, a
->vd
, 1, MO_64
);
2806 static bool trans_VTBL(DisasContext
*s
, arg_VTBL
*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
->len
+ 1) > 32) {
2823 * This is UNPREDICTABLE; we choose to UNDEF to avoid the
2824 * helper function running off the end of the register file.
2829 if (!vfp_access_check(s
)) {
2833 desc
= tcg_constant_i32((a
->vn
<< 2) | a
->len
);
2834 def
= tcg_temp_new_i64();
2836 read_neon_element64(def
, a
->vd
, 0, MO_64
);
2838 tcg_gen_movi_i64(def
, 0);
2840 val
= tcg_temp_new_i64();
2841 read_neon_element64(val
, a
->vm
, 0, MO_64
);
2843 gen_helper_neon_tbl(val
, cpu_env
, desc
, val
, def
);
2844 write_neon_element64(val
, a
->vd
, 0, MO_64
);
2848 static bool trans_VDUP_scalar(DisasContext
*s
, arg_VDUP_scalar
*a
)
2850 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2854 /* UNDEF accesses to D16-D31 if they don't exist. */
2855 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2856 ((a
->vd
| a
->vm
) & 0x10)) {
2864 if (!vfp_access_check(s
)) {
2868 tcg_gen_gvec_dup_mem(a
->size
, neon_full_reg_offset(a
->vd
),
2869 neon_element_offset(a
->vm
, a
->index
, a
->size
),
2870 a
->q
? 16 : 8, a
->q
? 16 : 8);
2874 static bool trans_VREV64(DisasContext
*s
, arg_VREV64
*a
)
2879 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2883 /* UNDEF accesses to D16-D31 if they don't exist. */
2884 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2885 ((a
->vd
| a
->vm
) & 0x10)) {
2889 if ((a
->vd
| a
->vm
) & a
->q
) {
2897 if (!vfp_access_check(s
)) {
2901 tmp
[0] = tcg_temp_new_i32();
2902 tmp
[1] = tcg_temp_new_i32();
2904 for (pass
= 0; pass
< (a
->q
? 2 : 1); pass
++) {
2905 for (half
= 0; half
< 2; half
++) {
2906 read_neon_element32(tmp
[half
], a
->vm
, pass
* 2 + half
, MO_32
);
2909 tcg_gen_bswap32_i32(tmp
[half
], tmp
[half
]);
2912 gen_swap_half(tmp
[half
], tmp
[half
]);
2917 g_assert_not_reached();
2920 write_neon_element32(tmp
[1], a
->vd
, pass
* 2, MO_32
);
2921 write_neon_element32(tmp
[0], a
->vd
, pass
* 2 + 1, MO_32
);
2926 static bool do_2misc_pairwise(DisasContext
*s
, arg_2misc
*a
,
2927 NeonGenWidenFn
*widenfn
,
2928 NeonGenTwo64OpFn
*opfn
,
2929 NeonGenTwo64OpFn
*accfn
)
2932 * Pairwise long operations: widen both halves of the pair,
2933 * combine the pairs with the opfn, and then possibly accumulate
2934 * into the destination with the accfn.
2938 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
2942 /* UNDEF accesses to D16-D31 if they don't exist. */
2943 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
2944 ((a
->vd
| a
->vm
) & 0x10)) {
2948 if ((a
->vd
| a
->vm
) & a
->q
) {
2956 if (!vfp_access_check(s
)) {
2960 for (pass
= 0; pass
< a
->q
+ 1; pass
++) {
2962 TCGv_i64 rm0_64
, rm1_64
, rd_64
;
2964 rm0_64
= tcg_temp_new_i64();
2965 rm1_64
= tcg_temp_new_i64();
2966 rd_64
= tcg_temp_new_i64();
2968 tmp
= tcg_temp_new_i32();
2969 read_neon_element32(tmp
, a
->vm
, pass
* 2, MO_32
);
2970 widenfn(rm0_64
, tmp
);
2971 read_neon_element32(tmp
, a
->vm
, pass
* 2 + 1, MO_32
);
2972 widenfn(rm1_64
, tmp
);
2974 opfn(rd_64
, rm0_64
, rm1_64
);
2977 TCGv_i64 tmp64
= tcg_temp_new_i64();
2978 read_neon_element64(tmp64
, a
->vd
, pass
, MO_64
);
2979 accfn(rd_64
, tmp64
, rd_64
);
2981 write_neon_element64(rd_64
, a
->vd
, pass
, MO_64
);
2986 static bool trans_VPADDL_S(DisasContext
*s
, arg_2misc
*a
)
2988 static NeonGenWidenFn
* const widenfn
[] = {
2989 gen_helper_neon_widen_s8
,
2990 gen_helper_neon_widen_s16
,
2991 tcg_gen_ext_i32_i64
,
2994 static NeonGenTwo64OpFn
* const opfn
[] = {
2995 gen_helper_neon_paddl_u16
,
2996 gen_helper_neon_paddl_u32
,
3001 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
], NULL
);
3004 static bool trans_VPADDL_U(DisasContext
*s
, arg_2misc
*a
)
3006 static NeonGenWidenFn
* const widenfn
[] = {
3007 gen_helper_neon_widen_u8
,
3008 gen_helper_neon_widen_u16
,
3009 tcg_gen_extu_i32_i64
,
3012 static NeonGenTwo64OpFn
* const opfn
[] = {
3013 gen_helper_neon_paddl_u16
,
3014 gen_helper_neon_paddl_u32
,
3019 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
], NULL
);
3022 static bool trans_VPADAL_S(DisasContext
*s
, arg_2misc
*a
)
3024 static NeonGenWidenFn
* const widenfn
[] = {
3025 gen_helper_neon_widen_s8
,
3026 gen_helper_neon_widen_s16
,
3027 tcg_gen_ext_i32_i64
,
3030 static NeonGenTwo64OpFn
* const opfn
[] = {
3031 gen_helper_neon_paddl_u16
,
3032 gen_helper_neon_paddl_u32
,
3036 static NeonGenTwo64OpFn
* const accfn
[] = {
3037 gen_helper_neon_addl_u16
,
3038 gen_helper_neon_addl_u32
,
3043 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
],
3047 static bool trans_VPADAL_U(DisasContext
*s
, arg_2misc
*a
)
3049 static NeonGenWidenFn
* const widenfn
[] = {
3050 gen_helper_neon_widen_u8
,
3051 gen_helper_neon_widen_u16
,
3052 tcg_gen_extu_i32_i64
,
3055 static NeonGenTwo64OpFn
* const opfn
[] = {
3056 gen_helper_neon_paddl_u16
,
3057 gen_helper_neon_paddl_u32
,
3061 static NeonGenTwo64OpFn
* const accfn
[] = {
3062 gen_helper_neon_addl_u16
,
3063 gen_helper_neon_addl_u32
,
3068 return do_2misc_pairwise(s
, a
, widenfn
[a
->size
], opfn
[a
->size
],
3072 typedef void ZipFn(TCGv_ptr
, TCGv_ptr
);
3074 static bool do_zip_uzp(DisasContext
*s
, arg_2misc
*a
,
3079 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3083 /* UNDEF accesses to D16-D31 if they don't exist. */
3084 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3085 ((a
->vd
| a
->vm
) & 0x10)) {
3089 if ((a
->vd
| a
->vm
) & a
->q
) {
3094 /* Bad size or size/q combination */
3098 if (!vfp_access_check(s
)) {
3102 pd
= vfp_reg_ptr(true, a
->vd
);
3103 pm
= vfp_reg_ptr(true, a
->vm
);
3108 static bool trans_VUZP(DisasContext
*s
, arg_2misc
*a
)
3110 static ZipFn
* const fn
[2][4] = {
3112 gen_helper_neon_unzip8
,
3113 gen_helper_neon_unzip16
,
3117 gen_helper_neon_qunzip8
,
3118 gen_helper_neon_qunzip16
,
3119 gen_helper_neon_qunzip32
,
3123 return do_zip_uzp(s
, a
, fn
[a
->q
][a
->size
]);
3126 static bool trans_VZIP(DisasContext
*s
, arg_2misc
*a
)
3128 static ZipFn
* const fn
[2][4] = {
3130 gen_helper_neon_zip8
,
3131 gen_helper_neon_zip16
,
3135 gen_helper_neon_qzip8
,
3136 gen_helper_neon_qzip16
,
3137 gen_helper_neon_qzip32
,
3141 return do_zip_uzp(s
, a
, fn
[a
->q
][a
->size
]);
3144 static bool do_vmovn(DisasContext
*s
, arg_2misc
*a
,
3145 NeonGenNarrowEnvFn
*narrowfn
)
3150 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3154 /* UNDEF accesses to D16-D31 if they don't exist. */
3155 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3156 ((a
->vd
| a
->vm
) & 0x10)) {
3168 if (!vfp_access_check(s
)) {
3172 rm
= tcg_temp_new_i64();
3173 rd0
= tcg_temp_new_i32();
3174 rd1
= tcg_temp_new_i32();
3176 read_neon_element64(rm
, a
->vm
, 0, MO_64
);
3177 narrowfn(rd0
, cpu_env
, rm
);
3178 read_neon_element64(rm
, a
->vm
, 1, MO_64
);
3179 narrowfn(rd1
, cpu_env
, rm
);
3180 write_neon_element32(rd0
, a
->vd
, 0, MO_32
);
3181 write_neon_element32(rd1
, a
->vd
, 1, MO_32
);
3185 #define DO_VMOVN(INSN, FUNC) \
3186 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3188 static NeonGenNarrowEnvFn * const narrowfn[] = { \
3194 return do_vmovn(s, a, narrowfn[a->size]); \
3197 DO_VMOVN(VMOVN
, gen_neon_narrow_u
)
3198 DO_VMOVN(VQMOVUN
, gen_helper_neon_unarrow_sat
)
3199 DO_VMOVN(VQMOVN_S
, gen_helper_neon_narrow_sat_s
)
3200 DO_VMOVN(VQMOVN_U
, gen_helper_neon_narrow_sat_u
)
3202 static bool trans_VSHLL(DisasContext
*s
, arg_2misc
*a
)
3206 static NeonGenWidenFn
* const widenfns
[] = {
3207 gen_helper_neon_widen_u8
,
3208 gen_helper_neon_widen_u16
,
3209 tcg_gen_extu_i32_i64
,
3212 NeonGenWidenFn
*widenfn
= widenfns
[a
->size
];
3214 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3218 /* UNDEF accesses to D16-D31 if they don't exist. */
3219 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3220 ((a
->vd
| a
->vm
) & 0x10)) {
3232 if (!vfp_access_check(s
)) {
3236 rd
= tcg_temp_new_i64();
3237 rm0
= tcg_temp_new_i32();
3238 rm1
= tcg_temp_new_i32();
3240 read_neon_element32(rm0
, a
->vm
, 0, MO_32
);
3241 read_neon_element32(rm1
, a
->vm
, 1, MO_32
);
3244 tcg_gen_shli_i64(rd
, rd
, 8 << a
->size
);
3245 write_neon_element64(rd
, a
->vd
, 0, MO_64
);
3247 tcg_gen_shli_i64(rd
, rd
, 8 << a
->size
);
3248 write_neon_element64(rd
, a
->vd
, 1, MO_64
);
3252 static bool trans_VCVT_B16_F32(DisasContext
*s
, arg_2misc
*a
)
3256 TCGv_i32 dst0
, dst1
;
3258 if (!dc_isar_feature(aa32_bf16
, s
)) {
3262 /* UNDEF accesses to D16-D31 if they don't exist. */
3263 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3264 ((a
->vd
| a
->vm
) & 0x10)) {
3268 if ((a
->vm
& 1) || (a
->size
!= 1)) {
3272 if (!vfp_access_check(s
)) {
3276 fpst
= fpstatus_ptr(FPST_STD
);
3277 tmp
= tcg_temp_new_i64();
3278 dst0
= tcg_temp_new_i32();
3279 dst1
= tcg_temp_new_i32();
3281 read_neon_element64(tmp
, a
->vm
, 0, MO_64
);
3282 gen_helper_bfcvt_pair(dst0
, tmp
, fpst
);
3284 read_neon_element64(tmp
, a
->vm
, 1, MO_64
);
3285 gen_helper_bfcvt_pair(dst1
, tmp
, fpst
);
3287 write_neon_element32(dst0
, a
->vd
, 0, MO_32
);
3288 write_neon_element32(dst1
, a
->vd
, 1, MO_32
);
3292 static bool trans_VCVT_F16_F32(DisasContext
*s
, arg_2misc
*a
)
3295 TCGv_i32 ahp
, tmp
, tmp2
, tmp3
;
3297 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
) ||
3298 !dc_isar_feature(aa32_fp16_spconv
, s
)) {
3302 /* UNDEF accesses to D16-D31 if they don't exist. */
3303 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3304 ((a
->vd
| a
->vm
) & 0x10)) {
3308 if ((a
->vm
& 1) || (a
->size
!= 1)) {
3312 if (!vfp_access_check(s
)) {
3316 fpst
= fpstatus_ptr(FPST_STD
);
3317 ahp
= get_ahp_flag();
3318 tmp
= tcg_temp_new_i32();
3319 read_neon_element32(tmp
, a
->vm
, 0, MO_32
);
3320 gen_helper_vfp_fcvt_f32_to_f16(tmp
, tmp
, fpst
, ahp
);
3321 tmp2
= tcg_temp_new_i32();
3322 read_neon_element32(tmp2
, a
->vm
, 1, MO_32
);
3323 gen_helper_vfp_fcvt_f32_to_f16(tmp2
, tmp2
, fpst
, ahp
);
3324 tcg_gen_shli_i32(tmp2
, tmp2
, 16);
3325 tcg_gen_or_i32(tmp2
, tmp2
, tmp
);
3326 read_neon_element32(tmp
, a
->vm
, 2, MO_32
);
3327 gen_helper_vfp_fcvt_f32_to_f16(tmp
, tmp
, fpst
, ahp
);
3328 tmp3
= tcg_temp_new_i32();
3329 read_neon_element32(tmp3
, a
->vm
, 3, MO_32
);
3330 write_neon_element32(tmp2
, a
->vd
, 0, MO_32
);
3331 gen_helper_vfp_fcvt_f32_to_f16(tmp3
, tmp3
, fpst
, ahp
);
3332 tcg_gen_shli_i32(tmp3
, tmp3
, 16);
3333 tcg_gen_or_i32(tmp3
, tmp3
, tmp
);
3334 write_neon_element32(tmp3
, a
->vd
, 1, MO_32
);
3338 static bool trans_VCVT_F32_F16(DisasContext
*s
, arg_2misc
*a
)
3341 TCGv_i32 ahp
, tmp
, tmp2
, tmp3
;
3343 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
) ||
3344 !dc_isar_feature(aa32_fp16_spconv
, s
)) {
3348 /* UNDEF accesses to D16-D31 if they don't exist. */
3349 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3350 ((a
->vd
| a
->vm
) & 0x10)) {
3354 if ((a
->vd
& 1) || (a
->size
!= 1)) {
3358 if (!vfp_access_check(s
)) {
3362 fpst
= fpstatus_ptr(FPST_STD
);
3363 ahp
= get_ahp_flag();
3364 tmp3
= tcg_temp_new_i32();
3365 tmp2
= tcg_temp_new_i32();
3366 tmp
= tcg_temp_new_i32();
3367 read_neon_element32(tmp
, a
->vm
, 0, MO_32
);
3368 read_neon_element32(tmp2
, a
->vm
, 1, MO_32
);
3369 tcg_gen_ext16u_i32(tmp3
, tmp
);
3370 gen_helper_vfp_fcvt_f16_to_f32(tmp3
, tmp3
, fpst
, ahp
);
3371 write_neon_element32(tmp3
, a
->vd
, 0, MO_32
);
3372 tcg_gen_shri_i32(tmp
, tmp
, 16);
3373 gen_helper_vfp_fcvt_f16_to_f32(tmp
, tmp
, fpst
, ahp
);
3374 write_neon_element32(tmp
, a
->vd
, 1, MO_32
);
3375 tcg_gen_ext16u_i32(tmp3
, tmp2
);
3376 gen_helper_vfp_fcvt_f16_to_f32(tmp3
, tmp3
, fpst
, ahp
);
3377 write_neon_element32(tmp3
, a
->vd
, 2, MO_32
);
3378 tcg_gen_shri_i32(tmp2
, tmp2
, 16);
3379 gen_helper_vfp_fcvt_f16_to_f32(tmp2
, tmp2
, fpst
, ahp
);
3380 write_neon_element32(tmp2
, a
->vd
, 3, MO_32
);
3384 static bool do_2misc_vec(DisasContext
*s
, arg_2misc
*a
, GVecGen2Fn
*fn
)
3386 int vec_size
= a
->q
? 16 : 8;
3387 int rd_ofs
= neon_full_reg_offset(a
->vd
);
3388 int rm_ofs
= neon_full_reg_offset(a
->vm
);
3390 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3394 /* UNDEF accesses to D16-D31 if they don't exist. */
3395 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3396 ((a
->vd
| a
->vm
) & 0x10)) {
3404 if ((a
->vd
| a
->vm
) & a
->q
) {
3408 if (!vfp_access_check(s
)) {
3412 fn(a
->size
, rd_ofs
, rm_ofs
, vec_size
, vec_size
);
3417 #define DO_2MISC_VEC(INSN, FN) \
3418 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3420 return do_2misc_vec(s, a, FN); \
3423 DO_2MISC_VEC(VNEG
, tcg_gen_gvec_neg
)
3424 DO_2MISC_VEC(VABS
, tcg_gen_gvec_abs
)
3425 DO_2MISC_VEC(VCEQ0
, gen_gvec_ceq0
)
3426 DO_2MISC_VEC(VCGT0
, gen_gvec_cgt0
)
3427 DO_2MISC_VEC(VCLE0
, gen_gvec_cle0
)
3428 DO_2MISC_VEC(VCGE0
, gen_gvec_cge0
)
3429 DO_2MISC_VEC(VCLT0
, gen_gvec_clt0
)
3431 static bool trans_VMVN(DisasContext
*s
, arg_2misc
*a
)
3436 return do_2misc_vec(s
, a
, tcg_gen_gvec_not
);
3439 #define WRAP_2M_3_OOL_FN(WRAPNAME, FUNC, DATA) \
3440 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \
3441 uint32_t rm_ofs, uint32_t oprsz, \
3444 tcg_gen_gvec_3_ool(rd_ofs, rd_ofs, rm_ofs, oprsz, maxsz, \
3448 #define WRAP_2M_2_OOL_FN(WRAPNAME, FUNC, DATA) \
3449 static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \
3450 uint32_t rm_ofs, uint32_t oprsz, \
3453 tcg_gen_gvec_2_ool(rd_ofs, rm_ofs, oprsz, maxsz, DATA, FUNC); \
3456 WRAP_2M_3_OOL_FN(gen_AESE
, gen_helper_crypto_aese
, 0)
3457 WRAP_2M_3_OOL_FN(gen_AESD
, gen_helper_crypto_aese
, 1)
3458 WRAP_2M_2_OOL_FN(gen_AESMC
, gen_helper_crypto_aesmc
, 0)
3459 WRAP_2M_2_OOL_FN(gen_AESIMC
, gen_helper_crypto_aesmc
, 1)
3460 WRAP_2M_2_OOL_FN(gen_SHA1H
, gen_helper_crypto_sha1h
, 0)
3461 WRAP_2M_2_OOL_FN(gen_SHA1SU1
, gen_helper_crypto_sha1su1
, 0)
3462 WRAP_2M_2_OOL_FN(gen_SHA256SU0
, gen_helper_crypto_sha256su0
, 0)
3464 #define DO_2M_CRYPTO(INSN, FEATURE, SIZE) \
3465 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3467 if (!dc_isar_feature(FEATURE, s) || a->size != SIZE) { \
3470 return do_2misc_vec(s, a, gen_##INSN); \
3473 DO_2M_CRYPTO(AESE
, aa32_aes
, 0)
3474 DO_2M_CRYPTO(AESD
, aa32_aes
, 0)
3475 DO_2M_CRYPTO(AESMC
, aa32_aes
, 0)
3476 DO_2M_CRYPTO(AESIMC
, aa32_aes
, 0)
3477 DO_2M_CRYPTO(SHA1H
, aa32_sha1
, 2)
3478 DO_2M_CRYPTO(SHA1SU1
, aa32_sha1
, 2)
3479 DO_2M_CRYPTO(SHA256SU0
, aa32_sha2
, 2)
3481 static bool do_2misc(DisasContext
*s
, arg_2misc
*a
, NeonGenOneOpFn
*fn
)
3486 /* Handle a 2-reg-misc operation by iterating 32 bits at a time */
3487 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3491 /* UNDEF accesses to D16-D31 if they don't exist. */
3492 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3493 ((a
->vd
| a
->vm
) & 0x10)) {
3501 if ((a
->vd
| a
->vm
) & a
->q
) {
3505 if (!vfp_access_check(s
)) {
3509 tmp
= tcg_temp_new_i32();
3510 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
3511 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
3513 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
3518 static bool trans_VREV32(DisasContext
*s
, arg_2misc
*a
)
3520 static NeonGenOneOpFn
* const fn
[] = {
3521 tcg_gen_bswap32_i32
,
3526 return do_2misc(s
, a
, fn
[a
->size
]);
3529 static bool trans_VREV16(DisasContext
*s
, arg_2misc
*a
)
3534 return do_2misc(s
, a
, gen_rev16
);
3537 static bool trans_VCLS(DisasContext
*s
, arg_2misc
*a
)
3539 static NeonGenOneOpFn
* const fn
[] = {
3540 gen_helper_neon_cls_s8
,
3541 gen_helper_neon_cls_s16
,
3542 gen_helper_neon_cls_s32
,
3545 return do_2misc(s
, a
, fn
[a
->size
]);
3548 static void do_VCLZ_32(TCGv_i32 rd
, TCGv_i32 rm
)
3550 tcg_gen_clzi_i32(rd
, rm
, 32);
3553 static bool trans_VCLZ(DisasContext
*s
, arg_2misc
*a
)
3555 static NeonGenOneOpFn
* const fn
[] = {
3556 gen_helper_neon_clz_u8
,
3557 gen_helper_neon_clz_u16
,
3561 return do_2misc(s
, a
, fn
[a
->size
]);
3564 static bool trans_VCNT(DisasContext
*s
, arg_2misc
*a
)
3569 return do_2misc(s
, a
, gen_helper_neon_cnt_u8
);
3572 static void gen_VABS_F(unsigned vece
, uint32_t rd_ofs
, uint32_t rm_ofs
,
3573 uint32_t oprsz
, uint32_t maxsz
)
3575 tcg_gen_gvec_andi(vece
, rd_ofs
, rm_ofs
,
3576 vece
== MO_16
? 0x7fff : 0x7fffffff,
3580 static bool trans_VABS_F(DisasContext
*s
, arg_2misc
*a
)
3582 if (a
->size
== MO_16
) {
3583 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
3586 } else if (a
->size
!= MO_32
) {
3589 return do_2misc_vec(s
, a
, gen_VABS_F
);
3592 static void gen_VNEG_F(unsigned vece
, uint32_t rd_ofs
, uint32_t rm_ofs
,
3593 uint32_t oprsz
, uint32_t maxsz
)
3595 tcg_gen_gvec_xori(vece
, rd_ofs
, rm_ofs
,
3596 vece
== MO_16
? 0x8000 : 0x80000000,
3600 static bool trans_VNEG_F(DisasContext
*s
, arg_2misc
*a
)
3602 if (a
->size
== MO_16
) {
3603 if (!dc_isar_feature(aa32_fp16_arith
, s
)) {
3606 } else if (a
->size
!= MO_32
) {
3609 return do_2misc_vec(s
, a
, gen_VNEG_F
);
3612 static bool trans_VRECPE(DisasContext
*s
, arg_2misc
*a
)
3617 return do_2misc(s
, a
, gen_helper_recpe_u32
);
3620 static bool trans_VRSQRTE(DisasContext
*s
, arg_2misc
*a
)
3625 return do_2misc(s
, a
, gen_helper_rsqrte_u32
);
3628 #define WRAP_1OP_ENV_FN(WRAPNAME, FUNC) \
3629 static void WRAPNAME(TCGv_i32 d, TCGv_i32 m) \
3631 FUNC(d, cpu_env, m); \
3634 WRAP_1OP_ENV_FN(gen_VQABS_s8
, gen_helper_neon_qabs_s8
)
3635 WRAP_1OP_ENV_FN(gen_VQABS_s16
, gen_helper_neon_qabs_s16
)
3636 WRAP_1OP_ENV_FN(gen_VQABS_s32
, gen_helper_neon_qabs_s32
)
3637 WRAP_1OP_ENV_FN(gen_VQNEG_s8
, gen_helper_neon_qneg_s8
)
3638 WRAP_1OP_ENV_FN(gen_VQNEG_s16
, gen_helper_neon_qneg_s16
)
3639 WRAP_1OP_ENV_FN(gen_VQNEG_s32
, gen_helper_neon_qneg_s32
)
3641 static bool trans_VQABS(DisasContext
*s
, arg_2misc
*a
)
3643 static NeonGenOneOpFn
* const fn
[] = {
3649 return do_2misc(s
, a
, fn
[a
->size
]);
3652 static bool trans_VQNEG(DisasContext
*s
, arg_2misc
*a
)
3654 static NeonGenOneOpFn
* const fn
[] = {
3660 return do_2misc(s
, a
, fn
[a
->size
]);
3663 #define DO_2MISC_FP_VEC(INSN, HFUNC, SFUNC) \
3664 static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \
3666 uint32_t oprsz, uint32_t maxsz) \
3668 static gen_helper_gvec_2_ptr * const fns[4] = { \
3669 NULL, HFUNC, SFUNC, NULL, \
3672 fpst = fpstatus_ptr(vece == MO_16 ? FPST_STD_F16 : FPST_STD); \
3673 tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz, 0, \
3676 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3678 if (a->size == MO_16) { \
3679 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
3682 } else if (a->size != MO_32) { \
3685 return do_2misc_vec(s, a, gen_##INSN); \
3688 DO_2MISC_FP_VEC(VRECPE_F
, gen_helper_gvec_frecpe_h
, gen_helper_gvec_frecpe_s
)
3689 DO_2MISC_FP_VEC(VRSQRTE_F
, gen_helper_gvec_frsqrte_h
, gen_helper_gvec_frsqrte_s
)
3690 DO_2MISC_FP_VEC(VCGT0_F
, gen_helper_gvec_fcgt0_h
, gen_helper_gvec_fcgt0_s
)
3691 DO_2MISC_FP_VEC(VCGE0_F
, gen_helper_gvec_fcge0_h
, gen_helper_gvec_fcge0_s
)
3692 DO_2MISC_FP_VEC(VCEQ0_F
, gen_helper_gvec_fceq0_h
, gen_helper_gvec_fceq0_s
)
3693 DO_2MISC_FP_VEC(VCLT0_F
, gen_helper_gvec_fclt0_h
, gen_helper_gvec_fclt0_s
)
3694 DO_2MISC_FP_VEC(VCLE0_F
, gen_helper_gvec_fcle0_h
, gen_helper_gvec_fcle0_s
)
3695 DO_2MISC_FP_VEC(VCVT_FS
, gen_helper_gvec_sstoh
, gen_helper_gvec_sitos
)
3696 DO_2MISC_FP_VEC(VCVT_FU
, gen_helper_gvec_ustoh
, gen_helper_gvec_uitos
)
3697 DO_2MISC_FP_VEC(VCVT_SF
, gen_helper_gvec_tosszh
, gen_helper_gvec_tosizs
)
3698 DO_2MISC_FP_VEC(VCVT_UF
, gen_helper_gvec_touszh
, gen_helper_gvec_touizs
)
3700 DO_2MISC_FP_VEC(VRINTX_impl
, gen_helper_gvec_vrintx_h
, gen_helper_gvec_vrintx_s
)
3702 static bool trans_VRINTX(DisasContext
*s
, arg_2misc
*a
)
3704 if (!arm_dc_feature(s
, ARM_FEATURE_V8
)) {
3707 return trans_VRINTX_impl(s
, a
);
3710 #define DO_VEC_RMODE(INSN, RMODE, OP) \
3711 static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \
3713 uint32_t oprsz, uint32_t maxsz) \
3715 static gen_helper_gvec_2_ptr * const fns[4] = { \
3717 gen_helper_gvec_##OP##h, \
3718 gen_helper_gvec_##OP##s, \
3722 fpst = fpstatus_ptr(vece == 1 ? FPST_STD_F16 : FPST_STD); \
3723 tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz, \
3724 arm_rmode_to_sf(RMODE), fns[vece]); \
3726 static bool trans_##INSN(DisasContext *s, arg_2misc *a) \
3728 if (!arm_dc_feature(s, ARM_FEATURE_V8)) { \
3731 if (a->size == MO_16) { \
3732 if (!dc_isar_feature(aa32_fp16_arith, s)) { \
3735 } else if (a->size != MO_32) { \
3738 return do_2misc_vec(s, a, gen_##INSN); \
3741 DO_VEC_RMODE(VCVTAU
, FPROUNDING_TIEAWAY
, vcvt_rm_u
)
3742 DO_VEC_RMODE(VCVTAS
, FPROUNDING_TIEAWAY
, vcvt_rm_s
)
3743 DO_VEC_RMODE(VCVTNU
, FPROUNDING_TIEEVEN
, vcvt_rm_u
)
3744 DO_VEC_RMODE(VCVTNS
, FPROUNDING_TIEEVEN
, vcvt_rm_s
)
3745 DO_VEC_RMODE(VCVTPU
, FPROUNDING_POSINF
, vcvt_rm_u
)
3746 DO_VEC_RMODE(VCVTPS
, FPROUNDING_POSINF
, vcvt_rm_s
)
3747 DO_VEC_RMODE(VCVTMU
, FPROUNDING_NEGINF
, vcvt_rm_u
)
3748 DO_VEC_RMODE(VCVTMS
, FPROUNDING_NEGINF
, vcvt_rm_s
)
3750 DO_VEC_RMODE(VRINTN
, FPROUNDING_TIEEVEN
, vrint_rm_
)
3751 DO_VEC_RMODE(VRINTA
, FPROUNDING_TIEAWAY
, vrint_rm_
)
3752 DO_VEC_RMODE(VRINTZ
, FPROUNDING_ZERO
, vrint_rm_
)
3753 DO_VEC_RMODE(VRINTM
, FPROUNDING_NEGINF
, vrint_rm_
)
3754 DO_VEC_RMODE(VRINTP
, FPROUNDING_POSINF
, vrint_rm_
)
3756 static bool trans_VSWP(DisasContext
*s
, arg_2misc
*a
)
3761 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3765 /* UNDEF accesses to D16-D31 if they don't exist. */
3766 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3767 ((a
->vd
| a
->vm
) & 0x10)) {
3775 if ((a
->vd
| a
->vm
) & a
->q
) {
3779 if (!vfp_access_check(s
)) {
3783 rm
= tcg_temp_new_i64();
3784 rd
= tcg_temp_new_i64();
3785 for (pass
= 0; pass
< (a
->q
? 2 : 1); pass
++) {
3786 read_neon_element64(rm
, a
->vm
, pass
, MO_64
);
3787 read_neon_element64(rd
, a
->vd
, pass
, MO_64
);
3788 write_neon_element64(rm
, a
->vd
, pass
, MO_64
);
3789 write_neon_element64(rd
, a
->vm
, pass
, MO_64
);
3794 static void gen_neon_trn_u8(TCGv_i32 t0
, TCGv_i32 t1
)
3798 rd
= tcg_temp_new_i32();
3799 tmp
= tcg_temp_new_i32();
3801 tcg_gen_shli_i32(rd
, t0
, 8);
3802 tcg_gen_andi_i32(rd
, rd
, 0xff00ff00);
3803 tcg_gen_andi_i32(tmp
, t1
, 0x00ff00ff);
3804 tcg_gen_or_i32(rd
, rd
, tmp
);
3806 tcg_gen_shri_i32(t1
, t1
, 8);
3807 tcg_gen_andi_i32(t1
, t1
, 0x00ff00ff);
3808 tcg_gen_andi_i32(tmp
, t0
, 0xff00ff00);
3809 tcg_gen_or_i32(t1
, t1
, tmp
);
3810 tcg_gen_mov_i32(t0
, rd
);
3813 static void gen_neon_trn_u16(TCGv_i32 t0
, TCGv_i32 t1
)
3817 rd
= tcg_temp_new_i32();
3818 tmp
= tcg_temp_new_i32();
3820 tcg_gen_shli_i32(rd
, t0
, 16);
3821 tcg_gen_andi_i32(tmp
, t1
, 0xffff);
3822 tcg_gen_or_i32(rd
, rd
, tmp
);
3823 tcg_gen_shri_i32(t1
, t1
, 16);
3824 tcg_gen_andi_i32(tmp
, t0
, 0xffff0000);
3825 tcg_gen_or_i32(t1
, t1
, tmp
);
3826 tcg_gen_mov_i32(t0
, rd
);
3829 static bool trans_VTRN(DisasContext
*s
, arg_2misc
*a
)
3834 if (!arm_dc_feature(s
, ARM_FEATURE_NEON
)) {
3838 /* UNDEF accesses to D16-D31 if they don't exist. */
3839 if (!dc_isar_feature(aa32_simd_r32
, s
) &&
3840 ((a
->vd
| a
->vm
) & 0x10)) {
3844 if ((a
->vd
| a
->vm
) & a
->q
) {
3852 if (!vfp_access_check(s
)) {
3856 tmp
= tcg_temp_new_i32();
3857 tmp2
= tcg_temp_new_i32();
3858 if (a
->size
== MO_32
) {
3859 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
+= 2) {
3860 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
3861 read_neon_element32(tmp2
, a
->vd
, pass
+ 1, MO_32
);
3862 write_neon_element32(tmp2
, a
->vm
, pass
, MO_32
);
3863 write_neon_element32(tmp
, a
->vd
, pass
+ 1, MO_32
);
3866 for (pass
= 0; pass
< (a
->q
? 4 : 2); pass
++) {
3867 read_neon_element32(tmp
, a
->vm
, pass
, MO_32
);
3868 read_neon_element32(tmp2
, a
->vd
, pass
, MO_32
);
3869 if (a
->size
== MO_8
) {
3870 gen_neon_trn_u8(tmp
, tmp2
);
3872 gen_neon_trn_u16(tmp
, tmp2
);
3874 write_neon_element32(tmp2
, a
->vm
, pass
, MO_32
);
3875 write_neon_element32(tmp
, a
->vd
, pass
, MO_32
);
3881 static bool trans_VSMMLA(DisasContext
*s
, arg_VSMMLA
*a
)
3883 if (!dc_isar_feature(aa32_i8mm
, s
)) {
3886 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
3887 gen_helper_gvec_smmla_b
);
3890 static bool trans_VUMMLA(DisasContext
*s
, arg_VUMMLA
*a
)
3892 if (!dc_isar_feature(aa32_i8mm
, s
)) {
3895 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
3896 gen_helper_gvec_ummla_b
);
3899 static bool trans_VUSMMLA(DisasContext
*s
, arg_VUSMMLA
*a
)
3901 if (!dc_isar_feature(aa32_i8mm
, s
)) {
3904 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
3905 gen_helper_gvec_usmmla_b
);
3908 static bool trans_VMMLA_b16(DisasContext
*s
, arg_VMMLA_b16
*a
)
3910 if (!dc_isar_feature(aa32_bf16
, s
)) {
3913 return do_neon_ddda(s
, 7, a
->vd
, a
->vn
, a
->vm
, 0,
3914 gen_helper_gvec_bfmmla
);
3917 static bool trans_VFMA_b16(DisasContext
*s
, arg_VFMA_b16
*a
)
3919 if (!dc_isar_feature(aa32_bf16
, s
)) {
3922 return do_neon_ddda_fpst(s
, 7, a
->vd
, a
->vn
, a
->vm
, a
->q
, FPST_STD
,
3923 gen_helper_gvec_bfmlal
);
3926 static bool trans_VFMA_b16_scal(DisasContext
*s
, arg_VFMA_b16_scal
*a
)
3928 if (!dc_isar_feature(aa32_bf16
, s
)) {
3931 return do_neon_ddda_fpst(s
, 6, a
->vd
, a
->vn
, a
->vm
,
3932 (a
->index
<< 1) | a
->q
, FPST_STD
,
3933 gen_helper_gvec_bfmlal_idx
);