From fa05a7078c2e751388de251fc8e575d3ffbeee1f Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sun, 11 Oct 2026 23:35:07 +1100 Subject: [PATCH 1/4] Do not polyfill Int128/UInt128/nint/nuint BigMul on net10 --- src/Polyfill/Numbers/Int128Polyfill.cs | 4 ++++ src/Polyfill/Numbers/IntPtrPolyfill.cs | 4 ++++ src/Polyfill/Numbers/UInt128Polyfill.cs | 8 ++++++++ src/Polyfill/Numbers/UIntPtrPolyfill.cs | 4 ++++ src/Split/net10.0/Numbers/Int128Polyfill.cs | 12 ------------ src/Split/net10.0/Numbers/IntPtrPolyfill.cs | 18 ------------------ src/Split/net10.0/Numbers/UInt128Polyfill.cs | 20 -------------------- src/Split/net10.0/Numbers/UIntPtrPolyfill.cs | 18 ------------------ src/Tests/BigMulTests.cs | 19 +++++++++++++++++++ 9 files changed, 39 insertions(+), 68 deletions(-) diff --git a/src/Polyfill/Numbers/Int128Polyfill.cs b/src/Polyfill/Numbers/Int128Polyfill.cs index 9dd3bfdb..13b17760 100644 --- a/src/Polyfill/Numbers/Int128Polyfill.cs +++ b/src/Polyfill/Numbers/Int128Polyfill.cs @@ -22,6 +22,8 @@ public static Int128 Log10(Int128 value) return Log10Core((UInt128) value); } +#if !NET10_0_OR_GREATER + /// /// Produces the full product of two 128-bit numbers. /// @@ -37,6 +39,8 @@ public static Int128 BigMul(Int128 left, Int128 right, out Int128 lower) return (Int128) upper - ((left >> 127) & right) - ((right >> 127) & left); } } + +#endif } static Int128 Log10Core(UInt128 value) diff --git a/src/Polyfill/Numbers/IntPtrPolyfill.cs b/src/Polyfill/Numbers/IntPtrPolyfill.cs index 62ccf7b0..5c9866b9 100644 --- a/src/Polyfill/Numbers/IntPtrPolyfill.cs +++ b/src/Polyfill/Numbers/IntPtrPolyfill.cs @@ -132,6 +132,8 @@ public static nint Log10(nint value) return (nint) Log10Core((ulong) value); } +#if !NET10_0_OR_GREATER + /// /// Produces the full product of two native-sized signed numbers. /// @@ -152,6 +154,8 @@ public static nint BigMul(nint left, nint right, out nint lower) return (nint) upper; } } + +#endif } } #endif diff --git a/src/Polyfill/Numbers/UInt128Polyfill.cs b/src/Polyfill/Numbers/UInt128Polyfill.cs index fc128c6e..69c626ba 100644 --- a/src/Polyfill/Numbers/UInt128Polyfill.cs +++ b/src/Polyfill/Numbers/UInt128Polyfill.cs @@ -15,14 +15,20 @@ static partial class Polyfill public static UInt128 Log10(UInt128 value) => (UInt128) Log10Core(value); +#if !NET10_0_OR_GREATER + /// /// Produces the full product of two unsigned 128-bit numbers. /// //Link: https://learn.microsoft.com/en-us/dotnet/api/system.uint128.bigmul?view=net-11.0 public static UInt128 BigMul(UInt128 left, UInt128 right, out UInt128 lower) => BigMulCore(left, right, out lower); + +#endif } +#if !NET10_0_OR_GREATER + // Splits each operand into 64-bit limbs and accumulates the four partial products. // Every partial product of two 64-bit limbs is exact in 128 bits, so no wider // intermediate type is needed. @@ -43,6 +49,8 @@ static UInt128 BigMulCore(UInt128 left, UInt128 right, out UInt128 lower) return leftUpper * rightUpper + (middle >> 64) + (middleLower >> 64); } } + +#endif } #endif diff --git a/src/Polyfill/Numbers/UIntPtrPolyfill.cs b/src/Polyfill/Numbers/UIntPtrPolyfill.cs index 11b8c373..d8f5ea70 100644 --- a/src/Polyfill/Numbers/UIntPtrPolyfill.cs +++ b/src/Polyfill/Numbers/UIntPtrPolyfill.cs @@ -125,6 +125,8 @@ public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, out public static nuint Log10(nuint value) => (nuint) Log10Core(value); +#if !NET10_0_OR_GREATER + /// /// Produces the full product of two native-sized unsigned numbers. /// @@ -145,6 +147,8 @@ public static nuint BigMul(nuint left, nuint right, out nuint lower) return (nuint) upper; } } + +#endif } } #endif diff --git a/src/Split/net10.0/Numbers/Int128Polyfill.cs b/src/Split/net10.0/Numbers/Int128Polyfill.cs index 79ab62a8..b18f70a1 100644 --- a/src/Split/net10.0/Numbers/Int128Polyfill.cs +++ b/src/Split/net10.0/Numbers/Int128Polyfill.cs @@ -17,18 +17,6 @@ public static Int128 Log10(Int128 value) } return Log10Core((UInt128) value); } - /// - /// Produces the full product of two 128-bit numbers. - /// - public static Int128 BigMul(Int128 left, Int128 right, out Int128 lower) - { - unchecked - { - var upper = BigMulCore((UInt128) left, (UInt128) right, out var unsignedLower); - lower = (Int128) unsignedLower; - return (Int128) upper - ((left >> 127) & right) - ((right >> 127) & left); - } - } } static Int128 Log10Core(UInt128 value) { diff --git a/src/Split/net10.0/Numbers/IntPtrPolyfill.cs b/src/Split/net10.0/Numbers/IntPtrPolyfill.cs index 32959837..57fe93fc 100644 --- a/src/Split/net10.0/Numbers/IntPtrPolyfill.cs +++ b/src/Split/net10.0/Numbers/IntPtrPolyfill.cs @@ -19,23 +19,5 @@ public static nint Log10(nint value) } return (nint) Log10Core((ulong) value); } - /// - /// Produces the full product of two native-sized signed numbers. - /// - public static nint BigMul(nint left, nint right, out nint lower) - { - unchecked - { - if (IntPtr.Size == 4) - { - var product = (long) left * right; - lower = (nint) (int) product; - return (nint) (int) (product >> 32); - } - var upper = Math.BigMul((long) left, (long) right, out var low); - lower = (nint) low; - return (nint) upper; - } - } } } diff --git a/src/Split/net10.0/Numbers/UInt128Polyfill.cs b/src/Split/net10.0/Numbers/UInt128Polyfill.cs index 3589ed61..c3c33950 100644 --- a/src/Split/net10.0/Numbers/UInt128Polyfill.cs +++ b/src/Split/net10.0/Numbers/UInt128Polyfill.cs @@ -11,25 +11,5 @@ static partial class Polyfill /// public static UInt128 Log10(UInt128 value) => (UInt128) Log10Core(value); - /// - /// Produces the full product of two unsigned 128-bit numbers. - /// - public static UInt128 BigMul(UInt128 left, UInt128 right, out UInt128 lower) => - BigMulCore(left, right, out lower); - } - static UInt128 BigMulCore(UInt128 left, UInt128 right, out UInt128 lower) - { - unchecked - { - UInt128 leftLower = (ulong) left; - UInt128 leftUpper = (ulong) (left >> 64); - UInt128 rightLower = (ulong) right; - UInt128 rightUpper = (ulong) (right >> 64); - var lowerLower = leftLower * rightLower; - var middle = leftUpper * rightLower + (lowerLower >> 64); - var middleLower = leftLower * rightUpper + (ulong) middle; - lower = (middleLower << 64) | (ulong) lowerLower; - return leftUpper * rightUpper + (middle >> 64) + (middleLower >> 64); - } } } diff --git a/src/Split/net10.0/Numbers/UIntPtrPolyfill.cs b/src/Split/net10.0/Numbers/UIntPtrPolyfill.cs index a134f9c5..8eb6c210 100644 --- a/src/Split/net10.0/Numbers/UIntPtrPolyfill.cs +++ b/src/Split/net10.0/Numbers/UIntPtrPolyfill.cs @@ -13,23 +13,5 @@ static partial class Polyfill /// public static nuint Log10(nuint value) => (nuint) Log10Core(value); - /// - /// Produces the full product of two native-sized unsigned numbers. - /// - public static nuint BigMul(nuint left, nuint right, out nuint lower) - { - unchecked - { - if (UIntPtr.Size == 4) - { - var product = (ulong) left * right; - lower = (nuint) (uint) product; - return (nuint) (uint) (product >> 32); - } - var upper = Math.BigMul((ulong) left, (ulong) right, out var low); - lower = (nuint) low; - return (nuint) upper; - } - } } } diff --git a/src/Tests/BigMulTests.cs b/src/Tests/BigMulTests.cs index 957bbba3..fb179409 100644 --- a/src/Tests/BigMulTests.cs +++ b/src/Tests/BigMulTests.cs @@ -9,6 +9,25 @@ public class BigMulTests static long[] longs = [0, 1, -1, 2, -2, 0x0123456789ABCDEF, unchecked((long) 0xFEDCBA9876543210), long.MaxValue, long.MinValue]; static ulong[] ulongs = [0, 1, 2, 0x0123456789ABCDEF, 0x8000_0000_0000_0000, ulong.MaxValue]; + // Where the BCL declares BigMul the polyfill must not be compiled: a static member of the + // type always wins over a static extension member, so the polyfill would be dead code. + [Test] + public async Task NotPolyfilledWhereBclHasIt() + { + var duplicates = typeof(Polyfills.Polyfill) + .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) + .Where(_ => _.Name == "BigMul") + .Where(_ => + { + var parameters = _.GetParameters().Select(_ => _.ParameterType).ToArray(); + return parameters[0].GetMethod("BigMul", BindingFlags.Public | BindingFlags.Static, null, parameters, null) != null; + }) + .Select(_ => _.ToString()) + .ToList(); + + await Assert.That(duplicates).IsEmpty(); + } + [Test] public async Task Int32() { From 12f70769ad9d579748cac92908efa8e9f6559c4b Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 12 Oct 2026 09:58:37 +1100 Subject: [PATCH 2/4] Regenerate docs --- apiCount.include.md | 2 +- assemblySize.include.md | 4 ++-- readme.md | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apiCount.include.md b/apiCount.include.md index 75cf8af9..1c4cee37 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -23,6 +23,6 @@ | `net7.0` | 522 | | `net8.0` | 400 | | `net9.0` | 253 | -| `net10.0` | 190 | +| `net10.0` | 186 | | `net11.0` | 56 | | `uap10.0` | 1071 | diff --git a/assemblySize.include.md b/assemblySize.include.md index a67c889c..2e5c5395 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -21,7 +21,7 @@ | net7.0 | 10.0KB | 224.5KB | +214.5KB | +9.5KB | +6.0KB | +512bytes | +3.5KB | | net8.0 | 9.5KB | 196.0KB | +186.5KB | +8.0KB | | +512bytes | +3.0KB | | net9.0 | 9.5KB | 126.0KB | +116.5KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 101.5KB | +91.5KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 100.0KB | +90.0KB | +8.5KB | | +512bytes | +3.5KB | | net11.0 | 10.0KB | 17.5KB | +7.5KB | +9.0KB | | +512bytes | +3.5KB | @@ -48,5 +48,5 @@ | net7.0 | 10.0KB | 320.3KB | +310.3KB | +17.0KB | +7.4KB | +1.1KB | +4.2KB | | net8.0 | 9.5KB | 277.2KB | +267.7KB | +15.4KB | +299bytes | +1.1KB | +3.7KB | | net9.0 | 9.5KB | 180.8KB | +171.3KB | +15.9KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 146.2KB | +136.2KB | +15.9KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 143.9KB | +133.9KB | +15.9KB | | +1.1KB | +4.2KB | | net11.0 | 10.0KB | 25.7KB | +15.7KB | +16.4KB | | +1.1KB | +4.2KB | diff --git a/readme.md b/readme.md index c1bb7855..c95757c5 100644 --- a/readme.md +++ b/readme.md @@ -38,8 +38,13 @@ The package targets `netstandard2.0` and is designed to support the following ru | `net7.0` | 522 | | `net8.0` | 400 | | `net9.0` | 253 | +<<<<<<< HEAD | `net10.0` | 190 | | `net11.0` | 56 | +======= +| `net10.0` | 186 | +| `net11.0` | 58 | +>>>>>>> 83cfa509 (Docs changes) | `uap10.0` | 1071 | From af04110bbb4f6d3af83b327191d675a8c5f83492 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 12 Oct 2026 09:58:47 +1100 Subject: [PATCH 3/4] Fix readme conflict markers --- readme.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/readme.md b/readme.md index c95757c5..c1bb7855 100644 --- a/readme.md +++ b/readme.md @@ -38,13 +38,8 @@ The package targets `netstandard2.0` and is designed to support the following ru | `net7.0` | 522 | | `net8.0` | 400 | | `net9.0` | 253 | -<<<<<<< HEAD | `net10.0` | 190 | | `net11.0` | 56 | -======= -| `net10.0` | 186 | -| `net11.0` | 58 | ->>>>>>> 83cfa509 (Docs changes) | `uap10.0` | 1071 | From ef97ac55c3fb830e64038f4460f08981eb600dd1 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 11 Oct 2026 23:00:46 +0000 Subject: [PATCH 4/4] Docs changes --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index c1bb7855..427ead89 100644 --- a/readme.md +++ b/readme.md @@ -38,7 +38,7 @@ The package targets `netstandard2.0` and is designed to support the following ru | `net7.0` | 522 | | `net8.0` | 400 | | `net9.0` | 253 | -| `net10.0` | 190 | +| `net10.0` | 186 | | `net11.0` | 56 | | `uap10.0` | 1071 | @@ -120,7 +120,7 @@ Only [SDK-style projects](https://learn.microsoft.com/en-us/dotnet/core/project- | net7.0 | 10.0KB | 224.5KB | +214.5KB | +9.5KB | +6.0KB | +512bytes | +3.5KB | | net8.0 | 9.5KB | 196.0KB | +186.5KB | +8.0KB | | +512bytes | +3.0KB | | net9.0 | 9.5KB | 126.0KB | +116.5KB | +8.5KB | | +512bytes | +3.5KB | -| net10.0 | 10.0KB | 101.5KB | +91.5KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 100.0KB | +90.0KB | +8.5KB | | +512bytes | +3.5KB | | net11.0 | 10.0KB | 17.5KB | +7.5KB | +9.0KB | | +512bytes | +3.5KB | @@ -147,7 +147,7 @@ Only [SDK-style projects](https://learn.microsoft.com/en-us/dotnet/core/project- | net7.0 | 10.0KB | 320.3KB | +310.3KB | +17.0KB | +7.4KB | +1.1KB | +4.2KB | | net8.0 | 9.5KB | 277.2KB | +267.7KB | +15.4KB | +299bytes | +1.1KB | +3.7KB | | net9.0 | 9.5KB | 180.8KB | +171.3KB | +15.9KB | | +1.1KB | +4.2KB | -| net10.0 | 10.0KB | 146.2KB | +136.2KB | +15.9KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 143.9KB | +133.9KB | +15.9KB | | +1.1KB | +4.2KB | | net11.0 | 10.0KB | 25.7KB | +15.7KB | +16.4KB | | +1.1KB | +4.2KB |