Akumuli
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
bit_twiddling.h
1 #pragma once
2 
3 namespace Akumuli {
4 
7 struct BitHacks {
8 
10  static inline int count_bits(uint32_t bitmap) {
11 #if __GNUC__
12  return __builtin_popcount(bitmap);
13 #else
14  bitmap = bitmap - ((bitmap >> 1) & 0x55555555);
15  bitmap = (bitmap & 0x33333333) + ((bitmap >> 2) & 0x33333333);
16  return (((bitmap + (bitmap >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
17 #endif
18  }
19 };
20 }
Definition: bit_twiddling.h:7
static int count_bits(uint32_t bitmap)
Return number of 1-bits in bitmap.
Definition: bit_twiddling.h:10