diff options
Diffstat (limited to 'src/corelib/tools/qalgorithms.h')
-rw-r--r-- | src/corelib/tools/qalgorithms.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index ffa3082d5e..27630aea87 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -620,7 +620,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); @@ -679,7 +683,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); |