From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 8DB783858402 for ; Sun, 16 Jan 2022 18:07:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8DB783858402 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-224-UyosjoecNv29O3OZUq0Y_g-1; Sun, 16 Jan 2022 13:07:01 -0500 X-MC-Unique: UyosjoecNv29O3OZUq0Y_g-1 Received: by mail-qt1-f198.google.com with SMTP id bb10-20020a05622a1b0a00b002cae750b213so697583qtb.22 for ; Sun, 16 Jan 2022 10:07:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pzA9jREwHEoHqUIe98xV+KWAoNRjvl2rv6mj21B9u84=; b=GIlcYIElmFyKj2I2bwC0sGqwniUiuhjFwyUtbZMCl2VuCs0ip4fd7aUUfuncSmy+wY tCUz+wEuK4V4EtTe7oZFDFnVPOQP8Isn/MLzcy60mWRk2VFNH6zuEtXbfQpQ2gp7r8yB 9PdU9wGOrVy+mNqm57xWuUnmV6E1I5QXugLF4K5ZMhL3seG04RjaHZcsWW/+xH5rI7hM 264i3yb60LvdPG9cq9lbcf4xyROCzyIUwdYsVi3MlTuOicXF+sfQIxhvA/3uaE6BV3do MJ1seWoRcbgF0/IaNSJDozJmmuX3jTVIg0WT05zSNx7YG4QpBBTT/Iw4ctuKAP+fmU3+ T6qg== X-Gm-Message-State: AOAM5337v5M1r49Kuk5VxLOYMmFWGJIp0EYSddklpEWXcsYWRtphufmc uO+lxOf4lNtl9iO4OmwFiW8aqE1e58YUkWmLzwIJgQqUxmDR1BazqXqBsxOxXKyrqR+bWgsKamy 9ua2V2hP0YSrNu/8= X-Received: by 2002:a37:6144:: with SMTP id v65mr11953433qkb.528.1642356420861; Sun, 16 Jan 2022 10:07:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9haCPKJyBBy+8Q0ww/uGIwGFeufjAbDOxdxWYNtC/DL5RZLU1t/grsviG6YbYlesjZpwsag== X-Received: by 2002:a37:6144:: with SMTP id v65mr11953421qkb.528.1642356420656; Sun, 16 Jan 2022 10:07:00 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id o10sm7994149qtx.33.2022.01.16.10.06.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Jan 2022 10:06:59 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 5/6] libstdc++: Use fast_float in std::from_chars for binary32/64 Date: Sun, 16 Jan 2022 13:06:51 -0500 Message-Id: <20220116180652.3694791-5-ppalka@redhat.com> X-Mailer: git-send-email 2.35.0.rc1 In-Reply-To: <20220116180652.3694791-1-ppalka@redhat.com> References: <20220116180652.3694791-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Jan 2022 18:07:03 -0000 This makes our std::from_chars implementation use fast_float for parsing chars_format::scientific/fixed/general parsing into binary32/64 values. 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. --- 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 b186da9a955..c340eb18ea8 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) { @@ -775,8 +788,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; @@ -797,6 +814,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 @@ -806,8 +824,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; @@ -828,6 +850,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 -- 2.35.0.rc1