public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work058)] Fix long double tests when default long double is not IBM.
@ 2021-07-04  5:09 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2021-07-04  5:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:85e40285688666de932f74b976dd03cd1c61e04f

commit 85e40285688666de932f74b976dd03cd1c61e04f
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Sun Jul 4 01:09:11 2021 -0400

    Fix long double tests when default long double is not IBM.
    
    This patch adds 3 more selections to target-supports.exp to see if we can force
    the compiler 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.
    
    Can I check this patch into the master branch?
    
    gcc/testsuite/
    2021-07-04  Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/70117
            * gcc.target/powerpc/pr70117.c: Force the long double type to use
            the IBM 128-bit format.
            * c-c++-common/dfp/convert-bfp-11.c: Force using IBM 128-bit long
            double.  Remove check for 64-bit long double.
            * lib/target-supports.exp
            (add_options_for_ppc_long_double_override_ibm128): New function.
            (check_effective_target_ppc_long_double_override_ibm128): New
            function.
            (add_options_for_ppc_long_double_override_ieee128): New function.
            (check_effective_target_ppc_long_double_override_ieee128): New
            function.
            (add_options_for_ppc_long_double_override_64bit): New function.
            (check_effective_target_ppc_long_double_override_64bit): New
            function.

Diff:
---
 gcc/testsuite/c-c++-common/dfp/convert-bfp-11.c |  18 ++--
 gcc/testsuite/gcc.target/powerpc/pr70117.c      |   6 +-
 gcc/testsuite/lib/target-supports.exp           | 107 ++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 10 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..35da07d1fa4 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,14 @@
-/* { dg-skip-if "" { ! "powerpc*-*-linux*" } } */
+/* { dg-require-effective-target dfp } */
+/* { dg-require-effective-target ppc_long_double_override_ibm128 } */
+/* { dg-add-options ppc_long_double_override_ibm128 } */
 
-/* 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 force 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.  */
+
+/* Test decimal float conversions to and from IBM 128-bit long double.   */
 
 #include "convert.h"
 
@@ -36,9 +41,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..8a5fad1dee0 100644
--- a/gcc/testsuite/gcc.target/powerpc/pr70117.c
+++ b/gcc/testsuite/gcc.target/powerpc/pr70117.c
@@ -1,5 +1,7 @@
-/* { 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 ppc_long_double_override_ibm128 } */
+/* { dg-options "-std=c99 -O2" } */
+/* { dg-add-options ppc_long_double_override_ibm128 } */
 
 #include <float.h>
 
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 789723fb287..0a392cb0fd5 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -2360,6 +2360,113 @@ proc check_effective_target_ppc_ieee128_ok { } {
     }]
 }
 
