#define require_fp require((STATE.mstatus & MSTATUS_FS) != 0)
#define require_accelerator require((STATE.mstatus & MSTATUS_XS) != 0)
-#define set_fp_exceptions ({ STATE.fflags |= softfloat_exceptionFlags; \
+#define set_fp_exceptions ({ if (softfloat_exceptionFlags) { \
+ dirty_fp_state; \
+ STATE.fflags |= softfloat_exceptionFlags; \
+ } \
softfloat_exceptionFlags = 0; })
#define sext32(x) ((sreg_t)(int32_t)(x))
-int csr = validate_csr(insn.csr(), true);
+bool write = insn.rs1() != 0;
+int csr = validate_csr(insn.csr(), write);
reg_t old = p->get_csr(csr);
-p->set_csr(csr, old & ~RS1);
+if (write) {
+ p->set_csr(csr, old & ~RS1);
+}
WRITE_RD(sext_xlen(old));
-int csr = validate_csr(insn.csr(), true);
+bool write = insn.rs1() != 0;
+int csr = validate_csr(insn.csr(), write);
reg_t old = p->get_csr(csr);
-p->set_csr(csr, old & ~(reg_t)insn.rs1());
+if (write) {
+ p->set_csr(csr, old & ~(reg_t)insn.rs1());
+}
WRITE_RD(sext_xlen(old));
-int csr = validate_csr(insn.csr(), insn.rs1() != 0);
+bool write = insn.rs1() != 0;
+int csr = validate_csr(insn.csr(), write);
reg_t old = p->get_csr(csr);
-p->set_csr(csr, old | RS1);
+if (write) {
+ p->set_csr(csr, old | RS1);
+}
WRITE_RD(sext_xlen(old));
-int csr = validate_csr(insn.csr(), true);
+bool write = insn.rs1() != 0;
+int csr = validate_csr(insn.csr(), write);
reg_t old = p->get_csr(csr);
-p->set_csr(csr, old | insn.rs1());
+if (write) {
+ p->set_csr(csr, old | insn.rs1());
+}
WRITE_RD(sext_xlen(old));