mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
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.
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
|