diff --git a/include/boost/core/bit.hpp b/include/boost/core/bit.hpp index 98bf517..5324c43 100644 --- a/include/boost/core/bit.hpp +++ b/include/boost/core/bit.hpp @@ -190,6 +190,46 @@ BOOST_CONSTEXPR int countl_one( T x ) BOOST_NOEXCEPT // countr +#if defined(__GNUC__) || defined(__clang__) + +namespace detail +{ + +BOOST_CONSTEXPR inline int countr_impl( unsigned char x ) BOOST_NOEXCEPT +{ + return x? __builtin_ctz( x ): std::numeric_limits::digits; +} + +BOOST_CONSTEXPR inline int countr_impl( unsigned short x ) BOOST_NOEXCEPT +{ + return x? __builtin_ctz( x ): std::numeric_limits::digits; +} + +BOOST_CONSTEXPR inline int countr_impl( unsigned int x ) BOOST_NOEXCEPT +{ + return x? __builtin_ctz( x ): std::numeric_limits::digits; +} + +BOOST_CONSTEXPR inline int countr_impl( unsigned long x ) BOOST_NOEXCEPT +{ + return x? __builtin_ctzl( x ): std::numeric_limits::digits; +} + +BOOST_CONSTEXPR inline int countr_impl( unsigned long long x ) BOOST_NOEXCEPT +{ + return x? __builtin_ctzll( x ): std::numeric_limits::digits; +} + +} // namespace detail + +template +BOOST_CONSTEXPR int countr_zero( T x ) BOOST_NOEXCEPT +{ + return boost::core::detail::countr_impl( x ); +} + +#else // defined(__GNUC__) || defined(__clang__) + namespace detail { @@ -241,6 +281,8 @@ int countr_zero( T x ) BOOST_NOEXCEPT } } +#endif // defined(__GNUC__) || defined(__clang__) + template BOOST_CONSTEXPR int countr_one( T x ) BOOST_NOEXCEPT {