From b1337f21d7863163f7db630067c6db880d23b0be Mon Sep 17 00:00:00 2001 From: LDj3SNuD <35856442+LDj3SNuD@users.noreply.github.com> Date: Tue, 3 Jul 2018 00:46:32 +0200 Subject: [PATCH] Improve CountSetBits8() algorithm. --- ChocolArm64/Instruction/ASoftFallback.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ChocolArm64/Instruction/ASoftFallback.cs b/ChocolArm64/Instruction/ASoftFallback.cs index 585ffd2d87..5c0a9c8e3a 100644 --- a/ChocolArm64/Instruction/ASoftFallback.cs +++ b/ChocolArm64/Instruction/ASoftFallback.cs @@ -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;