From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1005) id 6E4663858D28; Wed, 18 Jan 2023 08:55:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E4663858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674032135; bh=WGv+8w/mMBcs9/7yEPRh5Jry2yjNps3VMrbJVvohIsU=; h=From:To:Subject:Date:From; b=AR36l6wo9UeyLq1uOc7DqqFFj3lNdMbk9zBG2Mdbyd5iieOTcwZCse9pfuAmzFK62 arFXWACV0kRYd04cwWrdHe7hCKiDxx6e277uzB+2Kfc0ONqbW9Bv9DpM3vRNLeAPfH eT0zrsLBmAfotsRYfXHI/QEbSnpYJiSa53DgOvRA= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Michael Meissner 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 X-Act-Checkin: gcc X-Git-Author: Michael Meissner X-Git-Refname: refs/users/meissner/heads/work106 X-Git-Oldrev: 8f04200d59a29dd4c49c51c92e3a85bccde0eb70 X-Git-Newrev: 09ea1b9d4c330252841cd8f8b420b0e8ba03a2d9 Message-Id: <20230118085535.6E4663858D28@sourceware.org> Date: Wed, 18 Jan 2023 08:55:35 +0000 (GMT) List-Id: https://gcc.gnu.org/g:09ea1b9d4c330252841cd8f8b420b0e8ba03a2d9 commit 09ea1b9d4c330252841cd8f8b420b0e8ba03a2d9 Author: Michael Meissner 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 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