[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 13/16] tcg: Expand usadd/ussub with umin/umax
From: |
Richard Henderson |
Subject: |
[PATCH v2 13/16] tcg: Expand usadd/ussub with umin/umax |
Date: |
Sun, 7 Feb 2021 18:50:58 -0800 |
For usadd, we only have to consider overflow. Since ~B + B == -1,
the maximum value for A that saturates is ~B.
For ussub, we only have to consider underflow. The minimum value
that saturates to 0 from A - B is B.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
tcg/tcg-op-vec.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/tcg/tcg-op-vec.c b/tcg/tcg-op-vec.c
index d19aa7373e..9747b7bb06 100644
--- a/tcg/tcg-op-vec.c
+++ b/tcg/tcg-op-vec.c
@@ -120,6 +120,18 @@ bool tcg_can_emit_vecop_list(const TCGOpcode *list,
continue;
}
break;
+ case INDEX_op_usadd_vec:
+ if (tcg_can_emit_vec_op(INDEX_op_umin_vec, type, vece) ||
+ tcg_can_emit_vec_op(INDEX_op_cmp_vec, type, vece)) {
+ continue;
+ }
+ break;
+ case INDEX_op_ussub_vec:
+ if (tcg_can_emit_vec_op(INDEX_op_umax_vec, type, vece) ||
+ tcg_can_emit_vec_op(INDEX_op_cmp_vec, type, vece)) {
+ continue;
+ }
+ break;
case INDEX_op_cmpsel_vec:
case INDEX_op_smin_vec:
case INDEX_op_smax_vec:
@@ -604,7 +616,18 @@ void tcg_gen_ssadd_vec(unsigned vece, TCGv_vec r, TCGv_vec
a, TCGv_vec b)
void tcg_gen_usadd_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b)
{
- do_op3_nofail(vece, r, a, b, INDEX_op_usadd_vec);
+ if (!do_op3(vece, r, a, b, INDEX_op_usadd_vec)) {
+ const TCGOpcode *hold_list = tcg_swap_vecop_list(NULL);
+ TCGv_vec t = tcg_temp_new_vec_matching(r);
+
+ /* usadd(a, b) = min(a, ~b) + b */
+ tcg_gen_not_vec(vece, t, b);
+ tcg_gen_umin_vec(vece, t, t, a);
+ tcg_gen_add_vec(vece, r, r, b);
+
+ tcg_temp_free_vec(t);
+ tcg_swap_vecop_list(hold_list);
+ }
}
void tcg_gen_sssub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b)
@@ -614,7 +637,17 @@ void tcg_gen_sssub_vec(unsigned vece, TCGv_vec r, TCGv_vec
a, TCGv_vec b)
void tcg_gen_ussub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b)
{
- do_op3_nofail(vece, r, a, b, INDEX_op_ussub_vec);
+ if (!do_op3(vece, r, a, b, INDEX_op_ussub_vec)) {
+ const TCGOpcode *hold_list = tcg_swap_vecop_list(NULL);
+ TCGv_vec t = tcg_temp_new_vec_matching(r);
+
+ /* ussub(a, b) = max(a, b) - b */
+ tcg_gen_umax_vec(vece, t, a, b);
+ tcg_gen_sub_vec(vece, r, t, b);
+
+ tcg_temp_free_vec(t);
+ tcg_swap_vecop_list(hold_list);
+ }
}
static void do_minmax(unsigned vece, TCGv_vec r, TCGv_vec a,
--
2.25.1
- [PATCH v2 05/16] tcg/s390x: Implement tcg_out_ld/st for vector types, (continued)
- [PATCH v2 05/16] tcg/s390x: Implement tcg_out_ld/st for vector types, Richard Henderson, 2021/02/07
- [PATCH v2 04/16] tcg/s390x: Add host vector framework, Richard Henderson, 2021/02/07
- [PATCH v2 07/16] tcg/s390x: Implement tcg_out_dup*_vec, Richard Henderson, 2021/02/07
- [PATCH v2 09/16] tcg/s390x: Implement andc, orc, abs, neg, not vector operations, Richard Henderson, 2021/02/07
- [PATCH v2 10/16] tcg/s390x: Implement TCG_TARGET_HAS_mul_vec, Richard Henderson, 2021/02/07
- [PATCH v2 01/16] tcg/s390x: Rename from tcg/s390, Richard Henderson, 2021/02/07
- [PATCH v2 08/16] tcg/s390x: Implement minimal vector operations, Richard Henderson, 2021/02/07
- [PATCH v2 06/16] tcg/s390x: Implement tcg_out_mov for vector types, Richard Henderson, 2021/02/07
- [PATCH v2 12/16] tcg/s390x: Implement TCG_TARGET_HAS_minmax_vec, Richard Henderson, 2021/02/07
- [PATCH v2 11/16] tcg/s390x: Implement vector shift operations, Richard Henderson, 2021/02/07
- [PATCH v2 13/16] tcg: Expand usadd/ussub with umin/umax,
Richard Henderson <=
- [PATCH v2 14/16] tcg/s390x: Implement TCG_TARGET_HAS_sat_vec, Richard Henderson, 2021/02/07
- [PATCH v2 15/16] tcg/s390x: Implement TCG_TARGET_HAS_bitsel_vec, Richard Henderson, 2021/02/07
- [PATCH v2 16/16] tcg/s390x: Implement TCG_TARGET_HAS_cmpsel_vec, Richard Henderson, 2021/02/07