summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@theqtcompany.com>2015-12-03 12:50:44 +0100
committerErik Verbruggen <erik.verbruggen@qt.io>2016-05-31 12:09:52 +0000
commite70324f8dd1f191556599cf60100dd0ad0b16708 (patch)
tree7b605613143718896810150614538feab022e5a2 /src/corelib/kernel
parentf7e29f07ffead8bd1cb6ff81bb791de2fb11fa5e (diff)
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@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qmath.h22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h
index c24fc3a0ce..773884047a 100644
--- a/src/corelib/kernel/qmath.h
+++ b/src/corelib/kernel/qmath.h
@@ -45,6 +45,7 @@
#endif
#include <QtCore/qglobal.h>
+#include <QtCore/qalgorithms.h>
#ifndef _USE_MATH_DEFINES
# define _USE_MATH_DEFINES
@@ -241,20 +242,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)
@@ -267,7 +260,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;