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.129.124]) by sourceware.org (Postfix) with ESMTPS id D54F73858039 for ; Tue, 16 Nov 2021 00:25:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D54F73858039 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-A0fP7Fa4MsaUnhg2s_Z6-g-1; Mon, 15 Nov 2021 19:25:20 -0500 X-MC-Unique: A0fP7Fa4MsaUnhg2s_Z6-g-1 Received: by mail-qt1-f198.google.com with SMTP id g2-20020ac87d02000000b002b277218d03so8554425qtb.16 for ; Mon, 15 Nov 2021 16:25:20 -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=ZZGrpaRzoABiYDLrrZofupVpiFs3nigestqnXqjhzuo=; b=ZQeelWFSlwoBHwPMIlgGHw8pxex8b5MHjaJgnWe+xyMITUL+xlbnjsCefCmDpds3HQ AAKi0oVOkSMMx+8QV3xs1vkz2fePpCGfxlizv+Qgim3zq9bjfBTwmAS5AAVV8g/qtrlY tyDx2fj21IGKCjaPlYD08Ihllm7jChdrdr4pfGdufa650YhyRdS60Fngo3slE9ptnX6D SVK4vpi8QBdDFV9xjfNlWBlWEc56YKo6gkkNWcE+lRvzjQ1VU5g1fXyK6ZbI5oPA2Ads Myp+PnTiMrc7p1Zva5w1e0aEtzCZGwamSO3heITD7sdgADVjvekvYS7ORl6TeFzE+ums CuEA== X-Gm-Message-State: AOAM531Mvt5mvr3aWeS1toRmCdEJqu563LWkpba5riJTmUqLCTHgMiGs 5l+8IeRDsqQLUpXXaHfHQnbapgWoI01CaIYebEPUJfD+14g/BpQ835WgUo/H7IY7ElVU9zABMOC bg5YAds+MHnjJAc4= X-Received: by 2002:a37:9507:: with SMTP id x7mr2686720qkd.105.1637022319995; Mon, 15 Nov 2021 16:25:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzc4EXCl/KuCqKwswGkkkva6JDGEjItgqBQKw5vBNdm76+VVKkjgeuO3ChccecznSwWeWKjHw== X-Received: by 2002:a37:9507:: with SMTP id x7mr2686704qkd.105.1637022319786; Mon, 15 Nov 2021 16:25:19 -0800 (PST) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id j19sm7836545qkp.28.2021.11.15.16.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Nov 2021 16:25:18 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 4/5] libstdc++: Use fast_float in std::from_chars for binary32/64 Date: Mon, 15 Nov 2021 19:25:04 -0500 Message-Id: <20211116002505.2324582-4-ppalka@redhat.com> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211116002505.2324582-1-ppalka@redhat.com> References: <20211116002505.2324582-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=-15.8 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_H4, 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: Tue, 16 Nov 2021 00:25:23 -0000 This makes our std::from_chars implementation use fast_float for parsing chars_format::scientific/fixed/general parsing into binary32/64 values. For chars_format::hex (and long double) 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 | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc index aa074869872..13834f54d38 100644 --- a/libstdc++-v3/src/c++17/floating_from_chars.cc +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,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) { @@ -406,6 +419,11 @@ from_chars_result from_chars(const char* first, const char* last, float& value, chars_format fmt) noexcept { +#if USE_LIB_FAST_FLOAT + if (fmt != chars_format::hex) + return fast_float::from_chars(first, last, value, fmt); +#endif + errc ec = errc::invalid_argument; #if _GLIBCXX_USE_CXX11_ABI buffer_resource mr; @@ -432,6 +450,11 @@ from_chars_result from_chars(const char* first, const char* last, double& value, chars_format fmt) noexcept { +#if USE_LIB_FAST_FLOAT + if (fmt != chars_format::hex) + return fast_float::from_chars(first, last, value, fmt); +#endif + errc ec = errc::invalid_argument; #if _GLIBCXX_USE_CXX11_ABI buffer_resource mr; -- 2.34.0