Smstateen FCSR
v5 cover Smstateen FCSR
Patch 4 and 5 of the smstateen series need to be re-submitted with changes described in the email below.
https://lists.nongnu.org/archive/html/qemu-riscv/2022-11/msg00155.html
Hence splitting the patch 4 of the original series into three and re-submitting along with the original patch 5.
Changes in v5:
- Ammend patch 1 commit message
- Add reviewed-by tag
Changes in v4:
- Drop patch 3
- Add reviewed-by tag
Changes in v3:
- Reuse TB_FLAGS.FS (instead of TB_FLAGS.HS_FS) for smstateen as HS_FS bits been removed.
- Remove fcsr check for zfh and zfhmin
Changes in v2:
- Improve patch 1 description
- Reuse TB_FLAGS.HS_FS for smstateen
- Convert smstateen_fcsr_check to function
- Add fcsr check for zdinx
Mayuresh Chitale (3):
target/riscv: smstateen check for fcsr
target/riscv: Reuse tb->flags.FS
target/riscv: smstateen knobs
target/riscv/cpu.c | 3 ++- target/riscv/cpu_helper.c | 6 ++++++ target/riscv/csr.c | 15 +++++++++++++++ target/riscv/insn_trans/trans_rvf.c.inc | 7 ++++--- 4 files changed, 27 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/3 target/riscv: smstateen check for fcsr
Implement the s/h/mstateen.fcsr bit as defined in the smstateen spec and check for it when accessing the fcsr register and its fields.
--- target/riscv/csr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
target/riscv/csr.c +15 -0
@@ -82,6 +82,10 @@ static RISCVException fs(CPURISCVState *env, int csrno) !riscv_cpu_cfg(env)->ext_zfinx) {return RISCV_EXCP_ILLEGAL_INST ; } + +if (!env->debugger && !riscv_cpu_fp_enabled (env)) { +return smstateen_acc_ok (env,0 ,SMSTATEEN0_FCSR ); + }#endif return RISCV_EXCP_NONE ; }
@@ -2100,6 +2104,9 @@ static RISCVException write_mstateen0(CPURISCVState *env, int csrno, target_ulong new_val) {uint64_t wr_mask =SMSTATEEN_STATEEN |SMSTATEEN0_HSENVCFG ; +if (!riscv_has_ext (env,RVF )) { + wr_mask |=SMSTATEEN0_FCSR ; + }return write_mstateen (env, csrno, wr_mask, new_val); }
@@ -2173,6 +2180,10 @@ static RISCVException write_hstateen0(CPURISCVState *env, int csrno, {uint64_t wr_mask =SMSTATEEN_STATEEN |SMSTATEEN0_HSENVCFG ; +if (!riscv_has_ext (env,RVF )) { + wr_mask |=SMSTATEEN0_FCSR ; + } +return write_hstateen (env, csrno, wr_mask, new_val); }
@@ -2259,6 +2270,10 @@ static RISCVException write_sstateen0(CPURISCVState *env, int csrno, {uint64_t wr_mask =SMSTATEEN_STATEEN |SMSTATEEN0_HSENVCFG ; +if (!riscv_has_ext (env,RVF )) { + wr_mask |=SMSTATEEN0_FCSR ; + } +return write_sstateen (env, csrno, wr_mask, new_val); }
Signature · 1 line
2.34.1
Re: [PATCH v5 1/3] target/riscv: smstateen check for fcsr
Quoted 6 lines · Mayuresh Chitale
Implement the s/h/mstateen.fcsr bit as defined in the smstateen spec and check for it when accessing the fcsr register and its fields.
Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Weiwei Li <[email protected]>
Alistair
Quoted 54 lines
--- target/riscv/csr.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)target/riscv/csr.c +15
-1@@ -82,6 +82,10 @@ static RISCVException fs(CPURISCVState *env, int csrno) !riscv_cpu_cfg(env)->ext_zfinx) {return RISCV_EXCP_ILLEGAL_INST ; } + +if (!env->debugger && !riscv_cpu_fp_enabled (env)) { +return smstateen_acc_ok (env,0 ,SMSTATEEN0_FCSR ); + }#endif return RISCV_EXCP_NONE ; }@@ -2100,6 +2104,9 @@ static RISCVException write_mstateen0(CPURISCVState *env, int csrno, target_ulong new_val) {uint64_t wr_mask =SMSTATEEN_STATEEN |SMSTATEEN0_HSENVCFG ; +if (!riscv_has_ext (env,RVF )) { + wr_mask |=SMSTATEEN0_FCSR ; + }return write_mstateen (env, csrno, wr_mask, new_val); }@@ -2173,6 +2180,10 @@ static RISCVException write_hstateen0(CPURISCVState *env, int csrno, {uint64_t wr_mask =SMSTATEEN_STATEEN |SMSTATEEN0_HSENVCFG ; +if (!riscv_has_ext (env,RVF )) { + wr_mask |=SMSTATEEN0_FCSR ; + } +return write_hstateen (env, csrno, wr_mask, new_val); }@@ -2259,6 +2270,10 @@ static RISCVException write_sstateen0(CPURISCVState *env, int csrno, {uint64_t wr_mask =SMSTATEEN_STATEEN |SMSTATEEN0_HSENVCFG ; +if (!riscv_has_ext (env,RVF )) { + wr_mask |=SMSTATEEN0_FCSR ; + } +return write_sstateen (env, csrno, wr_mask, new_val); } --2.34.1
PATCH v5 2/3 target/riscv: Reuse tb->flags.FS
In reply to Mayuresh ChitaleWhen misa.F is 0 tb->flags.FS field is unused and can be used to save the current state of smstateen0.FCSR check which is needed by the floating point translation routines.
--- target/riscv/cpu_helper.c | 6 ++++++ target/riscv/insn_trans/trans_rvf.c.inc | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
target/riscv/cpu_helper.c +6 -0
@@ -119,6 +119,12 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, vs =MIN (vs,get_field (env->mstatus_hs,MSTATUS_VS )); } +/* With Zfinx, floating point is enabled/disabled by Smstateen. */ +if (!riscv_has_ext (env,RVF )) { + fs = (smstateen_acc_ok (env,0 ,SMSTATEEN0_FCSR ) ==RISCV_EXCP_NONE ) + ?EXT_STATUS_DIRTY :EXT_STATUS_DISABLED ; + } +if (cpu->cfg.debug && !icount_enabled ()) { flags =FIELD_DP32 (flags,TB_FLAGS ,ITRIGGER , env->itrigger_enabled); }
target/riscv/insn_trans/trans_rvf.c.inc +4 -3
@@ -19,9 +19,10 @@ */ #define REQUIRE_FPU do {\ - if (ctx->mstatus_fs == EXT_STATUS_DISABLED) \ - if (!ctx->cfg_ptr->ext_zfinx) \ - return false; \ + if (ctx->mstatus_fs == EXT_STATUS_DISABLED) { \ + ctx->virt_inst_excp = ctx->virt_enabled && ctx->cfg_ptr->ext_zfinx; \ + return false; \ + } \ } while (0) #define REQUIRE_ZFINX_OR_F(ctx) do {\
Signature · 1 line
2.34.1
Re: [PATCH v5 2/3] target/riscv: Reuse tb->flags.FS
Quoted 8 lines · Mayuresh Chitale
When misa.F is 0
tb->flags.FSfield is unused and can be used to save the current state of smstateen0.FCSR check which is needed by the floating point translation routines.Signed-off-by Mayuresh Chitale <[email protected]>Reviewed-by Richard Henderson <[email protected]>Reviewed-by Weiwei Li <[email protected]>
Alistair
Quoted 43 lines
--- target/riscv/cpu_helper.c | 6 ++++++ target/riscv/insn_trans/trans_rvf.c.inc | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-)target/riscv/cpu_helper.c +6
-0@@ -119,6 +119,12 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, vs =MIN (vs,get_field (env->mstatus_hs,MSTATUS_VS )); } +/* With Zfinx, floating point is enabled/disabled by Smstateen. */ +if (!riscv_has_ext (env,RVF )) { + fs = (smstateen_acc_ok (env,0 ,SMSTATEEN0_FCSR ) ==RISCV_EXCP_NONE ) + ?EXT_STATUS_DIRTY :EXT_STATUS_DISABLED ; + } +if (cpu->cfg.debug && !icount_enabled ()) { flags =FIELD_DP32 (flags,TB_FLAGS ,ITRIGGER , env->itrigger_enabled); }target/riscv/insn_trans/trans_rvf.c.inc +4
-4@@ -19,9 +19,10 @@ */ #define REQUIRE_FPU do {\ - if (ctx->mstatus_fs == EXT_STATUS_DISABLED) \ - if (!ctx->cfg_ptr->ext_zfinx) \ - return false; \ + if (ctx->mstatus_fs == EXT_STATUS_DISABLED) { \ + ctx->virt_inst_excp = ctx->virt_enabled && ctx->cfg_ptr->ext_zfinx; \ + return false; \ + } \ } while (0) #define REQUIRE_ZFINX_OR_F(ctx) do {\ --2.34.1
PATCH v5 3/3 target/riscv: smstateen knobs
In reply to Mayuresh ChitaleAdd knobs to allow users to enable smstateen and also export it via the ISA extension string.
--- target/riscv/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/cpu.c +2 -1
@@ -119,6 +119,7 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zhinx,PRIV_VERSION_1_12_0 , ext_zhinx),ISA_EXT_DATA_ENTRY (zhinxmin,PRIV_VERSION_1_12_0 , ext_zhinxmin),ISA_EXT_DATA_ENTRY (smaia,PRIV_VERSION_1_12_0 , ext_smaia), +ISA_EXT_DATA_ENTRY (smstateen,PRIV_VERSION_1_12_0 , ext_smstateen),ISA_EXT_DATA_ENTRY (ssaia,PRIV_VERSION_1_12_0 , ext_ssaia),ISA_EXT_DATA_ENTRY (sscofpmf,PRIV_VERSION_1_12_0 , ext_sscofpmf), ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc),
@@ -1498,8 +1499,8 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_BOOL ("smstateen" ,RISCVCPU , cfg.ext_smstateen, false),DEFINE_PROP_BOOL ("svadu" ,RISCVCPU , cfg.ext_svadu, true), -DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false),DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false), DEFINE_PROP_BOOL("svpbmt", RISCVCPU, cfg.ext_svpbmt, false),
Signature · 1 line
2.34.1
Alistair Francis
AppliedQuoted 25 lines · Mayuresh Chitale
Patch 4 and 5 of the smstateen series need to be re-submitted with changes described in the email below.
https://lists.nongnu.org/archive/html/qemu-riscv/2022-11/msg00155.html
Hence splitting the patch 4 of the original series into three and re-submitting along with the original patch 5.Changes in v5:
- Ammend patch 1 commit message
- Add reviewed-by tagChanges in v4:
- Drop patch 3
- Add reviewed-by tagChanges in v3:
- Reuse TB_FLAGS.FS (instead of TB_FLAGS.HS_FS) for smstateen asHS_FSbits been removed.
- Remove fcsr check for zfh and zfhminChanges in v2:
- Improve patch 1 description
- Reuse TB_FLAGS.HS_FS for smstateen
- Convertsmstateen_fcsr_checkto function
- Add fcsr check for zdinx
Quoted 4 lines
Mayuresh Chitale (3):
target/riscv: smstateen check for fcsr
target/riscv: Reusetb->flags.FS
target/riscv: smstateen knobs
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 10 lines
target/riscv/cpu.c | 3 ++- target/riscv/cpu_helper.c | 6 ++++++ target/riscv/csr.c | 15 +++++++++++++++ target/riscv/insn_trans/trans_rvf.c.inc | 7 ++++--- 4 files changed, 27 insertions(+), 4 deletions(-)--
2.34.1