From patchwork Tue Nov 16 00:25:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 47736 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7EA773858027 for ; Tue, 16 Nov 2021 00:29:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7EA773858027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637022558; bh=ZZGrpaRzoABiYDLrrZofupVpiFs3nigestqnXqjhzuo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GnRMvIiAltWO8gp9Mng6zjchXyiEetf+ysC+8J2M2me6EemGg6MOZta1+DhsuhTdw VClwpR29AmNLgQuQNz5q4fiTkPZR3Ws1ucBbmlH6UtaWlBS3fbHwZ30djqiQRVp6IV 8+idlePZNLh9QXPXt/xikWQtvzRoQCr+eHRSKPyM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 0A4BE3857C4A for ; Tue, 16 Nov 2021 00:25:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A4BE3857C4A Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-262-fs6J1IxdMoKsUxwuuF9c4A-1; Mon, 15 Nov 2021 19:25:20 -0500 X-MC-Unique: fs6J1IxdMoKsUxwuuF9c4A-1 Received: by mail-qv1-f69.google.com with SMTP id q9-20020ad45749000000b003bdeb0612c5so17657913qvx.8 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=aVohiD7tZo47yPd3M6FtPpeVUIWV0CO0haPVnNeDB59RUKROCSprMp4SdjBcrKTkaS o3c/y/mOCjQaRJDPm4aI6h8fqYWgEFJTQEsTPhpt17CitlUoThg92iWGCUceNaSZ58jk B4GOwFr5f3kGGZm38jDl+W/SAGW78Ydq+iKq+dQb0vYcMFCVtPp3J32xYHrVlkC6gaQC /jpw0+c7GMze0f9k3jTf+E5mBVCkHUVuKhvJJL5zo27QBENcBs1n+W565beW+PjD05d0 BjslSLdepxzB4x64cxcTaB3Hym2N6WbtEWwDTqDL1Utcx1mS3Q20H1xsU5FYCoTuUMlF KMDw== X-Gm-Message-State: AOAM533NBhEfTlt+jm81ooZliTuZ8HHvwBBQ9dMnohjLuwJmcn9ZWQr5 jAZQk3pYX6LkxcY1kETUEKHUySjS9EQb3T25zZE11z75JGcT2GoBrwm5W31mjhE6yQ2xXZc9MeB PkBZso+KZfAiFINPMH5PvV57oW9CcgZo69Ho3FYmaXNklJVhtKRcx5YhoqqHvyTbEh2s= X-Received: by 2002:a37:9507:: with SMTP id x7mr2686730qkd.105.1637022320073; Mon, 15 Nov 2021 16:25:20 -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) To: gcc-patches@gcc.gnu.org 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 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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;