target/riscv: Add Zilsd and Zclsd extension support
v9 cover target/riscv: Add Zilsd and Zclsd extension support
Thanks for Alistair's correction on the V8 version.
Now Zclsd has been disabled for the "max" CPU as C and F are already enabled.
lxx (1):
target/riscv: Add Zilsd and Zclsd extension support
target/riscv/cpu.c | 4 + target/riscv/cpu_cfg_fields.h.inc | 2 + target/riscv/insn16.decode | 8 ++ target/riscv/insn32.decode | 12 ++- target/riscv/insn_trans/trans_zilsd.c.inc | 112 ++++++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 32 +++++++ target/riscv/translate.c | 1 + 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 target/riscv/insn_trans/trans_zilsd.c.inc
Signature · 1 line
2.45.3
PATCH v9 1/1 target/riscv: Add Zilsd and Zclsd extension support
From: lxx <[email protected]>
This patch adds support for the Zilsd and Zclsd extension,
which is documented at https://github.com/riscv/riscv-zilsd/releases/tag/v1.0
--- target/riscv/cpu.c | 4 + target/riscv/cpu_cfg_fields.h.inc | 2 + target/riscv/insn16.decode | 8 ++ target/riscv/insn32.decode | 12 ++- target/riscv/insn_trans/trans_zilsd.c.inc | 112 ++++++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 32 +++++++ target/riscv/translate.c | 1 + 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 target/riscv/insn_trans/trans_zilsd.c.inc
target/riscv/cpu.c +4 -0
@@ -121,6 +121,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zihintntl,PRIV_VERSION_1_10_0 , ext_zihintntl),ISA_EXT_DATA_ENTRY (zihintpause,PRIV_VERSION_1_10_0 , ext_zihintpause),ISA_EXT_DATA_ENTRY (zihpm,PRIV_VERSION_1_12_0 , ext_zihpm), +ISA_EXT_DATA_ENTRY (zilsd,PRIV_VERSION_1_12_0 , ext_zilsd),ISA_EXT_DATA_ENTRY (zimop,PRIV_VERSION_1_13_0 , ext_zimop),ISA_EXT_DATA_ENTRY (zmmul,PRIV_VERSION_1_12_0 , ext_zmmul), ISA_EXT_DATA_ENTRY(za64rs, PRIV_VERSION_1_12_0, has_priv_1_12),
@@ -144,6 +145,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zcmop,PRIV_VERSION_1_13_0 , ext_zcmop),ISA_EXT_DATA_ENTRY (zcmp,PRIV_VERSION_1_12_0 , ext_zcmp),ISA_EXT_DATA_ENTRY (zcmt,PRIV_VERSION_1_12_0 , ext_zcmt), +ISA_EXT_DATA_ENTRY (zclsd,PRIV_VERSION_1_12_0 , ext_zclsd),ISA_EXT_DATA_ENTRY (zba,PRIV_VERSION_1_12_0 , ext_zba),ISA_EXT_DATA_ENTRY (zbb,PRIV_VERSION_1_12_0 , ext_zbb), ISA_EXT_DATA_ENTRY(zbc, PRIV_VERSION_1_12_0, ext_zbc),
@@ -1289,6 +1291,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {MULTI_EXT_CFG_BOOL ("zicntr" , ext_zicntr, true),MULTI_EXT_CFG_BOOL ("zihpm" , ext_zihpm, true), +MULTI_EXT_CFG_BOOL ("zilsd" , ext_zilsd, false),MULTI_EXT_CFG_BOOL ("zba" , ext_zba, true), MULTI_EXT_CFG_BOOL("zbb", ext_zbb, true),
@@ -1328,6 +1331,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {MULTI_EXT_CFG_BOOL ("zcmp" , ext_zcmp, false),MULTI_EXT_CFG_BOOL ("zcmt" , ext_zcmt, false),MULTI_EXT_CFG_BOOL ("zicond" , ext_zicond, false), +MULTI_EXT_CFG_BOOL ("zclsd" , ext_zclsd, false),/* Vector cryptography extensions */ MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false),
target/riscv/cpu_cfg_fields.h.inc +2 -0
@@ -19,6 +19,7 @@ BOOL_FIELD(ext_zce) BOOL_FIELD(ext_zcf) BOOL_FIELD(ext_zcmp) BOOL_FIELD(ext_zcmt) +BOOL_FIELD(ext_zclsd) BOOL_FIELD(ext_zk) BOOL_FIELD(ext_zkn) BOOL_FIELD(ext_zknd)
@@ -41,6 +42,7 @@ BOOL_FIELD(ext_zicond) BOOL_FIELD(ext_zihintntl) BOOL_FIELD(ext_zihintpause) BOOL_FIELD(ext_zihpm) +BOOL_FIELD(ext_zilsd) BOOL_FIELD(ext_zimop) BOOL_FIELD(ext_zcmop) BOOL_FIELD(ext_ztso)
target/riscv/insn16.decode +8 -0
@@ -130,10 +130,14 @@ sw 110 ... ... .. ... 00 @cs_w { ld 011 ... ... .. ... 00 @cl_d c_flw 011 ... ... .. ... 00 @cl_w + # *** Zclsd Extension *** + zclsd_ld 011 ... ... .. ... 00 @cl_d } { sd 111 ... ... .. ... 00 @cs_d c_fsw 111 ... ... .. ... 00 @cs_w + # *** Zclsd Extension *** + zclsd_sd 111 ... ... .. ... 00 @cs_d } # *** RV32/64C Standard Extension (Quadrant 1) ***
@@ -212,10 +216,14 @@ sw 110 . ..... ..... 10 @c_swsp c64_illegal 011 - 00000 ----- 10 # c.ldsp, RES rd=0 ld 011 . ..... ..... 10 @c_ldsp c_flw 011 . ..... ..... 10 @c_lwsp + # *** Zclsd Extension *** + zclsd_ldsp 011 . ..... ..... 10 @c_ldsp } { sd 111 . ..... ..... 10 @c_sdsp c_fsw 111 . ..... ..... 10 @c_swsp + # *** Zclsd Extension *** + zclsd_sd 111 . ..... ..... 10 @c_sdsp } # *** RV64 and RV32 Zcb Extension ***
target/riscv/insn32.decode +10 -2
@@ -182,8 +182,16 @@ csrrci ............ ..... 111 ..... 1110011 @csr # *** RV64I Base Instruction Set (in addition to RV32I) *** lwu ............ ..... 110 ..... 0000011 @i -ld ............ ..... 011 ..... 0000011 @i -sd ....... ..... ..... 011 ..... 0100011 @s +{ + ld ............ ..... 011 ..... 0000011 @i + # *** Zilsd instructions *** + zilsd_ld ............ ..... 011 ..... 0000011 @i +} +{ + sd ....... ..... ..... 011 ..... 0100011 @s + # *** Zilsd instructions *** + zilsd_sd ....... ..... ..... 011 ..... 0100011 @s +} addiw ............ ..... 000 ..... 0011011 @i slliw 0000000 ..... ..... 001 ..... 0011011 @sh5 srliw 0000000 ..... ..... 101 ..... 0011011 @sh5
target/riscv/insn_trans/trans_zilsd.c.inc new file +112 -0
112 lines not on this page · raw message
target/riscv/tcg/tcg-cpu.c +32 -0
@@ -818,6 +818,19 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) cpu->pmu_avail_ctrs =0 ; } +if (cpu->cfg.ext_zclsd) { +if (riscv_has_ext (env,RVC ) &&riscv_has_ext (env,RVF )) { +error_setg (errp, +"Zclsd cannot be supported together with C and F extension" ); +return ; + } +if (cpu->cfg.ext_zcf) { +error_setg (errp, +"Zclsd cannot be supported together with Zcf extension" ); +return ; + } + } +if (cpu->cfg.ext_zicfilp && !cpu->cfg.ext_zicsr) {error_setg (errp,"zicfilp extension requires zicsr extension" );return ;
@@ -1075,6 +1088,20 @@ static void cpu_enable_zc_implied_rules(RISCVCPU *cpu) } } +static void cpu_enable_zilsd_implied_rules (RISCVCPU *cpu) +{ +CPURISCVState *env = &cpu->env; + +if (cpu->cfg.ext_zilsd &&riscv_has_ext (env,RVC )) { +cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zclsd), true); + } + +if (cpu->cfg.ext_zclsd) { +cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zca), true); +cpu_cfg_ext_auto_update (cpu,CPU_CFG_OFFSET (ext_zilsd), true); + } +} +static void riscv_cpu_enable_implied_rules (RISCVCPU *cpu) {RISCVCPUImpliedExtsRule *rule;
@@ -1083,6 +1110,9 @@ static void riscv_cpu_enable_implied_rules(RISCVCPU *cpu)/* Enable the implied extensions for Zc. */ cpu_enable_zc_implied_rules (cpu); +/* Enable the implied extensions for Zilsd. */ +cpu_enable_zilsd_implied_rules (cpu); +/* Enable the implied MISAs. */ for (i =0 ; (rule = riscv_misa_ext_implied_rules[i]); i++) {if (riscv_has_ext (&cpu->env, rule->ext)) {
@@ -1586,6 +1616,8 @@ static void riscv_init_max_cpu_extensions(Object *obj)isa_ext_update_enabled (cpu,CPU_CFG_OFFSET (ext_zcmp), false);isa_ext_update_enabled (cpu,CPU_CFG_OFFSET (ext_zcmt), false); +isa_ext_update_enabled (cpu,CPU_CFG_OFFSET (ext_zclsd), false); +if (env->misa_mxl !=MXL_RV32 ) {isa_ext_update_enabled (cpu,CPU_CFG_OFFSET (ext_zcf), false); }
target/riscv/translate.c +1 -0
@@ -1200,6 +1200,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)/* Include the auto-generated decoder for 16 bit insn */ #include "decode-insn16.c.inc" #include "insn_trans/trans_rvzce.c.inc" +#include "insn_trans/trans_zilsd.c.inc" #include "insn_trans/trans_rvzcmop.c.inc" #include "insn_trans/trans_rvzicfiss.c.inc"
Signature · 1 line
2.45.3
Alistair Francis
AppliedQuoted 8 lines · ~liuxu
Thanks for Alistair's correction on the V8 version.
Now Zclsd has been disabled for the "max" CPU as C and F are already enabled.
lxx (1):
target/riscv: Add Zilsd and Zclsd extension support
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 13 lines
target/riscv/cpu.c | 4 + target/riscv/cpu_cfg_fields.h.inc | 2 + target/riscv/insn16.decode | 8 ++ target/riscv/insn32.decode | 12 ++- target/riscv/insn_trans/trans_zilsd.c.inc | 112 ++++++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 32 +++++++ target/riscv/translate.c | 1 + 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 target/riscv/insn_trans/trans_zilsd.c.inc--
2.45.3
Quoted 5 lines · ~liuxu
Thanks for Alistair's correction on the V8 version.
Now Zclsd has been disabled for the "max" CPU as C and F are already enabled.
This is still broken with userspace mode:
``` qemu-riscv64: Zclsd cannot be supported together with C and F extension ```
Alistair
Quoted 16 lines
lxx (1):
target/riscv: Add Zilsd and Zclsd extension supporttarget/riscv/cpu.c | 4 + target/riscv/cpu_cfg_fields.h.inc | 2 + target/riscv/insn16.decode | 8 ++ target/riscv/insn32.decode | 12 ++- target/riscv/insn_trans/trans_zilsd.c.inc | 112 ++++++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 32 +++++++ target/riscv/translate.c | 1 + 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 target/riscv/insn_trans/trans_zilsd.c.inc--
2.45.3
Quoted 7 lines · ~liuxu
Quoted 5 lines
Thanks for Alistair's correction on the V8 version.
Now Zclsd has been disabled for the "max" CPU as C and F are already enabled.
Quoted 7 lines
This is still broken with userspace mode:
``` qemu-riscv64: Zclsd cannot be supported together with C and F extension ```Alistair
Could you please tell me the specific reproduction method? I have re-reviewed the code and tried the tests that come with qemu, but I still haven't figured out why the above error occurre.
Quoted 15 lines
Quoted 15 lines
lxx (1):
target/riscv: Add Zilsd and Zclsd extension supporttarget/riscv/cpu.c | 4 + target/riscv/cpu_cfg_fields.h.inc | 2 + target/riscv/insn16.decode | 8 ++ target/riscv/insn32.decode | 12 ++- target/riscv/insn_trans/trans_zilsd.c.inc | 112 ++++++++++++++++++++++ target/riscv/tcg/tcg-cpu.c | 32 +++++++ target/riscv/translate.c | 1 + 7 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 target/riscv/insn_trans/trans_zilsd.c.inc--
2.45.3