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 | 117 ++++++++++++++--------------------
3 files changed, 49 insertions(+), 71 deletions(-)
diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
index 802d7c8352a..2a860d7a6c2 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_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg);
void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
@@ -200,7 +199,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2,
tcg_target_long offset);
/* 64 bit ops */
-void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg);
void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
diff --git a/include/tcg/tcg-op-def2.h.inc b/include/tcg/tcg-op-def2.h.inc
index 4497f2b6927..d0b1141dc10 100644
--- a/include/tcg/tcg-op-def2.h.inc
+++ b/include/tcg/tcg-op-def2.h.inc
@@ -28,6 +28,7 @@ DEF_RRR(add)
DEF_RRR(and)
DEF_RRR(andc)
DEF_RRR(clz)
+DEF_RRR(ctz)
DEF_RRR(div)
DEF_RRR(divu)
DEF_RRR(eqv)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 2be51a5762a..a33def70cad 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -499,6 +499,54 @@ static void gen_ctpop(TCGType type, TCGTemp *dst, TCGTemp
*src)
}
}
+static void gen_ctz(TCGType type, TCGTemp *dst, TCGTemp *src1, TCGTemp *src2)
+{
+ TCGTemp *t1, *t2;
+
+ if (tcg_op_supported(INDEX_op_ctz, type, 0)) {
+ gen_op_ttt(INDEX_op_ctz, type, dst, src1, src2);
+ return;
+ }
+ if (tcg_op_supported(INDEX_op_ctpop, type, 0)) {
+ t1 = tcg_temp_new_internal(type, TEMP_EBB);
+ gen_addi(type, t1, src1, -1);
+ gen_andc(type, t1, t1, src1);
+ gen_ctpop(type, t1, t1);
+ } else if (tcg_op_supported(INDEX_op_clz, type, 0)) {
+ int width = tcg_type_size(type) * 8;
+
+ t1 = tcg_temp_new_internal(type, TEMP_EBB);
+ gen_neg(type, t1, src1);
+ gen_and(type, t1, t1, src1);
+ gen_clzi(type, t1, t1, width);
+ gen_xori(type, t1, t1, width - 1);
+ } else if (type == TCG_TYPE_I64) {
+ gen_helper_ctz_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src1),
+ temp_tcgv_i64(src2));
+ return;
+ } else if (tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I64, 0) ||
+ tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0) ||
+ tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
+ t1 = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB);
+ t2 = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB);
+ gen_extu_i32_i64(t1, src1);
+ gen_extu_i32_i64(t2, src2);
+ gen_ctz(TCG_TYPE_I64, t1, t1, t2);
+ gen_extrl_i64_i32(dst, t1);
+ tcg_temp_free_internal(t1);
+ tcg_temp_free_internal(t2);
+ return;
+ } else {
+ gen_helper_ctz_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src1),
+ temp_tcgv_i32(src2));
+ return;
+ }
+
+ t2 = tcg_constant_internal(type, 0);
+ gen_movcond(type, TCG_COND_EQ, dst, src1, t2, src2, t1);
+ tcg_temp_free_internal(t1);
+}
+
static void gen_discard(TCGType type, TCGTemp *src)
{
tcg_gen_op1(INDEX_op_discard, type, temp_arg(src));
@@ -896,46 +944,6 @@ static void gen_xori(TCGType type, TCGTemp *dst, TCGTemp
*src1, int64_t src2)
/* 32 bit ops */
-void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
-{
- TCGv_i32 z, t;
-
- if (tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I32, 0)) {
- tcg_gen_op3_i32(INDEX_op_ctz, ret, arg1, arg2);
- return;
- }
- if (tcg_op_supported(INDEX_op_ctz, 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_ctz_i64(t1, t1, t2);
- tcg_gen_extrl_i64_i32(ret, t1);
- tcg_temp_free_i64(t1);
- tcg_temp_free_i64(t2);
- return;
- }
- if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_REG, 0)) {
- t = tcg_temp_ebb_new_i32();
- tcg_gen_subi_i32(t, arg1, 1);
- tcg_gen_andc_i32(t, t, arg1);
- tcg_gen_ctpop_i32(t, t);
- } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
- t = tcg_temp_ebb_new_i32();
- tcg_gen_neg_i32(t, arg1);
- tcg_gen_and_i32(t, t, arg1);
- tcg_gen_clzi_i32(t, t, 32);
- tcg_gen_xori_i32(t, t, 31);
- } else {
- gen_helper_ctz_i32(ret, arg1, arg2);
- return;
- }
-
- z = tcg_constant_i32(0);
- tcg_gen_movcond_i32(TCG_COND_EQ, ret, arg1, z, arg2, t);
- tcg_temp_free_i32(t);
-}
-
void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
{
if (arg2 == 32
@@ -1797,35 +1805,6 @@ void tcg_gen_revbit64_i64(TCGv_i64 ret, TCGv_i64 arg)
}
}
-void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
-{
- TCGv_i64 z, t;
-
- if (tcg_op_supported(INDEX_op_ctz, TCG_TYPE_I64, 0)) {
- tcg_gen_op3_i64(INDEX_op_ctz, ret, arg1, arg2);
- return;
- }
- if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
- t = tcg_temp_ebb_new_i64();
- tcg_gen_subi_i64(t, arg1, 1);
- tcg_gen_andc_i64(t, t, arg1);
- tcg_gen_ctpop_i64(t, t);
- } else if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_I64, 0)) {
- t = tcg_temp_ebb_new_i64();
- tcg_gen_neg_i64(t, arg1);
- tcg_gen_and_i64(t, t, arg1);
- tcg_gen_clzi_i64(t, t, 64);
- tcg_gen_xori_i64(t, t, 63);
- } else {
- gen_helper_ctz_i64(ret, arg1, arg2);
- return;
- }
-
- z = tcg_constant_i64(0);
- tcg_gen_movcond_i64(TCG_COND_EQ, ret, arg1, z, arg2, t);
- tcg_temp_free_i64(t);
-}
-
void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
{
if (arg2 == 64
--
2.53.0