Skip to contentSkip to conversation

target/riscv: Fix LMUL check to use VLEN

PATCH Applied Rob Bradford 3 participants 3 messages Jul 18, 2023 – Jul 19, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 target/riscv: Fix LMUL check to use VLEN

The previous check was failing with:

VLEN=128 ELEN = 64 SEW = 16 and LMUL = 1/8 which is a valid combination.

Fix the check to allow valid combinations when VLEN is a multiple of ELEN.

From the specification:

"In general, the requirement is to support LMUL ≥ SEWMIN/ELEN, where SEWMIN is the narrowest supported SEW value and ELEN is the widest supported SEW value. In the standard extensions, SEWMIN=8. For standard vector extensions with ELEN=32, fractional LMULs of 1/2 and 1/4 must be supported. For standard vector extensions with ELEN=64, fractional LMULs of 1/2, 1/4, and 1/8 must be supported." Elsewhere in the specification it makes clear that VLEN>=ELEN.

From inspection this new check allows:

VLEN=ELEN=64 1/2, 1/4, 1/8 for SEW >=8
VLEN=ELEN=32 1/2, 1/4 for SEW >=8

Fixes d9b7609a1fb2 ("target/riscv: rvv-1.0: configure instructions")

---
V2: Switch check to use VLEN and active SEW vs ELEN and minimum SEW

---
 target/riscv/vector_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/vector_helper.c +2 -2
index cfacf2ebba..4d06754826 100644
@@ -43,9 +43,9 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
                                             xlen - 1 - R_VTYPE_RESERVED_SHIFT);
 
     if (lmul & 4) {
-        /* Fractional LMUL. */
+        /* Fractional LMUL - check LMUL * VLEN >= SEW */
         if (lmul == 4 ||
-            cpu->cfg.elen >> (8 - lmul) < sew) {
+            cpu->cfg.vlen >> (8 - lmul) < sew) {
             vill = true;
         }
     }
Signature · 1 line
2.41.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 23 lines · Rob Bradford

The previous check was failing with:

VLEN=128 ELEN = 64 SEW = 16 and LMUL = 1/8 which is a valid combination.

Fix the check to allow valid combinations when VLEN is a multiple of ELEN.

From the specification:

"In general, the requirement is to support LMUL ≥ SEWMIN/ELEN, where SEWMIN is the narrowest supported SEW value and ELEN is the widest supported SEW value. In the standard extensions, SEWMIN=8. For standard vector extensions with ELEN=32, fractional LMULs of 1/2 and 1/4 must be supported. For standard vector extensions with ELEN=64, fractional LMULs of 1/2, 1/4, and 1/8 must be supported." Elsewhere in the specification it makes clear that VLEN>=ELEN.

From inspection this new check allows:

VLEN=ELEN=64 1/2, 1/4, 1/8 for SEW >=8
VLEN=ELEN=32 1/2, 1/4 for SEW >=8

Quoted 6 lines
Fixes d9b7609a1fb2 ("target/riscv: rvv-1.0: configure instructions")

---
V2: Switch check to use VLEN and active SEW vs ELEN and minimum SEW
---

Weiwei Li

Quoted 19 lines
  target/riscv/vector_helper.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/vector_helper.c +2 -2
index cfacf2ebba..4d06754826 100644
@@ -43,9 +43,9 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
                                              xlen - 1 - R_VTYPE_RESERVED_SHIFT);
 
      if (lmul & 4) {
-        /* Fractional LMUL. */
+        /* Fractional LMUL - check LMUL * VLEN >= SEW */
          if (lmul == 4 ||
-            cpu->cfg.elen >> (8 - lmul) < sew) {
+            cpu->cfg.vlen >> (8 - lmul) < sew) {
              vill = true;
          }
      }
#2 lore raw
In reply to Rob Bradford
Quoted 19 lines · Rob Bradford

The previous check was failing with:

VLEN=128 ELEN = 64 SEW = 16 and LMUL = 1/8 which is a valid combination.

Fix the check to allow valid combinations when VLEN is a multiple of ELEN.

From the specification:

"In general, the requirement is to support LMUL ≥ SEWMIN/ELEN, where SEWMIN is the narrowest supported SEW value and ELEN is the widest supported SEW value. In the standard extensions, SEWMIN=8. For standard vector extensions with ELEN=32, fractional LMULs of 1/2 and 1/4 must be supported. For standard vector extensions with ELEN=64, fractional LMULs of 1/2, 1/4, and 1/8 must be supported." Elsewhere in the specification it makes clear that VLEN>=ELEN.

Quoted 8 lines

From inspection this new check allows:

VLEN=ELEN=64 1/2, 1/4, 1/8 for SEW >=8
VLEN=ELEN=32 1/2, 1/4 for SEW >=8

Fixes d9b7609a1fb2 ("target/riscv: rvv-1.0: configure instructions")

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 26 lines

---
V2: Switch check to use VLEN and active SEW vs ELEN and minimum SEW

---
 target/riscv/vector_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/riscv/vector_helper.c +2 -3
index cfacf2ebba..4d06754826 100644
@@ -43,9 +43,9 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1,
                                             xlen - 1 - R_VTYPE_RESERVED_SHIFT);
 
     if (lmul & 4) {
-        /* Fractional LMUL. */
+        /* Fractional LMUL - check LMUL * VLEN >= SEW */
         if (lmul == 4 ||
-            cpu->cfg.elen >> (8 - lmul) < sew) {
+            cpu->cfg.vlen >> (8 - lmul) < sew) {
             vill = true;
         }
     }
--

2.41.0