+# Check if we can explicitly override the long double format to use the IBM
+# 128-bit extended double format, and GLIBC supports doing this override by
+# switching the sprintf to handle IBM 128-bit long double.
+
+proc add_options_for_ppc_long_double_override_ibm128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ibmlongdouble"
+    }
+    return "$flags"
+}
+
+proc check_effective_target_ppc_long_double_override_ibm128 { } {
+    return [check_runtime_nocache ppc_long_double_override_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 !defined(_ARCH_PPC) || !defined(__LONG_DOUBLE_IBM128__)
+	    return 1;
+	  #else
+	    b = one + two;
+	    if (memcmp ((void *)&a, (void *)&b, sizeof (long double)) != 0)
+	      return 1;
+	    sprintf (buffer, "%lg", b);
+	    return strcmp (buffer, "3") != 0;
+	  #endif
+	}
+    } [add_options_for_ppc_long_double_override_ibm128 ""]]
+}
+
+# Check if we can explicitly override the long double format to use the IEEE
+# 128-bit format, and GLIBC supports doing this override by switching the
+# sprintf to handle IEEE 128-bit long double.
+
+proc add_options_for_ppc_long_double_override_ieee128 { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-128 -Wno-psabi -mabi=ieeelongdouble"
+    }
+    return "$flags"
+}
+
+proc check_effective_target_ppc_long_double_override_ieee128 { } {
+    return [check_runtime_nocache ppc_long_double_override_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 !defined(_ARCH_PPC) || !defined(__LONG_DOUBLE_IEEE128__)
+	    return 1;
+	  #else
+	    b = one + two;
+	    if (memcmp ((void *)&a, (void *)&b, sizeof (long double)) != 0)
+	      return 1;
+	    sprintf (buffer, "%lg", b);
+	    return strcmp (buffer, "3") != 0;
+	  #endif
+	}
+    }  [add_options_for_ppc_long_double_override_ieee128 ""]]
+}
+
+# Check if we can explicitly override the long double format to use 64-bit
+# floating point, and GLIBC supports doing this override by switching the
+# sprintf to handle 64-bit long double.
+
+proc add_options_for_ppc_long_double_override_64bit { flags } {
+    if { [istarget powerpc*-*-*] } {
+	return "$flags -mlong-double-64"
+    }
+    return "$flags"
+}
+
+proc check_effective_target_ppc_long_double_override_64bit { } {
+    return [check_runtime_nocache ppc_long_double_override_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 !defined(_ARCH_PPC) || defined(__LONG_DOUBLE_128__)
+	    return 1;
+	  #else
+	    if (sizeof (long double) != sizeof (double))
+	      return 1;
+	    b = one + two;
+	    if (memcmp ((void *)&a, (void *)&b, sizeof (long double)) != 0)
+	      return 1;
+	    sprintf (buffer, "%lg", b);
+	    return strcmp (buffer, "3") != 0;
+	  #endif
+	}
+    }  [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] 2+ messages in thread

* [gcc(refs/users/meissner/heads/work058)] Fix long double tests when default long double is not IBM.
@ 2021-07-04  5:10 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2021-07-04  5:10 UTC (permalink / raw)
  To: gcc-cvs

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

commit aaab3bfb1c3bec3ef6f2cd6ccb32c52b90d17ed2
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Sun Jul 4 01:10:25 2021 -0400

    Fix long double tests when default long double is not IBM.
    
    This patch adds 3 more selections to target-supports.exp to see if we can force
    the compiler 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.
    
    Can I check this patch into the master branch?
    
    gcc/testsuite/
    2021-07-04  Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/70117
            * gcc.target/powerpc/pr70117.c: Force the long double type to use
            the IBM 128-bit format.
            * c-c++-common/dfp/convert-bfp-11.c: Force using IBM 128-bit long
            double.  Remove check for 64-bit long double.
            * lib/target-supports.exp
            (add_options_for_ppc_long_double_override_ibm128): New function.
            (check_effective_target_ppc_long_double_override_ibm128): New
            function.
            (add_options_for_ppc_long_double_override_ieee128): New function.
            (check_effective_target_ppc_long_double_override_ieee128): New
            function.
            (add_options_for_ppc_long_double_override_64bit): New function.
            (check_effective_target_ppc_long_double_override_64bit): New
            function.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.def |  5 ++---
 gcc/config/rs6000/rs6000-call.c      | 14 ++++++++++----
 gcc/config/rs6000/rs6000.c           |  4 ++--
 gcc/config/rs6000/rs6000.h           | 12 +++++++++---
 libgcc/config/rs6000/ibm-ldouble.c   |  4 ++--
 5 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.def b/gcc/config/rs6000/rs6000-builtin.def
index d7ce4de421e..a3f8d1cba1a 100644
--- a/gcc/config/rs6000/rs6000-builtin.def
+++ b/gcc/config/rs6000/rs6000-builtin.def
@@ -796,13 +796,12 @@
 		     | RS6000_BTC_BINARY),				\
 		    CODE_FOR_ ## ICODE)			/* ICODE */
 
-/* 128-bit __ibm128 floating point builtins (use -mfloat128 to indicate that
-   __ibm128 is available).  */
+/* 128-bit __ibm128 floating point builtins.  */
 #define BU_IBM128_2(ENUM, NAME, ATTR, ICODE)				\
   RS6000_BUILTIN_2 (MISC_BUILTIN_ ## ENUM,		/* ENUM */	\
 		    "__builtin_" NAME,			/* NAME */	\
 		    (RS6000_BTM_HARD_FLOAT		/* MASK */	\
-		     | RS6000_BTM_FLOAT128),				\
+		     | RS6000_BTM_IBM128),				\
 		    (RS6000_BTC_ ## ATTR		/* ATTR */	\
 		     | RS6000_BTC_BINARY),				\
 		    CODE_FOR_ ## ICODE)			/* ICODE */
diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c
index b67789845a5..7e08b4dfa22 100644
--- a/gcc/config/rs6000/rs6000-call.c
+++ b/gcc/config/rs6000/rs6000-call.c
@@ -11652,8 +11652,8 @@ rs6000_invalid_builtin (enum rs6000_builtins fncode)
     error ("%qs requires the %qs option", name, "-mhard-float");
   else if ((fnmask & RS6000_BTM_FLOAT128_HW) != 0)
     error ("%qs requires ISA 3.0 IEEE 128-bit floating point", name);
-  else if ((fnmask & RS6000_BTM_FLOAT128) != 0)
-    error ("%qs requires the %qs option", name, "%<-mfloat128%>");
+  else if ((fnmask & RS6000_BTM_IBM128) != 0)
+    error ("%qs requires the IBM 128-bit floating point", name);
   else if ((fnmask & (RS6000_BTM_POPCNTD | RS6000_BTM_POWERPC64))
 	   == (RS6000_BTM_POPCNTD | RS6000_BTM_POWERPC64))
     error ("%qs requires the %qs (or newer), and %qs or %qs options",
@@ -13356,7 +13356,7 @@ rs6000_init_builtins (void)
      For IEEE 128-bit floating point, always create the type __ieee128.  If the
      user used -mfloat128, rs6000-c.c will create a define from __float128 to
      __ieee128.  */
-  if (TARGET_FLOAT128_TYPE)
+  if (TARGET_IBM128)
     {
       if (!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128)
 	ibm128_float_type_node = long_double_type_node;
@@ -13370,7 +13370,13 @@ rs6000_init_builtins (void)
 
       lang_hooks.types.register_builtin_type (ibm128_float_type_node,
 					      "__ibm128");
+    }
+
+  else
+    ibm128_float_type_node = long_double_type_node;
 
+  if (TARGET_FLOAT128_TYPE)
+    {
       if (TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128)
 	ieee128_float_type_node = long_double_type_node;
       else
@@ -13381,7 +13387,7 @@ rs6000_init_builtins (void)
     }
 
   else
-    ieee128_float_type_node = ibm128_float_type_node = long_double_type_node;
+    ieee128_float_type_node = long_double_type_node;
 
   /* Vector pair and vector quad support.  */
   if (TARGET_EXTRA_BUILTINS)
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 26395b65ae8..cdc329b2fee 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -3428,7 +3428,7 @@ rs6000_builtin_mask_calculate (void)
 	  | ((TARGET_LONG_DOUBLE_128
 	      && TARGET_HARD_FLOAT
 	      && !TARGET_IEEEQUAD)	    ? RS6000_BTM_LDBL128   : 0)
-	  | ((TARGET_FLOAT128_TYPE)	    ? RS6000_BTM_FLOAT128  : 0)
+	  | ((TARGET_IBM128)		    ? RS6000_BTM_IBM128    : 0)
 	  | ((TARGET_FLOAT128_HW)	    ? RS6000_BTM_FLOAT128_HW : 0)
 	  | ((TARGET_MMA)		    ? RS6000_BTM_MMA	   : 0)
 	  | ((TARGET_POWER10)               ? RS6000_BTM_P10       : 0));
@@ -24225,7 +24225,7 @@ static struct rs6000_opt_mask const rs6000_builtin_mask_names[] =
   { "hard-float",	 RS6000_BTM_HARD_FLOAT,	false, false },
   { "long-double-128",	 RS6000_BTM_LDBL128,	false, false },
   { "powerpc64",	 RS6000_BTM_POWERPC64,  false, false },
