diff options
author | Maxim Pimenov <m@maps.me> | 2015-09-11 16:38:18 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-03-23 16:02:16 +0300 |
commit | d6800004d763a905c056bb3ca86e639f476377bc (patch) | |
tree | 593c88959f02ecdbaeda78a7add3eec77ea0704a /base/bits.hpp | |
parent | e8acd6f4596ebf011822e0c86fbca556faf3b724 (diff) |
Review fixes.
Diffstat (limited to 'base/bits.hpp')
-rw-r--r-- | base/bits.hpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/base/bits.hpp b/base/bits.hpp index cbae1baa4f..6b40d2406d 100644 --- a/base/bits.hpp +++ b/base/bits.hpp @@ -63,9 +63,13 @@ namespace bits inline uint32_t PopCount(uint64_t x) { - uint32_t lower = static_cast<uint32_t>(x); - uint32_t higher = static_cast<uint32_t>(x >> 32); - return PopCount(lower) + PopCount(higher); + 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); + return static_cast<uint8_t>(x); } // Will be implemented when needed. |