Hoist prime order thresholds in CPU heuristics
This commit is contained in:
1 parent
1bd3d5c163
commit
94a4ed8328
12 files changed
+670
-351
No files matched your search
@@ -36,30 +36,45 @@ internal static class DivisorByDivisorKernels
|
||||
byte firstHitValue;
|
||||
ulong previousExponent = firstExponent;
|
||||
ulong cycleRemainder = 0UL;
|
||||
if (cycleLength == 0UL)
|
||||
{
|
||||
firstHitValue = firstUnity ? (byte)1 : (byte)0;
|
||||
}
|
||||
else
|
||||
bool hasCycle = cycleLength != 0UL;
|
||||
if (hasCycle)
|
||||
{
|
||||
cycleRemainder = firstExponent % cycleLength;
|
||||
firstHitValue = cycleRemainder == 0UL && firstUnity ? (byte)1 : (byte)0;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstHitValue = firstUnity ? (byte)1 : (byte)0;
|
||||
}
|
||||
|
||||
hits[offset] = firstHitValue;
|
||||
byte anyHit = firstHitValue;
|
||||
|
||||
for (int i = 1; i < count; i++)
|
||||
int endIndex = offset + count;
|
||||
if (hasCycle)
|
||||
{
|
||||
ulong exponent = exponents[offset + i];
|
||||
ulong delta = exponent - previousExponent;
|
||||
previousExponent = exponent;
|
||||
|
||||
if (cycleLength != 0UL)
|
||||
for (int exponentIndex = offset + 1; exponentIndex < endIndex; exponentIndex++)
|
||||
{
|
||||
var remainderValue = new GpuUInt128(cycleRemainder);
|
||||
remainderValue.AddMod(delta, cycleLength);
|
||||
cycleRemainder = remainderValue.Low;
|
||||
ulong exponent = exponents[exponentIndex];
|
||||
ulong delta = exponent - previousExponent;
|
||||
previousExponent = exponent;
|
||||
|
||||
if (delta >= cycleLength)
|
||||
{
|
||||
delta -= cycleLength;
|
||||
if (delta >= cycleLength)
|
||||
{
|
||||
delta %= cycleLength;
|
||||
}
|
||||
}
|
||||
|
||||
ulong nextRemainder = cycleRemainder + delta;
|
||||
if (nextRemainder >= cycleLength)
|
||||
{
|
||||
nextRemainder -= cycleLength;
|
||||
}
|
||||
|
||||
cycleRemainder = nextRemainder;
|
||||
|
||||
byte hit = 0;
|
||||
if (cycleRemainder == 0UL)
|
||||
@@ -67,13 +82,17 @@ internal static class DivisorByDivisorKernels
|
||||
hit = stepper.ComputeNextIsUnityGpu(exponent) ? (byte)1 : (byte)0;
|
||||
}
|
||||
|
||||
hits[offset + i] = hit;
|
||||
hits[exponentIndex] = hit;
|
||||
anyHit |= hit;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int exponentIndex = offset + 1; exponentIndex < endIndex; exponentIndex++)
|
||||
{
|
||||
ulong exponent = exponents[exponentIndex];
|
||||
byte hit = stepper.ComputeNextIsUnityGpu(exponent) ? (byte)1 : (byte)0;
|
||||
hits[offset + i] = hit;
|
||||
hits[exponentIndex] = hit;
|
||||
anyHit |= hit;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user