target/riscv: Add support for 'B' extension
v2 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.
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.
Cheers,
Rob
[1] - https://github.com/riscv/riscv-b
Changes since V1:
- Rebased on master after latest riscv updates
- All patches have R-B tags
- Array formatting fix to make future diffs clean (Daniel)
- Dropped enabling for max CPU variant as misa.B is reserved until spec is at least frozen (Daniel & Drew)
Rob Bradford (2):
target/riscv: Add infrastructure for 'B' MISA extension target/riscv: Add step to validate 'B' extension
target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 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
@@ -1299,6 +1299,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
@@ -1056,6 +1056,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 v2 1/2] target/riscv: Add infrastructure for 'B' MISA extension
Quoted 7 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]>Reviewed-by Daniel Henrique Barboza <[email protected]>Reviewed-by Andrew Jones <[email protected]>
Alistair
Quoted 58 lines
--- 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 @@ -1299,6 +1299,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
-1@@ -1056,6 +1056,7 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {MISA_CFG (RVJ , false),MISA_CFG (RVV , false),MISA_CFG (RVG , false), + MISA_CFG(RVB, false), };/* -- 2.43.0
PATCH v2 2/2 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
@@ -442,6 +442,35 @@ static void riscv_cpu_validate_g(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.
@@ -455,6 +484,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)riscv_cpu_validate_g (cpu); } +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 v2 2/2] target/riscv: Add step to validate 'B' extension
Quoted 8 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]>Reviewed-by Daniel Henrique Barboza <[email protected]>Reviewed-by Andrew Jones <[email protected]>
Alistair
Quoted 59 lines
--- target/riscv/tcg/tcg-cpu.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)target/riscv/tcg/tcg-cpu.c +33
-1@@ -442,6 +442,35 @@ static void riscv_cpu_validate_g(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. @@ -455,6 +484,10 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)riscv_cpu_validate_g (cpu); } +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" ); --2.43.0
Alistair Francis
AppliedQuoted 28 lines · Rob Bradford
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.
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.
Cheers,
Rob
[1] - https://github.com/riscv/riscv-b
Changes since V1:
- Rebased on master after latest riscv updates
- All patches have R-B tags
- Array formatting fix to make future diffs clean (Daniel)
- Dropped enabling for max CPU variant as misa.B is reserved until spec is at least frozen (Daniel & Drew)
Quoted 3 lines
Rob Bradford (2):
target/riscv: Add infrastructure for 'B' MISA extension target/riscv: Add step to validate 'B' extension
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 10 lines
target/riscv/cpu.c | 5 +++-- target/riscv/cpu.h | 1 + target/riscv/tcg/tcg-cpu.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-)--
2.43.0