public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath
@ 2017-08-16  1:53 Michael Meissner
  2017-08-16  3:28 ` Michael Meissner
  2017-08-16  9:22 ` Joseph Myers
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Meissner @ 2017-08-16  1:53 UTC (permalink / raw)
  To: GCC Patches, Segher Boessenkool, David Edelsohn, Bill Schmidt,
	Tobias Burnus, Jakub Jelinek, Joseph Myers

I'm working on some changes to finally make __float128 default for PowerPC VSX
targets (power7..power9).  I am reworking my PowerPC changes, but in using a
previous version of my code, I needed to do some minor tweaks to allow
libquadmath to build on PowerPC when __float128 becomes on by default.

I have checked this out by doing bootstrap builds and make check for C, C++,
and Fortran on both a little endian power8 system and an x86_64 system.  Both
systems bootstrapped fine, and there were no regressions.  Can I install these
changes in the trunk?

As I mention in the PR, there are two main changes:

1) Know how to create complex float128 on PowerPC's.  This is different from
Intel because the PowerPC already had a TF/TCmode for the IBM long double
format, and so we use KF/KCmode for the IEEE 128-bit floating point type if the
long double type is IBM long double.

2) There were a few places where long double was used instead of __float128.  I
fixed these cases, either by changing the type of the constant, or by modifying
the code to do an explicit conversion.

This is due to the fact that we do not allow expressions to have both IBM long
double and __float128 in the expression.  This in turn is caused by GCC not
expecting there to be more than one floating point type for a given size, and
due to having the existing IBM long double format, we have two different
128-bit floating point types.

Another factor is if you have IBM long double and __float128 in an expression,
should the resultant type be IBM long double or __float128.  On the power7 and
power8 systems, you would want long double, because the long double code is
faster than the emulation of IEEE 128-bit floating point.  However on the
power9 systems, since there is hardware support for IEEE 128-bit floating
point, you would want that.

2017-08-15  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR libquadmath/81848
	* configure.ac (powerpc*-linux*): Use attribute mode KC to create
	complex __float128 on PowerPC instead of attribute mode TC.
	* quadmth.h (__complex128): Likewise.
	* configure: Regenerate.
	* math/cbrtq.c (CBRT2): Use __float128 not long double.
	(CBRT4): Likewise.
	(CBRT2I): Likewise.
	(CBRT4I): Likewise.
	* math/j0q.c (U0): Likewise.
	* math/sqrtq.c (sqrtq): Don't depend on implicit conversion
	between __float128, instead explicitly convert the __float128
	value to long double because the PowerPC does not allow __float128
	and long double in the same expression.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

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

* [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath
  2017-08-16  1:53 [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath Michael Meissner
@ 2017-08-16  3:28 ` Michael Meissner
  2017-08-16  9:22 ` Joseph Myers
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Meissner @ 2017-08-16  3:28 UTC (permalink / raw)
  To: GCC Patches, Segher Boessenkool, David Edelsohn, Bill Schmidt,
	Tobias Burnus, Jakub Jelinek, Joseph Myers

I'm working on some changes to finally make __float128 default for PowerPC VSX
targets (power7..power9).  I am reworking my PowerPC changes, but in using a
previous version of my code, I needed to do some minor tweaks to allow
libquadmath to build on PowerPC when __float128 becomes on by default.

I have checked this out by doing bootstrap builds and make check for C, C++,
and Fortran on both a little endian power8 system and an x86_64 system.  Both
systems bootstrapped fine, and there were no regressions.  Can I install these
changes in the trunk?

As I mention in the PR, there are two main changes:

1) Know how to create complex float128 on PowerPC's.  This is different from
Intel because the PowerPC already had a TF/TCmode for the IBM long double
format, and so we use KF/KCmode for the IEEE 128-bit floating point type if the
long double type is IBM long double.

2) There were a few places where long double was used instead of __float128.  I
fixed these cases, either by changing the type of the constant, or by modifying
the code to do an explicit conversion.

