From: Richard Henderson <richard.henderson@linaro.org>
To: Keith Packard <keithp@keithp.com>, qemu-devel@nongnu.org
Cc: Laurent Vivier <laurent@vivier.eu>
Subject: Re: [PATCH] target/m68k: Map FPU exceptions to FPSR register
Date: Wed, 2 Aug 2023 19:00:29 -0700 [thread overview]
Message-ID: <13b823f2-ab77-3456-1c00-bc9b8880327a@linaro.org> (raw)
In-Reply-To: <20230803005534.421387-1-keithp@keithp.com>
On 8/2/23 17:55, Keith Packard via wrote:
> Add helpers for reading/writing the 68881 FPSR register so that
> changes in floating point exception state can be seen by the
> application.
>
> Signed-off-by: Keith Packard <keithp@keithp.com>
> ---
> target/m68k/cpu.h | 2 ++
> target/m68k/fpu_helper.c | 72 ++++++++++++++++++++++++++++++++++++++++
> target/m68k/helper.c | 4 +--
> target/m68k/helper.h | 2 ++
> target/m68k/translate.c | 4 +--
> 5 files changed, 80 insertions(+), 4 deletions(-)
Good catch. Mostly ok.
> +static inline int cpu_m68k_exceptbits_from_host(int host_bits)
...
> +static inline int cpu_m68k_exceptbits_to_host(int target_bits)
No need for inline markers.
> +uint32_t HELPER(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 & ~(0xf8)) | target_flags;
> + return except;
> +}
> +
> +uint32_t cpu_m68k_get_fpsr(CPUM68KState *env)
> +{
> + return HELPER(get_fpsr)(env);
> +}
In general it is bad form to call HELPER(foo) directly.
In this case it doesn't hurt, but better form to reverse the implementations.
> +void HELPER(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 cpu_m68k_set_fpsr(CPUM68KState *env, uint32_t val)
> +{
> + return HELPER(set_fpsr)(env, val);
> +}
Likewise.
What's missing is an update to vmstate, to make sure all the architectural bits are
properly saved. Add
env->fpsr = cpu_m68k_get_fpsr(env);
to a (new) fpu_pre_save and
cpu_m68k_set_fpsr(env, env->fpsr);
to fpu_post_load in target/m68k/cpu.c.
r~
next prev parent reply other threads:[~2023-08-03 2:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 0:55 [PATCH] target/m68k: Map FPU exceptions to FPSR register Keith Packard via
2023-08-03 2:00 ` Richard Henderson [this message]
2023-08-03 3:53 ` Keith Packard via
-- strict thread matches above, loose matches on Subject: below --
2023-08-03 3:52 Keith Packard via
2023-08-03 14:49 ` Richard Henderson
2023-10-03 21:19 ` 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=13b823f2-ab77-3456-1c00-bc9b8880327a@linaro.org \
--to=richard.henderson@linaro.org \
--cc=keithp@keithp.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).