24#include <seastar/util/modules.hh>
32SEASTAR_MODULE_EXPORT_BEGIN
35constexpr unsigned count_leading_zeros(
unsigned x) {
36 return __builtin_clz(x);
40constexpr unsigned count_leading_zeros(
unsigned long x) {
41 return __builtin_clzl(x);
45constexpr unsigned count_leading_zeros(
unsigned long long x) {
46 return __builtin_clzll(x);
50constexpr unsigned count_trailing_zeros(
unsigned x) {
51 return __builtin_ctz(x);
55constexpr unsigned count_trailing_zeros(
unsigned long x) {
56 return __builtin_ctzl(x);
60constexpr unsigned count_trailing_zeros(
unsigned long long x) {
61 return __builtin_ctzll(x);
64template<std::
integral T>
65inline constexpr unsigned log2ceil(T n) {
69 return std::numeric_limits<T>::digits - count_leading_zeros(n - 1);
72template<std::
integral T>
73inline constexpr unsigned log2floor(T n) {
74 return std::numeric_limits<T>::digits - count_leading_zeros(n) - 1;
77SEASTAR_MODULE_EXPORT_END
Seastar API namespace.
Definition: abort_on_ebadf.hh:26