target/riscv: Add support for 'B' extension
cover target/riscv: Add support for 'B' extension
Add support for the new (fast track) 'B' extension [1] this extension uses the misa.B bit to indicate that the Zba, Zbb and Zbs extensions are present.
Since this extension is not yet frozen it is exposed via the 'x-b' cpu option. The validation logic is based on the new approach taken for the 'G' extension. [2]
The specification handles backward compatability: The misa.B bit may be set if Zba, Zbb and Zbs are present but in order to not break existing systems the bit is not required to be set if they are present. As such even though Zba, Zbb and Zbs default to on in QEMU this extension is not enabled by default in any cpu other than the 'max' variant.
Cheers,
Rob
[1] - https://github.com/riscv/riscv-b
[2] - https://patchew.org/QEMU/[email protected]/[email protected]/
Rob Bradford (3):
target/riscv: Add infrastructure for 'B' MISA extension target/riscv: Add step to validate 'B' extension target/riscv: Enable 'B' extension on max CPU type
target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 target/riscv: Add infrastructure for 'B' MISA extension
Add the infrastructure for the 'B' extension which is the union of the Zba, Zbb and Zbs instructions.
--- target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)
target/riscv/cpu.c +3 -2
@@ -38,9 +38,9 @@#include "tcg/tcg.h" /* RISC-V CPU definitions */ -static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;const uint32_t misa_bits[] = {RVI ,RVE ,RVM ,RVA ,RVF ,RVD ,RVV , -RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,0 }; +RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,RVB ,0 };/* * From vector_helper.c
@@ -1251,6 +1251,7 @@ static const MISAExtInfo misa_ext_info_arr[] = {MISA_EXT_INFO (RVJ ,"x-j" ,"Dynamic translated languages" ),MISA_EXT_INFO (RVV ,"v" ,"Vector operations" ),MISA_EXT_INFO (RVG ,"g" ,"General purpose (IMAFD_Zicsr_Zifencei)" ), + MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") };static int riscv_validate_misa_info_idx (uint32_t bit)
target/riscv/cpu.h +1 -0
@@ -69,6 +69,7 @@ typedef struct CPUArchState CPURISCVState;#define RVH RV('H')#define RVJ RV('J')#define RVG RV('G') +#define RVB RV('B')extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);
target/riscv/tcg/tcg-cpu.c +1 -0
@@ -791,6 +791,7 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {MISA_CFG (RVJ , false),MISA_CFG (RVV , false),MISA_CFG (RVG , false), + MISA_CFG(RVB, false) };/*
Signature · 1 line
2.43.0
Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
Quoted 51 lines · Rob Bradford
Add the infrastructure for the 'B' extension which is the union of the Zba, Zbb and Zbs instructions.
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)target/riscv/cpu.c +3
-2@@ -38,9 +38,9 @@#include "tcg/tcg.h" /* RISC-V CPU definitions */ -static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;const uint32_t misa_bits[] = {RVI ,RVE ,RVM ,RVA ,RVF ,RVD ,RVV , -RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,0 }; +RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,RVB ,0 };/* * From vector_helper.c @@ -1251,6 +1251,7 @@ static const MISAExtInfo misa_ext_info_arr[] = {MISA_EXT_INFO (RVJ ,"x-j" ,"Dynamic translated languages" ),MISA_EXT_INFO (RVV ,"v" ,"Vector operations" ),MISA_EXT_INFO (RVG ,"g" ,"General purpose (IMAFD_Zicsr_Zifencei)" ), + MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") };static int riscv_validate_misa_info_idx (uint32_t bit)target/riscv/cpu.h +1
-0@@ -69,6 +69,7 @@ typedef struct CPUArchState CPURISCVState;#define RVH RV('H')#define RVJ RV('J')#define RVG RV('G') +#define RVB RV('B')extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);target/riscv/tcg/tcg-cpu.c +0
-0
target/riscv/tcg/tcg-cpu.c static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { · line 794
Quoted 4 lines
target/riscv/tcg/tcg-cpu.c +1
-0@@ -791,6 +791,7 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {MISA_CFG (RVJ , false),MISA_CFG (RVV , false),MISA_CFG (RVG , false), +MISA_CFG (RVB , false)
Please add a comma at the end:
target/riscv/tcg/tcg-cpu.c static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { · line 795
Quoted 1 line
target/riscv/tcg/tcg-cpu.c +1
-0+ MISA_CFG(RVB, false),
This way, when a new bit is added, the change is limited to the new entry.
With this nit fixed:
Quoted 3 lines
target/riscv/tcg/tcg-cpu.c +0
-0};/*
Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
In reply to Rob BradfordQuoted 15 lines · Rob Bradford
Add the infrastructure for the 'B' extension which is the union of the Zba, Zbb and Zbs instructions.
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)target/riscv/cpu.c +0
-0
target/riscv/cpu.c line 41
Quoted 5 lines
target/riscv/cpu.c +1
-1@@ -38,9 +38,9 @@#include "tcg/tcg.h" /* RISC-V CPU definitions */ -static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;
Is there a corresponding proposed change to table 29.1 of the nonpriv spec which states B comes after C and before P? If so, can you provide a link to it? Otherwise, how do we know that?
Thanks,
drew
Quoted 42 lines
target/riscv/cpu.c +2
-1const uint32_t misa_bits[] = {RVI ,RVE ,RVM ,RVA ,RVF ,RVD ,RVV , -RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,0 }; +RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,RVB ,0 };/* * From vector_helper.c @@ -1251,6 +1251,7 @@ static const MISAExtInfo misa_ext_info_arr[] = {MISA_EXT_INFO (RVJ ,"x-j" ,"Dynamic translated languages" ),MISA_EXT_INFO (RVV ,"v" ,"Vector operations" ),MISA_EXT_INFO (RVG ,"g" ,"General purpose (IMAFD_Zicsr_Zifencei)" ), + MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") };static int riscv_validate_misa_info_idx (uint32_t bit)target/riscv/cpu.h +1
-0@@ -69,6 +69,7 @@ typedef struct CPUArchState CPURISCVState;#define RVH RV('H')#define RVJ RV('J')#define RVG RV('G') +#define RVB RV('B')extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);target/riscv/tcg/tcg-cpu.c +1
-0@@ -791,6 +791,7 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {MISA_CFG (RVJ , false),MISA_CFG (RVV , false),MISA_CFG (RVG , false), + MISA_CFG(RVB, false) };/* Signature · 1 line
2.43.0
Re: Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
Quoted 18 lines · Andrew Jones
Quoted 17 lines · Rob Bradford
Add the infrastructure for the 'B' extension which is the union of the Zba, Zbb and Zbs instructions.
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)target/riscv/cpu.c +0
-0@@ -38,9 +38,9 @@#include "tcg/tcg.h"
Quoted 7 lines
target/riscv/cpu.c line 41
Quoted 3 lines
target/riscv/cpu.c +1
-1/* RISC-V CPU definitions */ -static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;Is there a corresponding proposed change to table 29.1 of the nonpriv spec which states B comes after C and before P? If so, can you provide a link to it? Otherwise, how do we know that?
Oh, I see. The unpriv spec B chapter comes after the C chapter (and before J, P, ...). I still wonder if we'll have a 29.1 table update with the ratification of this extension though.
Thanks,
drew
Re: Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
+ Ved
Quoted 30 lines · Andrew Jones
Quoted 12 lines · Andrew Jones
Quoted 11 lines · Rob Bradford
Add the infrastructure for the 'B' extension which is the union of the
Zba, Zbb and Zbs instructions.Signed-off-by Rob Bradford <[email protected]>---
target/riscv/cpu.c | 5 +++--
target/riscv/cpu.h | 1 +
target/riscv/tcg/tcg-cpu.c | 1 +3 files changed, 5 insertions(+), 2 deletions(-)Quoted 16 lines
target/riscv/cpu.c line 41
Quoted 10 lines
target/riscv/cpu.c +0
-0@@ -38,9 +38,9 @@ #include "tcg/tcg.h"
/* RISC-V CPU definitions */target/riscv/cpu.c +1
-1-static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;Is there a corresponding proposed change to table 29.1 of the nonpriv spec
which states B comes after C and before P? If so, can you provide a link
to it? Otherwise, how do we know that?
Quoted 6 lines
Oh, I see. The unpriv spec B chapter comes after the C chapter (and before
J, P, ...). I still wonder if we'll have a 29.1 table update with the ratification of this extension though.
I agree it's a bit confusing - but the order is established by the table in the unprivileged spec and the table explanation also makes this clear.
"""
Table 27.1: Standard ISA extension names. The table also defines the canonical order in which
extension names must appear in the name string, with top-to-bottom in table indicating first-to-last
in the name string, e.g., RV32IMACV is legal, whereas RV32IMAVC is not. """
The proposed B specification does not make any remarks about the ordering in the ISA definition string. [1] I would worry there would be a lot of software churn if this ordering were to be changed.
Cheers,
Rob
Quoted 2 lines
Thanks,
drew
Re: Re: Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
Quoted 44 lines · Rob Bradford
+ Ved
Quoted 30 lines · Andrew Jones
Quoted 12 lines · Andrew Jones
Quoted 11 lines · Rob Bradford
Add the infrastructure for the 'B' extension which is the union of the
Zba, Zbb and Zbs instructions.Signed-off-by Rob Bradford <[email protected]>---
target/riscv/cpu.c | 5 +++--
target/riscv/cpu.h | 1 +
target/riscv/tcg/tcg-cpu.c | 1 +3 files changed, 5 insertions(+), 2 deletions(-)Quoted 16 lines
target/riscv/cpu.c line 41
Quoted 10 lines
target/riscv/cpu.c +0
-0@@ -38,9 +38,9 @@ #include "tcg/tcg.h"
/* RISC-V CPU definitions */target/riscv/cpu.c +1
-1-static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;Is there a corresponding proposed change to table 29.1 of the nonpriv spec
which states B comes after C and before P? If so, can you provide a link
to it? Otherwise, how do we know that?Quoted 6 lines
Oh, I see. The unpriv spec B chapter comes after the C chapter (and before
J, P, ...). I still wonder if we'll have a 29.1 table update with the ratification of this extension though.I agree it's a bit confusing - but the order is established by the table in the unprivileged spec and the table explanation also makes this clear.
Quoted 7 lines
"""
Table 27.1: Standard ISA extension names. The table also defines the canonical order in which
extension names must appear in the name string, with top-to-bottom in table indicating first-to-last
in the name string, e.g., RV32IMACV is legal, whereas RV32IMAVC is not. """
Yes, this is the table I was referring to when I referenced "table 29.1 of the nonpriv spec". Since there's a chance I was looking at too old a spec I've now gone straight to the source,
https://github.com/riscv/riscv-isa-manual/blob/main/src/naming.adoc
but I still don't see B there. Do you see B in the table you're looking at?
Quoted 4 lines
The proposed B specification does not make any remarks about the ordering in the ISA definition string. [1] I would worry there would be a lot of software churn if this ordering were to be changed.
The ordering shouldn't change, but I can't see where it's documented (beyond the B chapter coming after the C chapter).
Thanks,
drew
Re: Re: Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
Quoted 75 lines · Andrew Jones
Quoted 50 lines · Rob Bradford
+ Ved
Quoted 34 lines · Andrew Jones
Quoted 24 lines · Andrew Jones
Quoted 23 lines · Rob Bradford
Add the infrastructure for the 'B' extension which is the union
of the
Zba, Zbb and Zbs instructions.Signed-off-by Rob Bradford <[email protected]>---
target/riscv/cpu.c | 5 +++--
target/riscv/cpu.h | 1 +
target/riscv/tcg/tcg-cpu.c | 1 +3 files changed, 5 insertions(+), 2 deletions(-)target/riscv/cpu.c +0
-0@@ -38,9 +38,9 @@ #include "tcg/tcg.h"
/* RISC-V CPU definitions */
-static const char riscv_single_letter_exts[] =
"IEMAFDQCPVH";
+static const char riscv_single_letter_exts[] =Quoted 8 lines
Quoted 1 line
"IEMAFDQCBPVH";
Is there a corresponding proposed change to table 29.1 of the nonpriv spec
which states B comes after C and before P? If so, can you provide a
link
to it? Otherwise, how do we know that?Quoted 8 lines
Oh, I see. The unpriv spec B chapter comes after the C chapter (and
before
J, P, ...). I still wonder if we'll have a 29.1 table update with the
ratification of this extension though.I agree it's a bit confusing - but the order is established by the table in the unprivileged spec and the table explanation also makes this clear.
Quoted 10 lines
"""
Table 27.1: Standard ISA extension names. The table also defines the
canonical order in which
extension names must appear in the name string, with top-to-bottom in
table indicating first-to-last
in the name string, e.g., RV32IMACV is legal, whereas RV32IMAVC is not.
"""Yes, this is the table I was referring to when I referenced "table 29.1 of
the nonpriv spec". Since there's a chance I was looking at too old a spec
I've now gone straight to the source,https://github.com/riscv/riscv-isa-manual/blob/main/src/naming.adoc
but I still don't see B there. Do you see B in the table you're looking
at?Quoted 1 line
Quoted 7 lines
Quoted 4 lines
The proposed B specification does not make any remarks about the ordering in the ISA definition string. [1] I would worry there would be
a lot of software churn if this ordering were to be changed.The ordering shouldn't change, but I can't see where it's documented (beyond the B chapter coming after the C chapter).
I'm using table 27.1 in the published PDF which is the PDF in this release:
https://github.com/riscv/riscv-isa-manual/releases/tag/Ratified-IMAFDQC
It looks like it was removed in this commit (which is a set of backports):
https://github.com/riscv/riscv-isa-manual/commit/6ecd735338241583d53396b7065eab7c9ace68aa
Cheers,
Rob
Quoted 3 lines
Thanks,
drew
Re: Re: Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
Quoted 6 lines · Rob Bradford
I'm using table 27.1 in the published PDF which is the PDF in this release:
https://github.com/riscv/riscv-isa-manual/releases/tag/Ratified-IMAFDQC
It looks like it was removed in this commit (which is a set of backports):
We would retain the previously documented canonical order with B between C and P and that table updated on ratification.
regards
ved
Re: [PATCH 1/3] target/riscv: Add infrastructure for 'B' MISA extension
In reply to Rob BradfordQuoted 62 lines · Rob Bradford
Add the infrastructure for the 'B' extension which is the union of the Zba, Zbb and Zbs instructions.
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 1 + 3 files changed, 5 insertions(+), 2 deletions(-)target/riscv/cpu.c +3
-2@@ -38,9 +38,9 @@#include "tcg/tcg.h" /* RISC-V CPU definitions */ -static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ; +static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;const uint32_t misa_bits[] = {RVI ,RVE ,RVM ,RVA ,RVF ,RVD ,RVV , -RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,0 }; +RVC ,RVS ,RVU ,RVH ,RVJ ,RVG ,RVB ,0 };/* * From vector_helper.c @@ -1251,6 +1251,7 @@ static const MISAExtInfo misa_ext_info_arr[] = {MISA_EXT_INFO (RVJ ,"x-j" ,"Dynamic translated languages" ),MISA_EXT_INFO (RVV ,"v" ,"Vector operations" ),MISA_EXT_INFO (RVG ,"g" ,"General purpose (IMAFD_Zicsr_Zifencei)" ), + MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") };static int riscv_validate_misa_info_idx (uint32_t bit)target/riscv/cpu.h +1
-0@@ -69,6 +69,7 @@ typedef struct CPUArchState CPURISCVState;#define RVH RV('H')#define RVJ RV('J')#define RVG RV('G') +#define RVB RV('B')extern const uint32_t misa_bits[];const char *riscv_get_misa_ext_name (uint32_t bit);target/riscv/tcg/tcg-cpu.c +1
-0@@ -791,6 +791,7 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {MISA_CFG (RVJ , false),MISA_CFG (RVV , false),MISA_CFG (RVG , false), + MISA_CFG(RVB, false) };/* Signature · 1 line
2.43.0
PATCH 2/3 target/riscv: Add step to validate 'B' extension
In reply to Rob BradfordIf the B extension is enabled warn if the user has disabled any of the required extensions that are part of the 'B' extension. Conversely enable the extensions that make up the 'B' extension if it is enabled.
--- target/riscv/tcg/tcg-cpu.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
target/riscv/tcg/tcg-cpu.c +33 -0
@@ -273,6 +273,35 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) } } +static void riscv_cpu_validate_b (RISCVCPU *cpu) +{ +const char *warn_msg ="RVB mandates disabled extension %s" ; + +if (!cpu->cfg.ext_zba) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zba))) { + cpu->cfg.ext_zba = true; + }else { +warn_report (warn_msg,"zba" ); + } + } + +if (!cpu->cfg.ext_zbb) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zbb))) { + cpu->cfg.ext_zbb = true; + }else { +warn_report (warn_msg,"zbb" ); + } + } + +if (!cpu->cfg.ext_zbs) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zbs))) { + cpu->cfg.ext_zbs = true; + }else { +warn_report (warn_msg,"zbs" ); + } + } +} +/* * Check consistency between chosen extensions while setting * cpu->cfg accordingly.
@@ -309,6 +338,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) env->misa_ext_mask |=RVI |RVM |RVA |RVF |RVD ; } +if (riscv_has_ext (env,RVB )) { +riscv_cpu_validate_b (cpu); + } +if (riscv_has_ext (env,RVI ) &&riscv_has_ext (env,RVE )) {error_setg (errp,"I and E extensions are incompatible" );
Signature · 1 line
2.43.0
Re: [PATCH 2/3] target/riscv: Add step to validate 'B' extension
Quoted 6 lines · Rob Bradford
If the B extension is enabled warn if the user has disabled any of the required extensions that are part of the 'B' extension. Conversely enable the extensions that make up the 'B' extension if it is enabled.
Signed-off-by Rob Bradford <[email protected]>---
This patch doesn't apply cleanly on current master. Which is normal, since we just had a RISC-V PR merged.
I'm afraid you'll need to resend the series rebased on top of master (since it's newer than Alistair's riscv-to-apply.next now).
Quoted 3 lines
target/riscv/tcg/tcg-cpu.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
I fixed the conflicts and applied the patch and it works for me. So:
Quoted 51 lines
target/riscv/tcg/tcg-cpu.c +33
-0@@ -273,6 +273,35 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) } } +static void riscv_cpu_validate_b (RISCVCPU *cpu) +{ +const char *warn_msg ="RVB mandates disabled extension %s" ; + +if (!cpu->cfg.ext_zba) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zba))) { + cpu->cfg.ext_zba = true; + }else { +warn_report (warn_msg,"zba" ); + } + } + +if (!cpu->cfg.ext_zbb) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zbb))) { + cpu->cfg.ext_zbb = true; + }else { +warn_report (warn_msg,"zbb" ); + } + } + +if (!cpu->cfg.ext_zbs) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zbs))) { + cpu->cfg.ext_zbs = true; + }else { +warn_report (warn_msg,"zbs" ); + } + } +} +/* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -309,6 +338,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) env->misa_ext_mask |=RVI |RVM |RVA |RVF |RVD ; } +if (riscv_has_ext (env,RVB )) { +riscv_cpu_validate_b (cpu); + } +if (riscv_has_ext (env,RVI ) &&riscv_has_ext (env,RVE )) {error_setg (errp,"I and E extensions are incompatible" );
Re: [PATCH 2/3] target/riscv: Add step to validate 'B' extension
In reply to Rob BradfordQuoted 64 lines · Rob Bradford
If the B extension is enabled warn if the user has disabled any of the required extensions that are part of the 'B' extension. Conversely enable the extensions that make up the 'B' extension if it is enabled.
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/tcg/tcg-cpu.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)target/riscv/tcg/tcg-cpu.c +33
-0@@ -273,6 +273,35 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) } } +static void riscv_cpu_validate_b (RISCVCPU *cpu) +{ +const char *warn_msg ="RVB mandates disabled extension %s" ; + +if (!cpu->cfg.ext_zba) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zba))) { + cpu->cfg.ext_zba = true; + }else { +warn_report (warn_msg,"zba" ); + } + } + +if (!cpu->cfg.ext_zbb) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zbb))) { + cpu->cfg.ext_zbb = true; + }else { +warn_report (warn_msg,"zbb" ); + } + } + +if (!cpu->cfg.ext_zbs) { +if (!cpu_cfg_ext_is_user_set (CPU_CFG_OFFSET (ext_zbs))) { + cpu->cfg.ext_zbs = true; + }else { +warn_report (warn_msg,"zbs" ); + } + } +} +/* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -309,6 +338,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) env->misa_ext_mask |=RVI |RVM |RVA |RVF |RVD ; } +if (riscv_has_ext (env,RVB )) { +riscv_cpu_validate_b (cpu); + } +if (riscv_has_ext (env,RVI ) &&riscv_has_ext (env,RVE )) {error_setg (errp,"I and E extensions are incompatible" );Signature · 1 line
2.43.0
PATCH 3/3 target/riscv: Enable 'B' extension on max CPU type
In reply to Rob Bradford--- target/riscv/tcg/tcg-cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/tcg/tcg-cpu.c +2 -1
@@ -999,7 +999,8 @@ static void riscv_init_max_cpu_extensions(Object *obj)const RISCVCPUMultiExtConfig *prop;/* Enable RVG, RVJ and RVV that are disabled by default */ -riscv_cpu_set_misa (env, env->misa_mxl, env->misa_ext |RVG |RVJ |RVV ); +riscv_cpu_set_misa (env, env->misa_mxl, + env->misa_ext |RVG |RVJ |RVV |RVB );for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {isa_ext_update_enabled (cpu, prop->offset, true);
Signature · 1 line
2.43.0
Re: [PATCH 3/3] target/riscv: Enable 'B' extension on max CPU type
Quoted 10 lines · Rob Bradford
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/tcg/tcg-cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/riscv/tcg/tcg-cpu.c +0
-0
target/riscv/tcg/tcg-cpu.c static void riscv_init_max_cpu_extensions(Object *obj) · line 1003
Quoted 6 lines
target/riscv/tcg/tcg-cpu.c +2
-1@@ -999,7 +999,8 @@ static void riscv_init_max_cpu_extensions(Object *obj)const RISCVCPUMultiExtConfig *prop;/* Enable RVG, RVJ and RVV that are disabled by default */ -riscv_cpu_set_misa (env, env->misa_mxl, env->misa_ext |RVG |RVJ |RVV ); +riscv_cpu_set_misa (env, env->misa_mxl, + env->misa_ext |RVG |RVJ |RVV |RVB );
I'm aware that we decided a while ago the 'max' CPU could only have non-vendor and non-experimental extensions enabled. RVB is experimental, so in theory we shouldn't enable it.
But RVB is an alias for zba, zbb and zbs, extensions that the 'max' CPU is already enabling. In this case I think it's sensible to enable RVB here since it would just reflect stuff that it's already happening.
Quoted 3 lines
target/riscv/tcg/tcg-cpu.c +0
-0for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {isa_ext_update_enabled (cpu, prop->offset, true);
Re: [PATCH 3/3] target/riscv: Enable 'B' extension on max CPU type
Rob,
Given that you'll need to resend the patches due to the conflict in patch 2, I think it would be nice to mention in this commit message that we're ok with enabling RVB in the 'max' CPU, even though RVB per se is experimental, because it's just an alias for extensions that the CPU already uses.
I'm asking this because future Daniel will forget why we're adding an experimental extension in the 'max' CPU, and this info in the commit msg will spare him from searching the ML archives to discover why :)
Thanks,
Daniel
Quoted 35 lines · Daniel Henrique Barboza
Quoted 10 lines · Rob Bradford
Signed-off-by Rob Bradford <[email protected]>---
target/riscv/tcg/tcg-cpu.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)target/riscv/tcg/tcg-cpu.c +0
-0target/riscv/tcg/tcg-cpu.c static void riscv_init_max_cpu_extensions(Object *obj) · line 1002
Quoted 5 lines
target/riscv/tcg/tcg-cpu.c +2
-1@@ -999,7 +999,8 @@ static void riscv_init_max_cpu_extensions(Object *obj) const RISCVCPUMultiExtConfig *prop; /* Enable RVG, RVJ and RVV that are disabled by default */ - riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); + riscv_cpu_set_misa(env, env->misa_mxl, + env->misa_ext | RVG | RVJ | RVV | RVB);I'm aware that we decided a while ago the 'max' CPU could only have non-vendor and non-experimental extensions enabled. RVB is experimental, so in theory we shouldn't enable it.
But RVB is an alias for zba, zbb and zbs, extensions that the 'max' CPU is already enabling. In this case I think it's sensible to enable RVB here since it would just reflect stuff that it's already happening.
Reviewed-by Daniel Henrique Barboza <[email protected]>Quoted 2 lines
target/riscv/tcg/tcg-cpu.c +0
-0for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { isa_ext_update_enabled(cpu, prop->offset, true);
Re: Re: [PATCH 3/3] target/riscv: Enable 'B' extension on max CPU type
In reply to Daniel Henrique BarbozaQuoted 23 lines · Daniel Henrique Barboza
Quoted 10 lines · Rob Bradford
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/tcg/tcg-cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/riscv/tcg/tcg-cpu.c +0
-0target/riscv/tcg/tcg-cpu.c static void riscv_init_max_cpu_extensions(Object *obj) · line 1002
Quoted 5 lines
target/riscv/tcg/tcg-cpu.c +2
-1@@ -999,7 +999,8 @@ static void riscv_init_max_cpu_extensions(Object *obj)const RISCVCPUMultiExtConfig *prop;/* Enable RVG, RVJ and RVV that are disabled by default */ -riscv_cpu_set_misa (env, env->misa_mxl, env->misa_ext |RVG |RVJ |RVV ); +riscv_cpu_set_misa (env, env->misa_mxl, + env->misa_ext |RVG |RVJ |RVV |RVB );I'm aware that we decided a while ago the 'max' CPU could only have non-vendor and non-experimental extensions enabled. RVB is experimental, so in theory we shouldn't enable it.
Quoted 3 lines
But RVB is an alias for zba, zbb and zbs, extensions that the 'max' CPU is already enabling. In this case I think it's sensible to enable RVB here since it would just reflect stuff that it's already happening.
It's also setting the B bit in misa, which, until this spec is at least frozen, is a reserved bit and reserved bits "must return zero when read".
I don't want to stand in the way of progress and it seems 99.9% likely that the spec will be frozen and ratified, but, if we want to stick to our policies (which we should document), then even the 'max' cpu type should require x-b be added to the command line if it wants the B bit set in misa.
Thanks,
drew
Re: [PATCH 3/3] target/riscv: Enable 'B' extension on max CPU type
Quoted 24 lines · Andrew Jones
Quoted 23 lines · Daniel Henrique Barboza
Quoted 10 lines · Rob Bradford
Signed-off-by Rob Bradford <[email protected]>--- target/riscv/tcg/tcg-cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/riscv/tcg/tcg-cpu.c +0
-0target/riscv/tcg/tcg-cpu.c static void riscv_init_max_cpu_extensions(Object *obj) · line 1002
Quoted 5 lines
target/riscv/tcg/tcg-cpu.c +2
-1@@ -999,7 +999,8 @@ static void riscv_init_max_cpu_extensions(Object *obj)const RISCVCPUMultiExtConfig *prop;/* Enable RVG, RVJ and RVV that are disabled by default */ -riscv_cpu_set_misa (env, env->misa_mxl, env->misa_ext |RVG |RVJ |RVV ); +riscv_cpu_set_misa (env, env->misa_mxl, + env->misa_ext |RVG |RVJ |RVV |RVB );I'm aware that we decided a while ago the 'max' CPU could only have non-vendor and non-experimental extensions enabled. RVB is experimental, so in theory we shouldn't enable it.
Quoted 6 lines
Quoted 3 lines
But RVB is an alias for zba, zbb and zbs, extensions that the 'max' CPU is already enabling. In this case I think it's sensible to enable RVB here since it would just reflect stuff that it's already happening.
It's also setting the B bit in misa, which, until this spec is at least frozen, is a reserved bit and reserved bits "must return zero when read".
This is a side effect that I wasn't aware of.
Rob, given that the 'max' CPU already has the zb* extensions enabled, is there any other gain in enabling RVB in this CPU? If there isn't I'd rather leave this one out for now.
Thanks,
Daniel
Quoted 9 lines
I don't want to stand in the way of progress and it seems 99.9% likely that the spec will be frozen and ratified, but, if we want to stick to our policies (which we should document), then even the 'max' cpu type should require x-b be added to the command line if it wants the B bit set in misa.
Thanks,
drew
Re: [PATCH 3/3] target/riscv: Enable 'B' extension on max CPU type
Quoted 47 lines · Daniel Henrique Barboza
Quoted 39 lines · Andrew Jones
Quoted 29 lines · Daniel Henrique Barboza
Quoted 11 lines · Rob Bradford
Signed-off-by Rob Bradford <[email protected]>---
target/riscv/tcg/tcg-cpu.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)target/riscv/tcg/tcg- renamed from target/riscv/tcg/tcg-cpu.c +0
-0
cpu.c
indexf10871d352..9705daec93100644target/riscv/tcg/tcg-cpu.c static void · line 1005
Quoted 8 lines
target/riscv/tcg/tcg-cpu.c +2
-1@@ -999,7 +999,8 @@ static void riscv_init_max_cpu_extensions(Object *obj) const RISCVCPUMultiExtConfig *prop; /* Enable RVG, RVJ and RVV that are disabled by default */ - riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); + riscv_cpu_set_misa(env, env->misa_mxl, + env->misa_ext | RVG | RVJ | RVV | RVB);I'm aware that we decided a while ago the 'max' CPU could only have non-vendor and
non-experimental extensions enabled. RVB is experimental, so in theory we shouldn't
enable it.Quoted 7 lines
But RVB is an alias for zba, zbb and zbs, extensions that the 'max' CPU is already
enabling. In this case I think it's sensible to enable RVB here since it would
just
reflect stuff that it's already happening.Quoted 4 lines
It's also setting the B bit in misa, which, until this spec is at least
frozen, is a reserved bit and reserved bits "must return zero when read".
Quoted 8 lines
This is a side effect that I wasn't aware of.
Rob, given that the 'max' CPU already has the zb* extensions enabled, is there any
other gain in enabling RVB in this CPU? If there isn't I'd rather leave this one
out for now.
It seems completely reasonable to me to drop it for now.
Thanks for all the feedback,
Rob
Quoted 19 lines
Thanks,
Daniel
Quoted 13 lines
I don't want to stand in the way of progress and it seems 99.9% likely
that the spec will be frozen and ratified, but, if we want to stick to
our policies (which we should document), then even the 'max' cpu type
should require x-b be added to the command line if it wants the B bit
set in misa.Thanks,
drew