public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work106)] PR target/107299: Fix build issue when long double is IEEE 128-bit
@ 2023-01-18  8:55 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2023-01-18  8:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:09ea1b9d4c330252841cd8f8b420b0e8ba03a2d9

commit 09ea1b9d4c330252841cd8f8b420b0e8ba03a2d9
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Wed Jan 18 03:55:17 2023 -0500

    PR target/107299: Fix build issue when long double is IEEE 128-bit
    
    This patch updates the IEEE 128-bit types used in libgcc.
    
    At the moment, we cannot build GCC when the target uses IEEE 128-bit long
    doubles, such as building the compiler for a native Fedora 36 system.  The
    build dies when it is trying to build the _mulkc3.c and _divkc3 modules.
    
    This patch creates special types for declaring complex IEEE 128-bit multiply and
    divide support to use either _Float128 or long double, depending on whether long
    double is IBM or IEEE.
    
    It also uses the correct built-in functions in the libgcc complex IEEE 128-bit
    multiply and divide support.  This fixes the problems when long double types are
    used with explicit f128 built-in functions.
    
    While it is desirable to ultimately have __float128 and _Float128 use the same
    internal type and mode within GCC, at present if you use the option
    -mabi=ieeelongdouble, the __float128 type will use the long double type and not
    the _Float128 type.  We get an internal compiler error if we combine the
    signbitf128 built-in with a long double type.
    
    I've gone through several iterations of trying to fix this within GCC, and
    there are various problems that have come up.  I developed this alternative
    patch that changes libgcc so that it does not tickle the issue.  I hope we can
    fix the compiler at some point, but right now, this is preventing people on
    Fedora 36 systems from building compilers where the default long double is IEEE
    128-bit.
    
    I changed the three functions that deal with complex multiply and complex divide
    support (_mulkc3, _divkc3, and float128-ifunc) to always be compiled with IEEE
    128-bit long double.  This is to be type correct, and avoid mismatch declaration
    errors from the compiler.
    
    2023-01-18   Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/107299
            * config/rs6000/_divkc3.c (COPYSIGN): Use the correct built-in based on
            whether long double is IBM or IEEE.
            (INFINITY): Likewise.
            (FABS): Likewise.
            (__divkc3): Use either _Float128 or long double for the types to match
            whether long double is IBM or IEEE.
            * config/rs6000/_mulkc3.c (COPYSIGN): Use the correct built-in based on
            whether long double is IBM or IEEE.
            (INFINITY): Likewise.
            (__mulkc3): Use either _Float128 or long double for the types to match
            whether long double is IBM or IEEE.
            * config/rs6000/float128-ifunc.c (__mulkc3): Use either _Float128 or
            long double for the types to match whether long double is IBM or IEEE.
            (__divkc3): Likewise.
            * config/rs6000/quad-float128.h (TC): Define to switch complex IEEE
            128-bit type in machine independent code via mode attribute.
            (TFtype_cmuldiv): New macro.
            (TCtype_cmuldiv): Likewise.
            (__mulkc3_sw): Use TFtype_cmuldiv and TCtype_cmuldiv.
            (__divkc3_sw): Likewise.
            (__mulkc3_hw): Likewise.
            (__divkc3_hw): Likewise.
            (__mulkc3): Likewise.
            (__divkc3): Likewise.

Diff:
---
 libgcc/config/rs6000/_divkc3.c        | 21 ++++++++++++++----
 libgcc/config/rs6000/_mulkc3.c        | 20 +++++++++++++----
 libgcc/config/rs6000/float128-ifunc.c |  6 +++--
 libgcc/config/rs6000/quad-float128.h  | 42 ++++++++++++++++++++++++-----------
 4 files changed, 66 insertions(+), 23 deletions(-)

diff --git a/libgcc/config/rs6000/_divkc3.c b/libgcc/config/rs6000/_divkc3.c
index 59ab2137d1d..b1c9c9f6e3a 100644
--- a/libgcc/config/rs6000/_divkc3.c
+++ b/libgcc/config/rs6000/_divkc3.c
@@ -26,9 +26,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "soft-fp.h"
 #include "quad-float128.h"
 
