Skip to contentSkip to conversation

Smstateen FCSR

PATCH Superseded Mayuresh Chitale 3 participants 9 messages Apr 28, 2023 – Apr 29, 2023 RISC-V

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 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 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 (4):
target/riscv: smstateen check for fcsr
target/riscv: Reuse tb->flags.FS
target/riscv: check smstateen fcsr flag
target/riscv: smstateen knobs

 target/riscv/cpu.c                        |  3 ++-
 target/riscv/cpu_helper.c                 |  9 +++++++
 target/riscv/csr.c                        | 15 +++++++++++
 target/riscv/insn_trans/trans_rvd.c.inc   | 13 ++++++---
 target/riscv/insn_trans/trans_rvf.c.inc   | 24 ++++++++++++++---
 target/riscv/insn_trans/trans_rvzfh.c.inc | 32 +++++++++++++++--------
 target/riscv/translate.c                  | 12 ++++++++-
 7 files changed, 87 insertions(+), 21 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/4 target/riscv: smstateen check for fcsr

If smstateen is implemented and smtateen0.fcsr is clear and misa.F is off then the floating point operations must return illegal instruction exception or virtual instruction trap, if relevant.

---
 target/riscv/csr.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
target/riscv/csr.c +15 -0
index 4451bd1263..3f6b824bd2 100644
@@ -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
#2 lore raw

PATCH v3 2/4 target/riscv: Reuse tb->flags.FS

In reply to Mayuresh Chitale

When 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 |  9 +++++++++
 target/riscv/translate.c  | 12 +++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +9 -0
index b68dcfe7b6..126ac221a0 100644
@@ -119,6 +119,15 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
         vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS));
     }
 
+    /*
+     * If misa.F is 0 then the FS field of the tb->flags can be used to pass
+     * the current state of the smstateen.FCSR bit which must be checked for
+     * in the floating point translation routines.
+     */
+    if (!riscv_has_ext(env, RVF)) {
+        fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR) == RISCV_EXCP_NONE);
+    }
+
     if (cpu->cfg.debug && !icount_enabled()) {
         flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled);
     }
target/riscv/translate.c +11 -1
index 928da0d3f0..74f624aa62 100644
@@ -78,6 +78,7 @@ typedef struct DisasContext {
     int frm;
     RISCVMXL ol;
     bool virt_inst_excp;
+    bool smstateen_fcsr_ok;
     bool virt_enabled;
     const RISCVCPUConfig *cfg_ptr;
     /* vector extension */
@@ -1155,7 +1156,11 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
     ctx->pc_succ_insn = ctx->base.pc_first;
     ctx->priv = FIELD_EX32(tb_flags, TB_FLAGS, PRIV);
     ctx->mem_idx = FIELD_EX32(tb_flags, TB_FLAGS, MEM_IDX);
-    ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    if (has_ext(ctx, RVF)) {
+        ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    } else {
+        ctx->mstatus_fs = 0;
+    }
     ctx->mstatus_vs = FIELD_EX32(tb_flags, TB_FLAGS, VS);
     ctx->priv_ver = env->priv_ver;
     ctx->virt_enabled = FIELD_EX32(tb_flags, TB_FLAGS, VIRT_ENABLED);
@@ -1178,6 +1183,11 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
     ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
     ctx->zero = tcg_constant_tl(0);
     ctx->virt_inst_excp = false;
+    if (has_ext(ctx, RVF) || !cpu->cfg.ext_smstateen) {
+        ctx->smstateen_fcsr_ok = 1;
+    } else {
+        ctx->smstateen_fcsr_ok = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    }
 }
 
 static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
Signature · 1 line
2.34.1
Reviewed-by on v3 2/4
#3 lore raw

Re: [PATCH v3 2/4] target/riscv: Reuse tb->flags.FS

Quoted 6 lines · Mayuresh Chitale

When 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.

---

Weiwei Li

Quoted 61 lines
  target/riscv/cpu_helper.c |  9 +++++++++
  target/riscv/translate.c  | 12 +++++++++++-
  2 files changed, 20 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +9 -0
index b68dcfe7b6..126ac221a0 100644
@@ -119,6 +119,15 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
          vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS));
      }
 
