tcg: Merge INDEX_op_divu2_{i32,i64}

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2025-01-07 18:23:17 -08:00
parent 9bf558ed17
commit 8109598b68
4 changed files with 21 additions and 14 deletions

View file

@ -307,6 +307,16 @@ Arithmetic
pass *nh* as a simple sign-extension of *nl*, so the only pass *nh* as a simple sign-extension of *nl*, so the only
overflow should be *INT_MIN* / -1. overflow should be *INT_MIN* / -1.
* - divu2 *q*, *r*, *nl*, *nh*, *d*
- | *q* = *nh:nl* / *d* (unsigned)
| *r* = *nh:nl* % *d*
| Undefined behaviour if division by zero, or the double-word
numerator divided by the single-word divisor does not fit
within the single-word quotient. The code generator will
pass 0 to *nh* to make a simple zero-extension of *nl*,
so overflow should never occur.
Logical Logical
------- -------

View file

@ -45,6 +45,7 @@ DEF(andc, 1, 2, 0, TCG_OPF_INT)
DEF(divs, 1, 2, 0, TCG_OPF_INT) DEF(divs, 1, 2, 0, TCG_OPF_INT)
DEF(divs2, 2, 3, 0, TCG_OPF_INT) DEF(divs2, 2, 3, 0, TCG_OPF_INT)
DEF(divu, 1, 2, 0, TCG_OPF_INT) DEF(divu, 1, 2, 0, TCG_OPF_INT)
DEF(divu2, 2, 3, 0, TCG_OPF_INT)
DEF(eqv, 1, 2, 0, TCG_OPF_INT) DEF(eqv, 1, 2, 0, TCG_OPF_INT)
DEF(mul, 1, 2, 0, TCG_OPF_INT) DEF(mul, 1, 2, 0, TCG_OPF_INT)
DEF(mulsh, 1, 2, 0, TCG_OPF_INT) DEF(mulsh, 1, 2, 0, TCG_OPF_INT)
@ -73,7 +74,6 @@ DEF(st_i32, 0, 2, 1, 0)
/* arith */ /* arith */
DEF(rem_i32, 1, 2, 0, 0) DEF(rem_i32, 1, 2, 0, 0)
DEF(remu_i32, 1, 2, 0, 0) DEF(remu_i32, 1, 2, 0, 0)
DEF(divu2_i32, 2, 3, 0, 0)
/* shifts/rotates */ /* shifts/rotates */
DEF(shl_i32, 1, 2, 0, 0) DEF(shl_i32, 1, 2, 0, 0)
DEF(shr_i32, 1, 2, 0, 0) DEF(shr_i32, 1, 2, 0, 0)
@ -118,7 +118,6 @@ DEF(st_i64, 0, 2, 1, 0)
/* arith */ /* arith */
DEF(rem_i64, 1, 2, 0, 0) DEF(rem_i64, 1, 2, 0, 0)
DEF(remu_i64, 1, 2, 0, 0) DEF(remu_i64, 1, 2, 0, 0)
DEF(divu2_i64, 2, 3, 0, 0)
/* shifts/rotates */ /* shifts/rotates */
DEF(shl_i64, 1, 2, 0, 0) DEF(shl_i64, 1, 2, 0, 0)
DEF(shr_i64, 1, 2, 0, 0) DEF(shr_i64, 1, 2, 0, 0)

View file