+/* Use the correct built-ins depending on whether long double is IEEE 128-bit
+   or IBM 128-bit.  */
+#ifndef __LONG_DOUBLE_IEEE128__
 #define COPYSIGN(x,y) __builtin_copysignf128 (x, y)
 #define INFINITY __builtin_inff128 ()
 #define FABS __builtin_fabsf128
+
+#else
+#define COPYSIGN(x,y) __builtin_copysignl (x, y)
+#define INFINITY __builtin_infl ()
+#define FABS __builtin_fabsl
+#endif
+
 #define isnan __builtin_isnan
 #define isinf __builtin_isinf
 #define isfinite __builtin_isfinite
@@ -51,11 +61,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define RMAX2  (RBIG * RMIN2)
 #endif
 
-TCtype
-__divkc3 (TFtype a, TFtype b, TFtype c, TFtype d)
+TCtype_cmuldiv
+__divkc3 (TFtype_cmuldiv a,
+	  TFtype_cmuldiv b,
+	  TFtype_cmuldiv c,
+	  TFtype_cmuldiv d)
 {
-  TFtype denom, ratio, x, y;
-  TCtype res;
+  TFtype_cmuldiv denom, ratio, x, y;
+  TCtype_cmuldiv res;
 
   /* long double has significant potential underflow/overflow errors that
      can be greatly reduced with a limited number of tests and adjustments.
diff --git a/libgcc/config/rs6000/_mulkc3.c b/libgcc/config/rs6000/_mulkc3.c
index cfae81f8b5f..05d2913439a 100644
--- a/libgcc/config/rs6000/_mulkc3.c
+++ b/libgcc/config/rs6000/_mulkc3.c
@@ -26,8 +26,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "soft-fp.h"
 #include "quad-float128.h"
 
+/* Use the correct built-ins depending on whether long double is IEEE 128-bit
+   or IBM 128-bit.  */
+#ifndef __LONG_DOUBLE_IEEE128__
 #define COPYSIGN(x,y) __builtin_copysignf128 (x, y)
 #define INFINITY __builtin_inff128 ()
+
+#else
+#define COPYSIGN(x,y) __builtin_copysignl (x, y)
+#define INFINITY __builtin_infl ()
+#endif
+
 #define isnan __builtin_isnan
 #define isinf __builtin_isinf
 
@@ -35,11 +44,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define __mulkc3 __mulkc3_sw
 #endif
 
-TCtype
-__mulkc3 (TFtype a, TFtype b, TFtype c, TFtype d)
+TCtype_cmuldiv
+__mulkc3 (TFtype_cmuldiv a,
+	  TFtype_cmuldiv b,
+	  TFtype_cmuldiv c,
+	  TFtype_cmuldiv d)
 {
-  TFtype ac, bd, ad, bc, x, y;
-  TCtype res;
+  TFtype_cmuldiv ac, bd, ad, bc, x, y;
+  TCtype_cmuldiv res;
 
   ac = a * c;
   bd = b * d;
diff --git a/libgcc/config/rs6000/float128-ifunc.c b/libgcc/config/rs6000/float128-ifunc.c
index 73cbca2fc9a..6ea8fdd82c3 100644
--- a/libgcc/config/rs6000/float128-ifunc.c
+++ b/libgcc/config/rs6000/float128-ifunc.c
@@ -354,8 +354,10 @@ IBM128_TYPE __extendkftf2 (TFtype)
 TFtype __trunctfkf2 (IBM128_TYPE)
   __attribute__ ((__ifunc__ ("__trunctfkf2_resolve")));
 
-TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype)
+TCtype_cmuldiv __mulkc3 (TFtype_cmuldiv, TFtype_cmuldiv,
+			 TFtype_cmuldiv, TFtype_cmuldiv)
   __attribute__ ((__ifunc__ ("__mulkc3_resolve")));
 
-TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype)
+TCtype_cmuldiv __divkc3 (TFtype_cmuldiv, TFtype_cmuldiv,
+			 TFtype_cmuldiv, TFtype_cmuldiv)
   __attribute__ ((__ifunc__ ("__divkc3_resolve")));
