Skip to contentSkip to conversation

target/riscv: rvv: Minimum VLEN needs to respect V/Zve extensions

PATCH In review Max Chou 3 participants 4 messages Jun 27, 2025 – Jul 7, 2025 RISC-V

lore
Share & tools
lore

Max Chou

author
#0 lore raw

PATCH 1/1 target/riscv: rvv: Minimum VLEN needs to respect V/Zve extensions

According to the RISC-V instruction set manual, the minimum VLEN needs to respect the following extensions:

Extension Minimum VLEN
* V 128

* Zve64[d|f|x]   64
* Zve32[f|x]     32
---
 target/riscv/tcg/tcg-cpu.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
target/riscv/tcg/tcg-cpu.c +11 -2
index 163e7ce3642..187534009dd 100644
@@ -416,12 +416,21 @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)
 static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
                                  Error **errp)
 {
+    uint32_t min_vlen;
     uint32_t vlen = cfg->vlenb << 3;
 
-    if (vlen > RV_VLEN_MAX || vlen < 128) {
+    if (riscv_has_ext(env, RVV)) {
+        min_vlen = 128;
+    } else if (cfg->ext_zve64x) {
+        min_vlen = 64;
+    } else if (cfg->ext_zve32x) {
+        min_vlen = 32;
+    }
+
+    if (vlen > RV_VLEN_MAX || vlen < min_vlen) {
         error_setg(errp,
                    "Vector extension implementation only supports VLEN "
-                   "in the range [128, %d]", RV_VLEN_MAX);
+                   "in the range [%d, %d]", min_vlen, RV_VLEN_MAX);
         return;
     }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Max Chou

According to the RISC-V instruction set manual, the minimum VLEN needs to respect the following extensions:

Extension Minimum VLEN
* V 128

* Zve64[d|f|x]   64
* Zve32[f|x]     32
---
  target/riscv/tcg/tcg-cpu.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
target/riscv/tcg/tcg-cpu.c +7 -1
index 163e7ce3642..187534009dd 100644
@@ -416,12 +416,21 @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)
  static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
                                   Error **errp)
  {
+    uint32_t min_vlen;
      uint32_t vlen = cfg->vlenb << 3;
 
-    if (vlen > RV_VLEN_MAX || vlen < 128) {
+    if (riscv_has_ext(env, RVV)) {
+        min_vlen = 128;
+    } else if (cfg->ext_zve64x) {
+        min_vlen = 64;
+    } else if (cfg->ext_zve32x) {
+        min_vlen = 32;

target/riscv/tcg/tcg-cpu.c static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) · line 436

Quoted 10 lines
target/riscv/tcg/tcg-cpu.c +4 -1
+    }
+
+    if (vlen > RV_VLEN_MAX || vlen < min_vlen) {
          error_setg(errp,
                     "Vector extension implementation only supports VLEN "
-                   "in the range [128, %d]", RV_VLEN_MAX);
+                   "in the range [%d, %d]", min_vlen, RV_VLEN_MAX);
          return;
      }
 

Thanks,
Nutty

#2 lore raw
In reply to Max Chou
Quoted 22 lines · Max Chou

According to the RISC-V instruction set manual, the minimum VLEN needs to respect the following extensions:

Extension Minimum VLEN
* V 128

* Zve64[d|f|x]   64
* Zve32[f|x]     32
---
  target/riscv/tcg/tcg-cpu.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
target/riscv/tcg/tcg-cpu.c +1 -0
index 163e7ce3642..187534009dd 100644
@@ -416,12 +416,21 @@ static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)
  static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
                                   Error **errp)
  {
+    uint32_t min_vlen;

target/riscv/tcg/tcg-cpu.c static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) · line 428

Quoted 10 lines
target/riscv/tcg/tcg-cpu.c +7 -1
      uint32_t vlen = cfg->vlenb << 3;
 
-    if (vlen > RV_VLEN_MAX || vlen < 128) {
+    if (riscv_has_ext(env, RVV)) {
+        min_vlen = 128;
+    } else if (cfg->ext_zve64x) {
+        min_vlen = 64;
+    } else if (cfg->ext_zve32x) {
+        min_vlen = 32;
+    }

At this moment this is how we're calling riscv_cpu_validate_v():

    if (riscv_has_ext(env, RVV)) {
        riscv_cpu_validate_v(env, &cpu->cfg, &local_err);
        if (local_err != NULL) {
            error_propagate(errp, local_err);
            return;
        }
    }

riscv_has_ext(env, RVV) is always true inside the function. The code above will always result in min_vlen = 128 because of the 'else if' chaining.

IIUC the idea of the patch, what you want is something like:

target/riscv/tcg/tcg-cpu.c static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) · line 428

