Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Pimenov <m@maps.me>2015-09-11 16:38:18 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:02:16 +0300
commitd6800004d763a905c056bb3ca86e639f476377bc (patch)
tree593c88959f02ecdbaeda78a7add3eec77ea0704a /base/bits.hpp
parente8acd6f4596ebf011822e0c86fbca556faf3b724 (diff)
Review fixes.
Diffstat (limited to 'base/bits.hpp')
-rw-r--r--base/bits.hpp10
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.