Skip to contentSkip to conversation

target/riscv: Fix shift count overflow

PATCH Superseded demin.han 2 participants 2 messages Feb 24, 2024 RISC-V

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

demin.han

author
#0 lore raw

PATCH 1/1 target/riscv: Fix shift count overflow

The result of (8 - 3 - vlmul) is negtive when vlmul >= 6, and results in wrong vill.

---
 target/riscv/vector_helper.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/vector_helper.c +1 -2
index 84cec73eb2..ced0aca633 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.43.2
#1 lore raw
Quoted 13 lines · demin.han

The result of (8 - 3 - vlmul) is negtive when vlmul >= 6, and results in wrong vill.

---
  target/riscv/vector_helper.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
target/riscv/vector_helper.c +0 -0
index 84cec73eb2..ced0aca633 100644

target/riscv/vector_helper.c target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, · line 60

Quoted 10 lines
target/riscv/vector_helper.c +1 -2
@@ -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;
          }

Please add a new var:

uint16_t vlen = cpu->cfg.vlenb << 3;

And use it in the 'if' to be more readable:

           if (vlmul == 4 ||
               vlen >> (8 - 3 - vlmul) < sew) {
               vill = true;
           }

Thanks,

Daniel

Quoted 1 line
target/riscv/vector_helper.c +0 -0
      }