|
Boost : |
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2019-10-14 19:15:03
Hi,
There seems to be support for 16-bit floats on iOS, when using
Apple's XCode clang. This seems to be a storage-only format
with the only instruction set support being conversions to
and from 32- and 64-bit floats. Quick test:
#if __ARM_FP & 2
#warning "Have 16-bit FP"
#endif
void test()
{
__fp16 a = 1.234;
static_assert(sizeof(a)==2);
__fp16 b = 2.345;
auto sum = a+b;
static_assert(sizeof(sum)==4);
}
There doesn't seem to be a std::numeric_limits specialisation.
I suspect that other platforms have something similar. It would be
good to have a boost::float16_t typedef and a portable feature-test
macro (and maybe a software fallback). As far as I can see,
boost/math/cstdfloat/cstdfloat_types.hpp checks the sizes of
float, double and long double, and checks for 128-bit floats provided
by the compiler. Can this be extended to check for __fp16 ?
(P.S. it seems that gcc also has support, see
https://gcc.gnu.org/onlinedocs/gcc/Half-Precision.html )
Cheers, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk