From patchwork Thu May 4 12:05:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1776899 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=uf1r/YAe; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QBswC1ymSz20fg for ; Thu, 4 May 2023 22:05:47 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C105D38582BD for ; Thu, 4 May 2023 12:05:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C105D38582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683201944; bh=u2qNLRUHslsiCgkwFXyS/fc+NebWxThk+v9JC6vkdEY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uf1r/YAeGRsfAAX2jbYEQRPRzGF8pSN0UWXeaH5hnzcr2fE8eEyTH8MX9FOkKr2IB a1GB24V9qb+3FAGRPkwG9r5F31MZPCxvPWNjCQd5nQceNL4LnW/XOzZJoa6UFAowqE pTzhSDlk3sovzb8E6fGtGS/heJ5bgiDBLWkP6Luc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oa1-x35.google.com (mail-oa1-x35.google.com [IPv6:2001:4860:4864:20::35]) by sourceware.org (Postfix) with ESMTPS id EA3453858D33 for ; Thu, 4 May 2023 12:05:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA3453858D33 Received: by mail-oa1-x35.google.com with SMTP id 586e51a60fabf-1928860f63eso274119fac.0 for ; Thu, 04 May 2023 05:05:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683201919; x=1685793919; h=mime-version:user-agent:message-id:date:errors-to:organization :subject:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=u2qNLRUHslsiCgkwFXyS/fc+NebWxThk+v9JC6vkdEY=; b=QKuaubptU2n85Ah2N95glzeKtjZPOdNsCl4Tj9fOL+vsO1Vjp26bqbuhaUiAWDMSCM iXhkT2Rh4JZH9duHZGEl9LTnFv5UgnzO9iOgXs9E+ahqPOjji74aE0360bVVjLs93i3F Fqkk0uex18EQTttuONLQa60whI8x/J3Ec4uEoez6aSlgGbb8mFkCHdEgXIEzk1zeBgwP jGa8noRoxiBKEeZEprOyITqBdT8mcWDoQDAqtoichclsuSIq7j/JJDvufWu7iuqVNF9v 8yfdpIXNDVP18Ih+sAM3oeY1s6BjAulOsT87ffrF/zl4ijM60Ia+4EgisI3QisDari9M C/eQ== X-Gm-Message-State: AC+VfDyU4F5LkEu6Q1TZf9v+o9sHVIyEIzYXLgAt7LkjsnvSuy9oWHrH jzGN9G4gxeIpPSPWcDoyVk8c4dCcOQtJmrLwl54= X-Google-Smtp-Source: ACHHUZ4iU0ev3cTo8iRqV9rT/Qpmyycyd2nQIJes5KiVxV8yoB53HFAMV/9kKVNCxVvWSRZC1wWGJg== X-Received: by 2002:a05:6870:4c3:b0:18b:1926:43eb with SMTP id u3-20020a05687004c300b0018b192643ebmr693352oam.48.1683201918936; Thu, 04 May 2023 05:05:18 -0700 (PDT) Received: from free.home ([2804:7f1:2080:c4e6:caf1:179:3909:b1dd]) by smtp.gmail.com with ESMTPSA id d13-20020a056871040d00b0019296ee9606sm572686oag.4.2023.05.04.05.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 05:05:18 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 344C55wF2687770 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 4 May 2023 09:05:06 -0300 To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [libstdc++] use strtold for from_chars even without locale Organization: Free thinker, does not speak for AdaCore Date: Thu, 04 May 2023 09:05:05 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When we're using fast_float for 32- and 64-bit floating point, use strtold for wider long double, even if locales are unavailable. On vxworks, test for strtof's and strtold's declarations, so that they can be used even when cross compiling. Include stdlib.h in the decl-checking macro, so that it can find them. Regstrapped on x86_64-linux-gnu. Also tested on aarch64-vx7r2 with gcc-12, where uselocale is not available, and using strtold rather than fast_math's double fallback avoids a couple of from_chars-related testsuite fails (from_chars/4.cc and to_chars/long_double.cc). Ok to install? for libstdc++-v3/ChangeLog * src/c++17/floating_from_chars.cc (USE_STRTOD_FOR_FROM_CHARS): Define when using fast_float if long double is not as wide as double and strtold is not broken. * crossconfig.m4: Test for strtof and strtold declarations on vxworks. (GLIBCXX_CHECK_MATH_DECL): Include stdlib.h too. * configure: Rebuilt. --- libstdc++-v3/configure | 131 +++++++++++++++++++++++++ libstdc++-v3/crossconfig.m4 | 3 - libstdc++-v3/src/c++17/floating_from_chars.cc | 10 ++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure [omitted] diff --git a/libstdc++-v3/crossconfig.m4 b/libstdc++-v3/crossconfig.m4 index b3269cb88e077..9db32f4d422da 100644 --- a/libstdc++-v3/crossconfig.m4 +++ b/libstdc++-v3/crossconfig.m4 @@ -293,7 +293,7 @@ dnl # switch to more elaborate tests. GLIBCXX_CHECK_MATH_DECLS([ acosl asinl atan2l atanl ceill cosl coshl expl fabsl floorl fmodl frexpl ldexpl log10l logl modfl powl sinl sinhl sqrtl tanl tanhl hypotl - ldexpf modff hypotf frexpf]) + ldexpf modff hypotf frexpf strtof strtold]) dnl # sincosl is the only one missing here, compared with the *l dnl # functions in the list guarded by dnl # long_double_math_on_this_cpu in configure.ac, right after @@ -323,6 +323,7 @@ AC_DEFUN([GLIBCXX_CHECK_MATH_DECL], [ AC_LANG_SAVE AC_LANG_C AC_TRY_COMPILE([ +#include #include #ifdef HAVE_IEEEFP_H # include diff --git a/libstdc++-v3/src/c++17/floating_from_chars.cc b/libstdc++-v3/src/c++17/floating_from_chars.cc index 78b9d92cdc0fa..15af811d198c4 100644 --- a/libstdc++-v3/src/c++17/floating_from_chars.cc +++ b/libstdc++-v3/src/c++17/floating_from_chars.cc @@ -80,6 +80,10 @@ extern "C" _Float128 __strtof128(const char*, char**) # if __LDBL_MANT_DIG__ == __DBL_MANT_DIG__ // No need to use strtold. # undef USE_STRTOD_FOR_FROM_CHARS +# elif !defined USE_STRTOD_FOR_FROM_CHARS \ + && defined _GLIBCXX_HAVE_STRTOLD && !defined _GLIBCXX_HAVE_BROKEN_STRTOLD +// A working strtold will be more compliant than fast_float's double. +# define USE_STRTOD_FOR_FROM_CHARS 1 # endif #endif @@ -607,9 +611,11 @@ namespace ptrdiff_t from_chars_impl(const char* str, T& value, errc& ec) noexcept { +#if _GLIBCXX_HAVE_USELOCALE if (locale_t loc = ::newlocale(LC_ALL_MASK, "C", (locale_t)0)) [[likely]] { locale_t orig = ::uselocale(loc); +#endif #if _GLIBCXX_USE_C99_FENV_TR1 && defined(FE_TONEAREST) const int rounding = std::fegetround(); @@ -652,8 +658,10 @@ namespace std::fesetround(rounding); #endif +#if _GLIBCXX_HAVE_USELOCALE ::uselocale(orig); ::freelocale(loc); +#endif const ptrdiff_t n = endptr - str; if (conv_errno == ERANGE) [[unlikely]] @@ -674,9 +682,11 @@ namespace ec = errc(); } return n; +#if _GLIBCXX_HAVE_USELOCALE } else if (errno == ENOMEM) ec = errc::not_enough_memory; +#endif return 0; }