public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Stefan Liebler <stli@linux.vnet.ibm.com>
To: libc-alpha@sourceware.org
Subject: Re: Fix sysdeps/ieee754 pow handling of sNaN arguments (bug 20916) [committed]
Date: Mon, 12 Dec 2016 16:43:00 -0000	[thread overview]
Message-ID: <f3864388-4e9f-73ce-b028-90496fd253cf@linux.vnet.ibm.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1612022321370.1078@digraph.polyomino.org.uk>

On 12/03/2016 12:21 AM, Joseph Myers wrote:
> Various pow function implementations mishandle sNaN arguments in
> various ways.  This includes returning sNaN instead of qNaN for sNaN
> arguments.  For arguments (1, sNaN) and (sNaN, 0), TS 18661-1
> semantics are also that the result should be qNaN, whereas with a qNaN
> argument there the result should be 1, but for the dbl-64
> implementation of pow there are issues with sNaN arguments beyond not
> implementing the TS 18661-1 semantics in those special cases.
>
> This patch makes the implementations in sysdeps/ieee754 follow the TS
> 18661-1 semantics consistently.  Because x86 / x86_64 implementations
> still need fixing, testcases are not included with this patch; they
> will be included with the fix for the x86 / x86_64 versions.
>
> Tested for x86_64, x86, mips64 and powerpc (with such testcases, which
> pass in the mips64 and powerpc cases).  Committed.

Hi Joseph,
on s390, I get test fails in math/test-double / math/test-idouble:
testing double (without inline functions)
Failure: Test: pow (1, sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN
Failure: Test: pow (1, -sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN
Failure: Test: pow_downward (1, sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN
Failure: Test: pow_downward (1, -sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN
Failure: Test: pow_towardzero (1, sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN
Failure: Test: pow_towardzero (1, -sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN
Failure: Test: pow_upward (1, sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN
Failure: Test: pow_upward (1, -sNaN)
Result:
  is:          1.0000000000000000e+00   0x1.0000000000000p+0
  should be:  qNaN

Test suite completed:
   97258 test cases plus 86314 tests for exception flags and
     86314 tests for errno executed.
   8 errors occurred.


I've debugged in sysdeps/ieee754/dbl-64/e_pow.c and recognized that sNaN 
is converted to qNaN in line 85:
       if (y == 0)
	return 1.0;
This comparison is done with a load-and-test instruction from and to the 
same register, which results in a qNaN.
This value is passed to issignaling (y) in line 148:
   if (qy >= 0x7ff00000 && (qy > 0x7ff00000 || v.i[LOW_HALF] != 0))	/* 
NaN */
     return x == 1.0 && !issignaling (y) ? 1.0 : y + y;


 From ieee 754-2008 "6.2 Operations with NaNs":
"Under default exception handling, any operation signaling an invalid 
operation exception and for which a floating-point result is to be 
delivered shall deliver a quiet NaN."

As the used load-and-test instruction delivers a result, I think qNaN is 
correct. But is the compiler allowed to use this instruction for a 
comparision against zero?

How can I get rid of this issue?
Shall I use "if ((v.i[HIGH_HALF] & 0x7fffffff) == 0x0)" on s390?

Bye
Stefan

  reply	other threads:[~2016-12-12 16:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02 23:22 Joseph Myers
2016-12-12 16:43 ` Stefan Liebler [this message]
2016-12-13 21:42   ` Joseph Myers
2016-12-14  9:54     ` Andreas Krebbel
2016-12-14 17:22       ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f3864388-4e9f-73ce-b028-90496fd253cf@linux.vnet.ibm.com \
    --to=stli@linux.vnet.ibm.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).