From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 804F33858D37; Wed, 2 Nov 2022 12:37:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 804F33858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667392669; bh=TfqYlJvUaTt9PTFvTxdhahHeTU+mv6za4JeZ6GECrxY=; h=From:To:Subject:Date:From; b=fb6pzZIEULdeIfoXn3UgUWxaqy6GsNvnaWZuurFlRnnIlZye4aPdA6HJhx5gCxFIT sxPhLDIV1DUoygOzzaEUj2f5B6FWy2hpjScikHRA/f27OaTq2ybhI94fMeFb2nRArk 8W3vZ0ef5mQeFJu+12MSYYP73BmzFd87ttFx5a28= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3606] libstdc++: _Bfloat16 for X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: c3299cde4f33121f82a7a25d10c152ac96d2b035 X-Git-Newrev: 0c86a667486362e8bc6a92e5d36acaac4242c59f Message-Id: <20221102123749.804F33858D37@sourceware.org> Date: Wed, 2 Nov 2022 12:37:49 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0c86a667486362e8bc6a92e5d36acaac4242c59f commit r13-3606-g0c86a667486362e8bc6a92e5d36acaac4242c59f Author: Jakub Jelinek Date: Wed Nov 2 13:35:53 2022 +0100 libstdc++: _Bfloat16 for Jon pointed out that we have TODO: _Bfloat16 in . 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... 2022-11-02 Jakub Jelinek * 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. Diff: --- libstdc++-v3/libsupc++/compare | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/libsupc++/compare b/libstdc++-v3/libsupc++/compare index 066867e9ce1..e25f4ef52cb 100644 --- a/libstdc++-v3/libsupc++/compare +++ b/libstdc++-v3/libsupc++/compare @@ -672,7 +672,7 @@ namespace std _GLIBCXX_VISIBILITY(default) _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(default) 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(default) 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__;