public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] Appropriate portable data type for IEEE half-precision on C/C++
@ 2021-03-12  8:33 Kito Cheng
  2021-03-12  9:23 ` Jonathan Wakely
  0 siblings, 1 reply; 10+ messages in thread
From: Kito Cheng @ 2021-03-12  8:33 UTC (permalink / raw)
  To: GCC

Hi:

It's Kito, a RISC-V folks, recently RISC-V has an ISA extension draft
for IEEE half-precision operations [4], including arithmetic,
conversion, comparison...a full set of support for IEEE
half-precision.

So we are seeking the data type for IEEE half-precision, and then we
have few candidates for that:
1. _Float16
2. __fp16 (Same as ACLE)
3. Other type names maybe __float16_t

_Float16 was the best candidate since it kind of standard types from
ISO/IEC TS 18661-3, and it already supported by both clang and gcc,
however the issue is GCC don't support that on C++ mode and seems like
[1-2] it not intend to support that due to the decimal floating point
issue, C++ also has another proposal for extended floating-point types
(https://wg21.link/p1467), which included half-precision types, so in
my understanding, _Float16 won't be a portable typen between C/C++.

And the second candidate __fp16, which is the typename come from ACLE,
it has no C/C++ portable issue due to its target specific type, the
only issue is ACLE has defined that promote to float before operation,
which is not fully utilized the hardware features, so one possible
solution is RISC-V also defined __fp16 type, but with different
semantics, no promotion if HW fp16 are enabled, like _Float16 has
flexible evaluation format, then we can gain most advantage,
compilable for ARM source code, also benefit with the hardware
capability.
But users might get different slight results than ARM, since we might
not do float promotion before evaluation for __fp16.

So the last candidate is defined another typename like __float16_t,
and define the behavior almost same as _Float16 but with default
promotion rule like __fp16 from ACLE, it also has no C/C++ portable
issue, but lose a little bit compatibility with the ARM code.

What do you think about this? I guess ideally we could wait for
P1467[3] to be included in C++ standard, but it seems like we need to
wait another couple years to land.

Or maybe add a target specific type to resolve that immediate is more
realistic solution?

Thanks

[1] See "C++ note:" in commit log
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=c65699efcce48d68ef57ab3ce7fc5420fac5cbf9
[2] https://gcc.gnu.org/pipermail/gcc/2021-March/234965.html
[3] https://wg21.link/p1467
[4] https://github.com/riscv/riscv-isa-manual/pull/496

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

end of thread, other threads:[~2021-03-15 15:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12  8:33 [RFC] Appropriate portable data type for IEEE half-precision on C/C++ Kito Cheng
2021-03-12  9:23 ` Jonathan Wakely
2021-03-12  9:37   ` Kito Cheng
2021-03-12  9:44     ` Jonathan Wakely
2021-03-12  9:46       ` Jonathan Wakely
2021-03-12  9:57       ` Kito Cheng
2021-03-12 10:06         ` Jonathan Wakely
2021-03-12 18:07   ` Joseph Myers
2021-03-12 19:28     ` Gabriel Ravier
2021-03-15 15:35     ` Kito Cheng

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