Use mask for ActionPool
This commit is contained in:
@@ -92,11 +92,46 @@ internal static class Intrinsics
|
||||
return _base;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int NthBitSetScalar(ulong value, int n)
|
||||
{
|
||||
var mask = 0x00000000FFFFFFFFul;
|
||||
var size = 32;
|
||||
var _base = 0;
|
||||
|
||||
if (n++ >= BitOperations.PopCount(value))
|
||||
return 64;
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
var count = BitOperations.PopCount(value & mask);
|
||||
if (n > count)
|
||||
{
|
||||
_base += size;
|
||||
size >>= 1;
|
||||
mask |= mask << size;
|
||||
}
|
||||
else
|
||||
{
|
||||
size >>= 1;
|
||||
mask >>= size;
|
||||
}
|
||||
}
|
||||
|
||||
return _base;
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int NthBitSetBMI2(uint value, int n) =>
|
||||
BitOperations.TrailingZeroCount(Bmi2.ParallelBitDeposit(1u << n, value));
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static int NthBitSetBMI2(ulong value, int n) =>
|
||||
BitOperations.TrailingZeroCount(Bmi2.X64.ParallelBitDeposit(1ul << n, value));
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int NthBitSet(uint value, int n)
|
||||
@@ -109,6 +144,18 @@ internal static class Intrinsics
|
||||
NthBitSetScalar(value, n);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int NthBitSet(ulong value, int n)
|
||||
{
|
||||
if (n >= BitOperations.PopCount(value))
|
||||
return 64;
|
||||
|
||||
return Bmi2.X64.IsSupported ?
|
||||
NthBitSetBMI2(value, n) :
|
||||
NthBitSetScalar(value, n);
|
||||
}
|
||||
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Vector<float> ReciprocalSqrt(Vector<float> data)
|
||||
|
||||
Reference in New Issue
Block a user