qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] How to add my implementation of the fmadds instruction


From: Peter Maydell
Subject: Re: [Qemu-devel] How to add my implementation of the fmadds instruction to QEMU
Date: Tue, 27 Sep 2016 04:43:41 -0700

On 26 September 2016 at 18:05, G 3 <address@hidden> wrote:
> I made my own experimental implementation of the fmadds instruction that I
> would like to add to QEMU. How would I do this?
>
> My implementation would probably look like this:
>
> void fmadds(float *frD, float frA, float frC, float frB)
> {
>         *frD = frA * frC + frB;
> }

This isn't portable, because different host CPUs can have
different implementations of floating point arithmetic
with subtle differences (notably in corner cases like
subnormals and also related to the floating point exception
flags). This is why we use the softfloat library in fpu/,
which (although slow) is guaranteed to give the right results.
We did use to have a version of the fpu functions which
used a "just do a C float or double operation", but we
removed it many years ago for this reason.

In particular, for fmadds, it is important that there
is no intermediate rounding done between the multiply
and the addition. This means that you need to effectively
do the multiply and the addition at a higher precision than
the input arguments, so simple multiplication and addition
of floats will give you wrong answers.

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]