tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
countl_zero.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_BIT_COUNTL_ZERO_HPP
4#define TETL_BIT_COUNTL_ZERO_HPP
5
8
9namespace etl {
10
22template <etl::builtin_unsigned_integer UInt>
23[[nodiscard]] constexpr auto countl_zero(UInt x) noexcept -> int
24{
25 auto const totalBits = etl::numeric_limits<UInt>::digits;
26 if (x == UInt(0)) {
28 }
29
30 auto res = 0;
31 while (!(x & (UInt(1) << (static_cast<UInt>(totalBits) - UInt(1))))) {
32 x = static_cast<UInt>(x << UInt(1));
33 ++res;
34 }
35
36 return res;
37}
38
39} // namespace etl
40
41#endif // TETL_BIT_COUNTL_ZERO_HPP
constexpr auto countl_zero(UInt x) noexcept -> int
Returns the number of consecutive 0 bits in the value of x, starting from the most significant bit ("...
Definition countl_zero.hpp:23
Definition adjacent_find.hpp:8
static constexpr int digits
Definition numeric_limits.hpp:24