This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: RFC: powerpc: Incorrect results for pow when using FMA
- From: Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- To: Szabolcs Nagy <szabolcs dot nagy at arm dot com>
- Cc: "GNU C. Library" <libc-alpha at sourceware dot org>
- Date: Mon, 09 Mar 2015 16:46:44 -0300
- Subject: Re: RFC: powerpc: Incorrect results for pow when using FMA
- Authentication-results: sourceware.org; auth=none
- References: <54FDF0E1 dot 5090900 at linux dot vnet dot ibm dot com> <54FDF6AB dot 6030705 at arm dot com>
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