-  { "float128",		 RS6000_BTM_FLOAT128,   false, false },
+  { "ibm128",		 RS6000_BTM_IBM128,     false, false },
   { "float128-hw",	 RS6000_BTM_FLOAT128_HW,false, false },
   { "mma",		 RS6000_BTM_MMA,	false, false },
   { "power10",		 RS6000_BTM_P10,	false, false },
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index 4ca6372435d..c5f38f26649 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -504,6 +504,12 @@ extern int rs6000_vector_align[];
 #define TARGET_MINMAX	(TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT		\
 			 && (TARGET_P9_MINMAX || !flag_trapping_math))
 
+/* Whether the '__ibm128' keywork is enabled.  We enable __ibm128 either if the
+   IEEE 128-bit floating point support is enabled or if the long double support
+   uses the 128-bit IBM extended double format.  */
+#define TARGET_IBM128	(TARGET_FLOAT128_TYPE				\
+			 || (!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128))
+
 /* In switching from using target_flags to using rs6000_isa_flags, the options
    machinery creates OPTION_MASK_<xxx> instead of MASK_<xxx>.  For now map
    OPTION_MASK_<xxx> back into MASK_<xxx>.  */
@@ -2294,7 +2300,7 @@ extern int frame_pointer_needed;
 #define RS6000_BTC_SAT		RS6000_BTC_MISC	/* saturate sets VSCR.  */
 
 /* Builtin targets.  For now, we reuse the masks for those options that are in
-   target flags, and pick a random bit for ldbl128, which isn't in
+   target flags, and pick a random bit for ldbl128 and ibm128, which aren't in
    target_flags.  */
 #define RS6000_BTM_ALWAYS	0		/* Always enabled.  */
 #define RS6000_BTM_ALTIVEC	MASK_ALTIVEC	/* VMX/altivec vectors.  */
@@ -2316,7 +2322,7 @@ extern int frame_pointer_needed;
 #define RS6000_BTM_LDBL128	MASK_MULTIPLE	/* 128-bit long double.  */
 #define RS6000_BTM_64BIT	MASK_64BIT	/* 64-bit addressing.  */
 #define RS6000_BTM_POWERPC64	MASK_POWERPC64	/* 64-bit registers.  */
-#define RS6000_BTM_FLOAT128	MASK_FLOAT128_KEYWORD /* IEEE 128-bit float.  */
+#define RS6000_BTM_IBM128	MASK_FLOAT128_KEYWORD /* __ibm128 keyword.  */
 #define RS6000_BTM_FLOAT128_HW	MASK_FLOAT128_HW /* IEEE 128-bit float h/w.  */
 #define RS6000_BTM_MMA		MASK_MMA	/* ISA 3.1 MMA.  */
 #define RS6000_BTM_P10		MASK_POWER10
@@ -2339,7 +2345,7 @@ extern int frame_pointer_needed;
 				 | RS6000_BTM_HARD_FLOAT		\
 				 | RS6000_BTM_LDBL128			\
 				 | RS6000_BTM_POWERPC64			\
-				 | RS6000_BTM_FLOAT128			\
+				 | RS6000_BTM_IBM128			\
 				 | RS6000_BTM_FLOAT128_HW		\
 				 | RS6000_BTM_MMA			\
 				 | RS6000_BTM_P10)
diff --git a/libgcc/config/rs6000/ibm-ldouble.c b/libgcc/config/rs6000/ibm-ldouble.c
index 4c13453f975..92b4b4c583d 100644
--- a/libgcc/config/rs6000/ibm-ldouble.c
+++ b/libgcc/config/rs6000/ibm-ldouble.c
@@ -102,9 +102,9 @@ __asm__ (".symver __gcc_qadd,_xlqadd@GCC_3.4\n\t"
 static inline IBM128_TYPE
 pack_ldouble (double dh, double dl)
 {
-#if defined (__LONG_DOUBLE_128__) && defined (__LONG_DOUBLE_IBM128__)	\
+#if defined (__LONG_DOUBLE_128__)					\
     && !(defined (_SOFT_FLOAT) || defined (__NO_FPRS__))
-  return __builtin_pack_longdouble (dh, dl);
+  return __builtin_pack_ibm128 (dh, dl);
 #else
   union
   {


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

end of thread, other threads:[~2021-07-04  5:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-04  5:09 [gcc(refs/users/meissner/heads/work058)] Fix long double tests when default long double is not IBM Michael Meissner
2021-07-04  5:10 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).