[base] Fixed PopCount64.

This commit is contained in:
Yuri Gorshenin 2017-01-30 16:27:50 +03:00
parent c0a9fbc742
commit 64fe56bd9f

View file

@ -63,12 +63,10 @@ namespace bits
inline uint32_t PopCount(uint64_t x) noexcept
{
x = (x & 0x5555555555555555) + ((x & 0xAAAAAAAAAAAAAAAA) >> 1);
x = (x & 0x3333333333333333) + ((x & 0xCCCCCCCCCCCCCCCC) >> 2);
x = (x & 0x0F0F0F0F0F0F0F0F) + ((x & 0xF0F0F0F0F0F0F0F0) >> 4);
x = (x & 0x00FF00FF00FF00FF) + ((x & 0xFF00FF00FF00FF00) >> 8);
x = (x & 0x0000FFFF0000FFFF) + ((x & 0xFFFF0000FFFF0000) >> 16);
x = x + (x >> 32);
x = x - ((x & 0xAAAAAAAAAAAAAAAA) >> 1);
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333);
x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F;
x = (x * 0x0101010101010101) >> 56;
return static_cast<uint32_t>(x);
}