public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, V3] Require GLIBC 2.32 for Decimal/_Float128 conversions.
@ 2021-03-04 21:01 Michael Meissner
  2021-03-10 16:46 ` [Ping, Patch " Michael Meissner
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Michael Meissner @ 2021-03-04 21:01 UTC (permalink / raw)
  To: gcc-patches, Michael Meissner, Segher Boessenkool,
	David Edelsohn, Bill Schmidt, Peter Bergner, Joseph Myers

[PATCH V3] Require GLIBC 2.32 for Decimal/_Float128 conversions.

In the patch that I applied on March 2nd, I had code to provide support for
Decimal/_Float128 conversions if the user did not use at least GLIBC 2.32.  It
did this by using __ibm128 as an intermediate type.  The trouble is __ibm128
cannot represent all of the numbers that _Float128 can, and you lose if you do
this conversion.

This patch removes this support.  The dfp-bit.c functions now call the the
__sprintfieee128 and __strtoieee128 functions to do the conversion.  If the
user does not have GLIBC, they will get a linker error that these functions do
not exist.

The float128 support functions are only built into the static libgcc, so there
isn't an issue with having references to __strtoieee128 and __sprintfieee128
with older GLIBC libraries.

As an added bonus, this patch eliminates the __sprintfkf function which
included stdio.h to get a definition for the sprintf library function.  This
allows for building cross compilers without having to have a target stdio.h
available.

I have built bootstrap compilers for power9 little endian systems with the
three different long double formats (IBM 128-bit, IEEE 128-bit, and 64-bit) and
there were no regressions from previous runs.  I have also build bootstrap
compilers on a big endian power8 and there was no regression there either.

Can I check this patch into the master branch?

libgcc/
2021-03-04  Michael Meissner  <meissner@linux.ibm.com>

	* config/rs6000/t-float128 (fp128_decstr_funcs): Delete.
	(fp128_ppc_funcs): Do not add $(fp128_decstr_funcs).
	(fp128_decstr_objs): Delete.
	* dfp-bit.h: Call __sprintfieee128 to do conversions from
	_Float128 to a Decimal type.  Call __strtoieee128 to do
	conversions from a Decimal type to _Float128.
	* config/rs6000/_sprintfkf.c: Delete file.
	* config/rs6000/_sprintfkf.h: Delete file.
	* config/rs6000/_strtokf.c: Delete file.
	* config/rs6000/_strtokf.h: Delete file.
---
 libgcc/config/rs6000/_sprintfkf.c | 58 -------------------------------
 libgcc/config/rs6000/_sprintfkf.h | 27 --------------
 libgcc/config/rs6000/_strtokf.c   | 53 ----------------------------
 libgcc/config/rs6000/_strtokf.h   | 27 --------------
 libgcc/config/rs6000/t-float128   | 13 +------
 libgcc/dfp-bit.h                  |  8 ++---
 6 files changed, 5 insertions(+), 181 deletions(-)
 delete mode 100644 libgcc/config/rs6000/_sprintfkf.c
 delete mode 100644 libgcc/config/rs6000/_sprintfkf.h
 delete mode 100644 libgcc/config/rs6000/_strtokf.c
 delete mode 100644 libgcc/config/rs6000/_strtokf.h

diff --git a/libgcc/config/rs6000/_sprintfkf.c b/libgcc/config/rs6000/_sprintfkf.c
deleted file mode 100644
index 2d624f14e25..00000000000
--- a/libgcc/config/rs6000/_sprintfkf.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Copyright (C) 1989-2021 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/>.  */
-
-/* Conversion to IEEE 128-bit floating point from string using snprintf.  */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <soft-fp.h>
-#include <quad-float128.h>
-#include <stdio.h>
-#include <_sprintfkf.h>
-
-/* This function must be built with IBM 128-bit as long double, so that we can
-   access the strfroml function if do not have an IEEE 128-bit version, and if
-   that is not available, use sprintf.  */
-#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IBM128__)
-#error "Long double is not IBM 128-bit"
-#endif
-
-/* If the user is using GLIBC 2.32, we can use the __snprintfieee128 function.
-
-   If we are linked against an earlier library, we will have fake it by
-   converting the value to long double, and using sprintf to do the conversion.
-   This isn't ideal, as IEEE 128-bit has more exponent range than IBM
-   128-bit.  */
-
-extern int __sprintfieee128 (char *restrict, const char *restrict, ...)
-  __attribute__ ((__weak__));
-
-int __sprintfkf (char *restrict string,
-		 const char *restrict format,
-		 _Float128 number)
-{
-  if (__sprintfieee128)
-    return __sprintfieee128 (string, format, number);
-
-  return sprintf (string, format, (long double) number);
-}
diff --git a/libgcc/config/rs6000/_sprintfkf.h b/libgcc/config/rs6000/_sprintfkf.h
deleted file mode 100644
index de9d7137f69..00000000000
--- a/libgcc/config/rs6000/_sprintfkf.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright (C) 1989-2021 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/>.  */
-
-/* Declaration of the conversion function to IEEE 128-bit floating point from
-   string using snprintf.  */
-
-extern int __sprintfkf (char *restrict, const char *restrict, _Float128);
diff --git a/libgcc/config/rs6000/_strtokf.c b/libgcc/config/rs6000/_strtokf.c
deleted file mode 100644
index dc13534cdc2..00000000000
--- a/libgcc/config/rs6000/_strtokf.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Copyright (C) 1989-2021 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/>.  */
-
-/* Conversion to IEEE 128-bit floating point from string.  */
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <soft-fp.h>
-#include <quad-float128.h>
-
-/* This function must be built with IBM 128-bit as long double, so that we can
-   access the strtold function if do not have an IEEE 128-bit version.  */
-#if !defined(__LONG_DOUBLE_128__) || !defined(__LONG_DOUBLE_IBM128__)
-#error "Long double is not IBM 128-bit"
-#endif
-
-/* If the user is using GLIBC 2.32, we can use the __strtoieee128 function.
-
-   If we are linked against an earlier library, we will have fake it by
-   converting the string to IBM 128-bit long double, and then converting that to
-   __float128.  This isn't ideal, as IEEE 128-bit has more exponent range than
-   IBM 128-bit.  */
-
-extern _Float128 __strtoieee128 (const char *, char **) __attribute__ ((__weak__));
-
-_Float128
-__strtokf (const char *string, char **endptr)
-{
-  if (__strtoieee128)
-    return __strtoieee128 (string, endptr);
-
-  return strtold (string, endptr);
-}
diff --git a/libgcc/config/rs6000/_strtokf.h b/libgcc/config/rs6000/_strtokf.h
deleted file mode 100644
index a7ca8e09244..00000000000
--- a/libgcc/config/rs6000/_strtokf.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* Copyright (C) 1989-2021 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/>.  */
-
-/* Declaration of the conversion function to IEEE 128-bit floating point from
-   string.  */
-
-extern _Float128 __strtokf (const char *, char **);
diff --git a/libgcc/config/rs6000/t-float128 b/libgcc/config/rs6000/t-float128
index 6fb1a3d871b..8b089d4433c 100644
--- a/libgcc/config/rs6000/t-float128
+++ b/libgcc/config/rs6000/t-float128
@@ -26,10 +26,6 @@ fp128_softfp_obj	= $(fp128_softfp_static_obj) $(fp128_softfp_shared_obj)
 fp128_dec_funcs		= _kf_to_sd _kf_to_dd _kf_to_td \
 			  _sd_to_kf _dd_to_kf _td_to_kf
 
-# _Float128 to/from string conversions that must be compiled with IBM 128-bit
-# long double.
-fp128_decstr_funcs	= _strtokf _sprintfkf
-
 # Decimal <-> __ibm128 conversions
 ibm128_dec_funcs	= _tf_to_sd _tf_to_dd _tf_to_td \
 			  _sd_to_tf _dd_to_tf _td_to_tf
@@ -38,7 +34,7 @@ ibm128_dec_funcs	= _tf_to_sd _tf_to_dd _tf_to_td \
 fp128_ppc_funcs		= floattikf floatuntikf fixkfti fixunskfti \
 			  extendkftf2-sw trunctfkf2-sw \
 			  sfp-exceptions _mulkc3 _divkc3 _powikf2 \
-			  $(fp128_dec_funcs) $(fp128_decstr_funcs)
+			  $(fp128_dec_funcs)
 
 fp128_ppc_src		= $(addprefix $(srcdir)/config/rs6000/,$(addsuffix \
 				.c,$(fp128_ppc_funcs)))
@@ -88,9 +84,6 @@ $(fp128_obj)		 : $(srcdir)/config/rs6000/quad-float128.h
 fp128_dec_objs		= $(addsuffix $(objext),$(fp128_dec_funcs)) \
 			  $(addsuffix _s$(objext),$(fp128_dec_funcs))
 
-fp128_decstr_objs	= $(addsuffix $(objext),$(fp128_decstr_funcs)) \
-			  $(addsuffix _s$(objext),$(fp128_decstr_funcs))
-
 ibm128_dec_objs		= $(addsuffix $(objext),$(ibm128_dec_funcs)) \
 			  $(addsuffix _s$(objext),$(ibm128_dec_funcs))
 
@@ -98,12 +91,8 @@ 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)
-$(fp128_decstr_objs)	: INTERNAL_CFLAGS += $(IBM128_CFLAGS_DECIMAL)
 $(ibm128_dec_objs)	: INTERNAL_CFLAGS += $(IBM128_CFLAGS_DECIMAL)
 
-$(fp128_decstr_objs)	: $(srcdir)/config/rs6000/_strtokf.h \
-			  $(srcdir)/config/rs6000/_sprintfkf.h \
-
 $(fp128_softfp_src) : $(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@)) $(fp128_dep)
 	@src="$(srcdir)/soft-fp/$(subst -sw,,$(subst kf,tf,$@))"; \
 	echo "Create $@"; \
diff --git a/libgcc/dfp-bit.h b/libgcc/dfp-bit.h
index 5e3bfa65ab8..e04cb831026 100644
--- a/libgcc/dfp-bit.h
+++ b/libgcc/dfp-bit.h
@@ -298,8 +298,8 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #define BFP_TYPE _Float128
 #define BFP_FMT "%.36Le"
 #define BFP_VIA_TYPE _Float128
-#define STR_TO_BFP __strtokf
-#include <_strtokf.h>
+#define STR_TO_BFP __strtoieee128
+extern _Float128 __strtoieee128 (const char *, char **);
 
 #endif /* BFP_KIND */
 
@@ -647,8 +647,8 @@ extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
 
 #elif defined (L_kf_to_sd) || defined (L_kf_to_dd) || defined (L_kf_to_td)
 extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
-#include <_sprintfkf.h>
-#define BFP_SPRINTF __sprintfkf
+extern int __sprintfieee128 (char *restrict, const char *restrict, ...);
+#define BFP_SPRINTF __sprintfieee128
 #endif
 
 #endif /* _DFPBIT_H */
-- 
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-25 14:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 21:01 [PATCH, V3] Require GLIBC 2.32 for Decimal/_Float128 conversions Michael Meissner
2021-03-10 16:46 ` [Ping, Patch " Michael Meissner
2021-03-22 17:06 ` [PATCH, " Matheus Castanho
2021-03-25 13:05   ` Segher Boessenkool
2021-03-25 14:07 ` Segher Boessenkool

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).