[PATCH] PowerPC: Add float128/Decimal conversions

Michael Meissner meissner@linux.ibm.com
Fri Nov 20 00:05:24 GMT 2020


[PATCH] PowerPC: Add float128/Decimal conversions.

I accidently posted this patch on an internal IBM mailing list instead of
gcc-patches.

This patch replaces the following two patches:

September 24th, 2020:
Message-ID: <20200924203545.GD31597@ibm-toto.the-meissners.org>

October 22nd, 2020:
Message-ID: <20201022220603.GA11658@ibm-toto.the-meissners.org>

This is a simplification of those patches.  Those patches were initially
written before I was using the final glibc 2.32 (Advance Toolchain AT14.0).
With using that glibc and with the previous IEEE patches submitted, I can
simplify the conversions to just use the long double defaults, compiling the
modules for IEEE 128-bit long double.  It works because stdio.h/gcc switches
the sprintf call to __sprintfieee128, and the strtold call to __strtof128.

While most of the Decimal <-> Long double tests now pass when long doubles are
IEEE 128-bit, there is one test that fails:

	c-c++-common/dfp/convert-bfp-11.c

This test explicitly expects long double to be IBM 128-bit extended double.  A
later patch will fix this.

If the glibc is not 2.32 or later, this code just compiles to using abort.
That way the user won't get unknown reference errors due to the calls to the
glibc 2.32 functions that aren't in previous glibcs.

This patch is one of three critical patches needed to be able to build
compilers where the default is IEEE 128-bit.  The other patches were the
patches to rename the built-in functions, and the patches for prs 97543 and
97643 that were both posted earlier.

I have tested this patch on a little endian power9 system running Linux,
building bootstrap compilers with the 3 long double flavors (long double is
128-bit IEEE, long double is 128-bit IBM, and long double is 64-bit).  There
are no regressions with long double set to 128-bit IBM.

With the exception of convert-bfp-11.c mentioned above, none of the regressions
in the long double set to 128-bit IEEE affect the decimal support.

Can I check this into the master branch?

libgcc/
2020-11-17  Michael Meissner  <meissner@linux.ibm.com>

	* config/rs6000/t-float128 (fp128_dec_funcs): New macro.
	(ibm128_dec_funcs): New macro.
	(fp128_ppc_funcs): Add the Decimal <-> __float128 conversions.
	(fp128_dec_objs): Force Decimal <-> __float128 conversions to be
	compiled with -mabi=ieeelongdouble.
	(ibm128_dec_objs): Force Decimal <-> __float128 conversions to be
	compiled with -mabi=ieeelongdouble.
	(FP128_CFLAGS_DECIMAL): New macro.
	(IBM128_CFLAGS_DECIMAL): New macro.
	* config/rs6000/_dd_to_kf.c: New file.
	* config/rs6000/_kf_to_dd.c: New file.
	* config/rs6000/_kf_to_sd.c: New file.
	* config/rs6000/_kf_to_td.c: New file.
	* config/rs6000/_sd_to_kf.c: New file.
	* config/rs6000/_td_to_kf.c: New file.
---
 libgcc/config/rs6000/_dd_to_kf.c | 58 +++++++++++++++++++++++++++++++
 libgcc/config/rs6000/_kf_to_dd.c | 57 ++++++++++++++++++++++++++++++
 libgcc/config/rs6000/_kf_to_sd.c | 58 +++++++++++++++++++++++++++++++
 libgcc/config/rs6000/_kf_to_td.c | 56 ++++++++++++++++++++++++++++++
 libgcc/config/rs6000/_sd_to_kf.c | 59 ++++++++++++++++++++++++++++++++
 libgcc/config/rs6000/_td_to_kf.c | 58 +++++++++++++++++++++++++++++++
 libgcc/config/rs6000/t-float128  | 26 +++++++++++++-
 7 files changed, 371 insertions(+), 1 deletion(-)
 create mode 100644 libgcc/config/rs6000/_dd_to_kf.c
 create mode 100644 libgcc/config/rs6000/_kf_to_dd.c
 create mode 100644 libgcc/config/rs6000/_kf_to_sd.c
 create mode 100644 libgcc/config/rs6000/_kf_to_td.c
 create mode 100644 libgcc/config/rs6000/_sd_to_kf.c
 create mode 100644 libgcc/config/rs6000/_td_to_kf.c

