tcg: Expand usadd/ussub with umin/umax

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>
This commit is contained in:
Richard Henderson 2020-09-14 19:25:58 -07:00
parent dc29f4746f
commit 2552d60ebd

View File

@ -119,6 +119,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:
@ -603,7 +615,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, t, 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)
@ -613,7 +636,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,