[PATCH 1/2] PowerPC: Allow __ibm128 on older systems. In the patch submitted on October 22nd, 2020: https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556869.html https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557529.html
Segher suggested that rather than add #ifdef code in libgcc's ibm-ldouble.c to use __builtin_pack_ibm128 instead of __builtin_pack_longdouble, that I should instead make __ibm128 available in targets that have 128-bit IBM long double, but don't support __float128/_Float128. This patch fixes the compiler to allow __ibm128 on older systems, and it adjusts the two ibm128 built-in functions to accomidate this change. The next patch will be to change libgcc/ibm-ldouble.c to always use the __builtin_pack_ibm128 function. I have tested these patches on a little endian power9 server system and there were no regressions. I have also tested the paches on a big endian power8 server system and there were no regressions. On the big endian system, I have built both compilers with power8 being the default cpu and power5 being the default cpu. Can I check this patch into the master branch? gcc/ 2021-01-13 Michael Meissner <meiss...@linux.ibm.com> * config/rs6000/rs6000-builtin.def (BU_IBM128_2): Rename RS6000_BTM_IBM128 from RS6000_BTM_FLOAT128. * config/rs6000/rs6000-call.c (rs6000_invalid_builtin): Update error message for __ibm128 built-in functions. (rs6000_init_builtins): Create the __ibm128 keyword on older systems where long double uses the IBM extended double format, even if they don't support IEEE 128-bit floating point. * config/rs6000/rs6000.c (rs6000_builtin_mask_calculate): Rename RS6000_BTM_IBM128 from RS6000_BTM_FLOAT128. (rs6000_builtin_mask_names): Rename RS6000_BTM_IBM128 from RS6000_BTM_FLOAT128. * config/rs6000/rs6000.h (TARGET_IBM128): New macro. (RS6000_BTM_IBM128): Rename from RS6000_BTM_FLOAT128. (RS6000_BTM_COMMON): Rename RS6000_BTM_IBM128 from RS6000_BTM_FLOAT128. --- gcc/config/rs6000/rs6000-builtin.def | 5 ++--- gcc/config/rs6000/rs6000-call.c | 14 ++++++++++---- gcc/config/rs6000/rs6000.c | 4 ++-- gcc/config/rs6000/rs6000.h | 12 +++++++++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/gcc/config/rs6000/rs6000-builtin.def b/gcc/config/rs6000/rs6000-builtin.def index 8aa31ad0a06..1bf76eedadf 100644 --- a/gcc/config/rs6000/rs6000-builtin.def +++ b/gcc/config/rs6000/rs6000-builtin.def @@ -728,13 +728,12 @@ | RS6000_BTC_BINARY), \ CODE_FOR_ ## ICODE) /* ICODE */ -/* 128-bit __ibm128 floating point builtins (use -mfloat128 to indicate that - __ibm128 is available). */ +/* 128-bit __ibm128 floating point builtins. */ #define BU_IBM128_2(ENUM, NAME, ATTR, ICODE) \ RS6000_BUILTIN_2 (MISC_BUILTIN_ ## ENUM, /* ENUM */ \ "__builtin_" NAME, /* NAME */ \ (RS6000_BTM_HARD_FLOAT /* MASK */ \ - | RS6000_BTM_FLOAT128), \ + | RS6000_BTM_IBM128), \ (RS6000_BTC_ ## ATTR /* ATTR */ \ | RS6000_BTC_BINARY), \ CODE_FOR_ ## ICODE) /* ICODE */ diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index 519313bc0d6..5e58bea7e7a 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -11485,8 +11485,8 @@ rs6000_invalid_builtin (enum rs6000_builtins fncode) error ("%qs requires the %qs option", name, "-mhard-float"); else if ((fnmask & RS6000_BTM_FLOAT128_HW) != 0) error ("%qs requires ISA 3.0 IEEE 128-bit floating point", name); - else if ((fnmask & RS6000_BTM_FLOAT128) != 0) - error ("%qs requires the %qs option", name, "%<-mfloat128%>"); + else if ((fnmask & RS6000_BTM_IBM128) != 0) + error ("%qs requires the IBM 128-bit floating point", name); else if ((fnmask & (RS6000_BTM_POPCNTD | RS6000_BTM_POWERPC64)) == (RS6000_BTM_POPCNTD | RS6000_BTM_POWERPC64)) error ("%qs requires the %qs (or newer), and %qs or %qs options", @@ -13181,7 +13181,7 @@ rs6000_init_builtins (void) For IEEE 128-bit floating point, always create the type __ieee128. If the user used -mfloat128, rs6000-c.c will create a define from __float128 to __ieee128. */ - if (TARGET_FLOAT128_TYPE) + if (TARGET_IBM128) { if (!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128) ibm128_float_type_node = long_double_type_node; @@ -13195,7 +13195,13 @@ rs6000_init_builtins (void) lang_hooks.types.register_builtin_type (ibm128_float_type_node, "__ibm128"); + } + + else + ibm128_float_type_node = long_double_type_node; + if (TARGET_FLOAT128_TYPE) + { if (TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128) ieee128_float_type_node = long_double_type_node; else @@ -13206,7 +13212,7 @@ rs6000_init_builtins (void) } else - ieee128_float_type_node = ibm128_float_type_node = long_double_type_node; + ieee128_float_type_node = long_double_type_node; /* Vector pair and vector quad support. */ if (TARGET_EXTRA_BUILTINS) diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 282703b9715..d1a817973ba 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -3397,7 +3397,7 @@ rs6000_builtin_mask_calculate (void) | ((TARGET_LONG_DOUBLE_128 && TARGET_HARD_FLOAT && !TARGET_IEEEQUAD) ? RS6000_BTM_LDBL128 : 0) - | ((TARGET_FLOAT128_TYPE) ? RS6000_BTM_FLOAT128 : 0) + | ((TARGET_IBM128) ? RS6000_BTM_IBM128 : 0) | ((TARGET_FLOAT128_HW) ? RS6000_BTM_FLOAT128_HW : 0) | ((TARGET_MMA) ? RS6000_BTM_MMA : 0) | ((TARGET_POWER10) ? RS6000_BTM_P10 : 0)); @@ -23667,7 +23667,7 @@ static struct rs6000_opt_mask const rs6000_builtin_mask_names[] = { "hard-float", RS6000_BTM_HARD_FLOAT, false, false }, { "long-double-128", RS6000_BTM_LDBL128, false, false }, { "powerpc64", RS6000_BTM_POWERPC64, false, false }, - { "float128", RS6000_BTM_FLOAT128, false, false }, + { "ibm128", RS6000_BTM_IBM128, false, false }, { "float128-hw", RS6000_BTM_FLOAT128_HW,false, false }, { "mma", RS6000_BTM_MMA, false, false }, { "power10", RS6000_BTM_P10, false, false }, diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index 1ff07345a93..a35878ea90c 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -509,6 +509,12 @@ extern int rs6000_vector_align[]; #define TARGET_MINMAX (TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT \ && (TARGET_P9_MINMAX || !flag_trapping_math)) +/* Whether the '__ibm128' keywork is enabled. We enable __ibm128 either if the + IEEE 128-bit floating point support is enabled or if the long double support + uses the 128-bit IBM extended double format. */ +#define TARGET_IBM128 (TARGET_FLOAT128_TYPE \ + || (!TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128)) + /* In switching from using target_flags to using rs6000_isa_flags, the options machinery creates OPTION_MASK_<xxx> instead of MASK_<xxx>. For now map OPTION_MASK_<xxx> back into MASK_<xxx>. */ @@ -2308,7 +2314,7 @@ extern int frame_pointer_needed; #define RS6000_BTC_SAT RS6000_BTC_MISC /* saturate sets VSCR. */ /* Builtin targets. For now, we reuse the masks for those options that are in - target flags, and pick a random bit for ldbl128, which isn't in + target flags, and pick a random bit for ldbl128 and ibm128, which aren't in target_flags. */ #define RS6000_BTM_ALWAYS 0 /* Always enabled. */ #define RS6000_BTM_ALTIVEC MASK_ALTIVEC /* VMX/altivec vectors. */ @@ -2330,7 +2336,7 @@ extern int frame_pointer_needed; #define RS6000_BTM_LDBL128 MASK_MULTIPLE /* 128-bit long double. */ #define RS6000_BTM_64BIT MASK_64BIT /* 64-bit addressing. */ #define RS6000_BTM_POWERPC64 MASK_POWERPC64 /* 64-bit registers. */ -#define RS6000_BTM_FLOAT128 MASK_FLOAT128_KEYWORD /* IEEE 128-bit float. */ +#define RS6000_BTM_IBM128 MASK_FLOAT128_KEYWORD /* __ibm128 keyword. */ #define RS6000_BTM_FLOAT128_HW MASK_FLOAT128_HW /* IEEE 128-bit float h/w. */ #define RS6000_BTM_MMA MASK_MMA /* ISA 3.1 MMA. */ #define RS6000_BTM_P10 MASK_POWER10 @@ -2354,7 +2360,7 @@ extern int frame_pointer_needed; | RS6000_BTM_HARD_FLOAT \ | RS6000_BTM_LDBL128 \ | RS6000_BTM_POWERPC64 \ - | RS6000_BTM_FLOAT128 \ + | RS6000_BTM_IBM128 \ | RS6000_BTM_FLOAT128_HW \ | RS6000_BTM_MMA \ | RS6000_BTM_P10) -- 2.22.0 -- Michael Meissner, IBM IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797