[gcc(refs/users/meissner/heads/work031)] Rework Decimal/_Float128 conversion.
Michael Meissner
meissner@gcc.gnu.org
Wed Jan 6 20:59:00 GMT 2021
https://gcc.gnu.org/g:52bdf2615100c8a01446088bf796bd6f0a0600c5
commit 52bdf2615100c8a01446088bf796bd6f0a0600c5
Author: Michael Meissner <meissner@linux.ibm.com>
Date: Wed Jan 6 15:58:04 2021 -0500
Rework Decimal/_Float128 conversion.
libgcc/
2021-01-06 Michael Meissner <meissner@linux.ibm.com>
* config/rs6000/_strfromkf.c (__strfromkf): Rework slightly. Use
_Float128 explicitly instead of TFmode.
* config/rs6000/_strtokf.c (__strtokf): Likewise.
* config/rs6000/quad-float128.h (toplevel): Include stddef.h.
(__strtokf): Change prototype.
(__strfromkf): Change prototype.
Diff:
---
libgcc/config/rs6000/_strfromkf.c | 20 +++++++++-----------
libgcc/config/rs6000/_strtokf.c | 6 +++---
libgcc/config/rs6000/quad-float128.h | 11 +++++++----
3 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/libgcc/config/rs6000/_strfromkf.c b/libgcc/config/rs6000/_strfromkf.c
index 8cc7385b7b9..f8469ce10f0 100644
--- a/libgcc/config/rs6000/_strfromkf.c
+++ b/libgcc/config/rs6000/_strfromkf.c
@@ -39,26 +39,24 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#error "Long double is not IBM 128-bit"
#endif
-/* If the user is using GLIBC 2.32, we can use the __strfromieee128 function.
+/* 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 snprinf to do the conversion.
This isn't ideal, as IEEE 128-bit has more exponent range than IBM
128-bit. */
-extern int __strfromieee128 (char *restrict, size_t, const char *restrict,
- TFtype)
- __attribute__ ((__weak__));
+typedef int snprintf_type (char *restrict, size_t, const char *restrict, ...);
+
+extern snprintf_type __snprintfieee128 __attribute__ ((__weak__));
int __strfromkf (char *restrict string,
- unsigned long size,
+ size_t size,
const char *restrict format,
- TFtype number)
+ _Float128 number)
{
- size_t size2 = size;
-
- if (__strfromieee128)
- return __strfromieee128 (string, size2, format, number);
+ if (__snprintfieee128)
+ return __snprintfieee128 (string, size, format, number);
- return snprintf (string, size2, format, (long double)number);
+ return snprintf (string, size, format, (long double)number);
}
diff --git a/libgcc/config/rs6000/_strtokf.c b/libgcc/config/rs6000/_strtokf.c
index fe9f2630f61..696a2c907bb 100644
--- a/libgcc/config/rs6000/_strtokf.c
+++ b/libgcc/config/rs6000/_strtokf.c
@@ -41,9 +41,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
__float128. This isn't ideal, as IEEE 128-bit has more exponent range than
IBM 128-bit. */
-extern TFtype __strtoieee128 (const char *, char **) __attribute__ ((__weak__));
+extern _Float128 __strtoieee128 (const char *, char **) __attribute__ ((__weak__));
-TFtype
+_Float128
__strtokf (const char *string, char **endptr)
{
long double num;
@@ -52,5 +52,5 @@ __strtokf (const char *string, char **endptr)
return __strtoieee128 (string, endptr);
num = strtold (string, endptr);
- return (TFtype) num;
+ return (_Float128) num;
}
diff --git a/libgcc/config/rs6000/quad-float128.h b/libgcc/config/rs6000/quad-float128.h
index b1d7ff91085..5beb1531d2b 100644
--- a/libgcc/config/rs6000/quad-float128.h
+++ b/libgcc/config/rs6000/quad-float128.h
@@ -49,6 +49,7 @@ typedef __complex float TCtype __attribute__ ((mode (TC)));
#pragma GCC target ("vsx,float128")
#endif
+#include <stddef.h>
#include <quad.h>
#define IBM128_TYPE __ibm128
@@ -171,10 +172,12 @@ extern TFtype __trunctfkf2 (IBM128_TYPE);
extern TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype);
extern TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype);
-/* Convert IEEE 128-bit floating point to/from string. */
-extern TFtype __strtokf (const char *, char **);
-extern int __strfromkf (char *restrict, unsigned long, const char *restrict,
- 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. */
+extern _Float128 __strtokf (const char *, char **);
+extern int __strfromkf (char *restrict, size_t, const char *restrict,
+ _Float128);
/* Implementation of conversions between __ibm128 and __float128, to allow the
same code to be used on systems with IEEE 128-bit emulation and with IEEE
More information about the Gcc-cvs
mailing list