From patchwork Fri Oct 21 07:29:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 6540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp542961wrr; Fri, 21 Oct 2022 00:30:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67S5cGC9AnzWiwyVuZU86LOQPHwp7qBG1Gs0sZeFrL6bwQsBdU3GRnNneTG84GM6tO6eEM X-Received: by 2002:a17:907:7d8b:b0:78e:2534:4fd3 with SMTP id oz11-20020a1709077d8b00b0078e25344fd3mr14654921ejc.141.1666337415851; Fri, 21 Oct 2022 00:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666337415; cv=none; d=google.com; s=arc-20160816; b=Z8YVYkGR5Yg/NiStEFCnDs1Fw/Bexx5gD6L+e1EdlNBjeY/gH8hDRkF7q9oPrH6bEA LojQC90Gx154XAlFQ/dWq4kbt100RVnUoHL2E4hdtbZfEYh/S3S6WHXBijscO+ejnUFb 3asbAdtrYUKufBq1I4xaZXfu6XLB40qM+Foh6kDD54BW0XFqbl7fkLAn6KiXFWZujxIh GS4jb+cWRNWfKpmzp8CE6fSJeOP87kcQAb8GnayjVRnh927iGFBDLnBT+yiVbr4gOW+T Z2b/46Ws5sPdDGsoqmwq0hSqJxo0CxD4jHKM12U7Z39rpdtFlU98QMpLTYqJGcqz9Z1L 7rGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=WSuuTmcvlgB35aQgfzTIDi4FIeRAlIFJAs8h41W6c5c=; b=QFEnPgcjEaYhDXzjli5s4QrMbVXTHYabDLkTxgsUeKYHsM/RqtdB4yE8e4jNgR1hmm 9tBM0EmCD0wp6AzFAcUAsPyarY6mDbgPYgGlFKedh7tuKOkoShLh+5hwNChzjv31J8KH 5NyuuD+GHQBNBONQmoBCoH0s6x4CaH2i+wPk31IvO/OpadNdwMG9HsIhJVaMC2WPtbBy OQhGfxVP4QzvO4Kajha9vGkswJ3Mqgr+dOCNCvL+GwYH5XCCAOEMYAWxBHeBT/0AHHDS lNXGf2p+hbHGnJXBS7urcv1heqO/71ZnF78ZrUzONqyIPxYx3+l2YBonzgkt7P/L/3ep MnHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TKvoCwPy; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id dp21-20020a170906c15500b00780e844b2eesi15109815ejc.482.2022.10.21.00.30.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 00:30:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TKvoCwPy; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67F213857005 for ; Fri, 21 Oct 2022 07:30:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67F213857005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666337405; bh=WSuuTmcvlgB35aQgfzTIDi4FIeRAlIFJAs8h41W6c5c=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TKvoCwPyiWSctTpncputZCOin4iNFdJILHXjFbvSqKq58YdRnXpF7k9TcSUsldCzl YS0oDf4rQHrLYCZZ2whd8gfadjHbwQ4VUgqxy/1QHajrkt+icS8VqXgvbDR2aWyR5Q sqM6bfXl8haZOvHERb6m5yIc18mbDcQvZ+dIPCn8= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id EA5B63857407 for ; Fri, 21 Oct 2022 07:29:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EA5B63857407 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-633-w6SILfM0Mh2etG-YPX4juw-1; Fri, 21 Oct 2022 03:29:19 -0400 X-MC-Unique: w6SILfM0Mh2etG-YPX4juw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7446C3C10147; Fri, 21 Oct 2022 07:29:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 32B27141C68B; Fri, 21 Oct 2022 07:29:19 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 29L7TFTW3484855 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 21 Oct 2022 09:29:16 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29L7TFhH3484854; Fri, 21 Oct 2022 09:29:15 +0200 Date: Fri, 21 Oct 2022 09:29:14 +0200 To: Jonathan Wakely Subject: [PATCH] libstdc++: Small extended float support tweaks Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747281422230124712?= X-GMAIL-MSGID: =?utf-8?q?1747281422230124712?= Hi! The following patch isn't for immediate commit, as it has several dependencies, in particular: https://gcc.gnu.org/pipermail/gcc-patches/2022-October/603665.html https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604080.html https://gcc.gnu.org/pipermail/libstdc++/2022-October/054849.html On top of those, this patch 1) enables the std::float128_t overloads for x86 with glibc 2.26+ 2) makes std::nextafter(std::float16_t, std::float16_t) and std::nextafter(std::bfloat16_t, std::bfloat16_t) constexpr 3) adds (small) testsuite coverage for that Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk if/when the above dependencies are in? 2022-10-21 Jakub Jelinek * config/os/gnu-linux/os_defines.h (_GLIBCXX_HAVE_FLOAT128_MATH): Uncomment. * include/c_global/cmath (nextafter(_Float16, _Float16)): Make it constexpr. If std::__is_constant_evaluated() call __builtin_nextafterf16. (nextafter(__gnu_cxx::__bfloat16_t, __gnu_cxx::__bfloat16_t): Similarly but call __builtin_nextafterf16b. * testsuite/26_numerics/headers/cmath/nextafter_c++23.cc (test): Add static assertions to test constexpr nextafter. Jakub --- libstdc++-v3/config/os/gnu-linux/os_defines.h.jj 2022-10-18 11:35:55.514865483 +0200 +++ libstdc++-v3/config/os/gnu-linux/os_defines.h 2022-10-20 16:57:59.715681664 +0200 @@ -57,7 +57,7 @@ || (defined(__powerpc__) && defined(_ARCH_PWR8) \ && defined(__LITTLE_ENDIAN__) && (_CALL_ELF == 2) \ && defined(__FLOAT128__))) -//# define _GLIBCXX_HAVE_FLOAT128_MATH 1 +# define _GLIBCXX_HAVE_FLOAT128_MATH 1 #endif #if __GLIBC_PREREQ(2, 27) --- libstdc++-v3/include/c_global/cmath.jj 2022-10-19 11:23:51.484488161 +0200 +++ libstdc++-v3/include/c_global/cmath 2022-10-20 17:03:56.760805581 +0200 @@ -2755,9 +2755,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION nearbyint(_Float16 __x) { return _Float16(__builtin_nearbyintf(__x)); } - inline _Float16 + constexpr _Float16 nextafter(_Float16 __x, _Float16 __y) { + if (std::__is_constant_evaluated()) + return __builtin_nextafterf16(__x, __y); #ifdef __INT16_TYPE__ using __float16_int_type = __INT16_TYPE__; #else @@ -3471,9 +3473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION nearbyint(__gnu_cxx::__bfloat16_t __x) { return __gnu_cxx::__bfloat16_t(__builtin_nearbyintf(__x)); } - inline __gnu_cxx::__bfloat16_t + constexpr __gnu_cxx::__bfloat16_t nextafter(__gnu_cxx::__bfloat16_t __x, __gnu_cxx::__bfloat16_t __y) { + if (std::__is_constant_evaluated()) + return __builtin_nextafterf16b(__x, __y); #ifdef __INT16_TYPE__ using __bfloat16_int_type = __INT16_TYPE__; #else --- libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc.jj 2022-10-20 16:57:29.940088318 +0200 +++ libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc 2022-10-20 17:19:40.141923257 +0200 @@ -100,6 +100,8 @@ test () VERIFY( std::fpclassify(t36) == FP_NAN ); T t37 = std::nextafter(T(-0.0), T()); VERIFY( t37 == T() && !std::signbit(t37) ); + static_assert(std::nextafter(T(1.0), T(2.0)) > T(1.0)); + static_assert(std::nextafter(std::nextafter(T(1.0), T(5.0)), T(0.0)) == T(1.0)); } int