__builtin_popcountg 0 ▲ Revfad Blog 1 hour ago · Tech · hide · 0 comments Looking at https://en.cppreference.com/cpp/utility/bitset/count, I was intrigued to see popcount mentioned in the “See also” section. Handy. That made me curious to see how the stdlibs choose to implement it. Here it is for Clang: libcxx/include/__bit/popcount.h template <class _Tp> [[__nodiscard__]] _LIBCPP_CONSTEXPR int __popcount(_Tp __t) _NOEXCEPT { return __builtin_popcountg(__t); } #if _LIBCPP_STD_VER >= 20 template <__unsigned_integer _Tp> [[nodiscard]] constexpr int popcount(_Tp __t) noexcept { return std::__popcount(__t); } #endif For gcc: libstdc++-v3/include/std/bit template<__unsigned_integer _Tp> constexpr int popcount(_Tp __x) noexcept { return std::__popcount(__x); } ... #if _GLIBCXX_USE_BUILTIN_TRAIT(__builtin_popcountg) template<typename _Tp> constexpr int __popcount(_Tp __x) noexcept { return __builtin_popcountg(__x); } #else template<typename _Tp> _GLIBCXX14_CONSTEXPR int __popcount(_Tp __x) noexcept { using __gnu_cxx::__int_traits; constexpr auto _Nd =… No comments yet. Log in to reply on the Fediverse. Comments will appear here.