diff --git a/src/libraries/System.Private.CoreLib/src/System/Math.cs b/src/libraries/System.Private.CoreLib/src/System/Math.cs
index e2fe2051ce5c9..35423008dc317 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Math.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Math.cs
@@ -236,13 +236,24 @@ public static long BigMul(long a, long b, out long low)
return (long)high - ((a >> 63) & b) - ((b >> 63) & a);
}
+ /// Produces the full product of two unsigned 64-bit numbers.
+ /// The first number to multiply.
+ /// The second number to multiply.
+ /// The full product of the specified numbers.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static UInt128 BigMul(ulong a, ulong b)
+ {
+ ulong high = BigMul(a, b, out ulong low);
+ return new UInt128(high, low);
+ }
+
/// Produces the full product of two 64-bit numbers.
/// The first number to multiply.
/// The second number to multiply.
/// The full product of the specified numbers.
internal static Int128 BigMul(long a, long b)
{
- long high = Math.BigMul(a, b, out long low);
+ long high = BigMul(a, b, out long low);
return new Int128((ulong)high, (ulong)low);
}
diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt128.cs b/src/libraries/System.Private.CoreLib/src/System/UInt128.cs
index ec195239ca983..0ee4c3c800052 100644
--- a/src/libraries/System.Private.CoreLib/src/System/UInt128.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/UInt128.cs
@@ -1396,18 +1396,18 @@ internal static UInt128 BigMul(UInt128 left, UInt128 right, out UInt128 lower)
// Basically, it's an optimized version of FOIL method applied to
// low and high qwords of each operand
- UInt128 al = left._lower;
- UInt128 ah = left._upper;
+ ulong al = left._lower;
+ ulong ah = left._upper;
- UInt128 bl = right._lower;
- UInt128 bh = right._upper;
+ ulong bl = right._lower;
+ ulong bh = right._upper;
- UInt128 mull = al * bl;
- UInt128 t = ah * bl + mull._upper;
- UInt128 tl = al * bh + t._lower;
+ UInt128 mull = Math.BigMul(al, bl);
+ UInt128 t = Math.BigMul(ah, bl) + mull._upper;
+ UInt128 tl = Math.BigMul(al, bh) + t._lower;
lower = new UInt128(tl._lower, mull._lower);
- return ah * bh + t._upper + tl._upper;
+ return Math.BigMul(ah, bh) + t._upper + tl._upper;
}
//