countl_zero#
Fully qualified name: carb::cpp::countl_zero
Defined in carb/cpp/Bit.h
-
template<class T, std::enable_if_t<detail::IsUnsignedIntegral<T>::value, bool> = false>
int carb::cpp::countl_zero( - T val,
Returns the number of consecutive 0 bits in the value of val, starting from the most significant bit (“left”).
Note
Unlike std::countl_zero, this function is not constexpr. This is because the compiler intrinsics used to implement this function are not constexpr until C++20, so it was decided to drop constexpr in favor of being able to use compiler intrinsics. If a constexpr implementation is required, use countl_zero_constexpr().
Note
(Intel/AMD CPUs) To support backwards compatibility with older CPUs, by default this is implemented with a
bsrinstruction (i386+), that is slightly less performant (~3%) than the more modernlzcntinstruction. This function implementation will switch to usinglzcntif the compiler indicates that instruction is supported. On Visual Studio this is provided by passing/arch:AVX2command-line switch, or on GCC with-march=haswell(or several other-marchoptions). Thelzcntinstruction was introduced on Intel’s Haswell micro- architecture and AMD’s Jaguar and Piledriver micro-architectures.- Template Parameters:
T – An unsigned integral type
- Parameters:
val – An unsigned integral value
- Returns:
The number of consecutive 0 bits in the provided value, starting from the most significant bit.