Improve by-divisor residue reuse and fix Montgomery mul

This commit is contained in:
Marek Lemańczyk committed 2025-09-24 15:44:21 +02:00
1 parent 82a0fb1dd7
commit df69dcbadb
3 files changed
+190 -97

No files matched your search

+7 -10
View File
@@ -163,18 +163,15 @@ public static class ULongExtensions
{
ulong xLow = (uint)x;
ulong xHigh = x >> 32;
ulong yLow = (uint)y;
ulong yHigh = y >> 32;
ulong yLow = (uint)y;
ulong yHigh = y >> 32;
ulong w1 = xLow * yHigh;
ulong w2 = xHigh * yLow;
ulong w1 = xLow * yHigh;
ulong w2 = xHigh * yLow;
return (xHigh * yHigh) + (w1 >> 32) + (w2 >> 32) +
(
((xLow * yLow) >> 32) +
(uint)w1 +
(uint)w2
) >> 32;
ulong result = (xHigh * yHigh) + (w1 >> 32) + (w2 >> 32);
result += (((xLow * yLow) >> 32) + (uint)w1 + (uint)w2) >> 32;
return result;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]