Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apiCount.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
4 changes: 2 additions & 2 deletions assemblySize.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |


Expand All @@ -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 |
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
<!-- endInclude -->
Expand Down Expand Up @@ -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 |


Expand All @@ -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 |
<!-- endInclude -->

Expand Down
4 changes: 4 additions & 0 deletions src/Polyfill/Numbers/Int128Polyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static Int128 Log10(Int128 value)
return Log10Core((UInt128) value);
}

#if !NET10_0_OR_GREATER

/// <summary>
/// Produces the full product of two 128-bit numbers.
/// </summary>
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/Polyfill/Numbers/IntPtrPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public static nint Log10(nint value)
return (nint) Log10Core((ulong) value);
}

#if !NET10_0_OR_GREATER

/// <summary>
/// Produces the full product of two native-sized signed numbers.
/// </summary>
Expand All @@ -152,6 +154,8 @@ public static nint BigMul(nint left, nint right, out nint lower)
return (nint) upper;
}
}

#endif
}
}
#endif
8 changes: 8 additions & 0 deletions src/Polyfill/Numbers/UInt128Polyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ static partial class Polyfill
public static UInt128 Log10(UInt128 value) =>
(UInt128) Log10Core(value);

#if !NET10_0_OR_GREATER

/// <summary>
/// Produces the full product of two unsigned 128-bit numbers.
/// </summary>
//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.
Expand All @@ -43,6 +49,8 @@ static UInt128 BigMulCore(UInt128 left, UInt128 right, out UInt128 lower)
return leftUpper * rightUpper + (middle >> 64) + (middleLower >> 64);
}
}

#endif
}

#endif
4 changes: 4 additions & 0 deletions src/Polyfill/Numbers/UIntPtrPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out
public static nuint Log10(nuint value) =>
(nuint) Log10Core(value);

#if !NET10_0_OR_GREATER

/// <summary>
/// Produces the full product of two native-sized unsigned numbers.
/// </summary>
Expand All @@ -145,6 +147,8 @@ public static nuint BigMul(nuint left, nuint right, out nuint lower)
return (nuint) upper;
}
}

#endif
}
}
#endif
12 changes: 0 additions & 12 deletions src/Split/net10.0/Numbers/Int128Polyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ public static Int128 Log10(Int128 value)
}
return Log10Core((UInt128) value);
}
/// <summary>
/// Produces the full product of two 128-bit numbers.
/// </summary>
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)
{
Expand Down
18 changes: 0 additions & 18 deletions src/Split/net10.0/Numbers/IntPtrPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,5 @@ public static nint Log10(nint value)
}
return (nint) Log10Core((ulong) value);
}
/// <summary>
/// Produces the full product of two native-sized signed numbers.
/// </summary>
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;
}
}
}
}
20 changes: 0 additions & 20 deletions src/Split/net10.0/Numbers/UInt128Polyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,5 @@ static partial class Polyfill
/// </summary>
public static UInt128 Log10(UInt128 value) =>
(UInt128) Log10Core(value);
/// <summary>
/// Produces the full product of two unsigned 128-bit numbers.
/// </summary>
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);
}
}
}
18 changes: 0 additions & 18 deletions src/Split/net10.0/Numbers/UIntPtrPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,5 @@ static partial class Polyfill
/// </summary>
public static nuint Log10(nuint value) =>
(nuint) Log10Core(value);
/// <summary>
/// Produces the full product of two native-sized unsigned numbers.
/// </summary>
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;
}
}
}
}
19 changes: 19 additions & 0 deletions src/Tests/BigMulTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading