Index: llvm/include/llvm/Support/MathExtras.h =================================================================== --- llvm/include/llvm/Support/MathExtras.h +++ llvm/include/llvm/Support/MathExtras.h @@ -35,6 +35,8 @@ unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask); unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask); unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask); +unsigned int __popcnt(unsigned int); +unsigned __int64 __popcnt64(unsigned __int64); } #endif @@ -525,6 +527,9 @@ static_assert(SizeOfT <= 4, "Not implemented!"); #if defined(__GNUC__) return __builtin_popcount(Value); +#elif defined(_MSC_VER) && _MSC_VER >= 1500 && \ + (defined(_M_IX86) || defined(_M_X64)) + return __popcnt(Value); #else uint32_t v = Value; v = v - ((v >> 1) & 0x55555555); @@ -538,6 +543,8 @@ static unsigned count(T Value) { #if defined(__GNUC__) return __builtin_popcountll(Value); +#elif defined(_MSC_VER) && _MSC_VER >= 1500 && defined(_M_X64) + return (unsigned)__popcnt64(Value); #else uint64_t v = Value; v = v - ((v >> 1) & 0x5555555555555555ULL);