diff --git a/libgcc/config/rs6000/_dd_to_kf.c b/libgcc/config/rs6000/_dd_to_kf.c
new file mode 100644
index 00000000000..93601fa280e
--- /dev/null
+++ b/libgcc/config/rs6000/_dd_to_kf.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Decimal64 -> _Float128 conversion.  */
+
+/* FINE_GRAINED_LIBRARIES is used so we can isolate just to dd_to_tf conversion
+   function from dp-bits.c.  */
+#define FINE_GRAINED_LIBRARIES	1
+#define L_dd_to_tf		1
+#define WIDTH			64
+
+#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IEEE128__)
+#error "Long double is not IEEE 128-bit"
+#endif
+
+/* If we don't have at least GLIBC 2.32, the strtold used by dfp-bit.c does not
+   have support for float128.  Add an abort in case this is called.  */
+#include <features.h>
+
+#if ((__GLIBC__ * 1000) + __GLIBC_MINOR__) < 2032
+
+#include <stdlib.h>
+extern long double __dpd_extendddkf (_Decimal64);
+
+long double
+__dpd_extendddkf (_Decimal64 x __attribute__ ((unused)))
+{
+  abort ();
+}
+
+#else
+
+/* Map the external name to the float128 default.  */
+#define __dpd_extendddtf	__dpd_extendddkf
+
+/* Use dfp-bit.c to do the real work.  */
+#include "dfp-bit.c"
+#endif
diff --git a/libgcc/config/rs6000/_kf_to_dd.c b/libgcc/config/rs6000/_kf_to_dd.c
new file mode 100644
index 00000000000..fa4cc7e1716
--- /dev/null
+++ b/libgcc/config/rs6000/_kf_to_dd.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* _Float128 -> Decimal64 conversion.  */
+
+/* FINE_GRAINED_LIBRARIES is used so we can isolate just to tf_to_dd conversion
+   function from dp-bits.c.  */
+#define FINE_GRAINED_LIBRARIES	1
+#define L_tf_to_dd		1
+#define WIDTH			64
+
+#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IEEE128__)
+#error "Long double is not IEEE 128-bit"
+#endif
+
+/* If we don't have at least GLIBC 2.32, the strtold used by dfp-bit.c does not
+   have support for float128.  Add an abort in case this is called.  */
+#include <features.h>
+
+#if ((__GLIBC__ * 1000) + __GLIBC_MINOR__) < 2032
+
+#include <stdlib.h>
+extern _Decimal64 __dpd_trunckfdd (long double);
+
+_Decimal64
+__dpd_trunckfdd (long double x __attribute__ ((unused)))
+{
+  abort ();
+}
+
+#else
+/* Map the external name to the float128 default.  */
+#define __dpd_trunctfdd		__dpd_trunckfdd
+
+/* Use dfp-bit.c to do the real work.  */
+#include "dfp-bit.c"
+#endif
diff --git a/libgcc/config/rs6000/_kf_to_sd.c b/libgcc/config/rs6000/_kf_to_sd.c
new file mode 100644
index 00000000000..ec92d697f84
--- /dev/null
+++ b/libgcc/config/rs6000/_kf_to_sd.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* _Float128 -> Decimal32 conversion.  */
+
+/* FINE_GRAINED_LIBRARIES is used so we can isolate just to tf_to_sd conversion
+   function from dp-bits.c.  */
+#define FINE_GRAINED_LIBRARIES	1
+#define L_tf_to_sd		1
+#define WIDTH			32
+
+#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IEEE128__)
+#error "Long double is not IEEE 128-bit"
+#endif
+
+/* If we don't have at least GLIBC 2.32, the strtold used by dfp-bit.c does not
+   have support for float128.  Add an abort in case this is called.  */
+#include <features.h>
+
+#if ((__GLIBC__ * 1000) + __GLIBC_MINOR__) < 2032
+
+#include <stdlib.h>
+extern _Decimal32 __dpd_extendkfsd (long double);
+
+_Decimal32
+__dpd_extendkfsd (long double x __attribute__ ((unused)))
+{
+  abort ();
+}
+
+#else
+
+/* Map the external name to the float128 default.  */
+#define __dpd_trunctfsd	__dpd_trunckfsd
+
+/* Use dfp-bit.c to do the real work.  */
+#include "dfp-bit.c"
+#endif
diff --git a/libgcc/config/rs6000/_kf_to_td.c b/libgcc/config/rs6000/_kf_to_td.c
new file mode 100644
index 00000000000..9a8f65647ea
--- /dev/null
+++ b/libgcc/config/rs6000/_kf_to_td.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* _Float128 -> Decimal128 conversion.  */
+
+/* FINE_GRAINED_LIBRARIES is used so we can isolate just to tf_to_td conversion
+   function from dp-bits.c.  */
+#define FINE_GRAINED_LIBRARIES	1
+#define L_tf_to_td		1
+#define WIDTH			128
+
+#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IEEE128__)
+#error "Long double is not IEEE 128-bit"
+#endif
+
+/* If we don't have at least GLIBC 2.32, the strtold used by dfp-bit.c does not
+   have support for float128.  Add an abort in case this is called.  */
+#include <features.h>
+
+#if ((__GLIBC__ * 1000) + __GLIBC_MINOR__) < 2032
+
+extern _Decimal128 __dpd_extendkftd (long double);
+
+_Decimal128
+__dpd_extendkftd (long double x __attribute__ ((unused)))
+{
+  abort ();
+}
+
+#else
+/* Map the external name to the float128 default.  */
+#define __dpd_extendtftd	__dpd_extendkftd
+
+/* Use dfp-bit.c to do the real work.  */
+#include "dfp-bit.c"
+#endif
diff --git a/libgcc/config/rs6000/_sd_to_kf.c b/libgcc/config/rs6000/_sd_to_kf.c
new file mode 100644
index 00000000000..3c2f04d3f78
--- /dev/null
+++ b/libgcc/config/rs6000/_sd_to_kf.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Decimal32 -> _Float128 conversion.  */
+
+/* FINE_GRAINED_LIBRARIES is used so we can isolate just to sd_to_tf conversion
+   function from dp-bits.c.  */
+#define FINE_GRAINED_LIBRARIES	1
+#define L_sd_to_tf		1
+#define WIDTH			32
+
+#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IEEE128__)
+#error "Long double is not IEEE 128-bit"
+#endif
+
+/* If we don't have at least GLIBC 2.32, the strtold used by dfp-bit.c does not
+   have support for float128.  Add an abort in case this is called.  */
+#include <features.h>
+
+#if ((__GLIBC__ * 1000) + __GLIBC_MINOR__) < 2032
+
+#include <stdlib.h>
+extern long double __dpd_extendsdkf (_Decimal32);
+
+long double
+__dpd_extendsdkf (_Decimal32 x __attribute__ ((unused)))
+{
+  abort ();
+}
+
+#else
+
+
+/* Map the external name to the float128 default.  */
+#define __dpd_extendsdtf	__dpd_extendsdkf
+
+/* Use dfp-bit.c to do the real work.  */
+#include "dfp-bit.c"
+#endif
diff --git a/libgcc/config/rs6000/_td_to_kf.c b/libgcc/config/rs6000/_td_to_kf.c
new file mode 100644
index 00000000000..26eefabdabc
--- /dev/null
+++ b/libgcc/config/rs6000/_td_to_kf.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* Decimal128 -> _Float128 conversion.  */
+
+/* FINE_GRAINED_LIBRARIES is used so we can isolate just to td_to_tf conversion
+   function from dp-bits.c.  */
+#define FINE_GRAINED_LIBRARIES	1
+#define L_td_to_tf		1
+#define WIDTH			128
+
+#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IEEE128__)
+#error "Long double is not IEEE 128-bit"
+#endif
+
+/* If we don't have at least GLIBC 2.32, the strtold used by dfp-bit.c does not
+   have support for float128.  Add an abort in case this is called.  */
+#include <features.h>
+
+#if ((__GLIBC__ * 1000) + __GLIBC_MINOR__) < 2032
+
+#include <stdlib.h>
+extern long double __dpd_trunctdkf (_Decimal128);
+
+long double
+__dpd_trunctdkf (_Decimal128 x __attribute__ ((unused)))
+{
+  abort ();
+}
+
+#else
+
+/* Map the external name to the float128 default.  */
+#define __dpd_trunctdtf	__dpd_trunctdkf
+
+/* Use dfp-bit.c to do the real work.  */
+#include "dfp-bit.c"
+#endif
diff --git a/libgcc/config/rs6000/t-float128 b/libgcc/config/rs6000/t-float128
index d5413445189..8b089d4433c 100644
--- a/libgcc/config/rs6000/t-float128
+++ b/libgcc/config/rs6000/t-float128
@@ -22,10 +22,19 @@ fp128_softfp_static_obj	= $(addsuffix -sw$(objext),$(fp128_softfp_funcs))
 fp128_softfp_shared_obj	= $(addsuffix -sw_s$(objext),$(fp128_softfp_funcs))
 fp128_softfp_obj	= $(fp128_softfp_static_obj) $(fp128_softfp_shared_obj)
 
