xref: /openbmc/qemu/target/arm/tcg/translate-neon.c (revision 01dc65a3bc262ab1bec8fe89775e9bbfa627becb)
1f0984d40SFabiano Rosas /*
2f0984d40SFabiano Rosas  *  ARM translation: AArch32 Neon instructions
3f0984d40SFabiano Rosas  *
4f0984d40SFabiano Rosas  *  Copyright (c) 2003 Fabrice Bellard
5f0984d40SFabiano Rosas  *  Copyright (c) 2005-2007 CodeSourcery
6f0984d40SFabiano Rosas  *  Copyright (c) 2007 OpenedHand, Ltd.
7f0984d40SFabiano Rosas  *  Copyright (c) 2020 Linaro, Ltd.
8f0984d40SFabiano Rosas  *
9f0984d40SFabiano Rosas  * This library is free software; you can redistribute it and/or
10f0984d40SFabiano Rosas  * modify it under the terms of the GNU Lesser General Public
11f0984d40SFabiano Rosas  * License as published by the Free Software Foundation; either
12f0984d40SFabiano Rosas  * version 2.1 of the License, or (at your option) any later version.
13f0984d40SFabiano Rosas  *
14f0984d40SFabiano Rosas  * This library is distributed in the hope that it will be useful,
15f0984d40SFabiano Rosas  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16f0984d40SFabiano Rosas  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17f0984d40SFabiano Rosas  * Lesser General Public License for more details.
18f0984d40SFabiano Rosas  *
19f0984d40SFabiano Rosas  * You should have received a copy of the GNU Lesser General Public
20f0984d40SFabiano Rosas  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21f0984d40SFabiano Rosas  */
22f0984d40SFabiano Rosas 
23f0984d40SFabiano Rosas #include "qemu/osdep.h"
24f0984d40SFabiano Rosas #include "translate.h"
25f0984d40SFabiano Rosas #include "translate-a32.h"
26f0984d40SFabiano Rosas 
27f0984d40SFabiano Rosas /* Include the generated Neon decoder */
28f0984d40SFabiano Rosas #include "decode-neon-dp.c.inc"
29f0984d40SFabiano Rosas #include "decode-neon-ls.c.inc"
30f0984d40SFabiano Rosas #include "decode-neon-shared.c.inc"
31f0984d40SFabiano Rosas 
vfp_reg_ptr(bool dp,int reg)32f0984d40SFabiano Rosas static TCGv_ptr vfp_reg_ptr(bool dp, int reg)
33f0984d40SFabiano Rosas {
34f0984d40SFabiano Rosas     TCGv_ptr ret = tcg_temp_new_ptr();
35ad75a51eSRichard Henderson     tcg_gen_addi_ptr(ret, tcg_env, vfp_reg_offset(dp, reg));
36f0984d40SFabiano Rosas     return ret;
37f0984d40SFabiano Rosas }
38f0984d40SFabiano Rosas 
neon_load_element(TCGv_i32 var,int reg,int ele,MemOp mop)39f0984d40SFabiano Rosas static void neon_load_element(TCGv_i32 var, int reg, int ele, MemOp mop)
40f0984d40SFabiano Rosas {
41f0984d40SFabiano Rosas     long offset = neon_element_offset(reg, ele, mop & MO_SIZE);
42f0984d40SFabiano Rosas 
43f0984d40SFabiano Rosas     switch (mop) {
44f0984d40SFabiano Rosas     case MO_UB:
45ad75a51eSRichard Henderson         tcg_gen_ld8u_i32(var, tcg_env, offset);
46f0984d40SFabiano Rosas         break;
47f0984d40SFabiano Rosas     case MO_UW:
48ad75a51eSRichard Henderson         tcg_gen_ld16u_i32(var, tcg_env, offset);
49f0984d40SFabiano Rosas         break;
50f0984d40SFabiano Rosas     case MO_UL:
51ad75a51eSRichard Henderson         tcg_gen_ld_i32(var, tcg_env, offset);
52f0984d40SFabiano Rosas         break;
53f0984d40SFabiano Rosas     default:
54f0984d40SFabiano Rosas         g_assert_not_reached();
55f0984d40SFabiano Rosas     }
56f0984d40SFabiano Rosas }
57f0984d40SFabiano Rosas 
neon_load_element64(TCGv_i64 var,int reg,int ele,MemOp mop)58f0984d40SFabiano Rosas static void neon_load_element64(TCGv_i64 var, int reg, int ele, MemOp mop)
59f0984d40SFabiano Rosas {
60f0984d40SFabiano Rosas     long offset = neon_element_offset(reg, ele, mop & MO_SIZE);
61f0984d40SFabiano Rosas 
62f0984d40SFabiano Rosas     switch (mop) {
63f0984d40SFabiano Rosas     case MO_UB:
64ad75a51eSRichard Henderson         tcg_gen_ld8u_i64(var, tcg_env, offset);
65f0984d40SFabiano Rosas         break;
66f0984d40SFabiano Rosas     case MO_UW:
67ad75a51eSRichard Henderson         tcg_gen_ld16u_i64(var, tcg_env, offset);
68f0984d40SFabiano Rosas         break;
69f0984d40SFabiano Rosas     case MO_UL:
70ad75a51eSRichard Henderson         tcg_gen_ld32u_i64(var, tcg_env, offset);
71f0984d40SFabiano Rosas         break;
72f0984d40SFabiano Rosas     case MO_UQ:
73ad75a51eSRichard Henderson         tcg_gen_ld_i64(var, tcg_env, offset);
74f0984d40SFabiano Rosas         break;
75f0984d40SFabiano Rosas     default:
76f0984d40SFabiano Rosas         g_assert_not_reached();
77f0984d40SFabiano Rosas     }
78f0984d40SFabiano Rosas }
79f0984d40SFabiano Rosas 
neon_store_element(int reg,int ele,MemOp size,TCGv_i32 var)80f0984d40SFabiano Rosas static void neon_store_element(int reg, int ele, MemOp size, TCGv_i32 var)
81f0984d40SFabiano Rosas {
82f0984d40SFabiano Rosas     long offset = neon_element_offset(reg, ele, size);
83f0984d40SFabiano Rosas 
84f0984d40SFabiano Rosas     switch (size) {
85f0984d40SFabiano Rosas     case MO_8:
86ad75a51eSRichard Henderson         tcg_gen_st8_i32(var, tcg_env, offset);
87f0984d40SFabiano Rosas         break;
88f0984d40SFabiano Rosas     case MO_16:
89ad75a51eSRichard Henderson         tcg_gen_st16_i32(var, tcg_env, offset);
90f0984d40SFabiano Rosas         break;
91f0984d40SFabiano Rosas     case MO_32:
92ad75a51eSRichard Henderson         tcg_gen_st_i32(var, tcg_env, offset);
93f0984d40SFabiano Rosas         break;
94f0984d40SFabiano Rosas     default:
95f0984d40SFabiano Rosas         g_assert_not_reached();
96f0984d40SFabiano Rosas     }
97f0984d40SFabiano Rosas }
98f0984d40SFabiano Rosas 
neon_store_element64(int reg,int ele,MemOp size,TCGv_i64 var)99f0984d40SFabiano Rosas static void neon_store_element64(int reg, int ele, MemOp size, TCGv_i64 var)
100f0984d40SFabiano Rosas {
101f0984d40SFabiano Rosas     long offset = neon_element_offset(reg, ele, size);
102f0984d40SFabiano Rosas 
103f0984d40SFabiano Rosas     switch (size) {
104f0984d40SFabiano Rosas     case MO_8:
105ad75a51eSRichard Henderson         tcg_gen_st8_i64(var, tcg_env, offset);
106f0984d40SFabiano Rosas         break;
107f0984d40SFabiano Rosas     case MO_16:
108ad75a51eSRichard Henderson         tcg_gen_st16_i64(var, tcg_env, offset);
109f0984d40SFabiano Rosas         break;
110f0984d40SFabiano Rosas     case MO_32:
111ad75a51eSRichard Henderson         tcg_gen_st32_i64(var, tcg_env, offset);
112f0984d40SFabiano Rosas         break;
113f0984d40SFabiano Rosas     case MO_64:
114ad75a51eSRichard Henderson         tcg_gen_st_i64(var, tcg_env, offset);
115f0984d40SFabiano Rosas         break;
116f0984d40SFabiano Rosas     default:
117f0984d40SFabiano Rosas         g_assert_not_reached();
118f0984d40SFabiano Rosas     }
119f0984d40SFabiano Rosas }
120f0984d40SFabiano Rosas 
do_neon_ddda(DisasContext * s,int q,int vd,int vn,int vm,int data,gen_helper_gvec_4 * fn_gvec)121f0984d40SFabiano Rosas static bool do_neon_ddda(DisasContext *s, int q, int vd, int vn, int vm,
122f0984d40SFabiano Rosas                          int data, gen_helper_gvec_4 *fn_gvec)
123f0984d40SFabiano Rosas {
124f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
125f0984d40SFabiano Rosas     if (((vd | vn | vm) & 0x10) && !dc_isar_feature(aa32_simd_r32, s)) {
126f0984d40SFabiano Rosas         return false;
127f0984d40SFabiano Rosas     }
128f0984d40SFabiano Rosas 
129f0984d40SFabiano Rosas     /*
130f0984d40SFabiano Rosas      * UNDEF accesses to odd registers for each bit of Q.
131f0984d40SFabiano Rosas      * Q will be 0b111 for all Q-reg instructions, otherwise
132f0984d40SFabiano Rosas      * when we have mixed Q- and D-reg inputs.
133f0984d40SFabiano Rosas      */
134f0984d40SFabiano Rosas     if (((vd & 1) * 4 | (vn & 1) * 2 | (vm & 1)) & q) {
135f0984d40SFabiano Rosas         return false;
136f0984d40SFabiano Rosas     }
137f0984d40SFabiano Rosas 
138f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
139f0984d40SFabiano Rosas         return true;
140f0984d40SFabiano Rosas     }
141f0984d40SFabiano Rosas 
142f0984d40SFabiano Rosas     int opr_sz = q ? 16 : 8;
143f0984d40SFabiano Rosas     tcg_gen_gvec_4_ool(vfp_reg_offset(1, vd),
144f0984d40SFabiano Rosas                        vfp_reg_offset(1, vn),
145f0984d40SFabiano Rosas                        vfp_reg_offset(1, vm),
146f0984d40SFabiano Rosas                        vfp_reg_offset(1, vd),
147f0984d40SFabiano Rosas                        opr_sz, opr_sz, data, fn_gvec);
148f0984d40SFabiano Rosas     return true;
149f0984d40SFabiano Rosas }
150f0984d40SFabiano Rosas 
do_neon_ddda_env(DisasContext * s,int q,int vd,int vn,int vm,int data,gen_helper_gvec_4_ptr * fn_gvec)15175a6784dSPeter Maydell static bool do_neon_ddda_env(DisasContext *s, int q, int vd, int vn, int vm,
15275a6784dSPeter Maydell                              int data, gen_helper_gvec_4_ptr *fn_gvec)
15375a6784dSPeter Maydell {
15475a6784dSPeter Maydell     /* UNDEF accesses to D16-D31 if they don't exist. */
15575a6784dSPeter Maydell     if (((vd | vn | vm) & 0x10) && !dc_isar_feature(aa32_simd_r32, s)) {
15675a6784dSPeter Maydell         return false;
15775a6784dSPeter Maydell     }
15875a6784dSPeter Maydell 
15975a6784dSPeter Maydell     /*
16075a6784dSPeter Maydell      * UNDEF accesses to odd registers for each bit of Q.
16175a6784dSPeter Maydell      * Q will be 0b111 for all Q-reg instructions, otherwise
16275a6784dSPeter Maydell      * when we have mixed Q- and D-reg inputs.
16375a6784dSPeter Maydell      */
16475a6784dSPeter Maydell     if (((vd & 1) * 4 | (vn & 1) * 2 | (vm & 1)) & q) {
16575a6784dSPeter Maydell         return false;
16675a6784dSPeter Maydell     }
16775a6784dSPeter Maydell 
16875a6784dSPeter Maydell     if (!vfp_access_check(s)) {
16975a6784dSPeter Maydell         return true;
17075a6784dSPeter Maydell     }
17175a6784dSPeter Maydell 
17275a6784dSPeter Maydell     int opr_sz = q ? 16 : 8;
17375a6784dSPeter Maydell     tcg_gen_gvec_4_ptr(vfp_reg_offset(1, vd),
17475a6784dSPeter Maydell                        vfp_reg_offset(1, vn),
17575a6784dSPeter Maydell                        vfp_reg_offset(1, vm),
17675a6784dSPeter Maydell                        vfp_reg_offset(1, vd),
17775a6784dSPeter Maydell                        tcg_env,
17875a6784dSPeter Maydell                        opr_sz, opr_sz, data, fn_gvec);
17975a6784dSPeter Maydell     return true;
18075a6784dSPeter Maydell }
18175a6784dSPeter Maydell 
do_neon_ddda_fpst(DisasContext * s,int q,int vd,int vn,int vm,int data,ARMFPStatusFlavour fp_flavour,gen_helper_gvec_4_ptr * fn_gvec_ptr)182f0984d40SFabiano Rosas static bool do_neon_ddda_fpst(DisasContext *s, int q, int vd, int vn, int vm,
183f0984d40SFabiano Rosas                               int data, ARMFPStatusFlavour fp_flavour,
184f0984d40SFabiano Rosas                               gen_helper_gvec_4_ptr *fn_gvec_ptr)
185f0984d40SFabiano Rosas {
186f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
187f0984d40SFabiano Rosas     if (((vd | vn | vm) & 0x10) && !dc_isar_feature(aa32_simd_r32, s)) {
188f0984d40SFabiano Rosas         return false;
189f0984d40SFabiano Rosas     }
190f0984d40SFabiano Rosas 
191f0984d40SFabiano Rosas     /*
192f0984d40SFabiano Rosas      * UNDEF accesses to odd registers for each bit of Q.
193f0984d40SFabiano Rosas      * Q will be 0b111 for all Q-reg instructions, otherwise
194f0984d40SFabiano Rosas      * when we have mixed Q- and D-reg inputs.
195f0984d40SFabiano Rosas      */
196f0984d40SFabiano Rosas     if (((vd & 1) * 4 | (vn & 1) * 2 | (vm & 1)) & q) {
197f0984d40SFabiano Rosas         return false;
198f0984d40SFabiano Rosas     }
199f0984d40SFabiano Rosas 
200f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
201f0984d40SFabiano Rosas         return true;
202f0984d40SFabiano Rosas     }
203f0984d40SFabiano Rosas 
204f0984d40SFabiano Rosas     int opr_sz = q ? 16 : 8;
205f0984d40SFabiano Rosas     TCGv_ptr fpst = fpstatus_ptr(fp_flavour);
206f0984d40SFabiano Rosas 
207f0984d40SFabiano Rosas     tcg_gen_gvec_4_ptr(vfp_reg_offset(1, vd),
208f0984d40SFabiano Rosas                        vfp_reg_offset(1, vn),
209f0984d40SFabiano Rosas                        vfp_reg_offset(1, vm),
210f0984d40SFabiano Rosas                        vfp_reg_offset(1, vd),
211f0984d40SFabiano Rosas                        fpst, opr_sz, opr_sz, data, fn_gvec_ptr);
212f0984d40SFabiano Rosas     return true;
213f0984d40SFabiano Rosas }
214f0984d40SFabiano Rosas 
trans_VCMLA(DisasContext * s,arg_VCMLA * a)215f0984d40SFabiano Rosas static bool trans_VCMLA(DisasContext *s, arg_VCMLA *a)
216f0984d40SFabiano Rosas {
217f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_vcma, s)) {
218f0984d40SFabiano Rosas         return false;
219f0984d40SFabiano Rosas     }
220f0984d40SFabiano Rosas     if (a->size == MO_16) {
221f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_fp16_arith, s)) {
222f0984d40SFabiano Rosas             return false;
223f0984d40SFabiano Rosas         }
224f0984d40SFabiano Rosas         return do_neon_ddda_fpst(s, a->q * 7, a->vd, a->vn, a->vm, a->rot,
225f0984d40SFabiano Rosas                                  FPST_STD_F16, gen_helper_gvec_fcmlah);
226f0984d40SFabiano Rosas     }
227f0984d40SFabiano Rosas     return do_neon_ddda_fpst(s, a->q * 7, a->vd, a->vn, a->vm, a->rot,
228f0984d40SFabiano Rosas                              FPST_STD, gen_helper_gvec_fcmlas);
229f0984d40SFabiano Rosas }
230f0984d40SFabiano Rosas 
trans_VCADD(DisasContext * s,arg_VCADD * a)231f0984d40SFabiano Rosas static bool trans_VCADD(DisasContext *s, arg_VCADD *a)
232f0984d40SFabiano Rosas {
233f0984d40SFabiano Rosas     int opr_sz;
234f0984d40SFabiano Rosas     TCGv_ptr fpst;
235f0984d40SFabiano Rosas     gen_helper_gvec_3_ptr *fn_gvec_ptr;
236f0984d40SFabiano Rosas 
237f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_vcma, s)
238f0984d40SFabiano Rosas         || (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s))) {
239f0984d40SFabiano Rosas         return false;
240f0984d40SFabiano Rosas     }
241f0984d40SFabiano Rosas 
242f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
243f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
244f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
245f0984d40SFabiano Rosas         return false;
246f0984d40SFabiano Rosas     }
247f0984d40SFabiano Rosas 
248f0984d40SFabiano Rosas     if ((a->vn | a->vm | a->vd) & a->q) {
249f0984d40SFabiano Rosas         return false;
250f0984d40SFabiano Rosas     }
251f0984d40SFabiano Rosas 
252f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
253f0984d40SFabiano Rosas         return true;
254f0984d40SFabiano Rosas     }
255f0984d40SFabiano Rosas 
256f0984d40SFabiano Rosas     opr_sz = (1 + a->q) * 8;
257f0984d40SFabiano Rosas     fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
258f0984d40SFabiano Rosas     fn_gvec_ptr = (a->size == MO_16) ?
259f0984d40SFabiano Rosas         gen_helper_gvec_fcaddh : gen_helper_gvec_fcadds;
260f0984d40SFabiano Rosas     tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
261f0984d40SFabiano Rosas                        vfp_reg_offset(1, a->vn),
262f0984d40SFabiano Rosas                        vfp_reg_offset(1, a->vm),
263f0984d40SFabiano Rosas                        fpst, opr_sz, opr_sz, a->rot,
264f0984d40SFabiano Rosas                        fn_gvec_ptr);
265f0984d40SFabiano Rosas     return true;
266f0984d40SFabiano Rosas }
267f0984d40SFabiano Rosas 
trans_VSDOT(DisasContext * s,arg_VSDOT * a)268f0984d40SFabiano Rosas static bool trans_VSDOT(DisasContext *s, arg_VSDOT *a)
269f0984d40SFabiano Rosas {
270f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_dp, s)) {
271f0984d40SFabiano Rosas         return false;
272f0984d40SFabiano Rosas     }
273f0984d40SFabiano Rosas     return do_neon_ddda(s, a->q * 7, a->vd, a->vn, a->vm, 0,
274f0984d40SFabiano Rosas                         gen_helper_gvec_sdot_b);
275f0984d40SFabiano Rosas }
276f0984d40SFabiano Rosas 
trans_VUDOT(DisasContext * s,arg_VUDOT * a)277f0984d40SFabiano Rosas static bool trans_VUDOT(DisasContext *s, arg_VUDOT *a)
278f0984d40SFabiano Rosas {
279f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_dp, s)) {
280f0984d40SFabiano Rosas         return false;
281f0984d40SFabiano Rosas     }
282f0984d40SFabiano Rosas     return do_neon_ddda(s, a->q * 7, a->vd, a->vn, a->vm, 0,
283f0984d40SFabiano Rosas                         gen_helper_gvec_udot_b);
284f0984d40SFabiano Rosas }
285f0984d40SFabiano Rosas 
trans_VUSDOT(DisasContext * s,arg_VUSDOT * a)286f0984d40SFabiano Rosas static bool trans_VUSDOT(DisasContext *s, arg_VUSDOT *a)
287f0984d40SFabiano Rosas {
288f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_i8mm, s)) {
289f0984d40SFabiano Rosas         return false;
290f0984d40SFabiano Rosas     }
291f0984d40SFabiano Rosas     return do_neon_ddda(s, a->q * 7, a->vd, a->vn, a->vm, 0,
292f0984d40SFabiano Rosas                         gen_helper_gvec_usdot_b);
293f0984d40SFabiano Rosas }
294f0984d40SFabiano Rosas 
trans_VDOT_b16(DisasContext * s,arg_VDOT_b16 * a)295f0984d40SFabiano Rosas static bool trans_VDOT_b16(DisasContext *s, arg_VDOT_b16 *a)
296f0984d40SFabiano Rosas {
297f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_bf16, s)) {
298f0984d40SFabiano Rosas         return false;
299f0984d40SFabiano Rosas     }
30075a6784dSPeter Maydell     return do_neon_ddda_env(s, a->q * 7, a->vd, a->vn, a->vm, 0,
301f0984d40SFabiano Rosas                             gen_helper_gvec_bfdot);
302f0984d40SFabiano Rosas }
303f0984d40SFabiano Rosas 
trans_VFML(DisasContext * s,arg_VFML * a)304f0984d40SFabiano Rosas static bool trans_VFML(DisasContext *s, arg_VFML *a)
305f0984d40SFabiano Rosas {
306f0984d40SFabiano Rosas     int opr_sz;
307f0984d40SFabiano Rosas 
308f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_fhm, s)) {
309f0984d40SFabiano Rosas         return false;
310f0984d40SFabiano Rosas     }
311f0984d40SFabiano Rosas 
312f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
313f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
314f0984d40SFabiano Rosas         (a->vd & 0x10)) {
315f0984d40SFabiano Rosas         return false;
316f0984d40SFabiano Rosas     }
317f0984d40SFabiano Rosas 
318f0984d40SFabiano Rosas     if (a->vd & a->q) {
319f0984d40SFabiano Rosas         return false;
320f0984d40SFabiano Rosas     }
321f0984d40SFabiano Rosas 
322f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
323f0984d40SFabiano Rosas         return true;
324f0984d40SFabiano Rosas     }
325f0984d40SFabiano Rosas 
326f0984d40SFabiano Rosas     opr_sz = (1 + a->q) * 8;
327f0984d40SFabiano Rosas     tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
328f0984d40SFabiano Rosas                        vfp_reg_offset(a->q, a->vn),
329f0984d40SFabiano Rosas                        vfp_reg_offset(a->q, a->vm),
330ad75a51eSRichard Henderson                        tcg_env, opr_sz, opr_sz, a->s, /* is_2 == 0 */
331f0984d40SFabiano Rosas                        gen_helper_gvec_fmlal_a32);
332f0984d40SFabiano Rosas     return true;
333f0984d40SFabiano Rosas }
334f0984d40SFabiano Rosas 
trans_VCMLA_scalar(DisasContext * s,arg_VCMLA_scalar * a)335f0984d40SFabiano Rosas static bool trans_VCMLA_scalar(DisasContext *s, arg_VCMLA_scalar *a)
336f0984d40SFabiano Rosas {
337f0984d40SFabiano Rosas     int data = (a->index << 2) | a->rot;
338f0984d40SFabiano Rosas 
339f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_vcma, s)) {
340f0984d40SFabiano Rosas         return false;
341f0984d40SFabiano Rosas     }
342f0984d40SFabiano Rosas     if (a->size == MO_16) {
343f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_fp16_arith, s)) {
344f0984d40SFabiano Rosas             return false;
345f0984d40SFabiano Rosas         }
346f0984d40SFabiano Rosas         return do_neon_ddda_fpst(s, a->q * 6, a->vd, a->vn, a->vm, data,
347f0984d40SFabiano Rosas                                  FPST_STD_F16, gen_helper_gvec_fcmlah_idx);
348f0984d40SFabiano Rosas     }
349f0984d40SFabiano Rosas     return do_neon_ddda_fpst(s, a->q * 6, a->vd, a->vn, a->vm, data,
350f0984d40SFabiano Rosas                              FPST_STD, gen_helper_gvec_fcmlas_idx);
351f0984d40SFabiano Rosas }
352f0984d40SFabiano Rosas 
trans_VSDOT_scalar(DisasContext * s,arg_VSDOT_scalar * a)353f0984d40SFabiano Rosas static bool trans_VSDOT_scalar(DisasContext *s, arg_VSDOT_scalar *a)
354f0984d40SFabiano Rosas {
355f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_dp, s)) {
356f0984d40SFabiano Rosas         return false;
357f0984d40SFabiano Rosas     }
358f0984d40SFabiano Rosas     return do_neon_ddda(s, a->q * 6, a->vd, a->vn, a->vm, a->index,
359f0984d40SFabiano Rosas                         gen_helper_gvec_sdot_idx_b);
360f0984d40SFabiano Rosas }
361f0984d40SFabiano Rosas 
trans_VUDOT_scalar(DisasContext * s,arg_VUDOT_scalar * a)362f0984d40SFabiano Rosas static bool trans_VUDOT_scalar(DisasContext *s, arg_VUDOT_scalar *a)
363f0984d40SFabiano Rosas {
364f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_dp, s)) {
365f0984d40SFabiano Rosas         return false;
366f0984d40SFabiano Rosas     }
367f0984d40SFabiano Rosas     return do_neon_ddda(s, a->q * 6, a->vd, a->vn, a->vm, a->index,
368f0984d40SFabiano Rosas                         gen_helper_gvec_udot_idx_b);
369f0984d40SFabiano Rosas }
370f0984d40SFabiano Rosas 
trans_VUSDOT_scalar(DisasContext * s,arg_VUSDOT_scalar * a)371f0984d40SFabiano Rosas static bool trans_VUSDOT_scalar(DisasContext *s, arg_VUSDOT_scalar *a)
372f0984d40SFabiano Rosas {
373f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_i8mm, s)) {
374f0984d40SFabiano Rosas         return false;
375f0984d40SFabiano Rosas     }
376f0984d40SFabiano Rosas     return do_neon_ddda(s, a->q * 6, a->vd, a->vn, a->vm, a->index,
377f0984d40SFabiano Rosas                         gen_helper_gvec_usdot_idx_b);
378f0984d40SFabiano Rosas }
379f0984d40SFabiano Rosas 
trans_VSUDOT_scalar(DisasContext * s,arg_VSUDOT_scalar * a)380f0984d40SFabiano Rosas static bool trans_VSUDOT_scalar(DisasContext *s, arg_VSUDOT_scalar *a)
381f0984d40SFabiano Rosas {
382f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_i8mm, s)) {
383f0984d40SFabiano Rosas         return false;
384f0984d40SFabiano Rosas     }
385f0984d40SFabiano Rosas     return do_neon_ddda(s, a->q * 6, a->vd, a->vn, a->vm, a->index,
386f0984d40SFabiano Rosas                         gen_helper_gvec_sudot_idx_b);
387f0984d40SFabiano Rosas }
388f0984d40SFabiano Rosas 
trans_VDOT_b16_scal(DisasContext * s,arg_VDOT_b16_scal * a)389f0984d40SFabiano Rosas static bool trans_VDOT_b16_scal(DisasContext *s, arg_VDOT_b16_scal *a)
390f0984d40SFabiano Rosas {
391f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_bf16, s)) {
392f0984d40SFabiano Rosas         return false;
393f0984d40SFabiano Rosas     }
394c8d644b9SPeter Maydell     return do_neon_ddda_env(s, a->q * 6, a->vd, a->vn, a->vm, a->index,
395f0984d40SFabiano Rosas                             gen_helper_gvec_bfdot_idx);
396f0984d40SFabiano Rosas }
397f0984d40SFabiano Rosas 
trans_VFML_scalar(DisasContext * s,arg_VFML_scalar * a)398f0984d40SFabiano Rosas static bool trans_VFML_scalar(DisasContext *s, arg_VFML_scalar *a)
399f0984d40SFabiano Rosas {
400f0984d40SFabiano Rosas     int opr_sz;
401f0984d40SFabiano Rosas 
402f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_fhm, s)) {
403f0984d40SFabiano Rosas         return false;
404f0984d40SFabiano Rosas     }
405f0984d40SFabiano Rosas 
406f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
407f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
408f0984d40SFabiano Rosas         ((a->vd & 0x10) || (a->q && (a->vn & 0x10)))) {
409f0984d40SFabiano Rosas         return false;
410f0984d40SFabiano Rosas     }
411f0984d40SFabiano Rosas 
412f0984d40SFabiano Rosas     if (a->vd & a->q) {
413f0984d40SFabiano Rosas         return false;
414f0984d40SFabiano Rosas     }
415f0984d40SFabiano Rosas 
416f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
417f0984d40SFabiano Rosas         return true;
418f0984d40SFabiano Rosas     }
419f0984d40SFabiano Rosas 
420f0984d40SFabiano Rosas     opr_sz = (1 + a->q) * 8;
421f0984d40SFabiano Rosas     tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd),
422f0984d40SFabiano Rosas                        vfp_reg_offset(a->q, a->vn),
423f0984d40SFabiano Rosas                        vfp_reg_offset(a->q, a->rm),
424ad75a51eSRichard Henderson                        tcg_env, opr_sz, opr_sz,
425f0984d40SFabiano Rosas                        (a->index << 2) | a->s, /* is_2 == 0 */
426f0984d40SFabiano Rosas                        gen_helper_gvec_fmlal_idx_a32);
427f0984d40SFabiano Rosas     return true;
428f0984d40SFabiano Rosas }
429f0984d40SFabiano Rosas 
430f0984d40SFabiano Rosas static struct {
431f0984d40SFabiano Rosas     int nregs;
432f0984d40SFabiano Rosas     int interleave;
433f0984d40SFabiano Rosas     int spacing;
434f0984d40SFabiano Rosas } const neon_ls_element_type[11] = {
435f0984d40SFabiano Rosas     {1, 4, 1},
436f0984d40SFabiano Rosas     {1, 4, 2},
437f0984d40SFabiano Rosas     {4, 1, 1},
438f0984d40SFabiano Rosas     {2, 2, 2},
439f0984d40SFabiano Rosas     {1, 3, 1},
440f0984d40SFabiano Rosas     {1, 3, 2},
441f0984d40SFabiano Rosas     {3, 1, 1},
442f0984d40SFabiano Rosas     {1, 1, 1},
443f0984d40SFabiano Rosas     {1, 2, 1},
444f0984d40SFabiano Rosas     {1, 2, 2},
445f0984d40SFabiano Rosas     {2, 1, 1}
446f0984d40SFabiano Rosas };
447f0984d40SFabiano Rosas 
gen_neon_ldst_base_update(DisasContext * s,int rm,int rn,int stride)448f0984d40SFabiano Rosas static void gen_neon_ldst_base_update(DisasContext *s, int rm, int rn,
449f0984d40SFabiano Rosas                                       int stride)
450f0984d40SFabiano Rosas {
451f0984d40SFabiano Rosas     if (rm != 15) {
452f0984d40SFabiano Rosas         TCGv_i32 base;
453f0984d40SFabiano Rosas 
454f0984d40SFabiano Rosas         base = load_reg(s, rn);
455f0984d40SFabiano Rosas         if (rm == 13) {
456f0984d40SFabiano Rosas             tcg_gen_addi_i32(base, base, stride);
457f0984d40SFabiano Rosas         } else {
458f0984d40SFabiano Rosas             TCGv_i32 index;
459f0984d40SFabiano Rosas             index = load_reg(s, rm);
460f0984d40SFabiano Rosas             tcg_gen_add_i32(base, base, index);
461f0984d40SFabiano Rosas         }
462f0984d40SFabiano Rosas         store_reg(s, rn, base);
463f0984d40SFabiano Rosas     }
464f0984d40SFabiano Rosas }
465f0984d40SFabiano Rosas 
trans_VLDST_multiple(DisasContext * s,arg_VLDST_multiple * a)466f0984d40SFabiano Rosas static bool trans_VLDST_multiple(DisasContext *s, arg_VLDST_multiple *a)
467f0984d40SFabiano Rosas {
468f0984d40SFabiano Rosas     /* Neon load/store multiple structures */
469f0984d40SFabiano Rosas     int nregs, interleave, spacing, reg, n;
470f0984d40SFabiano Rosas     MemOp mop, align, endian;
471f0984d40SFabiano Rosas     int mmu_idx = get_mem_index(s);
472f0984d40SFabiano Rosas     int size = a->size;
473f0984d40SFabiano Rosas     TCGv_i64 tmp64;
474f0984d40SFabiano Rosas     TCGv_i32 addr;
475f0984d40SFabiano Rosas 
476f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
477f0984d40SFabiano Rosas         return false;
478f0984d40SFabiano Rosas     }
479f0984d40SFabiano Rosas 
480f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist */
481f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
482f0984d40SFabiano Rosas         return false;
483f0984d40SFabiano Rosas     }
484f0984d40SFabiano Rosas     if (a->itype > 10) {
485f0984d40SFabiano Rosas         return false;
486f0984d40SFabiano Rosas     }
487f0984d40SFabiano Rosas     /* Catch UNDEF cases for bad values of align field */
488f0984d40SFabiano Rosas     switch (a->itype & 0xc) {
489f0984d40SFabiano Rosas     case 4:
490f0984d40SFabiano Rosas         if (a->align >= 2) {
491f0984d40SFabiano Rosas             return false;
492f0984d40SFabiano Rosas         }
493f0984d40SFabiano Rosas         break;
494f0984d40SFabiano Rosas     case 8:
495f0984d40SFabiano Rosas         if (a->align == 3) {
496f0984d40SFabiano Rosas             return false;
497f0984d40SFabiano Rosas         }
498f0984d40SFabiano Rosas         break;
499f0984d40SFabiano Rosas     default:
500f0984d40SFabiano Rosas         break;
501f0984d40SFabiano Rosas     }
502f0984d40SFabiano Rosas     nregs = neon_ls_element_type[a->itype].nregs;
503f0984d40SFabiano Rosas     interleave = neon_ls_element_type[a->itype].interleave;
504f0984d40SFabiano Rosas     spacing = neon_ls_element_type[a->itype].spacing;
505f0984d40SFabiano Rosas     if (size == 3 && (interleave | spacing) != 1) {
506f0984d40SFabiano Rosas         return false;
507f0984d40SFabiano Rosas     }
508f0984d40SFabiano Rosas 
509f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
510f0984d40SFabiano Rosas         return true;
511f0984d40SFabiano Rosas     }
512f0984d40SFabiano Rosas 
513f0984d40SFabiano Rosas     /* For our purposes, bytes are always little-endian.  */
514f0984d40SFabiano Rosas     endian = s->be_data;
515f0984d40SFabiano Rosas     if (size == 0) {
516f0984d40SFabiano Rosas         endian = MO_LE;
517f0984d40SFabiano Rosas     }
518f0984d40SFabiano Rosas 
519f0984d40SFabiano Rosas     /* Enforce alignment requested by the instruction */
520f0984d40SFabiano Rosas     if (a->align) {
521f0984d40SFabiano Rosas         align = pow2_align(a->align + 2); /* 4 ** a->align */
522f0984d40SFabiano Rosas     } else {
523f0984d40SFabiano Rosas         align = s->align_mem ? MO_ALIGN : 0;
524f0984d40SFabiano Rosas     }
525f0984d40SFabiano Rosas 
526f0984d40SFabiano Rosas     /*
527f0984d40SFabiano Rosas      * Consecutive little-endian elements from a single register
528f0984d40SFabiano Rosas      * can be promoted to a larger little-endian operation.
529f0984d40SFabiano Rosas      */
530f0984d40SFabiano Rosas     if (interleave == 1 && endian == MO_LE) {
531f0984d40SFabiano Rosas         /* Retain any natural alignment. */
532f0984d40SFabiano Rosas         if (align == MO_ALIGN) {
533f0984d40SFabiano Rosas             align = pow2_align(size);
534f0984d40SFabiano Rosas         }
535f0984d40SFabiano Rosas         size = 3;
536f0984d40SFabiano Rosas     }
537f0984d40SFabiano Rosas 
538f0984d40SFabiano Rosas     tmp64 = tcg_temp_new_i64();
539f0984d40SFabiano Rosas     addr = tcg_temp_new_i32();
540f0984d40SFabiano Rosas     load_reg_var(s, addr, a->rn);
541f0984d40SFabiano Rosas 
542f0984d40SFabiano Rosas     mop = endian | size | align;
543f0984d40SFabiano Rosas     for (reg = 0; reg < nregs; reg++) {
544f0984d40SFabiano Rosas         for (n = 0; n < 8 >> size; n++) {
545f0984d40SFabiano Rosas             int xs;
546f0984d40SFabiano Rosas             for (xs = 0; xs < interleave; xs++) {
547f0984d40SFabiano Rosas                 int tt = a->vd + reg + spacing * xs;
548f0984d40SFabiano Rosas 
549f0984d40SFabiano Rosas                 if (a->l) {
550f0984d40SFabiano Rosas                     gen_aa32_ld_internal_i64(s, tmp64, addr, mmu_idx, mop);
551f0984d40SFabiano Rosas                     neon_store_element64(tt, n, size, tmp64);
552f0984d40SFabiano Rosas                 } else {
553f0984d40SFabiano Rosas                     neon_load_element64(tmp64, tt, n, size);
554f0984d40SFabiano Rosas                     gen_aa32_st_internal_i64(s, tmp64, addr, mmu_idx, mop);
555f0984d40SFabiano Rosas                 }
556f0984d40SFabiano Rosas                 tcg_gen_addi_i32(addr, addr, 1 << size);
557f0984d40SFabiano Rosas 
558f0984d40SFabiano Rosas                 /* Subsequent memory operations inherit alignment */
559f0984d40SFabiano Rosas                 mop &= ~MO_AMASK;
560f0984d40SFabiano Rosas             }
561f0984d40SFabiano Rosas         }
562f0984d40SFabiano Rosas     }
563f0984d40SFabiano Rosas 
564f0984d40SFabiano Rosas     gen_neon_ldst_base_update(s, a->rm, a->rn, nregs * interleave * 8);
565f0984d40SFabiano Rosas     return true;
566f0984d40SFabiano Rosas }
567f0984d40SFabiano Rosas 
trans_VLD_all_lanes(DisasContext * s,arg_VLD_all_lanes * a)568f0984d40SFabiano Rosas static bool trans_VLD_all_lanes(DisasContext *s, arg_VLD_all_lanes *a)
569f0984d40SFabiano Rosas {
570f0984d40SFabiano Rosas     /* Neon load single structure to all lanes */
571f0984d40SFabiano Rosas     int reg, stride, vec_size;
572f0984d40SFabiano Rosas     int vd = a->vd;
573f0984d40SFabiano Rosas     int size = a->size;
574f0984d40SFabiano Rosas     int nregs = a->n + 1;
575f0984d40SFabiano Rosas     TCGv_i32 addr, tmp;
576f0984d40SFabiano Rosas     MemOp mop, align;
577f0984d40SFabiano Rosas 
578f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
579f0984d40SFabiano Rosas         return false;
580f0984d40SFabiano Rosas     }
581f0984d40SFabiano Rosas 
582f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist */
583f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
584f0984d40SFabiano Rosas         return false;
585f0984d40SFabiano Rosas     }
586f0984d40SFabiano Rosas 
587f0984d40SFabiano Rosas     align = 0;
588f0984d40SFabiano Rosas     if (size == 3) {
589f0984d40SFabiano Rosas         if (nregs != 4 || a->a == 0) {
590f0984d40SFabiano Rosas             return false;
591f0984d40SFabiano Rosas         }
592f0984d40SFabiano Rosas         /* For VLD4 size == 3 a == 1 means 32 bits at 16 byte alignment */
593f0984d40SFabiano Rosas         size = MO_32;
594f0984d40SFabiano Rosas         align = MO_ALIGN_16;
595f0984d40SFabiano Rosas     } else if (a->a) {
596f0984d40SFabiano Rosas         switch (nregs) {
597f0984d40SFabiano Rosas         case 1:
598f0984d40SFabiano Rosas             if (size == 0) {
599f0984d40SFabiano Rosas                 return false;
600f0984d40SFabiano Rosas             }
601f0984d40SFabiano Rosas             align = MO_ALIGN;
602f0984d40SFabiano Rosas             break;
603f0984d40SFabiano Rosas         case 2:
604f0984d40SFabiano Rosas             align = pow2_align(size + 1);
605f0984d40SFabiano Rosas             break;
606f0984d40SFabiano Rosas         case 3:
607f0984d40SFabiano Rosas             return false;
608f0984d40SFabiano Rosas         case 4:
609f0984d40SFabiano Rosas             if (size == 2) {
610f0984d40SFabiano Rosas                 align = pow2_align(3);
611f0984d40SFabiano Rosas             } else {
612f0984d40SFabiano Rosas                 align = pow2_align(size + 2);
613f0984d40SFabiano Rosas             }
614f0984d40SFabiano Rosas             break;
615f0984d40SFabiano Rosas         default:
616f0984d40SFabiano Rosas             g_assert_not_reached();
617f0984d40SFabiano Rosas         }
618f0984d40SFabiano Rosas     }
619f0984d40SFabiano Rosas 
620f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
621f0984d40SFabiano Rosas         return true;
622f0984d40SFabiano Rosas     }
623f0984d40SFabiano Rosas 
624f0984d40SFabiano Rosas     /*
625f0984d40SFabiano Rosas      * VLD1 to all lanes: T bit indicates how many Dregs to write.
626f0984d40SFabiano Rosas      * VLD2/3/4 to all lanes: T bit indicates register stride.
627f0984d40SFabiano Rosas      */
628f0984d40SFabiano Rosas     stride = a->t ? 2 : 1;
629f0984d40SFabiano Rosas     vec_size = nregs == 1 ? stride * 8 : 8;
630f0984d40SFabiano Rosas     mop = size | align;
631f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
632f0984d40SFabiano Rosas     addr = tcg_temp_new_i32();
633f0984d40SFabiano Rosas     load_reg_var(s, addr, a->rn);
634f0984d40SFabiano Rosas     for (reg = 0; reg < nregs; reg++) {
635f0984d40SFabiano Rosas         gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), mop);
636f0984d40SFabiano Rosas         if ((vd & 1) && vec_size == 16) {
637f0984d40SFabiano Rosas             /*
638f0984d40SFabiano Rosas              * We cannot write 16 bytes at once because the
639f0984d40SFabiano Rosas              * destination is unaligned.
640f0984d40SFabiano Rosas              */
641f0984d40SFabiano Rosas             tcg_gen_gvec_dup_i32(size, neon_full_reg_offset(vd),
642f0984d40SFabiano Rosas                                  8, 8, tmp);
643f0984d40SFabiano Rosas             tcg_gen_gvec_mov(0, neon_full_reg_offset(vd + 1),
644f0984d40SFabiano Rosas                              neon_full_reg_offset(vd), 8, 8);
645f0984d40SFabiano Rosas         } else {
646f0984d40SFabiano Rosas             tcg_gen_gvec_dup_i32(size, neon_full_reg_offset(vd),
647f0984d40SFabiano Rosas                                  vec_size, vec_size, tmp);
648f0984d40SFabiano Rosas         }
649f0984d40SFabiano Rosas         tcg_gen_addi_i32(addr, addr, 1 << size);
650f0984d40SFabiano Rosas         vd += stride;
651f0984d40SFabiano Rosas 
652f0984d40SFabiano Rosas         /* Subsequent memory operations inherit alignment */
653f0984d40SFabiano Rosas         mop &= ~MO_AMASK;
654f0984d40SFabiano Rosas     }
655f0984d40SFabiano Rosas 
656f0984d40SFabiano Rosas     gen_neon_ldst_base_update(s, a->rm, a->rn, (1 << size) * nregs);
657f0984d40SFabiano Rosas 
658f0984d40SFabiano Rosas     return true;
659f0984d40SFabiano Rosas }
660f0984d40SFabiano Rosas 
trans_VLDST_single(DisasContext * s,arg_VLDST_single * a)661f0984d40SFabiano Rosas static bool trans_VLDST_single(DisasContext *s, arg_VLDST_single *a)
662f0984d40SFabiano Rosas {
663f0984d40SFabiano Rosas     /* Neon load/store single structure to one lane */
664f0984d40SFabiano Rosas     int reg;
665f0984d40SFabiano Rosas     int nregs = a->n + 1;
666f0984d40SFabiano Rosas     int vd = a->vd;
667f0984d40SFabiano Rosas     TCGv_i32 addr, tmp;
668f0984d40SFabiano Rosas     MemOp mop;
669f0984d40SFabiano Rosas 
670f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
671f0984d40SFabiano Rosas         return false;
672f0984d40SFabiano Rosas     }
673f0984d40SFabiano Rosas 
674f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist */
675f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
676f0984d40SFabiano Rosas         return false;
677f0984d40SFabiano Rosas     }
678f0984d40SFabiano Rosas 
679f0984d40SFabiano Rosas     /* Catch the UNDEF cases. This is unavoidably a bit messy. */
680f0984d40SFabiano Rosas     switch (nregs) {
681f0984d40SFabiano Rosas     case 1:
682f0984d40SFabiano Rosas         if (a->stride != 1) {
683f0984d40SFabiano Rosas             return false;
684f0984d40SFabiano Rosas         }
685f0984d40SFabiano Rosas         if (((a->align & (1 << a->size)) != 0) ||
686f0984d40SFabiano Rosas             (a->size == 2 && (a->align == 1 || a->align == 2))) {
687f0984d40SFabiano Rosas             return false;
688f0984d40SFabiano Rosas         }
689f0984d40SFabiano Rosas         break;
690f0984d40SFabiano Rosas     case 2:
691f0984d40SFabiano Rosas         if (a->size == 2 && (a->align & 2) != 0) {
692f0984d40SFabiano Rosas             return false;
693f0984d40SFabiano Rosas         }
694f0984d40SFabiano Rosas         break;
695f0984d40SFabiano Rosas     case 3:
696f0984d40SFabiano Rosas         if (a->align != 0) {
697f0984d40SFabiano Rosas             return false;
698f0984d40SFabiano Rosas         }
699f0984d40SFabiano Rosas         break;
700f0984d40SFabiano Rosas     case 4:
701f0984d40SFabiano Rosas         if (a->size == 2 && a->align == 3) {
702f0984d40SFabiano Rosas             return false;
703f0984d40SFabiano Rosas         }
704f0984d40SFabiano Rosas         break;
705f0984d40SFabiano Rosas     default:
706f0984d40SFabiano Rosas         g_assert_not_reached();
707f0984d40SFabiano Rosas     }
708f0984d40SFabiano Rosas     if ((vd + a->stride * (nregs - 1)) > 31) {
709f0984d40SFabiano Rosas         /*
710f0984d40SFabiano Rosas          * Attempts to write off the end of the register file are
711f0984d40SFabiano Rosas          * UNPREDICTABLE; we choose to UNDEF because otherwise we would
712f0984d40SFabiano Rosas          * access off the end of the array that holds the register data.
713f0984d40SFabiano Rosas          */
714f0984d40SFabiano Rosas         return false;
715f0984d40SFabiano Rosas     }
716f0984d40SFabiano Rosas 
717f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
718f0984d40SFabiano Rosas         return true;
719f0984d40SFabiano Rosas     }
720f0984d40SFabiano Rosas 
721f0984d40SFabiano Rosas     /* Pick up SCTLR settings */
722f0984d40SFabiano Rosas     mop = finalize_memop(s, a->size);
723f0984d40SFabiano Rosas 
724f0984d40SFabiano Rosas     if (a->align) {
725f0984d40SFabiano Rosas         MemOp align_op;
726f0984d40SFabiano Rosas 
727f0984d40SFabiano Rosas         switch (nregs) {
728f0984d40SFabiano Rosas         case 1:
729f0984d40SFabiano Rosas             /* For VLD1, use natural alignment. */
730f0984d40SFabiano Rosas             align_op = MO_ALIGN;
731f0984d40SFabiano Rosas             break;
732f0984d40SFabiano Rosas         case 2:
733f0984d40SFabiano Rosas             /* For VLD2, use double alignment. */
734f0984d40SFabiano Rosas             align_op = pow2_align(a->size + 1);
735f0984d40SFabiano Rosas             break;
736f0984d40SFabiano Rosas         case 4:
737f0984d40SFabiano Rosas             if (a->size == MO_32) {
738f0984d40SFabiano Rosas                 /*
739f0984d40SFabiano Rosas                  * For VLD4.32, align = 1 is double alignment, align = 2 is
740f0984d40SFabiano Rosas                  * quad alignment; align = 3 is rejected above.
741f0984d40SFabiano Rosas                  */
742f0984d40SFabiano Rosas                 align_op = pow2_align(a->size + a->align);
743f0984d40SFabiano Rosas             } else {
744f0984d40SFabiano Rosas                 /* For VLD4.8 and VLD.16, we want quad alignment. */
745f0984d40SFabiano Rosas                 align_op = pow2_align(a->size + 2);
746f0984d40SFabiano Rosas             }
747f0984d40SFabiano Rosas             break;
748f0984d40SFabiano Rosas         default:
749f0984d40SFabiano Rosas             /* For VLD3, the alignment field is zero and rejected above. */
750f0984d40SFabiano Rosas             g_assert_not_reached();
751f0984d40SFabiano Rosas         }
752f0984d40SFabiano Rosas 
753f0984d40SFabiano Rosas         mop = (mop & ~MO_AMASK) | align_op;
754f0984d40SFabiano Rosas     }
755f0984d40SFabiano Rosas 
756f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
757f0984d40SFabiano Rosas     addr = tcg_temp_new_i32();
758f0984d40SFabiano Rosas     load_reg_var(s, addr, a->rn);
759f0984d40SFabiano Rosas 
760f0984d40SFabiano Rosas     for (reg = 0; reg < nregs; reg++) {
761f0984d40SFabiano Rosas         if (a->l) {
762f0984d40SFabiano Rosas             gen_aa32_ld_internal_i32(s, tmp, addr, get_mem_index(s), mop);
763f0984d40SFabiano Rosas             neon_store_element(vd, a->reg_idx, a->size, tmp);
764f0984d40SFabiano Rosas         } else { /* Store */
765f0984d40SFabiano Rosas             neon_load_element(tmp, vd, a->reg_idx, a->size);
766f0984d40SFabiano Rosas             gen_aa32_st_internal_i32(s, tmp, addr, get_mem_index(s), mop);
767f0984d40SFabiano Rosas         }
768f0984d40SFabiano Rosas         vd += a->stride;
769f0984d40SFabiano Rosas         tcg_gen_addi_i32(addr, addr, 1 << a->size);
770f0984d40SFabiano Rosas 
771f0984d40SFabiano Rosas         /* Subsequent memory operations inherit alignment */
772f0984d40SFabiano Rosas         mop &= ~MO_AMASK;
773f0984d40SFabiano Rosas     }
774f0984d40SFabiano Rosas 
775f0984d40SFabiano Rosas     gen_neon_ldst_base_update(s, a->rm, a->rn, (1 << a->size) * nregs);
776f0984d40SFabiano Rosas 
777f0984d40SFabiano Rosas     return true;
778f0984d40SFabiano Rosas }
779f0984d40SFabiano Rosas 
do_3same(DisasContext * s,arg_3same * a,GVecGen3Fn fn)780f0984d40SFabiano Rosas static bool do_3same(DisasContext *s, arg_3same *a, GVecGen3Fn fn)
781f0984d40SFabiano Rosas {
782f0984d40SFabiano Rosas     int vec_size = a->q ? 16 : 8;
783f0984d40SFabiano Rosas     int rd_ofs = neon_full_reg_offset(a->vd);
784f0984d40SFabiano Rosas     int rn_ofs = neon_full_reg_offset(a->vn);
785f0984d40SFabiano Rosas     int rm_ofs = neon_full_reg_offset(a->vm);
786f0984d40SFabiano Rosas 
787f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
788f0984d40SFabiano Rosas         return false;
789f0984d40SFabiano Rosas     }
790f0984d40SFabiano Rosas 
791f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
792f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
793f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
794f0984d40SFabiano Rosas         return false;
795f0984d40SFabiano Rosas     }
796f0984d40SFabiano Rosas 
797f0984d40SFabiano Rosas     if ((a->vn | a->vm | a->vd) & a->q) {
798f0984d40SFabiano Rosas         return false;
799f0984d40SFabiano Rosas     }
800f0984d40SFabiano Rosas 
801f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
802f0984d40SFabiano Rosas         return true;
803f0984d40SFabiano Rosas     }
804f0984d40SFabiano Rosas 
805f0984d40SFabiano Rosas     fn(a->size, rd_ofs, rn_ofs, rm_ofs, vec_size, vec_size);
806f0984d40SFabiano Rosas     return true;
807f0984d40SFabiano Rosas }
808f0984d40SFabiano Rosas 
809f0984d40SFabiano Rosas #define DO_3SAME(INSN, FUNC)                                            \
810f0984d40SFabiano Rosas     static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a)        \
811f0984d40SFabiano Rosas     {                                                                   \
812f0984d40SFabiano Rosas         return do_3same(s, a, FUNC);                                    \
813f0984d40SFabiano Rosas     }
814f0984d40SFabiano Rosas 
DO_3SAME(VADD,tcg_gen_gvec_add)815f0984d40SFabiano Rosas DO_3SAME(VADD, tcg_gen_gvec_add)
816f0984d40SFabiano Rosas DO_3SAME(VSUB, tcg_gen_gvec_sub)
817f0984d40SFabiano Rosas DO_3SAME(VAND, tcg_gen_gvec_and)
818f0984d40SFabiano Rosas DO_3SAME(VBIC, tcg_gen_gvec_andc)
819f0984d40SFabiano Rosas DO_3SAME(VORR, tcg_gen_gvec_or)
820f0984d40SFabiano Rosas DO_3SAME(VORN, tcg_gen_gvec_orc)
821f0984d40SFabiano Rosas DO_3SAME(VEOR, tcg_gen_gvec_xor)
822f0984d40SFabiano Rosas DO_3SAME(VSHL_S, gen_gvec_sshl)
823f0984d40SFabiano Rosas DO_3SAME(VSHL_U, gen_gvec_ushl)
824f0984d40SFabiano Rosas DO_3SAME(VQADD_S, gen_gvec_sqadd_qc)
825f0984d40SFabiano Rosas DO_3SAME(VQADD_U, gen_gvec_uqadd_qc)
826f0984d40SFabiano Rosas DO_3SAME(VQSUB_S, gen_gvec_sqsub_qc)
827f0984d40SFabiano Rosas DO_3SAME(VQSUB_U, gen_gvec_uqsub_qc)
828940392c8SRichard Henderson DO_3SAME(VRSHL_S, gen_gvec_srshl)
829940392c8SRichard Henderson DO_3SAME(VRSHL_U, gen_gvec_urshl)
830e72a6878SRichard Henderson DO_3SAME(VQSHL_S, gen_neon_sqshl)
831e72a6878SRichard Henderson DO_3SAME(VQSHL_U, gen_neon_uqshl)
832cef9d54fSRichard Henderson DO_3SAME(VQRSHL_S, gen_neon_sqrshl)
833cef9d54fSRichard Henderson DO_3SAME(VQRSHL_U, gen_neon_uqrshl)
834f0984d40SFabiano Rosas 
835f0984d40SFabiano Rosas /* These insns are all gvec_bitsel but with the inputs in various orders. */
836f0984d40SFabiano Rosas #define DO_3SAME_BITSEL(INSN, O1, O2, O3)                               \
837f0984d40SFabiano Rosas     static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs,         \
838f0984d40SFabiano Rosas                                 uint32_t rn_ofs, uint32_t rm_ofs,       \
839f0984d40SFabiano Rosas                                 uint32_t oprsz, uint32_t maxsz)         \
840f0984d40SFabiano Rosas     {                                                                   \
841f0984d40SFabiano Rosas         tcg_gen_gvec_bitsel(vece, rd_ofs, O1, O2, O3, oprsz, maxsz);    \
842f0984d40SFabiano Rosas     }                                                                   \
843f0984d40SFabiano Rosas     DO_3SAME(INSN, gen_##INSN##_3s)
844f0984d40SFabiano Rosas 
845f0984d40SFabiano Rosas DO_3SAME_BITSEL(VBSL, rd_ofs, rn_ofs, rm_ofs)
846f0984d40SFabiano Rosas DO_3SAME_BITSEL(VBIT, rm_ofs, rn_ofs, rd_ofs)
847f0984d40SFabiano Rosas DO_3SAME_BITSEL(VBIF, rm_ofs, rd_ofs, rn_ofs)
848f0984d40SFabiano Rosas 
849f0984d40SFabiano Rosas #define DO_3SAME_NO_SZ_3(INSN, FUNC)                                    \
850f0984d40SFabiano Rosas     static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a)        \
851f0984d40SFabiano Rosas     {                                                                   \
852f0984d40SFabiano Rosas         if (a->size == 3) {                                             \
853f0984d40SFabiano Rosas             return false;                                               \
854f0984d40SFabiano Rosas         }                                                               \
855f0984d40SFabiano Rosas         return do_3same(s, a, FUNC);                                    \
856f0984d40SFabiano Rosas     }
857f0984d40SFabiano Rosas 
858f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VMAX_S, tcg_gen_gvec_smax)
859f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VMAX_U, tcg_gen_gvec_umax)
860f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VMIN_S, tcg_gen_gvec_smin)
861f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VMIN_U, tcg_gen_gvec_umin)
862f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VMUL, tcg_gen_gvec_mul)
863f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VMLA, gen_gvec_mla)
864f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VMLS, gen_gvec_mls)
865f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VTST, gen_gvec_cmtst)
866f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VABD_S, gen_gvec_sabd)
867f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VABA_S, gen_gvec_saba)
868f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VABD_U, gen_gvec_uabd)
869f0984d40SFabiano Rosas DO_3SAME_NO_SZ_3(VABA_U, gen_gvec_uaba)
870a11e54edSRichard Henderson DO_3SAME_NO_SZ_3(VPADD, gen_gvec_addp)
871a9240f48SRichard Henderson DO_3SAME_NO_SZ_3(VPMAX_S, gen_gvec_smaxp)
872a9240f48SRichard Henderson DO_3SAME_NO_SZ_3(VPMIN_S, gen_gvec_sminp)
873a9240f48SRichard Henderson DO_3SAME_NO_SZ_3(VPMAX_U, gen_gvec_umaxp)
874a9240f48SRichard Henderson DO_3SAME_NO_SZ_3(VPMIN_U, gen_gvec_uminp)
875203aca91SRichard Henderson DO_3SAME_NO_SZ_3(VHADD_S, gen_gvec_shadd)
876203aca91SRichard Henderson DO_3SAME_NO_SZ_3(VHADD_U, gen_gvec_uhadd)
87734c0d865SRichard Henderson DO_3SAME_NO_SZ_3(VHSUB_S, gen_gvec_shsub)
87834c0d865SRichard Henderson DO_3SAME_NO_SZ_3(VHSUB_U, gen_gvec_uhsub)
8798989b95eSRichard Henderson DO_3SAME_NO_SZ_3(VRHADD_S, gen_gvec_srhadd)
8808989b95eSRichard Henderson DO_3SAME_NO_SZ_3(VRHADD_U, gen_gvec_urhadd)
881f0984d40SFabiano Rosas 
882f0984d40SFabiano Rosas #define DO_3SAME_CMP(INSN, COND)                                        \
883f0984d40SFabiano Rosas     static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs,         \
884f0984d40SFabiano Rosas                                 uint32_t rn_ofs, uint32_t rm_ofs,       \
885f0984d40SFabiano Rosas                                 uint32_t oprsz, uint32_t maxsz)         \
886f0984d40SFabiano Rosas     {                                                                   \
887f0984d40SFabiano Rosas         tcg_gen_gvec_cmp(COND, vece, rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz); \
888f0984d40SFabiano Rosas     }                                                                   \
889f0984d40SFabiano Rosas     DO_3SAME_NO_SZ_3(INSN, gen_##INSN##_3s)
890f0984d40SFabiano Rosas 
891f0984d40SFabiano Rosas DO_3SAME_CMP(VCGT_S, TCG_COND_GT)
892f0984d40SFabiano Rosas DO_3SAME_CMP(VCGT_U, TCG_COND_GTU)
893f0984d40SFabiano Rosas DO_3SAME_CMP(VCGE_S, TCG_COND_GE)
894f0984d40SFabiano Rosas DO_3SAME_CMP(VCGE_U, TCG_COND_GEU)
895f0984d40SFabiano Rosas DO_3SAME_CMP(VCEQ, TCG_COND_EQ)
896f0984d40SFabiano Rosas 
897f0984d40SFabiano Rosas #define WRAP_OOL_FN(WRAPNAME, FUNC)                                        \
898f0984d40SFabiano Rosas     static void WRAPNAME(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs,  \
899f0984d40SFabiano Rosas                          uint32_t rm_ofs, uint32_t oprsz, uint32_t maxsz)  \
900f0984d40SFabiano Rosas     {                                                                      \
901f0984d40SFabiano Rosas         tcg_gen_gvec_3_ool(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, 0, FUNC); \
902f0984d40SFabiano Rosas     }
903f0984d40SFabiano Rosas 
904f0984d40SFabiano Rosas WRAP_OOL_FN(gen_VMUL_p_3s, gen_helper_gvec_pmul_b)
905f0984d40SFabiano Rosas 
906f0984d40SFabiano Rosas static bool trans_VMUL_p_3s(DisasContext *s, arg_3same *a)
907f0984d40SFabiano Rosas {
908f0984d40SFabiano Rosas     if (a->size != 0) {
909f0984d40SFabiano Rosas         return false;
910f0984d40SFabiano Rosas     }
911f0984d40SFabiano Rosas     return do_3same(s, a, gen_VMUL_p_3s);
912f0984d40SFabiano Rosas }
913f0984d40SFabiano Rosas 
914f0984d40SFabiano Rosas #define DO_VQRDMLAH(INSN, FUNC)                                         \
915f0984d40SFabiano Rosas     static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a)        \
916f0984d40SFabiano Rosas     {                                                                   \
917f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_rdm, s)) {                            \
918f0984d40SFabiano Rosas             return false;                                               \
919f0984d40SFabiano Rosas         }                                                               \
920f0984d40SFabiano Rosas         if (a->size != 1 && a->size != 2) {                             \
921f0984d40SFabiano Rosas             return false;                                               \
922f0984d40SFabiano Rosas         }                                                               \
923f0984d40SFabiano Rosas         return do_3same(s, a, FUNC);                                    \
924f0984d40SFabiano Rosas     }
925f0984d40SFabiano Rosas 
DO_VQRDMLAH(VQRDMLAH,gen_gvec_sqrdmlah_qc)926f0984d40SFabiano Rosas DO_VQRDMLAH(VQRDMLAH, gen_gvec_sqrdmlah_qc)
927f0984d40SFabiano Rosas DO_VQRDMLAH(VQRDMLSH, gen_gvec_sqrdmlsh_qc)
928f0984d40SFabiano Rosas 
929f0984d40SFabiano Rosas #define DO_SHA1(NAME, FUNC)                                             \
930f0984d40SFabiano Rosas     WRAP_OOL_FN(gen_##NAME##_3s, FUNC)                                  \
931f0984d40SFabiano Rosas     static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a)        \
932f0984d40SFabiano Rosas     {                                                                   \
933f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_sha1, s)) {                           \
934f0984d40SFabiano Rosas             return false;                                               \
935f0984d40SFabiano Rosas         }                                                               \
936f0984d40SFabiano Rosas         return do_3same(s, a, gen_##NAME##_3s);                         \
937f0984d40SFabiano Rosas     }
938f0984d40SFabiano Rosas 
939f0984d40SFabiano Rosas DO_SHA1(SHA1C, gen_helper_crypto_sha1c)
940f0984d40SFabiano Rosas DO_SHA1(SHA1P, gen_helper_crypto_sha1p)
941f0984d40SFabiano Rosas DO_SHA1(SHA1M, gen_helper_crypto_sha1m)
942f0984d40SFabiano Rosas DO_SHA1(SHA1SU0, gen_helper_crypto_sha1su0)
943f0984d40SFabiano Rosas 
944f0984d40SFabiano Rosas #define DO_SHA2(NAME, FUNC)                                             \
945f0984d40SFabiano Rosas     WRAP_OOL_FN(gen_##NAME##_3s, FUNC)                                  \
946f0984d40SFabiano Rosas     static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a)        \
947f0984d40SFabiano Rosas     {                                                                   \
948f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_sha2, s)) {                           \
949f0984d40SFabiano Rosas             return false;                                               \
950f0984d40SFabiano Rosas         }                                                               \
951f0984d40SFabiano Rosas         return do_3same(s, a, gen_##NAME##_3s);                         \
952f0984d40SFabiano Rosas     }
953f0984d40SFabiano Rosas 
954f0984d40SFabiano Rosas DO_SHA2(SHA256H, gen_helper_crypto_sha256h)
955f0984d40SFabiano Rosas DO_SHA2(SHA256H2, gen_helper_crypto_sha256h2)
956f0984d40SFabiano Rosas DO_SHA2(SHA256SU1, gen_helper_crypto_sha256su1)
957f0984d40SFabiano Rosas 
958f0984d40SFabiano Rosas /*
959ad75a51eSRichard Henderson  * Some helper functions need to be passed the tcg_env. In order
960f0984d40SFabiano Rosas  * to use those with the gvec APIs like tcg_gen_gvec_3() we need
961f0984d40SFabiano Rosas  * to create wrapper functions whose prototype is a NeonGenTwoOpFn()
962f0984d40SFabiano Rosas  * and which call a NeonGenTwoOpEnvFn().
963f0984d40SFabiano Rosas  */
964f0984d40SFabiano Rosas #define WRAP_ENV_FN(WRAPNAME, FUNC)                                     \
965f0984d40SFabiano Rosas     static void WRAPNAME(TCGv_i32 d, TCGv_i32 n, TCGv_i32 m)            \
966f0984d40SFabiano Rosas     {                                                                   \
967ad75a51eSRichard Henderson         FUNC(d, tcg_env, n, m);                                         \
968f0984d40SFabiano Rosas     }
969f0984d40SFabiano Rosas 
970f0984d40SFabiano Rosas #define DO_3SAME_VQDMULH(INSN, FUNC)                                    \
971f0984d40SFabiano Rosas     static bool trans_##INSN##_3s(DisasContext *s, arg_3same *a)        \
9728f81dcedSRichard Henderson     { return a->size >= 1 && a->size <= 2 && do_3same(s, a, FUNC); }
973f0984d40SFabiano Rosas 
9748f81dcedSRichard Henderson DO_3SAME_VQDMULH(VQDMULH, gen_gvec_sqdmulh_qc)
9758f81dcedSRichard Henderson DO_3SAME_VQDMULH(VQRDMULH, gen_gvec_sqrdmulh_qc)
976f0984d40SFabiano Rosas 
977f0984d40SFabiano Rosas #define WRAP_FP_GVEC(WRAPNAME, FPST, FUNC)                              \
978f0984d40SFabiano Rosas     static void WRAPNAME(unsigned vece, uint32_t rd_ofs,                \
979f0984d40SFabiano Rosas                          uint32_t rn_ofs, uint32_t rm_ofs,              \
980f0984d40SFabiano Rosas                          uint32_t oprsz, uint32_t maxsz)                \
981f0984d40SFabiano Rosas     {                                                                   \
982f0984d40SFabiano Rosas         TCGv_ptr fpst = fpstatus_ptr(FPST);                             \
983f0984d40SFabiano Rosas         tcg_gen_gvec_3_ptr(rd_ofs, rn_ofs, rm_ofs, fpst,                \
984f0984d40SFabiano Rosas                            oprsz, maxsz, 0, FUNC);                      \
985f0984d40SFabiano Rosas     }
986f0984d40SFabiano Rosas 
987f0984d40SFabiano Rosas #define DO_3S_FP_GVEC(INSN,SFUNC,HFUNC)                                 \
988f0984d40SFabiano Rosas     WRAP_FP_GVEC(gen_##INSN##_fp32_3s, FPST_STD, SFUNC)                 \
989f0984d40SFabiano Rosas     WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC)             \
990f0984d40SFabiano Rosas     static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a)     \
991f0984d40SFabiano Rosas     {                                                                   \
992f0984d40SFabiano Rosas         if (a->size == MO_16) {                                         \
993f0984d40SFabiano Rosas             if (!dc_isar_feature(aa32_fp16_arith, s)) {                 \
994f0984d40SFabiano Rosas                 return false;                                           \
995f0984d40SFabiano Rosas             }                                                           \
996f0984d40SFabiano Rosas             return do_3same(s, a, gen_##INSN##_fp16_3s);                \
997f0984d40SFabiano Rosas         }                                                               \
998f0984d40SFabiano Rosas         return do_3same(s, a, gen_##INSN##_fp32_3s);                    \
999f0984d40SFabiano Rosas     }
1000f0984d40SFabiano Rosas 
1001f0984d40SFabiano Rosas 
1002f0984d40SFabiano Rosas DO_3S_FP_GVEC(VADD, gen_helper_gvec_fadd_s, gen_helper_gvec_fadd_h)
1003f0984d40SFabiano Rosas DO_3S_FP_GVEC(VSUB, gen_helper_gvec_fsub_s, gen_helper_gvec_fsub_h)
1004f0984d40SFabiano Rosas DO_3S_FP_GVEC(VABD, gen_helper_gvec_fabd_s, gen_helper_gvec_fabd_h)
1005f0984d40SFabiano Rosas DO_3S_FP_GVEC(VMUL, gen_helper_gvec_fmul_s, gen_helper_gvec_fmul_h)
1006f0984d40SFabiano Rosas DO_3S_FP_GVEC(VCEQ, gen_helper_gvec_fceq_s, gen_helper_gvec_fceq_h)
1007f0984d40SFabiano Rosas DO_3S_FP_GVEC(VCGE, gen_helper_gvec_fcge_s, gen_helper_gvec_fcge_h)
1008f0984d40SFabiano Rosas DO_3S_FP_GVEC(VCGT, gen_helper_gvec_fcgt_s, gen_helper_gvec_fcgt_h)
1009f0984d40SFabiano Rosas DO_3S_FP_GVEC(VACGE, gen_helper_gvec_facge_s, gen_helper_gvec_facge_h)
1010f0984d40SFabiano Rosas DO_3S_FP_GVEC(VACGT, gen_helper_gvec_facgt_s, gen_helper_gvec_facgt_h)
1011f0984d40SFabiano Rosas DO_3S_FP_GVEC(VMAX, gen_helper_gvec_fmax_s, gen_helper_gvec_fmax_h)
1012f0984d40SFabiano Rosas DO_3S_FP_GVEC(VMIN, gen_helper_gvec_fmin_s, gen_helper_gvec_fmin_h)
1013f0984d40SFabiano Rosas DO_3S_FP_GVEC(VMLA, gen_helper_gvec_fmla_s, gen_helper_gvec_fmla_h)
1014f0984d40SFabiano Rosas DO_3S_FP_GVEC(VMLS, gen_helper_gvec_fmls_s, gen_helper_gvec_fmls_h)
1015f0984d40SFabiano Rosas DO_3S_FP_GVEC(VFMA, gen_helper_gvec_vfma_s, gen_helper_gvec_vfma_h)
1016f0984d40SFabiano Rosas DO_3S_FP_GVEC(VFMS, gen_helper_gvec_vfms_s, gen_helper_gvec_vfms_h)
1017f0984d40SFabiano Rosas DO_3S_FP_GVEC(VRECPS, gen_helper_gvec_recps_nf_s, gen_helper_gvec_recps_nf_h)
1018f0984d40SFabiano Rosas DO_3S_FP_GVEC(VRSQRTS, gen_helper_gvec_rsqrts_nf_s, gen_helper_gvec_rsqrts_nf_h)
1019c43a23e1SRichard Henderson DO_3S_FP_GVEC(VPADD, gen_helper_gvec_faddp_s, gen_helper_gvec_faddp_h)
1020c43a23e1SRichard Henderson DO_3S_FP_GVEC(VPMAX, gen_helper_gvec_fmaxp_s, gen_helper_gvec_fmaxp_h)
1021c43a23e1SRichard Henderson DO_3S_FP_GVEC(VPMIN, gen_helper_gvec_fminp_s, gen_helper_gvec_fminp_h)
1022f0984d40SFabiano Rosas 
1023f0984d40SFabiano Rosas WRAP_FP_GVEC(gen_VMAXNM_fp32_3s, FPST_STD, gen_helper_gvec_fmaxnum_s)
1024f0984d40SFabiano Rosas WRAP_FP_GVEC(gen_VMAXNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fmaxnum_h)
1025f0984d40SFabiano Rosas WRAP_FP_GVEC(gen_VMINNM_fp32_3s, FPST_STD, gen_helper_gvec_fminnum_s)
1026f0984d40SFabiano Rosas WRAP_FP_GVEC(gen_VMINNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fminnum_h)
1027f0984d40SFabiano Rosas 
1028f0984d40SFabiano Rosas static bool trans_VMAXNM_fp_3s(DisasContext *s, arg_3same *a)
1029f0984d40SFabiano Rosas {
1030f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_V8)) {
1031f0984d40SFabiano Rosas         return false;
1032f0984d40SFabiano Rosas     }
1033f0984d40SFabiano Rosas 
1034f0984d40SFabiano Rosas     if (a->size == MO_16) {
1035f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_fp16_arith, s)) {
1036f0984d40SFabiano Rosas             return false;
1037f0984d40SFabiano Rosas         }
1038f0984d40SFabiano Rosas         return do_3same(s, a, gen_VMAXNM_fp16_3s);
1039f0984d40SFabiano Rosas     }
1040f0984d40SFabiano Rosas     return do_3same(s, a, gen_VMAXNM_fp32_3s);
1041f0984d40SFabiano Rosas }
1042f0984d40SFabiano Rosas 
trans_VMINNM_fp_3s(DisasContext * s,arg_3same * a)1043f0984d40SFabiano Rosas static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a)
1044f0984d40SFabiano Rosas {
1045f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_V8)) {
1046f0984d40SFabiano Rosas         return false;
1047f0984d40SFabiano Rosas     }
1048f0984d40SFabiano Rosas 
1049f0984d40SFabiano Rosas     if (a->size == MO_16) {
1050f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_fp16_arith, s)) {
1051f0984d40SFabiano Rosas             return false;
1052f0984d40SFabiano Rosas         }
1053f0984d40SFabiano Rosas         return do_3same(s, a, gen_VMINNM_fp16_3s);
1054f0984d40SFabiano Rosas     }
1055f0984d40SFabiano Rosas     return do_3same(s, a, gen_VMINNM_fp32_3s);
1056f0984d40SFabiano Rosas }
1057f0984d40SFabiano Rosas 
do_vector_2sh(DisasContext * s,arg_2reg_shift * a,GVecGen2iFn * fn)1058f0984d40SFabiano Rosas static bool do_vector_2sh(DisasContext *s, arg_2reg_shift *a, GVecGen2iFn *fn)
1059f0984d40SFabiano Rosas {
1060f0984d40SFabiano Rosas     /* Handle a 2-reg-shift insn which can be vectorized. */
1061f0984d40SFabiano Rosas     int vec_size = a->q ? 16 : 8;
1062f0984d40SFabiano Rosas     int rd_ofs = neon_full_reg_offset(a->vd);
1063f0984d40SFabiano Rosas     int rm_ofs = neon_full_reg_offset(a->vm);
1064f0984d40SFabiano Rosas 
1065f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1066f0984d40SFabiano Rosas         return false;
1067f0984d40SFabiano Rosas     }
1068f0984d40SFabiano Rosas 
1069f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1070f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1071f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
1072f0984d40SFabiano Rosas         return false;
1073f0984d40SFabiano Rosas     }
1074f0984d40SFabiano Rosas 
1075f0984d40SFabiano Rosas     if ((a->vm | a->vd) & a->q) {
1076f0984d40SFabiano Rosas         return false;
1077f0984d40SFabiano Rosas     }
1078f0984d40SFabiano Rosas 
1079f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1080f0984d40SFabiano Rosas         return true;
1081f0984d40SFabiano Rosas     }
1082f0984d40SFabiano Rosas 
1083f0984d40SFabiano Rosas     fn(a->size, rd_ofs, rm_ofs, a->shift, vec_size, vec_size);
1084f0984d40SFabiano Rosas     return true;
1085f0984d40SFabiano Rosas }
1086f0984d40SFabiano Rosas 
1087f0984d40SFabiano Rosas #define DO_2SH(INSN, FUNC)                                              \
1088f0984d40SFabiano Rosas     static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a)  \
1089f0984d40SFabiano Rosas     {                                                                   \
1090f0984d40SFabiano Rosas         return do_vector_2sh(s, a, FUNC);                               \
1091f0984d40SFabiano Rosas     }                                                                   \
1092f0984d40SFabiano Rosas 
DO_2SH(VSHL,tcg_gen_gvec_shli)1093f0984d40SFabiano Rosas DO_2SH(VSHL, tcg_gen_gvec_shli)
1094f0984d40SFabiano Rosas DO_2SH(VSLI, gen_gvec_sli)
1095f0984d40SFabiano Rosas DO_2SH(VSRI, gen_gvec_sri)
1096f0984d40SFabiano Rosas DO_2SH(VSRA_S, gen_gvec_ssra)
1097f0984d40SFabiano Rosas DO_2SH(VSRA_U, gen_gvec_usra)
1098f0984d40SFabiano Rosas DO_2SH(VRSHR_S, gen_gvec_srshr)
1099f0984d40SFabiano Rosas DO_2SH(VRSHR_U, gen_gvec_urshr)
1100f0984d40SFabiano Rosas DO_2SH(VRSRA_S, gen_gvec_srsra)
1101f0984d40SFabiano Rosas DO_2SH(VRSRA_U, gen_gvec_ursra)
110200bcab5bSRichard Henderson DO_2SH(VSHR_S, gen_gvec_sshr)
110300bcab5bSRichard Henderson DO_2SH(VSHR_U, gen_gvec_ushr)
1104ef2b80ebSRichard Henderson DO_2SH(VQSHLU, gen_neon_sqshlui)
1105ef2b80ebSRichard Henderson DO_2SH(VQSHL_U, gen_neon_uqshli)
1106ef2b80ebSRichard Henderson DO_2SH(VQSHL_S, gen_neon_sqshli)
1107f0984d40SFabiano Rosas 
1108f0984d40SFabiano Rosas static bool do_2shift_narrow_64(DisasContext *s, arg_2reg_shift *a,
1109f0984d40SFabiano Rosas                                 NeonGenTwo64OpFn *shiftfn,
1110*3e683f0aSRichard Henderson                                 NeonGenOne64OpEnvFn *narrowfn)
1111f0984d40SFabiano Rosas {
1112f0984d40SFabiano Rosas     /* 2-reg-and-shift narrowing-shift operations, size == 3 case */
1113*3e683f0aSRichard Henderson     TCGv_i64 constimm, rm1, rm2, rd;
1114f0984d40SFabiano Rosas 
1115f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1116f0984d40SFabiano Rosas         return false;
1117f0984d40SFabiano Rosas     }
1118f0984d40SFabiano Rosas 
1119f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1120f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1121f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
1122f0984d40SFabiano Rosas         return false;
1123f0984d40SFabiano Rosas     }
1124f0984d40SFabiano Rosas 
1125f0984d40SFabiano Rosas     if (a->vm & 1) {
1126f0984d40SFabiano Rosas         return false;
1127f0984d40SFabiano Rosas     }
1128f0984d40SFabiano Rosas 
1129f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1130f0984d40SFabiano Rosas         return true;
1131f0984d40SFabiano Rosas     }
1132f0984d40SFabiano Rosas 
1133f0984d40SFabiano Rosas     /*
1134f0984d40SFabiano Rosas      * This is always a right shift, and the shiftfn is always a
1135f0984d40SFabiano Rosas      * left-shift helper, which thus needs the negated shift count.
1136f0984d40SFabiano Rosas      */
1137f0984d40SFabiano Rosas     constimm = tcg_constant_i64(-a->shift);
1138f0984d40SFabiano Rosas     rm1 = tcg_temp_new_i64();
1139f0984d40SFabiano Rosas     rm2 = tcg_temp_new_i64();
1140*3e683f0aSRichard Henderson     rd = tcg_temp_new_i64();
1141f0984d40SFabiano Rosas 
1142f0984d40SFabiano Rosas     /* Load both inputs first to avoid potential overwrite if rm == rd */
1143f0984d40SFabiano Rosas     read_neon_element64(rm1, a->vm, 0, MO_64);
1144f0984d40SFabiano Rosas     read_neon_element64(rm2, a->vm, 1, MO_64);
1145f0984d40SFabiano Rosas 
1146f0984d40SFabiano Rosas     shiftfn(rm1, rm1, constimm);
1147ad75a51eSRichard Henderson     narrowfn(rd, tcg_env, rm1);
1148*3e683f0aSRichard Henderson     write_neon_element64(rd, a->vd, 0, MO_32);
1149f0984d40SFabiano Rosas 
1150f0984d40SFabiano Rosas     shiftfn(rm2, rm2, constimm);
1151ad75a51eSRichard Henderson     narrowfn(rd, tcg_env, rm2);
1152*3e683f0aSRichard Henderson     write_neon_element64(rd, a->vd, 1, MO_32);
1153f0984d40SFabiano Rosas 
1154f0984d40SFabiano Rosas     return true;
1155f0984d40SFabiano Rosas }
1156f0984d40SFabiano Rosas 
do_2shift_narrow_32(DisasContext * s,arg_2reg_shift * a,NeonGenTwoOpFn * shiftfn,NeonGenOne64OpEnvFn * narrowfn)1157f0984d40SFabiano Rosas static bool do_2shift_narrow_32(DisasContext *s, arg_2reg_shift *a,
1158f0984d40SFabiano Rosas                                 NeonGenTwoOpFn *shiftfn,
1159*3e683f0aSRichard Henderson                                 NeonGenOne64OpEnvFn *narrowfn)
1160f0984d40SFabiano Rosas {
1161f0984d40SFabiano Rosas     /* 2-reg-and-shift narrowing-shift operations, size < 3 case */
1162f0984d40SFabiano Rosas     TCGv_i32 constimm, rm1, rm2, rm3, rm4;
1163f0984d40SFabiano Rosas     TCGv_i64 rtmp;
1164f0984d40SFabiano Rosas     uint32_t imm;
1165f0984d40SFabiano Rosas 
1166f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1167f0984d40SFabiano Rosas         return false;
1168f0984d40SFabiano Rosas     }
1169f0984d40SFabiano Rosas 
1170f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1171f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1172f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
1173f0984d40SFabiano Rosas         return false;
1174f0984d40SFabiano Rosas     }
1175f0984d40SFabiano Rosas 
1176f0984d40SFabiano Rosas     if (a->vm & 1) {
1177f0984d40SFabiano Rosas         return false;
1178f0984d40SFabiano Rosas     }
1179f0984d40SFabiano Rosas 
1180f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1181f0984d40SFabiano Rosas         return true;
1182f0984d40SFabiano Rosas     }
1183f0984d40SFabiano Rosas 
1184f0984d40SFabiano Rosas     /*
1185f0984d40SFabiano Rosas      * This is always a right shift, and the shiftfn is always a
1186f0984d40SFabiano Rosas      * left-shift helper, which thus needs the negated shift count
1187f0984d40SFabiano Rosas      * duplicated into each lane of the immediate value.
1188f0984d40SFabiano Rosas      */
1189f0984d40SFabiano Rosas     if (a->size == 1) {
1190f0984d40SFabiano Rosas         imm = (uint16_t)(-a->shift);
1191f0984d40SFabiano Rosas         imm |= imm << 16;
1192f0984d40SFabiano Rosas     } else {
1193f0984d40SFabiano Rosas         /* size == 2 */
1194f0984d40SFabiano Rosas         imm = -a->shift;
1195f0984d40SFabiano Rosas     }
1196f0984d40SFabiano Rosas     constimm = tcg_constant_i32(imm);
1197f0984d40SFabiano Rosas 
1198f0984d40SFabiano Rosas     /* Load all inputs first to avoid potential overwrite */
1199f0984d40SFabiano Rosas     rm1 = tcg_temp_new_i32();
1200f0984d40SFabiano Rosas     rm2 = tcg_temp_new_i32();
1201f0984d40SFabiano Rosas     rm3 = tcg_temp_new_i32();
1202f0984d40SFabiano Rosas     rm4 = tcg_temp_new_i32();
1203f0984d40SFabiano Rosas     read_neon_element32(rm1, a->vm, 0, MO_32);
1204f0984d40SFabiano Rosas     read_neon_element32(rm2, a->vm, 1, MO_32);
1205f0984d40SFabiano Rosas     read_neon_element32(rm3, a->vm, 2, MO_32);
1206f0984d40SFabiano Rosas     read_neon_element32(rm4, a->vm, 3, MO_32);
1207f0984d40SFabiano Rosas     rtmp = tcg_temp_new_i64();
1208f0984d40SFabiano Rosas 
1209f0984d40SFabiano Rosas     shiftfn(rm1, rm1, constimm);
1210f0984d40SFabiano Rosas     shiftfn(rm2, rm2, constimm);
1211f0984d40SFabiano Rosas 
1212f0984d40SFabiano Rosas     tcg_gen_concat_i32_i64(rtmp, rm1, rm2);
1213f0984d40SFabiano Rosas 
1214*3e683f0aSRichard Henderson     narrowfn(rtmp, tcg_env, rtmp);
1215*3e683f0aSRichard Henderson     write_neon_element64(rtmp, a->vd, 0, MO_32);
1216f0984d40SFabiano Rosas 
1217f0984d40SFabiano Rosas     shiftfn(rm3, rm3, constimm);
1218f0984d40SFabiano Rosas     shiftfn(rm4, rm4, constimm);
1219f0984d40SFabiano Rosas 
1220f0984d40SFabiano Rosas     tcg_gen_concat_i32_i64(rtmp, rm3, rm4);
1221f0984d40SFabiano Rosas 
1222*3e683f0aSRichard Henderson     narrowfn(rtmp, tcg_env, rtmp);
1223*3e683f0aSRichard Henderson     write_neon_element64(rtmp, a->vd, 1, MO_32);
1224f0984d40SFabiano Rosas     return true;
1225f0984d40SFabiano Rosas }
1226f0984d40SFabiano Rosas 
1227f0984d40SFabiano Rosas #define DO_2SN_64(INSN, FUNC, NARROWFUNC)                               \
1228f0984d40SFabiano Rosas     static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a)  \
1229f0984d40SFabiano Rosas     {                                                                   \
1230f0984d40SFabiano Rosas         return do_2shift_narrow_64(s, a, FUNC, NARROWFUNC);             \
1231f0984d40SFabiano Rosas     }
1232f0984d40SFabiano Rosas #define DO_2SN_32(INSN, FUNC, NARROWFUNC)                               \
1233f0984d40SFabiano Rosas     static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a)  \
1234f0984d40SFabiano Rosas     {                                                                   \
1235f0984d40SFabiano Rosas         return do_2shift_narrow_32(s, a, FUNC, NARROWFUNC);             \
1236f0984d40SFabiano Rosas     }
1237f0984d40SFabiano Rosas 
gen_neon_narrow_u32(TCGv_i64 dest,TCGv_ptr env,TCGv_i64 src)1238*3e683f0aSRichard Henderson static void gen_neon_narrow_u32(TCGv_i64 dest, TCGv_ptr env, TCGv_i64 src)
1239f0984d40SFabiano Rosas {
1240*3e683f0aSRichard Henderson     tcg_gen_ext32u_i64(dest, src);
1241f0984d40SFabiano Rosas }
1242f0984d40SFabiano Rosas 
gen_neon_narrow_u16(TCGv_i64 dest,TCGv_ptr env,TCGv_i64 src)1243*3e683f0aSRichard Henderson static void gen_neon_narrow_u16(TCGv_i64 dest, TCGv_ptr env, TCGv_i64 src)
1244f0984d40SFabiano Rosas {
1245f0984d40SFabiano Rosas     gen_helper_neon_narrow_u16(dest, src);
1246f0984d40SFabiano Rosas }
1247f0984d40SFabiano Rosas 
gen_neon_narrow_u8(TCGv_i64 dest,TCGv_ptr env,TCGv_i64 src)1248*3e683f0aSRichard Henderson static void gen_neon_narrow_u8(TCGv_i64 dest, TCGv_ptr env, TCGv_i64 src)
1249f0984d40SFabiano Rosas {
1250f0984d40SFabiano Rosas     gen_helper_neon_narrow_u8(dest, src);
1251f0984d40SFabiano Rosas }
1252f0984d40SFabiano Rosas 
DO_2SN_64(VSHRN_64,gen_ushl_i64,gen_neon_narrow_u32)1253f0984d40SFabiano Rosas DO_2SN_64(VSHRN_64, gen_ushl_i64, gen_neon_narrow_u32)
1254f0984d40SFabiano Rosas DO_2SN_32(VSHRN_32, gen_ushl_i32, gen_neon_narrow_u16)
1255f0984d40SFabiano Rosas DO_2SN_32(VSHRN_16, gen_helper_neon_shl_u16, gen_neon_narrow_u8)
1256f0984d40SFabiano Rosas 
1257f0984d40SFabiano Rosas DO_2SN_64(VRSHRN_64, gen_helper_neon_rshl_u64, gen_neon_narrow_u32)
1258f0984d40SFabiano Rosas DO_2SN_32(VRSHRN_32, gen_helper_neon_rshl_u32, gen_neon_narrow_u16)
1259f0984d40SFabiano Rosas DO_2SN_32(VRSHRN_16, gen_helper_neon_rshl_u16, gen_neon_narrow_u8)
1260f0984d40SFabiano Rosas 
1261f0984d40SFabiano Rosas DO_2SN_64(VQSHRUN_64, gen_sshl_i64, gen_helper_neon_unarrow_sat32)
1262f0984d40SFabiano Rosas DO_2SN_32(VQSHRUN_32, gen_sshl_i32, gen_helper_neon_unarrow_sat16)
1263f0984d40SFabiano Rosas DO_2SN_32(VQSHRUN_16, gen_helper_neon_shl_s16, gen_helper_neon_unarrow_sat8)
1264f0984d40SFabiano Rosas 
1265f0984d40SFabiano Rosas DO_2SN_64(VQRSHRUN_64, gen_helper_neon_rshl_s64, gen_helper_neon_unarrow_sat32)
1266f0984d40SFabiano Rosas DO_2SN_32(VQRSHRUN_32, gen_helper_neon_rshl_s32, gen_helper_neon_unarrow_sat16)
1267f0984d40SFabiano Rosas DO_2SN_32(VQRSHRUN_16, gen_helper_neon_rshl_s16, gen_helper_neon_unarrow_sat8)
1268f0984d40SFabiano Rosas DO_2SN_64(VQSHRN_S64, gen_sshl_i64, gen_helper_neon_narrow_sat_s32)
1269f0984d40SFabiano Rosas DO_2SN_32(VQSHRN_S32, gen_sshl_i32, gen_helper_neon_narrow_sat_s16)
1270f0984d40SFabiano Rosas DO_2SN_32(VQSHRN_S16, gen_helper_neon_shl_s16, gen_helper_neon_narrow_sat_s8)
1271f0984d40SFabiano Rosas 
1272f0984d40SFabiano Rosas DO_2SN_64(VQRSHRN_S64, gen_helper_neon_rshl_s64, gen_helper_neon_narrow_sat_s32)
1273f0984d40SFabiano Rosas DO_2SN_32(VQRSHRN_S32, gen_helper_neon_rshl_s32, gen_helper_neon_narrow_sat_s16)
1274f0984d40SFabiano Rosas DO_2SN_32(VQRSHRN_S16, gen_helper_neon_rshl_s16, gen_helper_neon_narrow_sat_s8)
1275f0984d40SFabiano Rosas 
1276f0984d40SFabiano Rosas DO_2SN_64(VQSHRN_U64, gen_ushl_i64, gen_helper_neon_narrow_sat_u32)
1277f0984d40SFabiano Rosas DO_2SN_32(VQSHRN_U32, gen_ushl_i32, gen_helper_neon_narrow_sat_u16)
1278f0984d40SFabiano Rosas DO_2SN_32(VQSHRN_U16, gen_helper_neon_shl_u16, gen_helper_neon_narrow_sat_u8)
1279f0984d40SFabiano Rosas 
1280f0984d40SFabiano Rosas DO_2SN_64(VQRSHRN_U64, gen_helper_neon_rshl_u64, gen_helper_neon_narrow_sat_u32)
1281f0984d40SFabiano Rosas DO_2SN_32(VQRSHRN_U32, gen_helper_neon_rshl_u32, gen_helper_neon_narrow_sat_u16)
1282f0984d40SFabiano Rosas DO_2SN_32(VQRSHRN_U16, gen_helper_neon_rshl_u16, gen_helper_neon_narrow_sat_u8)
1283f0984d40SFabiano Rosas 
1284f0984d40SFabiano Rosas static bool do_vshll_2sh(DisasContext *s, arg_2reg_shift *a,
1285f0984d40SFabiano Rosas                          NeonGenWidenFn *widenfn, bool u)
1286f0984d40SFabiano Rosas {
1287f0984d40SFabiano Rosas     TCGv_i64 tmp;
1288f0984d40SFabiano Rosas     TCGv_i32 rm0, rm1;
1289f0984d40SFabiano Rosas     uint64_t widen_mask = 0;
1290f0984d40SFabiano Rosas 
1291f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1292f0984d40SFabiano Rosas         return false;
1293f0984d40SFabiano Rosas     }
1294f0984d40SFabiano Rosas 
1295f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1296f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1297f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
1298f0984d40SFabiano Rosas         return false;
1299f0984d40SFabiano Rosas     }
1300f0984d40SFabiano Rosas 
1301f0984d40SFabiano Rosas     if (a->vd & 1) {
1302f0984d40SFabiano Rosas         return false;
1303f0984d40SFabiano Rosas     }
1304f0984d40SFabiano Rosas 
1305f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1306f0984d40SFabiano Rosas         return true;
1307f0984d40SFabiano Rosas     }
1308f0984d40SFabiano Rosas 
1309f0984d40SFabiano Rosas     /*
1310f0984d40SFabiano Rosas      * This is a widen-and-shift operation. The shift is always less
1311f0984d40SFabiano Rosas      * than the width of the source type, so after widening the input
1312f0984d40SFabiano Rosas      * vector we can simply shift the whole 64-bit widened register,
1313f0984d40SFabiano Rosas      * and then clear the potential overflow bits resulting from left
1314f0984d40SFabiano Rosas      * bits of the narrow input appearing as right bits of the left
1315f0984d40SFabiano Rosas      * neighbour narrow input. Calculate a mask of bits to clear.
1316f0984d40SFabiano Rosas      */
1317f0984d40SFabiano Rosas     if ((a->shift != 0) && (a->size < 2 || u)) {
1318f0984d40SFabiano Rosas         int esize = 8 << a->size;
1319f0984d40SFabiano Rosas         widen_mask = MAKE_64BIT_MASK(0, esize);
1320f0984d40SFabiano Rosas         widen_mask >>= esize - a->shift;
1321f0984d40SFabiano Rosas         widen_mask = dup_const(a->size + 1, widen_mask);
1322f0984d40SFabiano Rosas     }
1323f0984d40SFabiano Rosas 
1324f0984d40SFabiano Rosas     rm0 = tcg_temp_new_i32();
1325f0984d40SFabiano Rosas     rm1 = tcg_temp_new_i32();
1326f0984d40SFabiano Rosas     read_neon_element32(rm0, a->vm, 0, MO_32);
1327f0984d40SFabiano Rosas     read_neon_element32(rm1, a->vm, 1, MO_32);
1328f0984d40SFabiano Rosas     tmp = tcg_temp_new_i64();
1329f0984d40SFabiano Rosas 
1330f0984d40SFabiano Rosas     widenfn(tmp, rm0);
1331f0984d40SFabiano Rosas     if (a->shift != 0) {
1332f0984d40SFabiano Rosas         tcg_gen_shli_i64(tmp, tmp, a->shift);
1333f0984d40SFabiano Rosas         tcg_gen_andi_i64(tmp, tmp, ~widen_mask);
1334f0984d40SFabiano Rosas     }
1335f0984d40SFabiano Rosas     write_neon_element64(tmp, a->vd, 0, MO_64);
1336f0984d40SFabiano Rosas 
1337f0984d40SFabiano Rosas     widenfn(tmp, rm1);
1338f0984d40SFabiano Rosas     if (a->shift != 0) {
1339f0984d40SFabiano Rosas         tcg_gen_shli_i64(tmp, tmp, a->shift);
1340f0984d40SFabiano Rosas         tcg_gen_andi_i64(tmp, tmp, ~widen_mask);
1341f0984d40SFabiano Rosas     }
1342f0984d40SFabiano Rosas     write_neon_element64(tmp, a->vd, 1, MO_64);
1343f0984d40SFabiano Rosas     return true;
1344f0984d40SFabiano Rosas }
1345f0984d40SFabiano Rosas 
trans_VSHLL_S_2sh(DisasContext * s,arg_2reg_shift * a)1346f0984d40SFabiano Rosas static bool trans_VSHLL_S_2sh(DisasContext *s, arg_2reg_shift *a)
1347f0984d40SFabiano Rosas {
1348f0984d40SFabiano Rosas     static NeonGenWidenFn * const widenfn[] = {
1349f0984d40SFabiano Rosas         gen_helper_neon_widen_s8,
1350f0984d40SFabiano Rosas         gen_helper_neon_widen_s16,
1351f0984d40SFabiano Rosas         tcg_gen_ext_i32_i64,
1352f0984d40SFabiano Rosas     };
1353f0984d40SFabiano Rosas     return do_vshll_2sh(s, a, widenfn[a->size], false);
1354f0984d40SFabiano Rosas }
1355f0984d40SFabiano Rosas 
trans_VSHLL_U_2sh(DisasContext * s,arg_2reg_shift * a)1356f0984d40SFabiano Rosas static bool trans_VSHLL_U_2sh(DisasContext *s, arg_2reg_shift *a)
1357f0984d40SFabiano Rosas {
1358f0984d40SFabiano Rosas     static NeonGenWidenFn * const widenfn[] = {
1359f0984d40SFabiano Rosas         gen_helper_neon_widen_u8,
1360f0984d40SFabiano Rosas         gen_helper_neon_widen_u16,
1361f0984d40SFabiano Rosas         tcg_gen_extu_i32_i64,
1362f0984d40SFabiano Rosas     };
1363f0984d40SFabiano Rosas     return do_vshll_2sh(s, a, widenfn[a->size], true);
1364f0984d40SFabiano Rosas }
1365f0984d40SFabiano Rosas 
do_fp_2sh(DisasContext * s,arg_2reg_shift * a,gen_helper_gvec_2_ptr * fn)1366f0984d40SFabiano Rosas static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a,
1367f0984d40SFabiano Rosas                       gen_helper_gvec_2_ptr *fn)
1368f0984d40SFabiano Rosas {
1369f0984d40SFabiano Rosas     /* FP operations in 2-reg-and-shift group */
1370f0984d40SFabiano Rosas     int vec_size = a->q ? 16 : 8;
1371f0984d40SFabiano Rosas     int rd_ofs = neon_full_reg_offset(a->vd);
1372f0984d40SFabiano Rosas     int rm_ofs = neon_full_reg_offset(a->vm);
1373f0984d40SFabiano Rosas     TCGv_ptr fpst;
1374f0984d40SFabiano Rosas 
1375f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1376f0984d40SFabiano Rosas         return false;
1377f0984d40SFabiano Rosas     }
1378f0984d40SFabiano Rosas 
1379f0984d40SFabiano Rosas     if (a->size == MO_16) {
1380f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_fp16_arith, s)) {
1381f0984d40SFabiano Rosas             return false;
1382f0984d40SFabiano Rosas         }
1383f0984d40SFabiano Rosas     }
1384f0984d40SFabiano Rosas 
1385f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1386f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1387f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
1388f0984d40SFabiano Rosas         return false;
1389f0984d40SFabiano Rosas     }
1390f0984d40SFabiano Rosas 
1391f0984d40SFabiano Rosas     if ((a->vm | a->vd) & a->q) {
1392f0984d40SFabiano Rosas         return false;
1393f0984d40SFabiano Rosas     }
1394f0984d40SFabiano Rosas 
1395f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1396f0984d40SFabiano Rosas         return true;
1397f0984d40SFabiano Rosas     }
1398f0984d40SFabiano Rosas 
1399f0984d40SFabiano Rosas     fpst = fpstatus_ptr(a->size == MO_16 ? FPST_STD_F16 : FPST_STD);
1400f0984d40SFabiano Rosas     tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, vec_size, vec_size, a->shift, fn);
1401f0984d40SFabiano Rosas     return true;
1402f0984d40SFabiano Rosas }
1403f0984d40SFabiano Rosas 
1404f0984d40SFabiano Rosas #define DO_FP_2SH(INSN, FUNC)                                           \
1405f0984d40SFabiano Rosas     static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a)  \
1406f0984d40SFabiano Rosas     {                                                                   \
1407f0984d40SFabiano Rosas         return do_fp_2sh(s, a, FUNC);                                   \
1408f0984d40SFabiano Rosas     }
1409f0984d40SFabiano Rosas 
DO_FP_2SH(VCVT_SF,gen_helper_gvec_vcvt_sf)1410f0984d40SFabiano Rosas DO_FP_2SH(VCVT_SF, gen_helper_gvec_vcvt_sf)
1411f0984d40SFabiano Rosas DO_FP_2SH(VCVT_UF, gen_helper_gvec_vcvt_uf)
1412f0984d40SFabiano Rosas DO_FP_2SH(VCVT_FS, gen_helper_gvec_vcvt_fs)
1413f0984d40SFabiano Rosas DO_FP_2SH(VCVT_FU, gen_helper_gvec_vcvt_fu)
1414f0984d40SFabiano Rosas 
1415f0984d40SFabiano Rosas DO_FP_2SH(VCVT_SH, gen_helper_gvec_vcvt_sh)
1416f0984d40SFabiano Rosas DO_FP_2SH(VCVT_UH, gen_helper_gvec_vcvt_uh)
1417f0984d40SFabiano Rosas DO_FP_2SH(VCVT_HS, gen_helper_gvec_vcvt_hs)
1418f0984d40SFabiano Rosas DO_FP_2SH(VCVT_HU, gen_helper_gvec_vcvt_hu)
1419f0984d40SFabiano Rosas 
1420f0984d40SFabiano Rosas static bool do_1reg_imm(DisasContext *s, arg_1reg_imm *a,
1421f0984d40SFabiano Rosas                         GVecGen2iFn *fn)
1422f0984d40SFabiano Rosas {
1423f0984d40SFabiano Rosas     uint64_t imm;
1424f0984d40SFabiano Rosas     int reg_ofs, vec_size;
1425f0984d40SFabiano Rosas 
1426f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1427f0984d40SFabiano Rosas         return false;
1428f0984d40SFabiano Rosas     }
1429f0984d40SFabiano Rosas 
1430f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1431f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) {
1432f0984d40SFabiano Rosas         return false;
1433f0984d40SFabiano Rosas     }
1434f0984d40SFabiano Rosas 
1435f0984d40SFabiano Rosas     if (a->vd & a->q) {
1436f0984d40SFabiano Rosas         return false;
1437f0984d40SFabiano Rosas     }
1438f0984d40SFabiano Rosas 
1439f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1440f0984d40SFabiano Rosas         return true;
1441f0984d40SFabiano Rosas     }
1442f0984d40SFabiano Rosas 
1443f0984d40SFabiano Rosas     reg_ofs = neon_full_reg_offset(a->vd);
1444f0984d40SFabiano Rosas     vec_size = a->q ? 16 : 8;
1445f0984d40SFabiano Rosas     imm = asimd_imm_const(a->imm, a->cmode, a->op);
1446f0984d40SFabiano Rosas 
1447f0984d40SFabiano Rosas     fn(MO_64, reg_ofs, reg_ofs, imm, vec_size, vec_size);
1448f0984d40SFabiano Rosas     return true;
1449f0984d40SFabiano Rosas }
1450f0984d40SFabiano Rosas 
gen_VMOV_1r(unsigned vece,uint32_t dofs,uint32_t aofs,int64_t c,uint32_t oprsz,uint32_t maxsz)1451f0984d40SFabiano Rosas static void gen_VMOV_1r(unsigned vece, uint32_t dofs, uint32_t aofs,
1452f0984d40SFabiano Rosas                         int64_t c, uint32_t oprsz, uint32_t maxsz)
1453f0984d40SFabiano Rosas {
1454f0984d40SFabiano Rosas     tcg_gen_gvec_dup_imm(MO_64, dofs, oprsz, maxsz, c);
1455f0984d40SFabiano Rosas }
1456f0984d40SFabiano Rosas 
trans_Vimm_1r(DisasContext * s,arg_1reg_imm * a)1457f0984d40SFabiano Rosas static bool trans_Vimm_1r(DisasContext *s, arg_1reg_imm *a)
1458f0984d40SFabiano Rosas {
1459f0984d40SFabiano Rosas     /* Handle decode of cmode/op here between VORR/VBIC/VMOV */
1460f0984d40SFabiano Rosas     GVecGen2iFn *fn;
1461f0984d40SFabiano Rosas 
1462f0984d40SFabiano Rosas     if ((a->cmode & 1) && a->cmode < 12) {
1463f0984d40SFabiano Rosas         /* for op=1, the imm will be inverted, so BIC becomes AND. */
1464f0984d40SFabiano Rosas         fn = a->op ? tcg_gen_gvec_andi : tcg_gen_gvec_ori;
1465f0984d40SFabiano Rosas     } else {
1466f0984d40SFabiano Rosas         /* There is one unallocated cmode/op combination in this space */
1467f0984d40SFabiano Rosas         if (a->cmode == 15 && a->op == 1) {
1468f0984d40SFabiano Rosas             return false;
1469f0984d40SFabiano Rosas         }
1470f0984d40SFabiano Rosas         fn = gen_VMOV_1r;
1471f0984d40SFabiano Rosas     }
1472f0984d40SFabiano Rosas     return do_1reg_imm(s, a, fn);
1473f0984d40SFabiano Rosas }
1474f0984d40SFabiano Rosas 
do_prewiden_3d(DisasContext * s,arg_3diff * a,NeonGenWidenFn * widenfn,NeonGenTwo64OpFn * opfn,int src1_mop,int src2_mop)1475f0984d40SFabiano Rosas static bool do_prewiden_3d(DisasContext *s, arg_3diff *a,
1476f0984d40SFabiano Rosas                            NeonGenWidenFn *widenfn,
1477f0984d40SFabiano Rosas                            NeonGenTwo64OpFn *opfn,
1478f0984d40SFabiano Rosas                            int src1_mop, int src2_mop)
1479f0984d40SFabiano Rosas {
1480f0984d40SFabiano Rosas     /* 3-regs different lengths, prewidening case (VADDL/VSUBL/VAADW/VSUBW) */
1481f0984d40SFabiano Rosas     TCGv_i64 rn0_64, rn1_64, rm_64;
1482f0984d40SFabiano Rosas 
1483f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1484f0984d40SFabiano Rosas         return false;
1485f0984d40SFabiano Rosas     }
1486f0984d40SFabiano Rosas 
1487f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1488f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1489f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
1490f0984d40SFabiano Rosas         return false;
1491f0984d40SFabiano Rosas     }
1492f0984d40SFabiano Rosas 
1493f0984d40SFabiano Rosas     if (!opfn) {
1494f0984d40SFabiano Rosas         /* size == 3 case, which is an entirely different insn group */
1495f0984d40SFabiano Rosas         return false;
1496f0984d40SFabiano Rosas     }
1497f0984d40SFabiano Rosas 
1498f0984d40SFabiano Rosas     if ((a->vd & 1) || (src1_mop == MO_UQ && (a->vn & 1))) {
1499f0984d40SFabiano Rosas         return false;
1500f0984d40SFabiano Rosas     }
1501f0984d40SFabiano Rosas 
1502f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1503f0984d40SFabiano Rosas         return true;
1504f0984d40SFabiano Rosas     }
1505f0984d40SFabiano Rosas 
1506f0984d40SFabiano Rosas     rn0_64 = tcg_temp_new_i64();
1507f0984d40SFabiano Rosas     rn1_64 = tcg_temp_new_i64();
1508f0984d40SFabiano Rosas     rm_64 = tcg_temp_new_i64();
1509f0984d40SFabiano Rosas 
1510f0984d40SFabiano Rosas     if (src1_mop >= 0) {
1511f0984d40SFabiano Rosas         read_neon_element64(rn0_64, a->vn, 0, src1_mop);
1512f0984d40SFabiano Rosas     } else {
1513f0984d40SFabiano Rosas         TCGv_i32 tmp = tcg_temp_new_i32();
1514f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vn, 0, MO_32);
1515f0984d40SFabiano Rosas         widenfn(rn0_64, tmp);
1516f0984d40SFabiano Rosas     }
1517f0984d40SFabiano Rosas     if (src2_mop >= 0) {
1518f0984d40SFabiano Rosas         read_neon_element64(rm_64, a->vm, 0, src2_mop);
1519f0984d40SFabiano Rosas     } else {
1520f0984d40SFabiano Rosas         TCGv_i32 tmp = tcg_temp_new_i32();
1521f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vm, 0, MO_32);
1522f0984d40SFabiano Rosas         widenfn(rm_64, tmp);
1523f0984d40SFabiano Rosas     }
1524f0984d40SFabiano Rosas 
1525f0984d40SFabiano Rosas     opfn(rn0_64, rn0_64, rm_64);
1526f0984d40SFabiano Rosas 
1527f0984d40SFabiano Rosas     /*
1528f0984d40SFabiano Rosas      * Load second pass inputs before storing the first pass result, to
1529f0984d40SFabiano Rosas      * avoid incorrect results if a narrow input overlaps with the result.
1530f0984d40SFabiano Rosas      */
1531f0984d40SFabiano Rosas     if (src1_mop >= 0) {
1532f0984d40SFabiano Rosas         read_neon_element64(rn1_64, a->vn, 1, src1_mop);
1533f0984d40SFabiano Rosas     } else {
1534f0984d40SFabiano Rosas         TCGv_i32 tmp = tcg_temp_new_i32();
1535f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vn, 1, MO_32);
1536f0984d40SFabiano Rosas         widenfn(rn1_64, tmp);
1537f0984d40SFabiano Rosas     }
1538f0984d40SFabiano Rosas     if (src2_mop >= 0) {
1539f0984d40SFabiano Rosas         read_neon_element64(rm_64, a->vm, 1, src2_mop);
1540f0984d40SFabiano Rosas     } else {
1541f0984d40SFabiano Rosas         TCGv_i32 tmp = tcg_temp_new_i32();
1542f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vm, 1, MO_32);
1543f0984d40SFabiano Rosas         widenfn(rm_64, tmp);
1544f0984d40SFabiano Rosas     }
1545f0984d40SFabiano Rosas 
1546f0984d40SFabiano Rosas     write_neon_element64(rn0_64, a->vd, 0, MO_64);
1547f0984d40SFabiano Rosas 
1548f0984d40SFabiano Rosas     opfn(rn1_64, rn1_64, rm_64);
1549f0984d40SFabiano Rosas     write_neon_element64(rn1_64, a->vd, 1, MO_64);
1550f0984d40SFabiano Rosas 
1551f0984d40SFabiano Rosas     return true;
1552f0984d40SFabiano Rosas }
1553f0984d40SFabiano Rosas 
1554f0984d40SFabiano Rosas #define DO_PREWIDEN(INSN, S, OP, SRC1WIDE, SIGN)                        \
1555f0984d40SFabiano Rosas     static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a)        \
1556f0984d40SFabiano Rosas     {                                                                   \
1557f0984d40SFabiano Rosas         static NeonGenWidenFn * const widenfn[] = {                     \
1558f0984d40SFabiano Rosas             gen_helper_neon_widen_##S##8,                               \
1559f0984d40SFabiano Rosas             gen_helper_neon_widen_##S##16,                              \
1560f0984d40SFabiano Rosas             NULL, NULL,                                                 \
1561f0984d40SFabiano Rosas         };                                                              \
1562f0984d40SFabiano Rosas         static NeonGenTwo64OpFn * const addfn[] = {                     \
1563f0984d40SFabiano Rosas             gen_helper_neon_##OP##l_u16,                                \
1564f0984d40SFabiano Rosas             gen_helper_neon_##OP##l_u32,                                \
1565f0984d40SFabiano Rosas             tcg_gen_##OP##_i64,                                         \
1566f0984d40SFabiano Rosas             NULL,                                                       \
1567f0984d40SFabiano Rosas         };                                                              \
1568f0984d40SFabiano Rosas         int narrow_mop = a->size == MO_32 ? MO_32 | SIGN : -1;          \
1569f0984d40SFabiano Rosas         return do_prewiden_3d(s, a, widenfn[a->size], addfn[a->size],   \
1570f0984d40SFabiano Rosas                               SRC1WIDE ? MO_UQ : narrow_mop,             \
1571f0984d40SFabiano Rosas                               narrow_mop);                              \
1572f0984d40SFabiano Rosas     }
1573f0984d40SFabiano Rosas 
DO_PREWIDEN(VADDL_S,s,add,false,MO_SIGN)1574f0984d40SFabiano Rosas DO_PREWIDEN(VADDL_S, s, add, false, MO_SIGN)
1575f0984d40SFabiano Rosas DO_PREWIDEN(VADDL_U, u, add, false, 0)
1576f0984d40SFabiano Rosas DO_PREWIDEN(VSUBL_S, s, sub, false, MO_SIGN)
1577f0984d40SFabiano Rosas DO_PREWIDEN(VSUBL_U, u, sub, false, 0)
1578f0984d40SFabiano Rosas DO_PREWIDEN(VADDW_S, s, add, true, MO_SIGN)
1579f0984d40SFabiano Rosas DO_PREWIDEN(VADDW_U, u, add, true, 0)
1580f0984d40SFabiano Rosas DO_PREWIDEN(VSUBW_S, s, sub, true, MO_SIGN)
1581f0984d40SFabiano Rosas DO_PREWIDEN(VSUBW_U, u, sub, true, 0)
1582f0984d40SFabiano Rosas 
1583f0984d40SFabiano Rosas static bool do_narrow_3d(DisasContext *s, arg_3diff *a,
1584f0984d40SFabiano Rosas                          NeonGenTwo64OpFn *opfn, NeonGenNarrowFn *narrowfn)
1585f0984d40SFabiano Rosas {
1586f0984d40SFabiano Rosas     /* 3-regs different lengths, narrowing (VADDHN/VSUBHN/VRADDHN/VRSUBHN) */
1587f0984d40SFabiano Rosas     TCGv_i64 rn_64, rm_64;
1588f0984d40SFabiano Rosas     TCGv_i32 rd0, rd1;
1589f0984d40SFabiano Rosas 
1590f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1591f0984d40SFabiano Rosas         return false;
1592f0984d40SFabiano Rosas     }
1593f0984d40SFabiano Rosas 
1594f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1595f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1596f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
1597f0984d40SFabiano Rosas         return false;
1598f0984d40SFabiano Rosas     }
1599f0984d40SFabiano Rosas 
1600f0984d40SFabiano Rosas     if (!opfn || !narrowfn) {
1601f0984d40SFabiano Rosas         /* size == 3 case, which is an entirely different insn group */
1602f0984d40SFabiano Rosas         return false;
1603f0984d40SFabiano Rosas     }
1604f0984d40SFabiano Rosas 
1605f0984d40SFabiano Rosas     if ((a->vn | a->vm) & 1) {
1606f0984d40SFabiano Rosas         return false;
1607f0984d40SFabiano Rosas     }
1608f0984d40SFabiano Rosas 
1609f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1610f0984d40SFabiano Rosas         return true;
1611f0984d40SFabiano Rosas     }
1612f0984d40SFabiano Rosas 
1613f0984d40SFabiano Rosas     rn_64 = tcg_temp_new_i64();
1614f0984d40SFabiano Rosas     rm_64 = tcg_temp_new_i64();
1615f0984d40SFabiano Rosas     rd0 = tcg_temp_new_i32();
1616f0984d40SFabiano Rosas     rd1 = tcg_temp_new_i32();
1617f0984d40SFabiano Rosas 
1618f0984d40SFabiano Rosas     read_neon_element64(rn_64, a->vn, 0, MO_64);
1619f0984d40SFabiano Rosas     read_neon_element64(rm_64, a->vm, 0, MO_64);
1620f0984d40SFabiano Rosas 
1621f0984d40SFabiano Rosas     opfn(rn_64, rn_64, rm_64);
1622f0984d40SFabiano Rosas 
1623f0984d40SFabiano Rosas     narrowfn(rd0, rn_64);
1624f0984d40SFabiano Rosas 
1625f0984d40SFabiano Rosas     read_neon_element64(rn_64, a->vn, 1, MO_64);
1626f0984d40SFabiano Rosas     read_neon_element64(rm_64, a->vm, 1, MO_64);
1627f0984d40SFabiano Rosas 
1628f0984d40SFabiano Rosas     opfn(rn_64, rn_64, rm_64);
1629f0984d40SFabiano Rosas 
1630f0984d40SFabiano Rosas     narrowfn(rd1, rn_64);
1631f0984d40SFabiano Rosas 
1632f0984d40SFabiano Rosas     write_neon_element32(rd0, a->vd, 0, MO_32);
1633f0984d40SFabiano Rosas     write_neon_element32(rd1, a->vd, 1, MO_32);
1634f0984d40SFabiano Rosas 
1635f0984d40SFabiano Rosas     return true;
1636f0984d40SFabiano Rosas }
1637f0984d40SFabiano Rosas 
1638f0984d40SFabiano Rosas #define DO_NARROW_3D(INSN, OP, NARROWTYPE, EXTOP)                       \
1639f0984d40SFabiano Rosas     static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a)        \
1640f0984d40SFabiano Rosas     {                                                                   \
1641f0984d40SFabiano Rosas         static NeonGenTwo64OpFn * const addfn[] = {                     \
1642f0984d40SFabiano Rosas             gen_helper_neon_##OP##l_u16,                                \
1643f0984d40SFabiano Rosas             gen_helper_neon_##OP##l_u32,                                \
1644f0984d40SFabiano Rosas             tcg_gen_##OP##_i64,                                         \
1645f0984d40SFabiano Rosas             NULL,                                                       \
1646f0984d40SFabiano Rosas         };                                                              \
1647f0984d40SFabiano Rosas         static NeonGenNarrowFn * const narrowfn[] = {                   \
1648f0984d40SFabiano Rosas             gen_helper_neon_##NARROWTYPE##_high_u8,                     \
1649f0984d40SFabiano Rosas             gen_helper_neon_##NARROWTYPE##_high_u16,                    \
1650f0984d40SFabiano Rosas             EXTOP,                                                      \
1651f0984d40SFabiano Rosas             NULL,                                                       \
1652f0984d40SFabiano Rosas         };                                                              \
1653f0984d40SFabiano Rosas         return do_narrow_3d(s, a, addfn[a->size], narrowfn[a->size]);   \
1654f0984d40SFabiano Rosas     }
1655f0984d40SFabiano Rosas 
gen_narrow_round_high_u32(TCGv_i32 rd,TCGv_i64 rn)1656f0984d40SFabiano Rosas static void gen_narrow_round_high_u32(TCGv_i32 rd, TCGv_i64 rn)
1657f0984d40SFabiano Rosas {
1658f0984d40SFabiano Rosas     tcg_gen_addi_i64(rn, rn, 1u << 31);
1659f0984d40SFabiano Rosas     tcg_gen_extrh_i64_i32(rd, rn);
1660f0984d40SFabiano Rosas }
1661f0984d40SFabiano Rosas 
DO_NARROW_3D(VADDHN,add,narrow,tcg_gen_extrh_i64_i32)1662f0984d40SFabiano Rosas DO_NARROW_3D(VADDHN, add, narrow, tcg_gen_extrh_i64_i32)
1663f0984d40SFabiano Rosas DO_NARROW_3D(VSUBHN, sub, narrow, tcg_gen_extrh_i64_i32)
1664f0984d40SFabiano Rosas DO_NARROW_3D(VRADDHN, add, narrow_round, gen_narrow_round_high_u32)
1665f0984d40SFabiano Rosas DO_NARROW_3D(VRSUBHN, sub, narrow_round, gen_narrow_round_high_u32)
1666f0984d40SFabiano Rosas 
1667f0984d40SFabiano Rosas static bool do_long_3d(DisasContext *s, arg_3diff *a,
1668f0984d40SFabiano Rosas                        NeonGenTwoOpWidenFn *opfn,
1669f0984d40SFabiano Rosas                        NeonGenTwo64OpFn *accfn)
1670f0984d40SFabiano Rosas {
1671f0984d40SFabiano Rosas     /*
1672f0984d40SFabiano Rosas      * 3-regs different lengths, long operations.
1673f0984d40SFabiano Rosas      * These perform an operation on two inputs that returns a double-width
1674f0984d40SFabiano Rosas      * result, and then possibly perform an accumulation operation of
1675f0984d40SFabiano Rosas      * that result into the double-width destination.
1676f0984d40SFabiano Rosas      */
1677f0984d40SFabiano Rosas     TCGv_i64 rd0, rd1, tmp;
1678f0984d40SFabiano Rosas     TCGv_i32 rn, rm;
1679f0984d40SFabiano Rosas 
1680f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1681f0984d40SFabiano Rosas         return false;
1682f0984d40SFabiano Rosas     }
1683f0984d40SFabiano Rosas 
1684f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1685f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1686f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
1687f0984d40SFabiano Rosas         return false;
1688f0984d40SFabiano Rosas     }
1689f0984d40SFabiano Rosas 
1690f0984d40SFabiano Rosas     if (!opfn) {
1691f0984d40SFabiano Rosas         /* size == 3 case, which is an entirely different insn group */
1692f0984d40SFabiano Rosas         return false;
1693f0984d40SFabiano Rosas     }
1694f0984d40SFabiano Rosas 
1695f0984d40SFabiano Rosas     if (a->vd & 1) {
1696f0984d40SFabiano Rosas         return false;
1697f0984d40SFabiano Rosas     }
1698f0984d40SFabiano Rosas 
1699f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1700f0984d40SFabiano Rosas         return true;
1701f0984d40SFabiano Rosas     }
1702f0984d40SFabiano Rosas 
1703f0984d40SFabiano Rosas     rd0 = tcg_temp_new_i64();
1704f0984d40SFabiano Rosas     rd1 = tcg_temp_new_i64();
1705f0984d40SFabiano Rosas 
1706f0984d40SFabiano Rosas     rn = tcg_temp_new_i32();
1707f0984d40SFabiano Rosas     rm = tcg_temp_new_i32();
1708f0984d40SFabiano Rosas     read_neon_element32(rn, a->vn, 0, MO_32);
1709f0984d40SFabiano Rosas     read_neon_element32(rm, a->vm, 0, MO_32);
1710f0984d40SFabiano Rosas     opfn(rd0, rn, rm);
1711f0984d40SFabiano Rosas 
1712f0984d40SFabiano Rosas     read_neon_element32(rn, a->vn, 1, MO_32);
1713f0984d40SFabiano Rosas     read_neon_element32(rm, a->vm, 1, MO_32);
1714f0984d40SFabiano Rosas     opfn(rd1, rn, rm);
1715f0984d40SFabiano Rosas 
1716f0984d40SFabiano Rosas     /* Don't store results until after all loads: they might overlap */
1717f0984d40SFabiano Rosas     if (accfn) {
1718f0984d40SFabiano Rosas         tmp = tcg_temp_new_i64();
1719f0984d40SFabiano Rosas         read_neon_element64(tmp, a->vd, 0, MO_64);
1720f0984d40SFabiano Rosas         accfn(rd0, tmp, rd0);
1721f0984d40SFabiano Rosas         read_neon_element64(tmp, a->vd, 1, MO_64);
1722f0984d40SFabiano Rosas         accfn(rd1, tmp, rd1);
1723f0984d40SFabiano Rosas     }
1724f0984d40SFabiano Rosas 
1725f0984d40SFabiano Rosas     write_neon_element64(rd0, a->vd, 0, MO_64);
1726f0984d40SFabiano Rosas     write_neon_element64(rd1, a->vd, 1, MO_64);
1727f0984d40SFabiano Rosas 
1728f0984d40SFabiano Rosas     return true;
1729f0984d40SFabiano Rosas }
1730f0984d40SFabiano Rosas 
trans_VABDL_S_3d(DisasContext * s,arg_3diff * a)1731f0984d40SFabiano Rosas static bool trans_VABDL_S_3d(DisasContext *s, arg_3diff *a)
1732f0984d40SFabiano Rosas {
1733f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1734f0984d40SFabiano Rosas         gen_helper_neon_abdl_s16,
1735f0984d40SFabiano Rosas         gen_helper_neon_abdl_s32,
1736f0984d40SFabiano Rosas         gen_helper_neon_abdl_s64,
1737f0984d40SFabiano Rosas         NULL,
1738f0984d40SFabiano Rosas     };
1739f0984d40SFabiano Rosas 
1740f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], NULL);
1741f0984d40SFabiano Rosas }
1742f0984d40SFabiano Rosas 
trans_VABDL_U_3d(DisasContext * s,arg_3diff * a)1743f0984d40SFabiano Rosas static bool trans_VABDL_U_3d(DisasContext *s, arg_3diff *a)
1744f0984d40SFabiano Rosas {
1745f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1746f0984d40SFabiano Rosas         gen_helper_neon_abdl_u16,
1747f0984d40SFabiano Rosas         gen_helper_neon_abdl_u32,
1748f0984d40SFabiano Rosas         gen_helper_neon_abdl_u64,
1749f0984d40SFabiano Rosas         NULL,
1750f0984d40SFabiano Rosas     };
1751f0984d40SFabiano Rosas 
1752f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], NULL);
1753f0984d40SFabiano Rosas }
1754f0984d40SFabiano Rosas 
trans_VABAL_S_3d(DisasContext * s,arg_3diff * a)1755f0984d40SFabiano Rosas static bool trans_VABAL_S_3d(DisasContext *s, arg_3diff *a)
1756f0984d40SFabiano Rosas {
1757f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1758f0984d40SFabiano Rosas         gen_helper_neon_abdl_s16,
1759f0984d40SFabiano Rosas         gen_helper_neon_abdl_s32,
1760f0984d40SFabiano Rosas         gen_helper_neon_abdl_s64,
1761f0984d40SFabiano Rosas         NULL,
1762f0984d40SFabiano Rosas     };
1763f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const addfn[] = {
1764f0984d40SFabiano Rosas         gen_helper_neon_addl_u16,
1765f0984d40SFabiano Rosas         gen_helper_neon_addl_u32,
1766f0984d40SFabiano Rosas         tcg_gen_add_i64,
1767f0984d40SFabiano Rosas         NULL,
1768f0984d40SFabiano Rosas     };
1769f0984d40SFabiano Rosas 
1770f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], addfn[a->size]);
1771f0984d40SFabiano Rosas }
1772f0984d40SFabiano Rosas 
trans_VABAL_U_3d(DisasContext * s,arg_3diff * a)1773f0984d40SFabiano Rosas static bool trans_VABAL_U_3d(DisasContext *s, arg_3diff *a)
1774f0984d40SFabiano Rosas {
1775f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1776f0984d40SFabiano Rosas         gen_helper_neon_abdl_u16,
1777f0984d40SFabiano Rosas         gen_helper_neon_abdl_u32,
1778f0984d40SFabiano Rosas         gen_helper_neon_abdl_u64,
1779f0984d40SFabiano Rosas         NULL,
1780f0984d40SFabiano Rosas     };
1781f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const addfn[] = {
1782f0984d40SFabiano Rosas         gen_helper_neon_addl_u16,
1783f0984d40SFabiano Rosas         gen_helper_neon_addl_u32,
1784f0984d40SFabiano Rosas         tcg_gen_add_i64,
1785f0984d40SFabiano Rosas         NULL,
1786f0984d40SFabiano Rosas     };
1787f0984d40SFabiano Rosas 
1788f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], addfn[a->size]);
1789f0984d40SFabiano Rosas }
1790f0984d40SFabiano Rosas 
gen_mull_s32(TCGv_i64 rd,TCGv_i32 rn,TCGv_i32 rm)1791f0984d40SFabiano Rosas static void gen_mull_s32(TCGv_i64 rd, TCGv_i32 rn, TCGv_i32 rm)
1792f0984d40SFabiano Rosas {
1793f0984d40SFabiano Rosas     TCGv_i32 lo = tcg_temp_new_i32();
1794f0984d40SFabiano Rosas     TCGv_i32 hi = tcg_temp_new_i32();
1795f0984d40SFabiano Rosas 
1796f0984d40SFabiano Rosas     tcg_gen_muls2_i32(lo, hi, rn, rm);
1797f0984d40SFabiano Rosas     tcg_gen_concat_i32_i64(rd, lo, hi);
1798f0984d40SFabiano Rosas }
1799f0984d40SFabiano Rosas 
gen_mull_u32(TCGv_i64 rd,TCGv_i32 rn,TCGv_i32 rm)1800f0984d40SFabiano Rosas static void gen_mull_u32(TCGv_i64 rd, TCGv_i32 rn, TCGv_i32 rm)
1801f0984d40SFabiano Rosas {
1802f0984d40SFabiano Rosas     TCGv_i32 lo = tcg_temp_new_i32();
1803f0984d40SFabiano Rosas     TCGv_i32 hi = tcg_temp_new_i32();
1804f0984d40SFabiano Rosas 
1805f0984d40SFabiano Rosas     tcg_gen_mulu2_i32(lo, hi, rn, rm);
1806f0984d40SFabiano Rosas     tcg_gen_concat_i32_i64(rd, lo, hi);
1807f0984d40SFabiano Rosas }
1808f0984d40SFabiano Rosas 
trans_VMULL_S_3d(DisasContext * s,arg_3diff * a)1809f0984d40SFabiano Rosas static bool trans_VMULL_S_3d(DisasContext *s, arg_3diff *a)
1810f0984d40SFabiano Rosas {
1811f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1812f0984d40SFabiano Rosas         gen_helper_neon_mull_s8,
1813f0984d40SFabiano Rosas         gen_helper_neon_mull_s16,
1814f0984d40SFabiano Rosas         gen_mull_s32,
1815f0984d40SFabiano Rosas         NULL,
1816f0984d40SFabiano Rosas     };
1817f0984d40SFabiano Rosas 
1818f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], NULL);
1819f0984d40SFabiano Rosas }
1820f0984d40SFabiano Rosas 
trans_VMULL_U_3d(DisasContext * s,arg_3diff * a)1821f0984d40SFabiano Rosas static bool trans_VMULL_U_3d(DisasContext *s, arg_3diff *a)
1822f0984d40SFabiano Rosas {
1823f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1824f0984d40SFabiano Rosas         gen_helper_neon_mull_u8,
1825f0984d40SFabiano Rosas         gen_helper_neon_mull_u16,
1826f0984d40SFabiano Rosas         gen_mull_u32,
1827f0984d40SFabiano Rosas         NULL,
1828f0984d40SFabiano Rosas     };
1829f0984d40SFabiano Rosas 
1830f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], NULL);
1831f0984d40SFabiano Rosas }
1832f0984d40SFabiano Rosas 
1833f0984d40SFabiano Rosas #define DO_VMLAL(INSN,MULL,ACC)                                         \
1834f0984d40SFabiano Rosas     static bool trans_##INSN##_3d(DisasContext *s, arg_3diff *a)        \
1835f0984d40SFabiano Rosas     {                                                                   \
1836f0984d40SFabiano Rosas         static NeonGenTwoOpWidenFn * const opfn[] = {                   \
1837f0984d40SFabiano Rosas             gen_helper_neon_##MULL##8,                                  \
1838f0984d40SFabiano Rosas             gen_helper_neon_##MULL##16,                                 \
1839f0984d40SFabiano Rosas             gen_##MULL##32,                                             \
1840f0984d40SFabiano Rosas             NULL,                                                       \
1841f0984d40SFabiano Rosas         };                                                              \
1842f0984d40SFabiano Rosas         static NeonGenTwo64OpFn * const accfn[] = {                     \
1843f0984d40SFabiano Rosas             gen_helper_neon_##ACC##l_u16,                               \
1844f0984d40SFabiano Rosas             gen_helper_neon_##ACC##l_u32,                               \
1845f0984d40SFabiano Rosas             tcg_gen_##ACC##_i64,                                        \
1846f0984d40SFabiano Rosas             NULL,                                                       \
1847f0984d40SFabiano Rosas         };                                                              \
1848f0984d40SFabiano Rosas         return do_long_3d(s, a, opfn[a->size], accfn[a->size]);         \
1849f0984d40SFabiano Rosas     }
1850f0984d40SFabiano Rosas 
DO_VMLAL(VMLAL_S,mull_s,add)1851f0984d40SFabiano Rosas DO_VMLAL(VMLAL_S,mull_s,add)
1852f0984d40SFabiano Rosas DO_VMLAL(VMLAL_U,mull_u,add)
1853f0984d40SFabiano Rosas DO_VMLAL(VMLSL_S,mull_s,sub)
1854f0984d40SFabiano Rosas DO_VMLAL(VMLSL_U,mull_u,sub)
1855f0984d40SFabiano Rosas 
1856f0984d40SFabiano Rosas static void gen_VQDMULL_16(TCGv_i64 rd, TCGv_i32 rn, TCGv_i32 rm)
1857f0984d40SFabiano Rosas {
1858f0984d40SFabiano Rosas     gen_helper_neon_mull_s16(rd, rn, rm);
1859ad75a51eSRichard Henderson     gen_helper_neon_addl_saturate_s32(rd, tcg_env, rd, rd);
1860f0984d40SFabiano Rosas }
1861f0984d40SFabiano Rosas 
gen_VQDMULL_32(TCGv_i64 rd,TCGv_i32 rn,TCGv_i32 rm)1862f0984d40SFabiano Rosas static void gen_VQDMULL_32(TCGv_i64 rd, TCGv_i32 rn, TCGv_i32 rm)
1863f0984d40SFabiano Rosas {
1864f0984d40SFabiano Rosas     gen_mull_s32(rd, rn, rm);
1865ad75a51eSRichard Henderson     gen_helper_neon_addl_saturate_s64(rd, tcg_env, rd, rd);
1866f0984d40SFabiano Rosas }
1867f0984d40SFabiano Rosas 
trans_VQDMULL_3d(DisasContext * s,arg_3diff * a)1868f0984d40SFabiano Rosas static bool trans_VQDMULL_3d(DisasContext *s, arg_3diff *a)
1869f0984d40SFabiano Rosas {
1870f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1871f0984d40SFabiano Rosas         NULL,
1872f0984d40SFabiano Rosas         gen_VQDMULL_16,
1873f0984d40SFabiano Rosas         gen_VQDMULL_32,
1874f0984d40SFabiano Rosas         NULL,
1875f0984d40SFabiano Rosas     };
1876f0984d40SFabiano Rosas 
1877f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], NULL);
1878f0984d40SFabiano Rosas }
1879f0984d40SFabiano Rosas 
gen_VQDMLAL_acc_16(TCGv_i64 rd,TCGv_i64 rn,TCGv_i64 rm)1880f0984d40SFabiano Rosas static void gen_VQDMLAL_acc_16(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm)
1881f0984d40SFabiano Rosas {
1882ad75a51eSRichard Henderson     gen_helper_neon_addl_saturate_s32(rd, tcg_env, rn, rm);
1883f0984d40SFabiano Rosas }
1884f0984d40SFabiano Rosas 
gen_VQDMLAL_acc_32(TCGv_i64 rd,TCGv_i64 rn,TCGv_i64 rm)1885f0984d40SFabiano Rosas static void gen_VQDMLAL_acc_32(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm)
1886f0984d40SFabiano Rosas {
1887ad75a51eSRichard Henderson     gen_helper_neon_addl_saturate_s64(rd, tcg_env, rn, rm);
1888f0984d40SFabiano Rosas }
1889f0984d40SFabiano Rosas 
trans_VQDMLAL_3d(DisasContext * s,arg_3diff * a)1890f0984d40SFabiano Rosas static bool trans_VQDMLAL_3d(DisasContext *s, arg_3diff *a)
1891f0984d40SFabiano Rosas {
1892f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1893f0984d40SFabiano Rosas         NULL,
1894f0984d40SFabiano Rosas         gen_VQDMULL_16,
1895f0984d40SFabiano Rosas         gen_VQDMULL_32,
1896f0984d40SFabiano Rosas         NULL,
1897f0984d40SFabiano Rosas     };
1898f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const accfn[] = {
1899f0984d40SFabiano Rosas         NULL,
1900f0984d40SFabiano Rosas         gen_VQDMLAL_acc_16,
1901f0984d40SFabiano Rosas         gen_VQDMLAL_acc_32,
1902f0984d40SFabiano Rosas         NULL,
1903f0984d40SFabiano Rosas     };
1904f0984d40SFabiano Rosas 
1905f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], accfn[a->size]);
1906f0984d40SFabiano Rosas }
1907f0984d40SFabiano Rosas 
gen_VQDMLSL_acc_16(TCGv_i64 rd,TCGv_i64 rn,TCGv_i64 rm)1908f0984d40SFabiano Rosas static void gen_VQDMLSL_acc_16(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm)
1909f0984d40SFabiano Rosas {
1910f0984d40SFabiano Rosas     gen_helper_neon_negl_u32(rm, rm);
1911ad75a51eSRichard Henderson     gen_helper_neon_addl_saturate_s32(rd, tcg_env, rn, rm);
1912f0984d40SFabiano Rosas }
1913f0984d40SFabiano Rosas 
gen_VQDMLSL_acc_32(TCGv_i64 rd,TCGv_i64 rn,TCGv_i64 rm)1914f0984d40SFabiano Rosas static void gen_VQDMLSL_acc_32(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm)
1915f0984d40SFabiano Rosas {
1916f0984d40SFabiano Rosas     tcg_gen_neg_i64(rm, rm);
1917ad75a51eSRichard Henderson     gen_helper_neon_addl_saturate_s64(rd, tcg_env, rn, rm);
1918f0984d40SFabiano Rosas }
1919f0984d40SFabiano Rosas 
trans_VQDMLSL_3d(DisasContext * s,arg_3diff * a)1920f0984d40SFabiano Rosas static bool trans_VQDMLSL_3d(DisasContext *s, arg_3diff *a)
1921f0984d40SFabiano Rosas {
1922f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
1923f0984d40SFabiano Rosas         NULL,
1924f0984d40SFabiano Rosas         gen_VQDMULL_16,
1925f0984d40SFabiano Rosas         gen_VQDMULL_32,
1926f0984d40SFabiano Rosas         NULL,
1927f0984d40SFabiano Rosas     };
1928f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const accfn[] = {
1929f0984d40SFabiano Rosas         NULL,
1930f0984d40SFabiano Rosas         gen_VQDMLSL_acc_16,
1931f0984d40SFabiano Rosas         gen_VQDMLSL_acc_32,
1932f0984d40SFabiano Rosas         NULL,
1933f0984d40SFabiano Rosas     };
1934f0984d40SFabiano Rosas 
1935f0984d40SFabiano Rosas     return do_long_3d(s, a, opfn[a->size], accfn[a->size]);
1936f0984d40SFabiano Rosas }
1937f0984d40SFabiano Rosas 
trans_VMULL_P_3d(DisasContext * s,arg_3diff * a)1938f0984d40SFabiano Rosas static bool trans_VMULL_P_3d(DisasContext *s, arg_3diff *a)
1939f0984d40SFabiano Rosas {
1940f0984d40SFabiano Rosas     gen_helper_gvec_3 *fn_gvec;
1941f0984d40SFabiano Rosas 
1942f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
1943f0984d40SFabiano Rosas         return false;
1944f0984d40SFabiano Rosas     }
1945f0984d40SFabiano Rosas 
1946f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
1947f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
1948f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
1949f0984d40SFabiano Rosas         return false;
1950f0984d40SFabiano Rosas     }
1951f0984d40SFabiano Rosas 
1952f0984d40SFabiano Rosas     if (a->vd & 1) {
1953f0984d40SFabiano Rosas         return false;
1954f0984d40SFabiano Rosas     }
1955f0984d40SFabiano Rosas 
1956f0984d40SFabiano Rosas     switch (a->size) {
1957f0984d40SFabiano Rosas     case 0:
1958f0984d40SFabiano Rosas         fn_gvec = gen_helper_neon_pmull_h;
1959f0984d40SFabiano Rosas         break;
1960f0984d40SFabiano Rosas     case 2:
1961f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_pmull, s)) {
1962f0984d40SFabiano Rosas             return false;
1963f0984d40SFabiano Rosas         }
1964f0984d40SFabiano Rosas         fn_gvec = gen_helper_gvec_pmull_q;
1965f0984d40SFabiano Rosas         break;
1966f0984d40SFabiano Rosas     default:
1967f0984d40SFabiano Rosas         return false;
1968f0984d40SFabiano Rosas     }
1969f0984d40SFabiano Rosas 
1970f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
1971f0984d40SFabiano Rosas         return true;
1972f0984d40SFabiano Rosas     }
1973f0984d40SFabiano Rosas 
1974f0984d40SFabiano Rosas     tcg_gen_gvec_3_ool(neon_full_reg_offset(a->vd),
1975f0984d40SFabiano Rosas                        neon_full_reg_offset(a->vn),
1976f0984d40SFabiano Rosas                        neon_full_reg_offset(a->vm),
1977f0984d40SFabiano Rosas                        16, 16, 0, fn_gvec);
1978f0984d40SFabiano Rosas     return true;
1979f0984d40SFabiano Rosas }
1980f0984d40SFabiano Rosas 
gen_neon_dup_low16(TCGv_i32 var)1981f0984d40SFabiano Rosas static void gen_neon_dup_low16(TCGv_i32 var)
1982f0984d40SFabiano Rosas {
1983f0984d40SFabiano Rosas     TCGv_i32 tmp = tcg_temp_new_i32();
1984f0984d40SFabiano Rosas     tcg_gen_ext16u_i32(var, var);
1985f0984d40SFabiano Rosas     tcg_gen_shli_i32(tmp, var, 16);
1986f0984d40SFabiano Rosas     tcg_gen_or_i32(var, var, tmp);
1987f0984d40SFabiano Rosas }
1988f0984d40SFabiano Rosas 
gen_neon_dup_high16(TCGv_i32 var)1989f0984d40SFabiano Rosas static void gen_neon_dup_high16(TCGv_i32 var)
1990f0984d40SFabiano Rosas {
1991f0984d40SFabiano Rosas     TCGv_i32 tmp = tcg_temp_new_i32();
1992f0984d40SFabiano Rosas     tcg_gen_andi_i32(var, var, 0xffff0000);
1993f0984d40SFabiano Rosas     tcg_gen_shri_i32(tmp, var, 16);
1994f0984d40SFabiano Rosas     tcg_gen_or_i32(var, var, tmp);
1995f0984d40SFabiano Rosas }
1996f0984d40SFabiano Rosas 
neon_get_scalar(int size,int reg)1997f0984d40SFabiano Rosas static inline TCGv_i32 neon_get_scalar(int size, int reg)
1998f0984d40SFabiano Rosas {
1999f0984d40SFabiano Rosas     TCGv_i32 tmp = tcg_temp_new_i32();
2000f0984d40SFabiano Rosas     if (size == MO_16) {
2001f0984d40SFabiano Rosas         read_neon_element32(tmp, reg & 7, reg >> 4, MO_32);
2002f0984d40SFabiano Rosas         if (reg & 8) {
2003f0984d40SFabiano Rosas             gen_neon_dup_high16(tmp);
2004f0984d40SFabiano Rosas         } else {
2005f0984d40SFabiano Rosas             gen_neon_dup_low16(tmp);
2006f0984d40SFabiano Rosas         }
2007f0984d40SFabiano Rosas     } else {
2008f0984d40SFabiano Rosas         read_neon_element32(tmp, reg & 15, reg >> 4, MO_32);
2009f0984d40SFabiano Rosas     }
2010f0984d40SFabiano Rosas     return tmp;
2011f0984d40SFabiano Rosas }
2012f0984d40SFabiano Rosas 
do_2scalar(DisasContext * s,arg_2scalar * a,NeonGenTwoOpFn * opfn,NeonGenTwoOpFn * accfn)2013f0984d40SFabiano Rosas static bool do_2scalar(DisasContext *s, arg_2scalar *a,
2014f0984d40SFabiano Rosas                        NeonGenTwoOpFn *opfn, NeonGenTwoOpFn *accfn)
2015f0984d40SFabiano Rosas {
2016f0984d40SFabiano Rosas     /*
2017f0984d40SFabiano Rosas      * Two registers and a scalar: perform an operation between
2018f0984d40SFabiano Rosas      * the input elements and the scalar, and then possibly
2019f0984d40SFabiano Rosas      * perform an accumulation operation of that result into the
2020f0984d40SFabiano Rosas      * destination.
2021f0984d40SFabiano Rosas      */
2022f0984d40SFabiano Rosas     TCGv_i32 scalar, tmp;
2023f0984d40SFabiano Rosas     int pass;
2024f0984d40SFabiano Rosas 
2025f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2026f0984d40SFabiano Rosas         return false;
2027f0984d40SFabiano Rosas     }
2028f0984d40SFabiano Rosas 
2029f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2030f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2031f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
2032f0984d40SFabiano Rosas         return false;
2033f0984d40SFabiano Rosas     }
2034f0984d40SFabiano Rosas 
2035f0984d40SFabiano Rosas     if (!opfn) {
2036f0984d40SFabiano Rosas         /* Bad size (including size == 3, which is a different insn group) */
2037f0984d40SFabiano Rosas         return false;
2038f0984d40SFabiano Rosas     }
2039f0984d40SFabiano Rosas 
2040f0984d40SFabiano Rosas     if (a->q && ((a->vd | a->vn) & 1)) {
2041f0984d40SFabiano Rosas         return false;
2042f0984d40SFabiano Rosas     }
2043f0984d40SFabiano Rosas 
2044f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2045f0984d40SFabiano Rosas         return true;
2046f0984d40SFabiano Rosas     }
2047f0984d40SFabiano Rosas 
2048f0984d40SFabiano Rosas     scalar = neon_get_scalar(a->size, a->vm);
2049f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
2050f0984d40SFabiano Rosas 
2051f0984d40SFabiano Rosas     for (pass = 0; pass < (a->q ? 4 : 2); pass++) {
2052f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vn, pass, MO_32);
2053f0984d40SFabiano Rosas         opfn(tmp, tmp, scalar);
2054f0984d40SFabiano Rosas         if (accfn) {
2055f0984d40SFabiano Rosas             TCGv_i32 rd = tcg_temp_new_i32();
2056f0984d40SFabiano Rosas             read_neon_element32(rd, a->vd, pass, MO_32);
2057f0984d40SFabiano Rosas             accfn(tmp, rd, tmp);
2058f0984d40SFabiano Rosas         }
2059f0984d40SFabiano Rosas         write_neon_element32(tmp, a->vd, pass, MO_32);
2060f0984d40SFabiano Rosas     }
2061f0984d40SFabiano Rosas     return true;
2062f0984d40SFabiano Rosas }
2063f0984d40SFabiano Rosas 
trans_VMUL_2sc(DisasContext * s,arg_2scalar * a)2064f0984d40SFabiano Rosas static bool trans_VMUL_2sc(DisasContext *s, arg_2scalar *a)
2065f0984d40SFabiano Rosas {
2066f0984d40SFabiano Rosas     static NeonGenTwoOpFn * const opfn[] = {
2067f0984d40SFabiano Rosas         NULL,
2068f0984d40SFabiano Rosas         gen_helper_neon_mul_u16,
2069f0984d40SFabiano Rosas         tcg_gen_mul_i32,
2070f0984d40SFabiano Rosas         NULL,
2071f0984d40SFabiano Rosas     };
2072f0984d40SFabiano Rosas 
2073f0984d40SFabiano Rosas     return do_2scalar(s, a, opfn[a->size], NULL);
2074f0984d40SFabiano Rosas }
2075f0984d40SFabiano Rosas 
trans_VMLA_2sc(DisasContext * s,arg_2scalar * a)2076f0984d40SFabiano Rosas static bool trans_VMLA_2sc(DisasContext *s, arg_2scalar *a)
2077f0984d40SFabiano Rosas {
2078f0984d40SFabiano Rosas     static NeonGenTwoOpFn * const opfn[] = {
2079f0984d40SFabiano Rosas         NULL,
2080f0984d40SFabiano Rosas         gen_helper_neon_mul_u16,
2081f0984d40SFabiano Rosas         tcg_gen_mul_i32,
2082f0984d40SFabiano Rosas         NULL,
2083f0984d40SFabiano Rosas     };
2084f0984d40SFabiano Rosas     static NeonGenTwoOpFn * const accfn[] = {
2085f0984d40SFabiano Rosas         NULL,
2086f0984d40SFabiano Rosas         gen_helper_neon_add_u16,
2087f0984d40SFabiano Rosas         tcg_gen_add_i32,
2088f0984d40SFabiano Rosas         NULL,
2089f0984d40SFabiano Rosas     };
2090f0984d40SFabiano Rosas 
2091f0984d40SFabiano Rosas     return do_2scalar(s, a, opfn[a->size], accfn[a->size]);
2092f0984d40SFabiano Rosas }
2093f0984d40SFabiano Rosas 
trans_VMLS_2sc(DisasContext * s,arg_2scalar * a)2094f0984d40SFabiano Rosas static bool trans_VMLS_2sc(DisasContext *s, arg_2scalar *a)
2095f0984d40SFabiano Rosas {
2096f0984d40SFabiano Rosas     static NeonGenTwoOpFn * const opfn[] = {
2097f0984d40SFabiano Rosas         NULL,
2098f0984d40SFabiano Rosas         gen_helper_neon_mul_u16,
2099f0984d40SFabiano Rosas         tcg_gen_mul_i32,
2100f0984d40SFabiano Rosas         NULL,
2101f0984d40SFabiano Rosas     };
2102f0984d40SFabiano Rosas     static NeonGenTwoOpFn * const accfn[] = {
2103f0984d40SFabiano Rosas         NULL,
2104f0984d40SFabiano Rosas         gen_helper_neon_sub_u16,
2105f0984d40SFabiano Rosas         tcg_gen_sub_i32,
2106f0984d40SFabiano Rosas         NULL,
2107f0984d40SFabiano Rosas     };
2108f0984d40SFabiano Rosas 
2109f0984d40SFabiano Rosas     return do_2scalar(s, a, opfn[a->size], accfn[a->size]);
2110f0984d40SFabiano Rosas }
2111f0984d40SFabiano Rosas 
do_2scalar_fp_vec(DisasContext * s,arg_2scalar * a,gen_helper_gvec_3_ptr * fn)2112f0984d40SFabiano Rosas static bool do_2scalar_fp_vec(DisasContext *s, arg_2scalar *a,
2113f0984d40SFabiano Rosas                               gen_helper_gvec_3_ptr *fn)
2114f0984d40SFabiano Rosas {
2115f0984d40SFabiano Rosas     /* Two registers and a scalar, using gvec */
2116f0984d40SFabiano Rosas     int vec_size = a->q ? 16 : 8;
2117f0984d40SFabiano Rosas     int rd_ofs = neon_full_reg_offset(a->vd);
2118f0984d40SFabiano Rosas     int rn_ofs = neon_full_reg_offset(a->vn);
2119f0984d40SFabiano Rosas     int rm_ofs;
2120f0984d40SFabiano Rosas     int idx;
2121f0984d40SFabiano Rosas     TCGv_ptr fpstatus;
2122f0984d40SFabiano Rosas 
2123f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2124f0984d40SFabiano Rosas         return false;
2125f0984d40SFabiano Rosas     }
2126f0984d40SFabiano Rosas 
2127f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2128f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2129f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
2130f0984d40SFabiano Rosas         return false;
2131f0984d40SFabiano Rosas     }
2132f0984d40SFabiano Rosas 
2133f0984d40SFabiano Rosas     if (!fn) {
2134f0984d40SFabiano Rosas         /* Bad size (including size == 3, which is a different insn group) */
2135f0984d40SFabiano Rosas         return false;
2136f0984d40SFabiano Rosas     }
2137f0984d40SFabiano Rosas 
2138f0984d40SFabiano Rosas     if (a->q && ((a->vd | a->vn) & 1)) {
2139f0984d40SFabiano Rosas         return false;
2140f0984d40SFabiano Rosas     }
2141f0984d40SFabiano Rosas 
2142f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2143f0984d40SFabiano Rosas         return true;
2144f0984d40SFabiano Rosas     }
2145f0984d40SFabiano Rosas 
2146f0984d40SFabiano Rosas     /* a->vm is M:Vm, which encodes both register and index */
2147f0984d40SFabiano Rosas     idx = extract32(a->vm, a->size + 2, 2);
2148f0984d40SFabiano Rosas     a->vm = extract32(a->vm, 0, a->size + 2);
2149f0984d40SFabiano Rosas     rm_ofs = neon_full_reg_offset(a->vm);
2150f0984d40SFabiano Rosas 
2151f0984d40SFabiano Rosas     fpstatus = fpstatus_ptr(a->size == 1 ? FPST_STD_F16 : FPST_STD);
2152f0984d40SFabiano Rosas     tcg_gen_gvec_3_ptr(rd_ofs, rn_ofs, rm_ofs, fpstatus,
2153f0984d40SFabiano Rosas                        vec_size, vec_size, idx, fn);
2154f0984d40SFabiano Rosas     return true;
2155f0984d40SFabiano Rosas }
2156f0984d40SFabiano Rosas 
2157f0984d40SFabiano Rosas #define DO_VMUL_F_2sc(NAME, FUNC)                                       \
2158f0984d40SFabiano Rosas     static bool trans_##NAME##_F_2sc(DisasContext *s, arg_2scalar *a)   \
2159f0984d40SFabiano Rosas     {                                                                   \
2160f0984d40SFabiano Rosas         static gen_helper_gvec_3_ptr * const opfn[] = {                 \
2161f0984d40SFabiano Rosas             NULL,                                                       \
2162f0984d40SFabiano Rosas             gen_helper_##FUNC##_h,                                      \
2163f0984d40SFabiano Rosas             gen_helper_##FUNC##_s,                                      \
2164f0984d40SFabiano Rosas             NULL,                                                       \
2165f0984d40SFabiano Rosas         };                                                              \
2166f0984d40SFabiano Rosas         if (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s)) { \
2167f0984d40SFabiano Rosas             return false;                                               \
2168f0984d40SFabiano Rosas         }                                                               \
2169f0984d40SFabiano Rosas         return do_2scalar_fp_vec(s, a, opfn[a->size]);                  \
2170f0984d40SFabiano Rosas     }
2171f0984d40SFabiano Rosas 
DO_VMUL_F_2sc(VMUL,gvec_fmul_idx)2172f0984d40SFabiano Rosas DO_VMUL_F_2sc(VMUL, gvec_fmul_idx)
2173f0984d40SFabiano Rosas DO_VMUL_F_2sc(VMLA, gvec_fmla_nf_idx)
2174f0984d40SFabiano Rosas DO_VMUL_F_2sc(VMLS, gvec_fmls_nf_idx)
2175f0984d40SFabiano Rosas 
2176f0984d40SFabiano Rosas WRAP_ENV_FN(gen_VQDMULH_16, gen_helper_neon_qdmulh_s16)
2177f0984d40SFabiano Rosas WRAP_ENV_FN(gen_VQDMULH_32, gen_helper_neon_qdmulh_s32)
2178f0984d40SFabiano Rosas WRAP_ENV_FN(gen_VQRDMULH_16, gen_helper_neon_qrdmulh_s16)
2179f0984d40SFabiano Rosas WRAP_ENV_FN(gen_VQRDMULH_32, gen_helper_neon_qrdmulh_s32)
2180f0984d40SFabiano Rosas 
2181f0984d40SFabiano Rosas static bool trans_VQDMULH_2sc(DisasContext *s, arg_2scalar *a)
2182f0984d40SFabiano Rosas {
2183f0984d40SFabiano Rosas     static NeonGenTwoOpFn * const opfn[] = {
2184f0984d40SFabiano Rosas         NULL,
2185f0984d40SFabiano Rosas         gen_VQDMULH_16,
2186f0984d40SFabiano Rosas         gen_VQDMULH_32,
2187f0984d40SFabiano Rosas         NULL,
2188f0984d40SFabiano Rosas     };
2189f0984d40SFabiano Rosas 
2190f0984d40SFabiano Rosas     return do_2scalar(s, a, opfn[a->size], NULL);
2191f0984d40SFabiano Rosas }
2192f0984d40SFabiano Rosas 
trans_VQRDMULH_2sc(DisasContext * s,arg_2scalar * a)2193f0984d40SFabiano Rosas static bool trans_VQRDMULH_2sc(DisasContext *s, arg_2scalar *a)
2194f0984d40SFabiano Rosas {
2195f0984d40SFabiano Rosas     static NeonGenTwoOpFn * const opfn[] = {
2196f0984d40SFabiano Rosas         NULL,
2197f0984d40SFabiano Rosas         gen_VQRDMULH_16,
2198f0984d40SFabiano Rosas         gen_VQRDMULH_32,
2199f0984d40SFabiano Rosas         NULL,
2200f0984d40SFabiano Rosas     };
2201f0984d40SFabiano Rosas 
2202f0984d40SFabiano Rosas     return do_2scalar(s, a, opfn[a->size], NULL);
2203f0984d40SFabiano Rosas }
2204f0984d40SFabiano Rosas 
do_vqrdmlah_2sc(DisasContext * s,arg_2scalar * a,NeonGenThreeOpEnvFn * opfn)2205f0984d40SFabiano Rosas static bool do_vqrdmlah_2sc(DisasContext *s, arg_2scalar *a,
2206f0984d40SFabiano Rosas                             NeonGenThreeOpEnvFn *opfn)
2207f0984d40SFabiano Rosas {
2208f0984d40SFabiano Rosas     /*
2209f0984d40SFabiano Rosas      * VQRDMLAH/VQRDMLSH: this is like do_2scalar, but the opfn
2210f0984d40SFabiano Rosas      * performs a kind of fused op-then-accumulate using a helper
2211f0984d40SFabiano Rosas      * function that takes all of rd, rn and the scalar at once.
2212f0984d40SFabiano Rosas      */
2213f0984d40SFabiano Rosas     TCGv_i32 scalar, rn, rd;
2214f0984d40SFabiano Rosas     int pass;
2215f0984d40SFabiano Rosas 
2216f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2217f0984d40SFabiano Rosas         return false;
2218f0984d40SFabiano Rosas     }
2219f0984d40SFabiano Rosas 
2220f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_rdm, s)) {
2221f0984d40SFabiano Rosas         return false;
2222f0984d40SFabiano Rosas     }
2223f0984d40SFabiano Rosas 
2224f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2225f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2226f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
2227f0984d40SFabiano Rosas         return false;
2228f0984d40SFabiano Rosas     }
2229f0984d40SFabiano Rosas 
2230f0984d40SFabiano Rosas     if (!opfn) {
2231f0984d40SFabiano Rosas         /* Bad size (including size == 3, which is a different insn group) */
2232f0984d40SFabiano Rosas         return false;
2233f0984d40SFabiano Rosas     }
2234f0984d40SFabiano Rosas 
2235f0984d40SFabiano Rosas     if (a->q && ((a->vd | a->vn) & 1)) {
2236f0984d40SFabiano Rosas         return false;
2237f0984d40SFabiano Rosas     }
2238f0984d40SFabiano Rosas 
2239f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2240f0984d40SFabiano Rosas         return true;
2241f0984d40SFabiano Rosas     }
2242f0984d40SFabiano Rosas 
2243f0984d40SFabiano Rosas     scalar = neon_get_scalar(a->size, a->vm);
2244f0984d40SFabiano Rosas     rn = tcg_temp_new_i32();
2245f0984d40SFabiano Rosas     rd = tcg_temp_new_i32();
2246f0984d40SFabiano Rosas 
2247f0984d40SFabiano Rosas     for (pass = 0; pass < (a->q ? 4 : 2); pass++) {
2248f0984d40SFabiano Rosas         read_neon_element32(rn, a->vn, pass, MO_32);
2249f0984d40SFabiano Rosas         read_neon_element32(rd, a->vd, pass, MO_32);
2250ad75a51eSRichard Henderson         opfn(rd, tcg_env, rn, scalar, rd);
2251f0984d40SFabiano Rosas         write_neon_element32(rd, a->vd, pass, MO_32);
2252f0984d40SFabiano Rosas     }
2253f0984d40SFabiano Rosas     return true;
2254f0984d40SFabiano Rosas }
2255f0984d40SFabiano Rosas 
trans_VQRDMLAH_2sc(DisasContext * s,arg_2scalar * a)2256f0984d40SFabiano Rosas static bool trans_VQRDMLAH_2sc(DisasContext *s, arg_2scalar *a)
2257f0984d40SFabiano Rosas {
2258f0984d40SFabiano Rosas     static NeonGenThreeOpEnvFn *opfn[] = {
2259f0984d40SFabiano Rosas         NULL,
2260f0984d40SFabiano Rosas         gen_helper_neon_qrdmlah_s16,
2261f0984d40SFabiano Rosas         gen_helper_neon_qrdmlah_s32,
2262f0984d40SFabiano Rosas         NULL,
2263f0984d40SFabiano Rosas     };
2264f0984d40SFabiano Rosas     return do_vqrdmlah_2sc(s, a, opfn[a->size]);
2265f0984d40SFabiano Rosas }
2266f0984d40SFabiano Rosas 
trans_VQRDMLSH_2sc(DisasContext * s,arg_2scalar * a)2267f0984d40SFabiano Rosas static bool trans_VQRDMLSH_2sc(DisasContext *s, arg_2scalar *a)
2268f0984d40SFabiano Rosas {
2269f0984d40SFabiano Rosas     static NeonGenThreeOpEnvFn *opfn[] = {
2270f0984d40SFabiano Rosas         NULL,
2271f0984d40SFabiano Rosas         gen_helper_neon_qrdmlsh_s16,
2272f0984d40SFabiano Rosas         gen_helper_neon_qrdmlsh_s32,
2273f0984d40SFabiano Rosas         NULL,
2274f0984d40SFabiano Rosas     };
2275f0984d40SFabiano Rosas     return do_vqrdmlah_2sc(s, a, opfn[a->size]);
2276f0984d40SFabiano Rosas }
2277f0984d40SFabiano Rosas 
do_2scalar_long(DisasContext * s,arg_2scalar * a,NeonGenTwoOpWidenFn * opfn,NeonGenTwo64OpFn * accfn)2278f0984d40SFabiano Rosas static bool do_2scalar_long(DisasContext *s, arg_2scalar *a,
2279f0984d40SFabiano Rosas                             NeonGenTwoOpWidenFn *opfn,
2280f0984d40SFabiano Rosas                             NeonGenTwo64OpFn *accfn)
2281f0984d40SFabiano Rosas {
2282f0984d40SFabiano Rosas     /*
2283f0984d40SFabiano Rosas      * Two registers and a scalar, long operations: perform an
2284f0984d40SFabiano Rosas      * operation on the input elements and the scalar which produces
2285f0984d40SFabiano Rosas      * a double-width result, and then possibly perform an accumulation
2286f0984d40SFabiano Rosas      * operation of that result into the destination.
2287f0984d40SFabiano Rosas      */
2288f0984d40SFabiano Rosas     TCGv_i32 scalar, rn;
2289f0984d40SFabiano Rosas     TCGv_i64 rn0_64, rn1_64;
2290f0984d40SFabiano Rosas 
2291f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2292f0984d40SFabiano Rosas         return false;
2293f0984d40SFabiano Rosas     }
2294f0984d40SFabiano Rosas 
2295f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2296f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2297f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
2298f0984d40SFabiano Rosas         return false;
2299f0984d40SFabiano Rosas     }
2300f0984d40SFabiano Rosas 
2301f0984d40SFabiano Rosas     if (!opfn) {
2302f0984d40SFabiano Rosas         /* Bad size (including size == 3, which is a different insn group) */
2303f0984d40SFabiano Rosas         return false;
2304f0984d40SFabiano Rosas     }
2305f0984d40SFabiano Rosas 
2306f0984d40SFabiano Rosas     if (a->vd & 1) {
2307f0984d40SFabiano Rosas         return false;
2308f0984d40SFabiano Rosas     }
2309f0984d40SFabiano Rosas 
2310f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2311f0984d40SFabiano Rosas         return true;
2312f0984d40SFabiano Rosas     }
2313f0984d40SFabiano Rosas 
2314f0984d40SFabiano Rosas     scalar = neon_get_scalar(a->size, a->vm);
2315f0984d40SFabiano Rosas 
2316f0984d40SFabiano Rosas     /* Load all inputs before writing any outputs, in case of overlap */
2317f0984d40SFabiano Rosas     rn = tcg_temp_new_i32();
2318f0984d40SFabiano Rosas     read_neon_element32(rn, a->vn, 0, MO_32);
2319f0984d40SFabiano Rosas     rn0_64 = tcg_temp_new_i64();
2320f0984d40SFabiano Rosas     opfn(rn0_64, rn, scalar);
2321f0984d40SFabiano Rosas 
2322f0984d40SFabiano Rosas     read_neon_element32(rn, a->vn, 1, MO_32);
2323f0984d40SFabiano Rosas     rn1_64 = tcg_temp_new_i64();
2324f0984d40SFabiano Rosas     opfn(rn1_64, rn, scalar);
2325f0984d40SFabiano Rosas 
2326f0984d40SFabiano Rosas     if (accfn) {
2327f0984d40SFabiano Rosas         TCGv_i64 t64 = tcg_temp_new_i64();
2328f0984d40SFabiano Rosas         read_neon_element64(t64, a->vd, 0, MO_64);
2329f0984d40SFabiano Rosas         accfn(rn0_64, t64, rn0_64);
2330f0984d40SFabiano Rosas         read_neon_element64(t64, a->vd, 1, MO_64);
2331f0984d40SFabiano Rosas         accfn(rn1_64, t64, rn1_64);
2332f0984d40SFabiano Rosas     }
2333f0984d40SFabiano Rosas 
2334f0984d40SFabiano Rosas     write_neon_element64(rn0_64, a->vd, 0, MO_64);
2335f0984d40SFabiano Rosas     write_neon_element64(rn1_64, a->vd, 1, MO_64);
2336f0984d40SFabiano Rosas     return true;
2337f0984d40SFabiano Rosas }
2338f0984d40SFabiano Rosas 
trans_VMULL_S_2sc(DisasContext * s,arg_2scalar * a)2339f0984d40SFabiano Rosas static bool trans_VMULL_S_2sc(DisasContext *s, arg_2scalar *a)
2340f0984d40SFabiano Rosas {
2341f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
2342f0984d40SFabiano Rosas         NULL,
2343f0984d40SFabiano Rosas         gen_helper_neon_mull_s16,
2344f0984d40SFabiano Rosas         gen_mull_s32,
2345f0984d40SFabiano Rosas         NULL,
2346f0984d40SFabiano Rosas     };
2347f0984d40SFabiano Rosas 
2348f0984d40SFabiano Rosas     return do_2scalar_long(s, a, opfn[a->size], NULL);
2349f0984d40SFabiano Rosas }
2350f0984d40SFabiano Rosas 
trans_VMULL_U_2sc(DisasContext * s,arg_2scalar * a)2351f0984d40SFabiano Rosas static bool trans_VMULL_U_2sc(DisasContext *s, arg_2scalar *a)
2352f0984d40SFabiano Rosas {
2353f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
2354f0984d40SFabiano Rosas         NULL,
2355f0984d40SFabiano Rosas         gen_helper_neon_mull_u16,
2356f0984d40SFabiano Rosas         gen_mull_u32,
2357f0984d40SFabiano Rosas         NULL,
2358f0984d40SFabiano Rosas     };
2359f0984d40SFabiano Rosas 
2360f0984d40SFabiano Rosas     return do_2scalar_long(s, a, opfn[a->size], NULL);
2361f0984d40SFabiano Rosas }
2362f0984d40SFabiano Rosas 
2363f0984d40SFabiano Rosas #define DO_VMLAL_2SC(INSN, MULL, ACC)                                   \
2364f0984d40SFabiano Rosas     static bool trans_##INSN##_2sc(DisasContext *s, arg_2scalar *a)     \
2365f0984d40SFabiano Rosas     {                                                                   \
2366f0984d40SFabiano Rosas         static NeonGenTwoOpWidenFn * const opfn[] = {                   \
2367f0984d40SFabiano Rosas             NULL,                                                       \
2368f0984d40SFabiano Rosas             gen_helper_neon_##MULL##16,                                 \
2369f0984d40SFabiano Rosas             gen_##MULL##32,                                             \
2370f0984d40SFabiano Rosas             NULL,                                                       \
2371f0984d40SFabiano Rosas         };                                                              \
2372f0984d40SFabiano Rosas         static NeonGenTwo64OpFn * const accfn[] = {                     \
2373f0984d40SFabiano Rosas             NULL,                                                       \
2374f0984d40SFabiano Rosas             gen_helper_neon_##ACC##l_u32,                               \
2375f0984d40SFabiano Rosas             tcg_gen_##ACC##_i64,                                        \
2376f0984d40SFabiano Rosas             NULL,                                                       \
2377f0984d40SFabiano Rosas         };                                                              \
2378f0984d40SFabiano Rosas         return do_2scalar_long(s, a, opfn[a->size], accfn[a->size]);    \
2379f0984d40SFabiano Rosas     }
2380f0984d40SFabiano Rosas 
DO_VMLAL_2SC(VMLAL_S,mull_s,add)2381f0984d40SFabiano Rosas DO_VMLAL_2SC(VMLAL_S, mull_s, add)
2382f0984d40SFabiano Rosas DO_VMLAL_2SC(VMLAL_U, mull_u, add)
2383f0984d40SFabiano Rosas DO_VMLAL_2SC(VMLSL_S, mull_s, sub)
2384f0984d40SFabiano Rosas DO_VMLAL_2SC(VMLSL_U, mull_u, sub)
2385f0984d40SFabiano Rosas 
2386f0984d40SFabiano Rosas static bool trans_VQDMULL_2sc(DisasContext *s, arg_2scalar *a)
2387f0984d40SFabiano Rosas {
2388f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
2389f0984d40SFabiano Rosas         NULL,
2390f0984d40SFabiano Rosas         gen_VQDMULL_16,
2391f0984d40SFabiano Rosas         gen_VQDMULL_32,
2392f0984d40SFabiano Rosas         NULL,
2393f0984d40SFabiano Rosas     };
2394f0984d40SFabiano Rosas 
2395f0984d40SFabiano Rosas     return do_2scalar_long(s, a, opfn[a->size], NULL);
2396f0984d40SFabiano Rosas }
2397f0984d40SFabiano Rosas 
trans_VQDMLAL_2sc(DisasContext * s,arg_2scalar * a)2398f0984d40SFabiano Rosas static bool trans_VQDMLAL_2sc(DisasContext *s, arg_2scalar *a)
2399f0984d40SFabiano Rosas {
2400f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
2401f0984d40SFabiano Rosas         NULL,
2402f0984d40SFabiano Rosas         gen_VQDMULL_16,
2403f0984d40SFabiano Rosas         gen_VQDMULL_32,
2404f0984d40SFabiano Rosas         NULL,
2405f0984d40SFabiano Rosas     };
2406f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const accfn[] = {
2407f0984d40SFabiano Rosas         NULL,
2408f0984d40SFabiano Rosas         gen_VQDMLAL_acc_16,
2409f0984d40SFabiano Rosas         gen_VQDMLAL_acc_32,
2410f0984d40SFabiano Rosas         NULL,
2411f0984d40SFabiano Rosas     };
2412f0984d40SFabiano Rosas 
2413f0984d40SFabiano Rosas     return do_2scalar_long(s, a, opfn[a->size], accfn[a->size]);
2414f0984d40SFabiano Rosas }
2415f0984d40SFabiano Rosas 
trans_VQDMLSL_2sc(DisasContext * s,arg_2scalar * a)2416f0984d40SFabiano Rosas static bool trans_VQDMLSL_2sc(DisasContext *s, arg_2scalar *a)
2417f0984d40SFabiano Rosas {
2418f0984d40SFabiano Rosas     static NeonGenTwoOpWidenFn * const opfn[] = {
2419f0984d40SFabiano Rosas         NULL,
2420f0984d40SFabiano Rosas         gen_VQDMULL_16,
2421f0984d40SFabiano Rosas         gen_VQDMULL_32,
2422f0984d40SFabiano Rosas         NULL,
2423f0984d40SFabiano Rosas     };
2424f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const accfn[] = {
2425f0984d40SFabiano Rosas         NULL,
2426f0984d40SFabiano Rosas         gen_VQDMLSL_acc_16,
2427f0984d40SFabiano Rosas         gen_VQDMLSL_acc_32,
2428f0984d40SFabiano Rosas         NULL,
2429f0984d40SFabiano Rosas     };
2430f0984d40SFabiano Rosas 
2431f0984d40SFabiano Rosas     return do_2scalar_long(s, a, opfn[a->size], accfn[a->size]);
2432f0984d40SFabiano Rosas }
2433f0984d40SFabiano Rosas 
trans_VEXT(DisasContext * s,arg_VEXT * a)2434f0984d40SFabiano Rosas static bool trans_VEXT(DisasContext *s, arg_VEXT *a)
2435f0984d40SFabiano Rosas {
2436f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2437f0984d40SFabiano Rosas         return false;
2438f0984d40SFabiano Rosas     }
2439f0984d40SFabiano Rosas 
2440f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2441f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2442f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
2443f0984d40SFabiano Rosas         return false;
2444f0984d40SFabiano Rosas     }
2445f0984d40SFabiano Rosas 
2446f0984d40SFabiano Rosas     if ((a->vn | a->vm | a->vd) & a->q) {
2447f0984d40SFabiano Rosas         return false;
2448f0984d40SFabiano Rosas     }
2449f0984d40SFabiano Rosas 
2450f0984d40SFabiano Rosas     if (a->imm > 7 && !a->q) {
2451f0984d40SFabiano Rosas         return false;
2452f0984d40SFabiano Rosas     }
2453f0984d40SFabiano Rosas 
2454f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2455f0984d40SFabiano Rosas         return true;
2456f0984d40SFabiano Rosas     }
2457f0984d40SFabiano Rosas 
2458f0984d40SFabiano Rosas     if (!a->q) {
2459f0984d40SFabiano Rosas         /* Extract 64 bits from <Vm:Vn> */
2460f0984d40SFabiano Rosas         TCGv_i64 left, right, dest;
2461f0984d40SFabiano Rosas 
2462f0984d40SFabiano Rosas         left = tcg_temp_new_i64();
2463f0984d40SFabiano Rosas         right = tcg_temp_new_i64();
2464f0984d40SFabiano Rosas         dest = tcg_temp_new_i64();
2465f0984d40SFabiano Rosas 
2466f0984d40SFabiano Rosas         read_neon_element64(right, a->vn, 0, MO_64);
2467f0984d40SFabiano Rosas         read_neon_element64(left, a->vm, 0, MO_64);
2468f0984d40SFabiano Rosas         tcg_gen_extract2_i64(dest, right, left, a->imm * 8);
2469f0984d40SFabiano Rosas         write_neon_element64(dest, a->vd, 0, MO_64);
2470f0984d40SFabiano Rosas     } else {
2471f0984d40SFabiano Rosas         /* Extract 128 bits from <Vm+1:Vm:Vn+1:Vn> */
2472f0984d40SFabiano Rosas         TCGv_i64 left, middle, right, destleft, destright;
2473f0984d40SFabiano Rosas 
2474f0984d40SFabiano Rosas         left = tcg_temp_new_i64();
2475f0984d40SFabiano Rosas         middle = tcg_temp_new_i64();
2476f0984d40SFabiano Rosas         right = tcg_temp_new_i64();
2477f0984d40SFabiano Rosas         destleft = tcg_temp_new_i64();
2478f0984d40SFabiano Rosas         destright = tcg_temp_new_i64();
2479f0984d40SFabiano Rosas 
2480f0984d40SFabiano Rosas         if (a->imm < 8) {
2481f0984d40SFabiano Rosas             read_neon_element64(right, a->vn, 0, MO_64);
2482f0984d40SFabiano Rosas             read_neon_element64(middle, a->vn, 1, MO_64);
2483f0984d40SFabiano Rosas             tcg_gen_extract2_i64(destright, right, middle, a->imm * 8);
2484f0984d40SFabiano Rosas             read_neon_element64(left, a->vm, 0, MO_64);
2485f0984d40SFabiano Rosas             tcg_gen_extract2_i64(destleft, middle, left, a->imm * 8);
2486f0984d40SFabiano Rosas         } else {
2487f0984d40SFabiano Rosas             read_neon_element64(right, a->vn, 1, MO_64);
2488f0984d40SFabiano Rosas             read_neon_element64(middle, a->vm, 0, MO_64);
2489f0984d40SFabiano Rosas             tcg_gen_extract2_i64(destright, right, middle, (a->imm - 8) * 8);
2490f0984d40SFabiano Rosas             read_neon_element64(left, a->vm, 1, MO_64);
2491f0984d40SFabiano Rosas             tcg_gen_extract2_i64(destleft, middle, left, (a->imm - 8) * 8);
2492f0984d40SFabiano Rosas         }
2493f0984d40SFabiano Rosas 
2494f0984d40SFabiano Rosas         write_neon_element64(destright, a->vd, 0, MO_64);
2495f0984d40SFabiano Rosas         write_neon_element64(destleft, a->vd, 1, MO_64);
2496f0984d40SFabiano Rosas     }
2497f0984d40SFabiano Rosas     return true;
2498f0984d40SFabiano Rosas }
2499f0984d40SFabiano Rosas 
trans_VTBL(DisasContext * s,arg_VTBL * a)2500f0984d40SFabiano Rosas static bool trans_VTBL(DisasContext *s, arg_VTBL *a)
2501f0984d40SFabiano Rosas {
2502f0984d40SFabiano Rosas     TCGv_i64 val, def;
2503f0984d40SFabiano Rosas     TCGv_i32 desc;
2504f0984d40SFabiano Rosas 
2505f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2506f0984d40SFabiano Rosas         return false;
2507f0984d40SFabiano Rosas     }
2508f0984d40SFabiano Rosas 
2509f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2510f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2511f0984d40SFabiano Rosas         ((a->vd | a->vn | a->vm) & 0x10)) {
2512f0984d40SFabiano Rosas         return false;
2513f0984d40SFabiano Rosas     }
2514f0984d40SFabiano Rosas 
2515f0984d40SFabiano Rosas     if ((a->vn + a->len + 1) > 32) {
2516f0984d40SFabiano Rosas         /*
2517f0984d40SFabiano Rosas          * This is UNPREDICTABLE; we choose to UNDEF to avoid the
2518f0984d40SFabiano Rosas          * helper function running off the end of the register file.
2519f0984d40SFabiano Rosas          */
2520f0984d40SFabiano Rosas         return false;
2521f0984d40SFabiano Rosas     }
2522f0984d40SFabiano Rosas 
2523f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2524f0984d40SFabiano Rosas         return true;
2525f0984d40SFabiano Rosas     }
2526f0984d40SFabiano Rosas 
2527f0984d40SFabiano Rosas     desc = tcg_constant_i32((a->vn << 2) | a->len);
2528f0984d40SFabiano Rosas     def = tcg_temp_new_i64();
2529f0984d40SFabiano Rosas     if (a->op) {
2530f0984d40SFabiano Rosas         read_neon_element64(def, a->vd, 0, MO_64);
2531f0984d40SFabiano Rosas     } else {
2532f0984d40SFabiano Rosas         tcg_gen_movi_i64(def, 0);
2533f0984d40SFabiano Rosas     }
2534f0984d40SFabiano Rosas     val = tcg_temp_new_i64();
2535f0984d40SFabiano Rosas     read_neon_element64(val, a->vm, 0, MO_64);
2536f0984d40SFabiano Rosas 
2537ad75a51eSRichard Henderson     gen_helper_neon_tbl(val, tcg_env, desc, val, def);
2538f0984d40SFabiano Rosas     write_neon_element64(val, a->vd, 0, MO_64);
2539f0984d40SFabiano Rosas     return true;
2540f0984d40SFabiano Rosas }
2541f0984d40SFabiano Rosas 
trans_VDUP_scalar(DisasContext * s,arg_VDUP_scalar * a)2542f0984d40SFabiano Rosas static bool trans_VDUP_scalar(DisasContext *s, arg_VDUP_scalar *a)
2543f0984d40SFabiano Rosas {
2544f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2545f0984d40SFabiano Rosas         return false;
2546f0984d40SFabiano Rosas     }
2547f0984d40SFabiano Rosas 
2548f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2549f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2550f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2551f0984d40SFabiano Rosas         return false;
2552f0984d40SFabiano Rosas     }
2553f0984d40SFabiano Rosas 
2554f0984d40SFabiano Rosas     if (a->vd & a->q) {
2555f0984d40SFabiano Rosas         return false;
2556f0984d40SFabiano Rosas     }
2557f0984d40SFabiano Rosas 
2558f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2559f0984d40SFabiano Rosas         return true;
2560f0984d40SFabiano Rosas     }
2561f0984d40SFabiano Rosas 
2562f0984d40SFabiano Rosas     tcg_gen_gvec_dup_mem(a->size, neon_full_reg_offset(a->vd),
2563f0984d40SFabiano Rosas                          neon_element_offset(a->vm, a->index, a->size),
2564f0984d40SFabiano Rosas                          a->q ? 16 : 8, a->q ? 16 : 8);
2565f0984d40SFabiano Rosas     return true;
2566f0984d40SFabiano Rosas }
2567f0984d40SFabiano Rosas 
trans_VREV64(DisasContext * s,arg_VREV64 * a)2568f0984d40SFabiano Rosas static bool trans_VREV64(DisasContext *s, arg_VREV64 *a)
2569f0984d40SFabiano Rosas {
2570f0984d40SFabiano Rosas     int pass, half;
2571f0984d40SFabiano Rosas     TCGv_i32 tmp[2];
2572f0984d40SFabiano Rosas 
2573f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2574f0984d40SFabiano Rosas         return false;
2575f0984d40SFabiano Rosas     }
2576f0984d40SFabiano Rosas 
2577f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2578f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2579f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2580f0984d40SFabiano Rosas         return false;
2581f0984d40SFabiano Rosas     }
2582f0984d40SFabiano Rosas 
2583f0984d40SFabiano Rosas     if ((a->vd | a->vm) & a->q) {
2584f0984d40SFabiano Rosas         return false;
2585f0984d40SFabiano Rosas     }
2586f0984d40SFabiano Rosas 
2587f0984d40SFabiano Rosas     if (a->size == 3) {
2588f0984d40SFabiano Rosas         return false;
2589f0984d40SFabiano Rosas     }
2590f0984d40SFabiano Rosas 
2591f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2592f0984d40SFabiano Rosas         return true;
2593f0984d40SFabiano Rosas     }
2594f0984d40SFabiano Rosas 
2595f0984d40SFabiano Rosas     tmp[0] = tcg_temp_new_i32();
2596f0984d40SFabiano Rosas     tmp[1] = tcg_temp_new_i32();
2597f0984d40SFabiano Rosas 
2598f0984d40SFabiano Rosas     for (pass = 0; pass < (a->q ? 2 : 1); pass++) {
2599f0984d40SFabiano Rosas         for (half = 0; half < 2; half++) {
2600f0984d40SFabiano Rosas             read_neon_element32(tmp[half], a->vm, pass * 2 + half, MO_32);
2601f0984d40SFabiano Rosas             switch (a->size) {
2602f0984d40SFabiano Rosas             case 0:
2603f0984d40SFabiano Rosas                 tcg_gen_bswap32_i32(tmp[half], tmp[half]);
2604f0984d40SFabiano Rosas                 break;
2605f0984d40SFabiano Rosas             case 1:
2606f0984d40SFabiano Rosas                 gen_swap_half(tmp[half], tmp[half]);
2607f0984d40SFabiano Rosas                 break;
2608f0984d40SFabiano Rosas             case 2:
2609f0984d40SFabiano Rosas                 break;
2610f0984d40SFabiano Rosas             default:
2611f0984d40SFabiano Rosas                 g_assert_not_reached();
2612f0984d40SFabiano Rosas             }
2613f0984d40SFabiano Rosas         }
2614f0984d40SFabiano Rosas         write_neon_element32(tmp[1], a->vd, pass * 2, MO_32);
2615f0984d40SFabiano Rosas         write_neon_element32(tmp[0], a->vd, pass * 2 + 1, MO_32);
2616f0984d40SFabiano Rosas     }
2617f0984d40SFabiano Rosas     return true;
2618f0984d40SFabiano Rosas }
2619f0984d40SFabiano Rosas 
do_2misc_pairwise(DisasContext * s,arg_2misc * a,NeonGenWidenFn * widenfn,NeonGenTwo64OpFn * opfn,NeonGenTwo64OpFn * accfn)2620f0984d40SFabiano Rosas static bool do_2misc_pairwise(DisasContext *s, arg_2misc *a,
2621f0984d40SFabiano Rosas                               NeonGenWidenFn *widenfn,
2622f0984d40SFabiano Rosas                               NeonGenTwo64OpFn *opfn,
2623f0984d40SFabiano Rosas                               NeonGenTwo64OpFn *accfn)
2624f0984d40SFabiano Rosas {
2625f0984d40SFabiano Rosas     /*
2626f0984d40SFabiano Rosas      * Pairwise long operations: widen both halves of the pair,
2627f0984d40SFabiano Rosas      * combine the pairs with the opfn, and then possibly accumulate
2628f0984d40SFabiano Rosas      * into the destination with the accfn.
2629f0984d40SFabiano Rosas      */
2630f0984d40SFabiano Rosas     int pass;
2631f0984d40SFabiano Rosas 
2632f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2633f0984d40SFabiano Rosas         return false;
2634f0984d40SFabiano Rosas     }
2635f0984d40SFabiano Rosas 
2636f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2637f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2638f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2639f0984d40SFabiano Rosas         return false;
2640f0984d40SFabiano Rosas     }
2641f0984d40SFabiano Rosas 
2642f0984d40SFabiano Rosas     if ((a->vd | a->vm) & a->q) {
2643f0984d40SFabiano Rosas         return false;
2644f0984d40SFabiano Rosas     }
2645f0984d40SFabiano Rosas 
2646f0984d40SFabiano Rosas     if (!widenfn) {
2647f0984d40SFabiano Rosas         return false;
2648f0984d40SFabiano Rosas     }
2649f0984d40SFabiano Rosas 
2650f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2651f0984d40SFabiano Rosas         return true;
2652f0984d40SFabiano Rosas     }
2653f0984d40SFabiano Rosas 
2654f0984d40SFabiano Rosas     for (pass = 0; pass < a->q + 1; pass++) {
2655f0984d40SFabiano Rosas         TCGv_i32 tmp;
2656f0984d40SFabiano Rosas         TCGv_i64 rm0_64, rm1_64, rd_64;
2657f0984d40SFabiano Rosas 
2658f0984d40SFabiano Rosas         rm0_64 = tcg_temp_new_i64();
2659f0984d40SFabiano Rosas         rm1_64 = tcg_temp_new_i64();
2660f0984d40SFabiano Rosas         rd_64 = tcg_temp_new_i64();
2661f0984d40SFabiano Rosas 
2662f0984d40SFabiano Rosas         tmp = tcg_temp_new_i32();
2663f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vm, pass * 2, MO_32);
2664f0984d40SFabiano Rosas         widenfn(rm0_64, tmp);
2665f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vm, pass * 2 + 1, MO_32);
2666f0984d40SFabiano Rosas         widenfn(rm1_64, tmp);
2667f0984d40SFabiano Rosas 
2668f0984d40SFabiano Rosas         opfn(rd_64, rm0_64, rm1_64);
2669f0984d40SFabiano Rosas 
2670f0984d40SFabiano Rosas         if (accfn) {
2671f0984d40SFabiano Rosas             TCGv_i64 tmp64 = tcg_temp_new_i64();
2672f0984d40SFabiano Rosas             read_neon_element64(tmp64, a->vd, pass, MO_64);
2673f0984d40SFabiano Rosas             accfn(rd_64, tmp64, rd_64);
2674f0984d40SFabiano Rosas         }
2675f0984d40SFabiano Rosas         write_neon_element64(rd_64, a->vd, pass, MO_64);
2676f0984d40SFabiano Rosas     }
2677f0984d40SFabiano Rosas     return true;
2678f0984d40SFabiano Rosas }
2679f0984d40SFabiano Rosas 
trans_VPADDL_S(DisasContext * s,arg_2misc * a)2680f0984d40SFabiano Rosas static bool trans_VPADDL_S(DisasContext *s, arg_2misc *a)
2681f0984d40SFabiano Rosas {
2682f0984d40SFabiano Rosas     static NeonGenWidenFn * const widenfn[] = {
2683f0984d40SFabiano Rosas         gen_helper_neon_widen_s8,
2684f0984d40SFabiano Rosas         gen_helper_neon_widen_s16,
2685f0984d40SFabiano Rosas         tcg_gen_ext_i32_i64,
2686f0984d40SFabiano Rosas         NULL,
2687f0984d40SFabiano Rosas     };
2688f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const opfn[] = {
2689f0984d40SFabiano Rosas         gen_helper_neon_paddl_u16,
2690f0984d40SFabiano Rosas         gen_helper_neon_paddl_u32,
2691f0984d40SFabiano Rosas         tcg_gen_add_i64,
2692f0984d40SFabiano Rosas         NULL,
2693f0984d40SFabiano Rosas     };
2694f0984d40SFabiano Rosas 
2695f0984d40SFabiano Rosas     return do_2misc_pairwise(s, a, widenfn[a->size], opfn[a->size], NULL);
2696f0984d40SFabiano Rosas }
2697f0984d40SFabiano Rosas 
trans_VPADDL_U(DisasContext * s,arg_2misc * a)2698f0984d40SFabiano Rosas static bool trans_VPADDL_U(DisasContext *s, arg_2misc *a)
2699f0984d40SFabiano Rosas {
2700f0984d40SFabiano Rosas     static NeonGenWidenFn * const widenfn[] = {
2701f0984d40SFabiano Rosas         gen_helper_neon_widen_u8,
2702f0984d40SFabiano Rosas         gen_helper_neon_widen_u16,
2703f0984d40SFabiano Rosas         tcg_gen_extu_i32_i64,
2704f0984d40SFabiano Rosas         NULL,
2705f0984d40SFabiano Rosas     };
2706f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const opfn[] = {
2707f0984d40SFabiano Rosas         gen_helper_neon_paddl_u16,
2708f0984d40SFabiano Rosas         gen_helper_neon_paddl_u32,
2709f0984d40SFabiano Rosas         tcg_gen_add_i64,
2710f0984d40SFabiano Rosas         NULL,
2711f0984d40SFabiano Rosas     };
2712f0984d40SFabiano Rosas 
2713f0984d40SFabiano Rosas     return do_2misc_pairwise(s, a, widenfn[a->size], opfn[a->size], NULL);
2714f0984d40SFabiano Rosas }
2715f0984d40SFabiano Rosas 
trans_VPADAL_S(DisasContext * s,arg_2misc * a)2716f0984d40SFabiano Rosas static bool trans_VPADAL_S(DisasContext *s, arg_2misc *a)
2717f0984d40SFabiano Rosas {
2718f0984d40SFabiano Rosas     static NeonGenWidenFn * const widenfn[] = {
2719f0984d40SFabiano Rosas         gen_helper_neon_widen_s8,
2720f0984d40SFabiano Rosas         gen_helper_neon_widen_s16,
2721f0984d40SFabiano Rosas         tcg_gen_ext_i32_i64,
2722f0984d40SFabiano Rosas         NULL,
2723f0984d40SFabiano Rosas     };
2724f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const opfn[] = {
2725f0984d40SFabiano Rosas         gen_helper_neon_paddl_u16,
2726f0984d40SFabiano Rosas         gen_helper_neon_paddl_u32,
2727f0984d40SFabiano Rosas         tcg_gen_add_i64,
2728f0984d40SFabiano Rosas         NULL,
2729f0984d40SFabiano Rosas     };
2730f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const accfn[] = {
2731f0984d40SFabiano Rosas         gen_helper_neon_addl_u16,
2732f0984d40SFabiano Rosas         gen_helper_neon_addl_u32,
2733f0984d40SFabiano Rosas         tcg_gen_add_i64,
2734f0984d40SFabiano Rosas         NULL,
2735f0984d40SFabiano Rosas     };
2736f0984d40SFabiano Rosas 
2737f0984d40SFabiano Rosas     return do_2misc_pairwise(s, a, widenfn[a->size], opfn[a->size],
2738f0984d40SFabiano Rosas                              accfn[a->size]);
2739f0984d40SFabiano Rosas }
2740f0984d40SFabiano Rosas 
trans_VPADAL_U(DisasContext * s,arg_2misc * a)2741f0984d40SFabiano Rosas static bool trans_VPADAL_U(DisasContext *s, arg_2misc *a)
2742f0984d40SFabiano Rosas {
2743f0984d40SFabiano Rosas     static NeonGenWidenFn * const widenfn[] = {
2744f0984d40SFabiano Rosas         gen_helper_neon_widen_u8,
2745f0984d40SFabiano Rosas         gen_helper_neon_widen_u16,
2746f0984d40SFabiano Rosas         tcg_gen_extu_i32_i64,
2747f0984d40SFabiano Rosas         NULL,
2748f0984d40SFabiano Rosas     };
2749f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const opfn[] = {
2750f0984d40SFabiano Rosas         gen_helper_neon_paddl_u16,
2751f0984d40SFabiano Rosas         gen_helper_neon_paddl_u32,
2752f0984d40SFabiano Rosas         tcg_gen_add_i64,
2753f0984d40SFabiano Rosas         NULL,
2754f0984d40SFabiano Rosas     };
2755f0984d40SFabiano Rosas     static NeonGenTwo64OpFn * const accfn[] = {
2756f0984d40SFabiano Rosas         gen_helper_neon_addl_u16,
2757f0984d40SFabiano Rosas         gen_helper_neon_addl_u32,
2758f0984d40SFabiano Rosas         tcg_gen_add_i64,
2759f0984d40SFabiano Rosas         NULL,
2760f0984d40SFabiano Rosas     };
2761f0984d40SFabiano Rosas 
2762f0984d40SFabiano Rosas     return do_2misc_pairwise(s, a, widenfn[a->size], opfn[a->size],
2763f0984d40SFabiano Rosas                              accfn[a->size]);
2764f0984d40SFabiano Rosas }
2765f0984d40SFabiano Rosas 
2766f0984d40SFabiano Rosas typedef void ZipFn(TCGv_ptr, TCGv_ptr);
2767f0984d40SFabiano Rosas 
do_zip_uzp(DisasContext * s,arg_2misc * a,ZipFn * fn)2768f0984d40SFabiano Rosas static bool do_zip_uzp(DisasContext *s, arg_2misc *a,
2769f0984d40SFabiano Rosas                        ZipFn *fn)
2770f0984d40SFabiano Rosas {
2771f0984d40SFabiano Rosas     TCGv_ptr pd, pm;
2772f0984d40SFabiano Rosas 
2773f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2774f0984d40SFabiano Rosas         return false;
2775f0984d40SFabiano Rosas     }
2776f0984d40SFabiano Rosas 
2777f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2778f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2779f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2780f0984d40SFabiano Rosas         return false;
2781f0984d40SFabiano Rosas     }
2782f0984d40SFabiano Rosas 
2783f0984d40SFabiano Rosas     if ((a->vd | a->vm) & a->q) {
2784f0984d40SFabiano Rosas         return false;
2785f0984d40SFabiano Rosas     }
2786f0984d40SFabiano Rosas 
2787f0984d40SFabiano Rosas     if (!fn) {
2788f0984d40SFabiano Rosas         /* Bad size or size/q combination */
2789f0984d40SFabiano Rosas         return false;
2790f0984d40SFabiano Rosas     }
2791f0984d40SFabiano Rosas 
2792f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2793f0984d40SFabiano Rosas         return true;
2794f0984d40SFabiano Rosas     }
2795f0984d40SFabiano Rosas 
2796f0984d40SFabiano Rosas     pd = vfp_reg_ptr(true, a->vd);
2797f0984d40SFabiano Rosas     pm = vfp_reg_ptr(true, a->vm);
2798f0984d40SFabiano Rosas     fn(pd, pm);
2799f0984d40SFabiano Rosas     return true;
2800f0984d40SFabiano Rosas }
2801f0984d40SFabiano Rosas 
trans_VUZP(DisasContext * s,arg_2misc * a)2802f0984d40SFabiano Rosas static bool trans_VUZP(DisasContext *s, arg_2misc *a)
2803f0984d40SFabiano Rosas {
2804f0984d40SFabiano Rosas     static ZipFn * const fn[2][4] = {
2805f0984d40SFabiano Rosas         {
2806f0984d40SFabiano Rosas             gen_helper_neon_unzip8,
2807f0984d40SFabiano Rosas             gen_helper_neon_unzip16,
2808f0984d40SFabiano Rosas             NULL,
2809f0984d40SFabiano Rosas             NULL,
2810f0984d40SFabiano Rosas         }, {
2811f0984d40SFabiano Rosas             gen_helper_neon_qunzip8,
2812f0984d40SFabiano Rosas             gen_helper_neon_qunzip16,
2813f0984d40SFabiano Rosas             gen_helper_neon_qunzip32,
2814f0984d40SFabiano Rosas             NULL,
2815f0984d40SFabiano Rosas         }
2816f0984d40SFabiano Rosas     };
2817f0984d40SFabiano Rosas     return do_zip_uzp(s, a, fn[a->q][a->size]);
2818f0984d40SFabiano Rosas }
2819f0984d40SFabiano Rosas 
trans_VZIP(DisasContext * s,arg_2misc * a)2820f0984d40SFabiano Rosas static bool trans_VZIP(DisasContext *s, arg_2misc *a)
2821f0984d40SFabiano Rosas {
2822f0984d40SFabiano Rosas     static ZipFn * const fn[2][4] = {
2823f0984d40SFabiano Rosas         {
2824f0984d40SFabiano Rosas             gen_helper_neon_zip8,
2825f0984d40SFabiano Rosas             gen_helper_neon_zip16,
2826f0984d40SFabiano Rosas             NULL,
2827f0984d40SFabiano Rosas             NULL,
2828f0984d40SFabiano Rosas         }, {
2829f0984d40SFabiano Rosas             gen_helper_neon_qzip8,
2830f0984d40SFabiano Rosas             gen_helper_neon_qzip16,
2831f0984d40SFabiano Rosas             gen_helper_neon_qzip32,
2832f0984d40SFabiano Rosas             NULL,
2833f0984d40SFabiano Rosas         }
2834f0984d40SFabiano Rosas     };
2835f0984d40SFabiano Rosas     return do_zip_uzp(s, a, fn[a->q][a->size]);
2836f0984d40SFabiano Rosas }
2837f0984d40SFabiano Rosas 
do_vmovn(DisasContext * s,arg_2misc * a,NeonGenOne64OpEnvFn * narrowfn)2838f0984d40SFabiano Rosas static bool do_vmovn(DisasContext *s, arg_2misc *a,
2839*3e683f0aSRichard Henderson                      NeonGenOne64OpEnvFn *narrowfn)
2840f0984d40SFabiano Rosas {
2841*3e683f0aSRichard Henderson     TCGv_i64 rm, rd0, rd1;
2842f0984d40SFabiano Rosas 
2843f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2844f0984d40SFabiano Rosas         return false;
2845f0984d40SFabiano Rosas     }
2846f0984d40SFabiano Rosas 
2847f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2848f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2849f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2850f0984d40SFabiano Rosas         return false;
2851f0984d40SFabiano Rosas     }
2852f0984d40SFabiano Rosas 
2853f0984d40SFabiano Rosas     if (a->vm & 1) {
2854f0984d40SFabiano Rosas         return false;
2855f0984d40SFabiano Rosas     }
2856f0984d40SFabiano Rosas 
2857f0984d40SFabiano Rosas     if (!narrowfn) {
2858f0984d40SFabiano Rosas         return false;
2859f0984d40SFabiano Rosas     }
2860f0984d40SFabiano Rosas 
2861f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2862f0984d40SFabiano Rosas         return true;
2863f0984d40SFabiano Rosas     }
2864f0984d40SFabiano Rosas 
2865f0984d40SFabiano Rosas     rm = tcg_temp_new_i64();
2866*3e683f0aSRichard Henderson     rd0 = tcg_temp_new_i64();
2867*3e683f0aSRichard Henderson     rd1 = tcg_temp_new_i64();
2868f0984d40SFabiano Rosas 
2869f0984d40SFabiano Rosas     read_neon_element64(rm, a->vm, 0, MO_64);
2870ad75a51eSRichard Henderson     narrowfn(rd0, tcg_env, rm);
2871f0984d40SFabiano Rosas     read_neon_element64(rm, a->vm, 1, MO_64);
2872ad75a51eSRichard Henderson     narrowfn(rd1, tcg_env, rm);
2873*3e683f0aSRichard Henderson     write_neon_element64(rd0, a->vd, 0, MO_32);
2874*3e683f0aSRichard Henderson     write_neon_element64(rd1, a->vd, 1, MO_32);
2875f0984d40SFabiano Rosas     return true;
2876f0984d40SFabiano Rosas }
2877f0984d40SFabiano Rosas 
2878f0984d40SFabiano Rosas #define DO_VMOVN(INSN, FUNC)                                    \
2879f0984d40SFabiano Rosas     static bool trans_##INSN(DisasContext *s, arg_2misc *a)     \
2880f0984d40SFabiano Rosas     {                                                           \
2881*3e683f0aSRichard Henderson         static NeonGenOne64OpEnvFn * const narrowfn[] = {       \
2882f0984d40SFabiano Rosas             FUNC##8,                                            \
2883f0984d40SFabiano Rosas             FUNC##16,                                           \
2884f0984d40SFabiano Rosas             FUNC##32,                                           \
2885f0984d40SFabiano Rosas             NULL,                                               \
2886f0984d40SFabiano Rosas         };                                                      \
2887f0984d40SFabiano Rosas         return do_vmovn(s, a, narrowfn[a->size]);               \
2888f0984d40SFabiano Rosas     }
2889f0984d40SFabiano Rosas 
DO_VMOVN(VMOVN,gen_neon_narrow_u)2890f0984d40SFabiano Rosas DO_VMOVN(VMOVN, gen_neon_narrow_u)
2891f0984d40SFabiano Rosas DO_VMOVN(VQMOVUN, gen_helper_neon_unarrow_sat)
2892f0984d40SFabiano Rosas DO_VMOVN(VQMOVN_S, gen_helper_neon_narrow_sat_s)
2893f0984d40SFabiano Rosas DO_VMOVN(VQMOVN_U, gen_helper_neon_narrow_sat_u)
2894f0984d40SFabiano Rosas 
2895f0984d40SFabiano Rosas static bool trans_VSHLL(DisasContext *s, arg_2misc *a)
2896f0984d40SFabiano Rosas {
2897f0984d40SFabiano Rosas     TCGv_i32 rm0, rm1;
2898f0984d40SFabiano Rosas     TCGv_i64 rd;
2899f0984d40SFabiano Rosas     static NeonGenWidenFn * const widenfns[] = {
2900f0984d40SFabiano Rosas         gen_helper_neon_widen_u8,
2901f0984d40SFabiano Rosas         gen_helper_neon_widen_u16,
2902f0984d40SFabiano Rosas         tcg_gen_extu_i32_i64,
2903f0984d40SFabiano Rosas         NULL,
2904f0984d40SFabiano Rosas     };
2905f0984d40SFabiano Rosas     NeonGenWidenFn *widenfn = widenfns[a->size];
2906f0984d40SFabiano Rosas 
2907f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
2908f0984d40SFabiano Rosas         return false;
2909f0984d40SFabiano Rosas     }
2910f0984d40SFabiano Rosas 
2911f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2912f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2913f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2914f0984d40SFabiano Rosas         return false;
2915f0984d40SFabiano Rosas     }
2916f0984d40SFabiano Rosas 
2917f0984d40SFabiano Rosas     if (a->vd & 1) {
2918f0984d40SFabiano Rosas         return false;
2919f0984d40SFabiano Rosas     }
2920f0984d40SFabiano Rosas 
2921f0984d40SFabiano Rosas     if (!widenfn) {
2922f0984d40SFabiano Rosas         return false;
2923f0984d40SFabiano Rosas     }
2924f0984d40SFabiano Rosas 
2925f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2926f0984d40SFabiano Rosas         return true;
2927f0984d40SFabiano Rosas     }
2928f0984d40SFabiano Rosas 
2929f0984d40SFabiano Rosas     rd = tcg_temp_new_i64();
2930f0984d40SFabiano Rosas     rm0 = tcg_temp_new_i32();
2931f0984d40SFabiano Rosas     rm1 = tcg_temp_new_i32();
2932f0984d40SFabiano Rosas 
2933f0984d40SFabiano Rosas     read_neon_element32(rm0, a->vm, 0, MO_32);
2934f0984d40SFabiano Rosas     read_neon_element32(rm1, a->vm, 1, MO_32);
2935f0984d40SFabiano Rosas 
2936f0984d40SFabiano Rosas     widenfn(rd, rm0);
2937f0984d40SFabiano Rosas     tcg_gen_shli_i64(rd, rd, 8 << a->size);
2938f0984d40SFabiano Rosas     write_neon_element64(rd, a->vd, 0, MO_64);
2939f0984d40SFabiano Rosas     widenfn(rd, rm1);
2940f0984d40SFabiano Rosas     tcg_gen_shli_i64(rd, rd, 8 << a->size);
2941f0984d40SFabiano Rosas     write_neon_element64(rd, a->vd, 1, MO_64);
2942f0984d40SFabiano Rosas     return true;
2943f0984d40SFabiano Rosas }
2944f0984d40SFabiano Rosas 
trans_VCVT_B16_F32(DisasContext * s,arg_2misc * a)2945f0984d40SFabiano Rosas static bool trans_VCVT_B16_F32(DisasContext *s, arg_2misc *a)
2946f0984d40SFabiano Rosas {
2947f0984d40SFabiano Rosas     TCGv_ptr fpst;
2948f0984d40SFabiano Rosas     TCGv_i64 tmp;
2949f0984d40SFabiano Rosas     TCGv_i32 dst0, dst1;
2950f0984d40SFabiano Rosas 
2951f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_bf16, s)) {
2952f0984d40SFabiano Rosas         return false;
2953f0984d40SFabiano Rosas     }
2954f0984d40SFabiano Rosas 
2955f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2956f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2957f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2958f0984d40SFabiano Rosas         return false;
2959f0984d40SFabiano Rosas     }
2960f0984d40SFabiano Rosas 
2961f0984d40SFabiano Rosas     if ((a->vm & 1) || (a->size != 1)) {
2962f0984d40SFabiano Rosas         return false;
2963f0984d40SFabiano Rosas     }
2964f0984d40SFabiano Rosas 
2965f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
2966f0984d40SFabiano Rosas         return true;
2967f0984d40SFabiano Rosas     }
2968f0984d40SFabiano Rosas 
2969f0984d40SFabiano Rosas     fpst = fpstatus_ptr(FPST_STD);
2970f0984d40SFabiano Rosas     tmp = tcg_temp_new_i64();
2971f0984d40SFabiano Rosas     dst0 = tcg_temp_new_i32();
2972f0984d40SFabiano Rosas     dst1 = tcg_temp_new_i32();
2973f0984d40SFabiano Rosas 
2974f0984d40SFabiano Rosas     read_neon_element64(tmp, a->vm, 0, MO_64);
2975f0984d40SFabiano Rosas     gen_helper_bfcvt_pair(dst0, tmp, fpst);
2976f0984d40SFabiano Rosas 
2977f0984d40SFabiano Rosas     read_neon_element64(tmp, a->vm, 1, MO_64);
2978f0984d40SFabiano Rosas     gen_helper_bfcvt_pair(dst1, tmp, fpst);
2979f0984d40SFabiano Rosas 
2980f0984d40SFabiano Rosas     write_neon_element32(dst0, a->vd, 0, MO_32);
2981f0984d40SFabiano Rosas     write_neon_element32(dst1, a->vd, 1, MO_32);
2982f0984d40SFabiano Rosas     return true;
2983f0984d40SFabiano Rosas }
2984f0984d40SFabiano Rosas 
trans_VCVT_F16_F32(DisasContext * s,arg_2misc * a)2985f0984d40SFabiano Rosas static bool trans_VCVT_F16_F32(DisasContext *s, arg_2misc *a)
2986f0984d40SFabiano Rosas {
2987f0984d40SFabiano Rosas     TCGv_ptr fpst;
2988f0984d40SFabiano Rosas     TCGv_i32 ahp, tmp, tmp2, tmp3;
2989f0984d40SFabiano Rosas 
2990f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON) ||
2991f0984d40SFabiano Rosas         !dc_isar_feature(aa32_fp16_spconv, s)) {
2992f0984d40SFabiano Rosas         return false;
2993f0984d40SFabiano Rosas     }
2994f0984d40SFabiano Rosas 
2995f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
2996f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
2997f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
2998f0984d40SFabiano Rosas         return false;
2999f0984d40SFabiano Rosas     }
3000f0984d40SFabiano Rosas 
3001f0984d40SFabiano Rosas     if ((a->vm & 1) || (a->size != 1)) {
3002f0984d40SFabiano Rosas         return false;
3003f0984d40SFabiano Rosas     }
3004f0984d40SFabiano Rosas 
3005f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
3006f0984d40SFabiano Rosas         return true;
3007f0984d40SFabiano Rosas     }
3008f0984d40SFabiano Rosas 
3009f0984d40SFabiano Rosas     fpst = fpstatus_ptr(FPST_STD);
3010f0984d40SFabiano Rosas     ahp = get_ahp_flag();
3011f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
3012f0984d40SFabiano Rosas     read_neon_element32(tmp, a->vm, 0, MO_32);
3013f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f32_to_f16(tmp, tmp, fpst, ahp);
3014f0984d40SFabiano Rosas     tmp2 = tcg_temp_new_i32();
3015f0984d40SFabiano Rosas     read_neon_element32(tmp2, a->vm, 1, MO_32);
3016f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f32_to_f16(tmp2, tmp2, fpst, ahp);
3017f0984d40SFabiano Rosas     tcg_gen_shli_i32(tmp2, tmp2, 16);
3018f0984d40SFabiano Rosas     tcg_gen_or_i32(tmp2, tmp2, tmp);
3019f0984d40SFabiano Rosas     read_neon_element32(tmp, a->vm, 2, MO_32);
3020f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f32_to_f16(tmp, tmp, fpst, ahp);
3021f0984d40SFabiano Rosas     tmp3 = tcg_temp_new_i32();
3022f0984d40SFabiano Rosas     read_neon_element32(tmp3, a->vm, 3, MO_32);
3023f0984d40SFabiano Rosas     write_neon_element32(tmp2, a->vd, 0, MO_32);
3024f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f32_to_f16(tmp3, tmp3, fpst, ahp);
3025f0984d40SFabiano Rosas     tcg_gen_shli_i32(tmp3, tmp3, 16);
3026f0984d40SFabiano Rosas     tcg_gen_or_i32(tmp3, tmp3, tmp);
3027f0984d40SFabiano Rosas     write_neon_element32(tmp3, a->vd, 1, MO_32);
3028f0984d40SFabiano Rosas     return true;
3029f0984d40SFabiano Rosas }
3030f0984d40SFabiano Rosas 
trans_VCVT_F32_F16(DisasContext * s,arg_2misc * a)3031f0984d40SFabiano Rosas static bool trans_VCVT_F32_F16(DisasContext *s, arg_2misc *a)
3032f0984d40SFabiano Rosas {
3033f0984d40SFabiano Rosas     TCGv_ptr fpst;
3034f0984d40SFabiano Rosas     TCGv_i32 ahp, tmp, tmp2, tmp3;
3035f0984d40SFabiano Rosas 
3036f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON) ||
3037f0984d40SFabiano Rosas         !dc_isar_feature(aa32_fp16_spconv, s)) {
3038f0984d40SFabiano Rosas         return false;
3039f0984d40SFabiano Rosas     }
3040f0984d40SFabiano Rosas 
3041f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
3042f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
3043f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
3044f0984d40SFabiano Rosas         return false;
3045f0984d40SFabiano Rosas     }
3046f0984d40SFabiano Rosas 
3047f0984d40SFabiano Rosas     if ((a->vd & 1) || (a->size != 1)) {
3048f0984d40SFabiano Rosas         return false;
3049f0984d40SFabiano Rosas     }
3050f0984d40SFabiano Rosas 
3051f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
3052f0984d40SFabiano Rosas         return true;
3053f0984d40SFabiano Rosas     }
3054f0984d40SFabiano Rosas 
3055f0984d40SFabiano Rosas     fpst = fpstatus_ptr(FPST_STD);
3056f0984d40SFabiano Rosas     ahp = get_ahp_flag();
3057f0984d40SFabiano Rosas     tmp3 = tcg_temp_new_i32();
3058f0984d40SFabiano Rosas     tmp2 = tcg_temp_new_i32();
3059f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
3060f0984d40SFabiano Rosas     read_neon_element32(tmp, a->vm, 0, MO_32);
3061f0984d40SFabiano Rosas     read_neon_element32(tmp2, a->vm, 1, MO_32);
3062f0984d40SFabiano Rosas     tcg_gen_ext16u_i32(tmp3, tmp);
3063f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f16_to_f32(tmp3, tmp3, fpst, ahp);
3064f0984d40SFabiano Rosas     write_neon_element32(tmp3, a->vd, 0, MO_32);
3065f0984d40SFabiano Rosas     tcg_gen_shri_i32(tmp, tmp, 16);
3066f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f16_to_f32(tmp, tmp, fpst, ahp);
3067f0984d40SFabiano Rosas     write_neon_element32(tmp, a->vd, 1, MO_32);
3068f0984d40SFabiano Rosas     tcg_gen_ext16u_i32(tmp3, tmp2);
3069f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f16_to_f32(tmp3, tmp3, fpst, ahp);
3070f0984d40SFabiano Rosas     write_neon_element32(tmp3, a->vd, 2, MO_32);
3071f0984d40SFabiano Rosas     tcg_gen_shri_i32(tmp2, tmp2, 16);
3072f0984d40SFabiano Rosas     gen_helper_vfp_fcvt_f16_to_f32(tmp2, tmp2, fpst, ahp);
3073f0984d40SFabiano Rosas     write_neon_element32(tmp2, a->vd, 3, MO_32);
3074f0984d40SFabiano Rosas     return true;
3075f0984d40SFabiano Rosas }
3076f0984d40SFabiano Rosas 
do_2misc_vec(DisasContext * s,arg_2misc * a,GVecGen2Fn * fn)3077f0984d40SFabiano Rosas static bool do_2misc_vec(DisasContext *s, arg_2misc *a, GVecGen2Fn *fn)
3078f0984d40SFabiano Rosas {
3079f0984d40SFabiano Rosas     int vec_size = a->q ? 16 : 8;
3080f0984d40SFabiano Rosas     int rd_ofs = neon_full_reg_offset(a->vd);
3081f0984d40SFabiano Rosas     int rm_ofs = neon_full_reg_offset(a->vm);
3082f0984d40SFabiano Rosas 
3083f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
3084f0984d40SFabiano Rosas         return false;
3085f0984d40SFabiano Rosas     }
3086f0984d40SFabiano Rosas 
3087f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
3088f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
3089f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
3090f0984d40SFabiano Rosas         return false;
3091f0984d40SFabiano Rosas     }
3092f0984d40SFabiano Rosas 
3093f0984d40SFabiano Rosas     if (a->size == 3) {
3094f0984d40SFabiano Rosas         return false;
3095f0984d40SFabiano Rosas     }
3096f0984d40SFabiano Rosas 
3097f0984d40SFabiano Rosas     if ((a->vd | a->vm) & a->q) {
3098f0984d40SFabiano Rosas         return false;
3099f0984d40SFabiano Rosas     }
3100f0984d40SFabiano Rosas 
3101f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
3102f0984d40SFabiano Rosas         return true;
3103f0984d40SFabiano Rosas     }
3104f0984d40SFabiano Rosas 
3105f0984d40SFabiano Rosas     fn(a->size, rd_ofs, rm_ofs, vec_size, vec_size);
3106f0984d40SFabiano Rosas 
3107f0984d40SFabiano Rosas     return true;
3108f0984d40SFabiano Rosas }
3109f0984d40SFabiano Rosas 
3110f0984d40SFabiano Rosas #define DO_2MISC_VEC(INSN, FN)                                  \
3111f0984d40SFabiano Rosas     static bool trans_##INSN(DisasContext *s, arg_2misc *a)     \
3112f0984d40SFabiano Rosas     {                                                           \
3113f0984d40SFabiano Rosas         return do_2misc_vec(s, a, FN);                          \
3114f0984d40SFabiano Rosas     }
3115f0984d40SFabiano Rosas 
DO_2MISC_VEC(VNEG,tcg_gen_gvec_neg)3116f0984d40SFabiano Rosas DO_2MISC_VEC(VNEG, tcg_gen_gvec_neg)
3117f0984d40SFabiano Rosas DO_2MISC_VEC(VABS, tcg_gen_gvec_abs)
3118f0984d40SFabiano Rosas DO_2MISC_VEC(VCEQ0, gen_gvec_ceq0)
3119f0984d40SFabiano Rosas DO_2MISC_VEC(VCGT0, gen_gvec_cgt0)
3120f0984d40SFabiano Rosas DO_2MISC_VEC(VCLE0, gen_gvec_cle0)
3121f0984d40SFabiano Rosas DO_2MISC_VEC(VCGE0, gen_gvec_cge0)
3122f0984d40SFabiano Rosas DO_2MISC_VEC(VCLT0, gen_gvec_clt0)
3123f0984d40SFabiano Rosas 
3124f0984d40SFabiano Rosas static bool trans_VMVN(DisasContext *s, arg_2misc *a)
3125f0984d40SFabiano Rosas {
3126f0984d40SFabiano Rosas     if (a->size != 0) {
3127f0984d40SFabiano Rosas         return false;
3128f0984d40SFabiano Rosas     }
3129f0984d40SFabiano Rosas     return do_2misc_vec(s, a, tcg_gen_gvec_not);
3130f0984d40SFabiano Rosas }
3131f0984d40SFabiano Rosas 
3132f0984d40SFabiano Rosas #define WRAP_2M_3_OOL_FN(WRAPNAME, FUNC, DATA)                          \
3133f0984d40SFabiano Rosas     static void WRAPNAME(unsigned vece, uint32_t rd_ofs,                \
3134f0984d40SFabiano Rosas                          uint32_t rm_ofs, uint32_t oprsz,               \
3135f0984d40SFabiano Rosas                          uint32_t maxsz)                                \
3136f0984d40SFabiano Rosas     {                                                                   \
3137f0984d40SFabiano Rosas         tcg_gen_gvec_3_ool(rd_ofs, rd_ofs, rm_ofs, oprsz, maxsz,        \
3138f0984d40SFabiano Rosas                            DATA, FUNC);                                 \
3139f0984d40SFabiano Rosas     }
3140f0984d40SFabiano Rosas 
3141f0984d40SFabiano Rosas #define WRAP_2M_2_OOL_FN(WRAPNAME, FUNC, DATA)                          \
3142f0984d40SFabiano Rosas     static void WRAPNAME(unsigned vece, uint32_t rd_ofs,                \
3143f0984d40SFabiano Rosas                          uint32_t rm_ofs, uint32_t oprsz,               \
3144f0984d40SFabiano Rosas                          uint32_t maxsz)                                \
3145f0984d40SFabiano Rosas     {                                                                   \
3146f0984d40SFabiano Rosas         tcg_gen_gvec_2_ool(rd_ofs, rm_ofs, oprsz, maxsz, DATA, FUNC);   \
3147f0984d40SFabiano Rosas     }
3148f0984d40SFabiano Rosas 
3149f0984d40SFabiano Rosas WRAP_2M_3_OOL_FN(gen_AESE, gen_helper_crypto_aese, 0)
31500f23908cSRichard Henderson WRAP_2M_3_OOL_FN(gen_AESD, gen_helper_crypto_aesd, 0)
3151f0984d40SFabiano Rosas WRAP_2M_2_OOL_FN(gen_AESMC, gen_helper_crypto_aesmc, 0)
31520f23908cSRichard Henderson WRAP_2M_2_OOL_FN(gen_AESIMC, gen_helper_crypto_aesimc, 0)
3153f0984d40SFabiano Rosas WRAP_2M_2_OOL_FN(gen_SHA1H, gen_helper_crypto_sha1h, 0)
3154f0984d40SFabiano Rosas WRAP_2M_2_OOL_FN(gen_SHA1SU1, gen_helper_crypto_sha1su1, 0)
3155f0984d40SFabiano Rosas WRAP_2M_2_OOL_FN(gen_SHA256SU0, gen_helper_crypto_sha256su0, 0)
3156f0984d40SFabiano Rosas 
3157f0984d40SFabiano Rosas #define DO_2M_CRYPTO(INSN, FEATURE, SIZE)                       \
3158f0984d40SFabiano Rosas     static bool trans_##INSN(DisasContext *s, arg_2misc *a)     \
3159f0984d40SFabiano Rosas     {                                                           \
3160f0984d40SFabiano Rosas         if (!dc_isar_feature(FEATURE, s) || a->size != SIZE) {  \
3161f0984d40SFabiano Rosas             return false;                                       \
3162f0984d40SFabiano Rosas         }                                                       \
3163f0984d40SFabiano Rosas         return do_2misc_vec(s, a, gen_##INSN);                  \
3164f0984d40SFabiano Rosas     }
3165f0984d40SFabiano Rosas 
3166f0984d40SFabiano Rosas DO_2M_CRYPTO(AESE, aa32_aes, 0)
3167f0984d40SFabiano Rosas DO_2M_CRYPTO(AESD, aa32_aes, 0)
3168f0984d40SFabiano Rosas DO_2M_CRYPTO(AESMC, aa32_aes, 0)
3169f0984d40SFabiano Rosas DO_2M_CRYPTO(AESIMC, aa32_aes, 0)
3170f0984d40SFabiano Rosas DO_2M_CRYPTO(SHA1H, aa32_sha1, 2)
3171f0984d40SFabiano Rosas DO_2M_CRYPTO(SHA1SU1, aa32_sha1, 2)
3172f0984d40SFabiano Rosas DO_2M_CRYPTO(SHA256SU0, aa32_sha2, 2)
3173f0984d40SFabiano Rosas 
do_2misc(DisasContext * s,arg_2misc * a,NeonGenOneOpFn * fn)3174f0984d40SFabiano Rosas static bool do_2misc(DisasContext *s, arg_2misc *a, NeonGenOneOpFn *fn)
3175f0984d40SFabiano Rosas {
3176f0984d40SFabiano Rosas     TCGv_i32 tmp;
3177f0984d40SFabiano Rosas     int pass;
3178f0984d40SFabiano Rosas 
3179f0984d40SFabiano Rosas     /* Handle a 2-reg-misc operation by iterating 32 bits at a time */
3180f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
3181f0984d40SFabiano Rosas         return false;
3182f0984d40SFabiano Rosas     }
3183f0984d40SFabiano Rosas 
3184f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
3185f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
3186f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
3187f0984d40SFabiano Rosas         return false;
3188f0984d40SFabiano Rosas     }
3189f0984d40SFabiano Rosas 
3190f0984d40SFabiano Rosas     if (!fn) {
3191f0984d40SFabiano Rosas         return false;
3192f0984d40SFabiano Rosas     }
3193f0984d40SFabiano Rosas 
3194f0984d40SFabiano Rosas     if ((a->vd | a->vm) & a->q) {
3195f0984d40SFabiano Rosas         return false;
3196f0984d40SFabiano Rosas     }
3197f0984d40SFabiano Rosas 
3198f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
3199f0984d40SFabiano Rosas         return true;
3200f0984d40SFabiano Rosas     }
3201f0984d40SFabiano Rosas 
3202f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
3203f0984d40SFabiano Rosas     for (pass = 0; pass < (a->q ? 4 : 2); pass++) {
3204f0984d40SFabiano Rosas         read_neon_element32(tmp, a->vm, pass, MO_32);
3205f0984d40SFabiano Rosas         fn(tmp, tmp);
3206f0984d40SFabiano Rosas         write_neon_element32(tmp, a->vd, pass, MO_32);
3207f0984d40SFabiano Rosas     }
3208f0984d40SFabiano Rosas     return true;
3209f0984d40SFabiano Rosas }
3210f0984d40SFabiano Rosas 
trans_VREV32(DisasContext * s,arg_2misc * a)3211f0984d40SFabiano Rosas static bool trans_VREV32(DisasContext *s, arg_2misc *a)
3212f0984d40SFabiano Rosas {
3213f0984d40SFabiano Rosas     static NeonGenOneOpFn * const fn[] = {
3214f0984d40SFabiano Rosas         tcg_gen_bswap32_i32,
3215f0984d40SFabiano Rosas         gen_swap_half,
3216f0984d40SFabiano Rosas         NULL,
3217f0984d40SFabiano Rosas         NULL,
3218f0984d40SFabiano Rosas     };
3219f0984d40SFabiano Rosas     return do_2misc(s, a, fn[a->size]);
3220f0984d40SFabiano Rosas }
3221f0984d40SFabiano Rosas 
trans_VREV16(DisasContext * s,arg_2misc * a)3222f0984d40SFabiano Rosas static bool trans_VREV16(DisasContext *s, arg_2misc *a)
3223f0984d40SFabiano Rosas {
3224f0984d40SFabiano Rosas     if (a->size != 0) {
3225f0984d40SFabiano Rosas         return false;
3226f0984d40SFabiano Rosas     }
3227f0984d40SFabiano Rosas     return do_2misc(s, a, gen_rev16);
3228f0984d40SFabiano Rosas }
3229f0984d40SFabiano Rosas 
trans_VCLS(DisasContext * s,arg_2misc * a)3230f0984d40SFabiano Rosas static bool trans_VCLS(DisasContext *s, arg_2misc *a)
3231f0984d40SFabiano Rosas {
3232f0984d40SFabiano Rosas     static NeonGenOneOpFn * const fn[] = {
3233f0984d40SFabiano Rosas         gen_helper_neon_cls_s8,
3234f0984d40SFabiano Rosas         gen_helper_neon_cls_s16,
3235f0984d40SFabiano Rosas         gen_helper_neon_cls_s32,
3236f0984d40SFabiano Rosas         NULL,
3237f0984d40SFabiano Rosas     };
3238f0984d40SFabiano Rosas     return do_2misc(s, a, fn[a->size]);
3239f0984d40SFabiano Rosas }
3240f0984d40SFabiano Rosas 
do_VCLZ_32(TCGv_i32 rd,TCGv_i32 rm)3241f0984d40SFabiano Rosas static void do_VCLZ_32(TCGv_i32 rd, TCGv_i32 rm)
3242f0984d40SFabiano Rosas {
3243f0984d40SFabiano Rosas     tcg_gen_clzi_i32(rd, rm, 32);
3244f0984d40SFabiano Rosas }
3245f0984d40SFabiano Rosas 
trans_VCLZ(DisasContext * s,arg_2misc * a)3246f0984d40SFabiano Rosas static bool trans_VCLZ(DisasContext *s, arg_2misc *a)
3247f0984d40SFabiano Rosas {
3248f0984d40SFabiano Rosas     static NeonGenOneOpFn * const fn[] = {
3249f0984d40SFabiano Rosas         gen_helper_neon_clz_u8,
3250f0984d40SFabiano Rosas         gen_helper_neon_clz_u16,
3251f0984d40SFabiano Rosas         do_VCLZ_32,
3252f0984d40SFabiano Rosas         NULL,
3253f0984d40SFabiano Rosas     };
3254f0984d40SFabiano Rosas     return do_2misc(s, a, fn[a->size]);
3255f0984d40SFabiano Rosas }
3256f0984d40SFabiano Rosas 
trans_VCNT(DisasContext * s,arg_2misc * a)3257f0984d40SFabiano Rosas static bool trans_VCNT(DisasContext *s, arg_2misc *a)
3258f0984d40SFabiano Rosas {
3259f0984d40SFabiano Rosas     if (a->size != 0) {
3260f0984d40SFabiano Rosas         return false;
3261f0984d40SFabiano Rosas     }
3262f0984d40SFabiano Rosas     return do_2misc(s, a, gen_helper_neon_cnt_u8);
3263f0984d40SFabiano Rosas }
3264f0984d40SFabiano Rosas 
gen_VABS_F(unsigned vece,uint32_t rd_ofs,uint32_t rm_ofs,uint32_t oprsz,uint32_t maxsz)3265f0984d40SFabiano Rosas static void gen_VABS_F(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
3266f0984d40SFabiano Rosas                        uint32_t oprsz, uint32_t maxsz)
3267f0984d40SFabiano Rosas {
3268f0984d40SFabiano Rosas     tcg_gen_gvec_andi(vece, rd_ofs, rm_ofs,
3269f0984d40SFabiano Rosas                       vece == MO_16 ? 0x7fff : 0x7fffffff,
3270f0984d40SFabiano Rosas                       oprsz, maxsz);
3271f0984d40SFabiano Rosas }
3272f0984d40SFabiano Rosas 
trans_VABS_F(DisasContext * s,arg_2misc * a)3273f0984d40SFabiano Rosas static bool trans_VABS_F(DisasContext *s, arg_2misc *a)
3274f0984d40SFabiano Rosas {
3275f0984d40SFabiano Rosas     if (a->size == MO_16) {
3276f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_fp16_arith, s)) {
3277f0984d40SFabiano Rosas             return false;
3278f0984d40SFabiano Rosas         }
3279f0984d40SFabiano Rosas     } else if (a->size != MO_32) {
3280f0984d40SFabiano Rosas         return false;
3281f0984d40SFabiano Rosas     }
3282f0984d40SFabiano Rosas     return do_2misc_vec(s, a, gen_VABS_F);
3283f0984d40SFabiano Rosas }
3284f0984d40SFabiano Rosas 
gen_VNEG_F(unsigned vece,uint32_t rd_ofs,uint32_t rm_ofs,uint32_t oprsz,uint32_t maxsz)3285f0984d40SFabiano Rosas static void gen_VNEG_F(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs,
3286f0984d40SFabiano Rosas                        uint32_t oprsz, uint32_t maxsz)
3287f0984d40SFabiano Rosas {
3288f0984d40SFabiano Rosas     tcg_gen_gvec_xori(vece, rd_ofs, rm_ofs,
3289f0984d40SFabiano Rosas                       vece == MO_16 ? 0x8000 : 0x80000000,
3290f0984d40SFabiano Rosas                       oprsz, maxsz);
3291f0984d40SFabiano Rosas }
3292f0984d40SFabiano Rosas 
trans_VNEG_F(DisasContext * s,arg_2misc * a)3293f0984d40SFabiano Rosas static bool trans_VNEG_F(DisasContext *s, arg_2misc *a)
3294f0984d40SFabiano Rosas {
3295f0984d40SFabiano Rosas     if (a->size == MO_16) {
3296f0984d40SFabiano Rosas         if (!dc_isar_feature(aa32_fp16_arith, s)) {
3297f0984d40SFabiano Rosas             return false;
3298f0984d40SFabiano Rosas         }
3299f0984d40SFabiano Rosas     } else if (a->size != MO_32) {
3300f0984d40SFabiano Rosas         return false;
3301f0984d40SFabiano Rosas     }
3302f0984d40SFabiano Rosas     return do_2misc_vec(s, a, gen_VNEG_F);
3303f0984d40SFabiano Rosas }
3304f0984d40SFabiano Rosas 
trans_VRECPE(DisasContext * s,arg_2misc * a)3305f0984d40SFabiano Rosas static bool trans_VRECPE(DisasContext *s, arg_2misc *a)
3306f0984d40SFabiano Rosas {
3307f0984d40SFabiano Rosas     if (a->size != 2) {
3308f0984d40SFabiano Rosas         return false;
3309f0984d40SFabiano Rosas     }
3310f0984d40SFabiano Rosas     return do_2misc(s, a, gen_helper_recpe_u32);
3311f0984d40SFabiano Rosas }
3312f0984d40SFabiano Rosas 
trans_VRSQRTE(DisasContext * s,arg_2misc * a)3313f0984d40SFabiano Rosas static bool trans_VRSQRTE(DisasContext *s, arg_2misc *a)
3314f0984d40SFabiano Rosas {
3315f0984d40SFabiano Rosas     if (a->size != 2) {
3316f0984d40SFabiano Rosas         return false;
3317f0984d40SFabiano Rosas     }
3318f0984d40SFabiano Rosas     return do_2misc(s, a, gen_helper_rsqrte_u32);
3319f0984d40SFabiano Rosas }
3320f0984d40SFabiano Rosas 
3321f0984d40SFabiano Rosas #define WRAP_1OP_ENV_FN(WRAPNAME, FUNC) \
3322f0984d40SFabiano Rosas     static void WRAPNAME(TCGv_i32 d, TCGv_i32 m)        \
3323f0984d40SFabiano Rosas     {                                                   \
3324ad75a51eSRichard Henderson         FUNC(d, tcg_env, m);                            \
3325f0984d40SFabiano Rosas     }
3326f0984d40SFabiano Rosas 
WRAP_1OP_ENV_FN(gen_VQABS_s8,gen_helper_neon_qabs_s8)3327f0984d40SFabiano Rosas WRAP_1OP_ENV_FN(gen_VQABS_s8, gen_helper_neon_qabs_s8)
3328f0984d40SFabiano Rosas WRAP_1OP_ENV_FN(gen_VQABS_s16, gen_helper_neon_qabs_s16)
3329f0984d40SFabiano Rosas WRAP_1OP_ENV_FN(gen_VQABS_s32, gen_helper_neon_qabs_s32)
3330f0984d40SFabiano Rosas WRAP_1OP_ENV_FN(gen_VQNEG_s8, gen_helper_neon_qneg_s8)
3331f0984d40SFabiano Rosas WRAP_1OP_ENV_FN(gen_VQNEG_s16, gen_helper_neon_qneg_s16)
3332f0984d40SFabiano Rosas WRAP_1OP_ENV_FN(gen_VQNEG_s32, gen_helper_neon_qneg_s32)
3333f0984d40SFabiano Rosas 
3334f0984d40SFabiano Rosas static bool trans_VQABS(DisasContext *s, arg_2misc *a)
3335f0984d40SFabiano Rosas {
3336f0984d40SFabiano Rosas     static NeonGenOneOpFn * const fn[] = {
3337f0984d40SFabiano Rosas         gen_VQABS_s8,
3338f0984d40SFabiano Rosas         gen_VQABS_s16,
3339f0984d40SFabiano Rosas         gen_VQABS_s32,
3340f0984d40SFabiano Rosas         NULL,
3341f0984d40SFabiano Rosas     };
3342f0984d40SFabiano Rosas     return do_2misc(s, a, fn[a->size]);
3343f0984d40SFabiano Rosas }
3344f0984d40SFabiano Rosas 
trans_VQNEG(DisasContext * s,arg_2misc * a)3345f0984d40SFabiano Rosas static bool trans_VQNEG(DisasContext *s, arg_2misc *a)
3346f0984d40SFabiano Rosas {
3347f0984d40SFabiano Rosas     static NeonGenOneOpFn * const fn[] = {
3348f0984d40SFabiano Rosas         gen_VQNEG_s8,
3349f0984d40SFabiano Rosas         gen_VQNEG_s16,
3350f0984d40SFabiano Rosas         gen_VQNEG_s32,
3351f0984d40SFabiano Rosas         NULL,
3352f0984d40SFabiano Rosas     };
3353f0984d40SFabiano Rosas     return do_2misc(s, a, fn[a->size]);
3354f0984d40SFabiano Rosas }
3355f0984d40SFabiano Rosas 
3356f0984d40SFabiano Rosas #define DO_2MISC_FP_VEC(INSN, HFUNC, SFUNC)                             \
3357f0984d40SFabiano Rosas     static void gen_##INSN(unsigned vece, uint32_t rd_ofs,              \
3358f0984d40SFabiano Rosas                            uint32_t rm_ofs,                             \
3359f0984d40SFabiano Rosas                            uint32_t oprsz, uint32_t maxsz)              \
3360f0984d40SFabiano Rosas     {                                                                   \
3361f0984d40SFabiano Rosas         static gen_helper_gvec_2_ptr * const fns[4] = {                 \
3362f0984d40SFabiano Rosas             NULL, HFUNC, SFUNC, NULL,                                   \
3363f0984d40SFabiano Rosas         };                                                              \
3364f0984d40SFabiano Rosas         TCGv_ptr fpst;                                                  \
3365f0984d40SFabiano Rosas         fpst = fpstatus_ptr(vece == MO_16 ? FPST_STD_F16 : FPST_STD);   \
3366f0984d40SFabiano Rosas         tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz, 0,       \
3367f0984d40SFabiano Rosas                            fns[vece]);                                  \
3368f0984d40SFabiano Rosas     }                                                                   \
3369f0984d40SFabiano Rosas     static bool trans_##INSN(DisasContext *s, arg_2misc *a)             \
3370f0984d40SFabiano Rosas     {                                                                   \
3371f0984d40SFabiano Rosas         if (a->size == MO_16) {                                         \
3372f0984d40SFabiano Rosas             if (!dc_isar_feature(aa32_fp16_arith, s)) {                 \
3373f0984d40SFabiano Rosas                 return false;                                           \
3374f0984d40SFabiano Rosas             }                                                           \
3375f0984d40SFabiano Rosas         } else if (a->size != MO_32) {                                  \
3376f0984d40SFabiano Rosas             return false;                                               \
3377f0984d40SFabiano Rosas         }                                                               \
3378f0984d40SFabiano Rosas         return do_2misc_vec(s, a, gen_##INSN);                          \
3379f0984d40SFabiano Rosas     }
3380f0984d40SFabiano Rosas 
DO_2MISC_FP_VEC(VRECPE_F,gen_helper_gvec_frecpe_h,gen_helper_gvec_frecpe_s)3381f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VRECPE_F, gen_helper_gvec_frecpe_h, gen_helper_gvec_frecpe_s)
3382f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VRSQRTE_F, gen_helper_gvec_frsqrte_h, gen_helper_gvec_frsqrte_s)
3383f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCGT0_F, gen_helper_gvec_fcgt0_h, gen_helper_gvec_fcgt0_s)
3384f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCGE0_F, gen_helper_gvec_fcge0_h, gen_helper_gvec_fcge0_s)
3385f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCEQ0_F, gen_helper_gvec_fceq0_h, gen_helper_gvec_fceq0_s)
3386f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCLT0_F, gen_helper_gvec_fclt0_h, gen_helper_gvec_fclt0_s)
3387f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCLE0_F, gen_helper_gvec_fcle0_h, gen_helper_gvec_fcle0_s)
3388f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCVT_FS, gen_helper_gvec_sstoh, gen_helper_gvec_sitos)
3389f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCVT_FU, gen_helper_gvec_ustoh, gen_helper_gvec_uitos)
3390f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCVT_SF, gen_helper_gvec_tosszh, gen_helper_gvec_tosizs)
3391f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VCVT_UF, gen_helper_gvec_touszh, gen_helper_gvec_touizs)
3392f0984d40SFabiano Rosas 
3393f0984d40SFabiano Rosas DO_2MISC_FP_VEC(VRINTX_impl, gen_helper_gvec_vrintx_h, gen_helper_gvec_vrintx_s)
3394f0984d40SFabiano Rosas 
3395f0984d40SFabiano Rosas static bool trans_VRINTX(DisasContext *s, arg_2misc *a)
3396f0984d40SFabiano Rosas {
3397f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_V8)) {
3398f0984d40SFabiano Rosas         return false;
3399f0984d40SFabiano Rosas     }
3400f0984d40SFabiano Rosas     return trans_VRINTX_impl(s, a);
3401f0984d40SFabiano Rosas }
3402f0984d40SFabiano Rosas 
3403f0984d40SFabiano Rosas #define DO_VEC_RMODE(INSN, RMODE, OP)                                   \
3404f0984d40SFabiano Rosas     static void gen_##INSN(unsigned vece, uint32_t rd_ofs,              \
3405f0984d40SFabiano Rosas                            uint32_t rm_ofs,                             \
3406f0984d40SFabiano Rosas                            uint32_t oprsz, uint32_t maxsz)              \
3407f0984d40SFabiano Rosas     {                                                                   \
3408f0984d40SFabiano Rosas         static gen_helper_gvec_2_ptr * const fns[4] = {                 \
3409f0984d40SFabiano Rosas             NULL,                                                       \
3410f0984d40SFabiano Rosas             gen_helper_gvec_##OP##h,                                    \
3411f0984d40SFabiano Rosas             gen_helper_gvec_##OP##s,                                    \
3412f0984d40SFabiano Rosas             NULL,                                                       \
3413f0984d40SFabiano Rosas         };                                                              \
3414f0984d40SFabiano Rosas         TCGv_ptr fpst;                                                  \
3415f0984d40SFabiano Rosas         fpst = fpstatus_ptr(vece == 1 ? FPST_STD_F16 : FPST_STD);       \
3416f0984d40SFabiano Rosas         tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz,          \
3417f0984d40SFabiano Rosas                            arm_rmode_to_sf(RMODE), fns[vece]);          \
3418f0984d40SFabiano Rosas     }                                                                   \
3419f0984d40SFabiano Rosas     static bool trans_##INSN(DisasContext *s, arg_2misc *a)             \
3420f0984d40SFabiano Rosas     {                                                                   \
3421f0984d40SFabiano Rosas         if (!arm_dc_feature(s, ARM_FEATURE_V8)) {                       \
3422f0984d40SFabiano Rosas             return false;                                               \
3423f0984d40SFabiano Rosas         }                                                               \
3424f0984d40SFabiano Rosas         if (a->size == MO_16) {                                         \
3425f0984d40SFabiano Rosas             if (!dc_isar_feature(aa32_fp16_arith, s)) {                 \
3426f0984d40SFabiano Rosas                 return false;                                           \
3427f0984d40SFabiano Rosas             }                                                           \
3428f0984d40SFabiano Rosas         } else if (a->size != MO_32) {                                  \
3429f0984d40SFabiano Rosas             return false;                                               \
3430f0984d40SFabiano Rosas         }                                                               \
3431f0984d40SFabiano Rosas         return do_2misc_vec(s, a, gen_##INSN);                          \
3432f0984d40SFabiano Rosas     }
3433f0984d40SFabiano Rosas 
DO_VEC_RMODE(VCVTAU,FPROUNDING_TIEAWAY,vcvt_rm_u)3434f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTAU, FPROUNDING_TIEAWAY, vcvt_rm_u)
3435f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTAS, FPROUNDING_TIEAWAY, vcvt_rm_s)
3436f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTNU, FPROUNDING_TIEEVEN, vcvt_rm_u)
3437f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTNS, FPROUNDING_TIEEVEN, vcvt_rm_s)
3438f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTPU, FPROUNDING_POSINF, vcvt_rm_u)
3439f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTPS, FPROUNDING_POSINF, vcvt_rm_s)
3440f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTMU, FPROUNDING_NEGINF, vcvt_rm_u)
3441f0984d40SFabiano Rosas DO_VEC_RMODE(VCVTMS, FPROUNDING_NEGINF, vcvt_rm_s)
3442f0984d40SFabiano Rosas 
3443f0984d40SFabiano Rosas DO_VEC_RMODE(VRINTN, FPROUNDING_TIEEVEN, vrint_rm_)
3444f0984d40SFabiano Rosas DO_VEC_RMODE(VRINTA, FPROUNDING_TIEAWAY, vrint_rm_)
3445f0984d40SFabiano Rosas DO_VEC_RMODE(VRINTZ, FPROUNDING_ZERO, vrint_rm_)
3446f0984d40SFabiano Rosas DO_VEC_RMODE(VRINTM, FPROUNDING_NEGINF, vrint_rm_)
3447f0984d40SFabiano Rosas DO_VEC_RMODE(VRINTP, FPROUNDING_POSINF, vrint_rm_)
3448f0984d40SFabiano Rosas 
3449f0984d40SFabiano Rosas static bool trans_VSWP(DisasContext *s, arg_2misc *a)
3450f0984d40SFabiano Rosas {
3451f0984d40SFabiano Rosas     TCGv_i64 rm, rd;
3452f0984d40SFabiano Rosas     int pass;
3453f0984d40SFabiano Rosas 
3454f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
3455f0984d40SFabiano Rosas         return false;
3456f0984d40SFabiano Rosas     }
3457f0984d40SFabiano Rosas 
3458f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
3459f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
3460f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
3461f0984d40SFabiano Rosas         return false;
3462f0984d40SFabiano Rosas     }
3463f0984d40SFabiano Rosas 
3464f0984d40SFabiano Rosas     if (a->size != 0) {
3465f0984d40SFabiano Rosas         return false;
3466f0984d40SFabiano Rosas     }
3467f0984d40SFabiano Rosas 
3468f0984d40SFabiano Rosas     if ((a->vd | a->vm) & a->q) {
3469f0984d40SFabiano Rosas         return false;
3470f0984d40SFabiano Rosas     }
3471f0984d40SFabiano Rosas 
3472f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
3473f0984d40SFabiano Rosas         return true;
3474f0984d40SFabiano Rosas     }
3475f0984d40SFabiano Rosas 
3476f0984d40SFabiano Rosas     rm = tcg_temp_new_i64();
3477f0984d40SFabiano Rosas     rd = tcg_temp_new_i64();
3478f0984d40SFabiano Rosas     for (pass = 0; pass < (a->q ? 2 : 1); pass++) {
3479f0984d40SFabiano Rosas         read_neon_element64(rm, a->vm, pass, MO_64);
3480f0984d40SFabiano Rosas         read_neon_element64(rd, a->vd, pass, MO_64);
3481f0984d40SFabiano Rosas         write_neon_element64(rm, a->vd, pass, MO_64);
3482f0984d40SFabiano Rosas         write_neon_element64(rd, a->vm, pass, MO_64);
3483f0984d40SFabiano Rosas     }
3484f0984d40SFabiano Rosas     return true;
3485f0984d40SFabiano Rosas }
348624f4531dSRichard Henderson 
gen_neon_trn_u8(TCGv_i32 t0,TCGv_i32 t1)3487f0984d40SFabiano Rosas static void gen_neon_trn_u8(TCGv_i32 t0, TCGv_i32 t1)
3488f0984d40SFabiano Rosas {
3489f0984d40SFabiano Rosas     TCGv_i32 rd, tmp;
3490f0984d40SFabiano Rosas 
3491f0984d40SFabiano Rosas     rd = tcg_temp_new_i32();
3492f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
3493f0984d40SFabiano Rosas 
3494f0984d40SFabiano Rosas     tcg_gen_shli_i32(rd, t0, 8);
3495f0984d40SFabiano Rosas     tcg_gen_andi_i32(rd, rd, 0xff00ff00);
3496f0984d40SFabiano Rosas     tcg_gen_andi_i32(tmp, t1, 0x00ff00ff);
3497f0984d40SFabiano Rosas     tcg_gen_or_i32(rd, rd, tmp);
3498f0984d40SFabiano Rosas 
3499f0984d40SFabiano Rosas     tcg_gen_shri_i32(t1, t1, 8);
3500f0984d40SFabiano Rosas     tcg_gen_andi_i32(t1, t1, 0x00ff00ff);
3501f0984d40SFabiano Rosas     tcg_gen_andi_i32(tmp, t0, 0xff00ff00);
3502f0984d40SFabiano Rosas     tcg_gen_or_i32(t1, t1, tmp);
3503f0984d40SFabiano Rosas     tcg_gen_mov_i32(t0, rd);
3504f0984d40SFabiano Rosas }
3505f0984d40SFabiano Rosas 
gen_neon_trn_u16(TCGv_i32 t0,TCGv_i32 t1)3506f0984d40SFabiano Rosas static void gen_neon_trn_u16(TCGv_i32 t0, TCGv_i32 t1)
3507f0984d40SFabiano Rosas {
3508f0984d40SFabiano Rosas     TCGv_i32 rd, tmp;
3509f0984d40SFabiano Rosas 
3510f0984d40SFabiano Rosas     rd = tcg_temp_new_i32();
3511f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
3512f0984d40SFabiano Rosas 
3513f0984d40SFabiano Rosas     tcg_gen_shli_i32(rd, t0, 16);
3514f0984d40SFabiano Rosas     tcg_gen_andi_i32(tmp, t1, 0xffff);
3515f0984d40SFabiano Rosas     tcg_gen_or_i32(rd, rd, tmp);
3516f0984d40SFabiano Rosas     tcg_gen_shri_i32(t1, t1, 16);
3517f0984d40SFabiano Rosas     tcg_gen_andi_i32(tmp, t0, 0xffff0000);
3518f0984d40SFabiano Rosas     tcg_gen_or_i32(t1, t1, tmp);
3519f0984d40SFabiano Rosas     tcg_gen_mov_i32(t0, rd);
3520f0984d40SFabiano Rosas }
3521f0984d40SFabiano Rosas 
trans_VTRN(DisasContext * s,arg_2misc * a)3522f0984d40SFabiano Rosas static bool trans_VTRN(DisasContext *s, arg_2misc *a)
3523f0984d40SFabiano Rosas {
3524f0984d40SFabiano Rosas     TCGv_i32 tmp, tmp2;
3525f0984d40SFabiano Rosas     int pass;
3526f0984d40SFabiano Rosas 
3527f0984d40SFabiano Rosas     if (!arm_dc_feature(s, ARM_FEATURE_NEON)) {
3528f0984d40SFabiano Rosas         return false;
3529f0984d40SFabiano Rosas     }
3530f0984d40SFabiano Rosas 
3531f0984d40SFabiano Rosas     /* UNDEF accesses to D16-D31 if they don't exist. */
3532f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_simd_r32, s) &&
3533f0984d40SFabiano Rosas         ((a->vd | a->vm) & 0x10)) {
3534f0984d40SFabiano Rosas         return false;
3535f0984d40SFabiano Rosas     }
3536f0984d40SFabiano Rosas 
3537f0984d40SFabiano Rosas     if ((a->vd | a->vm) & a->q) {
3538f0984d40SFabiano Rosas         return false;
3539f0984d40SFabiano Rosas     }
3540f0984d40SFabiano Rosas 
3541f0984d40SFabiano Rosas     if (a->size == 3) {
3542f0984d40SFabiano Rosas         return false;
3543f0984d40SFabiano Rosas     }
3544f0984d40SFabiano Rosas 
3545f0984d40SFabiano Rosas     if (!vfp_access_check(s)) {
3546f0984d40SFabiano Rosas         return true;
3547f0984d40SFabiano Rosas     }
3548f0984d40SFabiano Rosas 
3549f0984d40SFabiano Rosas     tmp = tcg_temp_new_i32();
3550f0984d40SFabiano Rosas     tmp2 = tcg_temp_new_i32();
3551f0984d40SFabiano Rosas     if (a->size == MO_32) {
3552f0984d40SFabiano Rosas         for (pass = 0; pass < (a->q ? 4 : 2); pass += 2) {
3553f0984d40SFabiano Rosas             read_neon_element32(tmp, a->vm, pass, MO_32);
3554f0984d40SFabiano Rosas             read_neon_element32(tmp2, a->vd, pass + 1, MO_32);
3555f0984d40SFabiano Rosas             write_neon_element32(tmp2, a->vm, pass, MO_32);
3556f0984d40SFabiano Rosas             write_neon_element32(tmp, a->vd, pass + 1, MO_32);
3557f0984d40SFabiano Rosas         }
3558f0984d40SFabiano Rosas     } else {
3559f0984d40SFabiano Rosas         for (pass = 0; pass < (a->q ? 4 : 2); pass++) {
3560f0984d40SFabiano Rosas             read_neon_element32(tmp, a->vm, pass, MO_32);
3561f0984d40SFabiano Rosas             read_neon_element32(tmp2, a->vd, pass, MO_32);
3562f0984d40SFabiano Rosas             if (a->size == MO_8) {
3563f0984d40SFabiano Rosas                 gen_neon_trn_u8(tmp, tmp2);
3564f0984d40SFabiano Rosas             } else {
3565f0984d40SFabiano Rosas                 gen_neon_trn_u16(tmp, tmp2);
3566f0984d40SFabiano Rosas             }
3567f0984d40SFabiano Rosas             write_neon_element32(tmp2, a->vm, pass, MO_32);
3568f0984d40SFabiano Rosas             write_neon_element32(tmp, a->vd, pass, MO_32);
3569f0984d40SFabiano Rosas         }
3570f0984d40SFabiano Rosas     }
3571f0984d40SFabiano Rosas     return true;
3572f0984d40SFabiano Rosas }
3573f0984d40SFabiano Rosas 
trans_VSMMLA(DisasContext * s,arg_VSMMLA * a)3574f0984d40SFabiano Rosas static bool trans_VSMMLA(DisasContext *s, arg_VSMMLA *a)
3575f0984d40SFabiano Rosas {
3576f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_i8mm, s)) {
3577f0984d40SFabiano Rosas         return false;
3578f0984d40SFabiano Rosas     }
3579f0984d40SFabiano Rosas     return do_neon_ddda(s, 7, a->vd, a->vn, a->vm, 0,
3580f0984d40SFabiano Rosas                         gen_helper_gvec_smmla_b);
3581f0984d40SFabiano Rosas }
3582f0984d40SFabiano Rosas 
trans_VUMMLA(DisasContext * s,arg_VUMMLA * a)3583f0984d40SFabiano Rosas static bool trans_VUMMLA(DisasContext *s, arg_VUMMLA *a)
3584f0984d40SFabiano Rosas {
3585f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_i8mm, s)) {
3586f0984d40SFabiano Rosas         return false;
3587f0984d40SFabiano Rosas     }
3588f0984d40SFabiano Rosas     return do_neon_ddda(s, 7, a->vd, a->vn, a->vm, 0,
3589f0984d40SFabiano Rosas                         gen_helper_gvec_ummla_b);
3590f0984d40SFabiano Rosas }
3591f0984d40SFabiano Rosas 
trans_VUSMMLA(DisasContext * s,arg_VUSMMLA * a)3592f0984d40SFabiano Rosas static bool trans_VUSMMLA(DisasContext *s, arg_VUSMMLA *a)
3593f0984d40SFabiano Rosas {
3594f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_i8mm, s)) {
3595f0984d40SFabiano Rosas         return false;
3596f0984d40SFabiano Rosas     }
3597f0984d40SFabiano Rosas     return do_neon_ddda(s, 7, a->vd, a->vn, a->vm, 0,
3598f0984d40SFabiano Rosas                         gen_helper_gvec_usmmla_b);
3599f0984d40SFabiano Rosas }
3600f0984d40SFabiano Rosas 
trans_VMMLA_b16(DisasContext * s,arg_VMMLA_b16 * a)3601f0984d40SFabiano Rosas static bool trans_VMMLA_b16(DisasContext *s, arg_VMMLA_b16 *a)
3602f0984d40SFabiano Rosas {
3603f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_bf16, s)) {
3604f0984d40SFabiano Rosas         return false;
3605f0984d40SFabiano Rosas     }
36062da2d7dcSPeter Maydell     return do_neon_ddda_env(s, 7, a->vd, a->vn, a->vm, 0,
3607f0984d40SFabiano Rosas                             gen_helper_gvec_bfmmla);
3608f0984d40SFabiano Rosas }
3609f0984d40SFabiano Rosas 
trans_VFMA_b16(DisasContext * s,arg_VFMA_b16 * a)3610f0984d40SFabiano Rosas static bool trans_VFMA_b16(DisasContext *s, arg_VFMA_b16 *a)
3611f0984d40SFabiano Rosas {
3612f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_bf16, s)) {
3613f0984d40SFabiano Rosas         return false;
3614f0984d40SFabiano Rosas     }
3615f0984d40SFabiano Rosas     return do_neon_ddda_fpst(s, 7, a->vd, a->vn, a->vm, a->q, FPST_STD,
3616f0984d40SFabiano Rosas                              gen_helper_gvec_bfmlal);
3617f0984d40SFabiano Rosas }
3618f0984d40SFabiano Rosas 
trans_VFMA_b16_scal(DisasContext * s,arg_VFMA_b16_scal * a)3619f0984d40SFabiano Rosas static bool trans_VFMA_b16_scal(DisasContext *s, arg_VFMA_b16_scal *a)
3620f0984d40SFabiano Rosas {
3621f0984d40SFabiano Rosas     if (!dc_isar_feature(aa32_bf16, s)) {
3622f0984d40SFabiano Rosas         return false;
3623f0984d40SFabiano Rosas     }
3624f0984d40SFabiano Rosas     return do_neon_ddda_fpst(s, 6, a->vd, a->vn, a->vm,
3625f0984d40SFabiano Rosas                              (a->index << 1) | a->q, FPST_STD,
3626f0984d40SFabiano Rosas                              gen_helper_gvec_bfmlal_idx);
3627f0984d40SFabiano Rosas }
3628