2

Clang documentation says:

_Float16 arithmetic will be performed using native half-precision support when available on the target (e.g. on ARMv8.2a); otherwise it will be performed at a higher precision (currently always float) and then truncated down to _Float16.

Is there a way to say I want to use _Float16 only in the first case, and float otherwise, to avoid the truncation in the second case? I.e. something like

#if ???
using float_maybe_16 = _Float16;
#else
using float_maybe_16 = float;
#endif
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • "Is there a way to say I want to use _Float16 only in the first case, and float otherwise?" - Isn't the documentation you quoted saying that that's what you'll get by *default*?? – Jesper Juhl Apr 20 '20 at 17:37
  • @JesperJuhl No. The default is to truncate away extra precision when a real half-precision type is missing. The pseudocode as given would keep that precision if half-precision arithmetic is not available. It's a subtle distinction, so the OP should probably clarify whether that's the intent. – HTNW Apr 20 '20 at 18:02
  • Have you looked at `__SIZEOF_FLOAT__`? – F Trias Apr 20 '20 at 18:02
  • Yes, the intention is to avoid truncation in the second case. – Alexey Romanov Apr 20 '20 at 18:25
  • @FTrias Going by https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html it doesn't seem to be relevant, it's just `sizeof(float)` whether there is half-precision support or not. Unless I misunderstand something? – Alexey Romanov Apr 20 '20 at 18:32

0 Answers0