+    /*
+     * If misa.F is 0 then the FS field of the tb->flags can be used to pass
+     * the current state of the smstateen.FCSR bit which must be checked for
+     * in the floating point translation routines.
+     */
+    if (!riscv_has_ext(env, RVF)) {
+        fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR) == RISCV_EXCP_NONE);
+    }
+
      if (cpu->cfg.debug && !icount_enabled()) {
          flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled);
      }
target/riscv/translate.c +11 -1
index 928da0d3f0..74f624aa62 100644
@@ -78,6 +78,7 @@ typedef struct DisasContext {
      int frm;
      RISCVMXL ol;
      bool virt_inst_excp;
+    bool smstateen_fcsr_ok;
      bool virt_enabled;
      const RISCVCPUConfig *cfg_ptr;
      /* vector extension */
@@ -1155,7 +1156,11 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
      ctx->pc_succ_insn = ctx->base.pc_first;
      ctx->priv = FIELD_EX32(tb_flags, TB_FLAGS, PRIV);
      ctx->mem_idx = FIELD_EX32(tb_flags, TB_FLAGS, MEM_IDX);
-    ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    if (has_ext(ctx, RVF)) {
+        ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    } else {
+        ctx->mstatus_fs = 0;
+    }
      ctx->mstatus_vs = FIELD_EX32(tb_flags, TB_FLAGS, VS);
      ctx->priv_ver = env->priv_ver;
      ctx->virt_enabled = FIELD_EX32(tb_flags, TB_FLAGS, VIRT_ENABLED);
@@ -1178,6 +1183,11 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
      ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER);
      ctx->zero = tcg_constant_tl(0);
      ctx->virt_inst_excp = false;
+    if (has_ext(ctx, RVF) || !cpu->cfg.ext_smstateen) {
+        ctx->smstateen_fcsr_ok = 1;
+    } else {
+        ctx->smstateen_fcsr_ok = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    }
  }
 
  static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu)
#4 lore raw

Re: [PATCH v3 2/4] target/riscv: Reuse tb->flags.FS

In reply to Mayuresh Chitale
Quoted 16 lines · Mayuresh Chitale

When 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 |  9 +++++++++
  target/riscv/translate.c  | 12 +++++++++++-
  2 files changed, 20 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +0 -0
index b68dcfe7b6..126ac221a0 100644
@@ -119,6 +119,15 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
          vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS));

target/riscv/cpu_helper.c void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, · line 129

Quoted 10 lines
target/riscv/cpu_helper.c +8 -0
      }
 
+    /*
+     * If misa.F is 0 then the FS field of the tb->flags can be used to pass
+     * the current state of the smstateen.FCSR bit which must be checked for
+     * in the floating point translation routines.
+     */
+    if (!riscv_has_ext(env, RVF)) {
+        fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR) == RISCV_EXCP_NONE);
+    }

You have misunderstood my suggestion:

    /* With Zfinx, floating point is enabled/disabled by Smstateen. */
    if (!riscv_has_ext(env, RVF)) {
        fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR)
              ? EXT_STATUS_DIRTY : EXT_STATUS_DISABLED);
    }

target/riscv/cpu_helper.c void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, · line 130

Quoted 1 line
target/riscv/cpu_helper.c +1 -0
+    bool smstateen_fcsr_ok;

Not needed.

target/riscv/cpu_helper.c void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,

Quoted 6 lines
target/riscv/cpu_helper.c +5 -1
-    ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    if (has_ext(ctx, RVF)) {
+        ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS);
+    } else {
+        ctx->mstatus_fs = 0;
+    }

Not needed.

In patch 3, which should be merged with this, there are no changes to REQUIRE_ZFINX_OR_F, no additional smstateen_fcsr_check, and REQUIRE_FPU reduces to

#define REQUIRE_FPU do {                          \
    if (ctx->mstatus_fs == EXT_STATUS_DISABLED) { \
        return false;                             \
    }                                             \
} while (0)

This makes the DisasContext version of fs be the single gate for floating point. No extra checks required.

r~

#5 lore raw

Re: [PATCH v3 2/4] target/riscv: Reuse tb->flags.FS

Quoted 54 lines · Richard Henderson
Quoted 21 lines · Mayuresh Chitale

