Signed-off-by: Richard Henderson <[email protected]>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def.h.inc | 1 +
tcg/tcg-op.c | 54 +++++++++++++++++-------------------
3 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index b674d4c3c65..755e89d7715 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -129,7 +129,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned meminfo);
/* 32 bit ops */
-void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2);
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2);
@@ -190,7 +189,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2,
tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2);
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2);
diff --git a/include/tcg/tcg-op-def.h.inc b/include/tcg/tcg-op-def.h.inc
index 26583254111..202df7a62a8 100644
--- a/include/tcg/tcg-op-def.h.inc
+++ b/include/tcg/tcg-op-def.h.inc
@@ -7,6 +7,7 @@ DEF3(andi, TCGV, TCGV, TINT)
DEF3(andc, TCGV, TCGV, TCGV)
DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
+DEF3(clz, TCGV, TCGV, TCGV)
DEF1(discard, TCGV)
DEF3(div, TCGV, TCGV, TCGV)
DEF3(divu, TCGV, TCGV, TCGV)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index fae6cd7450d..fabec509aa9 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -496,6 +496,31 @@ static void gen_brcondi(TCGType type, TCGCond cond,
TCGTemp *src1,
gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
}
+static void gen_clz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ if (tcg_op_supported(INDEX_op_clz, type, 0)) {
+ gen_op_ttt(INDEX_op_clz, type, dst, src1, src2);
+ } else if (type == TCG_TYPE_I64) {
+ gen_helper_clz_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src1),
+ temp_tcgv_i64(src2));
+ } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
+ TCGTemp *t1 = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB);
+ TCGTemp *t2 = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB);
+
+ gen_extu_i32_i64(t1, src1);
+ gen_extu_i32_i64(t2, src2);
+ gen_addi(TCG_TYPE_I64, t2, t2, 32);
+ gen_op_ttt(INDEX_op_clz, TCG_TYPE_I64, t1, t1, t2);
+ gen_extrl_i64_i32(dst, t1);
+ tcg_temp_free_internal(t1);
+ tcg_temp_free_internal(t2);
+ gen_subi(TCG_TYPE_I32, dst, dst, 32);
+ } else {
+ gen_helper_clz_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src1),
+ temp_tcgv_i32(src2));
+ }
+}
+
static void gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -828,26 +853,6 @@ static void gen_xori(TCGType type, TCGTemp *dst, TCGTemp
*src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_clz, ret, arg1, arg2);
- } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
- TCGv_i64 t1 = tcg_temp_ebb_new_i64();
- TCGv_i64 t2 = tcg_temp_ebb_new_i64();
- tcg_gen_extu_i32_i64(t1, arg1);
- tcg_gen_extu_i32_i64(t2, arg2);
- tcg_gen_addi_i64(t2, t2, 32);
- tcg_gen_clz_i64(t1, t1, t2);
- tcg_gen_extrl_i64_i32(ret, t1);
- tcg_temp_free_i64(t1);
- tcg_temp_free_i64(t2);
- tcg_gen_subi_i32(ret, ret, 32);
- } else {
- gen_helper_clz_i32(ret, arg1, arg2);
- }
-}
-
void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
{
tcg_gen_clz_i32(ret, arg1, tcg_constant_i32(arg2));
@@ -1769,15 +1774,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_clz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_clz, ret, arg1, arg2);
- } else {
- gen_helper_clz_i64(ret, arg1, arg2);
- }
-}
-
void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
{
tcg_gen_clz_i64(ret, arg1, tcg_constant_i64(arg2));
--
2.53.0