public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Michael Meissner <meissner@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/meissner/heads/work106)] PR target/107299: Fix build issue when long double is IEEE 128-bit
Date: Wed, 18 Jan 2023 08:55:35 +0000 (GMT)	[thread overview]
Message-ID: <20230118085535.6E4663858D28@sourceware.org> (raw)

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

             reply	other threads:[~2023-01-18  8:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18  8:55 Michael Meissner [this message]
2023-01-18 16:19 Michael Meissner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230118085535.6E4663858D28@sourceware.org \
    --to=meissner@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).