diff --git a/libgcc/config/rs6000/quad-float128.h b/libgcc/config/rs6000/quad-float128.h
index ae0622c744c..6cfbee6e599 100644
--- a/libgcc/config/rs6000/quad-float128.h
+++ b/libgcc/config/rs6000/quad-float128.h
@@ -30,18 +30,28 @@
 /* quad.h defines the TFtype type by:
    typedef float TFtype __attribute__ ((mode (TF)));
 
-   This define forces it to use KFmode (aka, ieee 128-bit floating point).
-   However, when the compiler's default is changed so that long double is IEEE
-   128-bit floating point, we need to go back to using TFmode and TCmode.  */
+   These two defines override the machine independent files that use
+   __attribute__((mode(TF))) and __attribute__((mode(TC))) to create the IEEE
+   128-bit scalar and complex types.  */
 #ifndef __LONG_DOUBLE_IEEE128__
 #define TF KF
+#define TC KC
+#endif
 
-/* We also need TCtype to represent complex ieee 128-bit float for
-   __mulkc3 and __divkc3.  */
-typedef __complex float TCtype __attribute__ ((mode (KC)));
+/* Special types for IEEE 128-bit floating point complex multiply/divide
+   support.  We need to use _Float128 or long double specifically so that the
+   compiler doesn't complain about different types when we do the declaration.
+   __mulkc3 and __divkc3 are built-in functions with pre-defined types.  Using
+   __attribute__ mode creates a different type internally, and the compiler
+   complains when you issue the declaration when the original type used
+   _Float128 or long double.  */
+#ifdef __LONG_DOUBLE_IEEE128__
+#define TFtype_cmuldiv long double
+#define TCtype_cmuldiv _Complex long double
 
 #else
-typedef __complex float TCtype __attribute__ ((mode (TC)));
+#define TFtype_cmuldiv _Float128
+#define TCtype_cmuldiv _Complex _Float128
 #endif
 
 /* Force the use of the VSX instruction set.  */
@@ -100,8 +110,10 @@ extern UTItype_ppc __fixunskfti_sw (TFtype);
 #endif
 extern IBM128_TYPE __extendkftf2_sw (TFtype);
 extern TFtype __trunctfkf2_sw (IBM128_TYPE);
-extern TCtype __mulkc3_sw (TFtype, TFtype, TFtype, TFtype);
-extern TCtype __divkc3_sw (TFtype, TFtype, TFtype, TFtype);
+extern TCtype_cmuldiv __mulkc3_sw (TFtype_cmuldiv, TFtype_cmuldiv,
+				   TFtype_cmuldiv, TFtype_cmuldiv);
+extern TCtype_cmuldiv __divkc3_sw (TFtype_cmuldiv, TFtype_cmuldiv,
+				   TFtype_cmuldiv, TFtype_cmuldiv);
 
 #ifdef _ARCH_PPC64
 extern TItype_ppc __fixkfti (TFtype);
@@ -146,8 +158,10 @@ extern UTItype_ppc __fixunskfti_hw (TFtype);
 #endif
 extern IBM128_TYPE __extendkftf2_hw (TFtype);
 extern TFtype __trunctfkf2_hw (IBM128_TYPE);
-extern TCtype __mulkc3_hw (TFtype, TFtype, TFtype, TFtype);
-extern TCtype __divkc3_hw (TFtype, TFtype, TFtype, TFtype);
+extern TCtype_cmuldiv __mulkc3_hw (TFtype_cmuldiv, TFtype_cmuldiv,
+				   TFtype_cmuldiv, TFtype_cmuldiv);
+extern TCtype_cmuldiv __divkc3_hw (TFtype_cmuldiv, TFtype_cmuldiv,
+				   TFtype_cmuldiv, TFtype_cmuldiv);
 
 /* Ifunc function declarations, to automatically switch between software
    emulation and hardware support.  */
@@ -188,8 +202,10 @@ extern IBM128_TYPE __extendkftf2 (TFtype);
 extern TFtype __trunctfkf2 (IBM128_TYPE);
 
 /* Complex __float128 built on __float128 interfaces.  */
