[vlc-devel] [PATCH 3.0 16/16] contrib: qt: Backport more patches to fix building with even newer versions of Clang

Steve Lhomme robux4 at ycbcr.xyz
Sat Jun 20 08:27:28 CEST 2020


I think we'll update the Qt version at some point to a Qt5 LTS version 
but that will do for now.

OK for the whole set. I verified it passed by cherry-pick.sh test 
(correct hash and marked Signed-off)

For now x264 is disabled for UWP/WinRT builds but I'll check if it can 
be enabled now.

Note that I still have pending gnutls backports coming to fix llvm-mingw 
UWP builds in 3.0.

On 2020-06-19 23:27, Martin Storsjö wrote:
> The master branch has moved on to newer Qt versions that don't
> need these.
> ---
>   ...xx-macros-for-post-C-11-feature-test.patch | 159 +++++++
>   ...railing-ZeroBits-Use-__builtin_clzs-.patch |  54 +++
>   ...12-Remove-_bit_scan_-forward-reverse.patch | 418 ++++++++++++++++++
>   ...mpilation-with-trunk-clang-for-mingw.patch |  40 ++
>   contrib/src/qt/rules.mak                      |   4 +
>   5 files changed, 675 insertions(+)
>   create mode 100644 contrib/src/qt/0010-Add-the-QT_HAS_xxx-macros-for-post-C-11-feature-test.patch
>   create mode 100644 contrib/src/qt/0011-qCount-Leading-Trailing-ZeroBits-Use-__builtin_clzs-.patch
>   create mode 100644 contrib/src/qt/0012-Remove-_bit_scan_-forward-reverse.patch
>   create mode 100644 contrib/src/qt/0013-qsimd-Fix-compilation-with-trunk-clang-for-mingw.patch
> 
> diff --git a/contrib/src/qt/0010-Add-the-QT_HAS_xxx-macros-for-post-C-11-feature-test.patch b/contrib/src/qt/0010-Add-the-QT_HAS_xxx-macros-for-post-C-11-feature-test.patch
> new file mode 100644
> index 0000000000..12d0717d79
> --- /dev/null
> +++ b/contrib/src/qt/0010-Add-the-QT_HAS_xxx-macros-for-post-C-11-feature-test.patch
> @@ -0,0 +1,159 @@
> +From 35a0fcb2f7934189701a4a328d3d2896bda75d22 Mon Sep 17 00:00:00 2001
> +From: Thiago Macieira <thiago.macieira at intel.com>
> +Date: Wed, 1 Jul 2015 14:38:22 -0700
> +Subject: [PATCH 10/13] Add the QT_HAS_xxx macros for post-C++11 feature
> + testing
> +
> +And for compiler extensions. QT_HAS_BUILTIN and QT_HAS_ATTRIBUTE will
> +come in handy.
> +
> +Change-Id: I255870833a024a36adf6ffff13ecf06624bfc1ef
> +Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart at woboq.com>
> +Backport-Of: 6f298be07681f4038ddd5694d259ef64a574ac6f (v5.7)
> +---
> + src/corelib/global/qcompilerdetection.h | 31 +++++++++++++++++++++++++
> + src/corelib/global/qendian.h            |  2 --
> + src/corelib/global/qlogging.cpp         |  8 ++-----
> + src/corelib/global/qnumeric_p.h         | 16 +++++--------
> + 4 files changed, 39 insertions(+), 18 deletions(-)
> +
> +diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h
> +index 038ad03cb0..60c11003ba 100644
> +--- a/src/corelib/global/qcompilerdetection.h
> ++++ b/src/corelib/global/qcompilerdetection.h
> +@@ -1164,6 +1164,37 @@
> + #  define QT_HAS_FEATURE(x)             0
> + #endif
> +
> ++/*
> ++ * SG10's SD-6 feature detection and some useful extensions from Clang and GCC
> ++ * https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations
> ++ * http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros
> ++ */
> ++#ifdef __has_builtin
> ++#  define QT_HAS_BUILTIN(x)             __has_builtin(x)
> ++#else
> ++#  define QT_HAS_BUILTIN(x)             0
> ++#endif
> ++#ifdef __has_attribute
> ++#  define QT_HAS_ATTRIBUTE(x)           __has_attribute(x)
> ++#else
> ++#  define QT_HAS_ATTRIBUTE(x)           0
> ++#endif
> ++#ifdef __has_cpp_attribute
> ++#  define QT_HAS_CPP_ATTRIBUTE(x)       __has_cpp_attribute(x)
> ++#else
> ++#  define QT_HAS_CPP_ATTRIBUTE(x)       0
> ++#endif
> ++#ifdef __has_include
> ++#  define QT_HAS_INCLUDE(x)             __has_include(x)
> ++#else
> ++#  define QT_HAS_INCLUDE(x)             0
> ++#endif
> ++#ifdef __has_include_next
> ++#  define QT_HAS_INCLUDE_NEXT(x)        __has_include_next(x)
> ++#else
> ++#  define QT_HAS_INCLUDE_NEXT(x)        0
> ++#endif
> ++
> + /*
> +  * Warning/diagnostic handling
> +  */
> +diff --git a/src/corelib/global/qendian.h b/src/corelib/global/qendian.h
> +index 23dda270e3..a678d567ae 100644
> +--- a/src/corelib/global/qendian.h
> ++++ b/src/corelib/global/qendian.h
> +@@ -164,8 +164,6 @@ template <> inline quint16 qbswap<quint16>(quint16 source)
> + }
> + #endif // GCC & Clang intrinsics
> +
> +-#undef QT_HAS_BUILTIN
> +-
> + // signed specializations
> + template <> inline qint64 qbswap<qint64>(qint64 source)
> + {
> +diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
> +index 6b95449b3d..7c7adbec99 100644
> +--- a/src/corelib/global/qlogging.cpp
> ++++ b/src/corelib/global/qlogging.cpp
> +@@ -75,17 +75,13 @@
> + # include "private/qcore_unix_p.h"
> + #endif
> +
> +-#ifndef __has_include
> +-#  define __has_include(x) 0
> +-#endif
> +-
> + #ifndef QT_BOOTSTRAPPED
> + #if !defined QT_NO_REGULAREXPRESSION
> + #  ifdef __UCLIBC__
> + #    if __UCLIBC_HAS_BACKTRACE__
> + #      define QLOGGING_HAVE_BACKTRACE
> + #    endif
> +-#  elif (defined(__GLIBC__) && defined(__GLIBCXX__)) || (__has_include(<cxxabi.h>) && __has_include(<execinfo.h>))
> ++#  elif (defined(__GLIBC__) && defined(__GLIBCXX__)) || (QT_HAS_INCLUDE(<cxxabi.h>) && QT_HAS_INCLUDE(<execinfo.h>))
> + #    define QLOGGING_HAVE_BACKTRACE
> + #  endif
> + #endif
> +@@ -94,7 +90,7 @@
> + extern char *__progname;
> + #endif
> +
> +-#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_include(<sys/syscall.h>))
> ++#if defined(Q_OS_LINUX) && (defined(__GLIBC__) || QT_HAS_INCLUDE(<sys/syscall.h>))
> + #  include <sys/syscall.h>
> +
> + # if defined(Q_OS_ANDROID) && !defined(SYS_gettid)
> +diff --git a/src/corelib/global/qnumeric_p.h b/src/corelib/global/qnumeric_p.h
> +index b18d521d05..c29ec0ea7b 100644
> +--- a/src/corelib/global/qnumeric_p.h
> ++++ b/src/corelib/global/qnumeric_p.h
> +@@ -56,10 +56,6 @@
> + #  include <immintrin.h>    // for _addcarry_u<nn>
> + #endif
> +
> +-#ifndef __has_builtin
> +-#  define __has_builtin(x)  0
> +-#endif
> +-
> + QT_BEGIN_NAMESPACE
> +
> + #if !defined(Q_CC_MIPS)
> +@@ -230,28 +226,28 @@ mul_overflow(T v1, T v2, T *r)
> + #endif
> +
> + // GCC 5 and Clang have builtins to detect overflows
> +-#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || __has_builtin(__builtin_uadd_overflow)
> ++#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || QT_HAS_BUILTIN(__builtin_uadd_overflow)
> + template <> inline bool add_overflow(unsigned v1, unsigned v2, unsigned *r)
> + { return __builtin_uadd_overflow(v1, v2, r); }
> + #endif
> +-#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || __has_builtin(__builtin_uaddl_overflow)
> ++#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || QT_HAS_BUILTIN(__builtin_uaddl_overflow)
> + template <> inline bool add_overflow(unsigned long v1, unsigned long v2, unsigned long *r)
> + { return __builtin_uaddl_overflow(v1, v2, r); }
> + #endif
> +-#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || __has_builtin(__builtin_uaddll_overflow)
> ++#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || QT_HAS_BUILTIN(__builtin_uaddll_overflow)
> + template <> inline bool add_overflow(unsigned long long v1, unsigned long long v2, unsigned long long *r)
> + { return __builtin_uaddll_overflow(v1, v2, r); }
> + #endif
> +
> +-#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || __has_builtin(__builtin_umul_overflow)
> ++#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || QT_HAS_BUILTIN(__builtin_umul_overflow)
> + template <> inline bool mul_overflow(unsigned v1, unsigned v2, unsigned *r)
> + { return __builtin_umul_overflow(v1, v2, r); }
> + #endif
> +-#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || __has_builtin(__builtin_umull_overflow)
> ++#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || QT_HAS_BUILTIN(__builtin_umull_overflow)
> + template <> inline bool mul_overflow(unsigned long v1, unsigned long v2, unsigned long *r)
> + { return __builtin_umull_overflow(v1, v2, r); }
> + #endif
> +-#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || __has_builtin(__builtin_umulll_overflow)
> ++#if (defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 500) || QT_HAS_BUILTIN(__builtin_umulll_overflow)
> + template <> inline bool mul_overflow(unsigned long long v1, unsigned long long v2, unsigned long long *r)
> + { return __builtin_umulll_overflow(v1, v2, r); }
> + #  define HAVE_MUL64_OVERFLOW
> +--
> +2.21.1 (Apple Git-122.3)
> +
> diff --git a/contrib/src/qt/0011-qCount-Leading-Trailing-ZeroBits-Use-__builtin_clzs-.patch b/contrib/src/qt/0011-qCount-Leading-Trailing-ZeroBits-Use-__builtin_clzs-.patch
> new file mode 100644
> index 0000000000..8ef4215d5a
> --- /dev/null
> +++ b/contrib/src/qt/0011-qCount-Leading-Trailing-ZeroBits-Use-__builtin_clzs-.patch
> @@ -0,0 +1,54 @@
> +From 88c0c1b2b5b5fb780afbe4a0b82adfe87c1a45a4 Mon Sep 17 00:00:00 2001
> +From: Thiago Macieira <thiago.macieira at intel.com>
> +Date: Thu, 3 Dec 2015 17:37:02 -0800
> +Subject: [PATCH 11/13] qCount{Leading,Trailing}ZeroBits: Use __builtin_clzs
> + for 16-bit
> +
> +If possible.
> +
> +The BSF/BSR/TZCNT/LZCNT Intel instruction does not exist for 8-bit. And
> +it's a good idea to use the 32-bit instruction instead of the 16-bit one
> +for that case, to avoid the Length Changing Prefix (LCP).
> +
> +GCC doesn't allow us to use __builtin_cl[tz]s unless BMI is active,
> +while ICC generates the same code either way (Clang understands
> +__has_builtin).
> +
> +Change-Id: I8de47ed6c7be4847b99bffff141c91603c7024dc
> +Reviewed-by: Allan Sandfeld Jensen <allan.jensen at theqtcompany.com>
> +Backport-Of: f5f47987ce369aa3f7553e6c0da509461a1ddf1a (v5.7)
> +---
> + src/corelib/tools/qalgorithms.h | 8 ++++++++
> + 1 file changed, 8 insertions(+)
> +
> +diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
> +index 503f98feee..f066e5c28a 100644
> +--- a/src/corelib/tools/qalgorithms.h
> ++++ b/src/corelib/tools/qalgorithms.h
> +@@ -653,7 +653,11 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) Q_DECL_NOT
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) Q_DECL_NOTHROW
> + {
> + #if defined(Q_CC_GNU)
> ++#  if QT_HAS_BUILTIN(__builtin_ctzs) || defined(__BMI__)
> ++    return v ? __builtin_ctzs(v) : 16U;
> ++#  else
> +     return v ? __builtin_ctz(v) : 16U;
> ++#  endif
> + #else
> +     unsigned int c = 16; // c will be the number of zero bits on the right
> +     v &= -signed(v);
> +@@ -712,7 +716,11 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTH
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOTHROW
> + {
> + #if defined(Q_CC_GNU)
> ++#  if QT_HAS_BUILTIN(__builtin_clzs) || defined(__BMI__)
> ++    return v ? __builtin_clzs(v) : 16U;
> ++#  else
> +     return v ? __builtin_clz(v)-16U : 16U;
> ++#  endif
> + #else
> +     v = v | (v >> 1);
> +     v = v | (v >> 2);
> +--
> +2.21.1 (Apple Git-122.3)
> +
> diff --git a/contrib/src/qt/0012-Remove-_bit_scan_-forward-reverse.patch b/contrib/src/qt/0012-Remove-_bit_scan_-forward-reverse.patch
> new file mode 100644
> index 0000000000..2c067eeba8
> --- /dev/null
> +++ b/contrib/src/qt/0012-Remove-_bit_scan_-forward-reverse.patch
> @@ -0,0 +1,418 @@
> +From 7f59c885535a7ba0c6271319759c3a853aedd55c Mon Sep 17 00:00:00 2001
> +From: Erik Verbruggen <erik.verbruggen at theqtcompany.com>
> +Date: Thu, 3 Dec 2015 12:50:44 +0100
> +Subject: [PATCH 12/13] Remove _bit_scan_{forward,reverse}
> +
> +Use qCountTrailingZeroBits and qCountLeadingZeroBits from qalgorithms.h
> +instead. Also extended these versions for MSVC. The _bit_scan_* versions
> +stem from a time before the glorious days of qalgorithms.h. A big
> +advantage is that these functions can be used on all platforms.
> +
> +Change-Id: I5a1b886371520310a7fe16e617635ea335046beb
> +Reviewed-by: Simon Hausmann <simon.hausmann at qt.io>
> +Backport-Of: e70324f8dd1f191556599cf60100dd0ad0b16708 (v5.8)
> +---
> + src/corelib/codecs/qutfcodec.cpp |  16 +++-
> + src/corelib/kernel/qmath.h       |  22 ++---
> + src/corelib/tools/qalgorithms.h  | 139 +++++++++++++++++++++++++------
> + src/corelib/tools/qsimd_p.h      |  43 ----------
> + src/corelib/tools/qstring.cpp    |   8 +-
> + 5 files changed, 144 insertions(+), 84 deletions(-)
> +
> +diff --git a/src/corelib/codecs/qutfcodec.cpp b/src/corelib/codecs/qutfcodec.cpp
> +index 476990fb7a..f82d999501 100644
> +--- a/src/corelib/codecs/qutfcodec.cpp
> ++++ b/src/corelib/codecs/qutfcodec.cpp
> +@@ -47,6 +47,16 @@ enum { Endian = 0, Data = 1 };
> + static const uchar utf8bom[] = { 0xef, 0xbb, 0xbf };
> +
> + #if defined(__SSE2__) && defined(QT_COMPILER_SUPPORTS_SSE2)
> ++static Q_ALWAYS_INLINE uint qBitScanReverse(unsigned v) Q_DECL_NOTHROW
> ++{
> ++    uint result = qCountLeadingZeroBits(v);
> ++    // Now Invert the result: clz will count *down* from the msb to the lsb, so the msb index is 31
> ++    // and the lsb index is 0. The result for _bit_scan_reverse is expected to be the index when
> ++    // counting up: msb index is 0 (because it starts there), and the lsb index is 31.
> ++    result ^= sizeof(unsigned) * 8 - 1;
> ++    return result;
> ++}
> ++
> + static inline bool simdEncodeAscii(uchar *&dst, const ushort *&nextAscii, const ushort *&src, const ushort *end)
> + {
> +     // do sixteen characters at a time
> +@@ -75,9 +85,9 @@ static inline bool simdEncodeAscii(uchar *&dst, const ushort *&nextAscii, const
> +             // find the next probable ASCII character
> +             // we don't want to load 32 bytes again in this loop if we know there are non-ASCII
> +             // characters still coming
> +-            nextAscii = src + _bit_scan_reverse(n) + 1;
> ++            nextAscii = src + qBitScanReverse(n) + 1;
> +
> +-            n = _bit_scan_forward(n);
> ++            n = qCountTrailingZeroBits(n);
> +             dst += n;
> +             src += n;
> +             return false;
> +@@ -126,7 +136,7 @@ static inline bool simdDecodeAscii(ushort *&dst, const uchar *&nextAscii, const
> +         // find the next probable ASCII character
> +         // we don't want to load 16 bytes again in this loop if we know there are non-ASCII
> +         // characters still coming
> +-        n = _bit_scan_reverse(n);
> ++        n = qBitScanReverse(n);
> +         nextAscii = src + (n / BitSpacing) + 1;
> +         return false;
> +
> +diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h
> +index e60561c05f..d52895175f 100644
> +--- a/src/corelib/kernel/qmath.h
> ++++ b/src/corelib/kernel/qmath.h
> +@@ -39,6 +39,7 @@
> + #endif
> +
> + #include <QtCore/qglobal.h>
> ++#include <QtCore/qalgorithms.h>
> +
> + #ifndef _USE_MATH_DEFINES
> + #  define _USE_MATH_DEFINES
> +@@ -235,20 +236,12 @@ Q_DECL_CONSTEXPR inline double qRadiansToDegrees(double radians)
> + }
> +
> +
> +-#if defined(Q_CC_GNU)
> +-// clz instructions exist in at least MIPS, ARM, PowerPC and X86, so we can assume this builtin always maps to an efficient instruction.
> ++#if defined(QT_HAS_BUILTIN_CLZ)
> + inline quint32 qNextPowerOfTwo(quint32 v)
> + {
> +     if (v == 0)
> +         return 1;
> +-    return 2U << (31 ^ __builtin_clz(v));
> +-}
> +-
> +-inline quint64 qNextPowerOfTwo(quint64 v)
> +-{
> +-    if (v == 0)
> +-        return 1;
> +-    return Q_UINT64_C(2) << (63 ^ __builtin_clzll(v));
> ++    return 2U << (31 ^ QAlgorithmsPrivate::qt_builtin_clz(v));
> + }
> + #else
> + inline quint32 qNextPowerOfTwo(quint32 v)
> +@@ -261,7 +254,16 @@ inline quint32 qNextPowerOfTwo(quint32 v)
> +     ++v;
> +     return v;
> + }
> ++#endif
> +
> ++#if defined(QT_HAS_BUILTIN_CLZLL)
> ++inline quint64 qNextPowerOfTwo(quint64 v)
> ++{
> ++    if (v == 0)
> ++        return 1;
> ++    return Q_UINT64_C(2) << (63 ^ QAlgorithmsPrivate::qt_builtin_clzll(v));
> ++}
> ++#else
> + inline quint64 qNextPowerOfTwo(quint64 v)
> + {
> +     v |= v >> 1;
> +diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
> +index f066e5c28a..66b30e81a5 100644
> +--- a/src/corelib/tools/qalgorithms.h
> ++++ b/src/corelib/tools/qalgorithms.h
> +@@ -549,6 +549,105 @@ QT_DEPRECATED_X("Use std::binary_search") Q_OUTOFLINE_TEMPLATE RandomAccessItera
> +
> + #endif // QT_DEPRECATED_SINCE(5, 2)
> +
> ++// Clang had a bug where __builtin_ctz/clz is not marked as constexpr.
> ++#if defined Q_CC_CLANG && defined __apple_build_version__ &&  __clang_major__ < 7
> ++#  undef QT_HAS_CONSTEXPR_BUILTIN_CTZ_CLZ
> ++#else
> ++#  define QT_HAS_CONSTEXPR_BUILTIN_CTZ_CLZ
> ++#endif
> ++
> ++#if defined QT_HAS_CONSTEXPR_BUILTIN_CTZ_CLZ
> ++#if defined(Q_CC_GNU)
> ++#  define QT_HAS_BUILTIN_CTZS
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW
> ++{
> ++#  if QT_HAS_BUILTIN(__builtin_ctzs) || defined(__BMI__)
> ++    return __builtin_ctzs(v);
> ++#  else
> ++    return __builtin_ctz(v);
> ++#  endif
> ++}
> ++#define QT_HAS_BUILTIN_CLZS
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW
> ++{
> ++#  if QT_HAS_BUILTIN(__builtin_clzs) || defined(__BMI__)
> ++    return __builtin_clzs(v);
> ++#  else
> ++    return __builtin_clz(v) - 16U;
> ++#  endif
> ++}
> ++#define QT_HAS_BUILTIN_CTZ
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctz(quint32 v) Q_DECL_NOTHROW
> ++{
> ++    return __builtin_ctz(v);
> ++}
> ++#define QT_HAS_BUILTIN_CLZ
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clz(quint32 v) Q_DECL_NOTHROW
> ++{
> ++    return __builtin_clz(v);
> ++}
> ++#define QT_HAS_BUILTIN_CTZLL
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzll(quint64 v) Q_DECL_NOTHROW
> ++{
> ++    return __builtin_ctzll(v);
> ++}
> ++#define QT_HAS_BUILTIN_CLZLL
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzll(quint64 v) Q_DECL_NOTHROW
> ++{
> ++    return __builtin_clzll(v);
> ++}
> ++#elif defined(Q_CC_MSVC) && !defined(Q_OS_WINCE)
> ++#define QT_HAS_BUILTIN_CTZ
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctz(quint32 val)
> ++{
> ++    unsigned long result;
> ++    _BitScanForward(&result, val);
> ++    return result;
> ++}
> ++#define QT_HAS_BUILTIN_CLZ
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val)
> ++{
> ++    unsigned long result;
> ++    _BitScanReverse(&result, val);
> ++    // Now Invert the result: clz will count *down* from the msb to the lsb, so the msb index is 31
> ++    // and the lsb index is 0. The result for the index when counting up: msb index is 0 (because it
> ++    // starts there), and the lsb index is 31.
> ++    result ^= sizeof(quint32) * 8 - 1;
> ++    return result;
> ++}
> ++#if Q_PROCESSOR_WORDSIZE == 8
> ++// These are only defined for 64bit builds.
> ++#define QT_HAS_BUILTIN_CTZLL
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val)
> ++{
> ++    unsigned long result;
> ++    _BitScanForward64(&result, val);
> ++    return result;
> ++}
> ++// MSVC calls it _BitScanReverse and returns the carry flag, which we don't need
> ++#define QT_HAS_BUILTIN_CLZLL
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val)
> ++{
> ++    unsigned long result;
> ++    _BitScanReverse64(&result, val);
> ++    // see qt_builtin_clz
> ++    result ^= sizeof(quint64) * 8 - 1;
> ++    return result;
> ++}
> ++#endif
> ++#  define QT_HAS_BUILTIN_CTZS
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW
> ++{
> ++    return qt_builtin_ctz(v);
> ++}
> ++#define QT_HAS_BUILTIN_CLZS
> ++Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW
> ++{
> ++    return qt_builtin_clz(v) - 16U;
> ++}
> ++#endif
> ++#endif // QT_HAS_CONSTEXPR_BUILTIN_CTZ_CLZ
> ++
> + } //namespace QAlgorithmsPrivate
> +
> +
> +@@ -619,8 +718,8 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigne
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-    return v ? __builtin_ctz(v) : 32U;
> ++#if defined(QT_HAS_BUILTIN_CTZ)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_ctz(v) : 32U;
> + #else
> +     // see http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightParallel
> +     unsigned int c = 32; // c will be the number of zero bits on the right
> +@@ -637,8 +736,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NO
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-    return v ? __builtin_ctz(v) : 8U;
> ++#if defined(QT_HAS_BUILTIN_CTZ)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_ctz(v) : 8U;
> + #else
> +     unsigned int c = 8; // c will be the number of zero bits on the right
> +     v &= -signed(v);
> +@@ -652,12 +751,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint8 v) Q_DECL_NOT
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-#  if QT_HAS_BUILTIN(__builtin_ctzs) || defined(__BMI__)
> +-    return v ? __builtin_ctzs(v) : 16U;
> +-#  else
> +-    return v ? __builtin_ctz(v) : 16U;
> +-#  endif
> ++#if defined(QT_HAS_BUILTIN_CTZS)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_ctzs(v) : 16U;
> + #else
> +     unsigned int c = 16; // c will be the number of zero bits on the right
> +     v &= -signed(v);
> +@@ -672,8 +767,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint16 v) Q_DECL_NO
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint64 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-    return v ? __builtin_ctzll(v) : 64;
> ++#if defined(QT_HAS_BUILTIN_CTZLL)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_ctzll(v) : 64;
> + #else
> +     quint32 x = static_cast<quint32>(v);
> +     return x ? qCountTrailingZeroBits(x)
> +@@ -688,8 +783,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(unsigned long v) Q_D
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-    return v ? __builtin_clz(v) : 32U;
> ++#if defined(QT_HAS_BUILTIN_CLZ)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_clz(v) : 32U;
> + #else
> +     // Hacker's Delight, 2nd ed. Fig 5-16, p. 102
> +     v = v | (v >> 1);
> +@@ -703,8 +798,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint32 v) Q_DECL_NOT
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-    return v ? __builtin_clz(v)-24U : 8U;
> ++#if defined(QT_HAS_BUILTIN_CLZ)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_clz(v)-24U : 8U;
> + #else
> +     v = v | (v >> 1);
> +     v = v | (v >> 2);
> +@@ -715,12 +810,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint8 v) Q_DECL_NOTH
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-#  if QT_HAS_BUILTIN(__builtin_clzs) || defined(__BMI__)
> +-    return v ? __builtin_clzs(v) : 16U;
> +-#  else
> +-    return v ? __builtin_clz(v)-16U : 16U;
> +-#  endif
> ++#if defined(QT_HAS_BUILTIN_CLZS)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_clzs(v) : 16U;
> + #else
> +     v = v | (v >> 1);
> +     v = v | (v >> 2);
> +@@ -732,8 +823,8 @@ Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint16 v) Q_DECL_NOT
> +
> + Q_DECL_RELAXED_CONSTEXPR inline uint qCountLeadingZeroBits(quint64 v) Q_DECL_NOTHROW
> + {
> +-#if defined(Q_CC_GNU)
> +-    return v ? __builtin_clzll(v) : 64U;
> ++#if defined(QT_HAS_BUILTIN_CLZLL)
> ++    return v ? QAlgorithmsPrivate::qt_builtin_clzll(v) : 64U;
> + #else
> +     v = v | (v >> 1);
> +     v = v | (v >> 2);
> +diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h
> +index d689654b29..ff1fe34eb9 100644
> +--- a/src/corelib/tools/qsimd_p.h
> ++++ b/src/corelib/tools/qsimd_p.h
> +@@ -430,49 +430,6 @@ static inline quint64 qCpuFeatures()
> + #define qCpuHasFeature(feature)     ((qCompilerCpuFeatures & (Q_UINT64_C(1) << CpuFeature ## feature)) \
> +                                      || (qCpuFeatures() & (Q_UINT64_C(1) << CpuFeature ## feature)))
> +
> +-#ifdef Q_PROCESSOR_X86
> +-// Bit scan functions for x86
> +-#  if defined(Q_CC_MSVC)
> +-#    if defined _WIN32_WCE && _WIN32_WCE < 0x800
> +-extern "C" unsigned char _BitScanForward(unsigned long* Index, unsigned long Mask);
> +-extern "C" unsigned char _BitScanReverse(unsigned long* Index, unsigned long Mask);
> +-#       pragma intrinsic(_BitScanForward)
> +-#       pragma intrinsic(_BitScanReverse)
> +-#    endif
> +-// MSVC calls it _BitScanReverse and returns the carry flag, which we don't need
> +-static __forceinline unsigned long _bit_scan_reverse(uint val)
> +-{
> +-    unsigned long result;
> +-    _BitScanReverse(&result, val);
> +-    return result;
> +-}
> +-static __forceinline unsigned long _bit_scan_forward(uint val)
> +-{
> +-    unsigned long result;
> +-    _BitScanForward(&result, val);
> +-    return result;
> +-}
> +-#  elif (defined(Q_CC_CLANG) || (defined(Q_CC_GNU) && Q_CC_GNU < 405)) \
> +-    && !defined(Q_CC_INTEL)
> +-// Clang is missing the intrinsic for _bit_scan_reverse
> +-// GCC only added it in version 4.5
> +-static inline __attribute__((always_inline))
> +-unsigned _bit_scan_reverse(unsigned val)
> +-{
> +-    unsigned result;
> +-    asm("bsr %1, %0" : "=r" (result) : "r" (val));
> +-    return result;
> +-}
> +-static inline __attribute__((always_inline))
> +-unsigned _bit_scan_forward(unsigned val)
> +-{
> +-    unsigned result;
> +-    asm("bsf %1, %0" : "=r" (result) : "r" (val));
> +-    return result;
> +-}
> +-#  endif
> +-#endif // Q_PROCESSOR_X86
> +-
> + #define ALIGNMENT_PROLOGUE_16BYTES(ptr, i, length) \
> +     for (; i < static_cast<int>(qMin(static_cast<quintptr>(length), ((4 - ((reinterpret_cast<quintptr>(ptr) >> 2) & 0x3)) & 0x3))); ++i)
> +
> +diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
> +index 645d213d82..85f70a3e34 100644
> +--- a/src/corelib/tools/qstring.cpp
> ++++ b/src/corelib/tools/qstring.cpp
> +@@ -464,7 +464,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l)
> +         uint mask = ~_mm_movemask_epi8(result);
> +         if (ushort(mask)) {
> +             // found a different byte
> +-            uint idx = uint(_bit_scan_forward(mask));
> ++            uint idx = qCountTrailingZeroBits(mask);
> +             return reinterpret_cast<const QChar *>(ptr + idx)->unicode()
> +                     - reinterpret_cast<const QChar *>(ptr + distance + idx)->unicode();
> +         }
> +@@ -565,7 +565,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l)
> + #  endif
> +         if (mask) {
> +             // found a different character
> +-            uint idx = uint(_bit_scan_forward(mask));
> ++            uint idx = qCountTrailingZeroBits(mask);
> +             return uc[offset + idx / 2] - c[offset + idx / 2];
> +         }
> +     }
> +@@ -583,7 +583,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l)
> +         uint mask = ~_mm_movemask_epi8(result);
> +         if (ushort(mask)) {
> +             // found a different character
> +-            uint idx = uint(_bit_scan_forward(mask));
> ++            uint idx = qCountTrailingZeroBits(mask);
> +             return uc[offset + idx / 2] - c[offset + idx / 2];
> +         }
> +
> +@@ -678,7 +678,7 @@ static int findChar(const QChar *str, int len, QChar ch, int from,
> +                     // found a match
> +                     // same as: return n - s + _bit_scan_forward(mask) / 2
> +                     return (reinterpret_cast<const char *>(n) - reinterpret_cast<const char *>(s)
> +-                            + _bit_scan_forward(mask)) >> 1;
> ++                            + qCountTrailingZeroBits(mask)) >> 1;
> +                 }
> +             }
> +
> +--
> +2.21.1 (Apple Git-122.3)
> +
> diff --git a/contrib/src/qt/0013-qsimd-Fix-compilation-with-trunk-clang-for-mingw.patch b/contrib/src/qt/0013-qsimd-Fix-compilation-with-trunk-clang-for-mingw.patch
> new file mode 100644
> index 0000000000..ea59dbf474
> --- /dev/null
> +++ b/contrib/src/qt/0013-qsimd-Fix-compilation-with-trunk-clang-for-mingw.patch
> @@ -0,0 +1,40 @@
> +From 4d7a9efed1a3e65b1ec0232140a707fdf2458493 Mon Sep 17 00:00:00 2001
> +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
> +Date: Fri, 18 Jan 2019 09:31:10 +0200
> +Subject: [PATCH 13/13] qsimd: Fix compilation with trunk clang for mingw
> +
> +Current tip-of-tree clang (after Clang 8 was branched) added an
> +intrinsic function __builtin_ia32_xgetbv, and added the following
> +define that provides _xgetbv:
> +    #define _xgetbv(A) __builtin_ia32_xgetbv((long long)(A))
> +
> +This fallback declaration of the _xgetbv function only is used
> +in case the Q_OS_WIN branch of the #if/#elif below is used, if
> +the #if (defined(Q_CC_GNU) && !defined(Q_CC_EMSCRIPTEN)) ||
> +defined(Q_CC_GHS) wasn't taken. I left out the
> +!defined(Q_CC_EMSCRIPTEN) part as I believe Q_OS_WIN and
> +Q_CC_EMSCRIPTEN are mutually exclusive.
> +
> +Change-Id: I257fc4283ff9f0845df51ab764cf58acdf285c66
> +Reviewed-by: Thiago Macieira <thiago.macieira at intel.com>
> +Backport-Of: 9818af7d436f7aa1bf5c635041cc5d08fec599b5 (v5.12.2)
> +---
> + src/corelib/tools/qsimd.cpp | 2 +-
> + 1 file changed, 1 insertion(+), 1 deletion(-)
> +
> +diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp
> +index 334e37b674..4316496ae2 100644
> +--- a/src/corelib/tools/qsimd.cpp
> ++++ b/src/corelib/tools/qsimd.cpp
> +@@ -226,7 +226,7 @@ static void cpuidFeatures07_00(uint &ebx, uint &ecx)
> + #endif
> + }
> +
> +-#ifdef Q_OS_WIN
> ++#if defined(Q_OS_WIN) && !(defined(Q_CC_GNU) || defined(Q_CC_GHS))
> + // fallback overload in case this intrinsic does not exist: unsigned __int64 _xgetbv(unsigned int);
> + inline quint64 _xgetbv(__int64) { return 0; }
> + #endif
> +--
> +2.21.1 (Apple Git-122.3)
> +
> diff --git a/contrib/src/qt/rules.mak b/contrib/src/qt/rules.mak
> index 8c5c0eaf83..d70bcbc3a9 100644
> --- a/contrib/src/qt/rules.mak
> +++ b/contrib/src/qt/rules.mak
> @@ -31,6 +31,10 @@ qt: qt-$(QT_VERSION).tar.xz .sum-qt
>   	$(APPLY) $(SRC)/qt/0007-Only-define-QT_FASTCALL-on-x86_32.patch
>   	$(APPLY) $(SRC)/qt/0008-Skip-arm-pixman-drawhelpers-on-windows-just-like-on-.patch
>   	$(APPLY) $(SRC)/qt/0009-mkspecs-Add-a-win32-clang-g-mkspec-for-clang-targeti.patch
> +	$(APPLY) $(SRC)/qt/0010-Add-the-QT_HAS_xxx-macros-for-post-C-11-feature-test.patch
> +	$(APPLY) $(SRC)/qt/0011-qCount-Leading-Trailing-ZeroBits-Use-__builtin_clzs-.patch
> +	$(APPLY) $(SRC)/qt/0012-Remove-_bit_scan_-forward-reverse.patch
> +	$(APPLY) $(SRC)/qt/0013-qsimd-Fix-compilation-with-trunk-clang-for-mingw.patch
>   	$(APPLY) $(SRC)/qt/systray-no-sound.patch
>   	$(MOVE)
>   
> -- 
> 2.17.1
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list