When 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 |  9 +++++++++
  target/riscv/translate.c  | 12 +++++++++++-

  2 files changed, 20 insertions(+), 1 deletion(-)
target/riscv/cpu_helper.c +0 -0
index b68dcfe7b6..126ac221a0 100644
@@ -119,6 +119,15 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, 
 target_ulong *pc,
           vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS));
       }

  +    /*
+     * If misa.F is 0 then the FS field of the tb->flags can be used to pass

Quoted 8 lines

+     * the current state of the smstateen.FCSR bit which must be checked for
+     * in the floating point translation routines.
+     */
+    if (!riscv_has_ext(env, RVF)) {
+        fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR) == RISCV_EXCP_NONE);
+    }

You have misunderstood my suggestion:

    /* With Zfinx, floating point is enabled/disabled by Smstateen. */ if (!riscv_has_ext(env, RVF)) {
        fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR)
              ? EXT_STATUS_DIRTY : EXT_STATUS_DISABLED);
    }

Quoted 1 line

+    bool smstateen_fcsr_ok;

Not needed.

Quoted 6 lines

-    ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS); +    if (has_ext(ctx, RVF)) {
+        ctx->mstatus_fs = FIELD_EX32(tb_flags, TB_FLAGS, FS); +    } else {
+        ctx->mstatus_fs = 0;
+    }

Not needed.

In patch 3, which should be merged with this, there are no changes to REQUIRE_ZFINX_OR_F, no additional smstateen_fcsr_check, and REQUIRE_FPU reduces to

Quoted 8 lines

#define REQUIRE_FPU do {                          \
    if (ctx->mstatus_fs == EXT_STATUS_DISABLED) { \
        return false;                             \
    }                                             \
} while (0)

This makes the DisasContext version of fs be the single gate for floating point. No extra checks required.

Yeah. It's better to merge with REQUIRE_FPU.

However,  virtual instruction exception will be triggered in VS/VU mode if smstateen check fails, which is different from normal REQUIRE_FPU.

So, we may need to modify REQUIRE_FPU to distinguish them:

#define REQUIRE_FPU do {                          \
    if (ctx->mstatus_fs == EXT_STATUS_DISABLED) { \
          ctx->virt_inst_excp = ctx->virt_enabled && ctx->cfg_ptr->ext_zfinx;  \
          return false;                             \
    }                                             \
} while (0)

Regards,

Weiwei Li

Quoted 3 lines

r~

#6 lore raw

PATCH v3 3/4 target/riscv: check smstateen fcsr flag

In reply to Mayuresh Chitale

If misa.F and smstateen_fcsr_ok flag are clear then all the floating point instructions must generate an appropriate exception.

---
 target/riscv/insn_trans/trans_rvd.c.inc   | 13 ++++++---
 target/riscv/insn_trans/trans_rvf.c.inc   | 24 ++++++++++++++---
 target/riscv/insn_trans/trans_rvzfh.c.inc | 32 +++++++++++++++--------
 3 files changed, 50 insertions(+), 19 deletions(-)
target/riscv/insn_trans/trans_rvd.c.inc +9 -4
index 2c51e01c40..d9e0cf116f 100644
@@ -18,10 +18,15 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#define REQUIRE_ZDINX_OR_D(ctx) do { \
-    if (!ctx->cfg_ptr->ext_zdinx) { \
-        REQUIRE_EXT(ctx, RVD); \
-    } \
+#define REQUIRE_ZDINX_OR_D(ctx) do {           \
+    if (!has_ext(ctx, RVD)) {                  \
+        if (!ctx->cfg_ptr->ext_zdinx) {        \
+            return false;                      \
+        }                                      \
+        if (!smstateen_fcsr_check(ctx)) {      \
+            return false;                      \
+        }                                      \
+    }                                          \
 } while (0)
 
 #define REQUIRE_EVEN(ctx, reg) do { \
target/riscv/insn_trans/trans_rvf.c.inc +20 -4
index b2de4fcf3f..e4d9834237 100644
@@ -24,10 +24,26 @@
             return false; \
 } while (0)
 
