Flatten heuristic trial division bounds checks

This commit is contained in:
Marek Lemańczyk committed 2025-10-31 22:45:59 +01:00
1 parent 8c662c5c85
commit 469c8057d3
1 file changed
+7 -13
@@ -92,20 +92,14 @@ internal static class PrimeTesterKernels
int divisorLength = (int)divisorSquares.Length; int divisorLength = (int)divisorSquares.Length;
int threadIndex = index; int threadIndex = index;
if (threadIndex >= divisorLength) bool skipThread = threadIndex >= divisorLength;
{ ulong divisorSquare = skipThread ? 0UL : divisorSquares[threadIndex];
return; skipThread = skipThread | (divisorSquare > maxDivisorSquare);
}
ulong divisorSquare = divisorSquares[threadIndex]; ulong divisor = skipThread ? 1UL : divisors[threadIndex];
if (divisorSquare > maxDivisorSquare) ulong remainder = skipThread ? 1UL : n % divisor;
{ bool hasFactor = !skipThread & (remainder == 0UL);
return; if (hasFactor)
}
ulong divisor = divisors[threadIndex];
divisor = n % divisor;
if (divisor == 0UL)
{ {
resultFlag[0] = 1; resultFlag[0] = 1;
} }