Skip to contentSkip to conversation

target/riscv/vector_helper.c: Remove the check for extra tail elements

PATCH Superseded Xiao Wang 2 participants 3 messages Jun 6, 2023 – Jun 7, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xiao Wang

author
#0 lore raw

PATCH 1/1 target/riscv/vector_helper.c: Remove the check for extra tail elements

Commit 752614cab8e6 ("target/riscv: rvv: Add tail agnostic for vector load / store instructions") added an extra check for LMUL fragmentation, intended for setting the "rest tail elements" in the last register for a segment load insn.

Actually, the max_elements derived in vext_ld*() won't be a fraction of vector register size, since the lmul encoded in desc is emul, which has already been adjusted to 1 for LMUL fragmentation case by vext_get_emul() in trans_rvv.c.inc, for ld_stride(), ld_us(), ld_index() and ldff().

Besides, vext_get_emul() has also taken EEW/SEW into consideration, so no need to call vext_get_total_elems() which would base on the emul to derive another emul, the second emul would be incorrect when esz differs from sew.

Thus this patch removes the check for extra tail elements.

Fixes 752614cab8e6 ("target/riscv: rvv: Add tail agnostic for vector load / store instructions")
---
 target/riscv/vector_helper.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
target/riscv/vector_helper.c +6 -15
index f4d0438988..56a79bb5fa 100644
@@ -264,26 +264,17 @@ GEN_VEXT_ST_ELEM(ste_h, int16_t, H2, stw)
 GEN_VEXT_ST_ELEM(ste_w, int32_t, H4, stl)
 GEN_VEXT_ST_ELEM(ste_d, int64_t, H8, stq)
 
