Skip to content

Commit

Permalink
MSVC: add support for 64-bit POPCNT on 32-bit machines
Browse files Browse the repository at this point in the history
It's just adding the count of each half.

Change-Id: I9868946ceaf74002bde1fffd154b29908319007f
Reviewed-by: Samuel Gaist <[email protected]>
Reviewed-by: Olivier Goffart (Woboq GmbH) <[email protected]>
  • Loading branch information
thiagomacieira committed Aug 16, 2018
1 parent 242ea38 commit 04bbf53
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/corelib/tools/qalgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 04bbf53

Please sign in to comment.