On Wed, Jan 23, 2019 at 12:50 PM Joseph Myers <jos...@codesourcery.com> wrote:
>
> On Wed, 23 Jan 2019, H.J. Lu wrote:
>
> > +  fesetround (FE_DOWNWARD);
> > +  float fs = s128;
> > +  if (fs != -0x1p+127)
> > +    abort ();
> > +  double ds = s128;
> > +  if (ds != -0x1p+127)
> > +    abort ();
>
> This definitely needs #ifdef FE_DOWNWARD; even just limited to glibc
> configurations, there are soft-float 64-bit configurations with no support
> for rounding modes other than to-nearest.  Likewise for the other tests
> using rounding modes other than FE_TONEAREST.  OK with that change.
>
> It's possible it will turn out a new effective-target is needed for fenv.h
> support, if there are still configurations people are testing with that
> lack fenv.h at all.
>

This is the patch I am checking in.

Thanks.

-- 
H.J.
From ecb5e6357cff988a6e34aed324f13b777af82deb Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.to...@gmail.com>
Date: Tue, 22 Jan 2019 18:55:35 -0800
Subject: [PATCH] libgcc2.c: Correct DI/TI -> SF/DF conversions

FSTYPE FUNC (DWtype u) in libgcc2.c, which converts DI/TI to SF/DF, has

  /* No leading bits means u == minimum.  */
  if (count == 0)
    return -(Wtype_MAXp1_F * (Wtype_MAXp1_F / 2));

in the third case (where actually count == 0 only means the high part is
minimum).  It should be:

  /* No leading bits means u == minimum.  */
  if (count == 0)
    return Wtype_MAXp1_F * (FSTYPE) (hi | ((UWtype) u != 0));

instead.

gcc/testsuite/

2019-01-23  H.J. Lu  <hongjiu...@intel.com>

	PR libgcc/88931
	* gcc.dg/torture/fp-int-convert-timode-1.c: New test.
	* gcc.dg/torture/fp-int-convert-timode-2.c: Likewise.
	* gcc.dg/torture/fp-int-convert-timode-3.c: Likewise.
	* gcc.dg/torture/fp-int-convert-timode-4.c: Likewise.

libgcc/

2019-01-23  Joseph Myers  <jos...@codesourcery.com>

	PR libgcc/88931
	* libgcc2.c (FSTYPE FUNC (DWtype u)): Correct no leading bits
	case.
---
 .../gcc.dg/torture/fp-int-convert-timode-1.c  | 25 +++++++++++++++++
 .../gcc.dg/torture/fp-int-convert-timode-2.c  | 27 +++++++++++++++++++
 .../gcc.dg/torture/fp-int-convert-timode-3.c  | 27 +++++++++++++++++++
 .../gcc.dg/torture/fp-int-convert-timode-4.c  | 27 +++++++++++++++++++
 libgcc/libgcc2.c                              |  2 +-
 5 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-1.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
 create mode 100644 gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c

diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-1.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-1.c
new file mode 100644
index 00000000000..d6454fada72
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-1.c
@@ -0,0 +1,25 @@
+/* Test for correct rounding of conversions from __int128 to
+   float.  */
+/* { dg-do run } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-frounding-math" } */
+
+#include <fenv.h>
+#include <stdlib.h>
+
+int
+main (void)
+{
+  volatile unsigned long long h = 0x8000000000000000LL;
+  volatile unsigned long long l = 0xdLL;
+  volatile unsigned __int128 u128 = (((unsigned __int128) h) << 64) | l;
+  volatile __int128 s128 = u128;
+  fesetround (FE_TONEAREST);
+  float fs = s128;
+  if (fs != -0x1p+127)
+    abort ();
+  double ds = s128;
+  if (ds != -0x1p+127)
+    abort ();
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
new file mode 100644
index 00000000000..dbfa481b4fb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-2.c
@@ -0,0 +1,27 @@
+/* Test for correct rounding of conversions from __int128 to
+   float.  */
+/* { dg-do run } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-frounding-math" } */
+
+#include <fenv.h>
+#include <stdlib.h>
+
+int
+main (void)
+{
+#ifdef FE_DOWNWARD
+  volatile unsigned long long h = 0x8000000000000000LL;
+  volatile unsigned long long l = 0xdLL;
+  volatile unsigned __int128 u128 = (((unsigned __int128) h) << 64) | l;
+  volatile __int128 s128 = u128;
+  fesetround (FE_DOWNWARD);
+  float fs = s128;
+  if (fs != -0x1p+127)
+    abort ();
+  double ds = s128;
+  if (ds != -0x1p+127)
+    abort ();
+#endif
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
new file mode 100644
index 00000000000..63a305ec3c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-3.c
@@ -0,0 +1,27 @@
+/* Test for correct rounding of conversions from __int128 to
+   float.  */
+/* { dg-do run } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-frounding-math" } */
+
+#include <fenv.h>
+#include <stdlib.h>
+
+int
+main (void)
+{
+#ifdef FE_UPWARD
+  volatile unsigned long long h = 0x8000000000000000LL;
+  volatile unsigned long long l = 0xdLL;
+  volatile unsigned __int128 u128 = (((unsigned __int128) h) << 64) | l;
+  volatile __int128 s128 = u128;
+  fesetround (FE_UPWARD);
+  float fs = s128;
+  if (fs != -0x1.fffffep+126)
+    abort ();
+  double ds = s128;
+  if (ds != -0x1.fffffffffffffp+126)
+    abort ();
+#endif
+  exit (0);
+}
diff --git a/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
new file mode 100644
index 00000000000..e71610995cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/fp-int-convert-timode-4.c
@@ -0,0 +1,27 @@
+/* Test for correct rounding of conversions from __int128 to
+   float.  */
+/* { dg-do run } */
+/* { dg-require-effective-target int128 } */
+/* { dg-options "-frounding-math" } */
+
+#include <fenv.h>
+#include <stdlib.h>
+
+int
+main (void)
+{
+#ifdef FE_TOWARDZERO
+  volatile unsigned long long h = 0x8000000000000000LL;
+  volatile unsigned long long l = 0xdLL;
+  volatile unsigned __int128 u128 = (((unsigned __int128) h) << 64) | l;
+  volatile __int128 s128 = u128;
+  fesetround (FE_TOWARDZERO);
+  float fs = s128;
+  if (fs != -0x1.fffffep+126)
+    abort ();
+  double ds = s128;
+  if (ds != -0x1.fffffffffffffp+126)
+    abort ();
+#endif
+  exit (0);
+}
diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c
index d84f25b0779..04d3185e805 100644
--- a/libgcc/libgcc2.c
+++ b/libgcc/libgcc2.c
@@ -1684,7 +1684,7 @@ FUNC (DWtype u)
 
   /* No leading bits means u == minimum.  */
   if (count == 0)
-    return -(Wtype_MAXp1_F * (Wtype_MAXp1_F / 2));
+    return Wtype_MAXp1_F * (FSTYPE) (hi | ((UWtype) u != 0));
 
   shift = 1 + W_TYPE_SIZE - count;
 
-- 
2.20.1

Reply via email to