WickedEngine/Utility/vk_mem_alloc.h
static inline uint32_t VmaCountBitsSet(uint32_t v)
{
#ifdef _MSC_VER
    return __popcnt(v);
#elif defined __GNUC__ || defined __clang__
    return static_cast<uint32_t>(__builtin_popcount(v));
#else
    uint32_t c = v - ((v >> 1) & 0x55555555);
    c = ((c >> 2) & 0x33333333) + (c & 0x33333333);
    c = ((c >> 4) + c) & 0x0F0F0F0F;
    c = ((c >> 8) + c) & 0x00FF00FF;
    c = ((c >> 16) + c) & 0x0000FFFF;
    return c;
#endif
}
// Returns number of bits set to 1 in (v).
Returns number of bits set to 1 in (v).
Returns number of bits set to 1 in ( v ) .
static inline uint32_t VmaCountBitsSet(uint32_t v)
{
#ifdef _MSC_VER
    return __popcnt(v);
#elif defined __GNUC__ || defined __clang__
    return static_cast<uint32_t>(__builtin_popcount(v));
#else
    uint32_t c = v - ((v >> 1) & 0x55555555);
    c = ((c >> 2) & 0x33333333) + (c & 0x33333333);
    c = ((c >> 4) + c) & 0x0F0F0F0F;
    c = ((c >> 8) + c) & 0x00FF00FF;
    c = ((c >> 16) + c) & 0x0000FFFF;
    return c;
#endif
}
static inline uint32_t VmaCountBitsSet ( uint32_t v ) { #ifdef _MSC_VER return __popcnt ( v ) ; #elif defined __GNUC__ || defined __clang__ return static_cast < uint32_t > ( __builtin_popcount ( v ) ) ; #else uint32_t c = v - ( ( v >> 1 ) & 0x55555555 ) ; c = ( ( c >> 2 ) & 0x33333333 ) + ( c & 0x33333333 ) ; c = ( ( c >> 4 ) + c ) & 0x0F0F0F0F ; c = ( ( c >> 8 ) + c ) & 0x00FF00FF ; c = ( ( c >> 16 ) + c ) & 0x0000FFFF ; return c ; #endif }
Returns number of bits set to 1 in (v).
Returns number of bits set to 1 in ( v ) .