summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* qfloat16: make relational operators constexpr when QFLOAT16_IS_NATIVEIvan Solovev2024-01-191-0/+40
| | | | | | | | | | | | | | | | | | | When qfloat16 uses float as an underlying type, the operators cannot be constexpr, because operator float() is not constexpr. However, operator NativeType() is, so we can make the relational operators constexpr when we are using a native 16-bit float as an underlying type. To avoid code duplication, introduce new temporary macros for constexpr and Q_DECLARE_PARTIALLY_ORDERED_LITERAL_TYPE. Extend the tests to verify that the operators are constexpr when native float16 type is used. Task-number: QTBUG-119433 Pick-to: 6.7 Change-Id: I001b087d78c398c71b71a504b65c316199dd4792 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* qfloat16: extend comparison with integral typesIvan Solovev2023-12-081-4/+35
| | | | | | | | | | | | | | | | | | | | | | | qfloat16 implemented comparison with int, but not with other integral types. As a result, comparing qfloat16 vs qint64 or short was ambiguous, because the compiler had (at least) two options: * qint64 -> int * qint64 -> float Fix it by explicitly introducing comparison operators for other integral types. Use the new compare helper macros for that, and implement helper methods as templates restricted on integral types. Note that we have to manually extend the std::is_integral type trait because libstdc++ only treats __{u}int128_t types as integral when compiling in -std=gnu++XX mode, and we compile Qt in -std=c++XX mode. Fixes: QTBUG-117637 Change-Id: Id0c074af1e9ccc2c2492eb2cc4ee62a4a7131b07 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* qfloat16: use new comparison helper macrosIvan Solovev2023-12-081-0/+105
| | | | | | | | | | This replaces all the other helper macros which were used to generate the relational operators before, and also gains support for operator<=>() in C++20 mode. Change-Id: I40cec3cb5a5c42523787414d610e00afe6fc86f8 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* qfloat16: make it a built-in metatypeThiago Macieira2022-11-281-0/+12
| | | | | | | | | | | I've reserved the IDs for int128, uint128, bfloat16, and float128, because the mask in qvariant.cpp's qIsNumericType() requires primitives to be less than 64 to operate properly. Added a QMetaType/QDataStream test to confirm it is indeed built-in. Change-Id: I3d74c753055744deb8acfffd17247f7f57bada02 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* qfloat16: add QTextStream & QDebug streaming operatorsThiago Macieira2022-11-281-0/+22
| | | | | Change-Id: Ieba79baf5ac34264a988fffd172655bdcaf12a59 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* qfloat16: add QDataStream testsThiago Macieira2022-11-281-0/+25
| | | | | | Change-Id: I3d74c753055744deb8acfffd172494bf935864b8 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* qfloat16: add support for native _Float16 (C2x extended floating point)Thiago Macieira2022-11-281-2/+2
| | | | | | | | | | | | | | | | | | | | The C++ equivalent is std::float16_t, defined in P1467[1], and is coming with GCC 13 both in native mode (for x86, using AVX512FP16) and in emulated mode. The C and C++ types will be the same type (<stdfloat> simply typedefs). qfloat16 will need to remain a wrapper with an integer member to keep ABI with previous Qt versions. Because it is a trivially-copyable small type, it gets currently passed in registers; the presence of the integer member means it gets passed in general-purpose registers, while a single _Float16 member would be passed in a floating-point register. See: https://gcc.godbolt.org/z/8fEendjff [1] https://wg21.link/p1467 Change-Id: I8a5b6425b64a4e319b94fffd161be56397cb48e6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-28/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Remove remnants of the old Intel C++ compilerThiago Macieira2022-05-111-6/+0
| | | | | | | | | | | | | We don't support it any more. I don't think it has ever properly compiled Qt 6 (and it's no longer working for me against GCC 12's libstdc++ headers). If you report a bug against it, Intel support's first question is if you can try instead the new Clang/LLVM-based oneAPI C++ compiler. So we support only that one, which identifies itself as Q_CC_CLANG. Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16eb57a092c8439e Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Fix has_signaling_NaN usage for INTEGRITYTatiana Borisova2022-03-161-2/+5
| | | | | | | | | | - The newest GHS compiler versions set the value of has_signaling_NaN to False. Add compilation and autotest fix for GHS-compiler 2021/2022 releases. Task-number: QTBUG-99123 Pick-to: 6.2 6.3 Change-Id: I45e5da6759a15c60c17f896e565002cbba8524ed Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix tst_qfloat16 run time error for INTEGRITY (tested on sa8115)Tatiana Borisova2022-01-301-0/+5
| | | | | | | | | | | - Bounds::has_denorm returns denorm_indeterminate. It is expected behavior for GHS compiler. Task-number: QTBUG-99123 Pick-to: 6.2 6.3 Change-Id: I8402c541093a73623b6dc507012d98e565789cff Reviewed-by: Kimmo Ollila <kimmo.ollila@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* Fix tst_qfloat16 runtime failure for INTEGRITYTatiana Borisova2021-12-061-0/+13
| | | | | | | | | | - GHS compiler is not fully compliant with iec559. Therefore we need to update is_iec559 checking for GHS case. Pick-to: 6.2 Change-Id: Ia094509d26bf5f0109f2937547a056267019cffb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
* Use a more forgiving threshold for qFuzzyIsNull(qfloat16)Edward Welbourne2021-04-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Analysis of problems with the new test for qFuzzyIsNull() revealed that, where its version for double uses approximately 4500 * epsilon and for float used 84 * epsilon as threshold, the qfloat16 version's value was barely more than epsilon, with the result that the test had to use a different value than the threshold to pass. (Converting the threshold from float to qfloat16 and back made it bigger; in effect, the threshold value was not <= itself.) Furthermore, comparison with qFuzzyCompare() implied a value of 1/102.5 should be used, roughly 10 * epsilon, for consistency. When 1/102.5 is rounded to three significant digits (the precision we use in QTest::toString(), for example), to give 0.00976f as threshold, we get a value that, after conversion to qfloat16 and back to float, does give a result <= what we started with. So change qFuzzyIsNull() and its test to use this as qfloat16's threshold value. [ChangeLog][QtCore][QFloat16] The qfloat16 threshold value for qFuzzyIsNull() has changed from 1e-3 to 9.76e-3, almost a factor of ten increase, for consistency with qFuzzyCompare()'s tolerance. Values between these would previously have had qFuzzyIsNull(f) false despite qFuzzyCompre(f, 1+f) being true. Change-Id: I35816dce78da34a3e2339c8bc42d5bd03714a3f6 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add tests for qFuzzyIsNull() to tst_QNumeric and tst_QFloat16Edward Welbourne2021-04-291-1/+30
| | | | | | | | | | | | | They were missing. I also wanted to verify that it's true for sub-normal values. At the same time, relocate qfloat16's implementation of qFuzzyIsNull() to between those of qFuzzyCompare() and qIsNull(), since its apparent absence initially confused me. Change-Id: I9637c0070e754d16744c76fc9f846596257c6a63 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace QtTest headers with QTestDavid Skoland2020-12-221-1/+1
| | | | | | | | | | | Complete search and replace of QtTest and QtTest/QtTest with QTest, as QtTest includes the whole module. Replace all such instances with correct header includes. See Jira task for more discussion. Fixes: QTBUG-88831 Change-Id: I981cfae18a1cabcabcabee376016b086d9d01f44 Pick-to: 6.0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Round float->qfloat16 to evenAllan Sandfeld Jensen2020-09-061-2/+68
| | | | | | | | Calibrated to match F16C and ARM-FP16 hardware conversions. Change-Id: I3bdd4d3db3046fee4aeb24e4ce8b9bc9a06e0397 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add float->qfloat16 rounding and fix the testsAllan Sandfeld Jensen2020-07-311-32/+32
| | | | | | | | | | | | Our hardware optimized conversions of float to qfloat16 rounds to even where our table based conversion truncated to zero. The rounding is not in this patch exactly round to even like the hardware implementation but much closer. Change-Id: I4c5e72c15fef9079d3660680b2727ff7ba4e768a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Make qfloat16 helper functions consistent with float/double versionsAllan Sandfeld Jensen2020-07-281-1/+1
| | | | | | | | | | Infinite is only when the mantissa is 0, everything else is NaN. std::isnormal returns false on zero. Pick-to: 5.15 Change-Id: I897fc0dc3b8a9c557bb1922ea7ca8df501e91859 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add qfloat16::copySign() since we can't overload std::copysign()Edward Welbourne2019-11-061-1/+10
| | | | | Change-Id: Idfaf841b3eb3538f076ae4f0de2d7d029e1588fe Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Correct handling of -qfloat16(0)Edward Welbourne2019-10-031-1/+12
| | | | | | | | It is finite and normal; it classifies as a zero; and it should not be > qfloat16(0). Added tests to match. Change-Id: I7874fb54f622b4cdf28b0894050ad3e75cf5d77c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Reorganise the qfloat16 auto-testEdward Welbourne2019-10-031-84/+102
| | | | | | | | | | | | | | | | | | | | | | Its limits() test was rather large and had some overlap with an older qNan() test, that needed some clean-up (it combined qfloat16 values with double and float values in ways that caused qfloat16 to be promoted to another type, so we weren't testing qfloat16). Renamed the qNan() test to qNaN(), separated out the parts of it that actually tested infinity. Moved various parts of limits() to these and rationalised the result. Split out a properties() test from limits() for the properties of the qfloat16 type that are supplied by its numeric_limits. Split out a data-driven finite() test to cover some repeated code that was in limits() and extended it to test more values. Added more tests of isNormal(). Fixed my earlier UK-ish spelling of "optimise", in the process, and identify the processor rather than the virtualization as the context where the compiler errs. Change-Id: I8133da6fb7995ee20e5802c6357d611c8c0cba73 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.13' into devLiang Qi2019-06-141-2/+2
|\ | | | | | | | | | | | | | | | | | | Conflicts: qmake/generators/makefile.cpp qmake/generators/unix/unixmake2.cpp src/corelib/thread/qthread_unix.cpp tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp Change-Id: I1df0d4ba20685de7f9300bf07458c13376493408
| * Correct qfloat16's 1/inf == 0 testEdward Welbourne2019-05-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It should have been qfloat16(1)/qfloat16(infinity) in any case. Sadly, that behaves no better than qfloat16(1.f/qfloat16(infinity)), which was promoting the infinity back to float. So retain the check for over-optimization (but make the comment more accurate). This is a follow-up to d441f6bba7b2aaf1e11b95c1ad4c785e6939f6ba. Change-Id: Iec4afe4b04081b0ebfbf98058da606dc3ade07f4 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Merge remote-tracking branch 'origin/5.13' into devFriedemann Kleint2019-05-271-1/+3
|\| | | | | | | Change-Id: Ia279fc4a8226626041c772902a07b2f90f37b53b
| * Skip flaky qfloat16 1/inf == 0 test on QEMU/Arm64Edward Welbourne2019-05-151-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | It's not clear why this test fails - and only does so sometimes - but fail it does, so we ned to skip it to let development keep going. As it happens, the same platform over-optimizes various computations using qfloat16; which can at least be used to test for this platform, since it wrongly distinguishes two qfloat16 values that theory and all other platfomrs agree should coincide. Fixes: QTBUG-75812 Change-Id: Ie9463d7dc21bca679337b475d13417b9f42bbf9b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* | QtTestLib: handle float16 the same as double and floatEdward Welbourne2019-04-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In QCOMPARE, handle NaNs and infinities the way tests want them handled, rather than by strict IEEE rules. In particular, if a test expects NaN, this lets it treat that just like any other expected value, despite NaN != NaN as float16 values. Likewise, format infinities and NaNs specially in toString() so that they're reported consistently. Enable the qfloat16 tests that depend on this QCOMPARE() behavior. Refise the testlib selftest's float test to test qfloat16 the same way it tests float and double (and format the test the same way). This is a follow-up to 37f617c405a. Change-Id: I433256a09b1657e6725d68d07c5f80d805bf586a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Implement qFpClassify(qfloat16)Edward Welbourne2019-04-241-0/+19
| | | | | | | | | | | | | | | | | | This extends support for qfloat16 sufficiently for the things testlib needs in order to treat it as a first-class citizen. Extended tests for qfloat to check qFpClassify() on it. Change-Id: I906292afaf51cd9c94ba384ff5aaa855edd56da1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Implement std::numeric_limits<qfloat16>Edward Welbourne2019-04-241-0/+142
|/ | | | | | | | | | This shall make it more nearly a first-class numeric type; in particular, I need some of these for testlib's comparing and formatting of float16 to handle NaNs and infinities sensibly. Change-Id: Ic894dd0eb3e05653cd7645ab496463e7a884dff8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.10' into devLars Knoll2018-01-021-0/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: .qmake.conf sc/corelib/io/qfsfileengine_p.h src/corelib/io/qstorageinfo_unix.cpp src/platformsupport/eglconvenience/qeglpbuffer_p.h src/platformsupport/input/libinput/qlibinputkeyboard.cpp src/platformsupport/input/libinput/qlibinputpointer.cpp src/plugins/platforms/cocoa/qcocoamenu.mm src/plugins/platforms/ios/qiosscreen.h src/plugins/platforms/ios/qioswindow.h src/plugins/platforms/ios/quiview.mm src/printsupport/dialogs/qpagesetupdialog_unix_p.h src/printsupport/dialogs/qprintpreviewdialog.cpp src/printsupport/widgets/qcupsjobwidget_p.h src/widgets/widgets/qmenu.cpp tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp Change-Id: Iecb4883122efe97ef0ed850271e6c51bab568e9c
| * qfloat16: NaN is not infiniteThiago Macieira2017-12-271-0/+2
| | | | | | | | | | | | Change-Id: I39332e0a867442d58082fffd1502b7010424f0f8 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
* | Add functions for fast bulk conversion of qfloat16Allan Sandfeld Jensen2017-11-211-0/+38
|/ | | | | | | | | | | | | | | | Both ARM and x86 can convert fp16 much faster in bulk than one at a time. This also enables hardware accelerated conversion on x86, when F16C isn't unconditionally available at compile time. This code is implemented in C to ensure that there's no leakage of inline symbols from the .obj file that was compiled by Visual Studio with AVX support. Unfortunately, simd.prf uses $(CXX) instead of $(CC) for all its sources, which means the file gets interpreted as C++ by g++, clang++ and icpc. Those compilers at least don't leak any symbols. Done-with: Thiago Macieira <thiago.macieira@intel.com> Change-Id: I9d26d99e83392861fb09564e0e8e8d76cd8483b3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Eliminate ambiguous casts involving qfloat16Glen Mabey2017-05-071-2/+57
| | | | | | | | | | | | The operator double() and operator long double() members of qfloat16 are causing cast ambiguities. This removes them, leaving only operator float() which seems to be adequate. Also, additional arithmetic operator tests were added which without this removal fail to compile. Change-Id: Id52a101b318fd754969b3de13c1e528d0aac2387 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tests: Unify license to GPL-EXCEPTKai Koehne2017-04-031-18/+6
| | | | | | Change-Id: Ic718650a8a7bddd4ee28c5650a3f5baf70886e51 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io>
* New qfloat16 classGlen Mabey2017-01-311-0/+266
This constitutes a fairly complete submission of an entirely new floating point type which conforms to IEEE 754 as a 16-bit storage class. Conversion between qfloat16 and float is currently performed through a sequence of lookup tables. Global-level functions qRound(), qRound64(), qFuzzyCompare(), qFuzzyIsNull(), and qIsNull() each with a qfloat16 parameter have been included for completeness. [ChangeLog][QtCore] Added new qfloat16 class. Change-Id: Ia52eb27846965c14f8140c00faf5ba33c9443976 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>