public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/18104] New: powerpc: Incorrect results for pow when using FMA
@ 2015-03-10 13:35 azanella at linux dot vnet.ibm.com
  2015-03-10 13:36 ` [Bug math/18104] " azanella at linux dot vnet.ibm.com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: azanella at linux dot vnet.ibm.com @ 2015-03-10 13:35 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18104

            Bug ID: 18104
           Summary: powerpc: Incorrect results for pow when using FMA
           Product: glibc
           Version: 2.20
            Status: NEW
          Severity: normal
          Priority: P2
         Component: math
          Assignee: unassigned at sourceware dot org
          Reporter: azanella at linux dot vnet.ibm.com

Checking on a internal issue report, the following testcase is showing
precision errors only for powerpc builds:

--

#include <math.h>
#include <mpfr.h>

int main ()
{
  union Di
  {
    double d;
    unsigned long long i;
  };
  union Di x;
  x.i = 0x553B9BA800000000LL;

  mpfr_t xm;
  mpfr_init2 (xm, 512);
  mpfr_set_d (xm, x.d, MPFR_RNDD);

  mpfr_t squarem;
  mpfr_init2 (squarem, 512);
  mpfr_mul (squarem, xm, xm, MPFR_RNDD);

  double square = x.d * x.d;

  mpfr_printf ("mpfr: x*x   = %.17Re\n", squarem);
  mpfr_printf ("    : x*x   = %.17e\n", square);

  mpfr_t cubem;
  mpfr_init2 (cubem, 512);
  mpfr_mul (cubem, squarem, xm, MPFR_RNDD);

  double cube = square * x.d;

  mpfr_printf ("mpfr: x*x*x = %.17Re\n", cubem);
  mpfr_printf ("    : x*x*x = %.17e\n", cube);

  mpfr_t powm;
  mpfr_init2 (powm, 512);
  mpfr_t onehalfm;
  mpfr_init2 (onehalfm, 512);
  mpfr_set_d (onehalfm, 1.5, MPFR_RNDD);
  mpfr_pow (powm, squarem, onehalfm, MPFR_RNDD);

  double powc = pow (square, 1.5);

  mpfr_printf ("mpfr: pow (x*x, 1.5) = %.17Re\n", powm);
  mpfr_printf ("libc: pow (x*x, 1.5) = %.17e\n", powc);

  return 0;
}

--

With current master I am seeing:

$ ./testrun.sh ./test-mpfr 
mpfr: x*x   = 1.49357829132402765e+205
    : x*x   = 1.49357829132402765e+205
mpfr: x*x*x = 5.77220822056602683e+307
    : x*x*x = 5.77220822056602633e+307
mpfr: pow (x*x, 1.5) = 5.77220822056602683e+307
libc: pow (x*x, 1.5) = 5.77220822056619098e+307

While I would expect the mpfr and libc pow result to have the same precision,
as for x86_64.

At first I though it was a compiler bug, bug looking into this deeper, this is
probably a GLIBC build issue.  The difference between the power1() -O1
assembler code and -O2 is that the -O2 code makes use of FMA instructions. This
causes a slight difference in values of the second param to the __exp1()
function call.  The __exp1() return value in teh -O1 case returns a invalid
value which forces us to call __slow_pow() leading to the "expected" value. 

In the -O2 case, the __exp1() value is considered valid and we just return 
it as is, leading to the slight difference in values.

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. I would suggest the following 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

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug math/18104] powerpc: Incorrect results for pow when using FMA
  2015-03-10 13:35 [Bug math/18104] New: powerpc: Incorrect results for pow when using FMA azanella at linux dot vnet.ibm.com
@ 2015-03-10 13:36 ` azanella at linux dot vnet.ibm.com
  2015-03-10 14:05 ` zatrazz at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: azanella at linux dot vnet.ibm.com @ 2015-03-10 13:36 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18104

Adhemerval Zanella Netto <azanella at linux dot vnet.ibm.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |azanella at linux dot vnet.ibm.com

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug math/18104] powerpc: Incorrect results for pow when using FMA
  2015-03-10 13:35 [Bug math/18104] New: powerpc: Incorrect results for pow when using FMA azanella at linux dot vnet.ibm.com
  2015-03-10 13:36 ` [Bug math/18104] " azanella at linux dot vnet.ibm.com
