All of lore.kernel.org
 help / color / mirror / Atom feed
From: WX Chen <wxchen0913@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, Palmer Dabbelt <palmer@dabbelt.com>,
	Alistair Francis <alistair.francis@wdc.com>,
	Weiwei Li <liwei1518@gmail.com>,
	Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
	Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
	Chao Liu <chao.liu@processmission.com>,
	Tao Tang <tangtao1634@phytium.com.cn>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH v3] target/riscv: use gen_goto_tb for vsetvli
Date: Mon, 23 Nov 2026 14:40:36 +0800	[thread overview]
Message-ID: <21d62cec-01fb-40d1-8de8-83bcb6fc7feb@gmail.com> (raw)
In-Reply-To: <20261111-research-vsetvli-direct-chain-20261104-v3-1-8d3a18474a68@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 6051 bytes --]

|A gentle ping on this patch.

|

|Thanks,
Chen|

On 11/11/26 21:40, WX Chen wrote:
> This patch uses gen_goto_tb() to reduce the overhead of the
> unconditional lookup_and_goto_ptr() exit currently generated
> for vsetvli.
>
> When translating vsetvli, the immediate vtype provides information
> that can be used to optimize the exit generated by do_vsetvl().
>
> For the vsetvli forms optimized by this patch, the immediate vtype and
> existing state update flow determine the other relevant translation state.
> Only VL_EQ_VLMAX can vary with AVL. This patch therefore uses separate
> jump slots depending on whether the returned VL equals VLMAX,
> enabling direct TB linking after vsetvli.
>
> The register-vtype vsetvl instruction retains the existing lookup
> path, as its vtype is not known at translation time.
>
> The package benchmarks measure build time with the RISC-V cc1 compiler running under QEMU,
> while the dedicated workload repeatedly executes two vsetvli instructions,
> alternating between VL = VLMAX and VL < VLMAX.
>
> benchmark result:
> Dedicated workload:
> | Workload | QEMU | Runs | Median (s) | Min–max (s) | Wall change (s) | Wall change | Wall / baseline |
> | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |
> | vsetvli-chain | baseline | 5 | 2.154520 | 2.145543–2.173475 | 0.000000 | 0.00% | 1.000x |
> | vsetvli-chain | candidate | 5 | 0.492811 | 0.489481–0.499191 | -1.661710 | -77.13% | 0.229x |
>
> Perf of dedicated workload:
> | Workload | QEMU | Event | Samples | Symbol | Symbol samples | Overhead |
> | --- | --- | --- | ---: | --- | ---: | ---: |
> | vsetvli-chain | baseline | cycles:u | 2151 | `helper_lookup_tb_ptr` | 2007 | 93.58%|
> | vsetvli-chain | candidate | cycles:u | 482 | `helper_lookup_tb_ptr` | 0 | 0.00% |
>
> Package build benchmark
> | Package | QEMU | Runs | Median wall (s) | Min–max (s) | Stddev (s) | Wall change | Wall / baseline |
> | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |
> | lz4 | candidate | 3 | 79.506 | 79.000–80.063 | 0.532 | -1.25% | 0.987x |
> | zlib | candidate | 3 | 45.474 | 45.426–45.476 | 0.028 | -0.44% | 0.996x |
> | sqlite | candidate | 3 | 278.771 | 278.470–278.962 | 0.248 | -1.07% | 0.989x |
>
> Signed-off-by: WX Chen<wxchen0913@gmail.com>
> ---
> v3:
> - Expand the commit message to explain the optimization rationale,
>    following feedback from Sashiko AI review.
> - Add a benchmark result.
> - No code changes.
> v2:
> The overall structure is quite the same as v1 except that v2 considers the condition that QEMU forces
> `VL_EQ_VLMAX = false` when `maxsz < 8`, which reduces the number of `goto_tb` slots from two to one in
> some cases.
>
> For `vsetvli` with `rd != x0 && rs1 == x0`, v2 also uses a single
> `goto_tb` slot because the successor TB lookup key is fixed for a given
> source TB.
>
> Both changes follow Chao Liu's suggestions.
>
> v2 patch link:https://lore.kernel.org/qemu-devel/20261110-research-vsetvli-direct-chain-20261104-v2-1-8e65aadfb6aa@gmail.com/
> benchmark link:https://github.com/zhenbaii/qemu-riscv-bench
>
> To run the benchmark from the benchmark repository, pass the baseline
> and patched QEMU commit IDs to the vsetvli-v2 recipe:
>
>    ./reproduce.sh BASELINE_COMMIT PATCHED_COMMIT --recipe vsetvli-v2
> ---
>   target/riscv/tcg/insn_trans/trans_rvv.c.inc | 30 ++++++++++++++++++++++++-----
>   1 file changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/target/riscv/tcg/insn_trans/trans_rvv.c.inc b/target/riscv/tcg/insn_trans/trans_rvv.c.inc
> index 7e1295f33e7d4b7a2ff26cbf428f6b5d9eb682ff..17e8eb5ecaede655b58b5bdc9f10ff9284efc5b6 100644
> --- a/target/riscv/tcg/insn_trans/trans_rvv.c.inc
> +++ b/target/riscv/tcg/insn_trans/trans_rvv.c.inc
> @@ -191,7 +191,8 @@ static bool require_noover(const int8_t dst, const int8_t dst_lmul,
>       return !is_overlapped(dst, dst_size, src, src_size);
>   }
>   
> -static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2)
> +static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2,
> +                      uint32_t vtype, bool vtype_is_imm)
>   {
>       TCGv s1, dst;
>   
> @@ -215,8 +216,27 @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2)
>       gen_set_gpr(s, rd, dst);
>       finalize_rvv_inst(s);
>   
> -    gen_update_pc(s, s->cur_insn_len);
> -    lookup_and_goto_ptr(s);
> +    if (!vtype_is_imm || (rd == 0 && rs1 == 0)) {
> +        gen_update_pc(s, s->cur_insn_len);
> +        lookup_and_goto_ptr(s);
> +    } else {
> +        uint32_t vsew = FIELD_EX32(vtype, VTYPE, VSEW);
> +        int8_t lmul = sextract32(FIELD_EX32(vtype, VTYPE, VLMUL), 0, 3);
> +        uint32_t vlmax = vext_get_vlmax(s->cfg_ptr->vlenb, vsew, lmul);
> +
> +        if (rs1 == 0 || (vlmax << vsew) < 8) {
> +            gen_goto_tb(s, 0, s->cur_insn_len);
> +        } else {
> +            target_ulong pc_save = s->pc_save;
> +            TCGLabel *not_vlmax = gen_new_label();
> +
> +            tcg_gen_brcondi_tl(TCG_COND_NE, dst, vlmax, not_vlmax);
> +            gen_goto_tb(s, 0, s->cur_insn_len);
> +            s->pc_save = pc_save;
> +            gen_set_label(not_vlmax);
> +            gen_goto_tb(s, 1, s->cur_insn_len);
> +        }
> +    }
>       s->base.is_jmp = DISAS_NORETURN;
>       return true;
>   }
> @@ -244,13 +264,13 @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2)
>   static bool trans_vsetvl(DisasContext *s, arg_vsetvl *a)
>   {
>       TCGv s2 = get_gpr(s, a->rs2, EXT_ZERO);
> -    return do_vsetvl(s, a->rd, a->rs1, s2);
> +    return do_vsetvl(s, a->rd, a->rs1, s2, 0, false);
>   }
>   
>   static bool trans_vsetvli(DisasContext *s, arg_vsetvli *a)
>   {
>       TCGv s2 = tcg_constant_tl(a->zimm);
> -    return do_vsetvl(s, a->rd, a->rs1, s2);
> +    return do_vsetvl(s, a->rd, a->rs1, s2, a->zimm, true);
>   }
>   
>   static bool trans_vsetivli(DisasContext *s, arg_vsetivli *a)
>
> ---
> base-commit: a3565937b39779d4e3704298095f566e7559ad53
> change-id: 20261104-research-vsetvli-direct-chain-20261104-206bc2104ddb
>
> Best regards,

[-- Attachment #2: Type: text/html, Size: 6638 bytes --]

  parent reply	other threads:[~2026-11-23  6:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 13:40 [PATCH v3] target/riscv: use gen_goto_tb for vsetvli WX Chen
2026-11-13 18:18 ` Richard Henderson
2026-11-14  7:58   ` WX Chen
2026-11-14 15:16     ` Richard Henderson
2026-11-23  6:40 ` WX Chen [this message]
2026-11-24 20:32 ` Daniel Henrique Barboza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21d62cec-01fb-40d1-8de8-83bcb6fc7feb@gmail.com \
    --to=wxchen0913@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=chao.liu@processmission.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=tangtao1634@phytium.com.cn \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.