-static void vext_set_tail_elems_1s(CPURISCVState *env, target_ulong vl,
-                                   void *vd, uint32_t desc, uint32_t nf,
+static void vext_set_tail_elems_1s(target_ulong vl, void *vd,
+                                   uint32_t desc, uint32_t nf,
                                    uint32_t esz, uint32_t max_elems)
 {
-    uint32_t total_elems = vext_get_total_elems(env, desc, esz);
-    uint32_t vlenb = riscv_cpu_cfg(env)->vlen >> 3;
     uint32_t vta = vext_vta(desc);
-    uint32_t registers_used;
     int k;
 
     for (k = 0; k < nf; ++k) {
         vext_set_elems_1s(vd, vta, (k * max_elems + vl) * esz,
                           (k * max_elems + max_elems) * esz);
     }
-
-    if (nf * max_elems % total_elems != 0) {
-        registers_used = ((nf * max_elems) * esz + (vlenb - 1)) / vlenb;
-        vext_set_elems_1s(vd, vta, (nf * max_elems) * esz,
-                          registers_used * vlenb);
-    }
 }
 
 /*
@@ -319,7 +310,7 @@ vext_ldst_stride(void *vd, void *v0, target_ulong base,
     }
     env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, env->vl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(env->vl, vd, desc, nf, esz, max_elems);
 }
 
 #define GEN_VEXT_LD_STRIDE(NAME, ETYPE, LOAD_FN)                        \
@@ -378,7 +369,7 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,
     }
     env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, evl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(evl, vd, desc, nf, esz, max_elems);
 }
 
 /*
@@ -499,7 +490,7 @@ vext_ldst_index(void *vd, void *v0, target_ulong base,
     }
     env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, env->vl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(env->vl, vd, desc, nf, esz, max_elems);
 }
 
 #define GEN_VEXT_LD_INDEX(NAME, ETYPE, INDEX_FN, LOAD_FN)                  \
@@ -629,7 +620,7 @@ ProbeSuccess:
     }
     env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, env->vl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(env->vl, vd, desc, nf, esz, max_elems);
 }
 
 #define GEN_VEXT_LDFF(NAME, ETYPE, LOAD_FN)               \
Signature · 1 line
2.25.1
#1 lore raw

Hi,

Quoted 44 lines · Xiao Wang

Commit 752614cab8e6 ("target/riscv: rvv: Add tail agnostic for vector load / store instructions") added an extra check for LMUL fragmentation, intended for setting the "rest tail elements" in the last register for a segment load insn.

Actually, the max_elements derived in vext_ld*() won't be a fraction of vector register size, since the lmul encoded in desc is emul, which has already been adjusted to 1 for LMUL fragmentation case by vext_get_emul() in trans_rvv.c.inc, for ld_stride(), ld_us(), ld_index() and ldff().

Besides, vext_get_emul() has also taken EEW/SEW into consideration, so no need to call vext_get_total_elems() which would base on the emul to derive another emul, the second emul would be incorrect when esz differs from sew.

Thus this patch removes the check for extra tail elements.

Fixes 752614cab8e6 ("target/riscv: rvv: Add tail agnostic for vector load / store instructions")
---
  target/riscv/vector_helper.c | 21 ++++++---------------
  1 file changed, 6 insertions(+), 15 deletions(-)
target/riscv/vector_helper.c +2 -5
index f4d0438988..56a79bb5fa 100644
@@ -264,26 +264,17 @@ GEN_VEXT_ST_ELEM(ste_h, int16_t, H2, stw)
  GEN_VEXT_ST_ELEM(ste_w, int32_t, H4, stl)
  GEN_VEXT_ST_ELEM(ste_d, int64_t, H8, stq)
 
-static void vext_set_tail_elems_1s(CPURISCVState *env, target_ulong vl,
-                                   void *vd, uint32_t desc, uint32_t nf,
+static void vext_set_tail_elems_1s(target_ulong vl, void *vd,
+                                   uint32_t desc, uint32_t nf,
                                     uint32_t esz, uint32_t max_elems)
  {
-    uint32_t total_elems = vext_get_total_elems(env, desc, esz);
-    uint32_t vlenb = riscv_cpu_cfg(env)->vlen >> 3;
      uint32_t vta = vext_vta(desc);
-    uint32_t registers_used;
      int k;
 
      for (k = 0; k < nf; ++k) {

target/riscv/vector_helper.c GEN_VEXT_ST_ELEM(ste_h, int16_t, H2, stw) · line 278

Quoted 10 lines
target/riscv/vector_helper.c +0 -6
          vext_set_elems_1s(vd, vta, (k * max_elems + vl) * esz,
                            (k * max_elems + max_elems) * esz);
      }
-
-    if (nf * max_elems % total_elems != 0) {
-        registers_used = ((nf * max_elems) * esz + (vlenb - 1)) / vlenb;
-        vext_set_elems_1s(vd, vta, (nf * max_elems) * esz,
-                          registers_used * vlenb);
-    }
  }

Can you please rebase it on top of master? This function has at least one change (a vta check right at the start) that isn't accounted for in this patch.

Code LGTM otherwise. Thanks,

Daniel

Quoted 38 lines
target/riscv/vector_helper.c +4 -4
  /*
@@ -319,7 +310,7 @@ vext_ldst_stride(void *vd, void *v0, target_ulong base,
      }
      env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, env->vl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(env->vl, vd, desc, nf, esz, max_elems);
  }
 
  #define GEN_VEXT_LD_STRIDE(NAME, ETYPE, LOAD_FN)                        \
@@ -378,7 +369,7 @@ vext_ldst_us(void *vd, target_ulong base, CPURISCVState *env, uint32_t desc,
      }
      env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, evl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(evl, vd, desc, nf, esz, max_elems);
  }
 
  /*
@@ -499,7 +490,7 @@ vext_ldst_index(void *vd, void *v0, target_ulong base,
      }
      env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, env->vl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(env->vl, vd, desc, nf, esz, max_elems);
  }
 
  #define GEN_VEXT_LD_INDEX(NAME, ETYPE, INDEX_FN, LOAD_FN)                  \
@@ -629,7 +620,7 @@ ProbeSuccess:
      }
      env->vstart = 0;
 
-    vext_set_tail_elems_1s(env, env->vl, vd, desc, nf, esz, max_elems);
+    vext_set_tail_elems_1s(env->vl, vd, desc, nf, esz, max_elems);
  }
 
  #define GEN_VEXT_LDFF(NAME, ETYPE, LOAD_FN)               \
#2 lore raw

Hi,

Quoted 80 lines

-----Original Message-----
From: Daniel Henrique Barboza <[email protected]>
Sent: Tuesday, June 6, 2023 6:31 PM
To: Wang, Xiao W <[email protected]>; [email protected]
Cc: Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Meng, Bin <[email protected]>; Weiwei Li <[email protected]>; Liu Zhiwei <[email protected]>; open list:RISC-V TCG CPUs <[email protected]>
Subject: Re: [PATCH] target/riscv/vector_helper.c: Remove the check for extra tail elements

Hi,

Quoted 8 lines · Xiao Wang

Commit 752614cab8e6 ("target/riscv: rvv: Add tail agnostic for vector load / store instructions") added an extra check for LMUL fragmentation, intended for setting the "rest tail elements" in the last register for a segment load insn.

Actually, the max_elements derived in vext_ld*() won't be a fraction of vector register size, since the lmul encoded in desc is emul, which has already been adjusted to 1 for LMUL fragmentation case by

vext_get_emul()

Quoted 3 lines

in trans_rvv.c.inc, for ld_stride(), ld_us(), ld_index() and ldff().

Besides, vext_get_emul() has also taken EEW/SEW into consideration, so

no

Quoted 1 line

need to call vext_get_total_elems() which would base on the emul to

derive

Quoted 1 line

another emul, the second emul would be incorrect when esz differs from

sew.

Quoted 4 lines

Thus this patch removes the check for extra tail elements.

Fixes 752614cab8e6 ("target/riscv: rvv: Add tail agnostic for vector load /

store instructions")

Quoted 27 lines
---
  target/riscv/vector_helper.c | 21 ++++++---------------
  1 file changed, 6 insertions(+), 15 deletions(-)
target/riscv/vector_helper.c +2 -5
index f4d0438988..56a79bb5fa 100644
@@ -264,26 +264,17 @@ GEN_VEXT_ST_ELEM(ste_h, int16_t, H2, stw)
  GEN_VEXT_ST_ELEM(ste_w, int32_t, H4, stl)
  GEN_VEXT_ST_ELEM(ste_d, int64_t, H8, stq)
 
-static void vext_set_tail_elems_1s(CPURISCVState *env, target_ulong vl,
-                                   void *vd, uint32_t desc, uint32_t nf,
+static void vext_set_tail_elems_1s(target_ulong vl, void *vd,
+                                   uint32_t desc, uint32_t nf,
                                     uint32_t esz, uint32_t max_elems)
  {
-    uint32_t total_elems = vext_get_total_elems(env, desc, esz);
-    uint32_t vlenb = riscv_cpu_cfg(env)->vlen >> 3;
      uint32_t vta = vext_vta(desc);
-    uint32_t registers_used;
      int k;
 
      for (k = 0; k < nf; ++k) {

target/riscv/vector_helper.c GEN_VEXT_ST_ELEM(ste_h, int16_t, H2, stw) · line 278

Quoted 10 lines
target/riscv/vector_helper.c +0 -6
          vext_set_elems_1s(vd, vta, (k * max_elems + vl) * esz,
                            (k * max_elems + max_elems) * esz);
      }
-
-    if (nf * max_elems % total_elems != 0) {
-        registers_used = ((nf * max_elems) * esz + (vlenb - 1)) / vlenb;
-        vext_set_elems_1s(vd, vta, (nf * max_elems) * esz,
-                          registers_used * vlenb);
-    }
  }

Can you please rebase it on top of master? This function has at least one change (a vta check right at the start) that isn't accounted for in this patch.

Quoted 5 lines

Code LGTM otherwise. Thanks,

Daniel

OK. I think you refer to the riscv-to-apply.next branch in https://github.com/alistair23/qemu.git, I see the vta check in that branch only. Would do a rebase. Thanks.

-Xiao