From befda1accab417ce5f55cb11816e6ded51af55e3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 11 Jan 2023 18:34:13 -0800 Subject: [PATCH] QTypes: add q{u,}int128 as a first-class, integer type This is supported on all 64-bit platforms by Clang and GCC and will be used by QUuid, with support in QDataStream and partial support in QTextStream. CBOR also has a reserved "additional information" field for 128-bit quantities, but it's not allowable right now. This conflicts with the quint128 type in QtBluetooth, which was not an integral type. It has been removed in 1e903be81f43da4e31385bb7866bb4d3f07e5eba. Change-Id: Id8e48e8f498c4a029619fffd172893c81aed3481 Reviewed-by: Volker Hilsheimer --- src/corelib/global/qendian.h | 17 +++++++++++++++++ src/corelib/global/qtypes.h | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h index 9cd0044cbc6..29d632ef04d 100644 --- a/src/corelib/global/qendian.h +++ b/src/corelib/global/qendian.h @@ -105,6 +105,23 @@ inline constexpr T qbswap(T source) return T(qbswap_helper(typename QIntegerForSizeof::Unsigned(source))); } +#ifdef __SIZEOF_INT128__ +// extra definitions for q(u)int128, in case std::is_integral_v<~~> == false +inline constexpr quint128 qbswap(quint128 source) +{ + quint128 result = {}; + result = qbswap_helper(quint64(source)); + result <<= 64; + result |= qbswap_helper(quint64(source >> 64)); + return result; +} + +inline constexpr quint128 qbswap(qint128 source) +{ + return qint128(qbswap(quint128(source))); +} +#endif + // floating specializations template Float qbswapFloatHelper(Float source) diff --git a/src/corelib/global/qtypes.h b/src/corelib/global/qtypes.h index d08a919c136..412ab3af623 100644 --- a/src/corelib/global/qtypes.h +++ b/src/corelib/global/qtypes.h @@ -58,6 +58,11 @@ typedef unsigned long long quint64; /* 64 bit unsigned */ typedef qint64 qlonglong; typedef quint64 qulonglong; +#if defined(__SIZEOF_INT128__) +__extension__ typedef __int128_t qint128; +__extension__ typedef __uint128_t quint128; +#endif + #ifndef __cplusplus // In C++ mode, we define below using QIntegerForSize template static_assert(sizeof(ptrdiff_t) == sizeof(size_t), "Weird ptrdiff_t and size_t definitions"); @@ -103,7 +108,7 @@ template <> struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qin template <> struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; }; template <> struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; }; #if defined(Q_CC_GNU) && defined(__SIZEOF_INT128__) -template <> struct QIntegerForSize<16> { __extension__ typedef unsigned __int128 Unsigned; __extension__ typedef __int128 Signed; }; +template <> struct QIntegerForSize<16> { typedef quint128 Unsigned; typedef qint128 Signed; }; #endif template struct QIntegerForSizeof: QIntegerForSize { }; typedef QIntegerForSize::Signed qregisterint;