All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] target/riscv: use gen_goto_tb for vsetvli
@ 2026-11-11 13:40 WX Chen
  2026-11-13 18:18 ` Richard Henderson
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: WX Chen @ 2026-11-11 13:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Daniel Henrique Barboza, Liu Zhiwei, Chao Liu, Tao Tang, WX Chen

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,
-- 
WX Chen <wxchen0913@gmail.com>



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] target/riscv: use gen_goto_tb for vsetvli
  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-23  6:40 ` WX Chen
  2026-11-24 20:32 ` Daniel Henrique Barboza
  2 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2026-11-13 18:18 UTC (permalink / raw)
  To: qemu-devel

On 11/11/26 06:40, WX Chen wrote:
> +            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);

Did you mean TCG_COND_GEU?  Surely dst very large results in vlmax.


r~


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] target/riscv: use gen_goto_tb for vsetvli
  2026-11-13 18:18 ` Richard Henderson
@ 2026-11-14  7:58   ` WX Chen
  2026-11-14 15:16     ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: WX Chen @ 2026-11-14  7:58 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel, qemu-riscv, wxchen0913

> Did you mean TCG_COND_GEU? Surely dst very large results in vlmax.

Hi Richard,

Thanks for the review!

I think TCG_COND_NE is correct here. The `dst` value actually comes
from the previous `gen_helper_vsetvl(dst, tcg_env, ...);` call.

According to the definition of the `vsetvli` instruction, it will
set vl CSR and copy its value to a dst reg. The value of `vl` is determined
by the relationship between AVL and VLMAX:

AVL <= VLMAX:
    VL = AVL

AVL < (2 * VLMAX):
    ceil(AVL / 2) ≤ VL ≤ VLMAX

Otherwise:
    VL = VLMAX

So, `dst` here is either equal to VLMAX or smaller than it.
That's why TCG_COND_NE is used here.

Thanks,
Chen


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] target/riscv: use gen_goto_tb for vsetvli
  2026-11-14  7:58   ` WX Chen
@ 2026-11-14 15:16     ` Richard Henderson
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2026-11-14 15:16 UTC (permalink / raw)
  To: WX Chen; +Cc: qemu-devel, qemu-riscv

On 11/14/26 00:58, WX Chen wrote:
>> Did you mean TCG_COND_GEU? Surely dst very large results in vlmax.
> 
> Hi Richard,
> 
> Thanks for the review!
> 
> I think TCG_COND_NE is correct here. The `dst` value actually comes
> from the previous `gen_helper_vsetvl(dst, tcg_env, ...);` call.
> 
> According to the definition of the `vsetvli` instruction, it will
> set vl CSR and copy its value to a dst reg. The value of `vl` is determined
> by the relationship between AVL and VLMAX:
> 
> AVL <= VLMAX:
>      VL = AVL
> 
> AVL < (2 * VLMAX):
>      ceil(AVL / 2) ≤ VL ≤ VLMAX
> 
> Otherwise:
>      VL = VLMAX
> 
> So, `dst` here is either equal to VLMAX or smaller than it.
> That's why TCG_COND_NE is used here.
Ok.  I didn't follow the logic outside the patch context.

r~


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] target/riscv: use gen_goto_tb for vsetvli
  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-23  6:40 ` WX Chen
  2026-11-24 20:32 ` Daniel Henrique Barboza
  2 siblings, 0 replies; 6+ messages in thread
From: WX Chen @ 2026-11-23  6:40 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-riscv, Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Daniel Henrique Barboza, Liu Zhiwei, Chao Liu, Tao Tang,
	Richard Henderson

[-- 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 --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] target/riscv: use gen_goto_tb for vsetvli
  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-23  6:40 ` WX Chen
@ 2026-11-24 20:32 ` Daniel Henrique Barboza
  2 siblings, 0 replies; 6+ messages in thread
From: Daniel Henrique Barboza @ 2026-11-24 20:32 UTC (permalink / raw)
  To: WX Chen, qemu-devel
  Cc: qemu-riscv, Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Liu Zhiwei, Chao Liu, Tao Tang



On 11/11/2026 10:40 AM, 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>


Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.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,



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-24 20:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-11-24 20:32 ` Daniel Henrique Barboza

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.