diff --git a/PerfectNumbers.Core/Gpu/GpuUInt128.cs b/PerfectNumbers.Core/Gpu/GpuUInt128.cs index b21731f..e5fa967 100644 --- a/PerfectNumbers.Core/Gpu/GpuUInt128.cs +++ b/PerfectNumbers.Core/Gpu/GpuUInt128.cs @@ -393,25 +393,22 @@ public struct GpuUInt128 : IComparable, IEquatable ulong w1 = xLow * yHigh; ulong w2 = xHigh * yLow; - return (xHigh * yHigh) + (w1 >> 32) + (w2 >> 32) + - ( - ( - ((xLow * yLow) >> 32) + - (uint)w1 + - (uint)w2 - ) >> 32 - ); + ulong w3 = xLow * yLow; + + ulong result = (xHigh * yHigh) + (w1 >> 32) + (w2 >> 32); + result += ((w3 >> 32) + (uint)w1 + (uint)w2) >> 32; + return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Mul64(GpuUInt128 other) { // Multiply this.Low (assumed 64-bit value) by full 128-bit other - ulong operand = Low, - otherLow = other.Low; - - Low = operand * otherLow; - High = operand * other.High + MulHigh(operand, otherLow); + ulong operand = Low; + // otherLow = other.Low; + + Low = operand * other.Low; + High = operand * other.High + MulHigh(operand, other.Low); } [MethodImpl(MethodImplOptions.AggressiveInlining)]