Skip to contentSkip to conversation

target/riscv/vector_helper.c: Avoid shifting negative in fractional LMUL checking

PATCH In review Max Chou 2 participants 3 messages Mar 6, 2024 – Mar 7, 2024 RISC-V

lore
Share & tools
lore

Max Chou

author
#0 lore raw

PATCH 1/1 target/riscv/vector_helper.c: Avoid shifting negative in fractional LMUL checking

When vlmul is larger than 5, the original fractional LMUL checking may gets unexpected result.

---
 target/riscv/vector_helper.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/vector_helper.c +1 -2
index 84cec73eb20..adceec378fd 100644
@@ -53,10 +53,9 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
          * VLEN * LMUL >= SEW
          * VLEN >> (8 - lmul) >= sew
          * (vlenb << 3) >> (8 - lmul) >= sew
-         * vlenb >> (8 - 3 - lmul) >= sew
          */
         if (vlmul == 4 ||
-            cpu->cfg.vlenb >> (8 - 3 - vlmul) < sew) {
+            ((cpu->cfg.vlenb << 3) >> (8 - vlmul)) < sew) {
             vill = true;
         }
     }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Max Chou

When vlmul is larger than 5, the original fractional LMUL checking may gets unexpected result.

---

There's already a fix for it in the ML:

"[PATCH v3] target/riscv: Fix shift count overflow"

https://lore.kernel.org/qemu-riscv/[email protected]/

Hopefully it'll be queued for the next PR. Thanks,

Daniel

Quoted 19 lines
  target/riscv/vector_helper.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/vector_helper.c +1 -2
index 84cec73eb20..adceec378fd 100644
@@ -53,10 +53,9 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
           * VLEN * LMUL >= SEW
           * VLEN >> (8 - lmul) >= sew
           * (vlenb << 3) >> (8 - lmul) >= sew
-         * vlenb >> (8 - 3 - lmul) >= sew
           */
          if (vlmul == 4 ||
-            cpu->cfg.vlenb >> (8 - 3 - vlmul) < sew) {
+            ((cpu->cfg.vlenb << 3) >> (8 - vlmul)) < sew) {
              vill = true;
          }
      }
author
#2 lore raw

Looks liked that I missed this one.

Thank you Daniel

Max.

Quoted 43 lines · Daniel Henrique Barboza
Quoted 5 lines · Max Chou

When vlmul is larger than 5, the original fractional LMUL checking may gets unexpected result.

---

There's already a fix for it in the ML:

"[PATCH v3] target/riscv: Fix shift count overflow"

https://lore.kernel.org/qemu-riscv/[email protected]/

Hopefully it'll be queued for the next PR. Thanks,

Daniel

Quoted 20 lines

  target/riscv/vector_helper.c | 3 +--

  1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/vector_helper.c +0 -1
index 84cec73eb20..adceec378fd 100644
@@ -53,10 +53,9 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, 
 target_ulong s1,
            * VLEN * LMUL >= SEW
            * VLEN >> (8 - lmul) >= sew
            * (vlenb << 3) >> (8 - lmul) >= sew
-         * vlenb >> (8 - 3 - lmul) >= sew
            */

          if (vlmul == 4 ||
-            cpu->cfg.vlenb >> (8 - 3 - vlmul) < sew) { +            ((cpu->cfg.vlenb << 3) >> (8 - vlmul)) < sew) { vill = true;
          }
      }