Iros
 
Loading...
Searching...
No Matches
countr_zero.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 (value == 0) {
12 return 0;
13 }
14
15 if constexpr (sizeof(T) <= sizeof(unsigned int)) {
16 return __builtin_ctz(value);
17 } else if constexpr (sizeof(T) <= sizeof(unsigned long)) {
18 return __builtin_ctzl(value);
19 } else if constexpr (sizeof(T) <= sizeof(unsigned long long)) {
20 return __builtin_ctzll(value);
21 } else {
22 static_assert(sizeof(T) == 16);
23 auto low = u64(value & math::NumericLimits<u64>::max);
24 if (low != 0) {
25 return (*this)(low);
26 }
27 auto high = u64(value >> 64);
28 return (*this)(high) + 64;
29 }
30 }
31 };
32}
33
34constexpr inline auto countr_zero = detail::CountrZeroFunction {};
35}
36
37namespace di {
39}
Definition bit_proxy_reference.h:5
Definition bit_proxy_reference.h:5
constexpr auto countr_zero
Definition countr_zero.h:34
__UINT64_TYPE__ u64
Definition integers.h:12
Definition zstring_parser.h:9
Definition countr_zero.h:8
constexpr auto operator()(T value) const -> int
Definition countr_zero.h:10
Definition numeric_limits.h:7