blob: 78ee1ced80fdf3f1f8759072945bb26d80cc3852 [file] [log] [blame]
Richard Hendersondb432672017-09-15 14:11:45 -07001/*
2 * Generic vector operation expansion
3 *
4 * Copyright (c) 2018 Linaro
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
Thomas Huthfb0343d2019-01-23 15:08:56 +01009 * version 2.1 of the License, or (at your option) any later version.
Richard Hendersondb432672017-09-15 14:11:45 -070010 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "qemu/osdep.h"
Philippe Mathieu-Daudédcb32f12020-01-01 12:23:00 +010021#include "tcg/tcg.h"
Richard Henderson47f73132023-02-24 22:45:43 -100022#include "tcg/tcg-temp-internal.h"
Richard Hendersonad3d0e42023-03-28 18:17:24 -070023#include "tcg/tcg-op-common.h"
Richard Henderson447ca1c2023-04-01 10:15:11 -070024#include "tcg/tcg-op-gvec-common.h"
Philippe Mathieu-Daudédcb32f12020-01-01 12:23:00 +010025#include "tcg/tcg-gvec-desc.h"
Richard Hendersondb432672017-09-15 14:11:45 -070026
27#define MAX_UNROLL 4
28
Richard Henderson53229a72019-03-17 00:27:29 +000029#ifdef CONFIG_DEBUG_TCG
30static const TCGOpcode vecop_list_empty[1] = { 0 };
31#else
32#define vecop_list_empty NULL
33#endif
34
35
Richard Hendersondb432672017-09-15 14:11:45 -070036/* Verify vector size and alignment rules. OFS should be the OR of all
37 of the operand offsets so that we can check them all at once. */
38static void check_size_align(uint32_t oprsz, uint32_t maxsz, uint32_t ofs)
39{
Richard Hendersone2e71682020-08-30 08:57:20 -070040 uint32_t max_align;
41
42 switch (oprsz) {
43 case 8:
44 case 16:
45 case 32:
46 tcg_debug_assert(oprsz <= maxsz);
47 break;
48 default:
49 tcg_debug_assert(oprsz == maxsz);
50 break;
51 }
52 tcg_debug_assert(maxsz <= (8 << SIMD_MAXSZ_BITS));
53
54 max_align = maxsz >= 16 ? 15 : 7;
Richard Hendersondb432672017-09-15 14:11:45 -070055 tcg_debug_assert((maxsz & max_align) == 0);
56 tcg_debug_assert((ofs & max_align) == 0);
57}
58
59/* Verify vector overlap rules for two operands. */
60static void check_overlap_2(uint32_t d, uint32_t a, uint32_t s)
61{
62 tcg_debug_assert(d == a || d + s <= a || a + s <= d);
63}
64
65/* Verify vector overlap rules for three operands. */
66static void check_overlap_3(uint32_t d, uint32_t a, uint32_t b, uint32_t s)
67{
68 check_overlap_2(d, a, s);
69 check_overlap_2(d, b, s);
70 check_overlap_2(a, b, s);
71}
72
73/* Verify vector overlap rules for four operands. */
74static void check_overlap_4(uint32_t d, uint32_t a, uint32_t b,
75 uint32_t c, uint32_t s)
76{
77 check_overlap_2(d, a, s);
78 check_overlap_2(d, b, s);
79 check_overlap_2(d, c, s);
80 check_overlap_2(a, b, s);
81 check_overlap_2(a, c, s);
82 check_overlap_2(b, c, s);
83}
84
85/* Create a descriptor from components. */
86uint32_t simd_desc(uint32_t oprsz, uint32_t maxsz, int32_t data)
87{
88 uint32_t desc = 0;
89
Richard Hendersone2e71682020-08-30 08:57:20 -070090 check_size_align(oprsz, maxsz, 0);
91 tcg_debug_assert(data == sextract32(data, 0, SIMD_DATA_BITS));
Richard Hendersondb432672017-09-15 14:11:45 -070092
93 oprsz = (oprsz / 8) - 1;
94 maxsz = (maxsz / 8) - 1;
Richard Hendersone2e71682020-08-30 08:57:20 -070095
96 /*
97 * We have just asserted in check_size_align that either
98 * oprsz is {8,16,32} or matches maxsz. Encode the final
99 * case with '2', as that would otherwise map to 24.
100 */
101 if (oprsz == maxsz) {
102 oprsz = 2;
103 }
104
Richard Hendersondb432672017-09-15 14:11:45 -0700105 desc = deposit32(desc, SIMD_OPRSZ_SHIFT, SIMD_OPRSZ_BITS, oprsz);
106 desc = deposit32(desc, SIMD_MAXSZ_SHIFT, SIMD_MAXSZ_BITS, maxsz);
107 desc = deposit32(desc, SIMD_DATA_SHIFT, SIMD_DATA_BITS, data);
108
109 return desc;
110}
111
112/* Generate a call to a gvec-style helper with two vector operands. */
113void tcg_gen_gvec_2_ool(uint32_t dofs, uint32_t aofs,
114 uint32_t oprsz, uint32_t maxsz, int32_t data,
115 gen_helper_gvec_2 *fn)
116{
117 TCGv_ptr a0, a1;
Richard Henderson88d40052020-09-03 18:18:08 -0700118 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Hendersondb432672017-09-15 14:11:45 -0700119
Richard Henderson5dd48602023-01-29 13:26:49 -1000120 a0 = tcg_temp_ebb_new_ptr();
121 a1 = tcg_temp_ebb_new_ptr();
Richard Hendersondb432672017-09-15 14:11:45 -0700122
Richard Hendersonad75a512023-09-13 16:37:36 -0700123 tcg_gen_addi_ptr(a0, tcg_env, dofs);
124 tcg_gen_addi_ptr(a1, tcg_env, aofs);
Richard Hendersondb432672017-09-15 14:11:45 -0700125
126 fn(a0, a1, desc);
127
128 tcg_temp_free_ptr(a0);
129 tcg_temp_free_ptr(a1);
Richard Hendersondb432672017-09-15 14:11:45 -0700130}
131
Richard Henderson22fc3522017-12-21 10:58:36 -0800132/* Generate a call to a gvec-style helper with two vector operands
133 and one scalar operand. */
134void tcg_gen_gvec_2i_ool(uint32_t dofs, uint32_t aofs, TCGv_i64 c,
135 uint32_t oprsz, uint32_t maxsz, int32_t data,
136 gen_helper_gvec_2i *fn)
137{
138 TCGv_ptr a0, a1;
Richard Henderson88d40052020-09-03 18:18:08 -0700139 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Henderson22fc3522017-12-21 10:58:36 -0800140
Richard Henderson5dd48602023-01-29 13:26:49 -1000141 a0 = tcg_temp_ebb_new_ptr();
142 a1 = tcg_temp_ebb_new_ptr();
Richard Henderson22fc3522017-12-21 10:58:36 -0800143
Richard Hendersonad75a512023-09-13 16:37:36 -0700144 tcg_gen_addi_ptr(a0, tcg_env, dofs);
145 tcg_gen_addi_ptr(a1, tcg_env, aofs);
Richard Henderson22fc3522017-12-21 10:58:36 -0800146
147 fn(a0, a1, c, desc);
148
149 tcg_temp_free_ptr(a0);
150 tcg_temp_free_ptr(a1);
Richard Henderson22fc3522017-12-21 10:58:36 -0800151}
152
Richard Hendersondb432672017-09-15 14:11:45 -0700153/* Generate a call to a gvec-style helper with three vector operands. */
154void tcg_gen_gvec_3_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
155 uint32_t oprsz, uint32_t maxsz, int32_t data,
156 gen_helper_gvec_3 *fn)
157{
158 TCGv_ptr a0, a1, a2;
Richard Henderson88d40052020-09-03 18:18:08 -0700159 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Hendersondb432672017-09-15 14:11:45 -0700160
Richard Henderson5dd48602023-01-29 13:26:49 -1000161 a0 = tcg_temp_ebb_new_ptr();
162 a1 = tcg_temp_ebb_new_ptr();
163 a2 = tcg_temp_ebb_new_ptr();
Richard Hendersondb432672017-09-15 14:11:45 -0700164
Richard Hendersonad75a512023-09-13 16:37:36 -0700165 tcg_gen_addi_ptr(a0, tcg_env, dofs);
166 tcg_gen_addi_ptr(a1, tcg_env, aofs);
167 tcg_gen_addi_ptr(a2, tcg_env, bofs);
Richard Hendersondb432672017-09-15 14:11:45 -0700168
169 fn(a0, a1, a2, desc);
170
171 tcg_temp_free_ptr(a0);
172 tcg_temp_free_ptr(a1);
173 tcg_temp_free_ptr(a2);
Richard Hendersondb432672017-09-15 14:11:45 -0700174}
175
176/* Generate a call to a gvec-style helper with four vector operands. */
177void tcg_gen_gvec_4_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
178 uint32_t cofs, uint32_t oprsz, uint32_t maxsz,
179 int32_t data, gen_helper_gvec_4 *fn)
180{
181 TCGv_ptr a0, a1, a2, a3;
Richard Henderson88d40052020-09-03 18:18:08 -0700182 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Hendersondb432672017-09-15 14:11:45 -0700183
Richard Henderson5dd48602023-01-29 13:26:49 -1000184 a0 = tcg_temp_ebb_new_ptr();
185 a1 = tcg_temp_ebb_new_ptr();
186 a2 = tcg_temp_ebb_new_ptr();
187 a3 = tcg_temp_ebb_new_ptr();
Richard Hendersondb432672017-09-15 14:11:45 -0700188
Richard Hendersonad75a512023-09-13 16:37:36 -0700189 tcg_gen_addi_ptr(a0, tcg_env, dofs);
190 tcg_gen_addi_ptr(a1, tcg_env, aofs);
191 tcg_gen_addi_ptr(a2, tcg_env, bofs);
192 tcg_gen_addi_ptr(a3, tcg_env, cofs);
Richard Hendersondb432672017-09-15 14:11:45 -0700193
194 fn(a0, a1, a2, a3, desc);
195
196 tcg_temp_free_ptr(a0);
197 tcg_temp_free_ptr(a1);
198 tcg_temp_free_ptr(a2);
199 tcg_temp_free_ptr(a3);
Richard Hendersondb432672017-09-15 14:11:45 -0700200}
201
202/* Generate a call to a gvec-style helper with five vector operands. */
203void tcg_gen_gvec_5_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
204 uint32_t cofs, uint32_t xofs, uint32_t oprsz,
205 uint32_t maxsz, int32_t data, gen_helper_gvec_5 *fn)
206{
207 TCGv_ptr a0, a1, a2, a3, a4;
Richard Henderson88d40052020-09-03 18:18:08 -0700208 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Hendersondb432672017-09-15 14:11:45 -0700209
Richard Henderson5dd48602023-01-29 13:26:49 -1000210 a0 = tcg_temp_ebb_new_ptr();
211 a1 = tcg_temp_ebb_new_ptr();
212 a2 = tcg_temp_ebb_new_ptr();
213 a3 = tcg_temp_ebb_new_ptr();
214 a4 = tcg_temp_ebb_new_ptr();
Richard Hendersondb432672017-09-15 14:11:45 -0700215
Richard Hendersonad75a512023-09-13 16:37:36 -0700216 tcg_gen_addi_ptr(a0, tcg_env, dofs);
217 tcg_gen_addi_ptr(a1, tcg_env, aofs);
218 tcg_gen_addi_ptr(a2, tcg_env, bofs);
219 tcg_gen_addi_ptr(a3, tcg_env, cofs);
220 tcg_gen_addi_ptr(a4, tcg_env, xofs);
Richard Hendersondb432672017-09-15 14:11:45 -0700221
222 fn(a0, a1, a2, a3, a4, desc);
223
224 tcg_temp_free_ptr(a0);
225 tcg_temp_free_ptr(a1);
226 tcg_temp_free_ptr(a2);
227 tcg_temp_free_ptr(a3);
228 tcg_temp_free_ptr(a4);
Richard Hendersondb432672017-09-15 14:11:45 -0700229}
230
231/* Generate a call to a gvec-style helper with three vector operands
232 and an extra pointer operand. */
233void tcg_gen_gvec_2_ptr(uint32_t dofs, uint32_t aofs,
234 TCGv_ptr ptr, uint32_t oprsz, uint32_t maxsz,
235 int32_t data, gen_helper_gvec_2_ptr *fn)
236{
237 TCGv_ptr a0, a1;
Richard Henderson88d40052020-09-03 18:18:08 -0700238 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Hendersondb432672017-09-15 14:11:45 -0700239
Richard Henderson5dd48602023-01-29 13:26:49 -1000240 a0 = tcg_temp_ebb_new_ptr();
241 a1 = tcg_temp_ebb_new_ptr();
Richard Hendersondb432672017-09-15 14:11:45 -0700242
Richard Hendersonad75a512023-09-13 16:37:36 -0700243 tcg_gen_addi_ptr(a0, tcg_env, dofs);
244 tcg_gen_addi_ptr(a1, tcg_env, aofs);
Richard Hendersondb432672017-09-15 14:11:45 -0700245
246 fn(a0, a1, ptr, desc);
247
248 tcg_temp_free_ptr(a0);
249 tcg_temp_free_ptr(a1);
Richard Hendersondb432672017-09-15 14:11:45 -0700250}
251
252/* Generate a call to a gvec-style helper with three vector operands
253 and an extra pointer operand. */
254void tcg_gen_gvec_3_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
255 TCGv_ptr ptr, uint32_t oprsz, uint32_t maxsz,
256 int32_t data, gen_helper_gvec_3_ptr *fn)
257{
258 TCGv_ptr a0, a1, a2;
Richard Henderson88d40052020-09-03 18:18:08 -0700259 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Hendersondb432672017-09-15 14:11:45 -0700260
Richard Henderson5dd48602023-01-29 13:26:49 -1000261 a0 = tcg_temp_ebb_new_ptr();
262 a1 = tcg_temp_ebb_new_ptr();
263 a2 = tcg_temp_ebb_new_ptr();
Richard Hendersondb432672017-09-15 14:11:45 -0700264
Richard Hendersonad75a512023-09-13 16:37:36 -0700265 tcg_gen_addi_ptr(a0, tcg_env, dofs);
266 tcg_gen_addi_ptr(a1, tcg_env, aofs);
267 tcg_gen_addi_ptr(a2, tcg_env, bofs);
Richard Hendersondb432672017-09-15 14:11:45 -0700268
269 fn(a0, a1, a2, ptr, desc);
270
271 tcg_temp_free_ptr(a0);
272 tcg_temp_free_ptr(a1);
273 tcg_temp_free_ptr(a2);
Richard Hendersondb432672017-09-15 14:11:45 -0700274}
275
276/* Generate a call to a gvec-style helper with four vector operands
277 and an extra pointer operand. */
278void tcg_gen_gvec_4_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
279 uint32_t cofs, TCGv_ptr ptr, uint32_t oprsz,
280 uint32_t maxsz, int32_t data,
281 gen_helper_gvec_4_ptr *fn)
282{
283 TCGv_ptr a0, a1, a2, a3;
Richard Henderson88d40052020-09-03 18:18:08 -0700284 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Hendersondb432672017-09-15 14:11:45 -0700285
Richard Henderson5dd48602023-01-29 13:26:49 -1000286 a0 = tcg_temp_ebb_new_ptr();
287 a1 = tcg_temp_ebb_new_ptr();
288 a2 = tcg_temp_ebb_new_ptr();
289 a3 = tcg_temp_ebb_new_ptr();
Richard Hendersondb432672017-09-15 14:11:45 -0700290
Richard Hendersonad75a512023-09-13 16:37:36 -0700291 tcg_gen_addi_ptr(a0, tcg_env, dofs);
292 tcg_gen_addi_ptr(a1, tcg_env, aofs);
293 tcg_gen_addi_ptr(a2, tcg_env, bofs);
294 tcg_gen_addi_ptr(a3, tcg_env, cofs);
Richard Hendersondb432672017-09-15 14:11:45 -0700295
296 fn(a0, a1, a2, a3, ptr, desc);
297
298 tcg_temp_free_ptr(a0);
299 tcg_temp_free_ptr(a1);
300 tcg_temp_free_ptr(a2);
301 tcg_temp_free_ptr(a3);
Richard Hendersondb432672017-09-15 14:11:45 -0700302}
303
Richard Henderson24459712020-02-11 16:31:38 -0800304/* Generate a call to a gvec-style helper with five vector operands
305 and an extra pointer operand. */
306void tcg_gen_gvec_5_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
307 uint32_t cofs, uint32_t eofs, TCGv_ptr ptr,
308 uint32_t oprsz, uint32_t maxsz, int32_t data,
309 gen_helper_gvec_5_ptr *fn)
310{
311 TCGv_ptr a0, a1, a2, a3, a4;
Richard Henderson88d40052020-09-03 18:18:08 -0700312 TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
Richard Henderson24459712020-02-11 16:31:38 -0800313
Richard Henderson5dd48602023-01-29 13:26:49 -1000314 a0 = tcg_temp_ebb_new_ptr();
315 a1 = tcg_temp_ebb_new_ptr();
316 a2 = tcg_temp_ebb_new_ptr();
317 a3 = tcg_temp_ebb_new_ptr();
318 a4 = tcg_temp_ebb_new_ptr();
Richard Henderson24459712020-02-11 16:31:38 -0800319
Richard Hendersonad75a512023-09-13 16:37:36 -0700320 tcg_gen_addi_ptr(a0, tcg_env, dofs);
321 tcg_gen_addi_ptr(a1, tcg_env, aofs);
322 tcg_gen_addi_ptr(a2, tcg_env, bofs);
323 tcg_gen_addi_ptr(a3, tcg_env, cofs);
324 tcg_gen_addi_ptr(a4, tcg_env, eofs);
Richard Henderson24459712020-02-11 16:31:38 -0800325
326 fn(a0, a1, a2, a3, a4, ptr, desc);
327
328 tcg_temp_free_ptr(a0);
329 tcg_temp_free_ptr(a1);
330 tcg_temp_free_ptr(a2);
331 tcg_temp_free_ptr(a3);
332 tcg_temp_free_ptr(a4);
Richard Henderson24459712020-02-11 16:31:38 -0800333}
334
Richard Hendersondb432672017-09-15 14:11:45 -0700335/* Return true if we want to implement something of OPRSZ bytes
336 in units of LNSZ. This limits the expansion of inline code. */
337static inline bool check_size_impl(uint32_t oprsz, uint32_t lnsz)
338{
Richard Hendersonf47db802020-03-28 19:47:07 -0700339 uint32_t q, r;
340
341 if (oprsz < lnsz) {
342 return false;
Richard Henderson499748d2018-07-09 14:51:34 +0100343 }
Richard Hendersonf47db802020-03-28 19:47:07 -0700344
345 q = oprsz / lnsz;
346 r = oprsz % lnsz;
347 tcg_debug_assert((r & 7) == 0);
348
349 if (lnsz < 16) {
350 /* For sizes below 16, accept no remainder. */
351 if (r != 0) {
352 return false;
353 }
354 } else {
355 /*
356 * Recall that ARM SVE allows vector sizes that are not a
357 * power of 2, but always a multiple of 16. The intent is
358 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
359 * In addition, expand_clr needs to handle a multiple of 8.
360 * Thus we can handle the tail with one more operation per
361 * diminishing power of 2.
362 */
363 q += ctpop32(r);
364 }
365
366 return q <= MAX_UNROLL;
Richard Hendersondb432672017-09-15 14:11:45 -0700367}
368
369static void expand_clr(uint32_t dofs, uint32_t maxsz);
370
371/* Duplicate C as per VECE. */
372uint64_t (dup_const)(unsigned vece, uint64_t c)
373{
374 switch (vece) {
375 case MO_8:
376 return 0x0101010101010101ull * (uint8_t)c;
377 case MO_16:
378 return 0x0001000100010001ull * (uint16_t)c;
379 case MO_32:
380 return 0x0000000100000001ull * (uint32_t)c;
381 case MO_64:
382 return c;
383 default:
384 g_assert_not_reached();
385 }
386}
387
388/* Duplicate IN into OUT as per VECE. */
Peter Maydell614dd4f2021-06-17 13:15:53 +0100389void tcg_gen_dup_i32(unsigned vece, TCGv_i32 out, TCGv_i32 in)
Richard Hendersondb432672017-09-15 14:11:45 -0700390{
391 switch (vece) {
392 case MO_8:
393 tcg_gen_ext8u_i32(out, in);
394 tcg_gen_muli_i32(out, out, 0x01010101);
395 break;
396 case MO_16:
397 tcg_gen_deposit_i32(out, in, in, 16, 16);
398 break;
399 case MO_32:
400 tcg_gen_mov_i32(out, in);
401 break;
402 default:
403 g_assert_not_reached();
404 }
405}
406
Peter Maydell614dd4f2021-06-17 13:15:53 +0100407void tcg_gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in)
Richard Hendersondb432672017-09-15 14:11:45 -0700408{
409 switch (vece) {
410 case MO_8:
411 tcg_gen_ext8u_i64(out, in);
412 tcg_gen_muli_i64(out, out, 0x0101010101010101ull);
413 break;
414 case MO_16:
415 tcg_gen_ext16u_i64(out, in);
416 tcg_gen_muli_i64(out, out, 0x0001000100010001ull);
417 break;
418 case MO_32:
419 tcg_gen_deposit_i64(out, in, in, 32, 32);
420 break;
421 case MO_64:
422 tcg_gen_mov_i64(out, in);
423 break;
424 default:
425 g_assert_not_reached();
426 }
427}
428
Richard Hendersonadb196c2018-02-17 08:30:16 -0800429/* Select a supported vector type for implementing an operation on SIZE
430 * bytes. If OP is 0, assume that the real operation to be performed is
431 * required by all backends. Otherwise, make sure than OP can be performed
432 * on elements of size VECE in the selected type. Do not select V64 if
433 * PREFER_I64 is true. Return 0 if no vector type is selected.
434 */
Richard Henderson53229a72019-03-17 00:27:29 +0000435static TCGType choose_vector_type(const TCGOpcode *list, unsigned vece,
436 uint32_t size, bool prefer_i64)
Richard Hendersonadb196c2018-02-17 08:30:16 -0800437{
Richard Hendersonf47db802020-03-28 19:47:07 -0700438 /*
439 * Recall that ARM SVE allows vector sizes that are not a
440 * power of 2, but always a multiple of 16. The intent is
441 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
442 * It is hard to imagine a case in which v256 is supported
443 * but v128 is not, but check anyway.
444 * In addition, expand_clr needs to handle a multiple of 8.
445 */
446 if (TCG_TARGET_HAS_v256 &&
447 check_size_impl(size, 32) &&
448 tcg_can_emit_vecop_list(list, TCG_TYPE_V256, vece) &&
449 (!(size & 16) ||
450 (TCG_TARGET_HAS_v128 &&
451 tcg_can_emit_vecop_list(list, TCG_TYPE_V128, vece))) &&
452 (!(size & 8) ||
453 (TCG_TARGET_HAS_v64 &&
454 tcg_can_emit_vecop_list(list, TCG_TYPE_V64, vece)))) {
455 return TCG_TYPE_V256;
Richard Hendersonadb196c2018-02-17 08:30:16 -0800456 }
Richard Hendersonf47db802020-03-28 19:47:07 -0700457 if (TCG_TARGET_HAS_v128 &&
458 check_size_impl(size, 16) &&
459 tcg_can_emit_vecop_list(list, TCG_TYPE_V128, vece) &&
460 (!(size & 8) ||
461 (TCG_TARGET_HAS_v64 &&
462 tcg_can_emit_vecop_list(list, TCG_TYPE_V64, vece)))) {
Richard Hendersonadb196c2018-02-17 08:30:16 -0800463 return TCG_TYPE_V128;
464 }
465 if (TCG_TARGET_HAS_v64 && !prefer_i64 && check_size_impl(size, 8)
Richard Henderson53229a72019-03-17 00:27:29 +0000466 && tcg_can_emit_vecop_list(list, TCG_TYPE_V64, vece)) {
Richard Hendersonadb196c2018-02-17 08:30:16 -0800467 return TCG_TYPE_V64;
468 }
469 return 0;
470}
471
Richard Henderson37ee55a2019-03-17 01:55:22 +0000472static void do_dup_store(TCGType type, uint32_t dofs, uint32_t oprsz,
473 uint32_t maxsz, TCGv_vec t_vec)
474{
475 uint32_t i = 0;
476
Richard Hendersonf47db802020-03-28 19:47:07 -0700477 tcg_debug_assert(oprsz >= 8);
478
479 /*
480 * This may be expand_clr for the tail of an operation, e.g.
481 * oprsz == 8 && maxsz == 64. The first 8 bytes of this store
482 * are misaligned wrt the maximum vector size, so do that first.
483 */
484 if (dofs & 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700485 tcg_gen_stl_vec(t_vec, tcg_env, dofs + i, TCG_TYPE_V64);
Richard Hendersonf47db802020-03-28 19:47:07 -0700486 i += 8;
487 }
488
Richard Henderson37ee55a2019-03-17 01:55:22 +0000489 switch (type) {
490 case TCG_TYPE_V256:
491 /*
492 * Recall that ARM SVE allows vector sizes that are not a
493 * power of 2, but always a multiple of 16. The intent is
494 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
495 */
496 for (; i + 32 <= oprsz; i += 32) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700497 tcg_gen_stl_vec(t_vec, tcg_env, dofs + i, TCG_TYPE_V256);
Richard Henderson37ee55a2019-03-17 01:55:22 +0000498 }
499 /* fallthru */
500 case TCG_TYPE_V128:
501 for (; i + 16 <= oprsz; i += 16) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700502 tcg_gen_stl_vec(t_vec, tcg_env, dofs + i, TCG_TYPE_V128);
Richard Henderson37ee55a2019-03-17 01:55:22 +0000503 }
504 break;
505 case TCG_TYPE_V64:
506 for (; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700507 tcg_gen_stl_vec(t_vec, tcg_env, dofs + i, TCG_TYPE_V64);
Richard Henderson37ee55a2019-03-17 01:55:22 +0000508 }
509 break;
510 default:
511 g_assert_not_reached();
512 }
513
514 if (oprsz < maxsz) {
515 expand_clr(dofs + oprsz, maxsz - oprsz);
516 }
517}
518
Richard Hendersondb432672017-09-15 14:11:45 -0700519/* Set OPRSZ bytes at DOFS to replications of IN_32, IN_64 or IN_C.
520 * Only one of IN_32 or IN_64 may be set;
521 * IN_C is used if IN_32 and IN_64 are unset.
522 */
523static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz,
524 uint32_t maxsz, TCGv_i32 in_32, TCGv_i64 in_64,
525 uint64_t in_c)
526{
527 TCGType type;
528 TCGv_i64 t_64;
529 TCGv_i32 t_32, t_desc;
530 TCGv_ptr t_ptr;
531 uint32_t i;
532
533 assert(vece <= (in_32 ? MO_32 : MO_64));
534 assert(in_32 == NULL || in_64 == NULL);
535
536 /* If we're storing 0, expand oprsz to maxsz. */
537 if (in_32 == NULL && in_64 == NULL) {
538 in_c = dup_const(vece, in_c);
539 if (in_c == 0) {
540 oprsz = maxsz;
Richard Henderson6d3ef042020-12-15 11:47:59 -0600541 vece = MO_8;
542 } else if (in_c == dup_const(MO_8, in_c)) {
543 vece = MO_8;
Richard Hendersondb432672017-09-15 14:11:45 -0700544 }
545 }
546
Richard Hendersonadb196c2018-02-17 08:30:16 -0800547 /* Implement inline with a vector type, if possible.
548 * Prefer integer when 64-bit host and no variable dup.
549 */
Richard Henderson53229a72019-03-17 00:27:29 +0000550 type = choose_vector_type(NULL, vece, oprsz,
Richard Hendersonadb196c2018-02-17 08:30:16 -0800551 (TCG_TARGET_REG_BITS == 64 && in_32 == NULL
552 && (in_64 == NULL || vece == MO_64)));
Richard Hendersondb432672017-09-15 14:11:45 -0700553 if (type != 0) {
554 TCGv_vec t_vec = tcg_temp_new_vec(type);
555
556 if (in_32) {
557 tcg_gen_dup_i32_vec(vece, t_vec, in_32);
558 } else if (in_64) {
559 tcg_gen_dup_i64_vec(vece, t_vec, in_64);
560 } else {
Richard Henderson37ee55a2019-03-17 01:55:22 +0000561 tcg_gen_dupi_vec(vece, t_vec, in_c);
Richard Hendersondb432672017-09-15 14:11:45 -0700562 }
Richard Henderson37ee55a2019-03-17 01:55:22 +0000563 do_dup_store(type, dofs, oprsz, maxsz, t_vec);
Richard Henderson37ee55a2019-03-17 01:55:22 +0000564 return;
Richard Hendersondb432672017-09-15 14:11:45 -0700565 }
566
567 /* Otherwise, inline with an integer type, unless "large". */
568 if (check_size_impl(oprsz, TCG_TARGET_REG_BITS / 8)) {
569 t_64 = NULL;
570 t_32 = NULL;
571
572 if (in_32) {
573 /* We are given a 32-bit variable input. For a 64-bit host,
574 use a 64-bit operation unless the 32-bit operation would
575 be simple enough. */
576 if (TCG_TARGET_REG_BITS == 64
577 && (vece != MO_32 || !check_size_impl(oprsz, 4))) {
Richard Henderson5dd48602023-01-29 13:26:49 -1000578 t_64 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -0700579 tcg_gen_extu_i32_i64(t_64, in_32);
Peter Maydell614dd4f2021-06-17 13:15:53 +0100580 tcg_gen_dup_i64(vece, t_64, t_64);
Richard Hendersondb432672017-09-15 14:11:45 -0700581 } else {
Richard Henderson5dd48602023-01-29 13:26:49 -1000582 t_32 = tcg_temp_ebb_new_i32();
Peter Maydell614dd4f2021-06-17 13:15:53 +0100583 tcg_gen_dup_i32(vece, t_32, in_32);
Richard Hendersondb432672017-09-15 14:11:45 -0700584 }
585 } else if (in_64) {
586 /* We are given a 64-bit variable input. */
Richard Henderson5dd48602023-01-29 13:26:49 -1000587 t_64 = tcg_temp_ebb_new_i64();
Peter Maydell614dd4f2021-06-17 13:15:53 +0100588 tcg_gen_dup_i64(vece, t_64, in_64);
Richard Hendersondb432672017-09-15 14:11:45 -0700589 } else {
590 /* We are given a constant input. */
591 /* For 64-bit hosts, use 64-bit constants for "simple" constants
592 or when we'd need too many 32-bit stores, or when a 64-bit
593 constant is really required. */
594 if (vece == MO_64
595 || (TCG_TARGET_REG_BITS == 64
596 && (in_c == 0 || in_c == -1
597 || !check_size_impl(oprsz, 4)))) {
Richard Henderson88d40052020-09-03 18:18:08 -0700598 t_64 = tcg_constant_i64(in_c);
Richard Hendersondb432672017-09-15 14:11:45 -0700599 } else {
Richard Henderson88d40052020-09-03 18:18:08 -0700600 t_32 = tcg_constant_i32(in_c);
Richard Hendersondb432672017-09-15 14:11:45 -0700601 }
602 }
603
604 /* Implement inline if we picked an implementation size above. */
605 if (t_32) {
606 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700607 tcg_gen_st_i32(t_32, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700608 }
609 tcg_temp_free_i32(t_32);
610 goto done;
611 }
612 if (t_64) {
613 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700614 tcg_gen_st_i64(t_64, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700615 }
616 tcg_temp_free_i64(t_64);
617 goto done;
Richard Hendersonadb196c2018-02-17 08:30:16 -0800618 }
Richard Hendersondb432672017-09-15 14:11:45 -0700619 }
620
621 /* Otherwise implement out of line. */
Richard Henderson5dd48602023-01-29 13:26:49 -1000622 t_ptr = tcg_temp_ebb_new_ptr();
Richard Hendersonad75a512023-09-13 16:37:36 -0700623 tcg_gen_addi_ptr(t_ptr, tcg_env, dofs);
Richard Henderson6d3ef042020-12-15 11:47:59 -0600624
625 /*
626 * This may be expand_clr for the tail of an operation, e.g.
627 * oprsz == 8 && maxsz == 64. The size of the clear is misaligned
628 * wrt simd_desc and will assert. Simply pass all replicated byte
629 * stores through to memset.
630 */
631 if (oprsz == maxsz && vece == MO_8) {
Richard Hendersone1986412023-02-24 15:35:45 -1000632 TCGv_ptr t_size = tcg_constant_ptr(oprsz);
Richard Henderson6d3ef042020-12-15 11:47:59 -0600633 TCGv_i32 t_val;
634
635 if (in_32) {
636 t_val = in_32;
637 } else if (in_64) {
Richard Henderson5dd48602023-01-29 13:26:49 -1000638 t_val = tcg_temp_ebb_new_i32();
Richard Henderson6d3ef042020-12-15 11:47:59 -0600639 tcg_gen_extrl_i64_i32(t_val, in_64);
640 } else {
Richard Henderson88d40052020-09-03 18:18:08 -0700641 t_val = tcg_constant_i32(in_c);
Richard Henderson6d3ef042020-12-15 11:47:59 -0600642 }
643 gen_helper_memset(t_ptr, t_ptr, t_val, t_size);
644
Richard Henderson88d40052020-09-03 18:18:08 -0700645 if (in_64) {
Richard Henderson6d3ef042020-12-15 11:47:59 -0600646 tcg_temp_free_i32(t_val);
647 }
Richard Henderson6d3ef042020-12-15 11:47:59 -0600648 tcg_temp_free_ptr(t_ptr);
649 return;
650 }
651
Richard Henderson88d40052020-09-03 18:18:08 -0700652 t_desc = tcg_constant_i32(simd_desc(oprsz, maxsz, 0));
Richard Hendersondb432672017-09-15 14:11:45 -0700653
654 if (vece == MO_64) {
655 if (in_64) {
656 gen_helper_gvec_dup64(t_ptr, t_desc, in_64);
657 } else {
Richard Henderson88d40052020-09-03 18:18:08 -0700658 t_64 = tcg_constant_i64(in_c);
Richard Hendersondb432672017-09-15 14:11:45 -0700659 gen_helper_gvec_dup64(t_ptr, t_desc, t_64);
Richard Hendersondb432672017-09-15 14:11:45 -0700660 }
661 } else {
662 typedef void dup_fn(TCGv_ptr, TCGv_i32, TCGv_i32);
663 static dup_fn * const fns[3] = {
664 gen_helper_gvec_dup8,
665 gen_helper_gvec_dup16,
666 gen_helper_gvec_dup32
667 };
668
669 if (in_32) {
670 fns[vece](t_ptr, t_desc, in_32);
Richard Henderson88d40052020-09-03 18:18:08 -0700671 } else if (in_64) {
Richard Henderson5dd48602023-01-29 13:26:49 -1000672 t_32 = tcg_temp_ebb_new_i32();
Richard Henderson88d40052020-09-03 18:18:08 -0700673 tcg_gen_extrl_i64_i32(t_32, in_64);
Richard Hendersondb432672017-09-15 14:11:45 -0700674 fns[vece](t_ptr, t_desc, t_32);
675 tcg_temp_free_i32(t_32);
Richard Henderson88d40052020-09-03 18:18:08 -0700676 } else {
677 if (vece == MO_8) {
678 in_c &= 0xff;
679 } else if (vece == MO_16) {
680 in_c &= 0xffff;
681 }
682 t_32 = tcg_constant_i32(in_c);
683 fns[vece](t_ptr, t_desc, t_32);
Richard Hendersondb432672017-09-15 14:11:45 -0700684 }
685 }
686
687 tcg_temp_free_ptr(t_ptr);
Richard Hendersondb432672017-09-15 14:11:45 -0700688 return;
689
690 done:
691 if (oprsz < maxsz) {
692 expand_clr(dofs + oprsz, maxsz - oprsz);
693 }
694}
695
696/* Likewise, but with zero. */
697static void expand_clr(uint32_t dofs, uint32_t maxsz)
698{
699 do_dup(MO_8, dofs, maxsz, maxsz, NULL, NULL, 0);
700}
701
702/* Expand OPSZ bytes worth of two-operand operations using i32 elements. */
703static void expand_2_i32(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
Richard Hendersonac09ae62020-04-08 15:22:47 -0700704 bool load_dest, void (*fni)(TCGv_i32, TCGv_i32))
Richard Hendersondb432672017-09-15 14:11:45 -0700705{
706 TCGv_i32 t0 = tcg_temp_new_i32();
Richard Hendersonac09ae62020-04-08 15:22:47 -0700707 TCGv_i32 t1 = tcg_temp_new_i32();
Richard Hendersondb432672017-09-15 14:11:45 -0700708 uint32_t i;
709
710 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700711 tcg_gen_ld_i32(t0, tcg_env, aofs + i);
Richard Hendersonac09ae62020-04-08 15:22:47 -0700712 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700713 tcg_gen_ld_i32(t1, tcg_env, dofs + i);
Richard Hendersonac09ae62020-04-08 15:22:47 -0700714 }
715 fni(t1, t0);
Richard Hendersonad75a512023-09-13 16:37:36 -0700716 tcg_gen_st_i32(t1, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700717 }
718 tcg_temp_free_i32(t0);
Richard Hendersonac09ae62020-04-08 15:22:47 -0700719 tcg_temp_free_i32(t1);
Richard Hendersondb432672017-09-15 14:11:45 -0700720}
721
Richard Hendersond0ec9792017-11-17 14:35:11 +0100722static void expand_2i_i32(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
723 int32_t c, bool load_dest,
724 void (*fni)(TCGv_i32, TCGv_i32, int32_t))
725{
726 TCGv_i32 t0 = tcg_temp_new_i32();
727 TCGv_i32 t1 = tcg_temp_new_i32();
728 uint32_t i;
729
730 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700731 tcg_gen_ld_i32(t0, tcg_env, aofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +0100732 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700733 tcg_gen_ld_i32(t1, tcg_env, dofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +0100734 }
735 fni(t1, t0, c);
Richard Hendersonad75a512023-09-13 16:37:36 -0700736 tcg_gen_st_i32(t1, tcg_env, dofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +0100737 }
738 tcg_temp_free_i32(t0);
739 tcg_temp_free_i32(t1);
740}
741
Richard Henderson22fc3522017-12-21 10:58:36 -0800742static void expand_2s_i32(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
743 TCGv_i32 c, bool scalar_first,
744 void (*fni)(TCGv_i32, TCGv_i32, TCGv_i32))
745{
746 TCGv_i32 t0 = tcg_temp_new_i32();
747 TCGv_i32 t1 = tcg_temp_new_i32();
748 uint32_t i;
749
750 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700751 tcg_gen_ld_i32(t0, tcg_env, aofs + i);
Richard Henderson22fc3522017-12-21 10:58:36 -0800752 if (scalar_first) {
753 fni(t1, c, t0);
754 } else {
755 fni(t1, t0, c);
756 }
Richard Hendersonad75a512023-09-13 16:37:36 -0700757 tcg_gen_st_i32(t1, tcg_env, dofs + i);
Richard Henderson22fc3522017-12-21 10:58:36 -0800758 }
759 tcg_temp_free_i32(t0);
760 tcg_temp_free_i32(t1);
761}
762
Richard Hendersondb432672017-09-15 14:11:45 -0700763/* Expand OPSZ bytes worth of three-operand operations using i32 elements. */
764static void expand_3_i32(uint32_t dofs, uint32_t aofs,
765 uint32_t bofs, uint32_t oprsz, bool load_dest,
766 void (*fni)(TCGv_i32, TCGv_i32, TCGv_i32))
767{
768 TCGv_i32 t0 = tcg_temp_new_i32();
769 TCGv_i32 t1 = tcg_temp_new_i32();
770 TCGv_i32 t2 = tcg_temp_new_i32();
771 uint32_t i;
772
773 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700774 tcg_gen_ld_i32(t0, tcg_env, aofs + i);
775 tcg_gen_ld_i32(t1, tcg_env, bofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700776 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700777 tcg_gen_ld_i32(t2, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700778 }
779 fni(t2, t0, t1);
Richard Hendersonad75a512023-09-13 16:37:36 -0700780 tcg_gen_st_i32(t2, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700781 }
782 tcg_temp_free_i32(t2);
783 tcg_temp_free_i32(t1);
784 tcg_temp_free_i32(t0);
785}
786
David Hildenbrande1227bb2019-04-16 20:52:21 +0200787static void expand_3i_i32(uint32_t dofs, uint32_t aofs, uint32_t bofs,
Richard Hendersonb3ee7192024-03-11 11:26:59 -1000788 uint32_t oprsz, int32_t c,
789 bool load_dest, bool write_aofs,
David Hildenbrande1227bb2019-04-16 20:52:21 +0200790 void (*fni)(TCGv_i32, TCGv_i32, TCGv_i32, int32_t))
791{
792 TCGv_i32 t0 = tcg_temp_new_i32();
793 TCGv_i32 t1 = tcg_temp_new_i32();
794 TCGv_i32 t2 = tcg_temp_new_i32();
795 uint32_t i;
796
797 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700798 tcg_gen_ld_i32(t0, tcg_env, aofs + i);
799 tcg_gen_ld_i32(t1, tcg_env, bofs + i);
David Hildenbrande1227bb2019-04-16 20:52:21 +0200800 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700801 tcg_gen_ld_i32(t2, tcg_env, dofs + i);
David Hildenbrande1227bb2019-04-16 20:52:21 +0200802 }
803 fni(t2, t0, t1, c);
Richard Hendersonad75a512023-09-13 16:37:36 -0700804 tcg_gen_st_i32(t2, tcg_env, dofs + i);
Richard Hendersonb3ee7192024-03-11 11:26:59 -1000805 if (write_aofs) {
806 tcg_gen_st_i32(t0, tcg_env, aofs + i);
807 }
David Hildenbrande1227bb2019-04-16 20:52:21 +0200808 }
809 tcg_temp_free_i32(t0);
810 tcg_temp_free_i32(t1);
811 tcg_temp_free_i32(t2);
812}
813
Richard Hendersondb432672017-09-15 14:11:45 -0700814/* Expand OPSZ bytes worth of three-operand operations using i32 elements. */
815static void expand_4_i32(uint32_t dofs, uint32_t aofs, uint32_t bofs,
Richard Henderson5d6acdd2018-12-17 13:30:56 -0800816 uint32_t cofs, uint32_t oprsz, bool write_aofs,
Richard Hendersondb432672017-09-15 14:11:45 -0700817 void (*fni)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32))
818{
819 TCGv_i32 t0 = tcg_temp_new_i32();
820 TCGv_i32 t1 = tcg_temp_new_i32();
821 TCGv_i32 t2 = tcg_temp_new_i32();
822 TCGv_i32 t3 = tcg_temp_new_i32();
823 uint32_t i;
824
825 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700826 tcg_gen_ld_i32(t1, tcg_env, aofs + i);
827 tcg_gen_ld_i32(t2, tcg_env, bofs + i);
828 tcg_gen_ld_i32(t3, tcg_env, cofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700829 fni(t0, t1, t2, t3);
Richard Hendersonad75a512023-09-13 16:37:36 -0700830 tcg_gen_st_i32(t0, tcg_env, dofs + i);
Richard Henderson5d6acdd2018-12-17 13:30:56 -0800831 if (write_aofs) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700832 tcg_gen_st_i32(t1, tcg_env, aofs + i);
Richard Henderson5d6acdd2018-12-17 13:30:56 -0800833 }
Richard Hendersondb432672017-09-15 14:11:45 -0700834 }
835 tcg_temp_free_i32(t3);
836 tcg_temp_free_i32(t2);
837 tcg_temp_free_i32(t1);
838 tcg_temp_free_i32(t0);
839}
840
Matheus Ferst9620ae02022-03-02 06:51:38 +0100841static void expand_4i_i32(uint32_t dofs, uint32_t aofs, uint32_t bofs,
842 uint32_t cofs, uint32_t oprsz, int32_t c,
843 void (*fni)(TCGv_i32, TCGv_i32, TCGv_i32, TCGv_i32,
844 int32_t))
845{
846 TCGv_i32 t0 = tcg_temp_new_i32();
847 TCGv_i32 t1 = tcg_temp_new_i32();
848 TCGv_i32 t2 = tcg_temp_new_i32();
849 TCGv_i32 t3 = tcg_temp_new_i32();
850 uint32_t i;
851
852 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700853 tcg_gen_ld_i32(t1, tcg_env, aofs + i);
854 tcg_gen_ld_i32(t2, tcg_env, bofs + i);
855 tcg_gen_ld_i32(t3, tcg_env, cofs + i);
Matheus Ferst9620ae02022-03-02 06:51:38 +0100856 fni(t0, t1, t2, t3, c);
Richard Hendersonad75a512023-09-13 16:37:36 -0700857 tcg_gen_st_i32(t0, tcg_env, dofs + i);
Matheus Ferst9620ae02022-03-02 06:51:38 +0100858 }
859 tcg_temp_free_i32(t3);
860 tcg_temp_free_i32(t2);
861 tcg_temp_free_i32(t1);
862 tcg_temp_free_i32(t0);
863}
864
Richard Hendersondb432672017-09-15 14:11:45 -0700865/* Expand OPSZ bytes worth of two-operand operations using i64 elements. */
866static void expand_2_i64(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
Richard Hendersonac09ae62020-04-08 15:22:47 -0700867 bool load_dest, void (*fni)(TCGv_i64, TCGv_i64))
Richard Hendersondb432672017-09-15 14:11:45 -0700868{
869 TCGv_i64 t0 = tcg_temp_new_i64();
Richard Hendersonac09ae62020-04-08 15:22:47 -0700870 TCGv_i64 t1 = tcg_temp_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -0700871 uint32_t i;
872
873 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700874 tcg_gen_ld_i64(t0, tcg_env, aofs + i);
Richard Hendersonac09ae62020-04-08 15:22:47 -0700875 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700876 tcg_gen_ld_i64(t1, tcg_env, dofs + i);
Richard Hendersonac09ae62020-04-08 15:22:47 -0700877 }
878 fni(t1, t0);
Richard Hendersonad75a512023-09-13 16:37:36 -0700879 tcg_gen_st_i64(t1, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700880 }
881 tcg_temp_free_i64(t0);
Richard Hendersonac09ae62020-04-08 15:22:47 -0700882 tcg_temp_free_i64(t1);
Richard Hendersondb432672017-09-15 14:11:45 -0700883}
884
Richard Hendersond0ec9792017-11-17 14:35:11 +0100885static void expand_2i_i64(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
886 int64_t c, bool load_dest,
887 void (*fni)(TCGv_i64, TCGv_i64, int64_t))
888{
889 TCGv_i64 t0 = tcg_temp_new_i64();
890 TCGv_i64 t1 = tcg_temp_new_i64();
891 uint32_t i;
892
893 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700894 tcg_gen_ld_i64(t0, tcg_env, aofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +0100895 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700896 tcg_gen_ld_i64(t1, tcg_env, dofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +0100897 }
898 fni(t1, t0, c);
Richard Hendersonad75a512023-09-13 16:37:36 -0700899 tcg_gen_st_i64(t1, tcg_env, dofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +0100900 }
901 tcg_temp_free_i64(t0);
902 tcg_temp_free_i64(t1);
903}
904
Richard Henderson22fc3522017-12-21 10:58:36 -0800905static void expand_2s_i64(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
906 TCGv_i64 c, bool scalar_first,
907 void (*fni)(TCGv_i64, TCGv_i64, TCGv_i64))
908{
909 TCGv_i64 t0 = tcg_temp_new_i64();
910 TCGv_i64 t1 = tcg_temp_new_i64();
911 uint32_t i;
912
913 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700914 tcg_gen_ld_i64(t0, tcg_env, aofs + i);
Richard Henderson22fc3522017-12-21 10:58:36 -0800915 if (scalar_first) {
916 fni(t1, c, t0);
917 } else {
918 fni(t1, t0, c);
919 }
Richard Hendersonad75a512023-09-13 16:37:36 -0700920 tcg_gen_st_i64(t1, tcg_env, dofs + i);
Richard Henderson22fc3522017-12-21 10:58:36 -0800921 }
922 tcg_temp_free_i64(t0);
923 tcg_temp_free_i64(t1);
924}
925
Richard Hendersondb432672017-09-15 14:11:45 -0700926/* Expand OPSZ bytes worth of three-operand operations using i64 elements. */
927static void expand_3_i64(uint32_t dofs, uint32_t aofs,
928 uint32_t bofs, uint32_t oprsz, bool load_dest,
929 void (*fni)(TCGv_i64, TCGv_i64, TCGv_i64))
930{
931 TCGv_i64 t0 = tcg_temp_new_i64();
932 TCGv_i64 t1 = tcg_temp_new_i64();
933 TCGv_i64 t2 = tcg_temp_new_i64();
934 uint32_t i;
935
936 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700937 tcg_gen_ld_i64(t0, tcg_env, aofs + i);
938 tcg_gen_ld_i64(t1, tcg_env, bofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700939 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700940 tcg_gen_ld_i64(t2, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700941 }
942 fni(t2, t0, t1);
Richard Hendersonad75a512023-09-13 16:37:36 -0700943 tcg_gen_st_i64(t2, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700944 }
945 tcg_temp_free_i64(t2);
946 tcg_temp_free_i64(t1);
947 tcg_temp_free_i64(t0);
948}
949
David Hildenbrande1227bb2019-04-16 20:52:21 +0200950static void expand_3i_i64(uint32_t dofs, uint32_t aofs, uint32_t bofs,
Richard Hendersonb3ee7192024-03-11 11:26:59 -1000951 uint32_t oprsz, int64_t c,
952 bool load_dest, bool write_aofs,
David Hildenbrande1227bb2019-04-16 20:52:21 +0200953 void (*fni)(TCGv_i64, TCGv_i64, TCGv_i64, int64_t))
954{
955 TCGv_i64 t0 = tcg_temp_new_i64();
956 TCGv_i64 t1 = tcg_temp_new_i64();
957 TCGv_i64 t2 = tcg_temp_new_i64();
958 uint32_t i;
959
960 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700961 tcg_gen_ld_i64(t0, tcg_env, aofs + i);
962 tcg_gen_ld_i64(t1, tcg_env, bofs + i);
David Hildenbrande1227bb2019-04-16 20:52:21 +0200963 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700964 tcg_gen_ld_i64(t2, tcg_env, dofs + i);
David Hildenbrande1227bb2019-04-16 20:52:21 +0200965 }
966 fni(t2, t0, t1, c);
Richard Hendersonad75a512023-09-13 16:37:36 -0700967 tcg_gen_st_i64(t2, tcg_env, dofs + i);
Richard Hendersonb3ee7192024-03-11 11:26:59 -1000968 if (write_aofs) {
969 tcg_gen_st_i64(t0, tcg_env, aofs + i);
970 }
David Hildenbrande1227bb2019-04-16 20:52:21 +0200971 }
972 tcg_temp_free_i64(t0);
973 tcg_temp_free_i64(t1);
974 tcg_temp_free_i64(t2);
975}
976
Richard Hendersondb432672017-09-15 14:11:45 -0700977/* Expand OPSZ bytes worth of three-operand operations using i64 elements. */
978static void expand_4_i64(uint32_t dofs, uint32_t aofs, uint32_t bofs,
Richard Henderson5d6acdd2018-12-17 13:30:56 -0800979 uint32_t cofs, uint32_t oprsz, bool write_aofs,
Richard Hendersondb432672017-09-15 14:11:45 -0700980 void (*fni)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64))
981{
982 TCGv_i64 t0 = tcg_temp_new_i64();
983 TCGv_i64 t1 = tcg_temp_new_i64();
984 TCGv_i64 t2 = tcg_temp_new_i64();
985 TCGv_i64 t3 = tcg_temp_new_i64();
986 uint32_t i;
987
988 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700989 tcg_gen_ld_i64(t1, tcg_env, aofs + i);
990 tcg_gen_ld_i64(t2, tcg_env, bofs + i);
991 tcg_gen_ld_i64(t3, tcg_env, cofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -0700992 fni(t0, t1, t2, t3);
Richard Hendersonad75a512023-09-13 16:37:36 -0700993 tcg_gen_st_i64(t0, tcg_env, dofs + i);
Richard Henderson5d6acdd2018-12-17 13:30:56 -0800994 if (write_aofs) {
Richard Hendersonad75a512023-09-13 16:37:36 -0700995 tcg_gen_st_i64(t1, tcg_env, aofs + i);
Richard Henderson5d6acdd2018-12-17 13:30:56 -0800996 }
Richard Hendersondb432672017-09-15 14:11:45 -0700997 }
998 tcg_temp_free_i64(t3);
999 tcg_temp_free_i64(t2);
1000 tcg_temp_free_i64(t1);
1001 tcg_temp_free_i64(t0);
1002}
1003
Matheus Ferst9620ae02022-03-02 06:51:38 +01001004static void expand_4i_i64(uint32_t dofs, uint32_t aofs, uint32_t bofs,
1005 uint32_t cofs, uint32_t oprsz, int64_t c,
1006 void (*fni)(TCGv_i64, TCGv_i64, TCGv_i64, TCGv_i64,
1007 int64_t))
1008{
1009 TCGv_i64 t0 = tcg_temp_new_i64();
1010 TCGv_i64 t1 = tcg_temp_new_i64();
1011 TCGv_i64 t2 = tcg_temp_new_i64();
1012 TCGv_i64 t3 = tcg_temp_new_i64();
1013 uint32_t i;
1014
1015 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001016 tcg_gen_ld_i64(t1, tcg_env, aofs + i);
1017 tcg_gen_ld_i64(t2, tcg_env, bofs + i);
1018 tcg_gen_ld_i64(t3, tcg_env, cofs + i);
Matheus Ferst9620ae02022-03-02 06:51:38 +01001019 fni(t0, t1, t2, t3, c);
Richard Hendersonad75a512023-09-13 16:37:36 -07001020 tcg_gen_st_i64(t0, tcg_env, dofs + i);
Matheus Ferst9620ae02022-03-02 06:51:38 +01001021 }
1022 tcg_temp_free_i64(t3);
1023 tcg_temp_free_i64(t2);
1024 tcg_temp_free_i64(t1);
1025 tcg_temp_free_i64(t0);
1026}
1027
Richard Hendersondb432672017-09-15 14:11:45 -07001028/* Expand OPSZ bytes worth of two-operand operations using host vectors. */
1029static void expand_2_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
1030 uint32_t oprsz, uint32_t tysz, TCGType type,
Richard Hendersonac09ae62020-04-08 15:22:47 -07001031 bool load_dest,
Richard Hendersondb432672017-09-15 14:11:45 -07001032 void (*fni)(unsigned, TCGv_vec, TCGv_vec))
1033{
Richard Henderson9628d002023-08-23 20:35:05 -07001034 for (uint32_t i = 0; i < oprsz; i += tysz) {
1035 TCGv_vec t0 = tcg_temp_new_vec(type);
1036 TCGv_vec t1 = tcg_temp_new_vec(type);
Richard Hendersondb432672017-09-15 14:11:45 -07001037
Richard Hendersonad75a512023-09-13 16:37:36 -07001038 tcg_gen_ld_vec(t0, tcg_env, aofs + i);
Richard Hendersonac09ae62020-04-08 15:22:47 -07001039 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001040 tcg_gen_ld_vec(t1, tcg_env, dofs + i);
Richard Hendersonac09ae62020-04-08 15:22:47 -07001041 }
1042 fni(vece, t1, t0);
Richard Hendersonad75a512023-09-13 16:37:36 -07001043 tcg_gen_st_vec(t1, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -07001044 }
Richard Hendersondb432672017-09-15 14:11:45 -07001045}
1046
Richard Hendersond0ec9792017-11-17 14:35:11 +01001047/* Expand OPSZ bytes worth of two-vector operands and an immediate operand
1048 using host vectors. */
1049static void expand_2i_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
1050 uint32_t oprsz, uint32_t tysz, TCGType type,
1051 int64_t c, bool load_dest,
1052 void (*fni)(unsigned, TCGv_vec, TCGv_vec, int64_t))
1053{
Richard Henderson9628d002023-08-23 20:35:05 -07001054 for (uint32_t i = 0; i < oprsz; i += tysz) {
1055 TCGv_vec t0 = tcg_temp_new_vec(type);
1056 TCGv_vec t1 = tcg_temp_new_vec(type);
Richard Hendersond0ec9792017-11-17 14:35:11 +01001057
Richard Hendersonad75a512023-09-13 16:37:36 -07001058 tcg_gen_ld_vec(t0, tcg_env, aofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +01001059 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001060 tcg_gen_ld_vec(t1, tcg_env, dofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +01001061 }
1062 fni(vece, t1, t0, c);
Richard Hendersonad75a512023-09-13 16:37:36 -07001063 tcg_gen_st_vec(t1, tcg_env, dofs + i);
Richard Hendersond0ec9792017-11-17 14:35:11 +01001064 }
Richard Hendersond0ec9792017-11-17 14:35:11 +01001065}
1066
Richard Henderson22fc3522017-12-21 10:58:36 -08001067static void expand_2s_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
1068 uint32_t oprsz, uint32_t tysz, TCGType type,
1069 TCGv_vec c, bool scalar_first,
1070 void (*fni)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec))
1071{
Richard Henderson9628d002023-08-23 20:35:05 -07001072 for (uint32_t i = 0; i < oprsz; i += tysz) {
1073 TCGv_vec t0 = tcg_temp_new_vec(type);
1074 TCGv_vec t1 = tcg_temp_new_vec(type);
Richard Henderson22fc3522017-12-21 10:58:36 -08001075
Richard Hendersonad75a512023-09-13 16:37:36 -07001076 tcg_gen_ld_vec(t0, tcg_env, aofs + i);
Richard Henderson22fc3522017-12-21 10:58:36 -08001077 if (scalar_first) {
1078 fni(vece, t1, c, t0);
1079 } else {
1080 fni(vece, t1, t0, c);
1081 }
Richard Hendersonad75a512023-09-13 16:37:36 -07001082 tcg_gen_st_vec(t1, tcg_env, dofs + i);
Richard Henderson22fc3522017-12-21 10:58:36 -08001083 }
Richard Henderson22fc3522017-12-21 10:58:36 -08001084}
1085
Richard Hendersondb432672017-09-15 14:11:45 -07001086/* Expand OPSZ bytes worth of three-operand operations using host vectors. */
1087static void expand_3_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
1088 uint32_t bofs, uint32_t oprsz,
1089 uint32_t tysz, TCGType type, bool load_dest,
1090 void (*fni)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec))
1091{
Richard Henderson9628d002023-08-23 20:35:05 -07001092 for (uint32_t i = 0; i < oprsz; i += tysz) {
1093 TCGv_vec t0 = tcg_temp_new_vec(type);
1094 TCGv_vec t1 = tcg_temp_new_vec(type);
1095 TCGv_vec t2 = tcg_temp_new_vec(type);
Richard Hendersondb432672017-09-15 14:11:45 -07001096
Richard Hendersonad75a512023-09-13 16:37:36 -07001097 tcg_gen_ld_vec(t0, tcg_env, aofs + i);
1098 tcg_gen_ld_vec(t1, tcg_env, bofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -07001099 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001100 tcg_gen_ld_vec(t2, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -07001101 }
1102 fni(vece, t2, t0, t1);
Richard Hendersonad75a512023-09-13 16:37:36 -07001103 tcg_gen_st_vec(t2, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -07001104 }
Richard Hendersondb432672017-09-15 14:11:45 -07001105}
1106
David Hildenbrande1227bb2019-04-16 20:52:21 +02001107/*
1108 * Expand OPSZ bytes worth of three-vector operands and an immediate operand
1109 * using host vectors.
1110 */
1111static void expand_3i_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
1112 uint32_t bofs, uint32_t oprsz, uint32_t tysz,
Richard Hendersonb3ee7192024-03-11 11:26:59 -10001113 TCGType type, int64_t c,
1114 bool load_dest, bool write_aofs,
David Hildenbrande1227bb2019-04-16 20:52:21 +02001115 void (*fni)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec,
1116 int64_t))
1117{
Richard Henderson9628d002023-08-23 20:35:05 -07001118 for (uint32_t i = 0; i < oprsz; i += tysz) {
1119 TCGv_vec t0 = tcg_temp_new_vec(type);
1120 TCGv_vec t1 = tcg_temp_new_vec(type);
1121 TCGv_vec t2 = tcg_temp_new_vec(type);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001122
Richard Hendersonad75a512023-09-13 16:37:36 -07001123 tcg_gen_ld_vec(t0, tcg_env, aofs + i);
1124 tcg_gen_ld_vec(t1, tcg_env, bofs + i);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001125 if (load_dest) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001126 tcg_gen_ld_vec(t2, tcg_env, dofs + i);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001127 }
1128 fni(vece, t2, t0, t1, c);
Richard Hendersonad75a512023-09-13 16:37:36 -07001129 tcg_gen_st_vec(t2, tcg_env, dofs + i);
Richard Hendersonb3ee7192024-03-11 11:26:59 -10001130 if (write_aofs) {
1131 tcg_gen_st_vec(t0, tcg_env, aofs + i);
1132 }
David Hildenbrande1227bb2019-04-16 20:52:21 +02001133 }
David Hildenbrande1227bb2019-04-16 20:52:21 +02001134}
1135
Richard Hendersondb432672017-09-15 14:11:45 -07001136/* Expand OPSZ bytes worth of four-operand operations using host vectors. */
1137static void expand_4_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
1138 uint32_t bofs, uint32_t cofs, uint32_t oprsz,
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001139 uint32_t tysz, TCGType type, bool write_aofs,
Richard Hendersondb432672017-09-15 14:11:45 -07001140 void (*fni)(unsigned, TCGv_vec, TCGv_vec,
1141 TCGv_vec, TCGv_vec))
1142{
Richard Henderson9628d002023-08-23 20:35:05 -07001143 for (uint32_t i = 0; i < oprsz; i += tysz) {
1144 TCGv_vec t0 = tcg_temp_new_vec(type);
1145 TCGv_vec t1 = tcg_temp_new_vec(type);
1146 TCGv_vec t2 = tcg_temp_new_vec(type);
1147 TCGv_vec t3 = tcg_temp_new_vec(type);
Richard Hendersondb432672017-09-15 14:11:45 -07001148
Richard Hendersonad75a512023-09-13 16:37:36 -07001149 tcg_gen_ld_vec(t1, tcg_env, aofs + i);
1150 tcg_gen_ld_vec(t2, tcg_env, bofs + i);
1151 tcg_gen_ld_vec(t3, tcg_env, cofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -07001152 fni(vece, t0, t1, t2, t3);
Richard Hendersonad75a512023-09-13 16:37:36 -07001153 tcg_gen_st_vec(t0, tcg_env, dofs + i);
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001154 if (write_aofs) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001155 tcg_gen_st_vec(t1, tcg_env, aofs + i);
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001156 }
Richard Hendersondb432672017-09-15 14:11:45 -07001157 }
Richard Hendersondb432672017-09-15 14:11:45 -07001158}
1159
Matheus Ferst9620ae02022-03-02 06:51:38 +01001160/*
1161 * Expand OPSZ bytes worth of four-vector operands and an immediate operand
1162 * using host vectors.
1163 */
1164static void expand_4i_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
1165 uint32_t bofs, uint32_t cofs, uint32_t oprsz,
1166 uint32_t tysz, TCGType type, int64_t c,
1167 void (*fni)(unsigned, TCGv_vec, TCGv_vec,
1168 TCGv_vec, TCGv_vec, int64_t))
1169{
Richard Henderson9628d002023-08-23 20:35:05 -07001170 for (uint32_t i = 0; i < oprsz; i += tysz) {
1171 TCGv_vec t0 = tcg_temp_new_vec(type);
1172 TCGv_vec t1 = tcg_temp_new_vec(type);
1173 TCGv_vec t2 = tcg_temp_new_vec(type);
1174 TCGv_vec t3 = tcg_temp_new_vec(type);
Matheus Ferst9620ae02022-03-02 06:51:38 +01001175
Richard Hendersonad75a512023-09-13 16:37:36 -07001176 tcg_gen_ld_vec(t1, tcg_env, aofs + i);
1177 tcg_gen_ld_vec(t2, tcg_env, bofs + i);
1178 tcg_gen_ld_vec(t3, tcg_env, cofs + i);
Matheus Ferst9620ae02022-03-02 06:51:38 +01001179 fni(vece, t0, t1, t2, t3, c);
Richard Hendersonad75a512023-09-13 16:37:36 -07001180 tcg_gen_st_vec(t0, tcg_env, dofs + i);
Matheus Ferst9620ae02022-03-02 06:51:38 +01001181 }
Matheus Ferst9620ae02022-03-02 06:51:38 +01001182}
1183
Richard Hendersondb432672017-09-15 14:11:45 -07001184/* Expand a vector two-operand operation. */
1185void tcg_gen_gvec_2(uint32_t dofs, uint32_t aofs,
1186 uint32_t oprsz, uint32_t maxsz, const GVecGen2 *g)
1187{
Richard Henderson53229a72019-03-17 00:27:29 +00001188 const TCGOpcode *this_list = g->opt_opc ? : vecop_list_empty;
1189 const TCGOpcode *hold_list = tcg_swap_vecop_list(this_list);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001190 TCGType type;
1191 uint32_t some;
1192
Richard Hendersondb432672017-09-15 14:11:45 -07001193 check_size_align(oprsz, maxsz, dofs | aofs);
1194 check_overlap_2(dofs, aofs, maxsz);
1195
Richard Hendersonadb196c2018-02-17 08:30:16 -08001196 type = 0;
1197 if (g->fniv) {
Richard Henderson53229a72019-03-17 00:27:29 +00001198 type = choose_vector_type(g->opt_opc, g->vece, oprsz, g->prefer_i64);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001199 }
1200 switch (type) {
1201 case TCG_TYPE_V256:
1202 /* Recall that ARM SVE allows vector sizes that are not a
1203 * power of 2, but always a multiple of 16. The intent is
1204 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
1205 */
1206 some = QEMU_ALIGN_DOWN(oprsz, 32);
Richard Hendersonac09ae62020-04-08 15:22:47 -07001207 expand_2_vec(g->vece, dofs, aofs, some, 32, TCG_TYPE_V256,
1208 g->load_dest, g->fniv);
Richard Hendersondb432672017-09-15 14:11:45 -07001209 if (some == oprsz) {
Richard Hendersonadb196c2018-02-17 08:30:16 -08001210 break;
Richard Hendersondb432672017-09-15 14:11:45 -07001211 }
1212 dofs += some;
1213 aofs += some;
1214 oprsz -= some;
1215 maxsz -= some;
Richard Hendersonadb196c2018-02-17 08:30:16 -08001216 /* fallthru */
1217 case TCG_TYPE_V128:
Richard Hendersonac09ae62020-04-08 15:22:47 -07001218 expand_2_vec(g->vece, dofs, aofs, oprsz, 16, TCG_TYPE_V128,
1219 g->load_dest, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001220 break;
1221 case TCG_TYPE_V64:
Richard Hendersonac09ae62020-04-08 15:22:47 -07001222 expand_2_vec(g->vece, dofs, aofs, oprsz, 8, TCG_TYPE_V64,
1223 g->load_dest, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001224 break;
1225
1226 case 0:
1227 if (g->fni8 && check_size_impl(oprsz, 8)) {
Richard Hendersonac09ae62020-04-08 15:22:47 -07001228 expand_2_i64(dofs, aofs, oprsz, g->load_dest, g->fni8);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001229 } else if (g->fni4 && check_size_impl(oprsz, 4)) {
Richard Hendersonac09ae62020-04-08 15:22:47 -07001230 expand_2_i32(dofs, aofs, oprsz, g->load_dest, g->fni4);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001231 } else {
1232 assert(g->fno != NULL);
1233 tcg_gen_gvec_2_ool(dofs, aofs, oprsz, maxsz, g->data, g->fno);
Richard Henderson53229a72019-03-17 00:27:29 +00001234 oprsz = maxsz;
Richard Hendersonadb196c2018-02-17 08:30:16 -08001235 }
1236 break;
1237
1238 default:
1239 g_assert_not_reached();
Richard Hendersondb432672017-09-15 14:11:45 -07001240 }
Richard Henderson53229a72019-03-17 00:27:29 +00001241 tcg_swap_vecop_list(hold_list);
Richard Hendersondb432672017-09-15 14:11:45 -07001242
Richard Hendersondb432672017-09-15 14:11:45 -07001243 if (oprsz < maxsz) {
1244 expand_clr(dofs + oprsz, maxsz - oprsz);
1245 }
1246}
1247
Richard Henderson22fc3522017-12-21 10:58:36 -08001248/* Expand a vector operation with two vectors and an immediate. */
Richard Hendersond0ec9792017-11-17 14:35:11 +01001249void tcg_gen_gvec_2i(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
1250 uint32_t maxsz, int64_t c, const GVecGen2i *g)
1251{
Richard Henderson53229a72019-03-17 00:27:29 +00001252 const TCGOpcode *this_list = g->opt_opc ? : vecop_list_empty;
1253 const TCGOpcode *hold_list = tcg_swap_vecop_list(this_list);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001254 TCGType type;
1255 uint32_t some;
1256
Richard Hendersond0ec9792017-11-17 14:35:11 +01001257 check_size_align(oprsz, maxsz, dofs | aofs);
1258 check_overlap_2(dofs, aofs, maxsz);
1259
Richard Hendersonadb196c2018-02-17 08:30:16 -08001260 type = 0;
1261 if (g->fniv) {
Richard Henderson53229a72019-03-17 00:27:29 +00001262 type = choose_vector_type(g->opt_opc, g->vece, oprsz, g->prefer_i64);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001263 }
1264 switch (type) {
1265 case TCG_TYPE_V256:
1266 /* Recall that ARM SVE allows vector sizes that are not a
1267 * power of 2, but always a multiple of 16. The intent is
1268 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
1269 */
1270 some = QEMU_ALIGN_DOWN(oprsz, 32);
Richard Hendersond0ec9792017-11-17 14:35:11 +01001271 expand_2i_vec(g->vece, dofs, aofs, some, 32, TCG_TYPE_V256,
1272 c, g->load_dest, g->fniv);
1273 if (some == oprsz) {
Richard Hendersonadb196c2018-02-17 08:30:16 -08001274 break;
Richard Hendersond0ec9792017-11-17 14:35:11 +01001275 }
1276 dofs += some;
1277 aofs += some;
1278 oprsz -= some;
1279 maxsz -= some;
Richard Hendersonadb196c2018-02-17 08:30:16 -08001280 /* fallthru */
1281 case TCG_TYPE_V128:
Richard Hendersond0ec9792017-11-17 14:35:11 +01001282 expand_2i_vec(g->vece, dofs, aofs, oprsz, 16, TCG_TYPE_V128,
1283 c, g->load_dest, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001284 break;
1285 case TCG_TYPE_V64:
Richard Hendersond0ec9792017-11-17 14:35:11 +01001286 expand_2i_vec(g->vece, dofs, aofs, oprsz, 8, TCG_TYPE_V64,
1287 c, g->load_dest, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001288 break;
1289
1290 case 0:
1291 if (g->fni8 && check_size_impl(oprsz, 8)) {
1292 expand_2i_i64(dofs, aofs, oprsz, c, g->load_dest, g->fni8);
1293 } else if (g->fni4 && check_size_impl(oprsz, 4)) {
1294 expand_2i_i32(dofs, aofs, oprsz, c, g->load_dest, g->fni4);
Richard Henderson22fc3522017-12-21 10:58:36 -08001295 } else {
Richard Hendersonadb196c2018-02-17 08:30:16 -08001296 if (g->fno) {
1297 tcg_gen_gvec_2_ool(dofs, aofs, oprsz, maxsz, c, g->fno);
1298 } else {
Richard Henderson88d40052020-09-03 18:18:08 -07001299 TCGv_i64 tcg_c = tcg_constant_i64(c);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001300 tcg_gen_gvec_2i_ool(dofs, aofs, tcg_c, oprsz,
1301 maxsz, c, g->fnoi);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001302 }
Richard Henderson53229a72019-03-17 00:27:29 +00001303 oprsz = maxsz;
Richard Henderson22fc3522017-12-21 10:58:36 -08001304 }
Richard Hendersonadb196c2018-02-17 08:30:16 -08001305 break;
1306
1307 default:
1308 g_assert_not_reached();
Richard Hendersond0ec9792017-11-17 14:35:11 +01001309 }
Richard Henderson53229a72019-03-17 00:27:29 +00001310 tcg_swap_vecop_list(hold_list);
Richard Hendersond0ec9792017-11-17 14:35:11 +01001311
Richard Hendersond0ec9792017-11-17 14:35:11 +01001312 if (oprsz < maxsz) {
1313 expand_clr(dofs + oprsz, maxsz - oprsz);
1314 }
1315}
1316
Richard Henderson22fc3522017-12-21 10:58:36 -08001317/* Expand a vector operation with two vectors and a scalar. */
1318void tcg_gen_gvec_2s(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
1319 uint32_t maxsz, TCGv_i64 c, const GVecGen2s *g)
1320{
1321 TCGType type;
1322
1323 check_size_align(oprsz, maxsz, dofs | aofs);
1324 check_overlap_2(dofs, aofs, maxsz);
1325
1326 type = 0;
1327 if (g->fniv) {
Richard Henderson53229a72019-03-17 00:27:29 +00001328 type = choose_vector_type(g->opt_opc, g->vece, oprsz, g->prefer_i64);
Richard Henderson22fc3522017-12-21 10:58:36 -08001329 }
1330 if (type != 0) {
Richard Henderson53229a72019-03-17 00:27:29 +00001331 const TCGOpcode *this_list = g->opt_opc ? : vecop_list_empty;
1332 const TCGOpcode *hold_list = tcg_swap_vecop_list(this_list);
Richard Henderson22fc3522017-12-21 10:58:36 -08001333 TCGv_vec t_vec = tcg_temp_new_vec(type);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001334 uint32_t some;
Richard Henderson22fc3522017-12-21 10:58:36 -08001335
1336 tcg_gen_dup_i64_vec(g->vece, t_vec, c);
1337
Richard Henderson22fc3522017-12-21 10:58:36 -08001338 switch (type) {
1339 case TCG_TYPE_V256:
Richard Hendersonadb196c2018-02-17 08:30:16 -08001340 /* Recall that ARM SVE allows vector sizes that are not a
1341 * power of 2, but always a multiple of 16. The intent is
1342 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
1343 */
1344 some = QEMU_ALIGN_DOWN(oprsz, 32);
1345 expand_2s_vec(g->vece, dofs, aofs, some, 32, TCG_TYPE_V256,
1346 t_vec, g->scalar_first, g->fniv);
1347 if (some == oprsz) {
1348 break;
Richard Henderson22fc3522017-12-21 10:58:36 -08001349 }
Richard Hendersonadb196c2018-02-17 08:30:16 -08001350 dofs += some;
1351 aofs += some;
1352 oprsz -= some;
1353 maxsz -= some;
Richard Henderson22fc3522017-12-21 10:58:36 -08001354 /* fallthru */
1355
1356 case TCG_TYPE_V128:
1357 expand_2s_vec(g->vece, dofs, aofs, oprsz, 16, TCG_TYPE_V128,
1358 t_vec, g->scalar_first, g->fniv);
1359 break;
1360
1361 case TCG_TYPE_V64:
1362 expand_2s_vec(g->vece, dofs, aofs, oprsz, 8, TCG_TYPE_V64,
1363 t_vec, g->scalar_first, g->fniv);
1364 break;
1365
1366 default:
1367 g_assert_not_reached();
1368 }
1369 tcg_temp_free_vec(t_vec);
Richard Henderson53229a72019-03-17 00:27:29 +00001370 tcg_swap_vecop_list(hold_list);
Richard Henderson22fc3522017-12-21 10:58:36 -08001371 } else if (g->fni8 && check_size_impl(oprsz, 8)) {
1372 TCGv_i64 t64 = tcg_temp_new_i64();
1373
Peter Maydell614dd4f2021-06-17 13:15:53 +01001374 tcg_gen_dup_i64(g->vece, t64, c);
Richard Henderson22fc3522017-12-21 10:58:36 -08001375 expand_2s_i64(dofs, aofs, oprsz, t64, g->scalar_first, g->fni8);
1376 tcg_temp_free_i64(t64);
1377 } else if (g->fni4 && check_size_impl(oprsz, 4)) {
1378 TCGv_i32 t32 = tcg_temp_new_i32();
1379
1380 tcg_gen_extrl_i64_i32(t32, c);
Peter Maydell614dd4f2021-06-17 13:15:53 +01001381 tcg_gen_dup_i32(g->vece, t32, t32);
Richard Henderson22fc3522017-12-21 10:58:36 -08001382 expand_2s_i32(dofs, aofs, oprsz, t32, g->scalar_first, g->fni4);
1383 tcg_temp_free_i32(t32);
1384 } else {
1385 tcg_gen_gvec_2i_ool(dofs, aofs, c, oprsz, maxsz, 0, g->fno);
1386 return;
1387 }
1388
1389 if (oprsz < maxsz) {
1390 expand_clr(dofs + oprsz, maxsz - oprsz);
1391 }
1392}
1393
Richard Hendersondb432672017-09-15 14:11:45 -07001394/* Expand a vector three-operand operation. */
1395void tcg_gen_gvec_3(uint32_t dofs, uint32_t aofs, uint32_t bofs,
1396 uint32_t oprsz, uint32_t maxsz, const GVecGen3 *g)
1397{
Richard Henderson53229a72019-03-17 00:27:29 +00001398 const TCGOpcode *this_list = g->opt_opc ? : vecop_list_empty;
1399 const TCGOpcode *hold_list = tcg_swap_vecop_list(this_list);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001400 TCGType type;
1401 uint32_t some;
1402
Richard Hendersondb432672017-09-15 14:11:45 -07001403 check_size_align(oprsz, maxsz, dofs | aofs | bofs);
1404 check_overlap_3(dofs, aofs, bofs, maxsz);
1405
Richard Hendersonadb196c2018-02-17 08:30:16 -08001406 type = 0;
1407 if (g->fniv) {
Richard Henderson53229a72019-03-17 00:27:29 +00001408 type = choose_vector_type(g->opt_opc, g->vece, oprsz, g->prefer_i64);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001409 }
1410 switch (type) {
1411 case TCG_TYPE_V256:
1412 /* Recall that ARM SVE allows vector sizes that are not a
1413 * power of 2, but always a multiple of 16. The intent is
1414 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
1415 */
1416 some = QEMU_ALIGN_DOWN(oprsz, 32);
Richard Hendersondb432672017-09-15 14:11:45 -07001417 expand_3_vec(g->vece, dofs, aofs, bofs, some, 32, TCG_TYPE_V256,
1418 g->load_dest, g->fniv);
1419 if (some == oprsz) {
Richard Hendersonadb196c2018-02-17 08:30:16 -08001420 break;
Richard Hendersondb432672017-09-15 14:11:45 -07001421 }
1422 dofs += some;
1423 aofs += some;
1424 bofs += some;
1425 oprsz -= some;
1426 maxsz -= some;
Richard Hendersonadb196c2018-02-17 08:30:16 -08001427 /* fallthru */
1428 case TCG_TYPE_V128:
Richard Hendersondb432672017-09-15 14:11:45 -07001429 expand_3_vec(g->vece, dofs, aofs, bofs, oprsz, 16, TCG_TYPE_V128,
1430 g->load_dest, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001431 break;
1432 case TCG_TYPE_V64:
Richard Hendersondb432672017-09-15 14:11:45 -07001433 expand_3_vec(g->vece, dofs, aofs, bofs, oprsz, 8, TCG_TYPE_V64,
1434 g->load_dest, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001435 break;
1436
1437 case 0:
1438 if (g->fni8 && check_size_impl(oprsz, 8)) {
1439 expand_3_i64(dofs, aofs, bofs, oprsz, g->load_dest, g->fni8);
1440 } else if (g->fni4 && check_size_impl(oprsz, 4)) {
1441 expand_3_i32(dofs, aofs, bofs, oprsz, g->load_dest, g->fni4);
1442 } else {
1443 assert(g->fno != NULL);
1444 tcg_gen_gvec_3_ool(dofs, aofs, bofs, oprsz,
1445 maxsz, g->data, g->fno);
Richard Henderson53229a72019-03-17 00:27:29 +00001446 oprsz = maxsz;
Richard Hendersonadb196c2018-02-17 08:30:16 -08001447 }
1448 break;
1449
1450 default:
1451 g_assert_not_reached();
Richard Hendersondb432672017-09-15 14:11:45 -07001452 }
Richard Henderson53229a72019-03-17 00:27:29 +00001453 tcg_swap_vecop_list(hold_list);
Richard Hendersondb432672017-09-15 14:11:45 -07001454
Richard Hendersondb432672017-09-15 14:11:45 -07001455 if (oprsz < maxsz) {
1456 expand_clr(dofs + oprsz, maxsz - oprsz);
1457 }
1458}
1459
David Hildenbrande1227bb2019-04-16 20:52:21 +02001460/* Expand a vector operation with three vectors and an immediate. */
1461void tcg_gen_gvec_3i(uint32_t dofs, uint32_t aofs, uint32_t bofs,
1462 uint32_t oprsz, uint32_t maxsz, int64_t c,
1463 const GVecGen3i *g)
1464{
Richard Henderson53229a72019-03-17 00:27:29 +00001465 const TCGOpcode *this_list = g->opt_opc ? : vecop_list_empty;
1466 const TCGOpcode *hold_list = tcg_swap_vecop_list(this_list);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001467 TCGType type;
1468 uint32_t some;
1469
1470 check_size_align(oprsz, maxsz, dofs | aofs | bofs);
1471 check_overlap_3(dofs, aofs, bofs, maxsz);
1472
1473 type = 0;
1474 if (g->fniv) {
Richard Henderson53229a72019-03-17 00:27:29 +00001475 type = choose_vector_type(g->opt_opc, g->vece, oprsz, g->prefer_i64);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001476 }
1477 switch (type) {
1478 case TCG_TYPE_V256:
1479 /*
1480 * Recall that ARM SVE allows vector sizes that are not a
1481 * power of 2, but always a multiple of 16. The intent is
1482 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
1483 */
1484 some = QEMU_ALIGN_DOWN(oprsz, 32);
1485 expand_3i_vec(g->vece, dofs, aofs, bofs, some, 32, TCG_TYPE_V256,
Richard Hendersonb3ee7192024-03-11 11:26:59 -10001486 c, g->load_dest, g->write_aofs, g->fniv);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001487 if (some == oprsz) {
1488 break;
1489 }
1490 dofs += some;
1491 aofs += some;
1492 bofs += some;
1493 oprsz -= some;
1494 maxsz -= some;
1495 /* fallthru */
1496 case TCG_TYPE_V128:
1497 expand_3i_vec(g->vece, dofs, aofs, bofs, oprsz, 16, TCG_TYPE_V128,
Richard Hendersonb3ee7192024-03-11 11:26:59 -10001498 c, g->load_dest, g->write_aofs, g->fniv);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001499 break;
1500 case TCG_TYPE_V64:
1501 expand_3i_vec(g->vece, dofs, aofs, bofs, oprsz, 8, TCG_TYPE_V64,
Richard Hendersonb3ee7192024-03-11 11:26:59 -10001502 c, g->load_dest, g->write_aofs, g->fniv);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001503 break;
1504
1505 case 0:
1506 if (g->fni8 && check_size_impl(oprsz, 8)) {
Richard Hendersonb3ee7192024-03-11 11:26:59 -10001507 expand_3i_i64(dofs, aofs, bofs, oprsz, c,
1508 g->load_dest, g->write_aofs, g->fni8);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001509 } else if (g->fni4 && check_size_impl(oprsz, 4)) {
Richard Hendersonb3ee7192024-03-11 11:26:59 -10001510 expand_3i_i32(dofs, aofs, bofs, oprsz, c,
1511 g->load_dest, g->write_aofs, g->fni4);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001512 } else {
1513 assert(g->fno != NULL);
1514 tcg_gen_gvec_3_ool(dofs, aofs, bofs, oprsz, maxsz, c, g->fno);
Richard Henderson53229a72019-03-17 00:27:29 +00001515 oprsz = maxsz;
David Hildenbrande1227bb2019-04-16 20:52:21 +02001516 }
1517 break;
1518
1519 default:
1520 g_assert_not_reached();
1521 }
Richard Henderson53229a72019-03-17 00:27:29 +00001522 tcg_swap_vecop_list(hold_list);
David Hildenbrande1227bb2019-04-16 20:52:21 +02001523
1524 if (oprsz < maxsz) {
1525 expand_clr(dofs + oprsz, maxsz - oprsz);
1526 }
1527}
1528
Richard Hendersondb432672017-09-15 14:11:45 -07001529/* Expand a vector four-operand operation. */
1530void tcg_gen_gvec_4(uint32_t dofs, uint32_t aofs, uint32_t bofs, uint32_t cofs,
1531 uint32_t oprsz, uint32_t maxsz, const GVecGen4 *g)
1532{
Richard Henderson53229a72019-03-17 00:27:29 +00001533 const TCGOpcode *this_list = g->opt_opc ? : vecop_list_empty;
1534 const TCGOpcode *hold_list = tcg_swap_vecop_list(this_list);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001535 TCGType type;
1536 uint32_t some;
1537
Richard Hendersondb432672017-09-15 14:11:45 -07001538 check_size_align(oprsz, maxsz, dofs | aofs | bofs | cofs);
1539 check_overlap_4(dofs, aofs, bofs, cofs, maxsz);
1540
Richard Hendersonadb196c2018-02-17 08:30:16 -08001541 type = 0;
1542 if (g->fniv) {
Richard Henderson53229a72019-03-17 00:27:29 +00001543 type = choose_vector_type(g->opt_opc, g->vece, oprsz, g->prefer_i64);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001544 }
1545 switch (type) {
1546 case TCG_TYPE_V256:
1547 /* Recall that ARM SVE allows vector sizes that are not a
1548 * power of 2, but always a multiple of 16. The intent is
1549 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
1550 */
1551 some = QEMU_ALIGN_DOWN(oprsz, 32);
Richard Hendersondb432672017-09-15 14:11:45 -07001552 expand_4_vec(g->vece, dofs, aofs, bofs, cofs, some,
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001553 32, TCG_TYPE_V256, g->write_aofs, g->fniv);
Richard Hendersondb432672017-09-15 14:11:45 -07001554 if (some == oprsz) {
Richard Hendersonadb196c2018-02-17 08:30:16 -08001555 break;
Richard Hendersondb432672017-09-15 14:11:45 -07001556 }
1557 dofs += some;
1558 aofs += some;
1559 bofs += some;
1560 cofs += some;
1561 oprsz -= some;
1562 maxsz -= some;
Richard Hendersonadb196c2018-02-17 08:30:16 -08001563 /* fallthru */
1564 case TCG_TYPE_V128:
Richard Hendersondb432672017-09-15 14:11:45 -07001565 expand_4_vec(g->vece, dofs, aofs, bofs, cofs, oprsz,
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001566 16, TCG_TYPE_V128, g->write_aofs, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001567 break;
1568 case TCG_TYPE_V64:
Richard Hendersondb432672017-09-15 14:11:45 -07001569 expand_4_vec(g->vece, dofs, aofs, bofs, cofs, oprsz,
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001570 8, TCG_TYPE_V64, g->write_aofs, g->fniv);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001571 break;
1572
1573 case 0:
1574 if (g->fni8 && check_size_impl(oprsz, 8)) {
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001575 expand_4_i64(dofs, aofs, bofs, cofs, oprsz,
1576 g->write_aofs, g->fni8);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001577 } else if (g->fni4 && check_size_impl(oprsz, 4)) {
Richard Henderson5d6acdd2018-12-17 13:30:56 -08001578 expand_4_i32(dofs, aofs, bofs, cofs, oprsz,
1579 g->write_aofs, g->fni4);
Richard Hendersonadb196c2018-02-17 08:30:16 -08001580 } else {
1581 assert(g->fno != NULL);
1582 tcg_gen_gvec_4_ool(dofs, aofs, bofs, cofs,
1583 oprsz, maxsz, g->data, g->fno);
Richard Henderson53229a72019-03-17 00:27:29 +00001584 oprsz = maxsz;
Richard Hendersonadb196c2018-02-17 08:30:16 -08001585 }
1586 break;
1587
1588 default:
1589 g_assert_not_reached();
Richard Hendersondb432672017-09-15 14:11:45 -07001590 }
Richard Henderson53229a72019-03-17 00:27:29 +00001591 tcg_swap_vecop_list(hold_list);
Richard Hendersondb432672017-09-15 14:11:45 -07001592
Richard Hendersondb432672017-09-15 14:11:45 -07001593 if (oprsz < maxsz) {
1594 expand_clr(dofs + oprsz, maxsz - oprsz);
1595 }
1596}
1597
Matheus Ferst9620ae02022-03-02 06:51:38 +01001598/* Expand a vector four-operand operation. */
1599void tcg_gen_gvec_4i(uint32_t dofs, uint32_t aofs, uint32_t bofs, uint32_t cofs,
1600 uint32_t oprsz, uint32_t maxsz, int64_t c,
1601 const GVecGen4i *g)
1602{
1603 const TCGOpcode *this_list = g->opt_opc ? : vecop_list_empty;
1604 const TCGOpcode *hold_list = tcg_swap_vecop_list(this_list);
1605 TCGType type;
1606 uint32_t some;
1607
1608 check_size_align(oprsz, maxsz, dofs | aofs | bofs | cofs);
1609 check_overlap_4(dofs, aofs, bofs, cofs, maxsz);
1610
1611 type = 0;
1612 if (g->fniv) {
1613 type = choose_vector_type(g->opt_opc, g->vece, oprsz, g->prefer_i64);
1614 }
1615 switch (type) {
1616 case TCG_TYPE_V256:
1617 /*
1618 * Recall that ARM SVE allows vector sizes that are not a
1619 * power of 2, but always a multiple of 16. The intent is
1620 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
1621 */
1622 some = QEMU_ALIGN_DOWN(oprsz, 32);
1623 expand_4i_vec(g->vece, dofs, aofs, bofs, cofs, some,
1624 32, TCG_TYPE_V256, c, g->fniv);
1625 if (some == oprsz) {
1626 break;
1627 }
1628 dofs += some;
1629 aofs += some;
1630 bofs += some;
1631 cofs += some;
1632 oprsz -= some;
1633 maxsz -= some;
1634 /* fallthru */
1635 case TCG_TYPE_V128:
1636 expand_4i_vec(g->vece, dofs, aofs, bofs, cofs, oprsz,
1637 16, TCG_TYPE_V128, c, g->fniv);
1638 break;
1639 case TCG_TYPE_V64:
1640 expand_4i_vec(g->vece, dofs, aofs, bofs, cofs, oprsz,
1641 8, TCG_TYPE_V64, c, g->fniv);
1642 break;
1643
1644 case 0:
1645 if (g->fni8 && check_size_impl(oprsz, 8)) {
1646 expand_4i_i64(dofs, aofs, bofs, cofs, oprsz, c, g->fni8);
1647 } else if (g->fni4 && check_size_impl(oprsz, 4)) {
1648 expand_4i_i32(dofs, aofs, bofs, cofs, oprsz, c, g->fni4);
1649 } else {
1650 assert(g->fno != NULL);
1651 tcg_gen_gvec_4_ool(dofs, aofs, bofs, cofs,
1652 oprsz, maxsz, c, g->fno);
1653 oprsz = maxsz;
1654 }
1655 break;
1656
1657 default:
1658 g_assert_not_reached();
1659 }
1660 tcg_swap_vecop_list(hold_list);
1661
1662 if (oprsz < maxsz) {
1663 expand_clr(dofs + oprsz, maxsz - oprsz);
1664 }
1665}
1666
Richard Hendersondb432672017-09-15 14:11:45 -07001667/*
1668 * Expand specific vector operations.
1669 */
1670
1671static void vec_mov2(unsigned vece, TCGv_vec a, TCGv_vec b)
1672{
1673 tcg_gen_mov_vec(a, b);
1674}
1675
1676void tcg_gen_gvec_mov(unsigned vece, uint32_t dofs, uint32_t aofs,
1677 uint32_t oprsz, uint32_t maxsz)
1678{
1679 static const GVecGen2 g = {
1680 .fni8 = tcg_gen_mov_i64,
1681 .fniv = vec_mov2,
1682 .fno = gen_helper_gvec_mov,
1683 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1684 };
1685 if (dofs != aofs) {
1686 tcg_gen_gvec_2(dofs, aofs, oprsz, maxsz, &g);
1687 } else {
1688 check_size_align(oprsz, maxsz, dofs);
1689 if (oprsz < maxsz) {
1690 expand_clr(dofs + oprsz, maxsz - oprsz);
1691 }
1692 }
1693}
1694
1695void tcg_gen_gvec_dup_i32(unsigned vece, uint32_t dofs, uint32_t oprsz,
1696 uint32_t maxsz, TCGv_i32 in)
1697{
1698 check_size_align(oprsz, maxsz, dofs);
1699 tcg_debug_assert(vece <= MO_32);
1700 do_dup(vece, dofs, oprsz, maxsz, in, NULL, 0);
1701}
1702
1703void tcg_gen_gvec_dup_i64(unsigned vece, uint32_t dofs, uint32_t oprsz,
1704 uint32_t maxsz, TCGv_i64 in)
1705{
1706 check_size_align(oprsz, maxsz, dofs);
1707 tcg_debug_assert(vece <= MO_64);
1708 do_dup(vece, dofs, oprsz, maxsz, NULL, in, 0);
1709}
1710
1711void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs,
1712 uint32_t oprsz, uint32_t maxsz)
1713{
Richard Henderson532ba362019-05-16 12:48:18 -07001714 check_size_align(oprsz, maxsz, dofs);
Richard Henderson37ee55a2019-03-17 01:55:22 +00001715 if (vece <= MO_64) {
Richard Henderson532ba362019-05-16 12:48:18 -07001716 TCGType type = choose_vector_type(NULL, vece, oprsz, 0);
Richard Henderson37ee55a2019-03-17 01:55:22 +00001717 if (type != 0) {
1718 TCGv_vec t_vec = tcg_temp_new_vec(type);
Richard Hendersonad75a512023-09-13 16:37:36 -07001719 tcg_gen_dup_mem_vec(vece, t_vec, tcg_env, aofs);
Richard Henderson37ee55a2019-03-17 01:55:22 +00001720 do_dup_store(type, dofs, oprsz, maxsz, t_vec);
Richard Henderson532ba362019-05-16 12:48:18 -07001721 } else if (vece <= MO_32) {
Richard Henderson5dd48602023-01-29 13:26:49 -10001722 TCGv_i32 in = tcg_temp_ebb_new_i32();
Richard Henderson532ba362019-05-16 12:48:18 -07001723 switch (vece) {
1724 case MO_8:
Richard Hendersonad75a512023-09-13 16:37:36 -07001725 tcg_gen_ld8u_i32(in, tcg_env, aofs);
Richard Henderson532ba362019-05-16 12:48:18 -07001726 break;
1727 case MO_16:
Richard Hendersonad75a512023-09-13 16:37:36 -07001728 tcg_gen_ld16u_i32(in, tcg_env, aofs);
Richard Henderson532ba362019-05-16 12:48:18 -07001729 break;
1730 default:
Richard Hendersonad75a512023-09-13 16:37:36 -07001731 tcg_gen_ld_i32(in, tcg_env, aofs);
Richard Henderson532ba362019-05-16 12:48:18 -07001732 break;
1733 }
1734 do_dup(vece, dofs, oprsz, maxsz, in, NULL, 0);
1735 tcg_temp_free_i32(in);
1736 } else {
Richard Henderson5dd48602023-01-29 13:26:49 -10001737 TCGv_i64 in = tcg_temp_ebb_new_i64();
Richard Hendersonad75a512023-09-13 16:37:36 -07001738 tcg_gen_ld_i64(in, tcg_env, aofs);
Richard Henderson532ba362019-05-16 12:48:18 -07001739 do_dup(vece, dofs, oprsz, maxsz, NULL, in, 0);
1740 tcg_temp_free_i64(in);
Richard Henderson37ee55a2019-03-17 01:55:22 +00001741 }
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001742 } else if (vece == 4) {
Richard Hendersondb432672017-09-15 14:11:45 -07001743 /* 128-bit duplicate. */
Richard Hendersondb432672017-09-15 14:11:45 -07001744 int i;
1745
Richard Hendersondb432672017-09-15 14:11:45 -07001746 tcg_debug_assert(oprsz >= 16);
1747 if (TCG_TARGET_HAS_v128) {
1748 TCGv_vec in = tcg_temp_new_vec(TCG_TYPE_V128);
1749
Richard Hendersonad75a512023-09-13 16:37:36 -07001750 tcg_gen_ld_vec(in, tcg_env, aofs);
Richard Henderson6a176462020-08-14 15:02:57 -07001751 for (i = (aofs == dofs) * 16; i < oprsz; i += 16) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001752 tcg_gen_st_vec(in, tcg_env, dofs + i);
Richard Hendersondb432672017-09-15 14:11:45 -07001753 }
Richard Hendersondb432672017-09-15 14:11:45 -07001754 } else {
Richard Henderson5dd48602023-01-29 13:26:49 -10001755 TCGv_i64 in0 = tcg_temp_ebb_new_i64();
1756 TCGv_i64 in1 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -07001757
Richard Hendersonad75a512023-09-13 16:37:36 -07001758 tcg_gen_ld_i64(in0, tcg_env, aofs);
1759 tcg_gen_ld_i64(in1, tcg_env, aofs + 8);
Richard Henderson6a176462020-08-14 15:02:57 -07001760 for (i = (aofs == dofs) * 16; i < oprsz; i += 16) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001761 tcg_gen_st_i64(in0, tcg_env, dofs + i);
1762 tcg_gen_st_i64(in1, tcg_env, dofs + i + 8);
Richard Hendersondb432672017-09-15 14:11:45 -07001763 }
1764 tcg_temp_free_i64(in0);
1765 tcg_temp_free_i64(in1);
1766 }
Richard Henderson532ba362019-05-16 12:48:18 -07001767 if (oprsz < maxsz) {
1768 expand_clr(dofs + oprsz, maxsz - oprsz);
1769 }
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001770 } else if (vece == 5) {
1771 /* 256-bit duplicate. */
1772 int i;
1773
1774 tcg_debug_assert(oprsz >= 32);
1775 tcg_debug_assert(oprsz % 32 == 0);
1776 if (TCG_TARGET_HAS_v256) {
1777 TCGv_vec in = tcg_temp_new_vec(TCG_TYPE_V256);
1778
Richard Hendersonad75a512023-09-13 16:37:36 -07001779 tcg_gen_ld_vec(in, tcg_env, aofs);
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001780 for (i = (aofs == dofs) * 32; i < oprsz; i += 32) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001781 tcg_gen_st_vec(in, tcg_env, dofs + i);
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001782 }
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001783 } else if (TCG_TARGET_HAS_v128) {
1784 TCGv_vec in0 = tcg_temp_new_vec(TCG_TYPE_V128);
1785 TCGv_vec in1 = tcg_temp_new_vec(TCG_TYPE_V128);
1786
Richard Hendersonad75a512023-09-13 16:37:36 -07001787 tcg_gen_ld_vec(in0, tcg_env, aofs);
1788 tcg_gen_ld_vec(in1, tcg_env, aofs + 16);
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001789 for (i = (aofs == dofs) * 32; i < oprsz; i += 32) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001790 tcg_gen_st_vec(in0, tcg_env, dofs + i);
1791 tcg_gen_st_vec(in1, tcg_env, dofs + i + 16);
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001792 }
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001793 } else {
1794 TCGv_i64 in[4];
1795 int j;
1796
1797 for (j = 0; j < 4; ++j) {
Richard Henderson5dd48602023-01-29 13:26:49 -10001798 in[j] = tcg_temp_ebb_new_i64();
Richard Hendersonad75a512023-09-13 16:37:36 -07001799 tcg_gen_ld_i64(in[j], tcg_env, aofs + j * 8);
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001800 }
1801 for (i = (aofs == dofs) * 32; i < oprsz; i += 32) {
1802 for (j = 0; j < 4; ++j) {
Richard Hendersonad75a512023-09-13 16:37:36 -07001803 tcg_gen_st_i64(in[j], tcg_env, dofs + i + j * 8);
Richard Hendersonfe4b0b52020-06-17 14:13:43 -07001804 }
1805 }
1806 for (j = 0; j < 4; ++j) {
1807 tcg_temp_free_i64(in[j]);
1808 }
1809 }
1810 if (oprsz < maxsz) {
1811 expand_clr(dofs + oprsz, maxsz - oprsz);
1812 }
1813 } else {
1814 g_assert_not_reached();
Richard Hendersondb432672017-09-15 14:11:45 -07001815 }
1816}
1817
Richard Henderson44c94672020-03-28 14:17:11 -07001818void tcg_gen_gvec_dup_imm(unsigned vece, uint32_t dofs, uint32_t oprsz,
1819 uint32_t maxsz, uint64_t x)
1820{
1821 check_size_align(oprsz, maxsz, dofs);
1822 do_dup(vece, dofs, oprsz, maxsz, NULL, NULL, x);
1823}
1824
Richard Hendersondb432672017-09-15 14:11:45 -07001825void tcg_gen_gvec_not(unsigned vece, uint32_t dofs, uint32_t aofs,
1826 uint32_t oprsz, uint32_t maxsz)
1827{
1828 static const GVecGen2 g = {
1829 .fni8 = tcg_gen_not_i64,
1830 .fniv = tcg_gen_not_vec,
1831 .fno = gen_helper_gvec_not,
1832 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1833 };
1834 tcg_gen_gvec_2(dofs, aofs, oprsz, maxsz, &g);
1835}
1836
1837/* Perform a vector addition using normal addition and a mask. The mask
1838 should be the sign bit of each lane. This 6-operation form is more
1839 efficient than separate additions when there are 4 or more lanes in
1840 the 64-bit operation. */
1841static void gen_addv_mask(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 m)
1842{
Richard Henderson5dd48602023-01-29 13:26:49 -10001843 TCGv_i64 t1 = tcg_temp_ebb_new_i64();
1844 TCGv_i64 t2 = tcg_temp_ebb_new_i64();
1845 TCGv_i64 t3 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -07001846
1847 tcg_gen_andc_i64(t1, a, m);
1848 tcg_gen_andc_i64(t2, b, m);
1849 tcg_gen_xor_i64(t3, a, b);
1850 tcg_gen_add_i64(d, t1, t2);
1851 tcg_gen_and_i64(t3, t3, m);
1852 tcg_gen_xor_i64(d, d, t3);
1853
1854 tcg_temp_free_i64(t1);
1855 tcg_temp_free_i64(t2);
1856 tcg_temp_free_i64(t3);
1857}
1858
1859void tcg_gen_vec_add8_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
1860{
Richard Henderson88d40052020-09-03 18:18:08 -07001861 TCGv_i64 m = tcg_constant_i64(dup_const(MO_8, 0x80));
Richard Hendersondb432672017-09-15 14:11:45 -07001862 gen_addv_mask(d, a, b, m);
Richard Hendersondb432672017-09-15 14:11:45 -07001863}
1864
LIU Zhiwei448e7aa2021-06-24 18:50:20 +08001865void tcg_gen_vec_add8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
1866{
1867 TCGv_i32 m = tcg_constant_i32((int32_t)dup_const(MO_8, 0x80));
Richard Henderson5dd48602023-01-29 13:26:49 -10001868 TCGv_i32 t1 = tcg_temp_ebb_new_i32();
1869 TCGv_i32 t2 = tcg_temp_ebb_new_i32();
1870 TCGv_i32 t3 = tcg_temp_ebb_new_i32();
LIU Zhiwei448e7aa2021-06-24 18:50:20 +08001871
1872 tcg_gen_andc_i32(t1, a, m);
1873 tcg_gen_andc_i32(t2, b, m);
1874 tcg_gen_xor_i32(t3, a, b);
1875 tcg_gen_add_i32(d, t1, t2);
1876 tcg_gen_and_i32(t3, t3, m);
1877 tcg_gen_xor_i32(d, d, t3);
1878
1879 tcg_temp_free_i32(t1);
1880 tcg_temp_free_i32(t2);
1881 tcg_temp_free_i32(t3);
1882}
1883
Richard Hendersondb432672017-09-15 14:11:45 -07001884void tcg_gen_vec_add16_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
1885{
Richard Henderson88d40052020-09-03 18:18:08 -07001886 TCGv_i64 m = tcg_constant_i64(dup_const(MO_16, 0x8000));
Richard Hendersondb432672017-09-15 14:11:45 -07001887 gen_addv_mask(d, a, b, m);
Richard Hendersondb432672017-09-15 14:11:45 -07001888}
1889
LIU Zhiwei3d066e52021-06-24 18:50:19 +08001890void tcg_gen_vec_add16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
1891{
Richard Henderson5dd48602023-01-29 13:26:49 -10001892 TCGv_i32 t1 = tcg_temp_ebb_new_i32();
1893 TCGv_i32 t2 = tcg_temp_ebb_new_i32();
LIU Zhiwei3d066e52021-06-24 18:50:19 +08001894
1895 tcg_gen_andi_i32(t1, a, ~0xffff);
1896 tcg_gen_add_i32(t2, a, b);
1897 tcg_gen_add_i32(t1, t1, b);
1898 tcg_gen_deposit_i32(d, t1, t2, 0, 16);
1899
1900 tcg_temp_free_i32(t1);
1901 tcg_temp_free_i32(t2);
1902}
1903
Richard Hendersondb432672017-09-15 14:11:45 -07001904void tcg_gen_vec_add32_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
1905{
Richard Henderson5dd48602023-01-29 13:26:49 -10001906 TCGv_i64 t1 = tcg_temp_ebb_new_i64();
1907 TCGv_i64 t2 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -07001908
1909 tcg_gen_andi_i64(t1, a, ~0xffffffffull);
1910 tcg_gen_add_i64(t2, a, b);
1911 tcg_gen_add_i64(t1, t1, b);
1912 tcg_gen_deposit_i64(d, t1, t2, 0, 32);
1913
1914 tcg_temp_free_i64(t1);
1915 tcg_temp_free_i64(t2);
1916}
1917
Richard Henderson53229a72019-03-17 00:27:29 +00001918static const TCGOpcode vecop_list_add[] = { INDEX_op_add_vec, 0 };
1919
Richard Hendersondb432672017-09-15 14:11:45 -07001920void tcg_gen_gvec_add(unsigned vece, uint32_t dofs, uint32_t aofs,
1921 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
1922{
1923 static const GVecGen3 g[4] = {
1924 { .fni8 = tcg_gen_vec_add8_i64,
1925 .fniv = tcg_gen_add_vec,
1926 .fno = gen_helper_gvec_add8,
Richard Henderson53229a72019-03-17 00:27:29 +00001927 .opt_opc = vecop_list_add,
Richard Hendersondb432672017-09-15 14:11:45 -07001928 .vece = MO_8 },
1929 { .fni8 = tcg_gen_vec_add16_i64,
1930 .fniv = tcg_gen_add_vec,
1931 .fno = gen_helper_gvec_add16,
Richard Henderson53229a72019-03-17 00:27:29 +00001932 .opt_opc = vecop_list_add,
Richard Hendersondb432672017-09-15 14:11:45 -07001933 .vece = MO_16 },
1934 { .fni4 = tcg_gen_add_i32,
1935 .fniv = tcg_gen_add_vec,
1936 .fno = gen_helper_gvec_add32,
Richard Henderson53229a72019-03-17 00:27:29 +00001937 .opt_opc = vecop_list_add,
Richard Hendersondb432672017-09-15 14:11:45 -07001938 .vece = MO_32 },
1939 { .fni8 = tcg_gen_add_i64,
1940 .fniv = tcg_gen_add_vec,
1941 .fno = gen_helper_gvec_add64,
Richard Henderson53229a72019-03-17 00:27:29 +00001942 .opt_opc = vecop_list_add,
Richard Hendersondb432672017-09-15 14:11:45 -07001943 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1944 .vece = MO_64 },
1945 };
1946
1947 tcg_debug_assert(vece <= MO_64);
1948 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
1949}
1950
Richard Henderson22fc3522017-12-21 10:58:36 -08001951void tcg_gen_gvec_adds(unsigned vece, uint32_t dofs, uint32_t aofs,
1952 TCGv_i64 c, uint32_t oprsz, uint32_t maxsz)
1953{
1954 static const GVecGen2s g[4] = {
1955 { .fni8 = tcg_gen_vec_add8_i64,
1956 .fniv = tcg_gen_add_vec,
1957 .fno = gen_helper_gvec_adds8,
Richard Henderson53229a72019-03-17 00:27:29 +00001958 .opt_opc = vecop_list_add,
Richard Henderson22fc3522017-12-21 10:58:36 -08001959 .vece = MO_8 },
1960 { .fni8 = tcg_gen_vec_add16_i64,
1961 .fniv = tcg_gen_add_vec,
1962 .fno = gen_helper_gvec_adds16,
Richard Henderson53229a72019-03-17 00:27:29 +00001963 .opt_opc = vecop_list_add,
Richard Henderson22fc3522017-12-21 10:58:36 -08001964 .vece = MO_16 },
1965 { .fni4 = tcg_gen_add_i32,
1966 .fniv = tcg_gen_add_vec,
1967 .fno = gen_helper_gvec_adds32,
Richard Henderson53229a72019-03-17 00:27:29 +00001968 .opt_opc = vecop_list_add,
Richard Henderson22fc3522017-12-21 10:58:36 -08001969 .vece = MO_32 },
1970 { .fni8 = tcg_gen_add_i64,
1971 .fniv = tcg_gen_add_vec,
1972 .fno = gen_helper_gvec_adds64,
Richard Henderson53229a72019-03-17 00:27:29 +00001973 .opt_opc = vecop_list_add,
Richard Henderson22fc3522017-12-21 10:58:36 -08001974 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
1975 .vece = MO_64 },
1976 };
1977
1978 tcg_debug_assert(vece <= MO_64);
1979 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, c, &g[vece]);
1980}
1981
1982void tcg_gen_gvec_addi(unsigned vece, uint32_t dofs, uint32_t aofs,
1983 int64_t c, uint32_t oprsz, uint32_t maxsz)
1984{
Richard Henderson88d40052020-09-03 18:18:08 -07001985 TCGv_i64 tmp = tcg_constant_i64(c);
Richard Henderson22fc3522017-12-21 10:58:36 -08001986 tcg_gen_gvec_adds(vece, dofs, aofs, tmp, oprsz, maxsz);
Richard Henderson22fc3522017-12-21 10:58:36 -08001987}
1988
Richard Henderson53229a72019-03-17 00:27:29 +00001989static const TCGOpcode vecop_list_sub[] = { INDEX_op_sub_vec, 0 };
1990
Richard Henderson22fc3522017-12-21 10:58:36 -08001991void tcg_gen_gvec_subs(unsigned vece, uint32_t dofs, uint32_t aofs,
1992 TCGv_i64 c, uint32_t oprsz, uint32_t maxsz)
1993{
1994 static const GVecGen2s g[4] = {
1995 { .fni8 = tcg_gen_vec_sub8_i64,
1996 .fniv = tcg_gen_sub_vec,
1997 .fno = gen_helper_gvec_subs8,
Richard Henderson53229a72019-03-17 00:27:29 +00001998 .opt_opc = vecop_list_sub,
Richard Henderson22fc3522017-12-21 10:58:36 -08001999 .vece = MO_8 },
2000 { .fni8 = tcg_gen_vec_sub16_i64,
2001 .fniv = tcg_gen_sub_vec,
2002 .fno = gen_helper_gvec_subs16,
Richard Henderson53229a72019-03-17 00:27:29 +00002003 .opt_opc = vecop_list_sub,
Richard Henderson22fc3522017-12-21 10:58:36 -08002004 .vece = MO_16 },
2005 { .fni4 = tcg_gen_sub_i32,
2006 .fniv = tcg_gen_sub_vec,
2007 .fno = gen_helper_gvec_subs32,
Richard Henderson53229a72019-03-17 00:27:29 +00002008 .opt_opc = vecop_list_sub,
Richard Henderson22fc3522017-12-21 10:58:36 -08002009 .vece = MO_32 },
2010 { .fni8 = tcg_gen_sub_i64,
2011 .fniv = tcg_gen_sub_vec,
2012 .fno = gen_helper_gvec_subs64,
Richard Henderson53229a72019-03-17 00:27:29 +00002013 .opt_opc = vecop_list_sub,
Richard Henderson22fc3522017-12-21 10:58:36 -08002014 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2015 .vece = MO_64 },
2016 };
2017
2018 tcg_debug_assert(vece <= MO_64);
2019 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, c, &g[vece]);
2020}
2021
Richard Hendersondb432672017-09-15 14:11:45 -07002022/* Perform a vector subtraction using normal subtraction and a mask.
2023 Compare gen_addv_mask above. */
2024static void gen_subv_mask(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 m)
2025{
Richard Henderson5dd48602023-01-29 13:26:49 -10002026 TCGv_i64 t1 = tcg_temp_ebb_new_i64();
2027 TCGv_i64 t2 = tcg_temp_ebb_new_i64();
2028 TCGv_i64 t3 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -07002029
2030 tcg_gen_or_i64(t1, a, m);
2031 tcg_gen_andc_i64(t2, b, m);
2032 tcg_gen_eqv_i64(t3, a, b);
2033 tcg_gen_sub_i64(d, t1, t2);
2034 tcg_gen_and_i64(t3, t3, m);
2035 tcg_gen_xor_i64(d, d, t3);
2036
2037 tcg_temp_free_i64(t1);
2038 tcg_temp_free_i64(t2);
2039 tcg_temp_free_i64(t3);
2040}
2041
2042void tcg_gen_vec_sub8_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
2043{
Richard Henderson88d40052020-09-03 18:18:08 -07002044 TCGv_i64 m = tcg_constant_i64(dup_const(MO_8, 0x80));
Richard Hendersondb432672017-09-15 14:11:45 -07002045 gen_subv_mask(d, a, b, m);
Richard Hendersondb432672017-09-15 14:11:45 -07002046}
2047
LIU Zhiwei448e7aa2021-06-24 18:50:20 +08002048void tcg_gen_vec_sub8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
2049{
2050 TCGv_i32 m = tcg_constant_i32((int32_t)dup_const(MO_8, 0x80));
Richard Henderson5dd48602023-01-29 13:26:49 -10002051 TCGv_i32 t1 = tcg_temp_ebb_new_i32();
2052 TCGv_i32 t2 = tcg_temp_ebb_new_i32();
2053 TCGv_i32 t3 = tcg_temp_ebb_new_i32();
LIU Zhiwei448e7aa2021-06-24 18:50:20 +08002054
2055 tcg_gen_or_i32(t1, a, m);
2056 tcg_gen_andc_i32(t2, b, m);
2057 tcg_gen_eqv_i32(t3, a, b);
2058 tcg_gen_sub_i32(d, t1, t2);
2059 tcg_gen_and_i32(t3, t3, m);
2060 tcg_gen_xor_i32(d, d, t3);
2061
2062 tcg_temp_free_i32(t1);
2063 tcg_temp_free_i32(t2);
2064 tcg_temp_free_i32(t3);
2065}
2066
Richard Hendersondb432672017-09-15 14:11:45 -07002067void tcg_gen_vec_sub16_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
2068{
Richard Henderson88d40052020-09-03 18:18:08 -07002069 TCGv_i64 m = tcg_constant_i64(dup_const(MO_16, 0x8000));
Richard Hendersondb432672017-09-15 14:11:45 -07002070 gen_subv_mask(d, a, b, m);
Richard Hendersondb432672017-09-15 14:11:45 -07002071}
2072
LIU Zhiwei3d066e52021-06-24 18:50:19 +08002073void tcg_gen_vec_sub16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
2074{
Richard Henderson5dd48602023-01-29 13:26:49 -10002075 TCGv_i32 t1 = tcg_temp_ebb_new_i32();
2076 TCGv_i32 t2 = tcg_temp_ebb_new_i32();
LIU Zhiwei3d066e52021-06-24 18:50:19 +08002077
2078 tcg_gen_andi_i32(t1, b, ~0xffff);
2079 tcg_gen_sub_i32(t2, a, b);
2080 tcg_gen_sub_i32(t1, a, t1);
2081 tcg_gen_deposit_i32(d, t1, t2, 0, 16);
2082
2083 tcg_temp_free_i32(t1);
2084 tcg_temp_free_i32(t2);
2085}
2086
Richard Hendersondb432672017-09-15 14:11:45 -07002087void tcg_gen_vec_sub32_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
2088{
Richard Henderson5dd48602023-01-29 13:26:49 -10002089 TCGv_i64 t1 = tcg_temp_ebb_new_i64();
2090 TCGv_i64 t2 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -07002091
2092 tcg_gen_andi_i64(t1, b, ~0xffffffffull);
2093 tcg_gen_sub_i64(t2, a, b);
2094 tcg_gen_sub_i64(t1, a, t1);
2095 tcg_gen_deposit_i64(d, t1, t2, 0, 32);
2096
2097 tcg_temp_free_i64(t1);
2098 tcg_temp_free_i64(t2);
2099}
2100
2101void tcg_gen_gvec_sub(unsigned vece, uint32_t dofs, uint32_t aofs,
2102 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2103{
2104 static const GVecGen3 g[4] = {
2105 { .fni8 = tcg_gen_vec_sub8_i64,
2106 .fniv = tcg_gen_sub_vec,
2107 .fno = gen_helper_gvec_sub8,
Richard Henderson53229a72019-03-17 00:27:29 +00002108 .opt_opc = vecop_list_sub,
Richard Hendersondb432672017-09-15 14:11:45 -07002109 .vece = MO_8 },
2110 { .fni8 = tcg_gen_vec_sub16_i64,
2111 .fniv = tcg_gen_sub_vec,
2112 .fno = gen_helper_gvec_sub16,
Richard Henderson53229a72019-03-17 00:27:29 +00002113 .opt_opc = vecop_list_sub,
Richard Hendersondb432672017-09-15 14:11:45 -07002114 .vece = MO_16 },
2115 { .fni4 = tcg_gen_sub_i32,
2116 .fniv = tcg_gen_sub_vec,
2117 .fno = gen_helper_gvec_sub32,
Richard Henderson53229a72019-03-17 00:27:29 +00002118 .opt_opc = vecop_list_sub,
Richard Hendersondb432672017-09-15 14:11:45 -07002119 .vece = MO_32 },
2120 { .fni8 = tcg_gen_sub_i64,
2121 .fniv = tcg_gen_sub_vec,
2122 .fno = gen_helper_gvec_sub64,
Richard Henderson53229a72019-03-17 00:27:29 +00002123 .opt_opc = vecop_list_sub,
Richard Hendersondb432672017-09-15 14:11:45 -07002124 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2125 .vece = MO_64 },
2126 };
2127
2128 tcg_debug_assert(vece <= MO_64);
2129 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2130}
2131
Richard Henderson53229a72019-03-17 00:27:29 +00002132static const TCGOpcode vecop_list_mul[] = { INDEX_op_mul_vec, 0 };
2133
Richard Henderson37740302017-11-21 10:11:14 +01002134void tcg_gen_gvec_mul(unsigned vece, uint32_t dofs, uint32_t aofs,
2135 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2136{
2137 static const GVecGen3 g[4] = {
2138 { .fniv = tcg_gen_mul_vec,
2139 .fno = gen_helper_gvec_mul8,
Richard Henderson53229a72019-03-17 00:27:29 +00002140 .opt_opc = vecop_list_mul,
Richard Henderson37740302017-11-21 10:11:14 +01002141 .vece = MO_8 },
2142 { .fniv = tcg_gen_mul_vec,
2143 .fno = gen_helper_gvec_mul16,
Richard Henderson53229a72019-03-17 00:27:29 +00002144 .opt_opc = vecop_list_mul,
Richard Henderson37740302017-11-21 10:11:14 +01002145 .vece = MO_16 },
2146 { .fni4 = tcg_gen_mul_i32,
2147 .fniv = tcg_gen_mul_vec,
2148 .fno = gen_helper_gvec_mul32,
Richard Henderson53229a72019-03-17 00:27:29 +00002149 .opt_opc = vecop_list_mul,
Richard Henderson37740302017-11-21 10:11:14 +01002150 .vece = MO_32 },
2151 { .fni8 = tcg_gen_mul_i64,
2152 .fniv = tcg_gen_mul_vec,
2153 .fno = gen_helper_gvec_mul64,
Richard Henderson53229a72019-03-17 00:27:29 +00002154 .opt_opc = vecop_list_mul,
Richard Henderson37740302017-11-21 10:11:14 +01002155 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2156 .vece = MO_64 },
2157 };
2158
2159 tcg_debug_assert(vece <= MO_64);
2160 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2161}
2162
Richard Henderson22fc3522017-12-21 10:58:36 -08002163void tcg_gen_gvec_muls(unsigned vece, uint32_t dofs, uint32_t aofs,
2164 TCGv_i64 c, uint32_t oprsz, uint32_t maxsz)
2165{
2166 static const GVecGen2s g[4] = {
2167 { .fniv = tcg_gen_mul_vec,
2168 .fno = gen_helper_gvec_muls8,
Richard Henderson53229a72019-03-17 00:27:29 +00002169 .opt_opc = vecop_list_mul,
Richard Henderson22fc3522017-12-21 10:58:36 -08002170 .vece = MO_8 },
2171 { .fniv = tcg_gen_mul_vec,
2172 .fno = gen_helper_gvec_muls16,
Richard Henderson53229a72019-03-17 00:27:29 +00002173 .opt_opc = vecop_list_mul,
Richard Henderson22fc3522017-12-21 10:58:36 -08002174 .vece = MO_16 },
2175 { .fni4 = tcg_gen_mul_i32,
2176 .fniv = tcg_gen_mul_vec,
2177 .fno = gen_helper_gvec_muls32,
Richard Henderson53229a72019-03-17 00:27:29 +00002178 .opt_opc = vecop_list_mul,
Richard Henderson22fc3522017-12-21 10:58:36 -08002179 .vece = MO_32 },
2180 { .fni8 = tcg_gen_mul_i64,
2181 .fniv = tcg_gen_mul_vec,
2182 .fno = gen_helper_gvec_muls64,
Richard Henderson53229a72019-03-17 00:27:29 +00002183 .opt_opc = vecop_list_mul,
Richard Henderson22fc3522017-12-21 10:58:36 -08002184 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2185 .vece = MO_64 },
2186 };
2187
2188 tcg_debug_assert(vece <= MO_64);
2189 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, c, &g[vece]);
2190}
2191
2192void tcg_gen_gvec_muli(unsigned vece, uint32_t dofs, uint32_t aofs,
2193 int64_t c, uint32_t oprsz, uint32_t maxsz)
2194{
Richard Henderson88d40052020-09-03 18:18:08 -07002195 TCGv_i64 tmp = tcg_constant_i64(c);
Richard Henderson22fc3522017-12-21 10:58:36 -08002196 tcg_gen_gvec_muls(vece, dofs, aofs, tmp, oprsz, maxsz);
Richard Henderson22fc3522017-12-21 10:58:36 -08002197}
2198
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002199void tcg_gen_gvec_ssadd(unsigned vece, uint32_t dofs, uint32_t aofs,
2200 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2201{
Richard Henderson53229a72019-03-17 00:27:29 +00002202 static const TCGOpcode vecop_list[] = { INDEX_op_ssadd_vec, 0 };
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002203 static const GVecGen3 g[4] = {
Richard Henderson8afaf052018-12-17 18:01:47 -08002204 { .fniv = tcg_gen_ssadd_vec,
2205 .fno = gen_helper_gvec_ssadd8,
Richard Henderson53229a72019-03-17 00:27:29 +00002206 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002207 .vece = MO_8 },
2208 { .fniv = tcg_gen_ssadd_vec,
2209 .fno = gen_helper_gvec_ssadd16,
Richard Henderson53229a72019-03-17 00:27:29 +00002210 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002211 .vece = MO_16 },
2212 { .fniv = tcg_gen_ssadd_vec,
2213 .fno = gen_helper_gvec_ssadd32,
Richard Henderson53229a72019-03-17 00:27:29 +00002214 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002215 .vece = MO_32 },
2216 { .fniv = tcg_gen_ssadd_vec,
2217 .fno = gen_helper_gvec_ssadd64,
Richard Henderson53229a72019-03-17 00:27:29 +00002218 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002219 .vece = MO_64 },
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002220 };
2221 tcg_debug_assert(vece <= MO_64);
2222 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2223}
2224
2225void tcg_gen_gvec_sssub(unsigned vece, uint32_t dofs, uint32_t aofs,
2226 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2227{
Richard Henderson53229a72019-03-17 00:27:29 +00002228 static const TCGOpcode vecop_list[] = { INDEX_op_sssub_vec, 0 };
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002229 static const GVecGen3 g[4] = {
Richard Henderson8afaf052018-12-17 18:01:47 -08002230 { .fniv = tcg_gen_sssub_vec,
2231 .fno = gen_helper_gvec_sssub8,
Richard Henderson53229a72019-03-17 00:27:29 +00002232 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002233 .vece = MO_8 },
2234 { .fniv = tcg_gen_sssub_vec,
2235 .fno = gen_helper_gvec_sssub16,
Richard Henderson53229a72019-03-17 00:27:29 +00002236 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002237 .vece = MO_16 },
2238 { .fniv = tcg_gen_sssub_vec,
2239 .fno = gen_helper_gvec_sssub32,
Richard Henderson53229a72019-03-17 00:27:29 +00002240 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002241 .vece = MO_32 },
2242 { .fniv = tcg_gen_sssub_vec,
2243 .fno = gen_helper_gvec_sssub64,
Richard Henderson53229a72019-03-17 00:27:29 +00002244 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002245 .vece = MO_64 },
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002246 };
2247 tcg_debug_assert(vece <= MO_64);
2248 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2249}
2250
Richard Henderson8afaf052018-12-17 18:01:47 -08002251static void tcg_gen_usadd_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002252{
Richard Henderson88d40052020-09-03 18:18:08 -07002253 TCGv_i32 max = tcg_constant_i32(-1);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002254 tcg_gen_add_i32(d, a, b);
2255 tcg_gen_movcond_i32(TCG_COND_LTU, d, d, a, max, d);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002256}
2257
Richard Henderson8afaf052018-12-17 18:01:47 -08002258static void tcg_gen_usadd_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002259{
Richard Henderson88d40052020-09-03 18:18:08 -07002260 TCGv_i64 max = tcg_constant_i64(-1);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002261 tcg_gen_add_i64(d, a, b);
2262 tcg_gen_movcond_i64(TCG_COND_LTU, d, d, a, max, d);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002263}
2264
2265void tcg_gen_gvec_usadd(unsigned vece, uint32_t dofs, uint32_t aofs,
2266 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2267{
Richard Henderson53229a72019-03-17 00:27:29 +00002268 static const TCGOpcode vecop_list[] = { INDEX_op_usadd_vec, 0 };
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002269 static const GVecGen3 g[4] = {
Richard Henderson8afaf052018-12-17 18:01:47 -08002270 { .fniv = tcg_gen_usadd_vec,
2271 .fno = gen_helper_gvec_usadd8,
Richard Henderson53229a72019-03-17 00:27:29 +00002272 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002273 .vece = MO_8 },
2274 { .fniv = tcg_gen_usadd_vec,
2275 .fno = gen_helper_gvec_usadd16,
Richard Henderson53229a72019-03-17 00:27:29 +00002276 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002277 .vece = MO_16 },
2278 { .fni4 = tcg_gen_usadd_i32,
2279 .fniv = tcg_gen_usadd_vec,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002280 .fno = gen_helper_gvec_usadd32,
Richard Henderson53229a72019-03-17 00:27:29 +00002281 .opt_opc = vecop_list,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002282 .vece = MO_32 },
Richard Henderson8afaf052018-12-17 18:01:47 -08002283 { .fni8 = tcg_gen_usadd_i64,
2284 .fniv = tcg_gen_usadd_vec,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002285 .fno = gen_helper_gvec_usadd64,
Richard Henderson53229a72019-03-17 00:27:29 +00002286 .opt_opc = vecop_list,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002287 .vece = MO_64 }
2288 };
2289 tcg_debug_assert(vece <= MO_64);
2290 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2291}
2292
Richard Henderson8afaf052018-12-17 18:01:47 -08002293static void tcg_gen_ussub_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002294{
Richard Henderson88d40052020-09-03 18:18:08 -07002295 TCGv_i32 min = tcg_constant_i32(0);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002296 tcg_gen_sub_i32(d, a, b);
2297 tcg_gen_movcond_i32(TCG_COND_LTU, d, a, b, min, d);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002298}
2299
Richard Henderson8afaf052018-12-17 18:01:47 -08002300static void tcg_gen_ussub_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002301{
Richard Henderson88d40052020-09-03 18:18:08 -07002302 TCGv_i64 min = tcg_constant_i64(0);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002303 tcg_gen_sub_i64(d, a, b);
2304 tcg_gen_movcond_i64(TCG_COND_LTU, d, a, b, min, d);
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002305}
2306
2307void tcg_gen_gvec_ussub(unsigned vece, uint32_t dofs, uint32_t aofs,
2308 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2309{
Richard Henderson53229a72019-03-17 00:27:29 +00002310 static const TCGOpcode vecop_list[] = { INDEX_op_ussub_vec, 0 };
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002311 static const GVecGen3 g[4] = {
Richard Henderson8afaf052018-12-17 18:01:47 -08002312 { .fniv = tcg_gen_ussub_vec,
2313 .fno = gen_helper_gvec_ussub8,
Richard Henderson53229a72019-03-17 00:27:29 +00002314 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002315 .vece = MO_8 },
2316 { .fniv = tcg_gen_ussub_vec,
2317 .fno = gen_helper_gvec_ussub16,
Richard Henderson53229a72019-03-17 00:27:29 +00002318 .opt_opc = vecop_list,
Richard Henderson8afaf052018-12-17 18:01:47 -08002319 .vece = MO_16 },
2320 { .fni4 = tcg_gen_ussub_i32,
2321 .fniv = tcg_gen_ussub_vec,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002322 .fno = gen_helper_gvec_ussub32,
Richard Henderson53229a72019-03-17 00:27:29 +00002323 .opt_opc = vecop_list,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002324 .vece = MO_32 },
Richard Henderson8afaf052018-12-17 18:01:47 -08002325 { .fni8 = tcg_gen_ussub_i64,
2326 .fniv = tcg_gen_ussub_vec,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002327 .fno = gen_helper_gvec_ussub64,
Richard Henderson53229a72019-03-17 00:27:29 +00002328 .opt_opc = vecop_list,
Richard Hendersonf49b12c2017-12-14 10:45:20 -06002329 .vece = MO_64 }
2330 };
2331 tcg_debug_assert(vece <= MO_64);
2332 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2333}
2334
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002335void tcg_gen_gvec_smin(unsigned vece, uint32_t dofs, uint32_t aofs,
2336 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2337{
Richard Henderson53229a72019-03-17 00:27:29 +00002338 static const TCGOpcode vecop_list[] = { INDEX_op_smin_vec, 0 };
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002339 static const GVecGen3 g[4] = {
2340 { .fniv = tcg_gen_smin_vec,
2341 .fno = gen_helper_gvec_smin8,
Richard Henderson53229a72019-03-17 00:27:29 +00002342 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002343 .vece = MO_8 },
2344 { .fniv = tcg_gen_smin_vec,
2345 .fno = gen_helper_gvec_smin16,
Richard Henderson53229a72019-03-17 00:27:29 +00002346 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002347 .vece = MO_16 },
2348 { .fni4 = tcg_gen_smin_i32,
2349 .fniv = tcg_gen_smin_vec,
2350 .fno = gen_helper_gvec_smin32,
Richard Henderson53229a72019-03-17 00:27:29 +00002351 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002352 .vece = MO_32 },
2353 { .fni8 = tcg_gen_smin_i64,
2354 .fniv = tcg_gen_smin_vec,
2355 .fno = gen_helper_gvec_smin64,
Richard Henderson53229a72019-03-17 00:27:29 +00002356 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002357 .vece = MO_64 }
2358 };
2359 tcg_debug_assert(vece <= MO_64);
2360 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2361}
2362
2363void tcg_gen_gvec_umin(unsigned vece, uint32_t dofs, uint32_t aofs,
2364 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2365{
Richard Henderson53229a72019-03-17 00:27:29 +00002366 static const TCGOpcode vecop_list[] = { INDEX_op_umin_vec, 0 };
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002367 static const GVecGen3 g[4] = {
2368 { .fniv = tcg_gen_umin_vec,
2369 .fno = gen_helper_gvec_umin8,
Richard Henderson53229a72019-03-17 00:27:29 +00002370 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002371 .vece = MO_8 },
2372 { .fniv = tcg_gen_umin_vec,
2373 .fno = gen_helper_gvec_umin16,
Richard Henderson53229a72019-03-17 00:27:29 +00002374 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002375 .vece = MO_16 },
2376 { .fni4 = tcg_gen_umin_i32,
2377 .fniv = tcg_gen_umin_vec,
2378 .fno = gen_helper_gvec_umin32,
Richard Henderson53229a72019-03-17 00:27:29 +00002379 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002380 .vece = MO_32 },
2381 { .fni8 = tcg_gen_umin_i64,
2382 .fniv = tcg_gen_umin_vec,
2383 .fno = gen_helper_gvec_umin64,
Richard Henderson53229a72019-03-17 00:27:29 +00002384 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002385 .vece = MO_64 }
2386 };
2387 tcg_debug_assert(vece <= MO_64);
2388 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2389}
2390
2391void tcg_gen_gvec_smax(unsigned vece, uint32_t dofs, uint32_t aofs,
2392 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2393{
Richard Henderson53229a72019-03-17 00:27:29 +00002394 static const TCGOpcode vecop_list[] = { INDEX_op_smax_vec, 0 };
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002395 static const GVecGen3 g[4] = {
2396 { .fniv = tcg_gen_smax_vec,
2397 .fno = gen_helper_gvec_smax8,
Richard Henderson53229a72019-03-17 00:27:29 +00002398 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002399 .vece = MO_8 },
2400 { .fniv = tcg_gen_smax_vec,
2401 .fno = gen_helper_gvec_smax16,
Richard Henderson53229a72019-03-17 00:27:29 +00002402 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002403 .vece = MO_16 },
2404 { .fni4 = tcg_gen_smax_i32,
2405 .fniv = tcg_gen_smax_vec,
2406 .fno = gen_helper_gvec_smax32,
Richard Henderson53229a72019-03-17 00:27:29 +00002407 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002408 .vece = MO_32 },
2409 { .fni8 = tcg_gen_smax_i64,
2410 .fniv = tcg_gen_smax_vec,
2411 .fno = gen_helper_gvec_smax64,
Richard Henderson53229a72019-03-17 00:27:29 +00002412 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002413 .vece = MO_64 }
2414 };
2415 tcg_debug_assert(vece <= MO_64);
2416 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2417}
2418
2419void tcg_gen_gvec_umax(unsigned vece, uint32_t dofs, uint32_t aofs,
2420 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2421{
Richard Henderson53229a72019-03-17 00:27:29 +00002422 static const TCGOpcode vecop_list[] = { INDEX_op_umax_vec, 0 };
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002423 static const GVecGen3 g[4] = {
2424 { .fniv = tcg_gen_umax_vec,
2425 .fno = gen_helper_gvec_umax8,
Richard Henderson53229a72019-03-17 00:27:29 +00002426 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002427 .vece = MO_8 },
2428 { .fniv = tcg_gen_umax_vec,
2429 .fno = gen_helper_gvec_umax16,
Richard Henderson53229a72019-03-17 00:27:29 +00002430 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002431 .vece = MO_16 },
2432 { .fni4 = tcg_gen_umax_i32,
2433 .fniv = tcg_gen_umax_vec,
2434 .fno = gen_helper_gvec_umax32,
Richard Henderson53229a72019-03-17 00:27:29 +00002435 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002436 .vece = MO_32 },
2437 { .fni8 = tcg_gen_umax_i64,
2438 .fniv = tcg_gen_umax_vec,
2439 .fno = gen_helper_gvec_umax64,
Richard Henderson53229a72019-03-17 00:27:29 +00002440 .opt_opc = vecop_list,
Richard Hendersondd0a0fc2018-12-17 19:35:46 -08002441 .vece = MO_64 }
2442 };
2443 tcg_debug_assert(vece <= MO_64);
2444 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
2445}
2446
Richard Hendersondb432672017-09-15 14:11:45 -07002447/* Perform a vector negation using normal negation and a mask.
2448 Compare gen_subv_mask above. */
2449static void gen_negv_mask(TCGv_i64 d, TCGv_i64 b, TCGv_i64 m)
2450{
Richard Henderson5dd48602023-01-29 13:26:49 -10002451 TCGv_i64 t2 = tcg_temp_ebb_new_i64();
2452 TCGv_i64 t3 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -07002453
2454 tcg_gen_andc_i64(t3, m, b);
2455 tcg_gen_andc_i64(t2, b, m);
2456 tcg_gen_sub_i64(d, m, t2);
2457 tcg_gen_xor_i64(d, d, t3);
2458
2459 tcg_temp_free_i64(t2);
2460 tcg_temp_free_i64(t3);
2461}
2462
2463void tcg_gen_vec_neg8_i64(TCGv_i64 d, TCGv_i64 b)
2464{
Richard Henderson88d40052020-09-03 18:18:08 -07002465 TCGv_i64 m = tcg_constant_i64(dup_const(MO_8, 0x80));
Richard Hendersondb432672017-09-15 14:11:45 -07002466 gen_negv_mask(d, b, m);
Richard Hendersondb432672017-09-15 14:11:45 -07002467}
2468
2469void tcg_gen_vec_neg16_i64(TCGv_i64 d, TCGv_i64 b)
2470{
Richard Henderson88d40052020-09-03 18:18:08 -07002471 TCGv_i64 m = tcg_constant_i64(dup_const(MO_16, 0x8000));
Richard Hendersondb432672017-09-15 14:11:45 -07002472 gen_negv_mask(d, b, m);
Richard Hendersondb432672017-09-15 14:11:45 -07002473}
2474
2475void tcg_gen_vec_neg32_i64(TCGv_i64 d, TCGv_i64 b)
2476{
Richard Henderson5dd48602023-01-29 13:26:49 -10002477 TCGv_i64 t1 = tcg_temp_ebb_new_i64();
2478 TCGv_i64 t2 = tcg_temp_ebb_new_i64();
Richard Hendersondb432672017-09-15 14:11:45 -07002479
2480 tcg_gen_andi_i64(t1, b, ~0xffffffffull);
2481 tcg_gen_neg_i64(t2, b);
2482 tcg_gen_neg_i64(t1, t1);
2483 tcg_gen_deposit_i64(d, t1, t2, 0, 32);
2484
2485 tcg_temp_free_i64(t1);
2486 tcg_temp_free_i64(t2);
2487}
2488
2489void tcg_gen_gvec_neg(unsigned vece, uint32_t dofs, uint32_t aofs,
2490 uint32_t oprsz, uint32_t maxsz)
2491{
Richard Henderson53229a72019-03-17 00:27:29 +00002492 static const TCGOpcode vecop_list[] = { INDEX_op_neg_vec, 0 };
Richard Hendersondb432672017-09-15 14:11:45 -07002493 static const GVecGen2 g[4] = {
2494 { .fni8 = tcg_gen_vec_neg8_i64,
2495 .fniv = tcg_gen_neg_vec,
2496 .fno = gen_helper_gvec_neg8,
Richard Henderson53229a72019-03-17 00:27:29 +00002497 .opt_opc = vecop_list,
Richard Hendersondb432672017-09-15 14:11:45 -07002498 .vece = MO_8 },
2499 { .fni8 = tcg_gen_vec_neg16_i64,
2500 .fniv = tcg_gen_neg_vec,
2501 .fno = gen_helper_gvec_neg16,
Richard Henderson53229a72019-03-17 00:27:29 +00002502 .opt_opc = vecop_list,
Richard Hendersondb432672017-09-15 14:11:45 -07002503 .vece = MO_16 },
2504 { .fni4 = tcg_gen_neg_i32,
2505 .fniv = tcg_gen_neg_vec,
2506 .fno = gen_helper_gvec_neg32,
Richard Henderson53229a72019-03-17 00:27:29 +00002507 .opt_opc = vecop_list,
Richard Hendersondb432672017-09-15 14:11:45 -07002508 .vece = MO_32 },
2509 { .fni8 = tcg_gen_neg_i64,
2510 .fniv = tcg_gen_neg_vec,
2511 .fno = gen_helper_gvec_neg64,
Richard Henderson53229a72019-03-17 00:27:29 +00002512 .opt_opc = vecop_list,
Richard Hendersondb432672017-09-15 14:11:45 -07002513 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2514 .vece = MO_64 },
2515 };
2516
2517 tcg_debug_assert(vece <= MO_64);
2518 tcg_gen_gvec_2(dofs, aofs, oprsz, maxsz, &g[vece]);
2519}
2520
Richard Hendersonbcefc902019-04-17 13:53:02 -10002521static void gen_absv_mask(TCGv_i64 d, TCGv_i64 b, unsigned vece)
2522{
Richard Henderson5dd48602023-01-29 13:26:49 -10002523 TCGv_i64 t = tcg_temp_ebb_new_i64();
Richard Hendersonbcefc902019-04-17 13:53:02 -10002524 int nbit = 8 << vece;
2525
2526 /* Create -1 for each negative element. */
2527 tcg_gen_shri_i64(t, b, nbit - 1);
2528 tcg_gen_andi_i64(t, t, dup_const(vece, 1));
2529 tcg_gen_muli_i64(t, t, (1 << nbit) - 1);
2530
2531 /*
Stephen Longe7e8f332020-08-13 09:18:18 -07002532 * Invert (via xor -1) and add one.
Richard Hendersonbcefc902019-04-17 13:53:02 -10002533 * Because of the ordering the msb is cleared,
2534 * so we never have carry into the next element.
2535 */
2536 tcg_gen_xor_i64(d, b, t);
Stephen Longe7e8f332020-08-13 09:18:18 -07002537 tcg_gen_andi_i64(t, t, dup_const(vece, 1));
2538 tcg_gen_add_i64(d, d, t);
Richard Hendersonbcefc902019-04-17 13:53:02 -10002539
2540 tcg_temp_free_i64(t);
2541}
2542
2543static void tcg_gen_vec_abs8_i64(TCGv_i64 d, TCGv_i64 b)
2544{
2545 gen_absv_mask(d, b, MO_8);
2546}
2547
2548static void tcg_gen_vec_abs16_i64(TCGv_i64 d, TCGv_i64 b)
2549{
2550 gen_absv_mask(d, b, MO_16);
2551}
2552
2553void tcg_gen_gvec_abs(unsigned vece, uint32_t dofs, uint32_t aofs,
2554 uint32_t oprsz, uint32_t maxsz)
2555{
2556 static const TCGOpcode vecop_list[] = { INDEX_op_abs_vec, 0 };
2557 static const GVecGen2 g[4] = {
2558 { .fni8 = tcg_gen_vec_abs8_i64,
2559 .fniv = tcg_gen_abs_vec,
2560 .fno = gen_helper_gvec_abs8,
2561 .opt_opc = vecop_list,
2562 .vece = MO_8 },
2563 { .fni8 = tcg_gen_vec_abs16_i64,
2564 .fniv = tcg_gen_abs_vec,
2565 .fno = gen_helper_gvec_abs16,
2566 .opt_opc = vecop_list,
2567 .vece = MO_16 },
2568 { .fni4 = tcg_gen_abs_i32,
2569 .fniv = tcg_gen_abs_vec,
2570 .fno = gen_helper_gvec_abs32,
2571 .opt_opc = vecop_list,
2572 .vece = MO_32 },
2573 { .fni8 = tcg_gen_abs_i64,
2574 .fniv = tcg_gen_abs_vec,
2575 .fno = gen_helper_gvec_abs64,
2576 .opt_opc = vecop_list,
2577 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2578 .vece = MO_64 },
2579 };
2580
2581 tcg_debug_assert(vece <= MO_64);
2582 tcg_gen_gvec_2(dofs, aofs, oprsz, maxsz, &g[vece]);
2583}
2584
Richard Hendersondb432672017-09-15 14:11:45 -07002585void tcg_gen_gvec_and(unsigned vece, uint32_t dofs, uint32_t aofs,
2586 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2587{
2588 static const GVecGen3 g = {
2589 .fni8 = tcg_gen_and_i64,
2590 .fniv = tcg_gen_and_vec,
2591 .fno = gen_helper_gvec_and,
Richard Hendersondb432672017-09-15 14:11:45 -07002592 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2593 };
Richard Henderson9a9eda72018-12-17 12:54:53 -08002594
2595 if (aofs == bofs) {
2596 tcg_gen_gvec_mov(vece, dofs, aofs, oprsz, maxsz);
2597 } else {
2598 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2599 }
Richard Hendersondb432672017-09-15 14:11:45 -07002600}
2601
2602void tcg_gen_gvec_or(unsigned vece, uint32_t dofs, uint32_t aofs,
2603 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2604{
2605 static const GVecGen3 g = {
2606 .fni8 = tcg_gen_or_i64,
2607 .fniv = tcg_gen_or_vec,
2608 .fno = gen_helper_gvec_or,
Richard Hendersondb432672017-09-15 14:11:45 -07002609 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2610 };
Richard Henderson9a9eda72018-12-17 12:54:53 -08002611
2612 if (aofs == bofs) {
2613 tcg_gen_gvec_mov(vece, dofs, aofs, oprsz, maxsz);
2614 } else {
2615 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2616 }
Richard Hendersondb432672017-09-15 14:11:45 -07002617}
2618
2619void tcg_gen_gvec_xor(unsigned vece, uint32_t dofs, uint32_t aofs,
2620 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2621{
2622 static const GVecGen3 g = {
2623 .fni8 = tcg_gen_xor_i64,
2624 .fniv = tcg_gen_xor_vec,
2625 .fno = gen_helper_gvec_xor,
Richard Hendersondb432672017-09-15 14:11:45 -07002626 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2627 };
Richard Henderson9a9eda72018-12-17 12:54:53 -08002628
2629 if (aofs == bofs) {
Richard Henderson03ddb6f2020-03-28 16:10:42 -07002630 tcg_gen_gvec_dup_imm(MO_64, dofs, oprsz, maxsz, 0);
Richard Henderson9a9eda72018-12-17 12:54:53 -08002631 } else {
2632 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2633 }
Richard Hendersondb432672017-09-15 14:11:45 -07002634}
2635
2636void tcg_gen_gvec_andc(unsigned vece, uint32_t dofs, uint32_t aofs,
2637 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2638{
2639 static const GVecGen3 g = {
2640 .fni8 = tcg_gen_andc_i64,
2641 .fniv = tcg_gen_andc_vec,
2642 .fno = gen_helper_gvec_andc,
Richard Hendersondb432672017-09-15 14:11:45 -07002643 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2644 };
Richard Henderson9a9eda72018-12-17 12:54:53 -08002645
2646 if (aofs == bofs) {
Richard Henderson03ddb6f2020-03-28 16:10:42 -07002647 tcg_gen_gvec_dup_imm(MO_64, dofs, oprsz, maxsz, 0);
Richard Henderson9a9eda72018-12-17 12:54:53 -08002648 } else {
2649 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2650 }
Richard Hendersondb432672017-09-15 14:11:45 -07002651}
2652
2653void tcg_gen_gvec_orc(unsigned vece, uint32_t dofs, uint32_t aofs,
2654 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2655{
2656 static const GVecGen3 g = {
2657 .fni8 = tcg_gen_orc_i64,
2658 .fniv = tcg_gen_orc_vec,
2659 .fno = gen_helper_gvec_orc,
Richard Hendersondb432672017-09-15 14:11:45 -07002660 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2661 };
Richard Henderson9a9eda72018-12-17 12:54:53 -08002662
2663 if (aofs == bofs) {
Richard Henderson03ddb6f2020-03-28 16:10:42 -07002664 tcg_gen_gvec_dup_imm(MO_64, dofs, oprsz, maxsz, -1);
Richard Henderson9a9eda72018-12-17 12:54:53 -08002665 } else {
2666 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2667 }
Richard Hendersondb432672017-09-15 14:11:45 -07002668}
Richard Hendersond0ec9792017-11-17 14:35:11 +01002669
Richard Hendersonf5508052018-12-17 13:22:06 -08002670void tcg_gen_gvec_nand(unsigned vece, uint32_t dofs, uint32_t aofs,
2671 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2672{
2673 static const GVecGen3 g = {
2674 .fni8 = tcg_gen_nand_i64,
2675 .fniv = tcg_gen_nand_vec,
2676 .fno = gen_helper_gvec_nand,
2677 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2678 };
2679
2680 if (aofs == bofs) {
2681 tcg_gen_gvec_not(vece, dofs, aofs, oprsz, maxsz);
2682 } else {
2683 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2684 }
2685}
2686
2687void tcg_gen_gvec_nor(unsigned vece, uint32_t dofs, uint32_t aofs,
2688 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2689{
2690 static const GVecGen3 g = {
2691 .fni8 = tcg_gen_nor_i64,
2692 .fniv = tcg_gen_nor_vec,
2693 .fno = gen_helper_gvec_nor,
2694 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2695 };
2696
2697 if (aofs == bofs) {
2698 tcg_gen_gvec_not(vece, dofs, aofs, oprsz, maxsz);
2699 } else {
2700 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2701 }
2702}
2703
2704void tcg_gen_gvec_eqv(unsigned vece, uint32_t dofs, uint32_t aofs,
2705 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
2706{
2707 static const GVecGen3 g = {
2708 .fni8 = tcg_gen_eqv_i64,
2709 .fniv = tcg_gen_eqv_vec,
2710 .fno = gen_helper_gvec_eqv,
2711 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2712 };
2713
2714 if (aofs == bofs) {
Richard Henderson03ddb6f2020-03-28 16:10:42 -07002715 tcg_gen_gvec_dup_imm(MO_64, dofs, oprsz, maxsz, -1);
Richard Hendersonf5508052018-12-17 13:22:06 -08002716 } else {
2717 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g);
2718 }
2719}
2720
Richard Henderson22fc3522017-12-21 10:58:36 -08002721static const GVecGen2s gop_ands = {
2722 .fni8 = tcg_gen_and_i64,
2723 .fniv = tcg_gen_and_vec,
2724 .fno = gen_helper_gvec_ands,
Richard Henderson22fc3522017-12-21 10:58:36 -08002725 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2726 .vece = MO_64
2727};
2728
2729void tcg_gen_gvec_ands(unsigned vece, uint32_t dofs, uint32_t aofs,
2730 TCGv_i64 c, uint32_t oprsz, uint32_t maxsz)
2731{
Richard Henderson5dd48602023-01-29 13:26:49 -10002732 TCGv_i64 tmp = tcg_temp_ebb_new_i64();
Peter Maydell614dd4f2021-06-17 13:15:53 +01002733 tcg_gen_dup_i64(vece, tmp, c);
Richard Henderson22fc3522017-12-21 10:58:36 -08002734 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ands);
2735 tcg_temp_free_i64(tmp);
2736}
2737
2738void tcg_gen_gvec_andi(unsigned vece, uint32_t dofs, uint32_t aofs,
2739 int64_t c, uint32_t oprsz, uint32_t maxsz)
2740{
Richard Henderson88d40052020-09-03 18:18:08 -07002741 TCGv_i64 tmp = tcg_constant_i64(dup_const(vece, c));
Richard Henderson22fc3522017-12-21 10:58:36 -08002742 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ands);
Richard Henderson22fc3522017-12-21 10:58:36 -08002743}
2744
Nazar Kazakov4221aa4a2023-04-28 15:47:47 +01002745void tcg_gen_gvec_andcs(unsigned vece, uint32_t dofs, uint32_t aofs,
2746 TCGv_i64 c, uint32_t oprsz, uint32_t maxsz)
2747{
2748 static GVecGen2s g = {
2749 .fni8 = tcg_gen_andc_i64,
2750 .fniv = tcg_gen_andc_vec,
2751 .fno = gen_helper_gvec_andcs,
2752 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2753 .vece = MO_64
2754 };
2755
2756 TCGv_i64 tmp = tcg_temp_ebb_new_i64();
2757 tcg_gen_dup_i64(vece, tmp, c);
Max Chou70bfde92023-06-23 00:16:24 +08002758 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &g);
Nazar Kazakov4221aa4a2023-04-28 15:47:47 +01002759 tcg_temp_free_i64(tmp);
2760}
2761
Richard Henderson22fc3522017-12-21 10:58:36 -08002762static const GVecGen2s gop_xors = {
2763 .fni8 = tcg_gen_xor_i64,
2764 .fniv = tcg_gen_xor_vec,
2765 .fno = gen_helper_gvec_xors,
Richard Henderson22fc3522017-12-21 10:58:36 -08002766 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2767 .vece = MO_64
2768};
2769
2770void tcg_gen_gvec_xors(unsigned vece, uint32_t dofs, uint32_t aofs,
2771 TCGv_i64 c, uint32_t oprsz, uint32_t maxsz)
2772{
Richard Henderson5dd48602023-01-29 13:26:49 -10002773 TCGv_i64 tmp = tcg_temp_ebb_new_i64();
Peter Maydell614dd4f2021-06-17 13:15:53 +01002774 tcg_gen_dup_i64(vece, tmp, c);
Richard Henderson22fc3522017-12-21 10:58:36 -08002775 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_xors);
2776 tcg_temp_free_i64(tmp);
2777}
2778
2779void tcg_gen_gvec_xori(unsigned vece, uint32_t dofs, uint32_t aofs,
2780 int64_t c, uint32_t oprsz, uint32_t maxsz)
2781{
Richard Henderson88d40052020-09-03 18:18:08 -07002782 TCGv_i64 tmp = tcg_constant_i64(dup_const(vece, c));
Richard Henderson22fc3522017-12-21 10:58:36 -08002783 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_xors);
Richard Henderson22fc3522017-12-21 10:58:36 -08002784}
2785
2786static const GVecGen2s gop_ors = {
2787 .fni8 = tcg_gen_or_i64,
2788 .fniv = tcg_gen_or_vec,
2789 .fno = gen_helper_gvec_ors,
Richard Henderson22fc3522017-12-21 10:58:36 -08002790 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2791 .vece = MO_64
2792};
2793
2794void tcg_gen_gvec_ors(unsigned vece, uint32_t dofs, uint32_t aofs,
2795 TCGv_i64 c, uint32_t oprsz, uint32_t maxsz)
2796{
Richard Henderson5dd48602023-01-29 13:26:49 -10002797 TCGv_i64 tmp = tcg_temp_ebb_new_i64();
Peter Maydell614dd4f2021-06-17 13:15:53 +01002798 tcg_gen_dup_i64(vece, tmp, c);
Richard Henderson22fc3522017-12-21 10:58:36 -08002799 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ors);
2800 tcg_temp_free_i64(tmp);
2801}
2802
2803void tcg_gen_gvec_ori(unsigned vece, uint32_t dofs, uint32_t aofs,
2804 int64_t c, uint32_t oprsz, uint32_t maxsz)
2805{
Richard Henderson88d40052020-09-03 18:18:08 -07002806 TCGv_i64 tmp = tcg_constant_i64(dup_const(vece, c));
Richard Henderson22fc3522017-12-21 10:58:36 -08002807 tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ors);
Richard Henderson22fc3522017-12-21 10:58:36 -08002808}
2809
Richard Hendersond0ec9792017-11-17 14:35:11 +01002810void tcg_gen_vec_shl8i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
2811{
2812 uint64_t mask = dup_const(MO_8, 0xff << c);
2813 tcg_gen_shli_i64(d, a, c);
2814 tcg_gen_andi_i64(d, d, mask);
2815}
2816
2817void tcg_gen_vec_shl16i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
2818{
2819 uint64_t mask = dup_const(MO_16, 0xffff << c);
2820 tcg_gen_shli_i64(d, a, c);
2821 tcg_gen_andi_i64(d, d, mask);
2822}
2823
LIU Zhiwei950ee592021-06-24 18:50:22 +08002824void tcg_gen_vec_shl8i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c)
2825{
2826 uint32_t mask = dup_const(MO_8, 0xff << c);
2827 tcg_gen_shli_i32(d, a, c);
2828 tcg_gen_andi_i32(d, d, mask);
2829}
2830
LIU Zhiwei04f2a8b2021-06-24 18:50:21 +08002831void tcg_gen_vec_shl16i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c)
2832{
2833 uint32_t mask = dup_const(MO_16, 0xffff << c);
2834 tcg_gen_shli_i32(d, a, c);
2835 tcg_gen_andi_i32(d, d, mask);
2836}
2837
Richard Hendersond0ec9792017-11-17 14:35:11 +01002838void tcg_gen_gvec_shli(unsigned vece, uint32_t dofs, uint32_t aofs,
2839 int64_t shift, uint32_t oprsz, uint32_t maxsz)
2840{
Richard Henderson53229a72019-03-17 00:27:29 +00002841 static const TCGOpcode vecop_list[] = { INDEX_op_shli_vec, 0 };
Richard Hendersond0ec9792017-11-17 14:35:11 +01002842 static const GVecGen2i g[4] = {
2843 { .fni8 = tcg_gen_vec_shl8i_i64,
2844 .fniv = tcg_gen_shli_vec,
2845 .fno = gen_helper_gvec_shl8i,
Richard Henderson53229a72019-03-17 00:27:29 +00002846 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002847 .vece = MO_8 },
2848 { .fni8 = tcg_gen_vec_shl16i_i64,
2849 .fniv = tcg_gen_shli_vec,
2850 .fno = gen_helper_gvec_shl16i,
Richard Henderson53229a72019-03-17 00:27:29 +00002851 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002852 .vece = MO_16 },
2853 { .fni4 = tcg_gen_shli_i32,
2854 .fniv = tcg_gen_shli_vec,
2855 .fno = gen_helper_gvec_shl32i,
Richard Henderson53229a72019-03-17 00:27:29 +00002856 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002857 .vece = MO_32 },
2858 { .fni8 = tcg_gen_shli_i64,
2859 .fniv = tcg_gen_shli_vec,
2860 .fno = gen_helper_gvec_shl64i,
Richard Henderson53229a72019-03-17 00:27:29 +00002861 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002862 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2863 .vece = MO_64 },
2864 };
2865
2866 tcg_debug_assert(vece <= MO_64);
2867 tcg_debug_assert(shift >= 0 && shift < (8 << vece));
2868 if (shift == 0) {
2869 tcg_gen_gvec_mov(vece, dofs, aofs, oprsz, maxsz);
2870 } else {
2871 tcg_gen_gvec_2i(dofs, aofs, oprsz, maxsz, shift, &g[vece]);
2872 }
2873}
2874
2875void tcg_gen_vec_shr8i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
2876{
2877 uint64_t mask = dup_const(MO_8, 0xff >> c);
2878 tcg_gen_shri_i64(d, a, c);
2879 tcg_gen_andi_i64(d, d, mask);
2880}
2881
2882void tcg_gen_vec_shr16i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
2883{
2884 uint64_t mask = dup_const(MO_16, 0xffff >> c);
2885 tcg_gen_shri_i64(d, a, c);
2886 tcg_gen_andi_i64(d, d, mask);
2887}
2888
LIU Zhiwei950ee592021-06-24 18:50:22 +08002889void tcg_gen_vec_shr8i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c)
2890{
2891 uint32_t mask = dup_const(MO_8, 0xff >> c);
2892 tcg_gen_shri_i32(d, a, c);
2893 tcg_gen_andi_i32(d, d, mask);
2894}
2895
LIU Zhiwei04f2a8b2021-06-24 18:50:21 +08002896void tcg_gen_vec_shr16i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c)
2897{
2898 uint32_t mask = dup_const(MO_16, 0xffff >> c);
2899 tcg_gen_shri_i32(d, a, c);
2900 tcg_gen_andi_i32(d, d, mask);
2901}
2902
Richard Hendersond0ec9792017-11-17 14:35:11 +01002903void tcg_gen_gvec_shri(unsigned vece, uint32_t dofs, uint32_t aofs,
2904 int64_t shift, uint32_t oprsz, uint32_t maxsz)
2905{
Richard Henderson53229a72019-03-17 00:27:29 +00002906 static const TCGOpcode vecop_list[] = { INDEX_op_shri_vec, 0 };
Richard Hendersond0ec9792017-11-17 14:35:11 +01002907 static const GVecGen2i g[4] = {
2908 { .fni8 = tcg_gen_vec_shr8i_i64,
2909 .fniv = tcg_gen_shri_vec,
2910 .fno = gen_helper_gvec_shr8i,
Richard Henderson53229a72019-03-17 00:27:29 +00002911 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002912 .vece = MO_8 },
2913 { .fni8 = tcg_gen_vec_shr16i_i64,
2914 .fniv = tcg_gen_shri_vec,
2915 .fno = gen_helper_gvec_shr16i,
Richard Henderson53229a72019-03-17 00:27:29 +00002916 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002917 .vece = MO_16 },
2918 { .fni4 = tcg_gen_shri_i32,
2919 .fniv = tcg_gen_shri_vec,
2920 .fno = gen_helper_gvec_shr32i,
Richard Henderson53229a72019-03-17 00:27:29 +00002921 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002922 .vece = MO_32 },
2923 { .fni8 = tcg_gen_shri_i64,
2924 .fniv = tcg_gen_shri_vec,
2925 .fno = gen_helper_gvec_shr64i,
Richard Henderson53229a72019-03-17 00:27:29 +00002926 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01002927 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
2928 .vece = MO_64 },
2929 };
2930
2931 tcg_debug_assert(vece <= MO_64);
2932 tcg_debug_assert(shift >= 0 && shift < (8 << vece));
2933 if (shift == 0) {
2934 tcg_gen_gvec_mov(vece, dofs, aofs, oprsz, maxsz);
2935 } else {
2936 tcg_gen_gvec_2i(dofs, aofs, oprsz, maxsz, shift, &g[vece]);
2937 }
2938}
2939
2940void tcg_gen_vec_sar8i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
2941{
2942 uint64_t s_mask = dup_const(MO_8, 0x80 >> c);
2943 uint64_t c_mask = dup_const(MO_8, 0xff >> c);
Richard Henderson5dd48602023-01-29 13:26:49 -10002944 TCGv_i64 s = tcg_temp_ebb_new_i64();
Richard Hendersond0ec9792017-11-17 14:35:11 +01002945
2946 tcg_gen_shri_i64(d, a, c);
2947 tcg_gen_andi_i64(s, d, s_mask); /* isolate (shifted) sign bit */
2948 tcg_gen_muli_i64(s, s, (2 << c) - 2); /* replicate isolated signs */
2949 tcg_gen_andi_i64(d, d, c_mask); /* clear out bits above sign */
2950 tcg_gen_or_i64(d, d, s); /* include sign extension */
2951 tcg_temp_free_i64(s);
2952}
2953
2954void tcg_gen_vec_sar16i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
2955{
2956 uint64_t s_mask = dup_const(MO_16, 0x8000 >> c);
2957 uint64_t c_mask = dup_const(MO_16, 0xffff >> c);
Richard Henderson5dd48602023-01-29 13:26:49 -10002958 TCGv_i64 s = tcg_temp_ebb_new_i64();
Richard Hendersond0ec9792017-11-17 14:35:11 +01002959
2960 tcg_gen_shri_i64(d, a, c);
2961 tcg_gen_andi_i64(s, d, s_mask); /* isolate (shifted) sign bit */
2962 tcg_gen_andi_i64(d, d, c_mask); /* clear out bits above sign */
2963 tcg_gen_muli_i64(s, s, (2 << c) - 2); /* replicate isolated signs */
2964 tcg_gen_or_i64(d, d, s); /* include sign extension */
2965 tcg_temp_free_i64(s);
2966}
2967
LIU Zhiwei950ee592021-06-24 18:50:22 +08002968void tcg_gen_vec_sar8i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c)
2969{
2970 uint32_t s_mask = dup_const(MO_8, 0x80 >> c);
2971 uint32_t c_mask = dup_const(MO_8, 0xff >> c);
Richard Henderson5dd48602023-01-29 13:26:49 -10002972 TCGv_i32 s = tcg_temp_ebb_new_i32();
LIU Zhiwei950ee592021-06-24 18:50:22 +08002973
2974 tcg_gen_shri_i32(d, a, c);
2975 tcg_gen_andi_i32(s, d, s_mask); /* isolate (shifted) sign bit */
2976 tcg_gen_muli_i32(s, s, (2 << c) - 2); /* replicate isolated signs */
2977 tcg_gen_andi_i32(d, d, c_mask); /* clear out bits above sign */
2978 tcg_gen_or_i32(d, d, s); /* include sign extension */
2979 tcg_temp_free_i32(s);
2980}
2981
LIU Zhiwei04f2a8b2021-06-24 18:50:21 +08002982void tcg_gen_vec_sar16i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c)
2983{
2984 uint32_t s_mask = dup_const(MO_16, 0x8000 >> c);
2985 uint32_t c_mask = dup_const(MO_16, 0xffff >> c);
Richard Henderson5dd48602023-01-29 13:26:49 -10002986 TCGv_i32 s = tcg_temp_ebb_new_i32();
LIU Zhiwei04f2a8b2021-06-24 18:50:21 +08002987
2988 tcg_gen_shri_i32(d, a, c);
2989 tcg_gen_andi_i32(s, d, s_mask); /* isolate (shifted) sign bit */
2990 tcg_gen_andi_i32(d, d, c_mask); /* clear out bits above sign */
2991 tcg_gen_muli_i32(s, s, (2 << c) - 2); /* replicate isolated signs */
2992 tcg_gen_or_i32(d, d, s); /* include sign extension */
2993 tcg_temp_free_i32(s);
2994}
2995
Richard Hendersond0ec9792017-11-17 14:35:11 +01002996void tcg_gen_gvec_sari(unsigned vece, uint32_t dofs, uint32_t aofs,
2997 int64_t shift, uint32_t oprsz, uint32_t maxsz)
2998{
Richard Henderson53229a72019-03-17 00:27:29 +00002999 static const TCGOpcode vecop_list[] = { INDEX_op_sari_vec, 0 };
Richard Hendersond0ec9792017-11-17 14:35:11 +01003000 static const GVecGen2i g[4] = {
3001 { .fni8 = tcg_gen_vec_sar8i_i64,
3002 .fniv = tcg_gen_sari_vec,
3003 .fno = gen_helper_gvec_sar8i,
Richard Henderson53229a72019-03-17 00:27:29 +00003004 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01003005 .vece = MO_8 },
3006 { .fni8 = tcg_gen_vec_sar16i_i64,
3007 .fniv = tcg_gen_sari_vec,
3008 .fno = gen_helper_gvec_sar16i,
Richard Henderson53229a72019-03-17 00:27:29 +00003009 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01003010 .vece = MO_16 },
3011 { .fni4 = tcg_gen_sari_i32,
3012 .fniv = tcg_gen_sari_vec,
3013 .fno = gen_helper_gvec_sar32i,
Richard Henderson53229a72019-03-17 00:27:29 +00003014 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01003015 .vece = MO_32 },
3016 { .fni8 = tcg_gen_sari_i64,
3017 .fniv = tcg_gen_sari_vec,
3018 .fno = gen_helper_gvec_sar64i,
Richard Henderson53229a72019-03-17 00:27:29 +00003019 .opt_opc = vecop_list,
Richard Hendersond0ec9792017-11-17 14:35:11 +01003020 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3021 .vece = MO_64 },
3022 };
3023
3024 tcg_debug_assert(vece <= MO_64);
3025 tcg_debug_assert(shift >= 0 && shift < (8 << vece));
3026 if (shift == 0) {
3027 tcg_gen_gvec_mov(vece, dofs, aofs, oprsz, maxsz);
3028 } else {
3029 tcg_gen_gvec_2i(dofs, aofs, oprsz, maxsz, shift, &g[vece]);
3030 }
3031}
Richard Henderson212be172017-11-17 20:47:42 +01003032
Richard Hendersonb0f7e742020-04-19 18:01:52 -07003033void tcg_gen_vec_rotl8i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
3034{
3035 uint64_t mask = dup_const(MO_8, 0xff << c);
3036
3037 tcg_gen_shli_i64(d, a, c);
3038 tcg_gen_shri_i64(a, a, 8 - c);
3039 tcg_gen_andi_i64(d, d, mask);
3040 tcg_gen_andi_i64(a, a, ~mask);
3041 tcg_gen_or_i64(d, d, a);
3042}
3043
3044void tcg_gen_vec_rotl16i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
3045{
3046 uint64_t mask = dup_const(MO_16, 0xffff << c);
3047
3048 tcg_gen_shli_i64(d, a, c);
3049 tcg_gen_shri_i64(a, a, 16 - c);
3050 tcg_gen_andi_i64(d, d, mask);
3051 tcg_gen_andi_i64(a, a, ~mask);
3052 tcg_gen_or_i64(d, d, a);
3053}
3054
3055void tcg_gen_gvec_rotli(unsigned vece, uint32_t dofs, uint32_t aofs,
3056 int64_t shift, uint32_t oprsz, uint32_t maxsz)
3057{
3058 static const TCGOpcode vecop_list[] = { INDEX_op_rotli_vec, 0 };
3059 static const GVecGen2i g[4] = {
3060 { .fni8 = tcg_gen_vec_rotl8i_i64,
3061 .fniv = tcg_gen_rotli_vec,
3062 .fno = gen_helper_gvec_rotl8i,
3063 .opt_opc = vecop_list,
3064 .vece = MO_8 },
3065 { .fni8 = tcg_gen_vec_rotl16i_i64,
3066 .fniv = tcg_gen_rotli_vec,
3067 .fno = gen_helper_gvec_rotl16i,
3068 .opt_opc = vecop_list,
3069 .vece = MO_16 },
3070 { .fni4 = tcg_gen_rotli_i32,
3071 .fniv = tcg_gen_rotli_vec,
3072 .fno = gen_helper_gvec_rotl32i,
3073 .opt_opc = vecop_list,
3074 .vece = MO_32 },
3075 { .fni8 = tcg_gen_rotli_i64,
3076 .fniv = tcg_gen_rotli_vec,
3077 .fno = gen_helper_gvec_rotl64i,
3078 .opt_opc = vecop_list,
3079 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3080 .vece = MO_64 },
3081 };
3082
3083 tcg_debug_assert(vece <= MO_64);
3084 tcg_debug_assert(shift >= 0 && shift < (8 << vece));
3085 if (shift == 0) {
3086 tcg_gen_gvec_mov(vece, dofs, aofs, oprsz, maxsz);
3087 } else {
3088 tcg_gen_gvec_2i(dofs, aofs, oprsz, maxsz, shift, &g[vece]);
3089 }
3090}
3091
3092void tcg_gen_gvec_rotri(unsigned vece, uint32_t dofs, uint32_t aofs,
3093 int64_t shift, uint32_t oprsz, uint32_t maxsz)
3094{
3095 tcg_debug_assert(vece <= MO_64);
3096 tcg_debug_assert(shift >= 0 && shift < (8 << vece));
3097 tcg_gen_gvec_rotli(vece, dofs, aofs, -shift & ((8 << vece) - 1),
3098 oprsz, maxsz);
3099}
3100
Richard Henderson5ee5c142019-04-13 20:42:37 -10003101/*
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003102 * Specialized generation vector shifts by a non-constant scalar.
3103 */
3104
3105typedef struct {
3106 void (*fni4)(TCGv_i32, TCGv_i32, TCGv_i32);
3107 void (*fni8)(TCGv_i64, TCGv_i64, TCGv_i64);
3108 void (*fniv_s)(unsigned, TCGv_vec, TCGv_vec, TCGv_i32);
3109 void (*fniv_v)(unsigned, TCGv_vec, TCGv_vec, TCGv_vec);
3110 gen_helper_gvec_2 *fno[4];
3111 TCGOpcode s_list[2];
3112 TCGOpcode v_list[2];
3113} GVecGen2sh;
3114
3115static void expand_2sh_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
3116 uint32_t oprsz, uint32_t tysz, TCGType type,
3117 TCGv_i32 shift,
3118 void (*fni)(unsigned, TCGv_vec, TCGv_vec, TCGv_i32))
3119{
Richard Henderson9628d002023-08-23 20:35:05 -07003120 for (uint32_t i = 0; i < oprsz; i += tysz) {
3121 TCGv_vec t0 = tcg_temp_new_vec(type);
3122 TCGv_vec t1 = tcg_temp_new_vec(type);
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003123
Richard Hendersonad75a512023-09-13 16:37:36 -07003124 tcg_gen_ld_vec(t0, tcg_env, aofs + i);
Richard Henderson9628d002023-08-23 20:35:05 -07003125 fni(vece, t1, t0, shift);
3126 tcg_gen_st_vec(t1, tcg_env, dofs + i);
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003127 }
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003128}
3129
3130static void
3131do_gvec_shifts(unsigned vece, uint32_t dofs, uint32_t aofs, TCGv_i32 shift,
3132 uint32_t oprsz, uint32_t maxsz, const GVecGen2sh *g)
3133{
3134 TCGType type;
3135 uint32_t some;
3136
3137 check_size_align(oprsz, maxsz, dofs | aofs);
3138 check_overlap_2(dofs, aofs, maxsz);
3139
3140 /* If the backend has a scalar expansion, great. */
3141 type = choose_vector_type(g->s_list, vece, oprsz, vece == MO_64);
3142 if (type) {
3143 const TCGOpcode *hold_list = tcg_swap_vecop_list(NULL);
3144 switch (type) {
3145 case TCG_TYPE_V256:
3146 some = QEMU_ALIGN_DOWN(oprsz, 32);
3147 expand_2sh_vec(vece, dofs, aofs, some, 32,
3148 TCG_TYPE_V256, shift, g->fniv_s);
3149 if (some == oprsz) {
3150 break;
3151 }
3152 dofs += some;
3153 aofs += some;
3154 oprsz -= some;
3155 maxsz -= some;
3156 /* fallthru */
3157 case TCG_TYPE_V128:
3158 expand_2sh_vec(vece, dofs, aofs, oprsz, 16,
3159 TCG_TYPE_V128, shift, g->fniv_s);
3160 break;
3161 case TCG_TYPE_V64:
3162 expand_2sh_vec(vece, dofs, aofs, oprsz, 8,
3163 TCG_TYPE_V64, shift, g->fniv_s);
3164 break;
3165 default:
3166 g_assert_not_reached();
3167 }
3168 tcg_swap_vecop_list(hold_list);
3169 goto clear_tail;
3170 }
3171
3172 /* If the backend supports variable vector shifts, also cool. */
3173 type = choose_vector_type(g->v_list, vece, oprsz, vece == MO_64);
3174 if (type) {
3175 const TCGOpcode *hold_list = tcg_swap_vecop_list(NULL);
3176 TCGv_vec v_shift = tcg_temp_new_vec(type);
3177
3178 if (vece == MO_64) {
Richard Henderson5dd48602023-01-29 13:26:49 -10003179 TCGv_i64 sh64 = tcg_temp_ebb_new_i64();
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003180 tcg_gen_extu_i32_i64(sh64, shift);
3181 tcg_gen_dup_i64_vec(MO_64, v_shift, sh64);
3182 tcg_temp_free_i64(sh64);
3183 } else {
3184 tcg_gen_dup_i32_vec(vece, v_shift, shift);
3185 }
3186
3187 switch (type) {
3188 case TCG_TYPE_V256:
3189 some = QEMU_ALIGN_DOWN(oprsz, 32);
3190 expand_2s_vec(vece, dofs, aofs, some, 32, TCG_TYPE_V256,
3191 v_shift, false, g->fniv_v);
3192 if (some == oprsz) {
3193 break;
3194 }
3195 dofs += some;
3196 aofs += some;
3197 oprsz -= some;
3198 maxsz -= some;
3199 /* fallthru */
3200 case TCG_TYPE_V128:
3201 expand_2s_vec(vece, dofs, aofs, oprsz, 16, TCG_TYPE_V128,
3202 v_shift, false, g->fniv_v);
3203 break;
3204 case TCG_TYPE_V64:
3205 expand_2s_vec(vece, dofs, aofs, oprsz, 8, TCG_TYPE_V64,
3206 v_shift, false, g->fniv_v);
3207 break;
3208 default:
3209 g_assert_not_reached();
3210 }
3211 tcg_temp_free_vec(v_shift);
3212 tcg_swap_vecop_list(hold_list);
3213 goto clear_tail;
3214 }
3215
3216 /* Otherwise fall back to integral... */
3217 if (vece == MO_32 && check_size_impl(oprsz, 4)) {
3218 expand_2s_i32(dofs, aofs, oprsz, shift, false, g->fni4);
3219 } else if (vece == MO_64 && check_size_impl(oprsz, 8)) {
Richard Henderson5dd48602023-01-29 13:26:49 -10003220 TCGv_i64 sh64 = tcg_temp_ebb_new_i64();
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003221 tcg_gen_extu_i32_i64(sh64, shift);
3222 expand_2s_i64(dofs, aofs, oprsz, sh64, false, g->fni8);
3223 tcg_temp_free_i64(sh64);
3224 } else {
Richard Henderson5dd48602023-01-29 13:26:49 -10003225 TCGv_ptr a0 = tcg_temp_ebb_new_ptr();
3226 TCGv_ptr a1 = tcg_temp_ebb_new_ptr();
3227 TCGv_i32 desc = tcg_temp_ebb_new_i32();
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003228
3229 tcg_gen_shli_i32(desc, shift, SIMD_DATA_SHIFT);
3230 tcg_gen_ori_i32(desc, desc, simd_desc(oprsz, maxsz, 0));
Richard Hendersonad75a512023-09-13 16:37:36 -07003231 tcg_gen_addi_ptr(a0, tcg_env, dofs);
3232 tcg_gen_addi_ptr(a1, tcg_env, aofs);
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003233
3234 g->fno[vece](a0, a1, desc);
3235
3236 tcg_temp_free_ptr(a0);
3237 tcg_temp_free_ptr(a1);
3238 tcg_temp_free_i32(desc);
3239 return;
3240 }
3241
3242 clear_tail:
3243 if (oprsz < maxsz) {
3244 expand_clr(dofs + oprsz, maxsz - oprsz);
3245 }
3246}
3247
3248void tcg_gen_gvec_shls(unsigned vece, uint32_t dofs, uint32_t aofs,
3249 TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz)
3250{
3251 static const GVecGen2sh g = {
3252 .fni4 = tcg_gen_shl_i32,
3253 .fni8 = tcg_gen_shl_i64,
3254 .fniv_s = tcg_gen_shls_vec,
3255 .fniv_v = tcg_gen_shlv_vec,
3256 .fno = {
3257 gen_helper_gvec_shl8i,
3258 gen_helper_gvec_shl16i,
3259 gen_helper_gvec_shl32i,
3260 gen_helper_gvec_shl64i,
3261 },
3262 .s_list = { INDEX_op_shls_vec, 0 },
3263 .v_list = { INDEX_op_shlv_vec, 0 },
3264 };
3265
3266 tcg_debug_assert(vece <= MO_64);
3267 do_gvec_shifts(vece, dofs, aofs, shift, oprsz, maxsz, &g);
3268}
3269
3270void tcg_gen_gvec_shrs(unsigned vece, uint32_t dofs, uint32_t aofs,
3271 TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz)
3272{
3273 static const GVecGen2sh g = {
3274 .fni4 = tcg_gen_shr_i32,
3275 .fni8 = tcg_gen_shr_i64,
3276 .fniv_s = tcg_gen_shrs_vec,
3277 .fniv_v = tcg_gen_shrv_vec,
3278 .fno = {
3279 gen_helper_gvec_shr8i,
3280 gen_helper_gvec_shr16i,
3281 gen_helper_gvec_shr32i,
3282 gen_helper_gvec_shr64i,
3283 },
3284 .s_list = { INDEX_op_shrs_vec, 0 },
3285 .v_list = { INDEX_op_shrv_vec, 0 },
3286 };
3287
3288 tcg_debug_assert(vece <= MO_64);
3289 do_gvec_shifts(vece, dofs, aofs, shift, oprsz, maxsz, &g);
3290}
3291
3292void tcg_gen_gvec_sars(unsigned vece, uint32_t dofs, uint32_t aofs,
3293 TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz)
3294{
3295 static const GVecGen2sh g = {
3296 .fni4 = tcg_gen_sar_i32,
3297 .fni8 = tcg_gen_sar_i64,
3298 .fniv_s = tcg_gen_sars_vec,
3299 .fniv_v = tcg_gen_sarv_vec,
3300 .fno = {
3301 gen_helper_gvec_sar8i,
3302 gen_helper_gvec_sar16i,
3303 gen_helper_gvec_sar32i,
3304 gen_helper_gvec_sar64i,
3305 },
3306 .s_list = { INDEX_op_sars_vec, 0 },
3307 .v_list = { INDEX_op_sarv_vec, 0 },
3308 };
3309
3310 tcg_debug_assert(vece <= MO_64);
3311 do_gvec_shifts(vece, dofs, aofs, shift, oprsz, maxsz, &g);
3312}
3313
Richard Henderson23850a72020-04-20 08:22:44 -07003314void tcg_gen_gvec_rotls(unsigned vece, uint32_t dofs, uint32_t aofs,
3315 TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz)
3316{
3317 static const GVecGen2sh g = {
3318 .fni4 = tcg_gen_rotl_i32,
3319 .fni8 = tcg_gen_rotl_i64,
3320 .fniv_s = tcg_gen_rotls_vec,
3321 .fniv_v = tcg_gen_rotlv_vec,
3322 .fno = {
3323 gen_helper_gvec_rotl8i,
3324 gen_helper_gvec_rotl16i,
3325 gen_helper_gvec_rotl32i,
3326 gen_helper_gvec_rotl64i,
3327 },
3328 .s_list = { INDEX_op_rotls_vec, 0 },
3329 .v_list = { INDEX_op_rotlv_vec, 0 },
3330 };
3331
3332 tcg_debug_assert(vece <= MO_64);
3333 do_gvec_shifts(vece, dofs, aofs, shift, oprsz, maxsz, &g);
3334}
3335
Nazar Kazakovbef317d2023-05-01 21:17:22 +01003336void tcg_gen_gvec_rotrs(unsigned vece, uint32_t dofs, uint32_t aofs,
3337 TCGv_i32 shift, uint32_t oprsz, uint32_t maxsz)
3338{
3339 TCGv_i32 tmp = tcg_temp_ebb_new_i32();
3340
3341 tcg_gen_neg_i32(tmp, shift);
3342 tcg_gen_andi_i32(tmp, tmp, (8 << vece) - 1);
3343 tcg_gen_gvec_rotls(vece, dofs, aofs, tmp, oprsz, maxsz);
3344 tcg_temp_free_i32(tmp);
3345}
3346
Richard Hendersonb4578cd2019-04-18 18:19:38 -10003347/*
Richard Henderson5ee5c142019-04-13 20:42:37 -10003348 * Expand D = A << (B % element bits)
3349 *
3350 * Unlike scalar shifts, where it is easy for the target front end
3351 * to include the modulo as part of the expansion. If the target
3352 * naturally includes the modulo as part of the operation, great!
3353 * If the target has some other behaviour from out-of-range shifts,
3354 * then it could not use this function anyway, and would need to
3355 * do it's own expansion with custom functions.
3356 */
3357static void tcg_gen_shlv_mod_vec(unsigned vece, TCGv_vec d,
3358 TCGv_vec a, TCGv_vec b)
3359{
3360 TCGv_vec t = tcg_temp_new_vec_matching(d);
Richard Henderson88d40052020-09-03 18:18:08 -07003361 TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
Richard Henderson5ee5c142019-04-13 20:42:37 -10003362
Richard Henderson88d40052020-09-03 18:18:08 -07003363 tcg_gen_and_vec(vece, t, b, m);
Richard Henderson5ee5c142019-04-13 20:42:37 -10003364 tcg_gen_shlv_vec(vece, d, a, t);
3365 tcg_temp_free_vec(t);
3366}
3367
3368static void tcg_gen_shl_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
3369{
Richard Henderson5dd48602023-01-29 13:26:49 -10003370 TCGv_i32 t = tcg_temp_ebb_new_i32();
Richard Henderson5ee5c142019-04-13 20:42:37 -10003371
3372 tcg_gen_andi_i32(t, b, 31);
3373 tcg_gen_shl_i32(d, a, t);
3374 tcg_temp_free_i32(t);
3375}
3376
3377static void tcg_gen_shl_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
3378{
Richard Henderson5dd48602023-01-29 13:26:49 -10003379 TCGv_i64 t = tcg_temp_ebb_new_i64();
Richard Henderson5ee5c142019-04-13 20:42:37 -10003380
3381 tcg_gen_andi_i64(t, b, 63);
3382 tcg_gen_shl_i64(d, a, t);
3383 tcg_temp_free_i64(t);
3384}
3385
3386void tcg_gen_gvec_shlv(unsigned vece, uint32_t dofs, uint32_t aofs,
3387 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
3388{
3389 static const TCGOpcode vecop_list[] = { INDEX_op_shlv_vec, 0 };
3390 static const GVecGen3 g[4] = {
3391 { .fniv = tcg_gen_shlv_mod_vec,
3392 .fno = gen_helper_gvec_shl8v,
3393 .opt_opc = vecop_list,
3394 .vece = MO_8 },
3395 { .fniv = tcg_gen_shlv_mod_vec,
3396 .fno = gen_helper_gvec_shl16v,
3397 .opt_opc = vecop_list,
3398 .vece = MO_16 },
3399 { .fni4 = tcg_gen_shl_mod_i32,
3400 .fniv = tcg_gen_shlv_mod_vec,
3401 .fno = gen_helper_gvec_shl32v,
3402 .opt_opc = vecop_list,
3403 .vece = MO_32 },
3404 { .fni8 = tcg_gen_shl_mod_i64,
3405 .fniv = tcg_gen_shlv_mod_vec,
3406 .fno = gen_helper_gvec_shl64v,
3407 .opt_opc = vecop_list,
3408 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3409 .vece = MO_64 },
3410 };
3411
3412 tcg_debug_assert(vece <= MO_64);
3413 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
3414}
3415
3416/*
3417 * Similarly for logical right shifts.
3418 */
3419
3420static void tcg_gen_shrv_mod_vec(unsigned vece, TCGv_vec d,
3421 TCGv_vec a, TCGv_vec b)
3422{
3423 TCGv_vec t = tcg_temp_new_vec_matching(d);
Richard Henderson88d40052020-09-03 18:18:08 -07003424 TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
Richard Henderson5ee5c142019-04-13 20:42:37 -10003425
Richard Henderson88d40052020-09-03 18:18:08 -07003426 tcg_gen_and_vec(vece, t, b, m);
Richard Henderson5ee5c142019-04-13 20:42:37 -10003427 tcg_gen_shrv_vec(vece, d, a, t);
3428 tcg_temp_free_vec(t);
3429}
3430
3431static void tcg_gen_shr_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
3432{
Richard Henderson5dd48602023-01-29 13:26:49 -10003433 TCGv_i32 t = tcg_temp_ebb_new_i32();
Richard Henderson5ee5c142019-04-13 20:42:37 -10003434
3435 tcg_gen_andi_i32(t, b, 31);
3436 tcg_gen_shr_i32(d, a, t);
3437 tcg_temp_free_i32(t);
3438}
3439
3440static void tcg_gen_shr_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
3441{
Richard Henderson5dd48602023-01-29 13:26:49 -10003442 TCGv_i64 t = tcg_temp_ebb_new_i64();
Richard Henderson5ee5c142019-04-13 20:42:37 -10003443
3444 tcg_gen_andi_i64(t, b, 63);
3445 tcg_gen_shr_i64(d, a, t);
3446 tcg_temp_free_i64(t);
3447}
3448
3449void tcg_gen_gvec_shrv(unsigned vece, uint32_t dofs, uint32_t aofs,
3450 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
3451{
3452 static const TCGOpcode vecop_list[] = { INDEX_op_shrv_vec, 0 };
3453 static const GVecGen3 g[4] = {
3454 { .fniv = tcg_gen_shrv_mod_vec,
3455 .fno = gen_helper_gvec_shr8v,
3456 .opt_opc = vecop_list,
3457 .vece = MO_8 },
3458 { .fniv = tcg_gen_shrv_mod_vec,
3459 .fno = gen_helper_gvec_shr16v,
3460 .opt_opc = vecop_list,
3461 .vece = MO_16 },
3462 { .fni4 = tcg_gen_shr_mod_i32,
3463 .fniv = tcg_gen_shrv_mod_vec,
3464 .fno = gen_helper_gvec_shr32v,
3465 .opt_opc = vecop_list,
3466 .vece = MO_32 },
3467 { .fni8 = tcg_gen_shr_mod_i64,
3468 .fniv = tcg_gen_shrv_mod_vec,
3469 .fno = gen_helper_gvec_shr64v,
3470 .opt_opc = vecop_list,
3471 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3472 .vece = MO_64 },
3473 };
3474
3475 tcg_debug_assert(vece <= MO_64);
3476 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
3477}
3478
3479/*
3480 * Similarly for arithmetic right shifts.
3481 */
3482
3483static void tcg_gen_sarv_mod_vec(unsigned vece, TCGv_vec d,
3484 TCGv_vec a, TCGv_vec b)
3485{
3486 TCGv_vec t = tcg_temp_new_vec_matching(d);
Richard Henderson88d40052020-09-03 18:18:08 -07003487 TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
Richard Henderson5ee5c142019-04-13 20:42:37 -10003488
Richard Henderson88d40052020-09-03 18:18:08 -07003489 tcg_gen_and_vec(vece, t, b, m);
Richard Henderson5ee5c142019-04-13 20:42:37 -10003490 tcg_gen_sarv_vec(vece, d, a, t);
3491 tcg_temp_free_vec(t);
3492}
3493
3494static void tcg_gen_sar_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
3495{
Richard Henderson5dd48602023-01-29 13:26:49 -10003496 TCGv_i32 t = tcg_temp_ebb_new_i32();
Richard Henderson5ee5c142019-04-13 20:42:37 -10003497
3498 tcg_gen_andi_i32(t, b, 31);
3499 tcg_gen_sar_i32(d, a, t);
3500 tcg_temp_free_i32(t);
3501}
3502
3503static void tcg_gen_sar_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
3504{
Richard Henderson5dd48602023-01-29 13:26:49 -10003505 TCGv_i64 t = tcg_temp_ebb_new_i64();
Richard Henderson5ee5c142019-04-13 20:42:37 -10003506
3507 tcg_gen_andi_i64(t, b, 63);
3508 tcg_gen_sar_i64(d, a, t);
3509 tcg_temp_free_i64(t);
3510}
3511
3512void tcg_gen_gvec_sarv(unsigned vece, uint32_t dofs, uint32_t aofs,
3513 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
3514{
3515 static const TCGOpcode vecop_list[] = { INDEX_op_sarv_vec, 0 };
3516 static const GVecGen3 g[4] = {
3517 { .fniv = tcg_gen_sarv_mod_vec,
3518 .fno = gen_helper_gvec_sar8v,
3519 .opt_opc = vecop_list,
3520 .vece = MO_8 },
3521 { .fniv = tcg_gen_sarv_mod_vec,
3522 .fno = gen_helper_gvec_sar16v,
3523 .opt_opc = vecop_list,
3524 .vece = MO_16 },
3525 { .fni4 = tcg_gen_sar_mod_i32,
3526 .fniv = tcg_gen_sarv_mod_vec,
3527 .fno = gen_helper_gvec_sar32v,
3528 .opt_opc = vecop_list,
3529 .vece = MO_32 },
3530 { .fni8 = tcg_gen_sar_mod_i64,
3531 .fniv = tcg_gen_sarv_mod_vec,
3532 .fno = gen_helper_gvec_sar64v,
3533 .opt_opc = vecop_list,
3534 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3535 .vece = MO_64 },
3536 };
3537
3538 tcg_debug_assert(vece <= MO_64);
3539 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
3540}
3541
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003542/*
3543 * Similarly for rotates.
3544 */
3545
3546static void tcg_gen_rotlv_mod_vec(unsigned vece, TCGv_vec d,
3547 TCGv_vec a, TCGv_vec b)
3548{
3549 TCGv_vec t = tcg_temp_new_vec_matching(d);
Richard Henderson88d40052020-09-03 18:18:08 -07003550 TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003551
Richard Henderson88d40052020-09-03 18:18:08 -07003552 tcg_gen_and_vec(vece, t, b, m);
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003553 tcg_gen_rotlv_vec(vece, d, a, t);
3554 tcg_temp_free_vec(t);
3555}
3556
3557static void tcg_gen_rotl_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
3558{
Richard Henderson5dd48602023-01-29 13:26:49 -10003559 TCGv_i32 t = tcg_temp_ebb_new_i32();
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003560
3561 tcg_gen_andi_i32(t, b, 31);
3562 tcg_gen_rotl_i32(d, a, t);
3563 tcg_temp_free_i32(t);
3564}
3565
3566static void tcg_gen_rotl_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
3567{
Richard Henderson5dd48602023-01-29 13:26:49 -10003568 TCGv_i64 t = tcg_temp_ebb_new_i64();
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003569
3570 tcg_gen_andi_i64(t, b, 63);
3571 tcg_gen_rotl_i64(d, a, t);
3572 tcg_temp_free_i64(t);
3573}
3574
3575void tcg_gen_gvec_rotlv(unsigned vece, uint32_t dofs, uint32_t aofs,
3576 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
3577{
3578 static const TCGOpcode vecop_list[] = { INDEX_op_rotlv_vec, 0 };
3579 static const GVecGen3 g[4] = {
3580 { .fniv = tcg_gen_rotlv_mod_vec,
3581 .fno = gen_helper_gvec_rotl8v,
3582 .opt_opc = vecop_list,
3583 .vece = MO_8 },
3584 { .fniv = tcg_gen_rotlv_mod_vec,
3585 .fno = gen_helper_gvec_rotl16v,
3586 .opt_opc = vecop_list,
3587 .vece = MO_16 },
3588 { .fni4 = tcg_gen_rotl_mod_i32,
3589 .fniv = tcg_gen_rotlv_mod_vec,
3590 .fno = gen_helper_gvec_rotl32v,
3591 .opt_opc = vecop_list,
3592 .vece = MO_32 },
3593 { .fni8 = tcg_gen_rotl_mod_i64,
3594 .fniv = tcg_gen_rotlv_mod_vec,
3595 .fno = gen_helper_gvec_rotl64v,
3596 .opt_opc = vecop_list,
3597 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3598 .vece = MO_64 },
3599 };
3600
3601 tcg_debug_assert(vece <= MO_64);
3602 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
3603}
3604
3605static void tcg_gen_rotrv_mod_vec(unsigned vece, TCGv_vec d,
3606 TCGv_vec a, TCGv_vec b)
3607{
3608 TCGv_vec t = tcg_temp_new_vec_matching(d);
Richard Henderson88d40052020-09-03 18:18:08 -07003609 TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003610
Richard Henderson88d40052020-09-03 18:18:08 -07003611 tcg_gen_and_vec(vece, t, b, m);
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003612 tcg_gen_rotrv_vec(vece, d, a, t);
3613 tcg_temp_free_vec(t);
3614}
3615
3616static void tcg_gen_rotr_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
3617{
Richard Henderson5dd48602023-01-29 13:26:49 -10003618 TCGv_i32 t = tcg_temp_ebb_new_i32();
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003619
3620 tcg_gen_andi_i32(t, b, 31);
3621 tcg_gen_rotr_i32(d, a, t);
3622 tcg_temp_free_i32(t);
3623}
3624
3625static void tcg_gen_rotr_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
3626{
Richard Henderson5dd48602023-01-29 13:26:49 -10003627 TCGv_i64 t = tcg_temp_ebb_new_i64();
Richard Henderson5d0ceda2020-04-19 19:47:59 -07003628
3629 tcg_gen_andi_i64(t, b, 63);
3630 tcg_gen_rotr_i64(d, a, t);
3631 tcg_temp_free_i64(t);
3632}
3633
3634void tcg_gen_gvec_rotrv(unsigned vece, uint32_t dofs, uint32_t aofs,
3635 uint32_t bofs, uint32_t oprsz, uint32_t maxsz)
3636{
3637 static const TCGOpcode vecop_list[] = { INDEX_op_rotrv_vec, 0 };
3638 static const GVecGen3 g[4] = {
3639 { .fniv = tcg_gen_rotrv_mod_vec,
3640 .fno = gen_helper_gvec_rotr8v,
3641 .opt_opc = vecop_list,
3642 .vece = MO_8 },
3643 { .fniv = tcg_gen_rotrv_mod_vec,
3644 .fno = gen_helper_gvec_rotr16v,
3645 .opt_opc = vecop_list,
3646 .vece = MO_16 },
3647 { .fni4 = tcg_gen_rotr_mod_i32,
3648 .fniv = tcg_gen_rotrv_mod_vec,
3649 .fno = gen_helper_gvec_rotr32v,
3650 .opt_opc = vecop_list,
3651 .vece = MO_32 },
3652 { .fni8 = tcg_gen_rotr_mod_i64,
3653 .fniv = tcg_gen_rotrv_mod_vec,
3654 .fno = gen_helper_gvec_rotr64v,
3655 .opt_opc = vecop_list,
3656 .prefer_i64 = TCG_TARGET_REG_BITS == 64,
3657 .vece = MO_64 },
3658 };
3659
3660 tcg_debug_assert(vece <= MO_64);
3661 tcg_gen_gvec_3(dofs, aofs, bofs, oprsz, maxsz, &g[vece]);
3662}
3663
Richard Henderson212be172017-11-17 20:47:42 +01003664/* Expand OPSZ bytes worth of three-operand operations using i32 elements. */
3665static void expand_cmp_i32(uint32_t dofs, uint32_t aofs, uint32_t bofs,
3666 uint32_t oprsz, TCGCond cond)
3667{
Richard Henderson5dd48602023-01-29 13:26:49 -10003668 TCGv_i32 t0 = tcg_temp_ebb_new_i32();
3669 TCGv_i32 t1 = tcg_temp_ebb_new_i32();
Richard Henderson212be172017-11-17 20:47:42 +01003670 uint32_t i;
3671
3672 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -07003673 tcg_gen_ld_i32(t0, tcg_env, aofs + i);
3674 tcg_gen_ld_i32(t1, tcg_env, bofs + i);
Richard Henderson4a883872023-08-04 23:29:53 +00003675 tcg_gen_negsetcond_i32(cond, t0, t0, t1);
Richard Hendersonad75a512023-09-13 16:37:36 -07003676 tcg_gen_st_i32(t0, tcg_env, dofs + i);
Richard Henderson212be172017-11-17 20:47:42 +01003677 }
3678 tcg_temp_free_i32(t1);
3679 tcg_temp_free_i32(t0);
3680}
3681
3682static void expand_cmp_i64(uint32_t dofs, uint32_t aofs, uint32_t bofs,
3683 uint32_t oprsz, TCGCond cond)
3684{
Richard Henderson5dd48602023-01-29 13:26:49 -10003685 TCGv_i64 t0 = tcg_temp_ebb_new_i64();
3686 TCGv_i64 t1 = tcg_temp_ebb_new_i64();
Richard Henderson212be172017-11-17 20:47:42 +01003687 uint32_t i;
3688
3689 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -07003690 tcg_gen_ld_i64(t0, tcg_env, aofs + i);
3691 tcg_gen_ld_i64(t1, tcg_env, bofs + i);
Richard Henderson4a883872023-08-04 23:29:53 +00003692 tcg_gen_negsetcond_i64(cond, t0, t0, t1);
Richard Hendersonad75a512023-09-13 16:37:36 -07003693 tcg_gen_st_i64(t0, tcg_env, dofs + i);
Richard Henderson212be172017-11-17 20:47:42 +01003694 }
3695 tcg_temp_free_i64(t1);
3696 tcg_temp_free_i64(t0);
3697}
3698
3699static void expand_cmp_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
3700 uint32_t bofs, uint32_t oprsz, uint32_t tysz,
3701 TCGType type, TCGCond cond)
3702{
Richard Henderson9628d002023-08-23 20:35:05 -07003703 for (uint32_t i = 0; i < oprsz; i += tysz) {
3704 TCGv_vec t0 = tcg_temp_new_vec(type);
3705 TCGv_vec t1 = tcg_temp_new_vec(type);
3706 TCGv_vec t2 = tcg_temp_new_vec(type);
Richard Henderson212be172017-11-17 20:47:42 +01003707
Richard Hendersonad75a512023-09-13 16:37:36 -07003708 tcg_gen_ld_vec(t0, tcg_env, aofs + i);
3709 tcg_gen_ld_vec(t1, tcg_env, bofs + i);
Richard Henderson9628d002023-08-23 20:35:05 -07003710 tcg_gen_cmp_vec(cond, vece, t2, t0, t1);
3711 tcg_gen_st_vec(t2, tcg_env, dofs + i);
Richard Henderson212be172017-11-17 20:47:42 +01003712 }
Richard Henderson212be172017-11-17 20:47:42 +01003713}
3714
3715void tcg_gen_gvec_cmp(TCGCond cond, unsigned vece, uint32_t dofs,
3716 uint32_t aofs, uint32_t bofs,
3717 uint32_t oprsz, uint32_t maxsz)
3718{
Richard Henderson53229a72019-03-17 00:27:29 +00003719 static const TCGOpcode cmp_list[] = { INDEX_op_cmp_vec, 0 };
Richard Henderson212be172017-11-17 20:47:42 +01003720 static gen_helper_gvec_3 * const eq_fn[4] = {
3721 gen_helper_gvec_eq8, gen_helper_gvec_eq16,
3722 gen_helper_gvec_eq32, gen_helper_gvec_eq64
3723 };
3724 static gen_helper_gvec_3 * const ne_fn[4] = {
3725 gen_helper_gvec_ne8, gen_helper_gvec_ne16,
3726 gen_helper_gvec_ne32, gen_helper_gvec_ne64
3727 };
3728 static gen_helper_gvec_3 * const lt_fn[4] = {
3729 gen_helper_gvec_lt8, gen_helper_gvec_lt16,
3730 gen_helper_gvec_lt32, gen_helper_gvec_lt64
3731 };
3732 static gen_helper_gvec_3 * const le_fn[4] = {
3733 gen_helper_gvec_le8, gen_helper_gvec_le16,
3734 gen_helper_gvec_le32, gen_helper_gvec_le64
3735 };
3736 static gen_helper_gvec_3 * const ltu_fn[4] = {
3737 gen_helper_gvec_ltu8, gen_helper_gvec_ltu16,
3738 gen_helper_gvec_ltu32, gen_helper_gvec_ltu64
3739 };
3740 static gen_helper_gvec_3 * const leu_fn[4] = {
3741 gen_helper_gvec_leu8, gen_helper_gvec_leu16,
3742 gen_helper_gvec_leu32, gen_helper_gvec_leu64
3743 };
3744 static gen_helper_gvec_3 * const * const fns[16] = {
3745 [TCG_COND_EQ] = eq_fn,
3746 [TCG_COND_NE] = ne_fn,
3747 [TCG_COND_LT] = lt_fn,
3748 [TCG_COND_LE] = le_fn,
3749 [TCG_COND_LTU] = ltu_fn,
3750 [TCG_COND_LEU] = leu_fn,
3751 };
Richard Henderson53229a72019-03-17 00:27:29 +00003752
3753 const TCGOpcode *hold_list;
Richard Hendersonadb196c2018-02-17 08:30:16 -08003754 TCGType type;
3755 uint32_t some;
Richard Henderson212be172017-11-17 20:47:42 +01003756
3757 check_size_align(oprsz, maxsz, dofs | aofs | bofs);
3758 check_overlap_3(dofs, aofs, bofs, maxsz);
3759
3760 if (cond == TCG_COND_NEVER || cond == TCG_COND_ALWAYS) {
3761 do_dup(MO_8, dofs, oprsz, maxsz,
3762 NULL, NULL, -(cond == TCG_COND_ALWAYS));
3763 return;
3764 }
3765
Richard Henderson53229a72019-03-17 00:27:29 +00003766 /*
3767 * Implement inline with a vector type, if possible.
Richard Hendersonadb196c2018-02-17 08:30:16 -08003768 * Prefer integer when 64-bit host and 64-bit comparison.
3769 */
Richard Henderson53229a72019-03-17 00:27:29 +00003770 hold_list = tcg_swap_vecop_list(cmp_list);
3771 type = choose_vector_type(cmp_list, vece, oprsz,
Richard Hendersonadb196c2018-02-17 08:30:16 -08003772 TCG_TARGET_REG_BITS == 64 && vece == MO_64);
3773 switch (type) {
3774 case TCG_TYPE_V256:
3775 /* Recall that ARM SVE allows vector sizes that are not a
3776 * power of 2, but always a multiple of 16. The intent is
3777 * that e.g. size == 80 would be expanded with 2x32 + 1x16.
3778 */
3779 some = QEMU_ALIGN_DOWN(oprsz, 32);
Richard Henderson212be172017-11-17 20:47:42 +01003780 expand_cmp_vec(vece, dofs, aofs, bofs, some, 32, TCG_TYPE_V256, cond);
3781 if (some == oprsz) {
Richard Hendersonadb196c2018-02-17 08:30:16 -08003782 break;
Richard Henderson212be172017-11-17 20:47:42 +01003783 }
3784 dofs += some;
3785 aofs += some;
3786 bofs += some;
3787 oprsz -= some;
3788 maxsz -= some;
Richard Hendersonadb196c2018-02-17 08:30:16 -08003789 /* fallthru */
3790 case TCG_TYPE_V128:
Richard Henderson212be172017-11-17 20:47:42 +01003791 expand_cmp_vec(vece, dofs, aofs, bofs, oprsz, 16, TCG_TYPE_V128, cond);
Richard Hendersonadb196c2018-02-17 08:30:16 -08003792 break;
3793 case TCG_TYPE_V64:
Richard Henderson212be172017-11-17 20:47:42 +01003794 expand_cmp_vec(vece, dofs, aofs, bofs, oprsz, 8, TCG_TYPE_V64, cond);
Richard Hendersonadb196c2018-02-17 08:30:16 -08003795 break;
Richard Henderson212be172017-11-17 20:47:42 +01003796
Richard Hendersonadb196c2018-02-17 08:30:16 -08003797 case 0:
3798 if (vece == MO_64 && check_size_impl(oprsz, 8)) {
3799 expand_cmp_i64(dofs, aofs, bofs, oprsz, cond);
3800 } else if (vece == MO_32 && check_size_impl(oprsz, 4)) {
3801 expand_cmp_i32(dofs, aofs, bofs, oprsz, cond);
3802 } else {
3803 gen_helper_gvec_3 * const *fn = fns[cond];
3804
3805 if (fn == NULL) {
3806 uint32_t tmp;
3807 tmp = aofs, aofs = bofs, bofs = tmp;
3808 cond = tcg_swap_cond(cond);
3809 fn = fns[cond];
3810 assert(fn != NULL);
3811 }
3812 tcg_gen_gvec_3_ool(dofs, aofs, bofs, oprsz, maxsz, 0, fn[vece]);
Richard Henderson53229a72019-03-17 00:27:29 +00003813 oprsz = maxsz;
Richard Henderson212be172017-11-17 20:47:42 +01003814 }
Richard Hendersonadb196c2018-02-17 08:30:16 -08003815 break;
3816
3817 default:
3818 g_assert_not_reached();
Richard Henderson212be172017-11-17 20:47:42 +01003819 }
Richard Henderson53229a72019-03-17 00:27:29 +00003820 tcg_swap_vecop_list(hold_list);
Richard Henderson212be172017-11-17 20:47:42 +01003821
Richard Henderson212be172017-11-17 20:47:42 +01003822 if (oprsz < maxsz) {
3823 expand_clr(dofs + oprsz, maxsz - oprsz);
3824 }
3825}
Richard Henderson38dc1292019-04-30 11:02:23 -07003826
Richard Henderson9622c692023-08-30 20:09:03 -07003827static void expand_cmps_vec(unsigned vece, uint32_t dofs, uint32_t aofs,
3828 uint32_t oprsz, uint32_t tysz, TCGType type,
3829 TCGCond cond, TCGv_vec c)
3830{
3831 TCGv_vec t0 = tcg_temp_new_vec(type);
3832 TCGv_vec t1 = tcg_temp_new_vec(type);
3833 uint32_t i;
3834
3835 for (i = 0; i < oprsz; i += tysz) {
Richard Hendersonad75a512023-09-13 16:37:36 -07003836 tcg_gen_ld_vec(t1, tcg_env, aofs + i);
Richard Henderson9622c692023-08-30 20:09:03 -07003837 tcg_gen_cmp_vec(cond, vece, t0, t1, c);
Richard Hendersonad75a512023-09-13 16:37:36 -07003838 tcg_gen_st_vec(t0, tcg_env, dofs + i);
Richard Henderson9622c692023-08-30 20:09:03 -07003839 }
3840}
3841
3842void tcg_gen_gvec_cmps(TCGCond cond, unsigned vece, uint32_t dofs,
3843 uint32_t aofs, TCGv_i64 c,
3844 uint32_t oprsz, uint32_t maxsz)
3845{
3846 static const TCGOpcode cmp_list[] = { INDEX_op_cmp_vec, 0 };
3847 static gen_helper_gvec_2i * const eq_fn[4] = {
3848 gen_helper_gvec_eqs8, gen_helper_gvec_eqs16,
3849 gen_helper_gvec_eqs32, gen_helper_gvec_eqs64
3850 };
3851 static gen_helper_gvec_2i * const lt_fn[4] = {
3852 gen_helper_gvec_lts8, gen_helper_gvec_lts16,
3853 gen_helper_gvec_lts32, gen_helper_gvec_lts64
3854 };
3855 static gen_helper_gvec_2i * const le_fn[4] = {
3856 gen_helper_gvec_les8, gen_helper_gvec_les16,
3857 gen_helper_gvec_les32, gen_helper_gvec_les64
3858 };
3859 static gen_helper_gvec_2i * const ltu_fn[4] = {
3860 gen_helper_gvec_ltus8, gen_helper_gvec_ltus16,
3861 gen_helper_gvec_ltus32, gen_helper_gvec_ltus64
3862 };
3863 static gen_helper_gvec_2i * const leu_fn[4] = {
3864 gen_helper_gvec_leus8, gen_helper_gvec_leus16,
3865 gen_helper_gvec_leus32, gen_helper_gvec_leus64
3866 };
3867 static gen_helper_gvec_2i * const * const fns[16] = {
3868 [TCG_COND_EQ] = eq_fn,
3869 [TCG_COND_LT] = lt_fn,
3870 [TCG_COND_LE] = le_fn,
3871 [TCG_COND_LTU] = ltu_fn,
3872 [TCG_COND_LEU] = leu_fn,
3873 };
3874
3875 TCGType type;
3876
3877 check_size_align(oprsz, maxsz, dofs | aofs);
3878 check_overlap_2(dofs, aofs, maxsz);
3879
3880 if (cond == TCG_COND_NEVER || cond == TCG_COND_ALWAYS) {
3881 do_dup(MO_8, dofs, oprsz, maxsz,
3882 NULL, NULL, -(cond == TCG_COND_ALWAYS));
3883 return;
3884 }
3885
3886 /*
3887 * Implement inline with a vector type, if possible.
3888 * Prefer integer when 64-bit host and 64-bit comparison.
3889 */
3890 type = choose_vector_type(cmp_list, vece, oprsz,
3891 TCG_TARGET_REG_BITS == 64 && vece == MO_64);
3892 if (type != 0) {
3893 const TCGOpcode *hold_list = tcg_swap_vecop_list(cmp_list);
3894 TCGv_vec t_vec = tcg_temp_new_vec(type);
3895 uint32_t some;
3896
3897 tcg_gen_dup_i64_vec(vece, t_vec, c);
3898 switch (type) {
3899 case TCG_TYPE_V256:
3900 some = QEMU_ALIGN_DOWN(oprsz, 32);
3901 expand_cmps_vec(vece, dofs, aofs, some, 32,
3902 TCG_TYPE_V256, cond, t_vec);
3903 aofs += some;
3904 dofs += some;
3905 oprsz -= some;
3906 maxsz -= some;
3907 /* fallthru */
3908
3909 case TCG_TYPE_V128:
3910 some = QEMU_ALIGN_DOWN(oprsz, 16);
3911 expand_cmps_vec(vece, dofs, aofs, some, 16,
3912 TCG_TYPE_V128, cond, t_vec);
3913 break;
3914
3915 case TCG_TYPE_V64:
3916 some = QEMU_ALIGN_DOWN(oprsz, 8);
3917 expand_cmps_vec(vece, dofs, aofs, some, 8,
3918 TCG_TYPE_V64, cond, t_vec);
3919 break;
3920
3921 default:
3922 g_assert_not_reached();
3923 }
3924 tcg_temp_free_vec(t_vec);
3925 tcg_swap_vecop_list(hold_list);
3926 } else if (vece == MO_64 && check_size_impl(oprsz, 8)) {
3927 TCGv_i64 t0 = tcg_temp_ebb_new_i64();
3928 uint32_t i;
3929
3930 for (i = 0; i < oprsz; i += 8) {
Richard Hendersonad75a512023-09-13 16:37:36 -07003931 tcg_gen_ld_i64(t0, tcg_env, aofs + i);
Richard Henderson9622c692023-08-30 20:09:03 -07003932 tcg_gen_negsetcond_i64(cond, t0, t0, c);
Richard Hendersonad75a512023-09-13 16:37:36 -07003933 tcg_gen_st_i64(t0, tcg_env, dofs + i);
Richard Henderson9622c692023-08-30 20:09:03 -07003934 }
3935 tcg_temp_free_i64(t0);
3936 } else if (vece == MO_32 && check_size_impl(oprsz, 4)) {
3937 TCGv_i32 t0 = tcg_temp_ebb_new_i32();
3938 TCGv_i32 t1 = tcg_temp_ebb_new_i32();
3939 uint32_t i;
3940
3941 tcg_gen_extrl_i64_i32(t1, c);
TANG Tiancheng9d8d5a52024-09-04 22:27:26 +08003942 for (i = 0; i < oprsz; i += 4) {
Richard Hendersonad75a512023-09-13 16:37:36 -07003943 tcg_gen_ld_i32(t0, tcg_env, aofs + i);
Richard Henderson9622c692023-08-30 20:09:03 -07003944 tcg_gen_negsetcond_i32(cond, t0, t0, t1);
Richard Hendersonad75a512023-09-13 16:37:36 -07003945 tcg_gen_st_i32(t0, tcg_env, dofs + i);
Richard Henderson9622c692023-08-30 20:09:03 -07003946 }
3947 tcg_temp_free_i32(t0);
3948 tcg_temp_free_i32(t1);
3949 } else {
3950 gen_helper_gvec_2i * const *fn = fns[cond];
3951 bool inv = false;
3952
3953 if (fn == NULL) {
3954 cond = tcg_invert_cond(cond);
3955 fn = fns[cond];
3956 assert(fn != NULL);
3957 inv = true;
3958 }
3959 tcg_gen_gvec_2i_ool(dofs, aofs, c, oprsz, maxsz, inv, fn[vece]);
3960 return;
3961 }
3962
3963 if (oprsz < maxsz) {
3964 expand_clr(dofs + oprsz, maxsz - oprsz);
3965 }
3966}
3967
3968void tcg_gen_gvec_cmpi(TCGCond cond, unsigned vece, uint32_t dofs,
3969 uint32_t aofs, int64_t c,
3970 uint32_t oprsz, uint32_t maxsz)
3971{
3972 TCGv_i64 tmp = tcg_constant_i64(c);
3973 tcg_gen_gvec_cmps(cond, vece, dofs, aofs, tmp, oprsz, maxsz);
3974}
3975
Richard Henderson38dc1292019-04-30 11:02:23 -07003976static void tcg_gen_bitsel_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 c)
3977{
Richard Henderson5dd48602023-01-29 13:26:49 -10003978 TCGv_i64 t = tcg_temp_ebb_new_i64();
Richard Henderson38dc1292019-04-30 11:02:23 -07003979
3980 tcg_gen_and_i64(t, b, a);
3981 tcg_gen_andc_i64(d, c, a);
3982 tcg_gen_or_i64(d, d, t);
3983 tcg_temp_free_i64(t);
3984}
3985
3986void tcg_gen_gvec_bitsel(unsigned vece, uint32_t dofs, uint32_t aofs,
3987 uint32_t bofs, uint32_t cofs,
3988 uint32_t oprsz, uint32_t maxsz)
3989{
3990 static const GVecGen4 g = {
3991 .fni8 = tcg_gen_bitsel_i64,
3992 .fniv = tcg_gen_bitsel_vec,
3993 .fno = gen_helper_gvec_bitsel,
3994 };
3995
3996 tcg_gen_gvec_4(dofs, aofs, bofs, cofs, oprsz, maxsz, &g);
3997}