+# Decimal <-> _Float128 conversions
+fp128_dec_funcs		= _kf_to_sd _kf_to_dd _kf_to_td \
+			  _sd_to_kf _dd_to_kf _td_to_kf
+
+# Decimal <-> __ibm128 conversions
+ibm128_dec_funcs	= _tf_to_sd _tf_to_dd _tf_to_td \
+			  _sd_to_tf _dd_to_tf _td_to_tf
+
 # New functions for software emulation
 fp128_ppc_funcs		= floattikf floatuntikf fixkfti fixunskfti \
 			  extendkftf2-sw trunctfkf2-sw \
-			  sfp-exceptions _mulkc3 _divkc3 _powikf2
+			  sfp-exceptions _mulkc3 _divkc3 _powikf2 \
+			  $(fp128_dec_funcs)
 
 fp128_ppc_src		= $(addprefix $(srcdir)/config/rs6000/,$(addsuffix \
 				.c,$(fp128_ppc_funcs)))
@@ -69,6 +78,21 @@ $(fp128_ppc_obj)	 : INTERNAL_CFLAGS += $(FP128_CFLAGS_SW)
 $(fp128_obj)		 : $(fp128_includes)
 $(fp128_obj)		 : $(srcdir)/config/rs6000/quad-float128.h
 
