[Support] Add MSVC intrinsic for CountPopulation.

Patch by Jakub Staszak.

llvm-svn: 172645
This commit is contained in:
Michael J. Spencer 2013-01-16 19:52:12 +00:00
parent ad228f4a72
commit 90a1773397
1 changed files with 4 additions and 0 deletions

View File

@ -299,6 +299,8 @@ inline unsigned CountTrailingOnes_64(uint64_t Value) {
inline unsigned CountPopulation_32(uint32_t Value) {
#if __GNUC__ >= 4
return __builtin_popcount(Value);
#elif _MSC_VER
return __popcnt(Value);
#else
uint32_t v = Value - ((Value >> 1) & 0x55555555);
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
@ -311,6 +313,8 @@ inline unsigned CountPopulation_32(uint32_t Value) {
inline unsigned CountPopulation_64(uint64_t Value) {
#if __GNUC__ >= 4
return __builtin_popcountll(Value);
#elif _MSC_VER
return __popcnt64(Value);
#else
uint64_t v = Value - ((Value >> 1) & 0x5555555555555555ULL);
v = (v & 0x3333333333333333ULL) + ((v >> 2) & 0x3333333333333333ULL);