RFC: powerpc: Incorrect results for pow when using FMA
Adhemerval Zanella
azanella@linux.vnet.ibm.com
Mon Mar 9 19:46:00 GMT 2015
On 09-03-2015 16:38, Szabolcs Nagy wrote:
>
> On 09/03/15 19:13, Adhemerval Zanella wrote:
>> If I look at the comments at the top of the source file (sysdeps/ieee754/dbl-64/e_pow.c)
>> where the power1() function lives, I see this comment:
>>
>> /* Assumption: Machine arithmetic operations are performed in */
>> /* round to nearest mode of IEEE 754 standard. */
>>
>> It would seem to me that using FMAs would violate the assumption stated in that comment,
>> since some of the internal FAM ops are not rounded before being used. I do notice that
>> if I add the -ffp-contract=off, then we get the "expected" answer. Is the "correct"
>> fix just to get this file compiled with -ffp-contract=off?
>>
> yes fma can break fp arithmetics that assume exact ieee semantics
>
> if compilers had proper iso c support then
>
> #pragma STDC FP_CONTRACT OFF
>
> in the affected functions would solve the problem
>
> (actually i'm not sure if it is supported now, but
> i'd add the pragma anyway for documentation and
> for future standard conforming compilers)
>
Right, but I think for GLIBC this is not usual way. I would suggest the followin
fix:
diff --git a/sysdeps/ieee754/dbl-64/Makefile b/sysdeps/ieee754/dbl-64/Makefile
index 35f545f..5557c75 100644
--- a/sysdeps/ieee754/dbl-64/Makefile
+++ b/sysdeps/ieee754/dbl-64/Makefile
@@ -2,4 +2,5 @@ ifeq ($(subdir),math)
# branred depends on precise IEEE double rounding
CFLAGS-branred.c = $(config-cflags-nofma)
CFLAGS-e_sqrt.c = $(config-cflags-nofma)
+CFLAGS-e_pow.c = $(config-cflags-nofma)
endif
More information about the Libc-alpha
mailing list