bitwise: add popcount overloads for short and char

This commit is contained in:
Danny Robson 2019-09-11 07:41:09 +10:00
parent 5106038734
commit 2258279518

View File

@ -83,6 +83,24 @@ namespace cruft {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/// Calculates the number of bits that are set. /// Calculates the number of bits that are set.
constexpr unsigned constexpr unsigned
popcount (unsigned char t)
{
return __builtin_popcount (t);
}
///------------------------------------------------------------------------
/// Calculates the number of bits that are set.
constexpr unsigned
popcount (unsigned short t)
{
return __builtin_popcount (t);
}
///------------------------------------------------------------------------
/// Calculates the number of bits that are set.
constexpr unsigned
popcount (unsigned t) popcount (unsigned t)
{ {
return __builtin_popcount (t); return __builtin_popcount (t);