Signed-off-by: Richard Henderson <[email protected]>
---
include/tcg/tcg-op-common.h | 2 --
include/tcg/tcg-op-def2.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 04fe772c1e0..62b8a579691 100644
--- a/include/tcg/tcg-op-common.h
+++ b/include/tcg/tcg-op-common.h
@@ -142,7 +142,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);
@@ -203,7 +202,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-def2.h.inc b/include/tcg/tcg-op-def2.h.inc
index cbaaba72ffa..8538f7350aa 100644
--- a/include/tcg/tcg-op-def2.h.inc
+++ b/include/tcg/tcg-op-def2.h.inc
@@ -25,6 +25,7 @@ DEF_RRI(xori)
DEF_RRR(add)
DEF_RRR(and)
DEF_RRR(andc)
+DEF_RRR(clz)
DEF_RRR(div)
DEF_RRR(divu)
DEF_RRR(eqv)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 14bec6053db..217dc3409b8 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -451,6 +451,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));
@@ -848,26 +873,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));
@@ -1789,15 +1794,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