-extern TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype);
-extern TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype);
+extern TCtype_cmuldiv __mulkc3 (TFtype_cmuldiv, TFtype_cmuldiv,
+				TFtype_cmuldiv, TFtype_cmuldiv);
+extern TCtype_cmuldiv __divkc3 (TFtype_cmuldiv, TFtype_cmuldiv,
+				TFtype_cmuldiv, TFtype_cmuldiv);
 
 /* Convert IEEE 128-bit floating point to/from string.  We explicitly use
    _Float128 instead of TFmode because _strtokf and _strfromkf must be compiled

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

* [gcc(refs/users/meissner/heads/work106)] PR target/107299: Fix build issue when long double is IEEE 128-bit
@ 2023-01-18 16:19 Michael Meissner
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Meissner @ 2023-01-18 16:19 UTC (permalink / raw)
  To: gcc-cvs

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

commit d54e3d92dd6541057c7feb7dace84f4eb8497012
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Wed Jan 18 11:19:20 2023 -0500

    PR target/107299: Fix build issue when long double is IEEE 128-bit
    
    This patch updates the IEEE 128-bit types used in libgcc.
    
    At the moment, we cannot build GCC when the target uses IEEE 128-bit long
    doubles, such as building the compiler for a native Fedora 36 system.  The
    build dies when it is trying to build the _mulkc3.c and _divkc3 modules.
    
    This patch changes libgcc to use long double for the IEEE 128-bit base type if
    long double is IEEE 128-bit, and it uses _Float128 otherwise.  The built-in
    functions are adjusted to be the correct version based on the IEEE 128-bit base
    type used.
    
    While it is desirable to ultimately have __float128 and _Float128 use the same
    internal type and mode within GCC, at present if you use the option
    -mabi=ieeelongdouble, the __float128 type will use the long double type and not
    the _Float128 type.  We get an internal compiler error if we combine the
    signbitf128 built-in with a long double type.
    
    I've gone through several iterations of trying to fix this within GCC, and
    there are various problems that have come up.  I developed this alternative
    patch that changes libgcc so that it does not tickle the issue.  I hope we can
    fix the compiler at some point, but right now, this is preventing people on
    Fedora 36 systems from building compilers where the default long double is IEEE
    128-bit.
    
    2023-01-18   Michael Meissner  <meissner@linux.ibm.com>
    
            PR target/107299
            * config/rs6000/_divkc3.c (COPYSIGN): Use the correct built-in based on
            whether long double is IBM or IEEE.
            (INFINITY): Likewise.
            (FABS): Likewise.
            * config/rs6000/_mulkc3.c (COPYSIGN): Likewise.
            (INFINITY): Likewise.
            * config/rs6000/quad-float128.h (TF): Remove definition.
            (TFtype): Define to be long double or _Float128.
            (TCtype): Define to be _Complex long double or _Complex _Float128.
            * libgcc2.h (TFtype): Allow machine config files to override this.
            (TCtype): Likewise.
            * soft-fp/quad.h (TFtype): Likewise.

Diff:
---
 libgcc/config/rs6000/_divkc3.c       |  8 ++++++++
 libgcc/config/rs6000/_mulkc3.c       |  7 +++++++
 libgcc/config/rs6000/quad-float128.h | 19 ++++++-------------
 libgcc/libgcc2.h                     |  4 ++++
 libgcc/soft-fp/quad.h                |  2 ++
 5 files changed, 27 insertions(+), 13 deletions(-)

diff --git a/libgcc/config/rs6000/_divkc3.c b/libgcc/config/rs6000/_divkc3.c
index 59ab2137d1d..8eeb0f76ba4 100644
--- a/libgcc/config/rs6000/_divkc3.c
+++ b/libgcc/config/rs6000/_divkc3.c
@@ -26,9 +26,17 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "soft-fp.h"
 #include "quad-float128.h"
 
+#ifndef __LONG_DOUBLE_IEEE128__
 #define COPYSIGN(x,y) __builtin_copysignf128 (x, y)
 #define INFINITY __builtin_inff128 ()
 #define FABS __builtin_fabsf128
+
+#else
+#define COPYSIGN(x,y) __builtin_copysignl (x, y)
+#define INFINITY __builtin_infl ()
+#define FABS __builtin_fabsl
+#endif
+
 #define isnan __builtin_isnan
 #define isinf __builtin_isinf
 #define isfinite __builtin_isfinite
diff --git a/libgcc/config/rs6000/_mulkc3.c b/libgcc/config/rs6000/_mulkc3.c
index cfae81f8b5f..290dc89bbc1 100644
--- a/libgcc/config/rs6000/_mulkc3.c
+++ b/libgcc/config/rs6000/_mulkc3.c
@@ -26,8 +26,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "soft-fp.h"
 #include "quad-float128.h"
 
+#ifndef __LONG_DOUBLE_IEEE128__
 #define COPYSIGN(x,y) __builtin_copysignf128 (x, y)
 #define INFINITY __builtin_inff128 ()
+
+#else
+#define COPYSIGN(x,y) __builtin_copysignl (x, y)
+#define INFINITY __builtin_infl ()
+#endif
+
 #define isnan __builtin_isnan
 #define isinf __builtin_isinf
 
diff --git a/libgcc/config/rs6000/quad-float128.h b/libgcc/config/rs6000/quad-float128.h
index ae0622c744c..8332184348a 100644
--- a/libgcc/config/rs6000/quad-float128.h
+++ b/libgcc/config/rs6000/quad-float128.h
@@ -27,21 +27,14 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-/* quad.h defines the TFtype type by:
-   typedef float TFtype __attribute__ ((mode (TF)));
-
-   This define forces it to use KFmode (aka, ieee 128-bit floating point).
-   However, when the compiler's default is changed so that long double is IEEE
-   128-bit floating point, we need to go back to using TFmode and TCmode.  */
-#ifndef __LONG_DOUBLE_IEEE128__
-#define TF KF
-
-/* We also need TCtype to represent complex ieee 128-bit float for
-   __mulkc3 and __divkc3.  */
-typedef __complex float TCtype __attribute__ ((mode (KC)));
+/* Override the types for IEEE 128-bit scalar and complex.  */
+#ifdef __LONG_DOUBLE_IEEE128__
+#define TFtype long double
+#define TCtype _Complex long double
 
 #else
