Iros
 
Loading...
Searching...
No Matches
popcount.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/meta/language.h"
5
6namespace di::bit {
7namespace detail {
9 template<concepts::UnsignedInteger T>
10 constexpr auto operator()(T value) const -> int {
11 if constexpr (sizeof(T) <= sizeof(unsigned int)) {
12 return __builtin_popcount(value);
13 } else if constexpr (sizeof(T) <= sizeof(unsigned long)) {
14 return __builtin_popcountl(value);
15 } else if constexpr (sizeof(T) <= sizeof(unsigned long long)) {
16 return __builtin_popcountll(value);
17 } else {
18 static_assert(sizeof(T) == 16);
19 auto low = u64(value & math::NumericLimits<u64>::max);
20 auto high = u64(value >> 64);
21 return (*this)(low) + (*this)(high);
22 }
23 }
24 };
25}
26
27constexpr inline auto popcount = detail::PopcountFunction {};
28}
29
30namespace di {
31using bit::popcount;
32}
Definition bit_proxy_reference.h:5
Definition bit_proxy_reference.h:5
constexpr auto popcount
Definition popcount.h:27
__UINT64_TYPE__ u64
Definition integers.h:12
Definition zstring_parser.h:9
Definition popcount.h:8
constexpr auto operator()(T value) const -> int
Definition popcount.h:10
Definition numeric_limits.h:7