4#ifndef TETL_BIT_POPCOUNT_HPP
5#define TETL_BIT_POPCOUNT_HPP
7#include <etl/_config/all.hpp>
9#include <etl/_concepts/builtin_unsigned_integer.hpp>
10#include <etl/_limits/numeric_limits.hpp>
11#include <etl/_type_traits/is_constant_evaluated.hpp>
12#include <etl/_type_traits/is_same.hpp>
19template <etl::builtin_unsigned_integer UInt>
20[[nodiscard]]
constexpr auto popcount_fallback(UInt val)
noexcept ->
int
23 for (; val != 0; val &= val - UInt(1)) {
38template <
etl::builtin_unsigned_integer UInt>
39[[nodiscard]]
constexpr auto popcount(UInt val)
noexcept ->
int
42#if __has_builtin(__builtin_popcount)
43 if constexpr (
sizeof(UInt) ==
sizeof(
unsigned long long)) {
44 return static_cast<
int>(__builtin_popcountll(val));
45 }
else if constexpr (
sizeof(UInt) ==
sizeof(
unsigned long)) {
46 return static_cast<
int>(__builtin_popcountl(val));
48 return static_cast<
int>(__builtin_popcount(val));
53 return etl::detail::popcount_fallback(val);
constexpr auto popcount(UInt val) noexcept -> int
Returns the number of 1 bits in the value of x.
Definition popcount.hpp:39
Definition adjacent_find.hpp:9
constexpr auto is_constant_evaluated() noexcept -> bool
Detects whether the function call occurs within a constant-evaluated context. Returns true if the eva...
Definition is_constant_evaluated.hpp:17