gcc/libgcc/dfp-bit.h

655 lines
23 KiB
C
Raw Normal View History

/* Header file for dfp-bit.c.
2021-01-04 10:26:59 +01:00
Copyright (C) 2005-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/>. */
#ifndef _DFPBIT_H
#define _DFPBIT_H
#include <float.h>
#include <fenv.h>
#include <decRound.h>
#include <decExcept.h>
#include "tconfig.h"
#include "coretypes.h"
#include "tm.h"
Move libgcc_tm_file to toplevel libgcc gcc: * configure.ac (libgcc_tm_file_list, libgcc_tm_include_list): Remove. * configure: Regenerate. * Makefile.in (libgcc_tm_file_list, libgcc_tm_include_list): Remove. (TM_H): Remove libgcc_tm.h, $(libgcc_tm_file_list). (libgcc_tm.h, cs-libgcc_tm.h): Remove. (clean): Remove libgcc_tm.h * mkconfig.sh: Don't include libgcc_tm.h in tm.h. * config.gcc (libgcc_tm_file): Remove. (arm*-*-linux*): Remove libgcc_tm_file for arm*-*-linux-*eabi. (arm*-*-uclinux*): Remove libgcc_tm_file for arm*-*-uclinux*eabi. (arm*-*-eabi*, arm*-*-symbianelf*): Remove libgcc_tm_file. (avr-*-rtems*): Likewise. (avr-*-*): Likewise. (frv-*-elf): Likewise. (frv-*-*linux*): Likewise. (h8300-*-rtems*): Likewise. (h8300-*-elf*): Likewise. (i[34567]86-*-darwin*): Likewise. (x86_64-*-darwin*): Likewise. (rx-*-elf*): Likewise. (tic6x-*-elf): Likewise. (tic6x-*-uclinux): Likewise. (i[34567]86-*-linux*, x86_64-*-linux*): Likewise. libgcc: * configure.ac (tm_file_): New variable. Determine from tm_file. (tm_file, tm_defines): Substitute. * configure: Regenerate. * mkheader.sh: New file. * Makefile.in (clean): Remove libgcc_tm.h. ($(objects)): Depend on libgcc_tm.h. (libgcc_tm_defines, libgcc_tm_file): New variables. (libgcc_tm.h, libgcc_tm.stamp): New targets. ($(libgcc-objects), $(libgcc-s-objects), $(libgcc-eh-objects)) ($(libgcov-objects), $(libunwind-objects), $(libunwind-s-objects)) ($(extra-parts)): Depend on libgcc_tm.h. * config.host (tm_defines, tm_file): New variable. (arm*-*-linux*): Set tm_file for arm*-*-linux-*eabi. (arm*-*-uclinux*): Set tm_file for arm*-*-uclinux*eabi. (arm*-*-eabi*, arm*-*-symbianelf*): Set tm_file. (avr-*-rtems*): Likewise. (avr-*-*): Likewise. (frv-*-elf): Likewise. (frv-*-*linux*): Likewise. (h8300-*-rtems*): Likewise. (h8300-*-elf*): Likewise. (i[34567]86-*-darwin*): Likewise. (x86_64-*-darwin*): Likewise. (rx-*-elf): Likewise. (tic6x-*-uclinux): Likewise. (tic6x-*-elf): Likewise. (i[34567]86-*-linux*, x86_64-*-linux*): Likewise. * config/alpha/gthr-posix.c: Include libgcc_tm.h. * config/i386/cygming-crtbegin.c: Likewise. * config/i386/cygming-crtend.c: Likewise. * config/ia64/fde-vms.c: Likewise. * config/ia64/unwind-ia64.c: Likewise. * config/libbid/bid_gcc_intrinsics.h: Likewise. * config/rs6000/darwin-fallback.c: Likewise. * config/stormy16/lib2funcs.c: Likewise. * config/xtensa/unwind-dw2-xtensa.c: Likewise. * crtstuff.c: Likewise. * dfp-bit.h: Likewise. * emutls.c: Likewise. * fixed-bit.c: Likewise. * fp-bit.c: Likewise. * generic-morestack-thread.c: Likewise. * generic-morestack.c: Likewise. * libgcc2.c: Likewise. * libgcov.c: Likewise. * unwind-dw2-fde-dip.c: Likewise. * unwind-dw2-fde.c: Likewise. * unwind-dw2.c: Likewise. * unwind-sjlj.c: Likewise. Co-Authored-By: Paolo Bonzini <bonzini@gnu.org> From-SVN: r180775
2011-11-02 16:26:35 +01:00
#include "libgcc_tm.h"
/* We need to know the size of long double that the C library supports.
Don't use LIBGCC2_HAS_XF_MODE or LIBGCC2_HAS_TF_MODE here because
some targets set both of those. */
Remove LIBGCC2_LONG_DOUBLE_TYPE_SIZE target macro. This patch removes the target macro LIBGCC2_LONG_DOUBLE_TYPE_SIZE. After recent changes, this macro was used in two ways in libgcc: to determine the mode of long double in dfp-bit.h, and to determine whether a particular mode has excess precision for use in complex multiplication. The former is concerned specifically with long double: it relates to use of strtold for converting between decimal and binary floating point. This is replaced by comparing __LDBL_MANT_DIG__ with the appropriate __LIBGCC_*_MANT_DIG__ macro. The latter is replaced __LIBGCC_*_EXCESS_PRECISION__ predefined macros. Remarks: * Comparing (__LDBL_MANT_DIG__ == __LIBGCC_XF_MANT_DIG__) is more fragile than it looks; it's possible for XFmode to have 53-bit mantissa (TARGET_96_ROUND_53_LONG_DOUBLE, on FreeBSD and DragonFlyBSD 32-bit), in which case such a comparison would not distinguish XFmode and DFmode as possible modes for long double. Fortunately, no target supporting that form of XFmode also supports long double = double (but if some target did, we'd need e.g. an additional macro giving the exponent range of each mode). Furthermore, this code doesn't actually get used for x86 (or any other target with XFmode support), because x86 uses BID not DPD and BID has its own conversion code (which handles conversions for both XFmode and TFmode without needing to go via strtold). And FreeBSD and DragonFlyBSD aren't among the targets with DFP support. So while in principle this code is fragile and it's a deficiency that it can't support both XFmode and TFmode at once (something that can't be solved with the string conversion approach without libc having TS 18661 functions such as strtof128), all these issues should not be a problem in practice. * If other cases of excess precision are supported in future, the code for defining __LIBGCC_*_EXCESS_PRECISION__ may need updating. Although the most likely such cases might not actually involve excess precision for any mode used in libgcc - FLT_EVAL_METHOD being 32 to do _Float16 arithmetic on _Float32 should have the effect of _Complex _Float16 arithmetic using __mulsc3 and __divsc3, rather than currently nonexistent __mulhc3 and __divhc3 as in bug 63250 for ARM. * As has been noted in the context of simultaneous support for __float128 and __ibm128 on Power, the semantics of macros such as LONG_DOUBLE_TYPE_SIZE are problematic because they rely on a poorly-defined precision value for floating-point modes (which seems to be intended as the number of significant bits in the representation, e.g. 80 for XFmode which may be either 12 or 16 bytes) uniquely identifying a mode (although defining an arbitrarily different value for one of the modes you wish to distinguish may work as a hack). It would be cleaner to have a target hook that gives a machine mode directly for float, double and long double, rather than going via these precision values. By eliminating all use of these macros (FLOAT_TYPE_SIZE, DOUBLE_TYPE_SIZE, LONG_DOUBLE_TYPE_SIZE) from code built for the target, this patch facilitates such a conversion to a hook (which I suppose would take some suitable enum as an argument to identify which of the three types to return a mode for). (The issue of multiple type support for DFP conversions would apply in that Power case. <https://gcc.gnu.org/ml/gcc-patches/2014-07/msg01084.html> doesn't seem to touch on it, but it would seem reasonable to punt on it initially as hard to fix. There would also be the issue of getting functions such as __powikf2, __mulkc3, __divkc3 defined, but that's rather easier to address.) Bootstrapped with no regressions on x86_64-unknown-linux-gnu. gcc: * doc/tm.texi.in (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * doc/tm.texi: Regenerate. * system.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Poison. * config/alpha/alpha.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386-interix.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/rtemself.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/ia64/ia64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/m68k.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/mips.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/n32-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/msp430/msp430.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rl78/rl78.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rs6000/rs6000.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rx/rx.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/s390/s390.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/freebsd.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. gcc/c-family: * c-cppbuiltin.c (c_cpp_builtins): Define __LIBGCC_*_EXCESS_PRECISION__ macros for supported floating-point modes. libgcc: * dfp-bit.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. (__LIBGCC_XF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_XF_MODE): Define in terms of __LIBGCC_XF_MANT_DIG__. (__LIBGCC_TF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_TF_MODE): Define in terms of __LIBGCC_TF_MANT_DIG__. * libgcc2.c (NOTRUNC): Define in terms of __LIBGCC_*_EXCESS_PRECISION__, not LIBGCC2_LONG_DOUBLE_TYPE_SIZE. * libgcc2.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. From-SVN: r215491
2014-09-23 02:48:46 +02:00
#ifndef __LIBGCC_XF_MANT_DIG__
#define __LIBGCC_XF_MANT_DIG__ 0
#endif
#define LONG_DOUBLE_HAS_XF_MODE \
Remove LIBGCC2_LONG_DOUBLE_TYPE_SIZE target macro. This patch removes the target macro LIBGCC2_LONG_DOUBLE_TYPE_SIZE. After recent changes, this macro was used in two ways in libgcc: to determine the mode of long double in dfp-bit.h, and to determine whether a particular mode has excess precision for use in complex multiplication. The former is concerned specifically with long double: it relates to use of strtold for converting between decimal and binary floating point. This is replaced by comparing __LDBL_MANT_DIG__ with the appropriate __LIBGCC_*_MANT_DIG__ macro. The latter is replaced __LIBGCC_*_EXCESS_PRECISION__ predefined macros. Remarks: * Comparing (__LDBL_MANT_DIG__ == __LIBGCC_XF_MANT_DIG__) is more fragile than it looks; it's possible for XFmode to have 53-bit mantissa (TARGET_96_ROUND_53_LONG_DOUBLE, on FreeBSD and DragonFlyBSD 32-bit), in which case such a comparison would not distinguish XFmode and DFmode as possible modes for long double. Fortunately, no target supporting that form of XFmode also supports long double = double (but if some target did, we'd need e.g. an additional macro giving the exponent range of each mode). Furthermore, this code doesn't actually get used for x86 (or any other target with XFmode support), because x86 uses BID not DPD and BID has its own conversion code (which handles conversions for both XFmode and TFmode without needing to go via strtold). And FreeBSD and DragonFlyBSD aren't among the targets with DFP support. So while in principle this code is fragile and it's a deficiency that it can't support both XFmode and TFmode at once (something that can't be solved with the string conversion approach without libc having TS 18661 functions such as strtof128), all these issues should not be a problem in practice. * If other cases of excess precision are supported in future, the code for defining __LIBGCC_*_EXCESS_PRECISION__ may need updating. Although the most likely such cases might not actually involve excess precision for any mode used in libgcc - FLT_EVAL_METHOD being 32 to do _Float16 arithmetic on _Float32 should have the effect of _Complex _Float16 arithmetic using __mulsc3 and __divsc3, rather than currently nonexistent __mulhc3 and __divhc3 as in bug 63250 for ARM. * As has been noted in the context of simultaneous support for __float128 and __ibm128 on Power, the semantics of macros such as LONG_DOUBLE_TYPE_SIZE are problematic because they rely on a poorly-defined precision value for floating-point modes (which seems to be intended as the number of significant bits in the representation, e.g. 80 for XFmode which may be either 12 or 16 bytes) uniquely identifying a mode (although defining an arbitrarily different value for one of the modes you wish to distinguish may work as a hack). It would be cleaner to have a target hook that gives a machine mode directly for float, double and long double, rather than going via these precision values. By eliminating all use of these macros (FLOAT_TYPE_SIZE, DOUBLE_TYPE_SIZE, LONG_DOUBLE_TYPE_SIZE) from code built for the target, this patch facilitates such a conversion to a hook (which I suppose would take some suitable enum as an argument to identify which of the three types to return a mode for). (The issue of multiple type support for DFP conversions would apply in that Power case. <https://gcc.gnu.org/ml/gcc-patches/2014-07/msg01084.html> doesn't seem to touch on it, but it would seem reasonable to punt on it initially as hard to fix. There would also be the issue of getting functions such as __powikf2, __mulkc3, __divkc3 defined, but that's rather easier to address.) Bootstrapped with no regressions on x86_64-unknown-linux-gnu. gcc: * doc/tm.texi.in (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * doc/tm.texi: Regenerate. * system.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Poison. * config/alpha/alpha.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386-interix.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/rtemself.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/ia64/ia64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/m68k.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/mips.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/n32-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/msp430/msp430.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rl78/rl78.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rs6000/rs6000.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rx/rx.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/s390/s390.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/freebsd.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. gcc/c-family: * c-cppbuiltin.c (c_cpp_builtins): Define __LIBGCC_*_EXCESS_PRECISION__ macros for supported floating-point modes. libgcc: * dfp-bit.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. (__LIBGCC_XF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_XF_MODE): Define in terms of __LIBGCC_XF_MANT_DIG__. (__LIBGCC_TF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_TF_MODE): Define in terms of __LIBGCC_TF_MANT_DIG__. * libgcc2.c (NOTRUNC): Define in terms of __LIBGCC_*_EXCESS_PRECISION__, not LIBGCC2_LONG_DOUBLE_TYPE_SIZE. * libgcc2.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. From-SVN: r215491
2014-09-23 02:48:46 +02:00
(__LDBL_MANT_DIG__ == __LIBGCC_XF_MANT_DIG__)
Remove LIBGCC2_LONG_DOUBLE_TYPE_SIZE target macro. This patch removes the target macro LIBGCC2_LONG_DOUBLE_TYPE_SIZE. After recent changes, this macro was used in two ways in libgcc: to determine the mode of long double in dfp-bit.h, and to determine whether a particular mode has excess precision for use in complex multiplication. The former is concerned specifically with long double: it relates to use of strtold for converting between decimal and binary floating point. This is replaced by comparing __LDBL_MANT_DIG__ with the appropriate __LIBGCC_*_MANT_DIG__ macro. The latter is replaced __LIBGCC_*_EXCESS_PRECISION__ predefined macros. Remarks: * Comparing (__LDBL_MANT_DIG__ == __LIBGCC_XF_MANT_DIG__) is more fragile than it looks; it's possible for XFmode to have 53-bit mantissa (TARGET_96_ROUND_53_LONG_DOUBLE, on FreeBSD and DragonFlyBSD 32-bit), in which case such a comparison would not distinguish XFmode and DFmode as possible modes for long double. Fortunately, no target supporting that form of XFmode also supports long double = double (but if some target did, we'd need e.g. an additional macro giving the exponent range of each mode). Furthermore, this code doesn't actually get used for x86 (or any other target with XFmode support), because x86 uses BID not DPD and BID has its own conversion code (which handles conversions for both XFmode and TFmode without needing to go via strtold). And FreeBSD and DragonFlyBSD aren't among the targets with DFP support. So while in principle this code is fragile and it's a deficiency that it can't support both XFmode and TFmode at once (something that can't be solved with the string conversion approach without libc having TS 18661 functions such as strtof128), all these issues should not be a problem in practice. * If other cases of excess precision are supported in future, the code for defining __LIBGCC_*_EXCESS_PRECISION__ may need updating. Although the most likely such cases might not actually involve excess precision for any mode used in libgcc - FLT_EVAL_METHOD being 32 to do _Float16 arithmetic on _Float32 should have the effect of _Complex _Float16 arithmetic using __mulsc3 and __divsc3, rather than currently nonexistent __mulhc3 and __divhc3 as in bug 63250 for ARM. * As has been noted in the context of simultaneous support for __float128 and __ibm128 on Power, the semantics of macros such as LONG_DOUBLE_TYPE_SIZE are problematic because they rely on a poorly-defined precision value for floating-point modes (which seems to be intended as the number of significant bits in the representation, e.g. 80 for XFmode which may be either 12 or 16 bytes) uniquely identifying a mode (although defining an arbitrarily different value for one of the modes you wish to distinguish may work as a hack). It would be cleaner to have a target hook that gives a machine mode directly for float, double and long double, rather than going via these precision values. By eliminating all use of these macros (FLOAT_TYPE_SIZE, DOUBLE_TYPE_SIZE, LONG_DOUBLE_TYPE_SIZE) from code built for the target, this patch facilitates such a conversion to a hook (which I suppose would take some suitable enum as an argument to identify which of the three types to return a mode for). (The issue of multiple type support for DFP conversions would apply in that Power case. <https://gcc.gnu.org/ml/gcc-patches/2014-07/msg01084.html> doesn't seem to touch on it, but it would seem reasonable to punt on it initially as hard to fix. There would also be the issue of getting functions such as __powikf2, __mulkc3, __divkc3 defined, but that's rather easier to address.) Bootstrapped with no regressions on x86_64-unknown-linux-gnu. gcc: * doc/tm.texi.in (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * doc/tm.texi: Regenerate. * system.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Poison. * config/alpha/alpha.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386-interix.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/rtemself.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/ia64/ia64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/m68k.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/mips.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/n32-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/msp430/msp430.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rl78/rl78.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rs6000/rs6000.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rx/rx.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/s390/s390.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/freebsd.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. gcc/c-family: * c-cppbuiltin.c (c_cpp_builtins): Define __LIBGCC_*_EXCESS_PRECISION__ macros for supported floating-point modes. libgcc: * dfp-bit.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. (__LIBGCC_XF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_XF_MODE): Define in terms of __LIBGCC_XF_MANT_DIG__. (__LIBGCC_TF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_TF_MODE): Define in terms of __LIBGCC_TF_MANT_DIG__. * libgcc2.c (NOTRUNC): Define in terms of __LIBGCC_*_EXCESS_PRECISION__, not LIBGCC2_LONG_DOUBLE_TYPE_SIZE. * libgcc2.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. From-SVN: r215491
2014-09-23 02:48:46 +02:00
#ifndef __LIBGCC_TF_MANT_DIG__
#define __LIBGCC_TF_MANT_DIG__ 0
#endif
#define LONG_DOUBLE_HAS_TF_MODE \
Remove LIBGCC2_LONG_DOUBLE_TYPE_SIZE target macro. This patch removes the target macro LIBGCC2_LONG_DOUBLE_TYPE_SIZE. After recent changes, this macro was used in two ways in libgcc: to determine the mode of long double in dfp-bit.h, and to determine whether a particular mode has excess precision for use in complex multiplication. The former is concerned specifically with long double: it relates to use of strtold for converting between decimal and binary floating point. This is replaced by comparing __LDBL_MANT_DIG__ with the appropriate __LIBGCC_*_MANT_DIG__ macro. The latter is replaced __LIBGCC_*_EXCESS_PRECISION__ predefined macros. Remarks: * Comparing (__LDBL_MANT_DIG__ == __LIBGCC_XF_MANT_DIG__) is more fragile than it looks; it's possible for XFmode to have 53-bit mantissa (TARGET_96_ROUND_53_LONG_DOUBLE, on FreeBSD and DragonFlyBSD 32-bit), in which case such a comparison would not distinguish XFmode and DFmode as possible modes for long double. Fortunately, no target supporting that form of XFmode also supports long double = double (but if some target did, we'd need e.g. an additional macro giving the exponent range of each mode). Furthermore, this code doesn't actually get used for x86 (or any other target with XFmode support), because x86 uses BID not DPD and BID has its own conversion code (which handles conversions for both XFmode and TFmode without needing to go via strtold). And FreeBSD and DragonFlyBSD aren't among the targets with DFP support. So while in principle this code is fragile and it's a deficiency that it can't support both XFmode and TFmode at once (something that can't be solved with the string conversion approach without libc having TS 18661 functions such as strtof128), all these issues should not be a problem in practice. * If other cases of excess precision are supported in future, the code for defining __LIBGCC_*_EXCESS_PRECISION__ may need updating. Although the most likely such cases might not actually involve excess precision for any mode used in libgcc - FLT_EVAL_METHOD being 32 to do _Float16 arithmetic on _Float32 should have the effect of _Complex _Float16 arithmetic using __mulsc3 and __divsc3, rather than currently nonexistent __mulhc3 and __divhc3 as in bug 63250 for ARM. * As has been noted in the context of simultaneous support for __float128 and __ibm128 on Power, the semantics of macros such as LONG_DOUBLE_TYPE_SIZE are problematic because they rely on a poorly-defined precision value for floating-point modes (which seems to be intended as the number of significant bits in the representation, e.g. 80 for XFmode which may be either 12 or 16 bytes) uniquely identifying a mode (although defining an arbitrarily different value for one of the modes you wish to distinguish may work as a hack). It would be cleaner to have a target hook that gives a machine mode directly for float, double and long double, rather than going via these precision values. By eliminating all use of these macros (FLOAT_TYPE_SIZE, DOUBLE_TYPE_SIZE, LONG_DOUBLE_TYPE_SIZE) from code built for the target, this patch facilitates such a conversion to a hook (which I suppose would take some suitable enum as an argument to identify which of the three types to return a mode for). (The issue of multiple type support for DFP conversions would apply in that Power case. <https://gcc.gnu.org/ml/gcc-patches/2014-07/msg01084.html> doesn't seem to touch on it, but it would seem reasonable to punt on it initially as hard to fix. There would also be the issue of getting functions such as __powikf2, __mulkc3, __divkc3 defined, but that's rather easier to address.) Bootstrapped with no regressions on x86_64-unknown-linux-gnu. gcc: * doc/tm.texi.in (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * doc/tm.texi: Regenerate. * system.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Poison. * config/alpha/alpha.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386-interix.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/i386.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/i386/rtemself.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/ia64/ia64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/m68k.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/m68k/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/mips.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/mips/n32-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/msp430/msp430.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rl78/rl78.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rs6000/rs6000.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/rx/rx.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/s390/s390.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/freebsd.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/linux64.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. * config/sparc/netbsd-elf.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. gcc/c-family: * c-cppbuiltin.c (c_cpp_builtins): Define __LIBGCC_*_EXCESS_PRECISION__ macros for supported floating-point modes. libgcc: * dfp-bit.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. (__LIBGCC_XF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_XF_MODE): Define in terms of __LIBGCC_XF_MANT_DIG__. (__LIBGCC_TF_MANT_DIG__): Define if not already defined. (LONG_DOUBLE_HAS_TF_MODE): Define in terms of __LIBGCC_TF_MANT_DIG__. * libgcc2.c (NOTRUNC): Define in terms of __LIBGCC_*_EXCESS_PRECISION__, not LIBGCC2_LONG_DOUBLE_TYPE_SIZE. * libgcc2.h (LIBGCC2_LONG_DOUBLE_TYPE_SIZE): Remove. From-SVN: r215491
2014-09-23 02:48:46 +02:00
(__LDBL_MANT_DIG__ == __LIBGCC_TF_MANT_DIG__)
/* Depending on WIDTH, define a number of macros:
DFP_C_TYPE: type of the arguments to the libgcc functions;
(eg _Decimal32)
IEEE_TYPE: the corresponding (encoded) IEEE754 type;
(eg decimal32)
TO_INTERNAL: the name of the decNumber function to convert an
encoded value into the decNumber internal representation;
TO_ENCODED: the name of the decNumber function to convert an
internally represented decNumber into the encoded
representation.
FROM_STRING: the name of the decNumber function to read an
encoded value from a string.
TO_STRING: the name of the decNumber function to write an
encoded value to a string. */
#if WIDTH == 32
#define DFP_C_TYPE _Decimal32
#define IEEE_TYPE decimal32
#define HOST_TO_IEEE __host_to_ieee_32
#define IEEE_TO_HOST __ieee_to_host_32
#define TO_INTERNAL __decimal32ToNumber
#define TO_ENCODED __decimal32FromNumber
#define FROM_STRING __decimal32FromString
#define TO_STRING __decimal32ToString
#elif WIDTH == 64
#define DFP_C_TYPE _Decimal64
#define IEEE_TYPE decimal64
#define HOST_TO_IEEE __host_to_ieee_64
#define IEEE_TO_HOST __ieee_to_host_64
#define TO_INTERNAL __decimal64ToNumber
#define TO_ENCODED __decimal64FromNumber
#define FROM_STRING __decimal64FromString
#define TO_STRING __decimal64ToString
#elif WIDTH == 128
#define DFP_C_TYPE _Decimal128
#define IEEE_TYPE decimal128
#define HOST_TO_IEEE __host_to_ieee_128
#define IEEE_TO_HOST __ieee_to_host_128
#define TO_INTERNAL __decimal128ToNumber
#define TO_ENCODED __decimal128FromNumber
#define FROM_STRING __decimal128FromString
#define TO_STRING __decimal128ToString
#else
#error invalid decimal float word width
#endif
/* We define __DEC_EVAL_METHOD__ to 2, saying that we evaluate all
operations and constants to the range and precision of the _Decimal128
type. Make it so. */
#if WIDTH == 32
#define CONTEXT_INIT DEC_INIT_DECIMAL32
#elif WIDTH == 64
#define CONTEXT_INIT DEC_INIT_DECIMAL64
#elif WIDTH == 128
#define CONTEXT_INIT DEC_INIT_DECIMAL128
#endif
#ifndef DFP_INIT_ROUNDMODE
#define DFP_INIT_ROUNDMODE(A) A = DEC_ROUND_HALF_EVEN
#endif
#ifdef DFP_EXCEPTIONS_ENABLED
/* Return IEEE exception flags based on decNumber status flags. */
#define DFP_IEEE_FLAGS(DEC_FLAGS) __extension__ \
({int _fe_flags = 0; \
if ((dec_flags & DEC_IEEE_854_Division_by_zero) != 0) \
_fe_flags |= FE_DIVBYZERO; \
if ((dec_flags & DEC_IEEE_854_Inexact) != 0) \
_fe_flags |= FE_INEXACT; \
if ((dec_flags & DEC_IEEE_854_Invalid_operation) != 0) \
_fe_flags |= FE_INVALID; \
if ((dec_flags & DEC_IEEE_854_Overflow) != 0) \
_fe_flags |= FE_OVERFLOW; \
if ((dec_flags & DEC_IEEE_854_Underflow) != 0) \
_fe_flags |= FE_UNDERFLOW; \
_fe_flags; })
#else
#define DFP_EXCEPTIONS_ENABLED 0
#define DFP_IEEE_FLAGS(A) 0
#define DFP_HANDLE_EXCEPTIONS(A) do {} while (0)
#endif
/* Conversions between different decimal float types use WIDTH_TO to
determine additional macros to define. */
#if defined (L_dd_to_sd) || defined (L_td_to_sd)
#define WIDTH_TO 32
#elif defined (L_sd_to_dd) || defined (L_td_to_dd)
#define WIDTH_TO 64
#elif defined (L_sd_to_td) || defined (L_dd_to_td)
#define WIDTH_TO 128
#endif
/* If WIDTH_TO is defined, define additional macros:
DFP_C_TYPE_TO: type of the result of dfp to dfp conversion.
IEEE_TYPE_TO: the corresponding (encoded) IEEE754 type.
TO_ENCODED_TO: the name of the decNumber function to convert an
internally represented decNumber into the encoded representation
for the destination. */
#if WIDTH_TO == 32
#define DFP_C_TYPE_TO _Decimal32
#define IEEE_TYPE_TO decimal32
#define TO_ENCODED_TO __decimal32FromNumber
#define IEEE_TO_HOST_TO __ieee_to_host_32
#elif WIDTH_TO == 64
#define DFP_C_TYPE_TO _Decimal64
#define IEEE_TYPE_TO decimal64
#define TO_ENCODED_TO __decimal64FromNumber
#define IEEE_TO_HOST_TO __ieee_to_host_64
#elif WIDTH_TO == 128
#define DFP_C_TYPE_TO _Decimal128
#define IEEE_TYPE_TO decimal128
#define TO_ENCODED_TO __decimal128FromNumber
#define IEEE_TO_HOST_TO __ieee_to_host_128
#endif
/* Conversions between decimal float types and integral types use INT_KIND
to determine the data type and C functions to use. */
#if defined (L_sd_to_si) || defined (L_dd_to_si) || defined (L_td_to_si) \
|| defined (L_si_to_sd) || defined (L_si_to_dd) || defined (L_si_to_td)
#define INT_KIND 1
#elif defined (L_sd_to_di) || defined (L_dd_to_di) || defined (L_td_to_di) \
|| defined (L_di_to_sd) || defined (L_di_to_dd) || defined (L_di_to_td)
#define INT_KIND 2
#elif defined (L_sd_to_usi) || defined (L_dd_to_usi) || defined (L_td_to_usi) \
|| defined (L_usi_to_sd) || defined (L_usi_to_dd) || defined (L_usi_to_td)
#define INT_KIND 3
#elif defined (L_sd_to_udi) || defined (L_dd_to_udi) || defined (L_td_to_udi) \
|| defined (L_udi_to_sd) || defined (L_udi_to_dd) || defined (L_udi_to_td)
#define INT_KIND 4
#endif
/* If INT_KIND is defined, define additional macros:
INT_TYPE: The integer data type.
INT_FMT: The format string for writing the integer to a string.
CAST_FOR_FMT: Cast variable of INT_KIND to C type for sprintf.
This works for ILP32 and LP64, won't for other type size systems.
STR_TO_INT: The function to read the integer from a string. */
#if INT_KIND == 1
#define INT_TYPE SItype
#define INT_FMT "%d"
#define CAST_FOR_FMT(A) (int)A
#define STR_TO_INT strtol
#elif INT_KIND == 2
#define INT_TYPE DItype
#define INT_FMT "%lld"
#define CAST_FOR_FMT(A) (long long)A
#define STR_TO_INT strtoll
#elif INT_KIND == 3
#define INT_TYPE USItype
#define INT_FMT "%u"
#define CAST_FOR_FMT(A) (unsigned int)A
#define STR_TO_INT strtoul
#elif INT_KIND == 4
#define INT_TYPE UDItype
#define INT_FMT "%llu"
#define CAST_FOR_FMT(A) (unsigned long long)A
#define STR_TO_INT strtoull
#endif
/* Conversions between decimal float types and binary float types use
BFP_KIND to determine the data type and C functions to use. */
#if defined (L_sd_to_sf) || defined (L_dd_to_sf) || defined (L_td_to_sf) \
|| defined (L_sf_to_sd) || defined (L_sf_to_dd) || defined (L_sf_to_td)
#define BFP_KIND 1
#elif defined (L_sd_to_df) || defined (L_dd_to_df ) || defined (L_td_to_df) \
|| defined (L_df_to_sd) || defined (L_df_to_dd) || defined (L_df_to_td)
#define BFP_KIND 2
#elif defined (L_sd_to_xf) || defined (L_dd_to_xf ) || defined (L_td_to_xf) \
|| defined (L_xf_to_sd) || defined (L_xf_to_dd) || defined (L_xf_to_td)
#define BFP_KIND 3
#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
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.
2021-02-22 21:33:29 +01:00
#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:
BFP_TYPE: The binary floating point data type.
BFP_FMT: The format string for writing the value to a string.
The number of decimal digits printed is
ceil (nbits / log2 (10.) + 1)
as described in David Matula's CACM 19(3) 716-723 June 1968 paper.
BFP_VIA_TYPE: Type to which to cast a variable of BPF_TYPE for a
call to sprintf.
STR_TO_BFP: The function to read the value from a string. */
#if BFP_KIND == 1
#define BFP_TYPE SFtype
#define BFP_FMT "%.9e"
#define BFP_VIA_TYPE double
#define STR_TO_BFP strtof
#elif BFP_KIND == 2
#define BFP_TYPE DFtype
#define BFP_FMT "%.17e"
#define BFP_VIA_TYPE double
#define STR_TO_BFP strtod
#elif BFP_KIND == 3
#if LONG_DOUBLE_HAS_XF_MODE
#define BFP_TYPE XFtype
#define BFP_FMT "%.21Le"
#define BFP_VIA_TYPE long double
#define STR_TO_BFP strtold
#endif /* LONG_DOUBLE_HAS_XF_MODE */
#elif BFP_KIND == 4
#if LONG_DOUBLE_HAS_TF_MODE
#define BFP_TYPE TFtype
#if LDBL_MANT_DIG == 106
#define BFP_FMT "%.33Le"
#elif LDBL_MANT_DIG == 113
#define BFP_FMT "%.36Le"
#else
#error "unknown long double size, cannot define BFP_FMT"
#endif /* LDBL_MANT_DIG */
#define STR_TO_BFP strtold
#define BFP_VIA_TYPE long double
#endif /* LONG_DOUBLE_HAS_TF_MODE */
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.
2021-02-22 21:33:29 +01:00
#elif BFP_KIND == 5
#define BFP_TYPE _Float128
#define BFP_FMT "%.36Le"
#define BFP_VIA_TYPE _Float128
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. libgcc/ 2021-03-29 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.
2021-03-29 22:43:14 +02:00
#define STR_TO_BFP __strtoieee128
extern _Float128 __strtoieee128 (const char *, char **);
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.
2021-02-22 21:33:29 +01:00
#endif /* BFP_KIND */
#if WIDTH == 128 || WIDTH_TO == 128
#include "decimal128.h"
#include "decQuad.h"
#endif
#if WIDTH == 64 || WIDTH_TO == 64
#include "decimal64.h"
#include "decDouble.h"
#endif
#if WIDTH == 32 || WIDTH_TO == 32
#include "decimal32.h"
#include "decSingle.h"
#endif
#include "decNumber.h"
/* Names of arithmetic functions. */
#if ENABLE_DECIMAL_BID_FORMAT
#define DPD_BID_NAME(DPD,BID) BID
#else
#define DPD_BID_NAME(DPD,BID) DPD
#endif
#if WIDTH == 32
#define DFP_ADD DPD_BID_NAME(__dpd_addsd3,__bid_addsd3)
#define DFP_SUB DPD_BID_NAME(__dpd_subsd3,__bid_subsd3)
#define DFP_MULTIPLY DPD_BID_NAME(__dpd_mulsd3,__bid_mulsd3)
#define DFP_DIVIDE DPD_BID_NAME(__dpd_divsd3,__bid_divsd3)
#define DFP_EQ DPD_BID_NAME(__dpd_eqsd2,__bid_eqsd2)
#define DFP_NE DPD_BID_NAME(__dpd_nesd2,__bid_nesd2)
#define DFP_LT DPD_BID_NAME(__dpd_ltsd2,__bid_ltsd2)
#define DFP_GT DPD_BID_NAME(__dpd_gtsd2,__bid_gtsd2)
#define DFP_LE DPD_BID_NAME(__dpd_lesd2,__bid_lesd2)
#define DFP_GE DPD_BID_NAME(__dpd_gesd2,__bid_gesd2)
#define DFP_UNORD DPD_BID_NAME(__dpd_unordsd2,__bid_unordsd2)
#elif WIDTH == 64
#define DFP_ADD DPD_BID_NAME(__dpd_adddd3,__bid_adddd3)
#define DFP_SUB DPD_BID_NAME(__dpd_subdd3,__bid_subdd3)
#define DFP_MULTIPLY DPD_BID_NAME(__dpd_muldd3,__bid_muldd3)
#define DFP_DIVIDE DPD_BID_NAME(__dpd_divdd3,__bid_divdd3)
#define DFP_EQ DPD_BID_NAME(__dpd_eqdd2,__bid_eqdd2)
#define DFP_NE DPD_BID_NAME(__dpd_nedd2,__bid_nedd2)
#define DFP_LT DPD_BID_NAME(__dpd_ltdd2,__bid_ltdd2)
#define DFP_GT DPD_BID_NAME(__dpd_gtdd2,__bid_gtdd2)
#define DFP_LE DPD_BID_NAME(__dpd_ledd2,__bid_ledd2)
#define DFP_GE DPD_BID_NAME(__dpd_gedd2,__bid_gedd2)
#define DFP_UNORD DPD_BID_NAME(__dpd_unorddd2,__bid_unorddd2)
#elif WIDTH == 128
#define DFP_ADD DPD_BID_NAME(__dpd_addtd3,__bid_addtd3)
#define DFP_SUB DPD_BID_NAME(__dpd_subtd3,__bid_subtd3)
#define DFP_MULTIPLY DPD_BID_NAME(__dpd_multd3,__bid_multd3)
#define DFP_DIVIDE DPD_BID_NAME(__dpd_divtd3,__bid_divtd3)
#define DFP_EQ DPD_BID_NAME(__dpd_eqtd2,__bid_eqtd2)
#define DFP_NE DPD_BID_NAME(__dpd_netd2,__bid_netd2)
#define DFP_LT DPD_BID_NAME(__dpd_lttd2,__bid_lttd2)
#define DFP_GT DPD_BID_NAME(__dpd_gttd2,__bid_gttd2)
#define DFP_LE DPD_BID_NAME(__dpd_letd2,__bid_letd2)
#define DFP_GE DPD_BID_NAME(__dpd_getd2,__bid_getd2)
#define DFP_UNORD DPD_BID_NAME(__dpd_unordtd2,__bid_unordtd2)
#endif
/* Names of decNumber functions for DPD arithmetic. */
#if WIDTH == 32
#define decFloat decDouble
#define DFP_BINARY_OP d32_binary_op
#define DFP_COMPARE_OP d32_compare_op
#define DEC_FLOAT_ADD decDoubleAdd
#define DEC_FLOAT_SUBTRACT decDoubleSubtract
#define DEC_FLOAT_MULTIPLY decDoubleMultiply
#define DEC_FLOAT_DIVIDE decDoubleDivide
#define DEC_FLOAT_COMPARE decDoubleCompare
#define DEC_FLOAT_IS_ZERO decDoubleIsZero
#define DEC_FLOAT_IS_NAN decDoubleIsNaN
#define DEC_FLOAT_IS_SIGNED decDoubleIsSigned
#elif WIDTH == 64
#define DFP_BINARY_OP dnn_binary_op
#define DFP_COMPARE_OP dnn_compare_op
#define decFloat decDouble
#define DEC_FLOAT_ADD decDoubleAdd
#define DEC_FLOAT_SUBTRACT decDoubleSubtract
#define DEC_FLOAT_MULTIPLY decDoubleMultiply
#define DEC_FLOAT_DIVIDE decDoubleDivide
#define DEC_FLOAT_COMPARE decDoubleCompare
#define DEC_FLOAT_IS_ZERO decDoubleIsZero
#define DEC_FLOAT_IS_NAN decDoubleIsNaN
#define DEC_FLOAT_IS_SIGNED decDoubleIsSigned
#elif WIDTH == 128
#define DFP_BINARY_OP dnn_binary_op
#define DFP_COMPARE_OP dnn_compare_op
#define decFloat decQuad
#define DEC_FLOAT_ADD decQuadAdd
#define DEC_FLOAT_SUBTRACT decQuadSubtract
#define DEC_FLOAT_MULTIPLY decQuadMultiply
#define DEC_FLOAT_DIVIDE decQuadDivide
#define DEC_FLOAT_COMPARE decQuadCompare
#define DEC_FLOAT_IS_ZERO decQuadIsZero
#define DEC_FLOAT_IS_NAN decQuadIsNaN
#define DEC_FLOAT_IS_SIGNED decQuadIsSigned
#endif
/* Names of functions to convert between different decimal float types. */
#if WIDTH == 32
#if WIDTH_TO == 64
#define DFP_TO_DFP DPD_BID_NAME(__dpd_extendsddd2,__bid_extendsddd2)
#elif WIDTH_TO == 128
#define DFP_TO_DFP DPD_BID_NAME(__dpd_extendsdtd2,__bid_extendsdtd2)
#endif
#elif WIDTH == 64
#if WIDTH_TO == 32
#define DFP_TO_DFP DPD_BID_NAME(__dpd_truncddsd2,__bid_truncddsd2)
#elif WIDTH_TO == 128
#define DFP_TO_DFP DPD_BID_NAME(__dpd_extendddtd2,__bid_extendddtd2)
#endif
#elif WIDTH == 128
#if WIDTH_TO == 32
#define DFP_TO_DFP DPD_BID_NAME(__dpd_trunctdsd2,__bid_trunctdsd2)
#elif WIDTH_TO == 64
#define DFP_TO_DFP DPD_BID_NAME(__dpd_trunctddd2,__bid_trunctddd2)
#endif
#endif
/* Names of functions to convert between decimal float and integers. */
#if WIDTH == 32
#if INT_KIND == 1
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatsisd,__bid_floatsisd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixsdsi,__bid_fixsdsi)
#define DEC_FLOAT_FROM_INT decDoubleFromInt32
#define DEC_FLOAT_TO_INT decDoubleToInt32
#elif INT_KIND == 2
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatdisd,__bid_floatdisd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixsddi,__bid_fixsddi)
#elif INT_KIND == 3
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatunssisd,__bid_floatunssisd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixunssdsi,__bid_fixunssdsi)
#define DEC_FLOAT_FROM_INT decDoubleFromUInt32
#define DEC_FLOAT_TO_INT decDoubleToUInt32
#elif INT_KIND == 4
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatunsdisd,__bid_floatunsdisd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixunssddi,__bid_fixunssddi)
#endif
#elif WIDTH == 64
#define decFloat decDouble
#if INT_KIND == 1
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatsidd,__bid_floatsidd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixddsi,__bid_fixddsi)
#define DEC_FLOAT_FROM_INT decDoubleFromInt32
#define DEC_FLOAT_TO_INT decDoubleToInt32
#elif INT_KIND == 2
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatdidd,__bid_floatdidd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixdddi,__bid_fixdddi)
#elif INT_KIND == 3
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatunssidd,__bid_floatunssidd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixunsddsi,__bid_fixunsddsi)
#define DEC_FLOAT_FROM_INT decDoubleFromUInt32
#define DEC_FLOAT_TO_INT decDoubleToUInt32
#elif INT_KIND == 4
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatunsdidd,__bid_floatunsdidd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixunsdddi,__bid_fixunsdddi)
#endif
#elif WIDTH == 128
#define decFloat decQuad
#if INT_KIND == 1
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatsitd,__bid_floatsitd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixtdsi,__bid_fixtdsi)
#define DEC_FLOAT_FROM_INT decQuadFromInt32
#define DEC_FLOAT_TO_INT decQuadToInt32
#elif INT_KIND == 2
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatditd,__bid_floatditd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixtddi,__bid_fixtddi)
#elif INT_KIND == 3
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatunssitd,__bid_floatunssitd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixunstdsi,__bid_fixunstdsi)
#define DEC_FLOAT_FROM_INT decQuadFromUInt32
#define DEC_FLOAT_TO_INT decQuadToUInt32
#elif INT_KIND == 4
#define INT_TO_DFP DPD_BID_NAME(__dpd_floatunsditd,__bid_floatunsditd)
#define DFP_TO_INT DPD_BID_NAME(__dpd_fixunstddi,__bid_fixunstddi)
#endif
#endif
/* Names of functions to convert between decimal float and binary float. */
#if WIDTH == 32
#if BFP_KIND == 1
#define BFP_TO_DFP DPD_BID_NAME(__dpd_extendsfsd,__bid_extendsfsd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_truncsdsf,__bid_truncsdsf)
#elif BFP_KIND == 2
#define BFP_TO_DFP DPD_BID_NAME(__dpd_truncdfsd,__bid_truncdfsd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsddf,__bid_extendsddf)
#elif BFP_KIND == 3
#define BFP_TO_DFP DPD_BID_NAME(__dpd_truncxfsd,__bid_truncxfsd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_extendsdxf,__bid_extendsdxf)
#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)
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.
2021-02-22 21:33:29 +01:00
#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
#if BFP_KIND == 1
#define BFP_TO_DFP DPD_BID_NAME(__dpd_extendsfdd,__bid_extendsfdd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_truncddsf,__bid_truncddsf)
#elif BFP_KIND == 2
#define BFP_TO_DFP DPD_BID_NAME(__dpd_extenddfdd,__bid_extenddfdd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_truncdddf,__bid_truncdddf)
#elif BFP_KIND == 3
#define BFP_TO_DFP DPD_BID_NAME(__dpd_truncxfdd,__bid_truncxfdd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_extendddxf,__bid_extendddxf)
#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)
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.
2021-02-22 21:33:29 +01:00
#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
#if BFP_KIND == 1
#define BFP_TO_DFP DPD_BID_NAME(__dpd_extendsftd,__bid_extendsftd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdsf,__bid_trunctdsf)
#elif BFP_KIND == 2
#define BFP_TO_DFP DPD_BID_NAME(__dpd_extenddftd,__bid_extenddftd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctddf,__bid_trunctddf)
#elif BFP_KIND == 3
#define BFP_TO_DFP DPD_BID_NAME(__dpd_extendxftd,__bid_extendxftd)
#define DFP_TO_BFP DPD_BID_NAME(__dpd_trunctdxf,__bid_trunctdxf)
#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)
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.
2021-02-22 21:33:29 +01:00
#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 */
/* Some handy typedefs. */
typedef float SFtype __attribute__ ((mode (SF)));
typedef float DFtype __attribute__ ((mode (DF)));
#if LONG_DOUBLE_HAS_XF_MODE
typedef float XFtype __attribute__ ((mode (XF)));
#endif /* LONG_DOUBLE_HAS_XF_MODE */
#if LONG_DOUBLE_HAS_TF_MODE
typedef float TFtype __attribute__ ((mode (TF)));
#endif /* LONG_DOUBLE_HAS_TF_MODE */
typedef int SItype __attribute__ ((mode (SI)));
typedef int DItype __attribute__ ((mode (DI)));
typedef unsigned int USItype __attribute__ ((mode (SI)));
typedef unsigned int UDItype __attribute__ ((mode (DI)));
/* The type of the result of a decimal float comparison. This must
match `__libgcc_cmp_return__' in GCC for the target. */
typedef int CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
/* Prototypes. */
#if defined (L_mul_sd) || defined (L_mul_dd) || defined (L_mul_td)
extern DFP_C_TYPE DFP_MULTIPLY (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_div_sd) || defined (L_div_dd) || defined (L_div_td)
extern DFP_C_TYPE DFP_DIVIDE (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_addsub_sd) || defined (L_addsub_dd) || defined (L_addsub_td)
extern DFP_C_TYPE DFP_ADD (DFP_C_TYPE, DFP_C_TYPE);
extern DFP_C_TYPE DFP_SUB (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_eq_sd) || defined (L_eq_dd) || defined (L_eq_td)
extern CMPtype DFP_EQ (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_ne_sd) || defined (L_ne_dd) || defined (L_ne_td)
extern CMPtype DFP_NE (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_lt_sd) || defined (L_lt_dd) || defined (L_lt_td)
extern CMPtype DFP_LT (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_gt_sd) || defined (L_gt_dd) || defined (L_gt_td)
extern CMPtype DFP_GT (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_le_sd) || defined (L_le_dd) || defined (L_le_td)
extern CMPtype DFP_LE (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_ge_sd) || defined (L_ge_dd) || defined (L_ge_td)
extern CMPtype DFP_GE (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_unord_sd) || defined (L_unord_dd) || defined (L_unord_td)
extern CMPtype DFP_UNORD (DFP_C_TYPE, DFP_C_TYPE);
#endif
#if defined (L_sd_to_dd) || defined (L_sd_to_td) || defined (L_dd_to_sd) \
|| defined (L_dd_to_td) || defined (L_td_to_sd) || defined (L_td_to_dd)
extern DFP_C_TYPE_TO DFP_TO_DFP (DFP_C_TYPE);
#endif
#if defined (L_sd_to_si) || defined (L_dd_to_si) || defined (L_td_to_si) \
|| defined (L_sd_to_di) || defined (L_dd_to_di) || defined (L_td_to_di) \
|| defined (L_sd_to_usi) || defined (L_dd_to_usi) || defined (L_td_to_usi) \
|| defined (L_sd_to_udi) || defined (L_dd_to_udi) || defined (L_td_to_udi)
extern INT_TYPE DFP_TO_INT (DFP_C_TYPE);
#endif
#if defined (L_si_to_sd) || defined (L_si_to_dd) || defined (L_si_to_td) \
|| defined (L_di_to_sd) || defined (L_di_to_dd) || defined (L_di_to_td) \
|| defined (L_usi_to_sd) || defined (L_usi_to_dd) || defined (L_usi_to_td) \
|| defined (L_udi_to_sd) || defined (L_udi_to_dd) || defined (L_udi_to_td)
extern DFP_C_TYPE INT_TO_DFP (INT_TYPE);
#endif
#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) \
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.
2021-02-22 21:33:29 +01:00
|| 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)) \
&& LONG_DOUBLE_HAS_TF_MODE)
extern BFP_TYPE DFP_TO_BFP (DFP_C_TYPE);
#endif
#if defined (L_sf_to_sd) || defined (L_sf_to_dd) || defined (L_sf_to_td) \
|| defined (L_df_to_sd) || defined (L_df_to_dd) || defined (L_df_to_td) \
|| ((defined (L_xf_to_sd) || defined (L_xf_to_dd) || defined (L_xf_to_td)) \
&& LONG_DOUBLE_HAS_XF_MODE) \
|| ((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);
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.
2021-02-22 21:33:29 +01:00
#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);
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. libgcc/ 2021-03-29 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.
2021-03-29 22:43:14 +02:00
extern int __sprintfieee128 (char *restrict, const char *restrict, ...);
#define BFP_SPRINTF __sprintfieee128
#endif
#endif /* _DFPBIT_H */