Open hez2010 opened 3 weeks ago
The issue here isn't really that there is no "fast path", it's that it's implemented as left - (left / right) * right
when instead it should be computing the remainder as part of the division, where its essentially "free".
The cost is significantly higher with the multi-step process because we have to fallback to a full division and multiplication algorithm.
Tagging subscribers to this area: @dotnet/area-system-numerics See info in area-owners.md if you want to be subscribed.
Description
The modulus operator for
{U}Int128
is too slow:Instead we can provide a fast path by using
DivRem
for cases wheremodulus
falls in the range ofUInt64
. For example:Configuration
.NET 9 Preview 7
Regression?
No
Data
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.1457) 13th Gen Intel Core i7-13700K, 1 CPU, 24 logical and 16 physical cores .NET SDK 9.0.100-preview.7.24407.12 [Host] : .NET 9.0.0 (9.0.24.40507), X64 RyuJIT AVX2 DefaultJob : .NET 9.0.0 (9.0.24.40507), X64 RyuJIT AVX2