Update ASoftFallback.cs

This commit is contained in:
LDj3SNuD 2018-10-13 01:10:05 +02:00 committed by GitHub
commit 15eb68f1d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -386,7 +386,7 @@ namespace ChocolArm64.Instruction
#endregion #endregion
#region "Count" #region "Count"
public static ulong CountLeadingSigns(ulong Value, int Size) public static ulong CountLeadingSigns(ulong Value, int Size) // Size is 8, 16, 32 or 64 (SIMD&FP or Base Inst.).
{ {
Value ^= Value >> 1; Value ^= Value >> 1;
@ -405,33 +405,54 @@ namespace ChocolArm64.Instruction
private static readonly byte[] ClzNibbleTbl = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; private static readonly byte[] ClzNibbleTbl = { 4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
public static ulong CountLeadingZeros(ulong Value, int Size) public static ulong CountLeadingZeros(ulong Value, int Size) // Size is 8, 16, 32 or 64 (SIMD&FP or Base Inst.).
{ {
if (Value == 0) if (Lzcnt.IsSupported && Size >= 32)
{ {
return (ulong)Size; return Size == 32
? (ulong)Lzcnt.LeadingZeroCount((uint)Value)
: Lzcnt.LeadingZeroCount(Value);
} }
else
int NibbleIdx = Size;
int PreCount, Count = 0;
do
{ {
NibbleIdx -= 4; if (Value == 0ul)
PreCount = ClzNibbleTbl[(Value >> NibbleIdx) & 0b1111]; {
Count += PreCount; return (ulong)Size;
} }
while (PreCount == 4);
return (ulong)Count; int NibbleIdx = Size;
int PreCount, Count = 0;
do
{
NibbleIdx -= 4;
PreCount = ClzNibbleTbl[(Value >> NibbleIdx) & 0b1111];
Count += PreCount;
}
while (PreCount == 4);
return (ulong)Count;
}
} }
public static uint CountSetBits8(uint Value) public static ulong CountSetBits8(ulong Value) // "Size" is 8 (SIMD&FP Inst.).
{ {
Value = ((Value >> 1) & 0x55) + (Value & 0x55); if (Popcnt.IsSupported)
Value = ((Value >> 2) & 0x33) + (Value & 0x33); {
return (ulong)Popcnt.PopCount(Value);
}
else
{
if (Value == 0xfful)
{
return 8ul;
}
return (Value >> 4) + (Value & 0x0f); Value = ((Value >> 1) & 0x55ul) + (Value & 0x55ul);
Value = ((Value >> 2) & 0x33ul) + (Value & 0x33ul);
return (Value >> 4) + (Value & 0x0ful);
}
} }
#endregion #endregion