mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 01:28:48 +00:00
Fix ulong.PopCount for .NET < Core 3.1 fallback
Previous implementation copied the uint version
This commit is contained in:
parent
b1eadf61f4
commit
efa5145836
@ -30,14 +30,14 @@ public static class UInt64Extensions
|
||||
#if NETCOREAPP3_1_OR_GREATER
|
||||
return BitOperations.PopCount(value);
|
||||
#else
|
||||
const uint c1 = 0x_55555555u;
|
||||
const uint c2 = 0x_33333333u;
|
||||
const uint c3 = 0x_0F0F0F0Fu;
|
||||
const uint c4 = 0x_01010101u;
|
||||
const ulong c1 = 0x_55555555_55555555ul;
|
||||
const ulong c2 = 0x_33333333_33333333ul;
|
||||
const ulong c3 = 0x_0F0F0F0F_0F0F0F0Ful;
|
||||
const ulong c4 = 0x_01010101_01010101ul;
|
||||
|
||||
value -= (value >> 1) & c1;
|
||||
value = (value & c2) + ((value >> 2) & c2);
|
||||
value = (((value + (value >> 4)) & c3) * c4) >> 24;
|
||||
value = (((value + (value >> 4)) & c3) * c4) >> 56;
|
||||
|
||||
return (int)value;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user