Improve CountSetBits8() algorithm.

This commit is contained in:
LDj3SNuD 2018-07-03 00:46:32 +02:00 committed by GitHub
parent dcd0208326
commit b1337f21d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,12 +30,12 @@ namespace ChocolArm64.Instruction
return (ulong)Size;
}
public static int CountSetBits8(byte Value)
public static uint CountSetBits8(uint Value)
{
return ((Value >> 0) & 1) + ((Value >> 1) & 1) +
((Value >> 2) & 1) + ((Value >> 3) & 1) +
((Value >> 4) & 1) + ((Value >> 5) & 1) +
((Value >> 6) & 1) + (Value >> 7);
Value = ((Value >> 1) & 0x55) + (Value & 0x55);
Value = ((Value >> 2) & 0x33) + (Value & 0x33);
return (Value >> 4) + (Value & 0x0f);
}
private const uint Crc32RevPoly = 0xedb88320;