On 27/9/26 10:59, Richard Henderson wrote:
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 | 45 ++++++++++++++----------------------
3 files changed, 18 insertions(+), 30 deletions(-)
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 3498be09e70..5ee49e2553d 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -422,6 +422,23 @@ void tcg_gen_brcondi(TCGType type, TCGCond cond, TCGTemp
*src1,
tcg_gen_brcond(type, cond, src1, tcg_constant_internal(type, src2), l);
}
+void tcg_gen_clrsb(TCGType type, TCGTemp *dst, TCGTemp *src)
+{
+ if (tcg_op_supported(INDEX_op_clz, TCG_TYPE_REG, 0)) {
+ g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(type);
+ int width = tcg_type_size(type) * 8;
tcg_type_bits()
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
+ tcg_gen_sari(type, tmp, src, width - 1);
+ tcg_gen_xor(type, tmp, tmp, src);
+ tcg_gen_clzi(type, tmp, tmp, width);
+ tcg_gen_addi(type, dst, tmp, -1);
+ } else if (type == TCG_TYPE_I32) {
+ gen_helper_clrsb_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src));
+ } else {
+ gen_helper_clrsb_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src));
+ }
+}