From 8a9f064ede7177956c2180589fabf72a23bd67df Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 6 Jan 2021 09:12:40 +0200 Subject: [PATCH] use compiler built-ins for byte swapping for reference: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html https://clang.llvm.org/docs/LanguageExtensions.html Signed-off-by: Ivailo Monev --- src/core/global/qendian.h | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/core/global/qendian.h b/src/core/global/qendian.h index 5024859f3..af05b095a 100644 --- a/src/core/global/qendian.h +++ b/src/core/global/qendian.h @@ -36,10 +36,6 @@ #include -#ifdef __GLIBC__ -#include -#endif - QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -165,49 +161,18 @@ template <> inline qint16 qFromBigEndian(const uchar *src) */ template T qbswap(const T source); -#ifdef __GLIBC__ template <> inline quint64 qbswap(const quint64 source) { - return bswap_64(source); + return __builtin_bswap64(source); } template <> inline quint32 qbswap(const quint32 source) { - return bswap_32(source); + return __builtin_bswap32(source); } template <> inline quint16 qbswap(const quint16 source) { - return bswap_16(source); -} -#else -template <> inline quint64 qbswap(const quint64 source) -{ - return 0 - | ((source & Q_UINT64_C(0x00000000000000ff)) << 56) - | ((source & Q_UINT64_C(0x000000000000ff00)) << 40) - | ((source & Q_UINT64_C(0x0000000000ff0000)) << 24) - | ((source & Q_UINT64_C(0x00000000ff000000)) << 8) - | ((source & Q_UINT64_C(0x000000ff00000000)) >> 8) - | ((source & Q_UINT64_C(0x0000ff0000000000)) >> 24) - | ((source & Q_UINT64_C(0x00ff000000000000)) >> 40) - | ((source & Q_UINT64_C(0xff00000000000000)) >> 56); -} - -template <> inline quint32 qbswap(const quint32 source) -{ - return 0 - | ((source & 0x000000ff) << 24) - | ((source & 0x0000ff00) << 8) - | ((source & 0x00ff0000) >> 8) - | ((source & 0xff000000) >> 24); -} - -template <> inline quint16 qbswap(const quint16 source) -{ - return quint16( 0 - | ((source & 0x00ff) << 8) - | ((source & 0xff00) >> 8) ); + return __builtin_bswap16(source); } -#endif // __GLIBC__ // signed specializations template <> inline qint64 qbswap(const qint64 source) -- 2.11.0