summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qfloat16.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-02-10 14:51:12 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-02-16 12:03:45 +0000
commit925a3c65297edc37e394b9837782e79d837d20d1 (patch)
tree62a10dac9c308b11aac2286ba0d2e66c529f41b5 /src/corelib/global/qfloat16.h
parent5486882b5253c858cc545cc3a08f0f89af59578e (diff)
Use native support for fp16 where available
Use F16C or ARM FP16 if available at compile time. Configure check added because older clang compilers have F16C defines and flags but not all the intrinsics. Change-Id: I71f358b8fd003e70ab8fcf35097414591e485112 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qfloat16.h')
-rw-r--r--src/corelib/global/qfloat16.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h
index 67c062d349..8fd2f212af 100644
--- a/src/corelib/global/qfloat16.h
+++ b/src/corelib/global/qfloat16.h
@@ -44,6 +44,10 @@
#include <QtCore/qmetatype.h>
#include <string.h>
+#if defined __F16C__
+#include <immintrin.h>
+#endif
+
QT_BEGIN_NAMESPACE
#if 0
@@ -111,19 +115,34 @@ inline int qIntCast(qfloat16 f) Q_DECL_NOTHROW
inline qfloat16::qfloat16(float f) Q_DECL_NOTHROW
{
+#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
+ b16 = _cvtss_sh(f, 0);
+#elif defined (__ARM_FP16_FORMAT_IEEE)
+ __fp16 f16 = f;
+ memcpy(&b16, &f16, sizeof(quint16));
+#else
quint32 u;
memcpy(&u, &f, sizeof(quint32));
b16 = basetable[(u >> 23) & 0x1ff]
+ ((u & 0x007fffff) >> shifttable[(u >> 23) & 0x1ff]);
+#endif
}
inline qfloat16::operator float() const Q_DECL_NOTHROW
{
+#if defined(QT_COMPILER_SUPPORTS_F16C) && defined(__F16C__)
+ return _cvtsh_ss(b16);
+#elif defined (__ARM_FP16_FORMAT_IEEE)
+ __fp16 f16;
+ memcpy(&f16, &b16, sizeof(quint16));
+ return f16;
+#else
quint32 u = mantissatable[offsettable[b16 >> 10] + (b16 & 0x3ff)]
+ exponenttable[b16 >> 10];
float f;
memcpy(&f, &u, sizeof(quint32));
return f;
+#endif
}
inline qfloat16::operator double() const Q_DECL_NOTHROW