From 78d4908a9ae232aa450c29df5d38063a37003a6c Mon Sep 17 00:00:00 2001 From: Haojin Tang Date: Wed, 16 Oct 2024 12:54:11 +0800 Subject: [PATCH] fix(fcvt): set xstatus.fs unconditionally on fcvt This commit also fixes a bug where fs and vs are not set to dirty when `check_vstart_ignore(s)` returns 1. --- src/isa/riscv64/instr/rvd/exec.h | 8 ++++++++ src/isa/riscv64/instr/rvf/exec.h | 8 ++++++++ src/isa/riscv64/instr/rvv/vcompute.h | 12 ------------ src/isa/riscv64/instr/rvv/vcompute_impl.c | 6 +++++- src/isa/riscv64/instr/rvzfa/exec.h | 2 ++ src/isa/riscv64/instr/rvzfh/exec.h | 8 ++++++++ 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/isa/riscv64/instr/rvd/exec.h b/src/isa/riscv64/instr/rvd/exec.h index 322da3a40..8277015ed 100644 --- a/src/isa/riscv64/instr/rvd/exec.h +++ b/src/isa/riscv64/instr/rvd/exec.h @@ -115,19 +115,27 @@ def_EHelper(fcvt_d_lu) { def_EHelper(fcvt_w_d) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToI32, FPCALL_W64)); rtl_sext(s, ddest, ddest, 4); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_wu_d) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToU32, FPCALL_W64)); rtl_sext(s, ddest, ddest, 4); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_l_d) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToI64, FPCALL_W64)); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_lu_d) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToU64, FPCALL_W64)); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_d_s) { diff --git a/src/isa/riscv64/instr/rvf/exec.h b/src/isa/riscv64/instr/rvf/exec.h index c3d2be771..d6d9c2f40 100644 --- a/src/isa/riscv64/instr/rvf/exec.h +++ b/src/isa/riscv64/instr/rvf/exec.h @@ -123,19 +123,27 @@ def_EHelper(fcvt_s_lu) { def_EHelper(fcvt_w_s) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToI32, FPCALL_W32)); rtl_sext(s, ddest, ddest, 4); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_wu_s) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToU32, FPCALL_W32)); rtl_sext(s, ddest, ddest, 4); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_l_s) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToI64, FPCALL_W32)); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_lu_s) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToU64, FPCALL_W32)); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fsgnjs) { diff --git a/src/isa/riscv64/instr/rvv/vcompute.h b/src/isa/riscv64/instr/rvv/vcompute.h index 0003efa5a..2563d9298 100644 --- a/src/isa/riscv64/instr/rvv/vcompute.h +++ b/src/isa/riscv64/instr/rvv/vcompute.h @@ -1180,38 +1180,26 @@ def_EHelper(vfmerge) { def_EHelper(vmfeq) { FLOAT_ARTHI_MASK(MFEQ) - void fp_set_dirty(); - fp_set_dirty(); } def_EHelper(vmfle) { FLOAT_ARTHI_MASK(MFLE) - void fp_set_dirty(); - fp_set_dirty(); } def_EHelper(vmflt) { FLOAT_ARTHI_MASK(MFLT) - void fp_set_dirty(); - fp_set_dirty(); } def_EHelper(vmfne) { FLOAT_ARTHI_MASK(MFNE) - void fp_set_dirty(); - fp_set_dirty(); } def_EHelper(vmfgt) { FLOAT_ARTHI_MASK(MFGT) - void fp_set_dirty(); - fp_set_dirty(); } def_EHelper(vmfge) { FLOAT_ARTHI_MASK(MFGE) - void fp_set_dirty(); - fp_set_dirty(); } def_EHelper(vfdiv) { diff --git a/src/isa/riscv64/instr/rvv/vcompute_impl.c b/src/isa/riscv64/instr/rvv/vcompute_impl.c index e032ae38e..3db21201b 100644 --- a/src/isa/riscv64/instr/rvv/vcompute_impl.c +++ b/src/isa/riscv64/instr/rvv/vcompute_impl.c @@ -1089,7 +1089,11 @@ void floating_arthimetic_instr(int opcode, int is_signed, int widening, int dest default: Loge("other fp type not supported"); longjmp_exception(EX_II); break; } check_vstart_exception(s); - if(check_vstart_ignore(s)) return; + if(check_vstart_ignore(s)) { + fp_set_dirty(); + vp_set_dirty(); + return; + } for(word_t idx = vstart->val; idx < vl->val; idx ++) { // mask rtlreg_t mask = get_mask(0, idx); diff --git a/src/isa/riscv64/instr/rvzfa/exec.h b/src/isa/riscv64/instr/rvzfa/exec.h index 1226d8c7b..d0e1fb81d 100644 --- a/src/isa/riscv64/instr/rvzfa/exec.h +++ b/src/isa/riscv64/instr/rvzfa/exec.h @@ -54,6 +54,8 @@ def_EHelper(froundnx_d) { def_EHelper(fcvtmod_w_d) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FCVTMOD, FPCALL_W64)); rtl_sext(s, ddest, ddest, 4); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fleq_s) { diff --git a/src/isa/riscv64/instr/rvzfh/exec.h b/src/isa/riscv64/instr/rvzfh/exec.h index f901ce355..19e9948f7 100644 --- a/src/isa/riscv64/instr/rvzfh/exec.h +++ b/src/isa/riscv64/instr/rvzfh/exec.h @@ -124,21 +124,29 @@ def_EHelper(fcvt_h_lu) { def_EHelper(fcvt_w_h) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToI32, FPCALL_W16)); rtl_sext(s, ddest, ddest, 4); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_wu_h) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToU32, FPCALL_W16)); rtl_sext(s, ddest, ddest, 4); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_l_h) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToI64, FPCALL_W16)); rtl_fsr(s, ddest, ddest, FPCALL_W64); + void fp_set_dirty(); + fp_set_dirty(); } def_EHelper(fcvt_lu_h) { rtl_hostcall(s, HOSTCALL_FP, ddest, dsrc1, rz, FPCALL_CMD(FPCALL_FToU64, FPCALL_W16)); rtl_fsr(s, ddest, ddest, FPCALL_W64); + void fp_set_dirty(); + fp_set_dirty(); }