public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>, Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] libstdc++: _Bfloat16 for <compare>
Date: Wed, 2 Nov 2022 10:39:37 +0100	[thread overview]
Message-ID: <Y2I62a8i1u1I7EaE@tucnak> (raw)

Hi!

Jon pointed out that we have TODO: _Bfloat16 in <compare>.
Right now _S_fp_fmt() returns _Binary16 for _Float16, __fp16 as well
as __bf16 and it actually works because we don't have a special handling
of _Binary16.  So, either we could just document that, but I'm a little bit
afraid if HPPA or MIPS don't start supporting _Float16 and/or __bf16.
If they do, we have the
#if defined __hppa__ || (defined __mips__ && !defined __mips_nan2008)
                  // IEEE 754-1985 allowed the meaning of the quiet/signaling
                  // bit to be reversed. Flip that to give desired ordering.
                  if (__builtin_isnan(__x) && __builtin_isnan(__y))
                    {
                      using _Int = decltype(__ix);

                      constexpr int __nantype = __fmt == _Binary32  ?  22
                                              : __fmt == _Binary64  ?  51
                                              : __fmt == _Binary128 ? 111
                                              : -1;
                      constexpr _Int __bit = _Int(1) << __nantype;
                      __ix ^= __bit;
                      __iy ^= __bit;
                    }
#endif
code, the only one where we actually care whether something is
_Binary{32,64,128} (elsewhere we just care about the x86 and m68k 80bits
or double double or just floating point type's sizeof) and we'd need
to handle there _Binary16 and/or _Bfloat16.

So this patch uses different enum for it even when it isn't needed right
now, after all _Binary16 isn't needed either and we could just use
_Binary32...

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2022-11-02  Jakub Jelinek  <jakub@redhat.com>

	* libsupc++/compare (_Strong_order::_Fp_fmt): Add _Bfloat16.
	(_Strong_order::_Bfloat16): New static data member.
	(_Strong_order::_S_fp_fmt): Return _Bfloat16 for std::bfloat16_t.

--- libstdc++-v3/libsupc++/compare.jj	2022-05-09 09:09:21.196461093 +0200
+++ libstdc++-v3/libsupc++/compare	2022-11-01 22:13:16.771219615 +0100
@@ -672,7 +672,7 @@ namespace std _GLIBCXX_VISIBILITY(defaul
 	_X86_80bit,  // x86 80-bit extended precision
 	_M68k_80bit, // m68k 80-bit extended precision
 	_Dbldbl, // IBM 128-bit double-double
-	// TODO: _Bfloat16,
+	_Bfloat16,   // std::bfloat16_t
       };
 
 #ifndef __cpp_using_enum
@@ -684,6 +684,7 @@ namespace std _GLIBCXX_VISIBILITY(defaul
       static constexpr _Fp_fmt _X86_80bit = _Fp_fmt::_X86_80bit;
       static constexpr _Fp_fmt _M68k_80bit = _Fp_fmt::_M68k_80bit;
       static constexpr _Fp_fmt _Dbldbl = _Fp_fmt::_Dbldbl;
+      static constexpr _Fp_fmt _Bfloat16 = _Fp_fmt::_Bfloat16;
 #endif
 
       // Identify the format used by a floating-point type.
@@ -714,6 +715,10 @@ namespace std _GLIBCXX_VISIBILITY(defaul
 	  if constexpr (__is_same(_Tp, __float80))
 	    return _X86_80bit;
 #endif
+#ifdef __STDCPP_BFLOAT16_T__
+	  if constexpr (__is_same(_Tp, decltype(0.0bf16)))
+	    return _Bfloat16;
+#endif
 
 	  constexpr int __width = sizeof(_Tp) * __CHAR_BIT__;
 

	Jakub


             reply	other threads:[~2022-11-02  9:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02  9:39 Jakub Jelinek [this message]
2022-11-02 11:16 ` Jonathan Wakely

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=Y2I62a8i1u1I7EaE@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    --cc=ppalka@redhat.com \
    /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).