This is due to the fact that we do not allow expressions to have both IBM long
double and __float128 in the expression.  This in turn is caused by GCC not
expecting there to be more than one floating point type for a given size, and
due to having the existing IBM long double format, we have two different
128-bit floating point types.

Another factor is if you have IBM long double and __float128 in an expression,
should the resultant type be IBM long double or __float128.  On the power7 and
power8 systems, you would want long double, because the long double code is
faster than the emulation of IEEE 128-bit floating point.  However on the
power9 systems, since there is hardware support for IEEE 128-bit floating
point, you would want that.

2017-08-15  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR libquadmath/81848
	* configure.ac (powerpc*-linux*): Use attribute mode KC to create
	complex __float128 on PowerPC instead of attribute mode TC.
	* quadmth.h (__complex128): Likewise.
	* configure: Regenerate.
	* math/cbrtq.c (CBRT2): Use __float128 not long double.
	(CBRT4): Likewise.
	(CBRT2I): Likewise.
	(CBRT4I): Likewise.
	* math/j0q.c (U0): Likewise.
	* math/sqrtq.c (sqrtq): Don't depend on implicit conversion
	between __float128, instead explicitly convert the __float128
	value to long double because the PowerPC does not allow __float128
	and long double in the same expression.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

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

* Re: [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath
  2017-08-16  1:53 [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath Michael Meissner
  2017-08-16  3:28 ` Michael Meissner
@ 2017-08-16  9:22 ` Joseph Myers
  2017-08-16  9:31   ` Michael Meissner
  1 sibling, 1 reply; 7+ messages in thread
From: Joseph Myers @ 2017-08-16  9:22 UTC (permalink / raw)
  To: Michael Meissner
  Cc: GCC Patches, Segher Boessenkool, David Edelsohn, Bill Schmidt,
	Tobias Burnus, Jakub Jelinek

ENOPATCH

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath
  2017-08-16  9:22 ` Joseph Myers
@ 2017-08-16  9:31   ` Michael Meissner
  2017-08-23 18:28     ` Ping " Michael Meissner
  2017-08-30  8:24     ` Jakub Jelinek
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Meissner @ 2017-08-16  9:31 UTC (permalink / raw)
  To: Joseph Myers
  Cc: Michael Meissner, GCC Patches, Segher Boessenkool,
	David Edelsohn, Bill Schmidt, Tobias Burnus, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 884 bytes --]

On Wed, Aug 16, 2017 at 01:46:12AM +0000, Joseph Myers wrote:
> ENOPATCH

2017-08-15  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR libquadmath/81848
	* configure.ac (powerpc*-linux*): Use attribute mode KC to create
	complex __float128 on PowerPC instead of attribute mode TC.
	* quadmth.h (__complex128): Likewise.
	* configure: Regenerate.
	* math/cbrtq.c (CBRT2): Use __float128 not long double.
	(CBRT4): Likewise.
	(CBRT2I): Likewise.
	(CBRT4I): Likewise.
	* math/j0q.c (U0): Likewise.
	* math/sqrtq.c (sqrtq): Don't depend on implicit conversion
	between __float128, instead explicitly convert the __float128
	value to long double because the PowerPC does not allow __float128
	and long double in the same expression.


-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

[-- Attachment #2: ieee128-patch21c --]
[-- Type: text/plain, Size: 4380 bytes --]

Index: libquadmath/configure.ac
===================================================================
--- libquadmath/configure.ac	(revision 251097)
+++ libquadmath/configure.ac	(working copy)
@@ -210,7 +210,11 @@ AM_CONDITIONAL(LIBQUAD_USE_SYMVER_SUN, [
 
 AC_CACHE_CHECK([whether __float128 is supported], [libquad_cv_have_float128],
   [GCC_TRY_COMPILE_OR_LINK([
+    #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__)
     typedef _Complex float __attribute__((mode(TC))) __complex128;
+    #else
+    typedef _Complex float __attribute__((mode(KC))) __complex128;
+    #endif
 
     __float128 foo (__float128 x)
     {
Index: libquadmath/configure
===================================================================
--- libquadmath/configure	(revision 251097)
+++ libquadmath/configure	(working copy)
@@ -12516,7 +12516,11 @@ else
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
+    #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__)
     typedef _Complex float __attribute__((mode(TC))) __complex128;
+    #else
+    typedef _Complex float __attribute__((mode(KC))) __complex128;
+    #endif
 
     __float128 foo (__float128 x)
     {
@@ -12563,7 +12567,11 @@ fi
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 
+    #if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__)
     typedef _Complex float __attribute__((mode(TC))) __complex128;
+    #else
+    typedef _Complex float __attribute__((mode(KC))) __complex128;
+    #endif
 
     __float128 foo (__float128 x)
     {
Index: libquadmath/quadmath.h
===================================================================
--- libquadmath/quadmath.h	(revision 251097)
+++ libquadmath/quadmath.h	(working copy)
@@ -29,7 +29,11 @@ extern "C" {
 
 /* Define the complex type corresponding to __float128
    ("_Complex __float128" is not allowed) */
+#if (!defined(_ARCH_PPC)) || defined(__LONG_DOUBLE_IEEE128__)
 typedef _Complex float __attribute__((mode(TC))) __complex128;
+#else
+typedef _Complex float __attribute__((mode(KC))) __complex128;
+#endif
 
 #ifdef __cplusplus
 # define __quadmath_throw throw ()
Index: libquadmath/math/cbrtq.c
===================================================================
--- libquadmath/math/cbrtq.c	(revision 251097)
+++ libquadmath/math/cbrtq.c	(working copy)
@@ -56,10 +56,10 @@ Adapted for glibc October, 2001.
 
 #include "quadmath-imp.h"
 
-static const long double CBRT2 = 1.259921049894873164767210607278228350570251Q;
-static const long double CBRT4 = 1.587401051968199474751705639272308260391493Q;
-static const long double CBRT2I = 0.7937005259840997373758528196361541301957467Q;
-static const long double CBRT4I = 0.6299605249474365823836053036391141752851257Q;
+static const __float128 CBRT2 = 1.259921049894873164767210607278228350570251Q;
+static const __float128 CBRT4 = 1.587401051968199474751705639272308260391493Q;
+static const __float128 CBRT2I = 0.7937005259840997373758528196361541301957467Q;
+static const __float128 CBRT4I = 0.6299605249474365823836053036391141752851257Q;
 
 
 __float128
Index: libquadmath/math/j0q.c
===================================================================
--- libquadmath/math/j0q.c	(revision 251097)
+++ libquadmath/math/j0q.c	(working copy)
@@ -816,7 +816,7 @@ static __float128 Y0_2D[NY0_2D + 1] = {
  /* 1.000000000000000000000000000000000000000E0 */
 };
 
-static const long double U0 = -7.3804295108687225274343927948483016310862e-02Q;
+static const __float128 U0 = -7.3804295108687225274343927948483016310862e-02Q;
 
 /* Bessel function of the second kind, order zero.  */
 
Index: libquadmath/math/sqrtq.c
===================================================================
--- libquadmath/math/sqrtq.c	(revision 251097)
+++ libquadmath/math/sqrtq.c	(working copy)
@@ -31,15 +31,18 @@ sqrtq (const __float128 x)
     return y;
   }
 
-#ifdef HAVE_SQRTL
-  if (x <= LDBL_MAX && x >= LDBL_MIN)
+#if defined(HAVE_SQRTL)
   {
-    /* Use long double result as starting point.  */
-    y = sqrtl ((long double) x);
+    long double xl = (long double)x;
+    if (xl <= LDBL_MAX && xl >= LDBL_MIN)
+      {
+	/* Use long double result as starting point.  */
+	y = sqrtl (xl);
 
-    /* One Newton iteration.  */
-    y -= 0.5q * (y - x / y);
-    return y;
+	/* One Newton iteration.  */
+	y -= 0.5q * (y - x / y);
+	return y;
+      }
   }
 #endif
 

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

* Re: Ping [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath
  2017-08-16  9:31   ` Michael Meissner
@ 2017-08-23 18:28     ` Michael Meissner
  2017-08-30  8:24     ` Jakub Jelinek
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Meissner @ 2017-08-23 18:28 UTC (permalink / raw)
  To: Michael Meissner, Joseph Myers, GCC Patches, Segher Boessenkool,
	David Edelsohn, Bill Schmidt, Tobias Burnus, Jakub Jelinek

Ping:

2017-08-15  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR libquadmath/81848
	* configure.ac (powerpc*-linux*): Use attribute mode KC to create
	complex __float128 on PowerPC instead of attribute mode TC.
	* quadmth.h (__complex128): Likewise.
	* configure: Regenerate.
	* math/cbrtq.c (CBRT2): Use __float128 not long double.
	(CBRT4): Likewise.
	(CBRT2I): Likewise.
	(CBRT4I): Likewise.
	* math/j0q.c (U0): Likewise.
	* math/sqrtq.c (sqrtq): Don't depend on implicit conversion
	between __float128, instead explicitly convert the __float128
	value to long double because the PowerPC does not allow __float128
	and long double in the same expression.

https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00977.html

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

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

* Re: [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath
  2017-08-16  9:31   ` Michael Meissner
  2017-08-23 18:28     ` Ping " Michael Meissner
@ 2017-08-30  8:24     ` Jakub Jelinek
  2017-09-01 20:18       ` Michael Meissner
  1 sibling, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2017-08-30  8:24 UTC (permalink / raw)
  To: Michael Meissner, Joseph Myers, GCC Patches, Segher Boessenkool,
	David Edelsohn, Bill Schmidt, Tobias Burnus

On Tue, Aug 15, 2017 at 11:06:01PM -0400, Michael Meissner wrote:
> 2017-08-15  Michael Meissner  <meissner@linux.vnet.ibm.com>
> 
> 	PR libquadmath/81848
> 	* configure.ac (powerpc*-linux*): Use attribute mode KC to create
> 	complex __float128 on PowerPC instead of attribute mode TC.
> 	* quadmth.h (__complex128): Likewise.

quadmath.h ?

> 	* configure: Regenerate.
> 	* math/cbrtq.c (CBRT2): Use __float128 not long double.
> 	(CBRT4): Likewise.
> 	(CBRT2I): Likewise.
> 	(CBRT4I): Likewise.
> 	* math/j0q.c (U0): Likewise.
> 	* math/sqrtq.c (sqrtq): Don't depend on implicit conversion
> 	between __float128, instead explicitly convert the __float128
> 	value to long double because the PowerPC does not allow __float128
> 	and long double in the same expression.

Does the Q suffix on ppc* imply __float128 like on x86_64 etc.?

> --- libquadmath/math/sqrtq.c	(revision 251097)
> +++ libquadmath/math/sqrtq.c	(working copy)
> @@ -31,15 +31,18 @@ sqrtq (const __float128 x)
>      return y;
>    }
>  
> -#ifdef HAVE_SQRTL
> -  if (x <= LDBL_MAX && x >= LDBL_MIN)
> +#if defined(HAVE_SQRTL)

Why the #ifdef -> #if defined change?  That looks unnecessary.

>    {
> -    /* Use long double result as starting point.  */
> -    y = sqrtl ((long double) x);
> +    long double xl = (long double)x;

Please add a space after (long double)

> +    if (xl <= LDBL_MAX && xl >= LDBL_MIN)
> +      {
> +	/* Use long double result as starting point.  */
> +	y = sqrtl (xl);
>  
> -    /* One Newton iteration.  */
> -    y -= 0.5q * (y - x / y);
> -    return y;
> +	/* One Newton iteration.  */
> +	y -= 0.5q * (y - x / y);
> +	return y;
> +      }
>    }
>  #endif
>  

Otherwise LGTM.

	Jakub

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

* Re: [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath
  2017-08-30  8:24     ` Jakub Jelinek
@ 2017-09-01 20:18       ` Michael Meissner
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Meissner @ 2017-09-01 20:18 UTC (permalink / raw)
  To: Jakub Jelinek
  Cc: Michael Meissner, Joseph Myers, GCC Patches, Segher Boessenkool,
	David Edelsohn, Bill Schmidt, Tobias Burnus

On Wed, Aug 30, 2017 at 01:11:51AM +0200, Jakub Jelinek wrote:
> On Tue, Aug 15, 2017 at 11:06:01PM -0400, Michael Meissner wrote:
> > 2017-08-15  Michael Meissner  <meissner@linux.vnet.ibm.com>
> > 
> > 	PR libquadmath/81848
> > 	* configure.ac (powerpc*-linux*): Use attribute mode KC to create
> > 	complex __float128 on PowerPC instead of attribute mode TC.
> > 	* quadmth.h (__complex128): Likewise.
> 
> quadmath.h ?

Yes, thanks.

> > 	* configure: Regenerate.
> > 	* math/cbrtq.c (CBRT2): Use __float128 not long double.
> > 	(CBRT4): Likewise.
> > 	(CBRT2I): Likewise.
> > 	(CBRT4I): Likewise.
> > 	* math/j0q.c (U0): Likewise.
> > 	* math/sqrtq.c (sqrtq): Don't depend on implicit conversion
> > 	between __float128, instead explicitly convert the __float128
> > 	value to long double because the PowerPC does not allow __float128
> > 	and long double in the same expression.
> 
> Does the Q suffix on ppc* imply __float128 like on x86_64 etc.?

Yes.

> > --- libquadmath/math/sqrtq.c	(revision 251097)
> > +++ libquadmath/math/sqrtq.c	(working copy)
> > @@ -31,15 +31,18 @@ sqrtq (const __float128 x)
> >      return y;
> >    }
> >  
> > -#ifdef HAVE_SQRTL
> > -  if (x <= LDBL_MAX && x >= LDBL_MIN)
> > +#if defined(HAVE_SQRTL)
> 
> Why the #ifdef -> #if defined change?  That looks unnecessary.

I'll change it back.

> >    {
> > -    /* Use long double result as starting point.  */
> > -    y = sqrtl ((long double) x);
> > +    long double xl = (long double)x;
> 
> Please add a space after (long double)

Ok.

> > +    if (xl <= LDBL_MAX && xl >= LDBL_MIN)
> > +      {
> > +	/* Use long double result as starting point.  */
> > +	y = sqrtl (xl);
> >  
> > -    /* One Newton iteration.  */
> > -    y -= 0.5q * (y - x / y);
> > -    return y;
> > +	/* One Newton iteration.  */
> > +	y -= 0.5q * (y - x / y);
> > +	return y;
> > +      }
> >    }
> >  #endif
> >  
> 
> Otherwise LGTM.

Thanks.

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.vnet.ibm.com, phone: +1 (978) 899-4797

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

end of thread, other threads:[~2017-09-01 20:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-16  1:53 [PATCH] libquadmath/81848, allow PowerPC to enable libquadmath Michael Meissner
2017-08-16  3:28 ` Michael Meissner
2017-08-16  9:22 ` Joseph Myers
2017-08-16  9:31   ` Michael Meissner
2017-08-23 18:28     ` Ping " Michael Meissner
2017-08-30  8:24     ` Jakub Jelinek
2017-09-01 20:18       ` 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).