public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work064)] Fix tests that require IBM 128-bit long double
@ 2021-08-13  1:53 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2021-08-13  1:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:41d7377550218066732bf48c548466d3dc2bd72e

commit 41d7377550218066732bf48c548466d3dc2bd72e
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Aug 12 21:52:54 2021 -0400

    Fix tests that require IBM 128-bit long double
    
    This patch adds 3 more selections to target-supports.exp to see if we can
    specify to use a particular long double format (IEEE 128-bit, IBM extended
    double, 64-bit), and the library support will track the changes for the long
    double.  This is needed because two of the tests in the test suite use long
    double, and they are actually testing IBM extended double.
    
    This patch also forces the two tests that explicitly require long double
    to use the IBM double-double encoding to explicitly run the test.  This
    requires GLIBC 2.32 or greater in order to do the switch.
    
    I have run tests on a little endian power9 system with 3 compilers.  There were
    no regressions with these patches, and the two tests in the following patches
    now work if the default long double is not IBM 128-bit:
    
     * One compiler used the default IBM 128-bit format;
     * One compiler used the IEEE 128-bit format; (and)
     * One compiler used 64-bit long doubles.
    
    I have also tested compilers on a big endian power8 system with a compiler
    defaulting to power8 code generation and another with the default cpu
    set.  There were no regressions.
    
    Compared the to last version that I posted, I simplified the fucntion names
    (eliminating the 'ppc_' and 'override_' parts).  I have changed the length
    parameter from using sizeof to just using 16.  I removed the #if code in the
    tests.  I changed the comments.
    
    I did not remove the void * casts in calling memcmp, because not having those
    casts will cause the test to fail.  This is because the variables are declared
    volatile, and GCC now complains that you are discarding the volatile in doing
    the call.  Having this warning makes the test fail.
    
    Can I check this patch into the master branch?
    
    2021-08-12  Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/testsuite/
            PR target/94630
            * gcc.target/powerpc/pr70117.c: Specify that we need the long double
            type to be IBM 128-bit.  Remove the code to use __ibm128.
            * c-c++-common/dfp/convert-bfp-11.c: Specify that we need the long
            double type to be IBM 128-bit.  Run the test at -O2 optimization.
            * lib/target-supports.exp (add_options_for_long_double_ibm128): New
            function.
            (check_effective_target_long_double_ibm128): New function.
            (add_options_for_long_double_ieee128): New function.
            (check_effective_target_long_double_ieee128): New function.
            (add_options_for_long_double_64bit): New function.
            (check_effective_target_long_double_64bit): New function.

Diff:
---
 gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c |  20 +++--
 gcc/testsuite/gcc.target/powerpc/pr70117.c      |  24 ++----
 gcc/testsuite/lib/target-supports.exp           | 110 ++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 24 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
index 95c433d2c24..c09c8342bbb 100644
--- a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
+++ b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
@@ -1,9 +1,16 @@
-/* { dg-skip-if "" { ! "powerpc*-*-linux*" } } */
+/* { dg-require-effective-target dfp } */
 
-/* Test decimal float conversions to and from IBM 128-bit long double. 
-   Checks are skipped at runtime if long double is not 128 bits.
-   Don't force 128-bit long doubles because runtime support depends
-   on glibc.  */
+/* We need the long double type to be IBM 128-bit because the CONVERT_TO_PINF
+   tests will fail if we use IEEE 128-bit floating point.  This is due to IEEE
+   128-bit having a larger exponent range than IBM 128-bit extended double.  So
+   tests that would generate an infinity with IBM 128-bit will generate a
+   normal number with IEEE 128-bit.  */
+
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-O2" } */
+/* { dg-add-options long_double_ibm128 } */
+
+/* Test decimal float conversions to and from IBM 128-bit long double.   */
 
 #include "convert.h"
 
