From 26d2bfef145c4fb834c25d0a60b0d80e95ebda73 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Thu, 10 Sep 2026 13:45:05 -1000 Subject: [PATCH] tcg: Generic expansion of tcg_gen_muli_* Reviewed-by: Matt Turner Signed-off-by: Richard Henderson --- include/tcg/tcg-op-common.h | 2 -- include/tcg/tcg-op-def.h.inc | 1 + tcg/tcg-op.c | 33 +++++++++++---------------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h index dd4e7f6686..2b2653d07c 100644 --- a/include/tcg/tcg-op-common.h +++ b/include/tcg/tcg-op-common.h @@ -123,7 +123,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo); /* 32 bit ops */ -void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2); void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2); void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2); void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2); @@ -208,7 +207,6 @@ void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg); /* 64 bit ops */ -void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2); void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2); void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2); void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2); diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc index b38969478a..abea00e7e0 100644 --- a/include/tcg/tcg-op-def.h.inc +++ b/include/tcg/tcg-op-def.h.inc @@ -9,6 +9,7 @@ DEF1(discard, TCGV) DEF2(mov, TCGV, TCGV) DEF2(movi, TCGV, TINT) DEF3(mul, TCGV, TCGV, TCGV) +DEF3(muli, TCGV, TCGV, TINT) DEF2(neg, TCGV, TCGV) DEF3(or, TCGV, TCGV, TCGV) DEF3(ori, TCGV, TCGV, TINT) diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index cc34e0f31f..23aeea8026 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -428,6 +428,17 @@ void tcg_gen_mul(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2) tcg_gen_op_ttt(INDEX_op_mul, type, dst, src1, src2); } +void tcg_gen_muli(TCGType type, TCGTemp *dst, TCGTemp *src1, int64_t src2) +{ + if (src2 == 0) { + tcg_gen_movi(type, dst, 0); + } else if (is_power_of_2(src2)) { + tcg_gen_shli(type, dst, src1, ctz64(src2)); + } else { + tcg_gen_mul(type, dst, src1, tcg_constant_internal(type, src2)); + } +} + void tcg_gen_neg(TCGType type, TCGTemp *dst, TCGTemp *src) { tcg_gen_op_tt(INDEX_op_neg, type, dst, src); @@ -597,17 +608,6 @@ void tcg_gen_negsetcondi_i32(TCGCond cond, TCGv_i32 ret, tcg_gen_negsetcond_i32(cond, ret, arg1, tcg_constant_i32(arg2)); } -void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2) -{ - if (arg2 == 0) { - tcg_gen_movi_i32(ret, 0); - } else if (is_power_of_2(arg2)) { - tcg_gen_shli_i32(ret, arg1, ctz32(arg2)); - } else { - tcg_gen_mul_i32(ret, arg1, tcg_constant_i32(arg2)); - } -} - void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) { if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I32, 0)) { @@ -1536,17 +1536,6 @@ void tcg_gen_negsetcond_i64(TCGCond cond, TCGv_i64 ret, } } -void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2) -{ - if (arg2 == 0) { - tcg_gen_movi_i64(ret, 0); - } else if (is_power_of_2(arg2)) { - tcg_gen_shli_i64(ret, arg1, ctz64(arg2)); - } else { - tcg_gen_mul_i64(ret, arg1, tcg_constant_i64(arg2)); - } -} - void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) { if (tcg_op_supported(INDEX_op_divs, TCG_TYPE_I64, 0)) {