public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-3577] libstdc++: Small extended float support tweaks
Date: Mon, 31 Oct 2022 15:49:25 +0000 (GMT) [thread overview]
Message-ID: <20221031154925.1051D3887006@sourceware.org> (raw)
https://gcc.gnu.org/g:cbf56503d5e2bbafb06a507cb37d30805a1013a0
commit r13-3577-gcbf56503d5e2bbafb06a507cb37d30805a1013a0
Author: Jakub Jelinek <jakub@redhat.com>
Date: Mon Oct 31 16:47:23 2022 +0100
libstdc++: Small extended float support tweaks
The following 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
2022-10-21 Jakub Jelinek <jakub@redhat.com>
* 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.
Diff:
---
libstdc++-v3/config/os/gnu-linux/os_defines.h | 2 +-
libstdc++-v3/include/c_global/cmath | 8 ++++++--
| 2 ++
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h
index e5b640a0738..044b4fc91a9 100644
--- a/libstdc++-v3/config/os/gnu-linux/os_defines.h
+++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h
@@ -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)
diff --git a/libstdc++-v3/include/c_global/cmath b/libstdc++-v3/include/c_global/cmath
index 555d6440849..e52055ac474 100644
--- a/libstdc++-v3/include/c_global/cmath
+++ b/libstdc++-v3/include/c_global/cmath
@@ -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
--git a/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc b/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc
index 45aa3b74b25..8d7daa9208d 100644
--- a/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc
+++ b/libstdc++-v3/testsuite/26_numerics/headers/cmath/nextafter_c++23.cc
@@ -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
reply other threads:[~2022-10-31 15:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221031154925.1051D3887006@sourceware.org \
--to=jakub@gcc.gnu.org \
--cc=gcc-cvs@gcc.gnu.org \
--cc=libstdc++-cvs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).