From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org, richard.henderson@linaro.org
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Richard Henderson <rth@twiddle.net>,
Aurelien Jarno <aurelien@aurel32.net>,
Riku Voipio <riku.voipio@iki.fi>,
Laurent Vivier <laurent@vivier.eu>,
"open list\:ARM" <qemu-arm@nongnu.org>
Subject: Re: [PATCH] fpu/softfloat: use hardware sqrt if we can (EXPERIMENT!)
Date: Wed, 21 Feb 2018 20:44:26 +0000 [thread overview]
Message-ID: <87k1v69iol.fsf@linaro.org> (raw)
In-Reply-To: <20180220210137.18018-1-alex.bennee@linaro.org>
Alex Bennée <alex.bennee@linaro.org> writes:
> This is an attempt to save some of the cost of sqrt by using the
> inbuilt support of the host hardware. The idea is assuming we start
> with a valid input we can use the hardware. If any tininess issues
> occur this will trip and FPU exception where:
>
> - we turn off cpu->use_host_fpu
> - mask the FPU exceptions
> - return to what we were doing
>
> Once we return we should pick up the fact that there was something
> weird about the operation and fall-back to the pure software
> implementation.
>
> You could imagine this being extended for code generation but instead
> of returning to the code we could exit and re-generate the TB but this
> time with pure software helpers rather than any support from the
> hardware.
>
> This is a sort of fix-it-up after the fact approach because reading
> the FP state is an expensive operation for everything so let's only
> worry about exceptions when they trip...
>
<snip>
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -20,6 +20,7 @@
> #include "qemu/bitops.h"
> #include <sys/ucontext.h>
> #include <sys/resource.h>
> +#include <fenv.h>
>
> #include "qemu.h"
> #include "qemu-common.h"
> @@ -639,6 +640,21 @@ static void host_signal_handler(int host_signum, siginfo_t *info,
> ucontext_t *uc = puc;
> struct emulated_sigtable *k;
>
> + /* Catch any FPU exceptions we might get from having tried to use
> + * the host FPU to speed up some calculations
> + */
> + if (host_signum == SIGFPE && cpu->use_host_fpu) {
> + cpu->use_host_fpu = false;
> + /* sadly this gets lost on the context switch when we return */
> + fedisableexcept(FE_INVALID |
> + FE_OVERFLOW |
> + FE_UNDERFLOW |
> + FE_INEXACT);
> + /* sigaddset(&uc->uc_sigmask, SIGFPE); */
> + uc->__fpregs_mem.mxcsr |= 0x1f80;
This is a bug, the correct place to reset mxcsr for the return is:
(uc->uc_mcontext.fpregs)->mxcsr |= 0x1f80;
--
Alex Bennée
next prev parent reply other threads:[~2018-02-21 20:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAFEAcA_Tp9cH5CBi4C6CRHpZ4ozygGSFYhdLaURBQOVZ9zVxvA@mail.gmail.com>
2018-02-20 21:01 ` [PATCH] fpu/softfloat: use hardware sqrt if we can (EXPERIMENT!) Alex Bennée
2018-02-21 20:44 ` Alex Bennée [this message]
2018-03-21 20:16 ` [Qemu-devel] " Emilio G. Cota
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=87k1v69iol.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=aurelien@aurel32.net \
--cc=crosthwaite.peter@gmail.com \
--cc=laurent@vivier.eu \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=riku.voipio@iki.fi \
--cc=rth@twiddle.net \
/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).