mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
25 lines
852 B
C
25 lines
852 B
C
|
#ifndef MATHLIB_BITS_H
|
||
|
#define MATHLIB_BITS_H
|
||
|
//=============================================================================//
|
||
|
//
|
||
|
// Purpose: bitwise utilities.
|
||
|
//
|
||
|
//=============================================================================//
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
// '__popcnt' instruction reimplementation (allows for usage without requiring
|
||
|
// a processor to feature the popcnt instruction, only use for tools that have
|
||
|
// to run on processors that do NOT support popcnt!).
|
||
|
//-----------------------------------------------------------------------------
|
||
|
inline unsigned int PopCount(unsigned long long x)
|
||
|
{
|
||
|
unsigned int count = 0;
|
||
|
while (x) {
|
||
|
x &= x - 1; // Clears the least significant bit set to 1.
|
||
|
count++;
|
||
|
}
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
#endif // MATHLIB_BITS_H
|