On 26 September 2016 at 18:05, G 3 <programmingk...@gmail.com> 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