2 * Tiny Code Generator for QEMU
4 * Copyright (c) 2018 Linaro, Inc.
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
9 * version 2.1 of the License, or (at your option) any later version.
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.
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/>.
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
27 /* Reduce the number of ifdefs below. This assumes that all uses of
28 TCGV_HIGH and TCGV_LOW are properly protected by a conditional that
29 the compiler can eliminate. */
30 #if TCG_TARGET_REG_BITS == 64
31 extern TCGv_i32
TCGV_LOW_link_error(TCGv_i64
);
32 extern TCGv_i32
TCGV_HIGH_link_error(TCGv_i64
);
33 #define TCGV_LOW TCGV_LOW_link_error
34 #define TCGV_HIGH TCGV_HIGH_link_error
38 * Vector optional opcode tracking.
39 * Except for the basic logical operations (and, or, xor), and
40 * data movement (mov, ld, st, dupi), many vector opcodes are
41 * optional and may not be supported on the host. Thank Intel
42 * for the irregularity in their instruction set.
44 * The gvec expanders allow custom vector operations to be composed,
45 * generally via the .fniv callback in the GVecGen* structures. At
46 * the same time, in deciding whether to use this hook we need to
47 * know if the host supports the required operations. This is
48 * presented as an array of opcodes, terminated by 0. Each opcode
49 * is assumed to be expanded with the given VECE.
51 * For debugging, we want to validate this array. Therefore, when
52 * tcg_ctx->vec_opt_opc is non-NULL, the tcg_gen_*_vec expanders
53 * will validate that their opcode is present in the list.
55 #ifdef CONFIG_DEBUG_TCG
56 void tcg_assert_listed_vecop(TCGOpcode op
)
58 const TCGOpcode
*p
= tcg_ctx
->vecop_list
;
65 g_assert_not_reached();
70 bool tcg_can_emit_vecop_list(const TCGOpcode
*list
,
71 TCGType type
, unsigned vece
)
77 for (; *list
; ++list
) {
78 TCGOpcode opc
= *list
;
80 #ifdef CONFIG_DEBUG_TCG
82 case INDEX_op_and_vec
:
84 case INDEX_op_xor_vec
:
85 case INDEX_op_mov_vec
:
86 case INDEX_op_dup_vec
:
87 case INDEX_op_dupi_vec
:
88 case INDEX_op_dup2_vec
:
91 case INDEX_op_bitsel_vec
:
92 /* These opcodes are mandatory and should not be listed. */
93 g_assert_not_reached();
99 if (tcg_can_emit_vec_op(opc
, type
, vece
)) {
104 * The opcode list is created by front ends based on what they
105 * actually invoke. We must mirror the logic in the routines
106 * below for generic expansions using other opcodes.
109 case INDEX_op_neg_vec
:
110 if (tcg_can_emit_vec_op(INDEX_op_sub_vec
, type
, vece
)) {
114 case INDEX_op_abs_vec
:
115 if (tcg_can_emit_vec_op(INDEX_op_sub_vec
, type
, vece
)
116 && (tcg_can_emit_vec_op(INDEX_op_smax_vec
, type
, vece
) > 0
117 || tcg_can_emit_vec_op(INDEX_op_sari_vec
, type
, vece
) > 0
118 || tcg_can_emit_vec_op(INDEX_op_cmp_vec
, type
, vece
))) {
122 case INDEX_op_cmpsel_vec
:
123 if (tcg_can_emit_vec_op(INDEX_op_cmp_vec
, type
, vece
)) {
135 void vec_gen_2(TCGOpcode opc
, TCGType type
, unsigned vece
, TCGArg r
, TCGArg a
)
137 TCGOp
*op
= tcg_emit_op(opc
);
138 TCGOP_VECL(op
) = type
- TCG_TYPE_V64
;
139 TCGOP_VECE(op
) = vece
;
144 void vec_gen_3(TCGOpcode opc
, TCGType type
, unsigned vece
,
145 TCGArg r
, TCGArg a
, TCGArg b
)
147 TCGOp
*op
= tcg_emit_op(opc
);
148 TCGOP_VECL(op
) = type
- TCG_TYPE_V64
;
149 TCGOP_VECE(op
) = vece
;
155 void vec_gen_4(TCGOpcode opc
, TCGType type
, unsigned vece
,
156 TCGArg r
, TCGArg a
, TCGArg b
, TCGArg c
)
158 TCGOp
*op
= tcg_emit_op(opc
);
159 TCGOP_VECL(op
) = type
- TCG_TYPE_V64
;
160 TCGOP_VECE(op
) = vece
;
167 static void vec_gen_6(TCGOpcode opc
, TCGType type
, unsigned vece
, TCGArg r
,
168 TCGArg a
, TCGArg b
, TCGArg c
, TCGArg d
, TCGArg e
)
170 TCGOp
*op
= tcg_emit_op(opc
);
171 TCGOP_VECL(op
) = type
- TCG_TYPE_V64
;
172 TCGOP_VECE(op
) = vece
;
181 static void vec_gen_op2(TCGOpcode opc
, unsigned vece
, TCGv_vec r
, TCGv_vec a
)
183 TCGTemp
*rt
= tcgv_vec_temp(r
);
184 TCGTemp
*at
= tcgv_vec_temp(a
);
185 TCGType type
= rt
->base_type
;
187 /* Must enough inputs for the output. */
188 tcg_debug_assert(at
->base_type
>= type
);
189 vec_gen_2(opc
, type
, vece
, temp_arg(rt
), temp_arg(at
));
192 static void vec_gen_op3(TCGOpcode opc
, unsigned vece
,
193 TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
195 TCGTemp
*rt
= tcgv_vec_temp(r
);
196 TCGTemp
*at
= tcgv_vec_temp(a
);
197 TCGTemp
*bt
= tcgv_vec_temp(b
);
198 TCGType type
= rt
->base_type
;
200 /* Must enough inputs for the output. */
201 tcg_debug_assert(at
->base_type
>= type
);
202 tcg_debug_assert(bt
->base_type
>= type
);
203 vec_gen_3(opc
, type
, vece
, temp_arg(rt
), temp_arg(at
), temp_arg(bt
));
206 void tcg_gen_mov_vec(TCGv_vec r
, TCGv_vec a
)
209 vec_gen_op2(INDEX_op_mov_vec
, 0, r
, a
);
213 #define MO_REG (TCG_TARGET_REG_BITS == 64 ? MO_64 : MO_32)
215 static void do_dupi_vec(TCGv_vec r
, unsigned vece
, TCGArg a
)
217 TCGTemp
*rt
= tcgv_vec_temp(r
);
218 vec_gen_2(INDEX_op_dupi_vec
, rt
->base_type
, vece
, temp_arg(rt
), a
);
221 TCGv_vec
tcg_const_zeros_vec(TCGType type
)
223 TCGv_vec ret
= tcg_temp_new_vec(type
);
224 do_dupi_vec(ret
, MO_REG
, 0);
228 TCGv_vec
tcg_const_ones_vec(TCGType type
)
230 TCGv_vec ret
= tcg_temp_new_vec(type
);
231 do_dupi_vec(ret
, MO_REG
, -1);
235 TCGv_vec
tcg_const_zeros_vec_matching(TCGv_vec m
)
237 TCGTemp
*t
= tcgv_vec_temp(m
);
238 return tcg_const_zeros_vec(t
->base_type
);
241 TCGv_vec
tcg_const_ones_vec_matching(TCGv_vec m
)
243 TCGTemp
*t
= tcgv_vec_temp(m
);
244 return tcg_const_ones_vec(t
->base_type
);
247 void tcg_gen_dup64i_vec(TCGv_vec r
, uint64_t a
)
249 if (TCG_TARGET_REG_BITS
== 32 && a
== deposit64(a
, 32, 32, a
)) {
250 do_dupi_vec(r
, MO_32
, a
);
251 } else if (TCG_TARGET_REG_BITS
== 64 || a
== (uint64_t)(int32_t)a
) {
252 do_dupi_vec(r
, MO_64
, a
);
254 TCGv_i64 c
= tcg_const_i64(a
);
255 tcg_gen_dup_i64_vec(MO_64
, r
, c
);
256 tcg_temp_free_i64(c
);
260 void tcg_gen_dup32i_vec(TCGv_vec r
, uint32_t a
)
262 do_dupi_vec(r
, MO_REG
, dup_const(MO_32
, a
));
265 void tcg_gen_dup16i_vec(TCGv_vec r
, uint32_t a
)
267 do_dupi_vec(r
, MO_REG
, dup_const(MO_16
, a
));
270 void tcg_gen_dup8i_vec(TCGv_vec r
, uint32_t a
)
272 do_dupi_vec(r
, MO_REG
, dup_const(MO_8
, a
));
275 void tcg_gen_dupi_vec(unsigned vece
, TCGv_vec r
, uint64_t a
)
277 do_dupi_vec(r
, MO_REG
, dup_const(vece
, a
));
280 void tcg_gen_dup_i64_vec(unsigned vece
, TCGv_vec r
, TCGv_i64 a
)
282 TCGArg ri
= tcgv_vec_arg(r
);
283 TCGTemp
*rt
= arg_temp(ri
);
284 TCGType type
= rt
->base_type
;
286 if (TCG_TARGET_REG_BITS
== 64) {
287 TCGArg ai
= tcgv_i64_arg(a
);
288 vec_gen_2(INDEX_op_dup_vec
, type
, vece
, ri
, ai
);
289 } else if (vece
== MO_64
) {
290 TCGArg al
= tcgv_i32_arg(TCGV_LOW(a
));
291 TCGArg ah
= tcgv_i32_arg(TCGV_HIGH(a
));
292 vec_gen_3(INDEX_op_dup2_vec
, type
, MO_64
, ri
, al
, ah
);
294 TCGArg ai
= tcgv_i32_arg(TCGV_LOW(a
));
295 vec_gen_2(INDEX_op_dup_vec
, type
, vece
, ri
, ai
);
299 void tcg_gen_dup_i32_vec(unsigned vece
, TCGv_vec r
, TCGv_i32 a
)
301 TCGArg ri
= tcgv_vec_arg(r
);
302 TCGArg ai
= tcgv_i32_arg(a
);
303 TCGTemp
*rt
= arg_temp(ri
);
304 TCGType type
= rt
->base_type
;
306 vec_gen_2(INDEX_op_dup_vec
, type
, vece
, ri
, ai
);
309 void tcg_gen_dup_mem_vec(unsigned vece
, TCGv_vec r
, TCGv_ptr b
,
312 TCGArg ri
= tcgv_vec_arg(r
);
313 TCGArg bi
= tcgv_ptr_arg(b
);
314 TCGTemp
*rt
= arg_temp(ri
);
315 TCGType type
= rt
->base_type
;
317 vec_gen_3(INDEX_op_dupm_vec
, type
, vece
, ri
, bi
, ofs
);
320 static void vec_gen_ldst(TCGOpcode opc
, TCGv_vec r
, TCGv_ptr b
, TCGArg o
)
322 TCGArg ri
= tcgv_vec_arg(r
);
323 TCGArg bi
= tcgv_ptr_arg(b
);
324 TCGTemp
*rt
= arg_temp(ri
);
325 TCGType type
= rt
->base_type
;
327 vec_gen_3(opc
, type
, 0, ri
, bi
, o
);
330 void tcg_gen_ld_vec(TCGv_vec r
, TCGv_ptr b
, TCGArg o
)
332 vec_gen_ldst(INDEX_op_ld_vec
, r
, b
, o
);
335 void tcg_gen_st_vec(TCGv_vec r
, TCGv_ptr b
, TCGArg o
)
337 vec_gen_ldst(INDEX_op_st_vec
, r
, b
, o
);
340 void tcg_gen_stl_vec(TCGv_vec r
, TCGv_ptr b
, TCGArg o
, TCGType low_type
)
342 TCGArg ri
= tcgv_vec_arg(r
);
343 TCGArg bi
= tcgv_ptr_arg(b
);
344 TCGTemp
*rt
= arg_temp(ri
);
345 TCGType type
= rt
->base_type
;
347 tcg_debug_assert(low_type
>= TCG_TYPE_V64
);
348 tcg_debug_assert(low_type
<= type
);
349 vec_gen_3(INDEX_op_st_vec
, low_type
, 0, ri
, bi
, o
);
352 void tcg_gen_and_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
354 vec_gen_op3(INDEX_op_and_vec
, 0, r
, a
, b
);
357 void tcg_gen_or_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
359 vec_gen_op3(INDEX_op_or_vec
, 0, r
, a
, b
);
362 void tcg_gen_xor_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
364 vec_gen_op3(INDEX_op_xor_vec
, 0, r
, a
, b
);
367 void tcg_gen_andc_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
369 if (TCG_TARGET_HAS_andc_vec
) {
370 vec_gen_op3(INDEX_op_andc_vec
, 0, r
, a
, b
);
372 TCGv_vec t
= tcg_temp_new_vec_matching(r
);
373 tcg_gen_not_vec(0, t
, b
);
374 tcg_gen_and_vec(0, r
, a
, t
);
375 tcg_temp_free_vec(t
);
379 void tcg_gen_orc_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
381 if (TCG_TARGET_HAS_orc_vec
) {
382 vec_gen_op3(INDEX_op_orc_vec
, 0, r
, a
, b
);
384 TCGv_vec t
= tcg_temp_new_vec_matching(r
);
385 tcg_gen_not_vec(0, t
, b
);
386 tcg_gen_or_vec(0, r
, a
, t
);
387 tcg_temp_free_vec(t
);
391 void tcg_gen_nand_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
393 /* TODO: Add TCG_TARGET_HAS_nand_vec when adding a backend supports it. */
394 tcg_gen_and_vec(0, r
, a
, b
);
395 tcg_gen_not_vec(0, r
, r
);
398 void tcg_gen_nor_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
400 /* TODO: Add TCG_TARGET_HAS_nor_vec when adding a backend supports it. */
401 tcg_gen_or_vec(0, r
, a
, b
);
402 tcg_gen_not_vec(0, r
, r
);
405 void tcg_gen_eqv_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
407 /* TODO: Add TCG_TARGET_HAS_eqv_vec when adding a backend supports it. */
408 tcg_gen_xor_vec(0, r
, a
, b
);
409 tcg_gen_not_vec(0, r
, r
);
412 static bool do_op2(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGOpcode opc
)
414 TCGTemp
*rt
= tcgv_vec_temp(r
);
415 TCGTemp
*at
= tcgv_vec_temp(a
);
416 TCGArg ri
= temp_arg(rt
);
417 TCGArg ai
= temp_arg(at
);
418 TCGType type
= rt
->base_type
;
421 tcg_debug_assert(at
->base_type
>= type
);
422 tcg_assert_listed_vecop(opc
);
423 can
= tcg_can_emit_vec_op(opc
, type
, vece
);
425 vec_gen_2(opc
, type
, vece
, ri
, ai
);
426 } else if (can
< 0) {
427 const TCGOpcode
*hold_list
= tcg_swap_vecop_list(NULL
);
428 tcg_expand_vec_op(opc
, type
, vece
, ri
, ai
);
429 tcg_swap_vecop_list(hold_list
);
436 void tcg_gen_not_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
)
438 if (!TCG_TARGET_HAS_not_vec
|| !do_op2(vece
, r
, a
, INDEX_op_not_vec
)) {
439 TCGv_vec t
= tcg_const_ones_vec_matching(r
);
440 tcg_gen_xor_vec(0, r
, a
, t
);
441 tcg_temp_free_vec(t
);
445 void tcg_gen_neg_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
)
447 const TCGOpcode
*hold_list
;
449 tcg_assert_listed_vecop(INDEX_op_neg_vec
);
450 hold_list
= tcg_swap_vecop_list(NULL
);
452 if (!TCG_TARGET_HAS_neg_vec
|| !do_op2(vece
, r
, a
, INDEX_op_neg_vec
)) {
453 TCGv_vec t
= tcg_const_zeros_vec_matching(r
);
454 tcg_gen_sub_vec(vece
, r
, t
, a
);
455 tcg_temp_free_vec(t
);
457 tcg_swap_vecop_list(hold_list
);
460 void tcg_gen_abs_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
)
462 const TCGOpcode
*hold_list
;
464 tcg_assert_listed_vecop(INDEX_op_abs_vec
);
465 hold_list
= tcg_swap_vecop_list(NULL
);
467 if (!do_op2(vece
, r
, a
, INDEX_op_abs_vec
)) {
468 TCGType type
= tcgv_vec_temp(r
)->base_type
;
469 TCGv_vec t
= tcg_temp_new_vec(type
);
471 tcg_debug_assert(tcg_can_emit_vec_op(INDEX_op_sub_vec
, type
, vece
));
472 if (tcg_can_emit_vec_op(INDEX_op_smax_vec
, type
, vece
) > 0) {
473 tcg_gen_neg_vec(vece
, t
, a
);
474 tcg_gen_smax_vec(vece
, r
, a
, t
);
476 if (tcg_can_emit_vec_op(INDEX_op_sari_vec
, type
, vece
) > 0) {
477 tcg_gen_sari_vec(vece
, t
, a
, (8 << vece
) - 1);
479 do_dupi_vec(t
, MO_REG
, 0);
480 tcg_gen_cmp_vec(TCG_COND_LT
, vece
, t
, a
, t
);
482 tcg_gen_xor_vec(vece
, r
, a
, t
);
483 tcg_gen_sub_vec(vece
, r
, r
, t
);
486 tcg_temp_free_vec(t
);
488 tcg_swap_vecop_list(hold_list
);
491 static void do_shifti(TCGOpcode opc
, unsigned vece
,
492 TCGv_vec r
, TCGv_vec a
, int64_t i
)
494 TCGTemp
*rt
= tcgv_vec_temp(r
);
495 TCGTemp
*at
= tcgv_vec_temp(a
);
496 TCGArg ri
= temp_arg(rt
);
497 TCGArg ai
= temp_arg(at
);
498 TCGType type
= rt
->base_type
;
501 tcg_debug_assert(at
->base_type
== type
);
502 tcg_debug_assert(i
>= 0 && i
< (8 << vece
));
503 tcg_assert_listed_vecop(opc
);
506 tcg_gen_mov_vec(r
, a
);
510 can
= tcg_can_emit_vec_op(opc
, type
, vece
);
512 vec_gen_3(opc
, type
, vece
, ri
, ai
, i
);
514 /* We leave the choice of expansion via scalar or vector shift
515 to the target. Often, but not always, dupi can feed a vector
516 shift easier than a scalar. */
517 const TCGOpcode
*hold_list
= tcg_swap_vecop_list(NULL
);
518 tcg_debug_assert(can
< 0);
519 tcg_expand_vec_op(opc
, type
, vece
, ri
, ai
, i
);
520 tcg_swap_vecop_list(hold_list
);
524 void tcg_gen_shli_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, int64_t i
)
526 do_shifti(INDEX_op_shli_vec
, vece
, r
, a
, i
);
529 void tcg_gen_shri_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, int64_t i
)
531 do_shifti(INDEX_op_shri_vec
, vece
, r
, a
, i
);
534 void tcg_gen_sari_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, int64_t i
)
536 do_shifti(INDEX_op_sari_vec
, vece
, r
, a
, i
);
539 void tcg_gen_cmp_vec(TCGCond cond
, unsigned vece
,
540 TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
542 TCGTemp
*rt
= tcgv_vec_temp(r
);
543 TCGTemp
*at
= tcgv_vec_temp(a
);
544 TCGTemp
*bt
= tcgv_vec_temp(b
);
545 TCGArg ri
= temp_arg(rt
);
546 TCGArg ai
= temp_arg(at
);
547 TCGArg bi
= temp_arg(bt
);
548 TCGType type
= rt
->base_type
;
551 tcg_debug_assert(at
->base_type
>= type
);
552 tcg_debug_assert(bt
->base_type
>= type
);
553 tcg_assert_listed_vecop(INDEX_op_cmp_vec
);
554 can
= tcg_can_emit_vec_op(INDEX_op_cmp_vec
, type
, vece
);
556 vec_gen_4(INDEX_op_cmp_vec
, type
, vece
, ri
, ai
, bi
, cond
);
558 const TCGOpcode
*hold_list
= tcg_swap_vecop_list(NULL
);
559 tcg_debug_assert(can
< 0);
560 tcg_expand_vec_op(INDEX_op_cmp_vec
, type
, vece
, ri
, ai
, bi
, cond
);
561 tcg_swap_vecop_list(hold_list
);
565 static void do_op3(unsigned vece
, TCGv_vec r
, TCGv_vec a
,
566 TCGv_vec b
, TCGOpcode opc
)
568 TCGTemp
*rt
= tcgv_vec_temp(r
);
569 TCGTemp
*at
= tcgv_vec_temp(a
);
570 TCGTemp
*bt
= tcgv_vec_temp(b
);
571 TCGArg ri
= temp_arg(rt
);
572 TCGArg ai
= temp_arg(at
);
573 TCGArg bi
= temp_arg(bt
);
574 TCGType type
= rt
->base_type
;
577 tcg_debug_assert(at
->base_type
>= type
);
578 tcg_debug_assert(bt
->base_type
>= type
);
579 tcg_assert_listed_vecop(opc
);
580 can
= tcg_can_emit_vec_op(opc
, type
, vece
);
582 vec_gen_3(opc
, type
, vece
, ri
, ai
, bi
);
584 const TCGOpcode
*hold_list
= tcg_swap_vecop_list(NULL
);
585 tcg_debug_assert(can
< 0);
586 tcg_expand_vec_op(opc
, type
, vece
, ri
, ai
, bi
);
587 tcg_swap_vecop_list(hold_list
);
591 void tcg_gen_add_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
593 do_op3(vece
, r
, a
, b
, INDEX_op_add_vec
);
596 void tcg_gen_sub_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
598 do_op3(vece
, r
, a
, b
, INDEX_op_sub_vec
);
601 void tcg_gen_mul_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
603 do_op3(vece
, r
, a
, b
, INDEX_op_mul_vec
);
606 void tcg_gen_ssadd_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
608 do_op3(vece
, r
, a
, b
, INDEX_op_ssadd_vec
);
611 void tcg_gen_usadd_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
613 do_op3(vece
, r
, a
, b
, INDEX_op_usadd_vec
);
616 void tcg_gen_sssub_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
618 do_op3(vece
, r
, a
, b
, INDEX_op_sssub_vec
);
621 void tcg_gen_ussub_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
623 do_op3(vece
, r
, a
, b
, INDEX_op_ussub_vec
);
626 void tcg_gen_smin_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
628 do_op3(vece
, r
, a
, b
, INDEX_op_smin_vec
);
631 void tcg_gen_umin_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
633 do_op3(vece
, r
, a
, b
, INDEX_op_umin_vec
);
636 void tcg_gen_smax_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
638 do_op3(vece
, r
, a
, b
, INDEX_op_smax_vec
);
641 void tcg_gen_umax_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
643 do_op3(vece
, r
, a
, b
, INDEX_op_umax_vec
);
646 void tcg_gen_shlv_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
648 do_op3(vece
, r
, a
, b
, INDEX_op_shlv_vec
);
651 void tcg_gen_shrv_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
653 do_op3(vece
, r
, a
, b
, INDEX_op_shrv_vec
);
656 void tcg_gen_sarv_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_vec b
)
658 do_op3(vece
, r
, a
, b
, INDEX_op_sarv_vec
);
661 static void do_shifts(unsigned vece
, TCGv_vec r
, TCGv_vec a
,
662 TCGv_i32 s
, TCGOpcode opc_s
, TCGOpcode opc_v
)
664 TCGTemp
*rt
= tcgv_vec_temp(r
);
665 TCGTemp
*at
= tcgv_vec_temp(a
);
666 TCGTemp
*st
= tcgv_i32_temp(s
);
667 TCGArg ri
= temp_arg(rt
);
668 TCGArg ai
= temp_arg(at
);
669 TCGArg si
= temp_arg(st
);
670 TCGType type
= rt
->base_type
;
671 const TCGOpcode
*hold_list
;
674 tcg_debug_assert(at
->base_type
>= type
);
675 tcg_assert_listed_vecop(opc_s
);
676 hold_list
= tcg_swap_vecop_list(NULL
);
678 can
= tcg_can_emit_vec_op(opc_s
, type
, vece
);
680 vec_gen_3(opc_s
, type
, vece
, ri
, ai
, si
);
681 } else if (can
< 0) {
682 tcg_expand_vec_op(opc_s
, type
, vece
, ri
, ai
, si
);
684 TCGv_vec vec_s
= tcg_temp_new_vec(type
);
687 TCGv_i64 s64
= tcg_temp_new_i64();
688 tcg_gen_extu_i32_i64(s64
, s
);
689 tcg_gen_dup_i64_vec(MO_64
, vec_s
, s64
);
690 tcg_temp_free_i64(s64
);
692 tcg_gen_dup_i32_vec(vece
, vec_s
, s
);
694 do_op3(vece
, r
, a
, vec_s
, opc_v
);
695 tcg_temp_free_vec(vec_s
);
697 tcg_swap_vecop_list(hold_list
);
700 void tcg_gen_shls_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_i32 b
)
702 do_shifts(vece
, r
, a
, b
, INDEX_op_shls_vec
, INDEX_op_shlv_vec
);
705 void tcg_gen_shrs_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_i32 b
)
707 do_shifts(vece
, r
, a
, b
, INDEX_op_shrs_vec
, INDEX_op_shrv_vec
);
710 void tcg_gen_sars_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
, TCGv_i32 b
)
712 do_shifts(vece
, r
, a
, b
, INDEX_op_sars_vec
, INDEX_op_sarv_vec
);
715 void tcg_gen_bitsel_vec(unsigned vece
, TCGv_vec r
, TCGv_vec a
,
716 TCGv_vec b
, TCGv_vec c
)
718 TCGTemp
*rt
= tcgv_vec_temp(r
);
719 TCGTemp
*at
= tcgv_vec_temp(a
);
720 TCGTemp
*bt
= tcgv_vec_temp(b
);
721 TCGTemp
*ct
= tcgv_vec_temp(c
);
722 TCGType type
= rt
->base_type
;
724 tcg_debug_assert(at
->base_type
>= type
);
725 tcg_debug_assert(bt
->base_type
>= type
);
726 tcg_debug_assert(ct
->base_type
>= type
);
728 if (TCG_TARGET_HAS_bitsel_vec
) {
729 vec_gen_4(INDEX_op_bitsel_vec
, type
, MO_8
,
730 temp_arg(rt
), temp_arg(at
), temp_arg(bt
), temp_arg(ct
));
732 TCGv_vec t
= tcg_temp_new_vec(type
);
733 tcg_gen_and_vec(MO_8
, t
, a
, b
);
734 tcg_gen_andc_vec(MO_8
, r
, c
, a
);
735 tcg_gen_or_vec(MO_8
, r
, r
, t
);
736 tcg_temp_free_vec(t
);
740 void tcg_gen_cmpsel_vec(TCGCond cond
, unsigned vece
, TCGv_vec r
,
741 TCGv_vec a
, TCGv_vec b
, TCGv_vec c
, TCGv_vec d
)
743 TCGTemp
*rt
= tcgv_vec_temp(r
);
744 TCGTemp
*at
= tcgv_vec_temp(a
);
745 TCGTemp
*bt
= tcgv_vec_temp(b
);
746 TCGTemp
*ct
= tcgv_vec_temp(c
);
747 TCGTemp
*dt
= tcgv_vec_temp(d
);
748 TCGArg ri
= temp_arg(rt
);
749 TCGArg ai
= temp_arg(at
);
750 TCGArg bi
= temp_arg(bt
);
751 TCGArg ci
= temp_arg(ct
);
752 TCGArg di
= temp_arg(dt
);
753 TCGType type
= rt
->base_type
;
754 const TCGOpcode
*hold_list
;
757 tcg_debug_assert(at
->base_type
>= type
);
758 tcg_debug_assert(bt
->base_type
>= type
);
759 tcg_debug_assert(ct
->base_type
>= type
);
760 tcg_debug_assert(dt
->base_type
>= type
);
762 tcg_assert_listed_vecop(INDEX_op_cmpsel_vec
);
763 hold_list
= tcg_swap_vecop_list(NULL
);
764 can
= tcg_can_emit_vec_op(INDEX_op_cmpsel_vec
, type
, vece
);
767 vec_gen_6(INDEX_op_cmpsel_vec
, type
, vece
, ri
, ai
, bi
, ci
, di
, cond
);
768 } else if (can
< 0) {
769 tcg_expand_vec_op(INDEX_op_cmpsel_vec
, type
, vece
,
770 ri
, ai
, bi
, ci
, di
, cond
);
772 TCGv_vec t
= tcg_temp_new_vec(type
);
773 tcg_gen_cmp_vec(cond
, vece
, t
, a
, b
);
774 tcg_gen_bitsel_vec(vece
, r
, t
, c
, d
);
775 tcg_temp_free_vec(t
);
777 tcg_swap_vecop_list(hold_list
);