This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, PR 57363] IBM long double: adding qNaN and number raises inexact exception
- From: Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Ulrich Weigand <Ulrich dot Weigand at de dot ibm dot com>
- Date: Mon, 18 Nov 2013 17:42:22 -0200
- Subject: Re: [PATCH, PR 57363] IBM long double: adding qNaN and number raises inexact exception
- Authentication-results: sourceware.org; auth=none
- References: <201311152154 dot rAFLsATV024350 at d06av02 dot portsmouth dot uk dot ibm dot com>
On 15-11-2013 19:54, Ulrich Weigand wrote:
> Should this be qNaN instead of sNaN here?
Yes, indeed.
>
> Also, since you already have a test case, I think it would be good to add it
> to the GCC test suite ...
>
> Otherwise, this looks reasonable to me (but I cannot approve the patch):
>
> Bye,
> Ulrich
>
Here it is with updated ChangeLog. Tested on PPC32 and PPC64. The testcase
fails at runtime without the fix with a FLoating-Point Exception.
---
2013-11-15 Adhemerval Zanella <azanella@linux.vnet.ibm.com>
* libgcc/config/rs6000/ibm-ldouble.c (__gcc_qadd): Fix add
of normal number and qNaN to not raise an inexact exception.
* gcc/testsuite/gcc.target/powerpc/pr57363.c: New file: check for
PR#57363.
--
diff --git a/gcc/testsuite/gcc.target/powerpc/pr57363.c b/gcc/testsuite/gcc.target/powerpc/pr57363.c
new file mode 100644
index 0000000..cc9b1d7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/pr57363.c
@@ -0,0 +1,19 @@
+/* { dg-do run { target { powerpc*-*-linux* } } } */
+/* { dg-options "-mlong-double-128" } */
+
+/* Check if adding a sNAN and a normal long double does not generate a
+ inexact exception. */
+
+#define _GNU_SOURCE
+#include <fenv.h>
+
+int main(void)
+{
+ double x = __builtin_nan ("");
+ long double y = 1.1L;
+
+ feenableexcept (FE_INEXACT);
+ feclearexcept (FE_ALL_EXCEPT);
+ x = x + y;
+ return fetestexcept(FE_INEXACT);
+}
diff --git a/libgcc/config/rs6000/ibm-ldouble.c b/libgcc/config/rs6000/ibm-ldouble.c
index 28e02e9..7ca900c 100644
--- a/libgcc/config/rs6000/ibm-ldouble.c
+++ b/libgcc/config/rs6000/ibm-ldouble.c
@@ -104,6 +104,8 @@ __gcc_qadd (double a, double aa, double c, double cc)
if (nonfinite (z))
{
+ if (fabs (z) != inf())
+ return z;
z = cc + aa + c + a;
if (nonfinite (z))
return z;