-#define REQUIRE_ZFINX_OR_F(ctx) do {\
-    if (!ctx->cfg_ptr->ext_zfinx) { \
-        REQUIRE_EXT(ctx, RVF); \
-    } \
+static inline bool smstateen_fcsr_check(DisasContext *ctx)
+{
+#ifndef CONFIG_USER_ONLY
+    if (!ctx->smstateen_fcsr_ok) {
+        ctx->virt_inst_excp = ctx->virt_enabled;
+        return false;
+    }
+#endif
+    return true;
+}
+
+#define REQUIRE_ZFINX_OR_F(ctx) do {           \
+    if (!has_ext(ctx, RVF)) {                  \
+        if (!ctx->cfg_ptr->ext_zfinx) {        \
+            return false;                      \
+        }                                      \
+        if (!smstateen_fcsr_check(ctx)) {      \
+            return false;                      \
+        }                                      \
+    }                                          \
 } while (0)
 
 #define REQUIRE_ZCF(ctx) do {                  \
target/riscv/insn_trans/trans_rvzfh.c.inc +21 -11
index 74dde37ff7..e228ae28a5 100644
@@ -16,28 +16,38 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#define REQUIRE_ZFH(ctx) do { \
+#define REQUIRE_ZFH(ctx) do {          \
     if (!ctx->cfg_ptr->ext_zfh) {      \
-        return false;         \
-    }                         \
-} while (0)
-
-#define REQUIRE_ZHINX_OR_ZFH(ctx) do { \
-    if (!ctx->cfg_ptr->ext_zhinx && !ctx->cfg_ptr->ext_zfh) { \
         return false;                  \
     }                                  \
 } while (0)
 
+#define REQUIRE_ZHINX_OR_ZFH(ctx) do {                \
+    if (!ctx->cfg_ptr->ext_zfh) {                     \
+        if (!ctx->cfg_ptr->ext_zhinx) {               \
+            return false;                             \
+        }                                             \
+        if (!smstateen_fcsr_check(ctx)) {             \
+            return false;                             \
+        }                                             \
+    }                                                 \
+} while (0)
+
 #define REQUIRE_ZFHMIN(ctx) do {              \
     if (!ctx->cfg_ptr->ext_zfhmin) {          \
         return false;                         \
     }                                         \
 } while (0)
 
-#define REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx) do {                 \
-    if (!(ctx->cfg_ptr->ext_zfhmin || ctx->cfg_ptr->ext_zhinxmin)) { \
-        return false;                                        \
-    }                                                        \
+#define REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx) do {             \
+    if (!ctx->cfg_ptr->ext_zfhmin) {                     \
+        if (ctx->cfg_ptr->ext_zhinxmin) {                \
+            return false;                                \
+        }                                                \
+        if (!smstateen_fcsr_check(ctx)) {                \
+            return false;                                \
+        }                                                \
+    }                                                    \
 } while (0)
 
 static bool trans_flh(DisasContext *ctx, arg_flh *a)
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v3 3/4] target/riscv: check smstateen fcsr flag

Quoted 74 lines · Mayuresh Chitale

If misa.F and smstateen_fcsr_ok flag are clear then all the floating point instructions must generate an appropriate exception.

---
  target/riscv/insn_trans/trans_rvd.c.inc   | 13 ++++++---
  target/riscv/insn_trans/trans_rvf.c.inc   | 24 ++++++++++++++---
  target/riscv/insn_trans/trans_rvzfh.c.inc | 32 +++++++++++++++--------
  3 files changed, 50 insertions(+), 19 deletions(-)
target/riscv/insn_trans/trans_rvd.c.inc +9 -4
index 2c51e01c40..d9e0cf116f 100644
@@ -18,10 +18,15 @@
   * this program.  If not, see <http://www.gnu.org/licenses/>.
   */
 
-#define REQUIRE_ZDINX_OR_D(ctx) do { \
-    if (!ctx->cfg_ptr->ext_zdinx) { \
-        REQUIRE_EXT(ctx, RVD); \
-    } \
+#define REQUIRE_ZDINX_OR_D(ctx) do {           \
+    if (!has_ext(ctx, RVD)) {                  \
+        if (!ctx->cfg_ptr->ext_zdinx) {        \
+            return false;                      \
+        }                                      \
+        if (!smstateen_fcsr_check(ctx)) {      \
+            return false;                      \
+        }                                      \
+    }                                          \
  } while (0)
 
  #define REQUIRE_EVEN(ctx, reg) do { \
