Kawe Mazidjatari 0de507713b Make fbits inline, and add PopCount
Floating point bitwise functions are now inline, also implemented a 'PopCount' function, which replicates the '__popcnt' instruction, but does not require the CPU to feature the instruction. This was mainly added as the SDK launcher doesn't check the CPU for SSSe3/popcnt, as it doesn't involve any instruction sets past SSE2.
2023-07-13 00:06:56 +02:00

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