21 #ifndef XAPIAN_INCLUDED_POPCOUNT_H
22 #define XAPIAN_INCLUDED_POPCOUNT_H
25 # error config.h must be included first in each C++ source file
28 #if !HAVE_DECL___BUILTIN_POPCOUNT
31 # if HAVE_DECL___POPCNT || HAVE_DECL___POPCNT64
37 template<
typename A,
typename V>
42 #if HAVE_DECL___BUILTIN_POPCOUNT
43 }
else if constexpr(
sizeof(V) ==
sizeof(
unsigned)) {
44 accumulator += __builtin_popcount(value);
45 #elif HAVE_DECL___POPCNT
46 }
else if constexpr(
sizeof(V) ==
sizeof(
unsigned)) {
47 accumulator +=
static_cast<A>(__popcnt(value));
49 #if HAVE_DECL___BUILTIN_POPCOUNTL
50 }
else if constexpr(
sizeof(V) ==
sizeof(
unsigned long)) {
51 accumulator += __builtin_popcountl(value);
53 #if HAVE_DECL___BUILTIN_POPCOUNTLL
54 }
else if constexpr(
sizeof(V) ==
sizeof(
unsigned long long)) {
55 accumulator += __builtin_popcountll(value);
56 #elif HAVE_DECL___POPCNT64
57 }
else if constexpr(
sizeof(V) ==
sizeof(
unsigned long long)) {
58 accumulator +=
static_cast<A>(__popcnt64(value));
61 auto u =
static_cast<std::make_unsigned_t<V>
>(value);
static void add_popcount(A &accumulator, V value)
Add the number of set bits in value to accumulator.