From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu, daniel@0x0f.com
Subject: [PATCH v3 04/26] target/m68k: Keep FPSR up-to-date
Date: Mon, 9 Sep 2024 10:28:01 -0700 [thread overview]
Message-ID: <20240909172823.649837-5-richard.henderson@linaro.org> (raw)
In-Reply-To: <20240909172823.649837-1-richard.henderson@linaro.org>
Proper support for m68k exceptions will require testing the FPCR vs
the FPSR for every instruction. As a step, do not keep FPSR bits in
fp_status, but copy them back to the FPSR in every instruction.
Since most of the FPSR must be updated on every insn, combine this
with the existing helper_ftst function to create helper_update_fpsr.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/m68k/cpu.h | 2 -
target/m68k/helper.h | 4 +-
target/m68k/cpu.c | 10 ----
target/m68k/fpu_helper.c | 115 ++++++++++++---------------------------
target/m68k/helper.c | 4 +-
target/m68k/translate.c | 10 ++--
6 files changed, 42 insertions(+), 103 deletions(-)
diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
index e8dd75d242..389cd1f364 100644
--- a/target/m68k/cpu.h
+++ b/target/m68k/cpu.h
@@ -199,8 +199,6 @@ void cpu_m68k_set_ccr(CPUM68KState *env, uint32_t);
void cpu_m68k_set_sr(CPUM68KState *env, uint32_t);
void cpu_m68k_restore_fp_status(CPUM68KState *env);
void cpu_m68k_set_fpcr(CPUM68KState *env, uint32_t val);
-uint32_t cpu_m68k_get_fpsr(CPUM68KState *env);
-void cpu_m68k_set_fpsr(CPUM68KState *env, uint32_t val);
/*
* Instead of computing the condition codes after each m68k instruction,
diff --git a/target/m68k/helper.h b/target/m68k/helper.h
index 95aa5e53bb..97a0b22ffb 100644
--- a/target/m68k/helper.h
+++ b/target/m68k/helper.h
@@ -54,10 +54,8 @@ DEF_HELPER_4(fsdiv, void, env, fp, fp, fp)
DEF_HELPER_4(fddiv, void, env, fp, fp, fp)
DEF_HELPER_4(fsgldiv, void, env, fp, fp, fp)
DEF_HELPER_FLAGS_3(fcmp, TCG_CALL_NO_RWG, void, env, fp, fp)
-DEF_HELPER_2(set_fpsr, void, env, i32)
-DEF_HELPER_1(get_fpsr, i32, env)
DEF_HELPER_FLAGS_2(set_fpcr, TCG_CALL_NO_RWG, void, env, i32)
-DEF_HELPER_FLAGS_2(ftst, TCG_CALL_NO_RWG, void, env, fp)
+DEF_HELPER_FLAGS_2(update_fpsr, TCG_CALL_NO_WG, void, env, fp)
DEF_HELPER_3(fconst, void, env, fp, i32)
DEF_HELPER_3(fmovemx_st_predec, i32, env, i32, i32)
DEF_HELPER_3(fmovemx_st_postinc, i32, env, i32, i32)
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 4d70cd50b4..8c28db2e95 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -390,20 +390,11 @@ static const VMStateDescription vmstate_freg = {
}
};
-static int fpu_pre_save(void *opaque)
-{
- M68kCPU *s = opaque;
-
- s->env.fpsr = cpu_m68k_get_fpsr(&s->env);
- return 0;
-}
-
static int fpu_post_load(void *opaque, int version)
{
M68kCPU *s = opaque;
cpu_m68k_set_fpcr(&s->env, s->env.fpcr);
- cpu_m68k_set_fpsr(&s->env, s->env.fpsr);
return 0;
}
@@ -412,7 +403,6 @@ const VMStateDescription vmmstate_fpu = {
.version_id = 1,
.minimum_version_id = 1,
.needed = fpu_needed,
- .pre_save = fpu_pre_save,
.post_load = fpu_post_load,
.fields = (const VMStateField[]) {
VMSTATE_UINT32(env.fpcr, M68kCPU),
diff --git a/target/m68k/fpu_helper.c b/target/m68k/fpu_helper.c
index c6d93b56a0..56694418f2 100644
--- a/target/m68k/fpu_helper.c
+++ b/target/m68k/fpu_helper.c
@@ -164,76 +164,47 @@ void HELPER(set_fpcr)(CPUM68KState *env, uint32_t val)
cpu_m68k_set_fpcr(env, val);
}
-/* Convert host exception flags to cpu_m68k form. */
-static int cpu_m68k_exceptbits_from_host(int host_bits)
+void HELPER(update_fpsr)(CPUM68KState *env, FPReg *pval)
{
- int target_bits = 0;
+ uint32_t fpsr = env->fpsr;
+ floatx80 val = pval->d;
+ int soft;
- if (host_bits & float_flag_invalid) {
- target_bits |= FPSR_AEXP_IOP;
- }
- if (host_bits & float_flag_overflow) {
- target_bits |= FPSR_AEXP_OVFL;
- }
- if (host_bits & (float_flag_underflow | float_flag_output_denormal)) {
- target_bits |= FPSR_AEXP_UNFL;
- }
- if (host_bits & float_flag_divbyzero) {
- target_bits |= FPSR_AEXP_DZ;
- }
- if (host_bits & float_flag_inexact) {
- target_bits |= FPSR_AEXC_INEX;
- }
- return target_bits;
-}
+ fpsr &= ~FPSR_CC_MASK;
-/* Convert cpu_m68k exception flags to target form. */
-static int cpu_m68k_exceptbits_to_host(int target_bits)
-{
- int host_bits = 0;
-
- if (target_bits & FPSR_AEXP_IOP) {
- host_bits |= float_flag_invalid;
+ if (floatx80_is_neg(val)) {
+ fpsr |= FPSR_CC_N;
}
- if (target_bits & FPSR_AEXP_OVFL) {
- host_bits |= float_flag_overflow;
+ if (floatx80_is_any_nan(val)) {
+ fpsr |= FPSR_CC_A;
+ } else if (floatx80_is_infinity(val)) {
+ fpsr |= FPSR_CC_I;
+ } else if (floatx80_is_zero(val)) {
+ fpsr |= FPSR_CC_Z;
}
- if (target_bits & FPSR_AEXP_UNFL) {
- host_bits |= float_flag_underflow;
+
+ soft = get_float_exception_flags(&env->fp_status);
+ if (soft) {
+ set_float_exception_flags(0, &env->fp_status);
+
+ if (soft & float_flag_invalid) {
+ fpsr |= FPSR_AEXP_IOP;
+ }
+ if (soft & float_flag_overflow) {
+ fpsr |= FPSR_AEXP_OVFL;
+ }
+ if (soft & (float_flag_underflow | float_flag_output_denormal)) {
+ fpsr |= FPSR_AEXP_UNFL;
+ }
+ if (soft & float_flag_divbyzero) {
+ fpsr |= FPSR_AEXP_DZ;
+ }
+ if (soft & float_flag_inexact) {
+ fpsr |= FPSR_AEXC_INEX;
+ }
}
- if (target_bits & FPSR_AEXP_DZ) {
- host_bits |= float_flag_divbyzero;
- }
- if (target_bits & FPSR_AEXC_INEX) {
- host_bits |= float_flag_inexact;
- }
- return host_bits;
-}
-uint32_t cpu_m68k_get_fpsr(CPUM68KState *env)
-{
- int host_flags = get_float_exception_flags(&env->fp_status);
- int target_flags = cpu_m68k_exceptbits_from_host(host_flags);
- int except = (env->fpsr & ~FPSR_AEXC_MASK) | target_flags;
- return except;
-}
-
-uint32_t HELPER(get_fpsr)(CPUM68KState *env)
-{
- return cpu_m68k_get_fpsr(env);
-}
-
-void cpu_m68k_set_fpsr(CPUM68KState *env, uint32_t val)
-{
- env->fpsr = val;
-
- int host_flags = cpu_m68k_exceptbits_to_host((int) env->fpsr);
- set_float_exception_flags(host_flags, &env->fp_status);
-}
-
-void HELPER(set_fpsr)(CPUM68KState *env, uint32_t val)
-{
- cpu_m68k_set_fpsr(env, val);
+ env->fpsr = fpsr;
}
#define PREC_BEGIN(prec) \
@@ -445,24 +416,6 @@ void HELPER(fcmp)(CPUM68KState *env, FPReg *val0, FPReg *val1)
env->fpsr = (env->fpsr & ~FPSR_CC_MASK) | float_comp_to_cc(float_compare);
}
-void HELPER(ftst)(CPUM68KState *env, FPReg *val)
-{
- uint32_t cc = 0;
-
- if (floatx80_is_neg(val->d)) {
- cc |= FPSR_CC_N;
- }
-
- if (floatx80_is_any_nan(val->d)) {
- cc |= FPSR_CC_A;
- } else if (floatx80_is_infinity(val->d)) {
- cc |= FPSR_CC_I;
- } else if (floatx80_is_zero(val->d)) {
- cc |= FPSR_CC_Z;
- }
- env->fpsr = (env->fpsr & ~FPSR_CC_MASK) | cc;
-}
-
void HELPER(fconst)(CPUM68KState *env, FPReg *val, uint32_t offset)
{
val->d = fpu_rom[offset];
diff --git a/target/m68k/helper.c b/target/m68k/helper.c
index 4c85badd5d..6fc5afd296 100644
--- a/target/m68k/helper.c
+++ b/target/m68k/helper.c
@@ -88,7 +88,7 @@ static int m68k_fpu_gdb_get_reg(CPUState *cs, GByteArray *mem_buf, int n)
case 8: /* fpcontrol */
return gdb_get_reg32(mem_buf, env->fpcr);
case 9: /* fpstatus */
- return gdb_get_reg32(mem_buf, cpu_m68k_get_fpsr(env));
+ return gdb_get_reg32(mem_buf, env->fpsr);
case 10: /* fpiar, not implemented */
return gdb_get_reg32(mem_buf, 0);
}
@@ -110,7 +110,7 @@ static int m68k_fpu_gdb_set_reg(CPUState *cs, uint8_t *mem_buf, int n)
cpu_m68k_set_fpcr(env, ldl_p(mem_buf));
return 4;
case 9: /* fpstatus */
- cpu_m68k_set_fpsr(env, ldl_p(mem_buf));
+ env->fpsr = ldl_p(mem_buf);
return 4;
case 10: /* fpiar, not implemented */
return 4;
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
index ad3ce34501..423c663607 100644
--- a/target/m68k/translate.c
+++ b/target/m68k/translate.c
@@ -4732,7 +4732,7 @@ static void gen_load_fcr(DisasContext *s, TCGv res, int reg)
tcg_gen_movi_i32(res, 0);
break;
case M68K_FPSR:
- gen_helper_get_fpsr(res, tcg_env);
+ tcg_gen_ld_i32(res, tcg_env, offsetof(CPUM68KState, fpsr));
break;
case M68K_FPCR:
tcg_gen_ld_i32(res, tcg_env, offsetof(CPUM68KState, fpcr));
@@ -4746,7 +4746,7 @@ static void gen_store_fcr(DisasContext *s, TCGv val, int reg)
case M68K_FPIAR:
break;
case M68K_FPSR:
- gen_helper_set_fpsr(tcg_env, val);
+ tcg_gen_st_i32(val, tcg_env, offsetof(CPUM68KState, fpsr));
break;
case M68K_FPCR:
gen_helper_set_fpcr(tcg_env, val);
@@ -4965,7 +4965,7 @@ DISAS_INSN(fpu)
EA_STORE, IS_USER(s)) == -1) {
gen_addr_fault(s);
}
- gen_helper_ftst(tcg_env, cpu_src);
+ gen_helper_update_fpsr(tcg_env, cpu_src);
return;
case 4: /* fmove to control register. */
case 5: /* fmove from control register. */
@@ -5159,12 +5159,12 @@ DISAS_INSN(fpu)
gen_helper_fcmp(tcg_env, cpu_src, cpu_dest);
return;
case 0x3a: /* ftst */
- gen_helper_ftst(tcg_env, cpu_src);
+ gen_helper_update_fpsr(tcg_env, cpu_src);
return;
default:
goto undef;
}
- gen_helper_ftst(tcg_env, cpu_dest);
+ gen_helper_update_fpsr(tcg_env, cpu_dest);
return;
undef:
/* FIXME: Is this right for offset addressing modes? */
--
2.43.0
next prev parent reply other threads:[~2024-09-09 17:29 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-09 17:27 [PATCH v3 00/26] target/m68k: fpu improvements Richard Henderson
2024-09-09 17:27 ` [PATCH v3 01/26] target/m68k: Always return a temporary from gen_lea_mode Richard Henderson
2024-09-09 17:27 ` [PATCH v3 02/26] target/m68k: Add FPSR exception bit defines Richard Henderson
2024-09-09 17:28 ` [PATCH v3 03/26] target/m68k: Restore fp rounding mode on vm load Richard Henderson
2024-09-09 21:59 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` Richard Henderson [this message]
2024-09-09 17:28 ` [PATCH v3 05/26] target/m68k: Update FPSR.EXC Richard Henderson
2024-09-09 17:28 ` [PATCH v3 06/26] softfloat: Set QEMU_NO_HARDFLOAT for m68k Richard Henderson
2024-09-09 17:28 ` [PATCH v3 07/26] target/m68k: Invoke update_fpsr for FMOVECR Richard Henderson
2024-09-09 17:28 ` [PATCH v3 08/26] target/m68k: Introduce M68K_FEATURE_FPU_PACKED_DECIMAL Richard Henderson
2024-09-09 17:28 ` [PATCH v3 09/26] target/m68k: Merge gen_ea into SRC_EA and DEST_EA Richard Henderson
2024-09-09 22:02 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 10/26] target/m68k: Use g_assert_not_reached in gen_lea_mode and gen_ea_mode Richard Henderson
2024-09-09 22:03 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 11/26] target/m68k: Use OS_UNSIZED in LEA, PEA, JMP Richard Henderson
2024-09-09 17:28 ` [PATCH v3 12/26] target/m68k: Move pre-dec/post-inc to gen_lea_mode Richard Henderson
2024-09-09 17:28 ` [PATCH v3 13/26] target/m68k: Split gen_ea_mode for load/store Richard Henderson
2024-09-09 17:28 ` [PATCH v3 14/26] target/m68k: Remove env argument to gen_lea_indexed Richard Henderson
2024-09-09 22:05 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 15/26] target/m68k: Remove env argument to gen_lea_mode Richard Henderson
2024-09-09 22:06 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 16/26] target/m68k: Remove env argument to gen_load_mode Richard Henderson
2024-09-09 22:06 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 17/26] target/m68k: Remove env argument to gen_store_mode Richard Henderson
2024-09-09 22:06 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 18/26] target/m68k: Remove env argument to gen_ea_mode_fp Richard Henderson
2024-09-09 22:06 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 19/26] target/m68k: Split gen_ea_mode_fp for load/store Richard Henderson
2024-09-09 22:13 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 20/26] target/m68k: Move gen_addr_fault into gen_{load, store}_mode_fp Richard Henderson
2024-09-09 22:14 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 21/26] target/m68k: Merge gen_load_fp, gen_load_mode_fp Richard Henderson
2024-09-09 22:16 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 22/26] target/m68k: Merge gen_store_fp, gen_store_mode_fp Richard Henderson
2024-09-09 22:16 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 23/26] target/m68k: Implement packed decimal real loads and stores Richard Henderson
2024-09-09 17:28 ` [PATCH v3 24/26] tests/tcg/m68k: Add packed decimal tests Richard Henderson
2024-09-09 17:28 ` [PATCH v3 25/26] target/m68k: Make vmstate variables static Richard Henderson
2024-09-09 22:17 ` Philippe Mathieu-Daudé
2024-09-09 17:28 ` [PATCH v3 26/26] target/m68k: Implement FPIAR Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240909172823.649837-5-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=daniel@0x0f.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).