On Sun, Sep 27, 2026 at 5:04 AM Richard Henderson
<[email protected]> 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                 | 41 +++++++++++++++---------------------
>  3 files changed, 18 insertions(+), 26 deletions(-)
>
> diff --git a/include/tcg/tcg-op-common.h b/include/tcg/tcg-op-common.h
> index acdd31dbeaf..7f977661b3d 100644
> --- a/include/tcg/tcg-op-common.h
> +++ b/include/tcg/tcg-op-common.h
> @@ -132,7 +132,6 @@ void tcg_gen_plugin_mem_cb(TCGv_i64 addr, unsigned 
> meminfo);
>  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_ctpop_i32(TCGv_i32 a1, TCGv_i32 a2);
>  void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
>  void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
>  void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2);
> @@ -191,7 +190,6 @@ void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, 
> tcg_target_long offset);
>  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_ctpop_i64(TCGv_i64 a1, TCGv_i64 a2);
>  void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2);
>  void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
>  void tcg_gen_rotr_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 cf832a6dc07..66977cada1f 100644
> --- a/include/tcg/tcg-op-def.h.inc
> +++ b/include/tcg/tcg-op-def.h.inc
> @@ -10,6 +10,7 @@ DEF4(brcond, TCGCond, TCGV, TCGV, TCGLabelPtr)
>  DEF4(brcondi, TCGCond, TCGV, TINT, TCGLabelPtr)
>  DEF3(clz, TCGV, TCGV, TCGV)
>  DEF3(clzi, TCGV, TCGV, TINT)
> +DEF2(ctpop, 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 f168386f46b..86dae114859 100644
> --- a/tcg/tcg-op.c
> +++ b/tcg/tcg-op.c
> @@ -450,6 +450,23 @@ void tcg_gen_clzi(TCGType type, TCGTemp *dst, TCGTemp 
> *src1, int64_t src2)
>      tcg_gen_clz(type, dst, src1, tcg_constant_internal(type, src2));
>  }
>
> +void tcg_gen_ctpop(TCGType type, TCGTemp *dst, TCGTemp *src)
> +{
> +    if (tcg_op_supported(INDEX_op_ctpop, type, 0)) {
> +        tcg_gen_op_tt(INDEX_op_ctpop, type, dst, src);
> +    } else if (type == TCG_TYPE_I64) {
> +        gen_helper_ctpop_i64(temp_tcgv_i64(dst), temp_tcgv_i64(src));
> +    } else if (tcg_op_supported(INDEX_op_ctpop, TCG_TYPE_I64, 0)) {
> +        g_autoptr(TCGTemp) tmp = tcg_temp_new_ebb(TCG_TYPE_I64);
> +
> +        tcg_gen_extu(tmp, src);
> +        tcg_gen_op_tt(INDEX_op_ctpop, TCG_TYPE_I64, tmp, src);

ctpop should read tmp instead of src, right? Otherwise the extu
immediately above is dead.

> +        tcg_gen_extrl(dst, tmp);
> +    } else {
> +        gen_helper_ctpop_i32(temp_tcgv_i32(dst), temp_tcgv_i32(src));
> +    }
> +}

Reply via email to