Update ASoftFallback.cs
This commit is contained in:
parent
4abff91426
commit
15eb68f1d0
1 changed files with 40 additions and 19 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue