summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qendian.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h
index 1cc8a823d9..0e67a1ab8e 100644
--- a/src/corelib/global/qendian.h
+++ b/src/corelib/global/qendian.h
@@ -41,6 +41,7 @@
#ifndef QENDIAN_H
#define QENDIAN_H
+#include <QtCore/qfloat16.h>
#include <QtCore/qglobal.h>
// include stdlib.h and hope that it defines __GLIBC__ for glibc-based systems
@@ -151,6 +152,31 @@ template <> inline Q_DECL_CONSTEXPR qint8 qbswap<qint8>(qint8 source)
return source;
}
+// floating specializations
+template<typename Float>
+Float qbswapFloatHelper(Float source)
+{
+ // memcpy call in qFromUnaligned is recognized by optimizer as a correct way of type prunning
+ auto temp = qFromUnaligned<typename QIntegerForSizeof<Float>::Unsigned>(&source);
+ temp = qbswap(temp);
+ return qFromUnaligned<Float>(&temp);
+}
+
+template <> inline qfloat16 qbswap<qfloat16>(qfloat16 source)
+{
+ return qbswapFloatHelper(source);
+}
+
+template <> inline float qbswap<float>(float source)
+{
+ return qbswapFloatHelper(source);
+}
+
+template <> inline double qbswap<double>(double source)
+{
+ return qbswapFloatHelper(source);
+}
+
/*
* qbswap(const T src, const void *dest);
* Changes the byte order of \a src from big endian to little endian or vice versa