Make GPU sieve results authoritative

This commit is contained in:
Marek Lemańczyk committed 2025-10-28 20:14:22 +01:00
1 parent ff9774925e
commit 1792349bad
3 files changed
+60 -15

No files matched your search

@@ -15,34 +15,44 @@ internal static class PrimeTesterKernels
ArrayView<uint> smallPrimesLastSeven,
ArrayView<uint> smallPrimesLastThree,
ArrayView<uint> smallPrimesLastNine,
ArrayView<ulong> smallPrimesPow2,
ArrayView<ulong> smallPrimesPow2LastOne,
ArrayView<ulong> smallPrimesPow2LastSeven,
ArrayView<ulong> smallPrimesPow2LastThree,
ArrayView<ulong> smallPrimesPow2LastNine,
ArrayView<byte> results)
{
ulong n = numbers[index];
byte result = 1;
ArrayView<uint> primes = smallPrimes;
ArrayView<ulong> primeSquares = smallPrimesPow2;
ulong lastDigit = n % 10UL;
switch (lastDigit)
{
case 1UL:
primes = smallPrimesLastOne;
primeSquares = smallPrimesPow2LastOne;
break;
case 3UL:
primes = smallPrimesLastThree;
primeSquares = smallPrimesPow2LastThree;
break;
case 7UL:
primes = smallPrimesLastSeven;
primeSquares = smallPrimesPow2LastSeven;
break;
case 9UL:
primes = smallPrimesLastNine;
primeSquares = smallPrimesPow2LastNine;
break;
}
int length = (int)primes.Length;
int length = XMath.Min((int)primes.Length, (int)primeSquares.Length);
for (int i = 0; i < length; i++)
{
ulong prime = primes[i];
ulong primeSquare = prime * prime;
ulong primeSquare = primeSquares[i];
if (primeSquare > n)
{
break;