RFC: powerpc: Incorrect results for pow when using FMA

Message ID 54FDF8A4.5060100@linux.vnet.ibm.com
State Committed
Delegated to: Adhemerval Zanella Netto
Headers

Commit Message

Adhemerval Zanella Netto March 9, 2015, 7:46 p.m. UTC
  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:
  

Comments

Joseph Myers March 9, 2015, 10:50 p.m. UTC | #1
On Mon, 9 Mar 2015, Adhemerval Zanella wrote:

> 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

OK (with ChangeLog entry and bug filed in Bugzilla as usual).
  

Patch

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