I have long wondered why boost is not using built-in functions. Even if we are concerned with purity, I would expect it to be an option at least.
For example, the lowest_bit calculation from
https://www.boost.org/doc/libs/1_70_0/boost/dynamic_bitset/detail/lowest_bit.hpp
template <typename T>
int lowest_bit(T x) {
BOOST_ASSERT(x >= 1); // PRE
// clear all bits on except the rightmost one,
// then calculate the logarithm base 2
//
return boost::integer_log2<T>( x - ( x & (x-1) ) );
}
involves a loop inside integer_log2 function, while it will be enough to call an appropriate version of __builtin_ctz() ???
Update: I found stackoverflow question with decoded __builtin_ctz Where is the source code of gcc builtins?
xor eax, eax
rep bsf eax, edi
ret