@ -637,10 +637,10 @@ void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
{ {
if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I32, 0)) { if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I32, 0)) {
tcg_gen_op3_i32(INDEX_op_divu, ret, arg1, arg2); tcg_gen_op3_i32(INDEX_op_divu, ret, arg1, arg2);
} else if (tcg_op_supported(INDEX_op_divu2_i32, TCG_TYPE_I32, 0)) { } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I32, 0)) {
TCGv_i32 t0 = tcg_temp_ebb_new_i32(); TCGv_i32 t0 = tcg_temp_ebb_new_i32();
TCGv_i32 zero = tcg_constant_i32(0); TCGv_i32 zero = tcg_constant_i32(0);
tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, zero, arg2); tcg_gen_op5_i32(INDEX_op_divu2, ret, t0, arg1, zero, arg2);
tcg_temp_free_i32(t0); tcg_temp_free_i32(t0);
} else { } else {
gen_helper_divu_i32(ret, arg1, arg2); gen_helper_divu_i32(ret, arg1, arg2);
@ -657,10 +657,10 @@ void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
tcg_gen_mul_i32(t0, t0, arg2); tcg_gen_mul_i32(t0, t0, arg2);
tcg_gen_sub_i32(ret, arg1, t0); tcg_gen_sub_i32(ret, arg1, t0);
tcg_temp_free_i32(t0); tcg_temp_free_i32(t0);
} else if (tcg_op_supported(INDEX_op_divu2_i32, TCG_TYPE_I32, 0)) { } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I32, 0)) {
TCGv_i32 t0 = tcg_temp_ebb_new_i32(); TCGv_i32 t0 = tcg_temp_ebb_new_i32();
TCGv_i32 zero = tcg_constant_i32(0); TCGv_i32 zero = tcg_constant_i32(0);
tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, zero, arg2); tcg_gen_op5_i32(INDEX_op_divu2, t0, ret, arg1, zero, arg2);
tcg_temp_free_i32(t0); tcg_temp_free_i32(t0);
} else { } else {
gen_helper_remu_i32(ret, arg1, arg2); gen_helper_remu_i32(ret, arg1, arg2);
@ -2005,10 +2005,10 @@ void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
{ {
if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I64, 0)) { if (tcg_op_supported(INDEX_op_divu, TCG_TYPE_I64, 0)) {
tcg_gen_op3_i64(INDEX_op_divu, ret, arg1, arg2); tcg_gen_op3_i64(INDEX_op_divu, ret, arg1, arg2);
} else if (tcg_op_supported(INDEX_op_divu2_i64, TCG_TYPE_I64, 0)) { } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I64, 0)) {
TCGv_i64 t0 = tcg_temp_ebb_new_i64(); TCGv_i64 t0 = tcg_temp_ebb_new_i64();
TCGv_i64 zero = tcg_constant_i64(0); TCGv_i64 zero = tcg_constant_i64(0);
tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, zero, arg2); tcg_gen_op5_i64(INDEX_op_divu2, ret, t0, arg1, zero, arg2);
tcg_temp_free_i64(t0); tcg_temp_free_i64(t0);
} else { } else {
gen_helper_divu_i64(ret, arg1, arg2); gen_helper_divu_i64(ret, arg1, arg2);
@ -2025,10 +2025,10 @@ void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
tcg_gen_mul_i64(t0, t0, arg2); tcg_gen_mul_i64(t0, t0, arg2);
tcg_gen_sub_i64(ret, arg1, t0); tcg_gen_sub_i64(ret, arg1, t0);
tcg_temp_free_i64(t0); tcg_temp_free_i64(t0);
} else if (tcg_op_supported(INDEX_op_divu2_i64, TCG_TYPE_I64, 0)) { } else if (tcg_op_supported(INDEX_op_divu2, TCG_TYPE_I64, 0)) {
TCGv_i64 t0 = tcg_temp_ebb_new_i64(); TCGv_i64 t0 = tcg_temp_ebb_new_i64();
TCGv_i64 zero = tcg_constant_i64(0); TCGv_i64 zero = tcg_constant_i64(0);
tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, zero, arg2); tcg_gen_op5_i64(INDEX_op_divu2, t0, ret, arg1, zero, arg2);
tcg_temp_free_i64(t0); tcg_temp_free_i64(t0);
} else { } else {
gen_helper_remu_i64(ret, arg1, arg2); gen_helper_remu_i64(ret, arg1, arg2);

View file

@ -1029,8 +1029,7 @@ static const TCGOutOp * const all_outop[NB_OPS] = {
OUTOP(INDEX_op_divs, TCGOutOpBinary, outop_divs), OUTOP(INDEX_op_divs, TCGOutOpBinary, outop_divs),
OUTOP(INDEX_op_divu, TCGOutOpBinary, outop_divu), OUTOP(INDEX_op_divu, TCGOutOpBinary, outop_divu),
OUTOP(INDEX_op_divs2, TCGOutOpDivRem, outop_divs2), OUTOP(INDEX_op_divs2, TCGOutOpDivRem, outop_divs2),
OUTOP(INDEX_op_divu2_i32, TCGOutOpDivRem, outop_divu2), OUTOP(INDEX_op_divu2, TCGOutOpDivRem, outop_divu2),
OUTOP(INDEX_op_divu2_i64, TCGOutOpDivRem, outop_divu2),
OUTOP(INDEX_op_eqv, TCGOutOpBinary, outop_eqv), OUTOP(INDEX_op_eqv, TCGOutOpBinary, outop_eqv),
OUTOP(INDEX_op_mul, TCGOutOpBinary, outop_mul), OUTOP(INDEX_op_mul, TCGOutOpBinary, outop_mul),
OUTOP(INDEX_op_mulsh, TCGOutOpBinary, outop_mulsh), OUTOP(INDEX_op_mulsh, TCGOutOpBinary, outop_mulsh),
@ -5471,8 +5470,7 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
break; break;
case INDEX_op_divs2: case INDEX_op_divs2:
case INDEX_op_divu2_i32: case INDEX_op_divu2:
case INDEX_op_divu2_i64:
{ {
const TCGOutOpDivRem *out = const TCGOutOpDivRem *out =
container_of(all_outop[op->opc], TCGOutOpDivRem, base); container_of(all_outop[op->opc], TCGOutOpDivRem, base);