summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-08-15 13:43:18 -0700
committerThiago Macieira <thiago.macieira@intel.com>2018-08-16 16:33:38 +0000
commit04bbf534f98387073ce327eac2718e0170f8d8c0 (patch)
treef2cd992d2c861f0cae4cbb6d47bf4369253e5424 /src
parent242ea38375534f529f155efa46593e2a42577455 (diff)
MSVC: add support for 64-bit POPCNT on 32-bit machines
It's just adding the count of each half. Change-Id: I9868946ceaf74002bde1fffd154b29908319007f Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qalgorithms.h9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h
index b658d8afcf..0146e22fa3 100644
--- a/src/corelib/tools/qalgorithms.h
+++ b/src/corelib/tools/qalgorithms.h
@@ -651,6 +651,7 @@ Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW
// So it's an acceptable compromise.
#if defined(__AVX__) || defined(__SSE4_2__) || defined(__POPCNT__)
#define QALGORITHMS_USE_BUILTIN_POPCOUNT
+#define QALGORITHMS_USE_BUILTIN_POPCOUNTLL
Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW
{
return __popcnt(v);
@@ -663,13 +664,15 @@ Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW
{
return __popcnt16(v);
}
-#if Q_PROCESSOR_WORDSIZE == 8
-#define QALGORITHMS_USE_BUILTIN_POPCOUNTLL
Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW
{
+#if Q_PROCESSOR_WORDSIZE == 8
return __popcnt64(v);
-}
+#else
+ return __popcnt(quint32(v)) + __popcnt(quint32(v >> 32));
#endif // MSVC 64bit
+}
+
#endif // __AVX__ || __SSE4_2__ || __POPCNT__
#endif // MSVC