@@ -36,9 +43,6 @@ CONVERT_TO_PINF (312, tf, sd, 1.6e+308L, d32)
 int
 main ()
 {
-  if (sizeof (long double) != 16)
-    return 0;
-
   convert_101 ();
   convert_102 ();
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr70117.c b/gcc/testsuite/gcc.target/powerpc/pr70117.c
index 3bbd2c595e0..4a51f583157 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr70117.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr70117.c
@@ -1,26 +1,18 @@
-/* { dg-do run { target { powerpc*-*-linux* powerpc*-*-darwin* powerpc*-*-aix* rs6000-*-* } } } */
-/* { dg-options "-std=c99 -mlong-double-128 -O2" } */
+/* { dg-do run } */
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-std=c99 -O2" } */
+/* { dg-add-options long_double_ibm128 } */
 
 #include <float.h>
 
-#if defined(__LONG_DOUBLE_IEEE128__)
-/* If long double is IEEE 128-bit, we need to use the __ibm128 type instead of
-   long double.  We can't use __ibm128 on systems that don't support IEEE
-   128-bit floating point, because the type is not enabled on those
-   systems.  */
-#define LDOUBLE __ibm128
-
-#elif defined(__LONG_DOUBLE_IBM128__)
-#define LDOUBLE long double
-
-#else
-#error "long double must be either IBM 128-bit or IEEE 128-bit"
+#ifndef __LONG_DOUBLE_IBM128__
+#error "long double must be IBM 128-bit"
 #endif
 
 union gl_long_double_union
 {
   struct { double hi; double lo; } dd;
-  LDOUBLE ld;
+  long double ld;
 };
 
 /* This is gnulib's LDBL_MAX which, being 107 bits in precision, is
@@ -36,7 +28,7 @@ volatile double dnan = 0.0/0.0;
 int
 main (void)
 {
-  LDOUBLE ld;
+  long double ld;
 
   ld = gl_LDBL_MAX.ld;
   if (__builtin_isinf (ld))
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 44465b14b06..09664e88537 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2360,6 +2360,116 @@ proc check_effective_target_ppc_ieee128_ok { } {
     }]
 }
 
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+
+proc add_options_for_long_double_ibm128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ibmlongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IBM 128-bit extended double format.  Under little endian
+# PowerPC Linux, you need GLIBC 2.32 or later to be able to use a different
+# long double format for running a program than the system default.
+
+proc check_effective_target_long_double_ibm128 { } {
+    return [check_runtime_nocache long_double_ibm128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile __ibm128 a = (__ibm128) 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    } [add_options_for_long_double_ibm128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+proc add_options_for_long_double_ieee128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ieeelongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 128-bit format.  Under little endian PowerPC Linux, you
+# need GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_ieee128 { } {
+    return [check_runtime_nocache long_double_ieee128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile _Float128 a = 3.0f128;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_long_double_ieee128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IEEE
+# 64-bit format on PowerPC.
+
+proc add_options_for_long_double_64bit { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-64"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 64-bit.  Under little endian PowerPC Linux, you need
+# GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_64bit { } {
+    return [check_runtime_nocache long_double_64bit {
+	#include <string.h>
+	#include <stdio.h>
+	volatile double a = 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 8)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_ppc_long_double_override_64bit ""]]
+}
+
 # Return 1 if the target supports executing VSX instructions, 0
 # otherwise.  Cache the result.


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

* [gcc(refs/users/meissner/heads/work064)] Fix tests that require IBM 128-bit long double
@ 2021-08-13  1:12 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2021-08-13  1:12 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:19c3934d39de4f982d5ea2a3cbda757bdd87bc11

commit 19c3934d39de4f982d5ea2a3cbda757bdd87bc11
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Aug 12 21:12:04 2021 -0400

    Fix tests that require IBM 128-bit long double
    
    This patch adds 3 more selections to target-supports.exp to see if we can
    specify to use a particular long double format (IEEE 128-bit, IBM extended
    double, 64-bit), and the library support will track the changes for the long
    double.  This is needed because two of the tests in the test suite use long
    double, and they are actually testing IBM extended double.
    
    This patch also forces the two tests that explicitly require long double
    to use the IBM double-double encoding to explicitly run the test.  This
    requires GLIBC 2.32 or greater in order to do the switch.
    
    I have run tests on a little endian power9 system with 3 compilers.  There were
    no regressions with these patches, and the two tests in the following patches
    now work if the default long double is not IBM 128-bit:
    
     * One compiler used the default IBM 128-bit format;
     * One compiler used the IEEE 128-bit format; (and)
     * One compiler used 64-bit long doubles.
    
    I have also tested compilers on a big endian power8 system with a compiler
    defaulting to power8 code generation and another with the default cpu
    set.  There were no regressions.
    
    Compared the to last version that I posted, I simplified the fucntion names
    (eliminating the 'ppc_' and 'override_' parts).  I have changed the length
    parameter from using sizeof to just using 16.  I removed the #if code in the
    tests.  I changed the comments.
    
    I did not remove the void * casts in calling memcmp, because not having those
    casts will cause the test to fail.  This is because the variables are declared
    volatile, and GCC now complains that you are discarding the volatile in doing
    the call.  Having this warning makes the test fail.
    
    Can I check this patch into the master branch?
    
    2021-08-12  Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/testsuite/
            PR target/94630
            * gcc.target/powerpc/pr70117.c: Specify that we need the long double
            type to be IBM 128-bit.  Remove the code to use __ibm128.
            * c-c++-common/dfp/convert-bfp-11.c: Specify that we need the long
            double type to be IBM 128-bit.  Run the test at -O2 optimization.
            * lib/target-supports.exp (add_options_for_long_double_ibm128): New
            function.
            (check_effective_target_long_double_ibm128): New function.
            (add_options_for_long_double_ieee128): New function.
            (check_effective_target_long_double_ieee128): New function.
            (add_options_for_long_double_64bit): New function.
            (check_effective_target_long_double_64bit): New function.

Diff:
---
 gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c |  20 +++--
 gcc/testsuite/gcc.target/powerpc/pr70117.c      |  24 ++----
 gcc/testsuite/lib/target-supports.exp           | 110 ++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 24 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
index 95c433d2c24..c09c8342bbb 100644
--- a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
+++ b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
@@ -1,9 +1,16 @@
-/* { dg-skip-if "" { ! "powerpc*-*-linux*" } } */
+/* { dg-require-effective-target dfp } */
 
-/* Test decimal float conversions to and from IBM 128-bit long double. 
-   Checks are skipped at runtime if long double is not 128 bits.
-   Don't force 128-bit long doubles because runtime support depends
-   on glibc.  */
+/* We need the long double type to be IBM 128-bit because the CONVERT_TO_PINF
+   tests will fail if we use IEEE 128-bit floating point.  This is due to IEEE
+   128-bit having a larger exponent range than IBM 128-bit extended double.  So
+   tests that would generate an infinity with IBM 128-bit will generate a
+   normal number with IEEE 128-bit.  */
+
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-O2" } */
+/* { dg-add-options long_double_ibm128 } */
+
+/* Test decimal float conversions to and from IBM 128-bit long double.   */
 
 #include "convert.h"
 
@@ -36,9 +43,6 @@ CONVERT_TO_PINF (312, tf, sd, 1.6e+308L, d32)
 int
 main ()
 {
-  if (sizeof (long double) != 16)
-    return 0;
-
   convert_101 ();
   convert_102 ();
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr70117.c b/gcc/testsuite/gcc.target/powerpc/pr70117.c
index 3bbd2c595e0..4a51f583157 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr70117.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr70117.c
@@ -1,26 +1,18 @@
-/* { dg-do run { target { powerpc*-*-linux* powerpc*-*-darwin* powerpc*-*-aix* rs6000-*-* } } } */
-/* { dg-options "-std=c99 -mlong-double-128 -O2" } */
+/* { dg-do run } */
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-std=c99 -O2" } */
+/* { dg-add-options long_double_ibm128 } */
 
 #include <float.h>
 
-#if defined(__LONG_DOUBLE_IEEE128__)
-/* If long double is IEEE 128-bit, we need to use the __ibm128 type instead of
-   long double.  We can't use __ibm128 on systems that don't support IEEE
-   128-bit floating point, because the type is not enabled on those
-   systems.  */
-#define LDOUBLE __ibm128
-
-#elif defined(__LONG_DOUBLE_IBM128__)
-#define LDOUBLE long double
-
-#else
-#error "long double must be either IBM 128-bit or IEEE 128-bit"
+#ifndef __LONG_DOUBLE_IBM128__
+#error "long double must be IBM 128-bit"
 #endif
 
 union gl_long_double_union
 {
   struct { double hi; double lo; } dd;
-  LDOUBLE ld;
+  long double ld;
 };
 
 /* This is gnulib's LDBL_MAX which, being 107 bits in precision, is
@@ -36,7 +28,7 @@ volatile double dnan = 0.0/0.0;
 int
 main (void)
 {
-  LDOUBLE ld;
+  long double ld;
 
   ld = gl_LDBL_MAX.ld;
   if (__builtin_isinf (ld))
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 44465b14b06..09664e88537 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2360,6 +2360,116 @@ proc check_effective_target_ppc_ieee128_ok { } {
     }]
 }
 
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+
+proc add_options_for_long_double_ibm128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ibmlongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IBM 128-bit extended double format.  Under little endian
+# PowerPC Linux, you need GLIBC 2.32 or later to be able to use a different
+# long double format for running a program than the system default.
+
+proc check_effective_target_long_double_ibm128 { } {
+    return [check_runtime_nocache long_double_ibm128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile __ibm128 a = (__ibm128) 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    } [add_options_for_long_double_ibm128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+proc add_options_for_long_double_ieee128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ieeelongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 128-bit format.  Under little endian PowerPC Linux, you
+# need GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_ieee128 { } {
+    return [check_runtime_nocache long_double_ieee128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile _Float128 a = 3.0f128;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_long_double_ieee128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IEEE
+# 64-bit format on PowerPC.
+
+proc add_options_for_long_double_64bit { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-64"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 64-bit.  Under little endian PowerPC Linux, you need
+# GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_64bit { } {
+    return [check_runtime_nocache long_double_64bit {
+	#include <string.h>
+	#include <stdio.h>
+	volatile double a = 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 8)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_ppc_long_double_override_64bit ""]]
+}
+
 # Return 1 if the target supports executing VSX instructions, 0
 # otherwise.  Cache the result.


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

* [gcc(refs/users/meissner/heads/work064)] Fix tests that require IBM 128-bit long double
@ 2021-08-13  0:40 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2021-08-13  0:40 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dd95a61d6605eeef905a467a560cdeb36b76794f

commit dd95a61d6605eeef905a467a560cdeb36b76794f
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Aug 12 20:40:09 2021 -0400

    Fix tests that require IBM 128-bit long double
    
    This patch adds 3 more selections to target-supports.exp to see if we can
    specify to use a particular long double format (IEEE 128-bit, IBM extended
    double, 64-bit), and the library support will track the changes for the long
    double.  This is needed because two of the tests in the test suite use long
    double, and they are actually testing IBM extended double.
    
    This patch also forces the two tests that explicitly require long double
    to use the IBM double-double encoding to explicitly run the test.  This
    requires GLIBC 2.32 or greater in order to do the switch.
    
    I have run tests on a little endian power9 system with 3 compilers.  There were
    no regressions with these patches, and the two tests in the following patches
    now work if the default long double is not IBM 128-bit:
    
     * One compiler used the default IBM 128-bit format;
     * One compiler used the IEEE 128-bit format; (and)
     * One compiler used 64-bit long doubles.
    
    I have also tested compilers on a big endian power8 system with a compiler
    defaulting to power8 code generation and another with the default cpu
    set.  There were no regressions.
    
    Compared the to last version that I posted, I simplified the fucntion names
    (eliminating the 'ppc_' and 'override_' parts).  I have eliminated the void *
    casts to memcmp.  I have changed the length parameter from using sizeof to just
    using 16.  I removed the #if code in the tests.  I changed the comments.
    
    Can I check this patch into the master branch?
    
    2021-08-12  Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/testsuite/
            PR target/94630
            * gcc.target/powerpc/pr70117.c: Specify that we need the long double
            type to be IBM 128-bit.  Remove the code to use __ibm128.
            * c-c++-common/dfp/convert-bfp-11.c: Specify that we need the long
            double type to be IBM 128-bit.  Run the test at -O2 optimization.
            * lib/target-supports.exp (add_options_for_long_double_ibm128): New
            function.
            (check_effective_target_long_double_ibm128): New function.
            (add_options_for_long_double_ieee128): New function.
            (check_effective_target_long_double_ieee128): New function.
            (add_options_for_long_double_64bit): New function.
            (check_effective_target_long_double_64bit): New function.

Diff:
---
 gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c |  20 +++--
 gcc/testsuite/gcc.target/powerpc/pr70117.c      |  24 ++----
 gcc/testsuite/lib/target-supports.exp           | 110 ++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 24 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
index 95c433d2c24..c09c8342bbb 100644
--- a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
+++ b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
@@ -1,9 +1,16 @@
-/* { dg-skip-if "" { ! "powerpc*-*-linux*" } } */
+/* { dg-require-effective-target dfp } */
 
-/* Test decimal float conversions to and from IBM 128-bit long double. 
-   Checks are skipped at runtime if long double is not 128 bits.
-   Don't force 128-bit long doubles because runtime support depends
-   on glibc.  */
+/* We need the long double type to be IBM 128-bit because the CONVERT_TO_PINF
+   tests will fail if we use IEEE 128-bit floating point.  This is due to IEEE
+   128-bit having a larger exponent range than IBM 128-bit extended double.  So
+   tests that would generate an infinity with IBM 128-bit will generate a
+   normal number with IEEE 128-bit.  */
+
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-O2" } */
+/* { dg-add-options long_double_ibm128 } */
+
+/* Test decimal float conversions to and from IBM 128-bit long double.   */
 
 #include "convert.h"
 
@@ -36,9 +43,6 @@ CONVERT_TO_PINF (312, tf, sd, 1.6e+308L, d32)
 int
 main ()
 {
-  if (sizeof (long double) != 16)
-    return 0;
-
   convert_101 ();
   convert_102 ();
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr70117.c b/gcc/testsuite/gcc.target/powerpc/pr70117.c
index 3bbd2c595e0..4a51f583157 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr70117.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr70117.c
@@ -1,26 +1,18 @@
-/* { dg-do run { target { powerpc*-*-linux* powerpc*-*-darwin* powerpc*-*-aix* rs6000-*-* } } } */
-/* { dg-options "-std=c99 -mlong-double-128 -O2" } */
+/* { dg-do run } */
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-std=c99 -O2" } */
+/* { dg-add-options long_double_ibm128 } */
 
 #include <float.h>
 
-#if defined(__LONG_DOUBLE_IEEE128__)
-/* If long double is IEEE 128-bit, we need to use the __ibm128 type instead of
-   long double.  We can't use __ibm128 on systems that don't support IEEE
-   128-bit floating point, because the type is not enabled on those
-   systems.  */
-#define LDOUBLE __ibm128
-
-#elif defined(__LONG_DOUBLE_IBM128__)
-#define LDOUBLE long double
-
-#else
-#error "long double must be either IBM 128-bit or IEEE 128-bit"
+#ifndef __LONG_DOUBLE_IBM128__
+#error "long double must be IBM 128-bit"
 #endif
 
 union gl_long_double_union
 {
   struct { double hi; double lo; } dd;
-  LDOUBLE ld;
+  long double ld;
 };
 
 /* This is gnulib's LDBL_MAX which, being 107 bits in precision, is
@@ -36,7 +28,7 @@ volatile double dnan = 0.0/0.0;
 int
 main (void)
 {
-  LDOUBLE ld;
+  long double ld;
 
   ld = gl_LDBL_MAX.ld;
   if (__builtin_isinf (ld))
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 44465b14b06..70ac58c2c3b 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2360,6 +2360,116 @@ proc check_effective_target_ppc_ieee128_ok { } {
     }]
 }
 
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+
+proc add_options_for_long_double_ibm128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ibmlongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IBM 128-bit extended double format.  Under little endian
+# PowerPC Linux, you need GLIBC 2.32 or later to be able to use a different
+# long double format for running a program than the system default.
+
+proc check_effective_target_long_double_ibm128 { } {
+    return [check_runtime_nocache long_double_ibm128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile __ibm128 a = (__ibm128) 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    } [add_options_for_long_double_ibm128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+proc add_options_for_long_double_ieee128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ieeelongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 128-bit format.  Under little endian PowerPC Linux, you
+# need GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_ieee128 { } {
+    return [check_runtime_nocache long_double_ieee128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile _Float128 a = 3.0f128;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_long_double_ieee128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IEEE
+# 64-bit format on PowerPC.
+
+proc add_options_for_long_double_64bit { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-64"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 64-bit.  Under little endian PowerPC Linux, you need
+# GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_64bit { } {
+    return [check_runtime_nocache long_double_64bit {
+	#include <string.h>
+	#include <stdio.h>
+	volatile double a = 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 8)
+	    return 1;
+	  b = one + two;
+	  if (memcmp ((void *)&a, (void *)&b, 8) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_ppc_long_double_override_64bit ""]]
+}
+
 # Return 1 if the target supports executing VSX instructions, 0
 # otherwise.  Cache the result.


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

* [gcc(refs/users/meissner/heads/work064)] Fix tests that require IBM 128-bit long double
@ 2021-08-12 21:55 Michael Meissner
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Meissner @ 2021-08-12 21:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:271c755b6e4062a777cdd23a5d85842048411229

commit 271c755b6e4062a777cdd23a5d85842048411229
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Aug 12 17:54:53 2021 -0400

    Fix tests that require IBM 128-bit long double
    
    This patch adds 3 more selections to target-supports.exp to see if we can
    specify to use a particular long double format (IEEE 128-bit, IBM extended
    double, 64-bit), and the library support will track the changes for the long
    double.  This is needed because two of the tests in the test suite use long
    double, and they are actually testing IBM extended double.
    
    This patch also forces the two tests that explicitly require long double
    to use the IBM double-double encoding to explicitly run the test.  This
    requires GLIBC 2.32 or greater in order to do the switch.
    
    I have run tests on a little endian power9 system with 3 compilers.  There were
    no regressions with these patches, and the two tests in the following patches
    now work if the default long double is not IBM 128-bit:
    
     * One compiler used the default IBM 128-bit format;
     * One compiler used the IEEE 128-bit format; (and)
     * One compiler used 64-bit long doubles.
    
    I have also tested compilers on a big endian power8 system with a compiler
    defaulting to power8 code generation and another with the default cpu
    set.  There were no regressions.
    
    Compared the to last version that I posted, I simplified the fucntion names
    (eliminating the 'ppc_' and 'override_' parts).  I have eliminated the void *
    casts to memcmp.  I have changed the length parameter from using sizeof to just
    using 16.  I removed the #if code in the tests.  I changed the comments.
    
    Can I check this patch into the master branch?
    
    2021-08-12  Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/testsuite/
            PR target/94630
            * gcc.target/powerpc/pr70117.c: Specify that we need the long double
            type to be IBM 128-bit.  Remove the code to use __ibm128.
            * c-c++-common/dfp/convert-bfp-11.c: Specify that we need the long
            double type to be IBM 128-bit.  Run the test at -O2 optimization.
            * lib/target-supports.exp (add_options_for_long_double_ibm128): New
            function.
            (check_effective_target_long_double_ibm128): New function.
            (add_options_for_long_double_ieee128): New function.
            (check_effective_target_long_double_ieee128): New function.
            (add_options_for_long_double_64bit): New function.
            (check_effective_target_long_double_64bit): New function.

Diff:
---
 gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c |  20 +++--
 gcc/testsuite/gcc.target/powerpc/pr70117.c      |  24 ++----
 gcc/testsuite/lib/target-supports.exp           | 110 ++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 24 deletions(-)

diff --git a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
index 95c433d2c24..c09c8342bbb 100644
--- a/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
+++ b/gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c
@@ -1,9 +1,16 @@
-/* { dg-skip-if "" { ! "powerpc*-*-linux*" } } */
+/* { dg-require-effective-target dfp } */
 
-/* Test decimal float conversions to and from IBM 128-bit long double. 
-   Checks are skipped at runtime if long double is not 128 bits.
-   Don't force 128-bit long doubles because runtime support depends
-   on glibc.  */
+/* We need the long double type to be IBM 128-bit because the CONVERT_TO_PINF
+   tests will fail if we use IEEE 128-bit floating point.  This is due to IEEE
+   128-bit having a larger exponent range than IBM 128-bit extended double.  So
+   tests that would generate an infinity with IBM 128-bit will generate a
+   normal number with IEEE 128-bit.  */
+
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-O2" } */
+/* { dg-add-options long_double_ibm128 } */
+
+/* Test decimal float conversions to and from IBM 128-bit long double.   */
 
 #include "convert.h"
 
@@ -36,9 +43,6 @@ CONVERT_TO_PINF (312, tf, sd, 1.6e+308L, d32)
 int
 main ()
 {
-  if (sizeof (long double) != 16)
-    return 0;
-
   convert_101 ();
   convert_102 ();
 
diff --git a/gcc/testsuite/gcc.target/powerpc/pr70117.c b/gcc/testsuite/gcc.target/powerpc/pr70117.c
index 3bbd2c595e0..4a51f583157 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr70117.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr70117.c
@@ -1,26 +1,18 @@
-/* { dg-do run { target { powerpc*-*-linux* powerpc*-*-darwin* powerpc*-*-aix* rs6000-*-* } } } */
-/* { dg-options "-std=c99 -mlong-double-128 -O2" } */
+/* { dg-do run } */
+/* { dg-require-effective-target long_double_ibm128 } */
+/* { dg-options "-std=c99 -O2" } */
+/* { dg-add-options long_double_ibm128 } */
 
 #include <float.h>
 
-#if defined(__LONG_DOUBLE_IEEE128__)
-/* If long double is IEEE 128-bit, we need to use the __ibm128 type instead of
-   long double.  We can't use __ibm128 on systems that don't support IEEE
-   128-bit floating point, because the type is not enabled on those
-   systems.  */
-#define LDOUBLE __ibm128
-
-#elif defined(__LONG_DOUBLE_IBM128__)
-#define LDOUBLE long double
-
-#else
-#error "long double must be either IBM 128-bit or IEEE 128-bit"
+#ifndef __LONG_DOUBLE_IBM128__
+#error "long double must be IBM 128-bit"
 #endif
 
 union gl_long_double_union
 {
   struct { double hi; double lo; } dd;
-  LDOUBLE ld;
+  long double ld;
 };
 
 /* This is gnulib's LDBL_MAX which, being 107 bits in precision, is
@@ -36,7 +28,7 @@ volatile double dnan = 0.0/0.0;
 int
 main (void)
 {
-  LDOUBLE ld;
+  long double ld;
 
   ld = gl_LDBL_MAX.ld;
   if (__builtin_isinf (ld))
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 44465b14b06..1b352107c6c 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2360,6 +2360,116 @@ proc check_effective_target_ppc_ieee128_ok { } {
     }]
 }
 
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+
+proc add_options_for_long_double_ibm128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ibmlongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IBM 128-bit extended double format.  Under little endian
+# PowerPC Linux, you need GLIBC 2.32 or later to be able to use a different
+# long double format for running a program than the system default.
+
+proc check_effective_target_long_double_ibm128 { } {
+    return [check_runtime_nocache long_double_ibm128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile __ibm128 a = (__ibm128) 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp (&a, &b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    } [add_options_for_long_double_ibm128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IBM
+# 128-bit format on PowerPC.
+proc add_options_for_long_double_ieee128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ieeelongdouble"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 128-bit format.  Under little endian PowerPC Linux, you
+# need GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_ieee128 { } {
+    return [check_runtime_nocache long_double_ieee128 {
+	#include <string.h>
+	#include <stdio.h>
+	volatile _Float128 a = 3.0f128;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 16)
+	    return 1;
+	  b = one + two;
+	  if (memcmp (&a, &b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_long_double_ieee128 ""]]
+}
+
+# Return the appropriate options to specify that long double uses the IEEE
+# 64-bit format on PowerPC.
+
+proc add_options_for_long_double_64bit { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-64"
+    }
+    return "$flags"
+}
+
+# Check if GCC and GLIBC supports explicitly specifying that the long double
+# format uses the IEEE 64-bit.  Under little endian PowerPC Linux, you need
+# GLIBC 2.32 or later to be able to use a different long double format for
+# running a program than the system default.
+
+proc check_effective_target_long_double_64bit { } {
+    return [check_runtime_nocache long_double_64bit {
+	#include <string.h>
+	#include <stdio.h>
+	volatile double a = 3.0;
+	volatile long double one = 1.0L;
+	volatile long double two = 2.0L;
+	volatile long double b;
+	char buffer[20];
+	int main()
+	{
+	  if (sizeof (long double) != 8)
+	    return 1;
+	  b = one + two;
+	  if (memcmp (&a, &b, 16) != 0)
+	    return 1;
+	  sprintf (buffer, "%lg", b);
+	  return strcmp (buffer, "3") != 0;
+	}
+    }  [add_options_for_ppc_long_double_override_64bit ""]]
+}
+
 # Return 1 if the target supports executing VSX instructions, 0
 # otherwise.  Cache the result.


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

end of thread, other threads:[~2021-08-13  1:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13  1:53 [gcc(refs/users/meissner/heads/work064)] Fix tests that require IBM 128-bit long double Michael Meissner
  -- strict thread matches above, loose matches on Subject: below --
2021-08-13  1:12 Michael Meissner
2021-08-13  0:40 Michael Meissner
2021-08-12 21:55 Michael Meissner

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).