diff options
Diffstat (limited to 'src/corelib/global/qfloat16.cpp')
-rw-r--r-- | src/corelib/global/qfloat16.cpp | 88 |
1 files changed, 73 insertions, 15 deletions
diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp index 87ff796368..6c21b7de5a 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,83 @@ 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 + \since 5.14 + bool qfloat16::isInf() const noexcept + + Tests whether this \c qfloat16 value is an infinity. + + \sa qIsInf() +*/ + +/*! + \internal + \since 5.14 + bool qfloat16::isNaN() const noexcept + + Tests whether this \c qfloat16 value is "not a number". + + \sa qIsNaN() +*/ + +/*! + \since 5.14 + bool qfloat16::isNormal() const noexcept + + Tests whether this \c qfloat16 value is finite and in normal form. + + \sa qFpClassify() +*/ + +/*! + \internal + \since 5.14 + bool qfloat16::isFinite() const noexcept + + Tests whether this \c qfloat16 value is finite. + + \sa qIsFinite() +*/ + +/*! + \internal + \since 5.14 + Implements qFpClassify() for qfloat16. + + \sa qFpClassify() +*/ +int qfloat16::fpClassify() const noexcept +{ + return isInf() ? FP_INFINITE : isNaN() ? FP_NAN + : !(b16 & 0x7fff) ? FP_ZERO : isNormal() ? FP_NORMAL : FP_SUBNORMAL; +} /*! \fn int qRound(qfloat16 value) \relates <QFloat16> @@ -142,8 +199,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 +211,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 +221,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 +236,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 +253,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 +269,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); @@ -223,6 +280,7 @@ Q_CORE_EXPORT void qFloatFromFloat16(float *out, const qfloat16 *in, qsizetype l QT_END_NAMESPACE +#include "qfloat16tables.cpp" #ifdef QFLOAT16_INCLUDE_FAST # include "qfloat16_f16c.c" #endif |