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/work105y)] PR target/107299: Use _Float128 and _Complex _Float128 types for PowerPC libgcc
Date: Thu, 12 Jan 2023 06:25:32 +0000 (GMT)	[thread overview]
Message-ID: <20230112062532.D83403858C66@sourceware.org> (raw)

https://gcc.gnu.org/g:34fb1e45d696dddc1df546e1bd19f5804950b570

commit 34fb1e45d696dddc1df546e1bd19f5804950b570
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Jan 12 01:25:09 2023 -0500

    PR target/107299: Use _Float128 and _Complex _Float128 types for PowerPC libgcc
    
    This patch tells GCC to use the _Float128 and _Complex _Float128 types when
    building the IEEE 128-bit support 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 module.
    
    The _mulkc3 and _divkc3 modules were written before the _Float128 and _Complex
    _Float128 types were available.  These routines had to use the mode attributes
    to get access to the __float128 complex type.  Unfortunately, with the current
    implementation of __float128, _Float128, and long double in the PowerPC
    backend, this code now breaks if long double is IEEE 128-bit.
    
    Originally I had hoped that we could fix the underlying problem with the
    compiler.  But that has become more complex than than I originally thought.  I
    believe the compiler should be fixed to avoid the breakage.
    
    This patch is a much simpler patch, and it avoids the problem by allowing the
    machine depenendent parts of libgcc to override the definition of TFtype
    (128-bit IEEE scalar) and TCtype (128-bit IEEE _Complex).  This allows us to use
    _Float128 and _Complex _Float128 when long double is IBM extended and plain long
    double when IEEE 128-bit is used.  We need to adjust the built-in functions used
    as well.
    
    2023-01-12   Michael Meissner  <meissner@linux.ibm.com>
    
            * config/rs6000/_divkc3.c (COPYSIGN): Use the correct built-in depending
            on whether TFmode is _Float128 or long double.
            (INFINITY): Likewise.
            (FABS): Likewise.
            * config/rs6000/_mulkc3.c (COPYSIGN): Likewise.
            (INFINITY): Likewise.
            * config/rs6000/quad-float128.h (TF): Delete definition.
            (TFtype): Define to be _Float128 or long double.
            (TCtype): Define to be _Complex _Float128 or _Complex long double.
            (__mulkc3): Delete definition since these are built-in functions.
            (__divkc3): Likewise.
            * libgcc2.h (TFtype): Allow MD code to override definition.
            (TCtype): Likewise.
            * soft-fp/quad.h (TFtype): Likewise.

Diff:
---
 libgcc/config/rs6000/_divkc3.c       | 10 +++++++++-
 libgcc/config/rs6000/_mulkc3.c       |  7 +++++++
 libgcc/config/rs6000/quad-float128.h | 21 +++++----------------
 libgcc/libgcc2.h                     |  5 +++++
 libgcc/soft-fp/quad.h                |  2 ++
 5 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/libgcc/config/rs6000/_divkc3.c b/libgcc/config/rs6000/_divkc3.c
index 59ab2137d1d..cc2b3d64b86 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
+#define FABS(x) __builtin_fabsf128 (x)
+
+#else
+#define COPYSIGN(x,y) __builtin_copysignl (x, y)
+#define INFINITY __builtin_infl ()
+#define FABS(x) __builtin_fabsl (x)
+#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..f58aeab2ac3 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.  */
+/* Override quad.h's definitions for 128-bit floating point type.  */
 #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)));
+#define TFtype _Float128
+#define TCtype _Complex _Float128
 
 #else
-typedef __complex float TCtype __attribute__ ((mode (TC)));
+#define TFtype long double
+#define TCtype _Complex long double
 #endif
 
 /* Force the use of the VSX instruction set.  */
@@ -187,10 +180,6 @@ extern UTItype_ppc __fixunskfti (TFtype);
 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);
-
 /* Convert IEEE 128-bit floating point to/from string.  We explicitly use
    _Float128 instead of TFmode because _strtokf and _strfromkf must be compiled
    with long double being IBM 128.  */
diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h
index fc24ac34502..a39c365d904 100644
--- a/libgcc/libgcc2.h
+++ b/libgcc/libgcc2.h
@@ -156,9 +156,14 @@ typedef		float XFtype	__attribute__ ((mode (XF)));
 typedef _Complex float XCtype	__attribute__ ((mode (XC)));
 #endif
 #if LIBGCC2_HAS_TF_MODE
+/* PowerPC would like to override this to be _Float128.  */
+#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

                 reply	other threads:[~2023-01-12  6:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230112062532.D83403858C66@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).