Remove try/finally from GPU Montgomery executor

This commit is contained in:
Marek Lemańczyk committed 2025-10-19 06:03:39 +02:00
1 parent 4fcf6254e6
commit 75f815567d
6 files changed
+421 -319

No files matched your search

+2 -19
View File
@@ -206,9 +206,6 @@ public class MersenneDivisorCycles
}
}
// TODO: Replace this naive doubling fallback with the unrolled-hex generator from
// MersenneDivisorCycleLengthGpuBenchmarks so large divisors avoid the millions of
// iterations measured in the scalar loop.
// TODO: Route this miss to an ephemeral single-cycle computation on the device selected by the current
// configuration (and skip persisting the result) when the divisor falls outside the in-memory snapshot
// so we respect the large-p memory limits and avoid extra cache locks.
@@ -987,25 +984,11 @@ public class MersenneDivisorCycles
private static ulong CalculateCycleLengthFallback(ulong divisor)
{
// Otherwise, find order of 2 mod divisor
// TODO: Switch this scalar fallback to the unrolled-hex stepping sequence once
// the generator is shared with CPU callers; the benchmark shows the unrolled
// variant winning decisively for divisors >= 131,071.
// Otherwise, find order of 2 mod divisor using the shared unrolled-hex stepping sequence.
// TODO: Expose a GPU-first branch here so high divisors leverage the ProcessEightBitWindows
// kernel measured fastest in CycleLengthGpuVsCpuBenchmarks, returning the result without
// storing it in the shared cache.
ulong order = 1UL;
ulong pow = 2UL;
while (pow != 1UL)
{
pow <<= 1;
if (pow >= divisor)
pow -= divisor;
order++;
}
return order;
return divisor.CalculateMersenneDivisorCycleLengthUnrolledHexCpu();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]