Quoted 9 lines
target/riscv/tcg/tcg-cpu.c +6 -1
+    uint32_t min_vlen = 128;
      uint32_t vlen = cfg->vlenb << 3;
 
-    if (vlen > RV_VLEN_MAX || vlen < 128) {
+    if (cfg->ext_zve64x) {
+        min_vlen = 64;
+    } else if (cfg->ext_zve32x) {
+        min_vlen = 32;
+    }

I.e. init min_vlen to 128 (since RVV is always true) and then change it according to zve64x and zve32x.

Thanks,

Daniel

Quoted 9 lines
target/riscv/tcg/tcg-cpu.c +3 -1
+
+    if (vlen > RV_VLEN_MAX || vlen < min_vlen) {
          error_setg(errp,
                     "Vector extension implementation only supports VLEN "
-                   "in the range [128, %d]", RV_VLEN_MAX);
+                   "in the range [%d, %d]", min_vlen, RV_VLEN_MAX);
          return;
      }
author
#3 lore raw

Hi Daniel,

Thanks for the question.
Yes, you are right.
And I find that I miss some patches for the part that you mentioned here. I'll update this patchset for it.

Thanks,
Max

Quoted 88 lines · Daniel Henrique Barboza

target/riscv/tcg/tcg-cpu.c static void

Quoted 18 lines · Max Chou

According to the RISC-V instruction set manual, the minimum VLEN needs to respect the following extensions:

Extension Minimum VLEN
* V 128

* Zve64[d|f|x]   64
* Zve32[f|x]     32
---
  target/riscv/tcg/tcg-cpu.c | 13 +++++++++++--
  1 file changed, 11 insertions(+), 2 deletions(-)
target/riscv/tcg/tcg-cpu.c +0 -0
index 163e7ce3642..187534009dd 100644
@@ -416,12 +416,21 @@ static void

riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)

target/riscv/tcg/tcg-cpu.c static void · line 416

Quoted 1 line
target/riscv/tcg/tcg-cpu.c +0 -0
  static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig

*cfg,

target/riscv/tcg/tcg-cpu.c static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) · line 428

Quoted 13 lines
target/riscv/tcg/tcg-cpu.c +8 -1
                                   Error **errp)
  {
+    uint32_t min_vlen;
      uint32_t vlen = cfg->vlenb << 3;
 
-    if (vlen > RV_VLEN_MAX || vlen < 128) {
+    if (riscv_has_ext(env, RVV)) {
+        min_vlen = 128;
+    } else if (cfg->ext_zve64x) {
+        min_vlen = 64;
+    } else if (cfg->ext_zve32x) {
+        min_vlen = 32;
+    }

At this moment this is how we're calling riscv_cpu_validate_v():

     if (riscv_has_ext(env, RVV)) {
         riscv_cpu_validate_v(env, &cpu->cfg, &local_err);
         if (local_err != NULL) {
             error_propagate(errp, local_err);
             return;
         }
     }

riscv_has_ext(env, RVV) is always true inside the function. The code above will
always result in min_vlen = 128 because of the 'else if' chaining.

IIUC the idea of the patch, what you want is something like:

target/riscv/tcg/tcg-cpu.c static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) · line 428

Quoted 9 lines
target/riscv/tcg/tcg-cpu.c +6 -1
+    uint32_t min_vlen = 128;
      uint32_t vlen = cfg->vlenb << 3;
 
-    if (vlen > RV_VLEN_MAX || vlen < 128) {
+    if (cfg->ext_zve64x) {
+        min_vlen = 64;
+    } else if (cfg->ext_zve32x) {
+        min_vlen = 32;
+    }

I.e. init min_vlen to 128 (since RVV is always true) and then change it according to
zve64x and zve32x.

Thanks,

Daniel

target/riscv/tcg/tcg-cpu.c static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)

Quoted 4 lines
target/riscv/tcg/tcg-cpu.c +2 -0
+
+    if (vlen > RV_VLEN_MAX || vlen < min_vlen) {
          error_setg(errp,
                     "Vector extension implementation only supports VLEN

"

Quoted 5 lines
target/riscv/tcg/tcg-cpu.c +1 -1
-                   "in the range [128, %d]", RV_VLEN_MAX);
+                   "in the range [%d, %d]", min_vlen, RV_VLEN_MAX);
          return;
      }