From: Peter Maydell <peter.maydell@linaro.org>
To: william lin <wlsaidhi@gmail.com>
Cc: KONRAD Frederic <frederic.konrad@adacore.com>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [Bug 645662] x87 fpu emulation not accurate enough
Date: Wed, 29 Nov 2017 10:27:42 +0000 [thread overview]
Message-ID: <CAFEAcA8eDeKBnLW45=fPt3NeApMkvkiJzFEshvep_5qmwZKGXA@mail.gmail.com> (raw)
In-Reply-To: <CAGC02hT7OvR1nbyD=AkOqPvxbNPz957=CPZsUxf1FJ73O8W52g@mail.gmail.com>
On 29 November 2017 at 09:59, william lin <wlsaidhi@gmail.com> wrote:
> This bug has been around for 7+ years now. Qemu switched to softfloat and
> it did not fix this. I think its most likely caused by Qemu's internal
> representation not being accurate enough or accuracy lost during
> conversion. However this is basically what is given to us in the bug
> report, and I have not been able to make much progress past this point, so
> we are asking for help.
Looking at the bug, it seems like inaccuracies in the results of
some of the transcendental operations (sin, cos, etc). This is
almost certainly the because our implementations of these in
target/i386/fpu_helper.c do this:
void helper_fsin(CPUX86State *env)
{
double fptemp = floatx80_to_double(env, ST0);
if ((fptemp > MAXTAN) || (fptemp < -MAXTAN)) {
env->fpus |= 0x400;
} else {
ST0 = double_to_floatx80(env, sin(fptemp));
env->fpus &= ~0x400; /* C2 <-- 0 */
/* the above code is for |arg| < 2**53 only */
}
}
ie convert the 80-bit value in the emulated FPU to a host double,
call the host libc sin() function and convert the resulting
double to 80-bit.
Fixing this to be bit-for-bit accurate will require that we
write our own transcendental arithmetic functions that can handle
80-bit precision, which is a bit of a hairy task. (Probably all the
functions that call floatx80_to_double() would need to be rewritten.
We currently use this approach for the "complicated" operations
that the x87 provides but which softfloat doesn't: sin, cos,
powers, logs, that sort of thing.)
I was going to suggest that we borrow the code to do this from
bochs, which does seem to have implemented complete software
emulation of these complicated x87 instructions, but unfortunately
the relevant files in bochs are under the softfloat-2b license, which
isn't (by the QEMU project's reading of the license) compatible
with the GPLv2 which we use :-(
thanks
-- PMM
next prev parent reply other threads:[~2017-11-29 10:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-29 8:34 [Qemu-devel] [Bug 645662] x87 fpu emulation not accurate enough william lin
2017-11-29 9:39 ` KONRAD Frederic
2017-11-29 9:59 ` william lin
2017-11-29 10:17 ` KONRAD Frederic
2017-11-29 10:27 ` Peter Maydell [this message]
2017-11-29 12:47 ` KONRAD Frederic
2017-11-29 12:51 ` Peter Maydell
2017-11-29 15:20 ` KONRAD Frederic
2017-11-29 15:32 ` Thomas Huth
2017-12-06 11:15 ` KONRAD Frederic
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='CAFEAcA8eDeKBnLW45=fPt3NeApMkvkiJzFEshvep_5qmwZKGXA@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=frederic.konrad@adacore.com \
--cc=qemu-devel@nongnu.org \
--cc=wlsaidhi@gmail.com \
/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).