aboutsummaryrefslogtreecommitdiff
path: root/libgcc/dfp-bit.h
diff options
context:
space:
mode:
authorMichael Meissner <meissner@linux.ibm.com>2021-02-22 15:33:29 -0500
committerMichael Meissner <meissner@linux.ibm.com>2021-02-22 15:33:29 -0500
commit781183595acba67a37c66f59a0c1d9b5fee7e248 (patch)
treeaebce9b934a865fdd62b1307093b2b7cd0c14fa2 /libgcc/dfp-bit.h
parent8e99b5ba4c19526335fe9cabdc6df7fb2edcfe6f (diff)
downloadgcc-781183595acba67a37c66f59a0c1d9b5fee7e248.zip
gcc-781183595acba67a37c66f59a0c1d9b5fee7e248.tar.gz
gcc-781183595acba67a37c66f59a0c1d9b5fee7e248.tar.bz2
Add conversions between _Float128 and Decimal.
This patch implements conversions between _Float128 and the 3 Decimal floating types. It does this by extendending the dfp-bit conversions to add a new binary floating point type (KF), and doing the conversions in the same manner as the other binary/decimal conversions. For conversions from _Float128 to Decimal, this patch uses a function (__sprintfkf) instead of the sprintf function to convert long double values to strings. The __sprintfkf function determines if GLIBC 2.32 or newer is used and calls the IEEE 128-bit version of sprintf (__sprintfieee128). If the GLIBC is earlier than 2.32, the code will convert _Float128 to __ibm128 and then use the normal sprintf to convert this value. For conversions from Decimal to _Float128, this patch uses a function (__strtokf) instead of strtold to convert the strings from the Decimal conversion to long double. The __strtokf function determines if GLIBC 2.32 or newer is used, and if it is, calls the IEEE 128-bit version (__strtoieee128). If the GLIBC is earlier than 2.32, the code will call strtold and convert the __ibm128 value to _Float128. These functions will primarily be used if/when the default PowerPC long double type is changed to IEEE 128-bit, but they could also be used if the user explicitly converts _Float128 to/from a Decimal type. libgcc/ 2021-02-22 Michael Meissner <meissner@linux.ibm.com> * 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/_sprintfkf.c: New file. * config/rs6000/_sprintfkf.h: New file. * config/rs6000/_strtokf.h: New file. * config/rs6000/_strtokf.c: New file. * config/rs6000/_td_to_kf.c: New file. * config/rs6000/quad-float128.h: Add new declarations. * config/rs6000/t-float128 (fp128_dec_funcs): New macro. (fp128_decstr_funcs): New macro. (ibm128_dec_funcs): New macro. (fp128_ppc_funcs): Add the new conversions. (fp128_dec_objs): Force Decimal <-> __float128 conversions to be compiled with -mabi=ieeelongdouble. (fp128_decstr_objs): Force __float128 <-> string conversions to be compiled with -mabi=ibmlongdouble. (ibm128_dec_objs): Force Decimal <-> __float128 conversions to be compiled with -mabi=ieeelongdouble. (FP128_CFLAGS_DECIMAL): New macro. (IBM128_CFLAGS_DECIMAL): New macro. * dfp-bit.c (DFP_TO_BFP): Add PowerPC _Float128 support. (BFP_TO_DFP): Add PowerPC _Float128 support. * dfp-bit.h (BFP_KIND): Add new binary floating point kind for IEEE 128-bit floating point. (DFP_TO_BFP): Add PowerPC _Float128 support. (BFP_TO_DFP): Add PowerPC _Float128 support. (BFP_SPRINTF): New macro.
Diffstat (limited to 'libgcc/dfp-bit.h')
-rw-r--r--libgcc/dfp-bit.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/libgcc/dfp-bit.h b/libgcc/dfp-bit.h
index 1fa42ee..5e3bfa6 100644
--- a/libgcc/dfp-bit.h
+++ b/libgcc/dfp-bit.h
@@ -241,6 +241,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#elif defined (L_sd_to_tf) || defined (L_dd_to_tf) || defined (L_td_to_tf) \
|| defined (L_tf_to_sd) || defined (L_tf_to_dd) || defined (L_tf_to_td)
#define BFP_KIND 4
+#elif defined (L_sd_to_kf) || defined (L_dd_to_kf) || defined (L_td_to_kf) \
+ || defined (L_kf_to_sd) || defined (L_kf_to_dd) || defined (L_kf_to_td)
+#define BFP_KIND 5
#endif
/* If BFP_KIND is defined, define additional macros:
@@ -291,6 +294,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define BFP_VIA_TYPE long double
#endif /* LONG_DOUBLE_HAS_TF_MODE */
+#elif BFP_KIND == 5
+#define BFP_TYPE _Float128
+#define BFP_FMT "%.36Le"
+#define BFP_VIA_TYPE _Float128
+#define STR_TO_BFP __strtokf
+#include <_strtokf.h>
+
#endif /* BFP_KIND */
#if WIDTH == 128 || WIDTH_TO == 128
@@ -490,6 +500,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#elif BFP_KIND == 4
#define BFP_TO_DFP DPD_BID_NAME(__dpd_trunctfsd,__bid_trunctfsd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsdtf,__bid_extendsdtf)
+#elif BFP_KIND == 5
+#define BFP_TO_DFP DPD_BID_NAME(__dpd_trunckfsd,__bid_trunckfsd)
+#define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsdkf,__bid_extendsdkf)
#endif /* BFP_KIND */
#elif WIDTH == 64
@@ -505,6 +518,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#elif BFP_KIND == 4
#define BFP_TO_DFP DPD_BID_NAME(__dpd_trunctfdd,__bid_trunctfdd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_extendddtf,__bid_extendddtf)
+#elif BFP_KIND == 5
+#define BFP_TO_DFP DPD_BID_NAME(__dpd_trunckfdd,__bid_trunckfdd)
+#define DFP_TO_BFP DPD_BID_NAME(__dpd_extendddkf,__bid_extendddkf)
#endif /* BFP_KIND */
#elif WIDTH == 128
@@ -520,6 +536,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#elif BFP_KIND == 4
#define BFP_TO_DFP DPD_BID_NAME(__dpd_extendtftd,__bid_extendtftd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdtf,__bid_trunctdtf)
+#elif BFP_KIND == 5
+#define BFP_TO_DFP DPD_BID_NAME(__dpd_extendkftd,__bid_extendkftd)
+#define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdkf,__bid_trunctdkf)
#endif /* BFP_KIND */
#endif /* WIDTH */
@@ -609,6 +628,7 @@ extern DFP_C_TYPE INT_TO_DFP (INT_TYPE);
#if defined (L_sd_to_sf) || defined (L_dd_to_sf) || defined (L_td_to_sf) \
|| defined (L_sd_to_df) || defined (L_dd_to_df) || defined (L_td_to_df) \
+ || defined (L_sd_to_kf) || defined (L_dd_to_kf) || defined (L_td_to_kf) \
|| ((defined (L_sd_to_xf) || defined (L_dd_to_xf) || defined (L_td_to_xf)) \
&& LONG_DOUBLE_HAS_XF_MODE) \
|| ((defined (L_sd_to_tf) || defined (L_dd_to_tf) || defined (L_td_to_tf)) \
@@ -623,6 +643,12 @@ extern BFP_TYPE DFP_TO_BFP (DFP_C_TYPE);
|| ((defined (L_tf_to_sd) || defined (L_tf_to_dd) || defined (L_tf_to_td)) \
&& LONG_DOUBLE_HAS_TF_MODE)
extern DFP_C_TYPE BFP_TO_DFP (BFP_TYPE);
+#define BFP_SPRINTF sprintf
+
+#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
#endif
#endif /* _DFPBIT_H */