mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-01-06 06:28:13 +01:00
bit_util: Implement BitCount portably
This commit is contained in:
parent
6ec651498d
commit
e8764c129f
1 changed files with 5 additions and 5 deletions
|
|
@ -72,11 +72,11 @@ inline T SignExtend(const T value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t BitCount(u32 value) {
|
inline size_t BitCount(u32 value) {
|
||||||
#ifdef _MSC_VER
|
// Portable SWAR algorithm for population count
|
||||||
return __popcnt(value);
|
value = value - ((value >> 1) & 0x55555555); // Two-bit count
|
||||||
#else
|
value = (value & 0x33333333) + ((value >> 2) & 0x33333333); // Nybble count
|
||||||
return __builtin_popcount(value);
|
value = (value + (value >> 4)) & 0x0F0F0F0F; // Byte count
|
||||||
#endif
|
return ((value * 0x01010101) >> 24) & 0xFF; // Summate the byte counts
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue