target/riscv: Lower bound of VLEN is 32, and check VLEN >= ELEN
PATCH 1/2 target/riscv: Lower bound of VLEN is 32, and check VLEN >= ELEN
According RVV spec 1.0, the minmal requirement of VLEN is great than or equal to ELEN, and minmal possible ELEN is 32, and also spec has mention Minimum VLEN for zve32* is 32, so the lower bound of VLEN is 32 I think.
[1] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#2-implementation-defined-constant-parameters
[2] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#182-zve-vector-extensions-for-embedded-processors
--- target/riscv/cpu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
target/riscv/cpu.c +8 -2
@@ -740,10 +740,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension VLEN must be power of 2");return ; } -if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <128 ) { +if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <32 ) {error_setg (errp,"Vector extension implementation only supports VLEN " -"in the range [128, %d]" ,RV_VLEN_MAX ); +"in the range [32, %d]" ,RV_VLEN_MAX );return ; }if (!is_power_of_2 (cpu->cfg.elen)) {
@@ -757,6 +757,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "in the range [8, 64]");return ; } +if (cpu->cfg.vlen < cpu->cfg.elen) { +error_setg (errp, +"Vector extension VLEN must be greater than or equal " +"to ELEN" ); +return ; + }if (cpu->cfg.vext_spec) {if (!g_strcmp0 (cpu->cfg.vext_spec,"v1.0" )) { vext_version =VEXT_VERSION_1_00_0 ;
Signature · 1 line
2.34.0
PATCH 2/2 target/riscv: Auto set elen from vector extension by default
Default ELEN is setting to 64 for now, which is incorrect setting for Zve32*, and spec has mention minimum VLEN and supported EEW in chapter "Zve*: Vector Extensions for Embedded Processors" is 32 for Zve32.
ELEN actaully could be derived from which extensions are enabled, so this patch set elen to 0 as auto detect, and keep the capability to let user could configure that.
--- target/riscv/cpu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
target/riscv/cpu.c +13 -3
@@ -751,13 +751,22 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension ELEN must be power of 2");return ; } -if (cpu->cfg.elen >64 || cpu->cfg.vlen <8 ) { +if (cpu->cfg.elen ==0 ) { +if (cpu->cfg.ext_zve32f) { + cpu->cfg.elen =32 ; + } +if (cpu->cfg.ext_zve64f || cpu->cfg.ext_v) { + cpu->cfg.elen =64 ; + } + } +if (cpu->cfg.elen !=0 && (cpu->cfg.elen >64 || + cpu->cfg.elen <8 )) {error_setg (errp,"Vector extension implementation only supports ELEN " "in the range [8, 64]" );return ; } -if (cpu->cfg.vlen < cpu->cfg.elen) { +if (cpu->cfg.elen !=0 && cpu->cfg.vlen < cpu->cfg.elen) {error_setg (errp,"Vector extension VLEN must be greater than or equal " "to ELEN" );
@@ -901,7 +910,8 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec),DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), -DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +/* elen = 0 means set from v or zve* extension */ +DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,0 ),DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false), DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false),
Signature · 1 line
2.34.0
Re: [PATCH 2/2] target/riscv: Auto set elen from vector extension by default
Quoted 19 lines · Kito Cheng
Default ELEN is setting to 64 for now, which is incorrect setting for Zve32*, and spec has mention minimum VLEN and supported EEW in chapter "Zve*: Vector Extensions for Embedded Processors" is 32 for Zve32.
ELEN actaully could be derived from which extensions are enabled, so this patch set elen to 0 as auto detect, and keep the capability to let user could configure that.
Signed-off-by Kito Cheng <[email protected]>--- target/riscv/cpu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)target/riscv/cpu.c +0
-0@@ -751,13 +751,22 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension ELEN must be power of 2");
target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 760
Quoted 10 lines
target/riscv/cpu.c +7
-1return ; } -if (cpu->cfg.elen >64 || cpu->cfg.vlen <8 ) { +if (cpu->cfg.elen ==0 ) { +if (cpu->cfg.ext_zve32f) { + cpu->cfg.elen =32 ; + } +if (cpu->cfg.ext_zve64f || cpu->cfg.ext_v) { + cpu->cfg.elen =64 ; + }
This code is in the "if(cpu->cfg.ext_v){...}", so "cpu->cfg.ext_zve64f || cpu->cfg.ext_v" will always be true.
It can use "else ... " directly.
target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 769
Quoted 10 lines
target/riscv/cpu.c +4
-1+ } +if (cpu->cfg.elen !=0 && (cpu->cfg.elen >64 || + cpu->cfg.elen <8 )) {error_setg (errp,"Vector extension implementation only supports ELEN " "in the range [8, 64]" );return ; } -if (cpu->cfg.vlen < cpu->cfg.elen) { +if (cpu->cfg.elen !=0 && cpu->cfg.vlen < cpu->cfg.elen) {
when cfg.elen is set to zero, it will be changed to the auto detect value(32/64) before this two check.
So this two modifications seem unnecessary.
Regards,
Weiwei Li
Quoted 13 lines
target/riscv/cpu.c +2
-1error_setg (errp,"Vector extension VLEN must be greater than or equal " "to ELEN" );@@ -901,7 +910,8 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec),DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), -DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +/* elen = 0 means set from v or zve* extension */ +DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,0 ),DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false), DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false),
Re: [PATCH 2/2] target/riscv: Auto set elen from vector extension by default
Quoted 34 lines · Weiwei Li
Quoted 20 lines · Kito Cheng
Default ELEN is setting to 64 for now, which is incorrect setting for Zve32*, and spec has mention minimum VLEN and supported EEW in chapter "Zve*: Vector Extensions for Embedded Processors" is 32 for Zve32.
ELEN actaully could be derived from which extensions are enabled, so this patch set elen to 0 as auto detect, and keep the capability to let user could configure that.
Signed-off-by Kito Cheng <[email protected]>---
target/riscv/cpu.c| 16 +++++++++++++---1 file changed, 13 insertions(+), 3 deletions(-)target/riscv/cpu.c +0
-0@@ -751,13 +751,22 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension ELEN must be power of 2");target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, · line 761
Quoted 10 lines
target/riscv/cpu.c +7
-1return; } - if (cpu->cfg.elen > 64 || cpu->cfg.vlen < 8) { + if (cpu->cfg.elen == 0) { + if (cpu->cfg.ext_zve32f) { + cpu->cfg.elen = 32; + } + if (cpu->cfg.ext_zve64f || cpu->cfg.ext_v) { + cpu->cfg.elen = 64; + }This code is in the "if(cpu->cfg.ext_v){...}", so "
cpu->cfg.ext_zve64f||cpu->cfg.ext_v" will always be true.
Quoted 1 line
It can use "else ... " directly.
Sorry, misunderstood the logic. It seems that we should set cpu->cfg.elen=64 directly here.
Regards,
Weiwei Li
Quoted 32 lines
Quoted 10 lines
target/riscv/cpu.c +3
-0+ } + if (cpu->cfg.elen != 0 && (cpu->cfg.elen > 64 || + cpu->cfg.elen < 8)) { error_setg(errp,"Vector extension implementation only supports ELEN " "in the range [8, 64]");
return;
}
- if (cpu->cfg.vlen<cpu->cfg.elen) {
+ if (cpu->cfg.elen!= 0 &&cpu->cfg.vlen<cpu->cfg.elen) {when cfg.elen is set to zero, it will be changed to the auto detect value(32/64) before this two check.
So this two modifications seem unnecessary.
Regards,
Weiwei Li
Quoted 12 lines
error_setg(errp,
"Vector extension VLEN must be greater than or equal " "to ELEN");target/riscv/cpu.c +2
-1@@ -901,7 +910,8 @@ static Property riscv_cpu_extensions[] = { DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128), - DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), + /* elen = 0 means set from v or zve* extension */ + DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 0), DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false), DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false),
Re: [PATCH 2/2] target/riscv: Auto set elen from vector extension by default
In reply to Kito ChengQuoted 36 lines · Kito Cheng
Default ELEN is setting to 64 for now, which is incorrect setting for Zve32*, and spec has mention minimum VLEN and supported EEW in chapter "Zve*: Vector Extensions for Embedded Processors" is 32 for Zve32.
ELEN actaully could be derived from which extensions are enabled, so this patch set elen to 0 as auto detect, and keep the capability to let user could configure that.
Signed-off-by Kito Cheng <[email protected]>--- target/riscv/cpu.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)target/riscv/cpu.c +10
-1@@ -751,13 +751,22 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension ELEN must be power of 2");return ; } -if (cpu->cfg.elen >64 || cpu->cfg.vlen <8 ) { +if (cpu->cfg.elen ==0 ) { +if (cpu->cfg.ext_zve32f) { + cpu->cfg.elen =32 ; + } +if (cpu->cfg.ext_zve64f || cpu->cfg.ext_v) { + cpu->cfg.elen =64 ; + } + } +if (cpu->cfg.elen !=0 && (cpu->cfg.elen >64 || + cpu->cfg.elen <8 )) { error_setg(errp, "Vector extension implementation only supportsELEN "
Quoted 4 lines
"in the range [8, 64]");
return;
}Should we also check whether cpu->cfg.elen set by user must >= 32 if Zve32f is enabled?
Same for Zve64f.
Regards,
Frank Chang
Quoted 20 lines
target/riscv/cpu.c +1
-1-if (cpu->cfg.vlen < cpu->cfg.elen) { +if (cpu->cfg.elen !=0 && cpu->cfg.vlen < cpu->cfg.elen) { error_setg(errp, "Vector extension VLEN must be greater than orequal "
"to ELEN");target/riscv/cpu.c +2
-2@@ -901,7 +910,8 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_STRING ("priv_spec" ,RISCVCPU , cfg.priv_spec),DEFINE_PROP_STRING ("vext_spec" ,RISCVCPU , cfg.vext_spec),DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), -DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +/* elen = 0 means set from v or zve* extension */ +DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,0 ),DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false), DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false), --2.34.0
Quoted 4 lines · Kito Cheng
According RVV spec 1.0, the minmal requirement of VLEN is great than or equal to ELEN, and minmal possible ELEN is 32, and also spec has mention
Minimum VLENfor zve32* is 32, so the lower bound of VLEN is 32 I think.
Sorry. I have a question about how to decide the minmal possible ELEN to be 32?
In current implementation, elen should be in the range [8, 64](and there seems to be a typo in the check for this).
If the minmal possible ELEN is 32, maybe we need change the check to "elen >= 32" too.
Regards,
Weiwei Li
Quoted 38 lines
[1] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#2-implementation-defined-constant-parameters
[2] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#182-zve-vector-extensions-for-embedded-processorsSigned-off-by Kito Cheng <[email protected]>--- target/riscv/cpu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)target/riscv/cpu.c +8
-2@@ -740,10 +740,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension VLEN must be power of 2");return ; } -if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <128 ) { +if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <32 ) {error_setg (errp,"Vector extension implementation only supports VLEN " -"in the range [128, %d]" ,RV_VLEN_MAX ); +"in the range [32, %d]" ,RV_VLEN_MAX );return ; }if (!is_power_of_2 (cpu->cfg.elen)) {@@ -757,6 +757,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "in the range [8, 64]");return ; } +if (cpu->cfg.vlen < cpu->cfg.elen) { +error_setg (errp, +"Vector extension VLEN must be greater than or equal " +"to ELEN" ); +return ; + }if (cpu->cfg.vext_spec) {if (!g_strcmp0 (cpu->cfg.vext_spec,"v1.0" )) { vext_version =VEXT_VERSION_1_00_0 ;
Quoted 19 lines · Kito Cheng
According RVV spec 1.0, the minmal requirement of VLEN is great than or equal to ELEN, and minmal possible ELEN is 32, and also spec has mention
Minimum VLENfor zve32* is 32, so the lower bound of VLEN is 32 I think.[1] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#2-implementation-defined-constant-parameters
[2] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc#182-zve-vector-extensions-for-embedded-processorsSigned-off-by Kito Cheng <[email protected]>--- target/riscv/cpu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)target/riscv/cpu.c +0
-0@@ -740,10 +740,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "Vector extension VLEN must be power of 2");
target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 748
Quoted 10 lines
target/riscv/cpu.c +2
-2return ; } -if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <128 ) { +if (cpu->cfg.vlen >RV_VLEN_MAX || cpu->cfg.vlen <32 ) {error_setg (errp,"Vector extension implementation only supports VLEN " -"in the range [128, %d]" ,RV_VLEN_MAX ); +"in the range [32, %d]" ,RV_VLEN_MAX );return ; }
The check for "VLEN in the range [128, RV_VLEN_MAX]" seems right here, since this check is for
V vector extension in current implementation and "The V vector extension requires Zvl128b"(in section 18.3).
Regards,
Weiwei Li
Quoted 14 lines
target/riscv/cpu.c +6
-0if (!is_power_of_2 (cpu->cfg.elen)) {@@ -757,6 +757,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) "in the range [8, 64]");return ; } +if (cpu->cfg.vlen < cpu->cfg.elen) { +error_setg (errp, +"Vector extension VLEN must be greater than or equal " +"to ELEN" ); +return ; + }if (cpu->cfg.vext_spec) {if (!g_strcmp0 (cpu->cfg.vext_spec,"v1.0" )) { vext_version =VEXT_VERSION_1_00_0 ;