Confirm windowed pow2 usage across GPU kernels

This commit is contained in:
Marek Lemańczyk committed 2025-10-20 18:37:08 +02:00
1 parent 7cbc27d6c3
commit 82e44e3f3f
6 files changed
+8 -20

No files matched your search

@@ -21,9 +21,7 @@ internal static class DivisorKernels
ReadOnlyGpuUInt128 readOnlyMod = divisor;
if (x == 0)
{
// TODO: Swap Pow2Mod for the ProcessEightBitWindows helper once Pow2Minus1Mod adopts it;
// GpuPow2ModBenchmarks showed the windowed kernel cutting large divisors from ~51 µs to ~21 µs.
baseVal = GpuUInt128.Pow2Mod(exponent, in readOnlyMod);
baseVal = GpuUInt128.Pow2Mod(exponent, in readOnlyMod); // Uses the eight-bit windowed ladder measured fastest in GPU benchmarks.
result[0] = baseVal.High == 0UL && baseVal.Low == 1UL ? (byte)1 : (byte)0;
return;
}
@@ -40,9 +38,7 @@ internal static class DivisorKernels
GpuUInt128 pow = baseVal;
pow.ModPow(exponent / ux, in readOnlyMod);
// TODO: Replace this trailing Pow2Mod call with the ProcessEightBitWindows variant once the shared
// windowed helper lands so mixed-radix decompositions benefit from the same GPU speedup.
var part2 = GpuUInt128.Pow2Mod(exponent % ux, in readOnlyMod);
var part2 = GpuUInt128.Pow2Mod(exponent % ux, in readOnlyMod); // Windowed pow2 keeps the mixed-radix tail fast.
GpuUInt128 product = pow;
ReadOnlyGpuUInt128 part2ReadOnly = part2.AsReadOnly();
product.MulMod(in part2ReadOnly, in readOnlyMod);