target/riscv/insn_trans/trans_rvf.c.inc +20 -4
index b2de4fcf3f..e4d9834237 100644
@@ -24,10 +24,26 @@
              return false; \
  } while (0)
 
-#define REQUIRE_ZFINX_OR_F(ctx) do {\
-    if (!ctx->cfg_ptr->ext_zfinx) { \
-        REQUIRE_EXT(ctx, RVF); \
-    } \
+static inline bool smstateen_fcsr_check(DisasContext *ctx)
+{
+#ifndef CONFIG_USER_ONLY
+    if (!ctx->smstateen_fcsr_ok) {
+        ctx->virt_inst_excp = ctx->virt_enabled;
+        return false;
+    }
+#endif
+    return true;
+}
+
+#define REQUIRE_ZFINX_OR_F(ctx) do {           \
+    if (!has_ext(ctx, RVF)) {                  \
+        if (!ctx->cfg_ptr->ext_zfinx) {        \
+            return false;                      \
+        }                                      \
+        if (!smstateen_fcsr_check(ctx)) {      \
+            return false;                      \
+        }                                      \
+    }                                          \
  } while (0)
 
  #define REQUIRE_ZCF(ctx) do {                  \
target/riscv/insn_trans/trans_rvzfh.c.inc +0 -0
index 74dde37ff7..e228ae28a5 100644

target/riscv/insn_trans/trans_rvzfh.c.inc line 19

Quoted 5 lines
target/riscv/insn_trans/trans_rvzfh.c.inc +1 -1
@@ -16,28 +16,38 @@
   * this program.  If not, see <http://www.gnu.org/licenses/>.
   */
 
-#define REQUIRE_ZFH(ctx) do { \
+#define REQUIRE_ZFH(ctx) do {          \

This modification seems unnecessary.

Otherwise, Reviewed-by: Weiwei Li <[email protected]>

Weiwei Li

Quoted 44 lines
target/riscv/insn_trans/trans_rvzfh.c.inc +20 -10
      if (!ctx->cfg_ptr->ext_zfh) {      \
-        return false;         \
-    }                         \
-} while (0)
-
-#define REQUIRE_ZHINX_OR_ZFH(ctx) do { \
-    if (!ctx->cfg_ptr->ext_zhinx && !ctx->cfg_ptr->ext_zfh) { \
          return false;                  \
      }                                  \
  } while (0)
 
+#define REQUIRE_ZHINX_OR_ZFH(ctx) do {                \
+    if (!ctx->cfg_ptr->ext_zfh) {                     \
+        if (!ctx->cfg_ptr->ext_zhinx) {               \
+            return false;                             \
+        }                                             \
+        if (!smstateen_fcsr_check(ctx)) {             \
+            return false;                             \
+        }                                             \
+    }                                                 \
+} while (0)
+
  #define REQUIRE_ZFHMIN(ctx) do {              \
      if (!ctx->cfg_ptr->ext_zfhmin) {          \
          return false;                         \
      }                                         \
  } while (0)
 
-#define REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx) do {                 \
-    if (!(ctx->cfg_ptr->ext_zfhmin || ctx->cfg_ptr->ext_zhinxmin)) { \
-        return false;                                        \
-    }                                                        \
+#define REQUIRE_ZFHMIN_OR_ZHINXMIN(ctx) do {             \
+    if (!ctx->cfg_ptr->ext_zfhmin) {                     \
+        if (ctx->cfg_ptr->ext_zhinxmin) {                \
+            return false;                                \
+        }                                                \
+        if (!smstateen_fcsr_check(ctx)) {                \
+            return false;                                \
+        }                                                \
+    }                                                    \
  } while (0)
 
  static bool trans_flh(DisasContext *ctx, arg_flh *a)
#8 lore raw

PATCH v3 4/4 target/riscv: smstateen knobs

In reply to Mayuresh Chitale

Add 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
index befa64528f..9420cd670e 100644
@@ -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