public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Small extended float support tweaks
@ 2022-10-21  7:29 Jakub Jelinek
  2022-10-31 10:16 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-10-21  7:29 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches, libstdc++

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  <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.

--- 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

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] libstdc++: Small extended float support tweaks
  2022-10-21  7:29 [PATCH] libstdc++: Small extended float support tweaks Jakub Jelinek
@ 2022-10-31 10:16 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2022-10-31 10:16 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, libstdc++

On Fri, 21 Oct 2022 at 08:29, Jakub Jelinek <jakub@redhat.com> wrote:
>
> 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?

Yes, thanks.


>
> 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.
>
> --- 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
>
>         Jakub
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-31 10:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21  7:29 [PATCH] libstdc++: Small extended float support tweaks Jakub Jelinek
2022-10-31 10:16 ` Jonathan Wakely

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).