-typedef __complex float TCtype __attribute__ ((mode (TC)));
+#define TFtype _Float128
+#define TCtype _Complex _Float128
 #endif
 
 /* Force the use of the VSX instruction set.  */
diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h
index fc24ac34502..6a249877c7a 100644
--- a/libgcc/libgcc2.h
+++ b/libgcc/libgcc2.h
@@ -156,9 +156,13 @@ typedef		float XFtype	__attribute__ ((mode (XF)));
 typedef _Complex float XCtype	__attribute__ ((mode (XC)));
 #endif
 #if LIBGCC2_HAS_TF_MODE
+#ifndef TFtype
 typedef		float TFtype	__attribute__ ((mode (TF)));
+#endif
+#ifndef TCtype
 typedef _Complex float TCtype	__attribute__ ((mode (TC)));
 #endif
+#endif
 
 typedef int cmp_return_type __attribute__((mode (__libgcc_cmp_return__)));
 typedef int shift_count_type __attribute__((mode (__libgcc_shift_count__)));
diff --git a/libgcc/soft-fp/quad.h b/libgcc/soft-fp/quad.h
index 3889bb44f1f..71f87d36ba9 100644
--- a/libgcc/soft-fp/quad.h
+++ b/libgcc/soft-fp/quad.h
@@ -65,7 +65,9 @@
 #define _FP_HIGHBIT_DW_Q	\
   ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_Q - 1) % _FP_W_TYPE_SIZE)
 
+#ifndef TFtype
 typedef float TFtype __attribute__ ((mode (TF)));
+#endif
 
 #if _FP_W_TYPE_SIZE < 64

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

end of thread, other threads:[~2023-01-18 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-18  8:55 [gcc(refs/users/meissner/heads/work106)] PR target/107299: Fix build issue when long double is IEEE 128-bit Michael Meissner
2023-01-18 16:19 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).