@ 2015-03-10 14:05 ` zatrazz at gmail dot com
  2015-03-10 17:54 ` cvs-commit at gcc dot gnu.org
  2015-09-24 16:50 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: zatrazz at gmail dot com @ 2015-03-10 14:05 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18104

Adhemerval Zanella Netto <zatrazz at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #1 from Adhemerval Zanella Netto <zatrazz at gmail dot com> ---
Fixed upstream by d421868bb85d1459b1d2df520bb26f3e11aa195a.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug math/18104] powerpc: Incorrect results for pow when using FMA
  2015-03-10 13:35 [Bug math/18104] New: powerpc: Incorrect results for pow when using FMA azanella at linux dot vnet.ibm.com
  2015-03-10 13:36 ` [Bug math/18104] " azanella at linux dot vnet.ibm.com
  2015-03-10 14:05 ` zatrazz at gmail dot com
@ 2015-03-10 17:54 ` cvs-commit at gcc dot gnu.org
  2015-09-24 16:50 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2015-03-10 17:54 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18104

--- Comment #2 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  6411f81da9ffcad6b90dba9be1b89ffccfd80ca2 (commit)
      from  d421868bb85d1459b1d2df520bb26f3e11aa195a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6411f81da9ffcad6b90dba9be1b89ffccfd80ca2

commit 6411f81da9ffcad6b90dba9be1b89ffccfd80ca2
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Tue Mar 10 17:53:40 2015 +0000

    Add test for bug 18104.

        [BZ #18104]
        * math/auto-libm-test-in: Add another test of pow.
        * math/auto-libm-test-out: Regenerated.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog               |    6 ++++++
 math/auto-libm-test-in  |    1 +
 math/auto-libm-test-out |   45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 0 deletions(-)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug math/18104] powerpc: Incorrect results for pow when using FMA
  2015-03-10 13:35 [Bug math/18104] New: powerpc: Incorrect results for pow when using FMA azanella at linux dot vnet.ibm.com
                   ` (2 preceding siblings ...)
  2015-03-10 17:54 ` cvs-commit at gcc dot gnu.org
@ 2015-09-24 16:50 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2015-09-24 16:50 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18104

--- Comment #4 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  51df2605064a2bfd44fa0655ef9815812347de80 (commit)
      from  24ffcbfc24e08212cc5b1fa8318940e75b06313c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=51df2605064a2bfd44fa0655ef9815812347de80

commit 51df2605064a2bfd44fa0655ef9815812347de80
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Thu Sep 24 16:48:32 2015 +0000

    Fix x86_64 fma4 pow inappropriate contraction (bug 19003).

    The x86_64 fma4 version of pow fails to disable contraction of
    operations other than those explicitly intended to use fma
    instructions, so resulting in large ulps errors on processors with
    fma4 instructions, as in bug 18104 (165ulp for the test added for that
    bug; error originally reported by "blaaa" on #glibc).  This patch adds
    $(config-cflags-nofma) for e_pow-fma4.c, corresponding to the use for
    e_pow.c in sysdeps/ieee754/dbl-64/Makefile.

    Tested for x86_64 on a processor with fma4.

        [BZ #19003]
        * sysdeps/x86_64/fpu/multiarch/Makefile (CFLAGS-e_pow-fma4.c): Add
        $(config-cflags-nofma).

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                             |    6 ++++++
 NEWS                                  |    2 +-
 sysdeps/x86_64/fpu/multiarch/Makefile |    2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-24 16:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-10 13:35 [Bug math/18104] New: powerpc: Incorrect results for pow when using FMA azanella at linux dot vnet.ibm.com
2015-03-10 13:36 ` [Bug math/18104] " azanella at linux dot vnet.ibm.com
2015-03-10 14:05 ` zatrazz at gmail dot com
2015-03-10 17:54 ` cvs-commit at gcc dot gnu.org
2015-09-24 16:50 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).