summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qfloat16.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qfloat16.cpp')
-rw-r--r--src/corelib/global/qfloat16.cpp46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp
index 87ff796368..68763c0606 100644
--- a/src/corelib/global/qfloat16.cpp
+++ b/src/corelib/global/qfloat16.cpp
@@ -1,5 +1,6 @@
/****************************************************************************
**
+** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2016 by Southwest Research Institute (R)
** Contact: http://www.qt-project.org/legal
**
@@ -37,8 +38,9 @@
**
****************************************************************************/
-#include "qfloat16_p.h"
+#include "qfloat16.h"
#include "private/qsimd_p.h"
+#include <cmath> // for fpclassify()'s return values
QT_BEGIN_NAMESPACE
@@ -78,28 +80,42 @@ QT_BEGIN_NAMESPACE
*/
/*!
- Returns true if the \c qfloat16 \a {f} is equivalent to infinity.
+ \fn bool qIsInf(qfloat16 f)
\relates <QFloat16>
+ Returns true if the \c qfloat16 \a {f} is equivalent to infinity.
+
\sa qIsInf
*/
-Q_REQUIRED_RESULT bool qIsInf(qfloat16 f) Q_DECL_NOTHROW { return qt_is_inf(f); }
/*!
- Returns true if the \c qfloat16 \a {f} is not a number (NaN).
+ \fn bool qIsNaN(qfloat16 f)
\relates <QFloat16>
+ Returns true if the \c qfloat16 \a {f} is not a number (NaN).
+
\sa qIsNaN
*/
-Q_REQUIRED_RESULT bool qIsNaN(qfloat16 f) Q_DECL_NOTHROW { return qt_is_nan(f); }
/*!
- Returns true if the \c qfloat16 \a {f} is a finite number.
+ \fn bool qIsFinite(qfloat16 f)
\relates <QFloat16>
+ Returns true if the \c qfloat16 \a {f} is a finite number.
+
\sa qIsFinite
*/
-Q_REQUIRED_RESULT bool qIsFinite(qfloat16 f) Q_DECL_NOTHROW { return qt_is_finite(f); }
+
+/*!
+ \internal
+ Implements qFpClassify() for qfloat16.
+ */
+
+int qfloat16::fpClassify() const noexcept
+{
+ return isInf() ? FP_INFINITE : isNaN() ? FP_NAN
+ : !b16 ? FP_ZERO : isNormal() ? FP_NORMAL : FP_SUBNORMAL;
+}
/*! \fn int qRound(qfloat16 value)
\relates <QFloat16>
@@ -142,8 +158,8 @@ extern "C" {
# define f16cextern extern
#endif
-f16cextern void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q_DECL_NOTHROW;
-f16cextern void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) Q_DECL_NOTHROW;
+f16cextern void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) noexcept;
+f16cextern void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) noexcept;
#undef f16cextern
}
@@ -154,7 +170,7 @@ static inline bool hasFastF16()
return true;
}
-static void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q_DECL_NOTHROW
+static void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) noexcept
{
__fp16 *out_f16 = reinterpret_cast<__fp16 *>(out);
qsizetype i = 0;
@@ -164,7 +180,7 @@ static void qFloatToFloat16_fast(quint16 *out, const float *in, qsizetype len) Q
out_f16[i] = __fp16(in[i]);
}
-static void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) Q_DECL_NOTHROW
+static void qFloatFromFloat16_fast(float *out, const quint16 *in, qsizetype len) noexcept
{
const __fp16 *in_f16 = reinterpret_cast<const __fp16 *>(in);
qsizetype i = 0;
@@ -179,12 +195,12 @@ static inline bool hasFastF16()
return false;
}
-static void qFloatToFloat16_fast(quint16 *, const float *, qsizetype) Q_DECL_NOTHROW
+static void qFloatToFloat16_fast(quint16 *, const float *, qsizetype) noexcept
{
Q_UNREACHABLE();
}
-static void qFloatFromFloat16_fast(float *, const quint16 *, qsizetype) Q_DECL_NOTHROW
+static void qFloatFromFloat16_fast(float *, const quint16 *, qsizetype) noexcept
{
Q_UNREACHABLE();
}
@@ -196,7 +212,7 @@ static void qFloatFromFloat16_fast(float *, const quint16 *, qsizetype) Q_DECL_N
Converts \a len floats from \a in to qfloat16 and stores them in \a out.
Both \a in and \a out must have \a len allocated entries.
*/
-Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len) Q_DECL_NOTHROW
+Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len) noexcept
{
if (hasFastF16())
return qFloatToFloat16_fast(reinterpret_cast<quint16 *>(out), in, len);
@@ -212,7 +228,7 @@ Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *out, const float *in, qsizetype len
Converts \a len qfloat16 from \a in to floats and stores them in \a out.
Both \a in and \a out must have \a len allocated entries.
*/
-Q_CORE_EXPORT void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype len) Q_DECL_NOTHROW
+Q_CORE_EXPORT void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype len) noexcept
{
if (hasFastF16())
return qFloatFromFloat16_fast(out, reinterpret_cast<const quint16 *>(in), len);