[PATCH 12/13] trans_rvv.c.inc: use cpu_vl in trans_vrgather_vi()

Daniel Henrique Barboza posted 13 patches 10 months ago
There is a newer version of this series
[PATCH 12/13] trans_rvv.c.inc: use cpu_vl in trans_vrgather_vi()
Posted by Daniel Henrique Barboza 10 months ago
There's no need to calculate 'vlmax'. We're garanteeing that 'vl_eq_vlmax'
is true, and we can retrieve 'vl' via 'cpu_vl'.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
 target/riscv/insn_trans/trans_rvv.c.inc | 29 ++++++++++++++++---------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
index 3782d0fa2f..43d20ae354 100644
--- a/target/riscv/insn_trans/trans_rvv.c.inc
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
@@ -3575,16 +3575,25 @@ static bool trans_vrgather_vi(DisasContext *s, arg_rmrr *a)
     }
 
     if (a->vm && s->vl_eq_vlmax && !(s->vta && s->lmul < 0)) {
-        int scale = s->lmul - (s->sew + 3);
-        int vlmax = s->cfg_ptr->vlen >> -scale;
-        if (a->rs1 >= vlmax) {
-            tcg_gen_gvec_dup_imm(MO_64, vreg_ofs(s, a->rd),
-                                 MAXSZ(s), MAXSZ(s), 0);
-        } else {
-            tcg_gen_gvec_dup_mem(s->sew, vreg_ofs(s, a->rd),
-                                 endian_ofs(s, a->rs2, a->rs1),
-                                 MAXSZ(s), MAXSZ(s));
-        }
+        TCGLabel *dup_imm = gen_new_label();
+        TCGLabel *done = gen_new_label();
+        TCGv_i32 vlmax = tcg_temp_new_i32();
+
+        /* a->rs1 >= vlmax, cpu_vl = vlmax */
+        tcg_gen_trunc_tl_i32(vlmax, cpu_vl);
+        tcg_gen_brcond_i32(TCG_COND_GEU, tcg_constant_i32(a->rs1), vlmax,
+                           dup_imm);
+        tcg_gen_gvec_dup_mem(s->sew, vreg_ofs(s, a->rd),
+                             endian_ofs(s, a->rs2, a->rs1),
+                             MAXSZ(s), MAXSZ(s));
+        tcg_gen_br(done);
+
+        gen_set_label(dup_imm);
+        tcg_gen_gvec_dup_imm(MO_64, vreg_ofs(s, a->rd),
+                             MAXSZ(s), MAXSZ(s), 0);
+
+        gen_set_label(done);
+
         mark_vs_dirty(s);
     } else {
         static gen_helper_opivx * const fns[4] = {
-- 
2.43.0