Refine Mul64 benchmarks with GPU-friendly variant

This commit is contained in:
Marek Lemańczyk committed 2025-09-30 04:24:40 +02:00
1 parent daab18504b
commit ebe3b306b9
4 files changed
+133 -6

No files matched your search

+5
View File
@@ -395,6 +395,11 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
ulong w2 = xHigh * yLow;
ulong w3 = xLow * yLow;
// Keeping the wide partial sum in a dedicated local prevents the JIT from
// materialising it on the stack before the final carry propagation. The
// additional store looks redundant in C#, but it shortens the generated
// instruction sequence by avoiding an extra temporary and results in a
// measurable throughput win in the MulHigh benchmarks.
ulong result = (xHigh * yHigh) + (w1 >> 32) + (w2 >> 32);
result += ((w3 >> 32) + (uint)w1 + (uint)w2) >> 32;
return result;