From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 43E8C385802A; Mon, 17 Jan 2022 19:33:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43E8C385802A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-6649] libstdc++: Use fast_float in std::from_chars for binary32/64 X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 40b0d4472a2591cf27f3a81aa3fba57dc4532648 X-Git-Newrev: 490e23032baaece71f2ec09fa1805064b150fbc2 Message-Id: <20220117193350.43E8C385802A@sourceware.org> Date: Mon, 17 Jan 2022 19:33:50 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Jan 2022 19:33:50 -0000 https://gcc.gnu.org/g:490e23032baaece71f2ec09fa1805064b150fbc2 commit r12-6649-g490e23032baaece71f2ec09fa1805064b150fbc2 Author: Patrick Palka Date: Mon Jan 17 14:33:12 2022 -0500 libstdc++: Use fast_float in std::from_chars for binary32/64 This makes our std::from_chars implementation use fast_float for decimal parsing of binary32/64 numbers. For other floating-point formats we still use the fallback implementation that goes through the strtod family of functions. libstdc++-v3/ChangeLog: * src/c++17/floating_from_chars.cc: (USE_LIB_FAST_FLOAT): Conditionally define, and use it to conditionally include fast_float. (from_chars): Use fast_float for float and double when USE_LIB_FAST_FLOAT. Diff: --- libstdc++-v3/src/c++17/floating_from_chars.cc | 31 +++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc index 3ad5b409da7..3158a3a96d3 100644 --- a/libstdc++-v3/src/c++17/floating_from_chars.cc +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,18 @@ extern "C" __ieee128 __strtoieee128(const char*, char**); #endif +#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 +# define USE_LIB_FAST_FLOAT 1 +#endif + +#if USE_LIB_FAST_FLOAT +# define FASTFLOAT_DEBUG_ASSERT __glibcxx_assert +namespace +{ +# include "fast_float/fast_float.h" +} // anon namespace +#endif + #if _GLIBCXX_HAVE_USELOCALE namespace std _GLIBCXX_VISIBILITY(default) { @@ -773,8 +786,12 @@ from_chars(const char* first, const char* last, float& value, #if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 if (fmt == chars_format::hex) return __floating_from_chars_hex(first, last, value); -#endif - + else + { + static_assert(USE_LIB_FAST_FLOAT); + return fast_float::from_chars(first, last, value, fmt); + } +#else errc ec = errc::invalid_argument; #if _GLIBCXX_USE_CXX11_ABI buffer_resource mr; @@ -795,6 +812,7 @@ from_chars(const char* first, const char* last, float& value, fmt = chars_format{}; } return make_result(first, len, fmt, ec); +#endif } from_chars_result @@ -804,8 +822,12 @@ from_chars(const char* first, const char* last, double& value, #if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 if (fmt == chars_format::hex) return __floating_from_chars_hex(first, last, value); -#endif - + else + { + static_assert(USE_LIB_FAST_FLOAT); + return fast_float::from_chars(first, last, value, fmt); + } +#else errc ec = errc::invalid_argument; #if _GLIBCXX_USE_CXX11_ABI buffer_resource mr; @@ -826,6 +848,7 @@ from_chars(const char* first, const char* last, double& value, fmt = chars_format{}; } return make_result(first, len, fmt, ec); +#endif } from_chars_result