+# Force the TF mode to/from decimal functions to be compiled with IBM long
+# double.  Add building the KF mode to/from decimal conversions with explict
+# IEEE long double.
+fp128_dec_objs		= $(addsuffix $(objext),$(fp128_dec_funcs)) \
+			  $(addsuffix _s$(objext),$(fp128_dec_funcs))
+
+ibm128_dec_objs		= $(addsuffix $(objext),$(ibm128_dec_funcs)) \
+			  $(addsuffix _s$(objext),$(ibm128_dec_funcs))
+
+FP128_CFLAGS_DECIMAL	= -mno-gnu-attribute -Wno-psabi -mabi=ieeelongdouble
+IBM128_CFLAGS_DECIMAL	= -mno-gnu-attribute -Wno-psabi -mabi=ibmlongdouble
+
+$(fp128_dec_objs)	: INTERNAL_CFLAGS += $(FP128_CFLAGS_DECIMAL)
+$(ibm128_dec_objs)	: INTERNAL_CFLAGS += $(IBM128_CFLAGS_DECIMAL)
+
 $(fp128_softfp_src) : $(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@)) $(fp128_dep)
 	@src="$(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@))"; \
 	echo "Create $@"; \
-- 
2.22.0


-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.ibm.com, phone: +1 (978) 899-4797


More information about the Gcc-patches mailing list