Relax ulong multiply-shift guards and refresh tests
This commit is contained in:
1 parent
38df505f4f
commit
75586d07b8
3 files changed
+2
-48
No files matched your search
@@ -39,29 +39,6 @@ public class ULongExtensionsMultiplyShiftTests
|
|||||||
result.Should().Be((ulong)expected);
|
result.Should().Be((ulong)expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void MultiplyShiftRightShiftFirst_returns_zero_when_shift_is_large()
|
|
||||||
{
|
|
||||||
ULongExtensions.MultiplyShiftRightShiftFirst(ulong.MaxValue, 123UL, 64).Should().Be(0UL);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(0UL, ulong.MaxValue, -1)]
|
|
||||||
[InlineData(1UL, 1UL, -3)]
|
|
||||||
public void MultiplyShiftRight_throws_when_shift_is_negative(ulong value, ulong multiplier, int shift)
|
|
||||||
{
|
|
||||||
Action act = () => ULongExtensions.MultiplyShiftRight(value, multiplier, shift);
|
|
||||||
|
|
||||||
act.Should().Throw<ArgumentOutOfRangeException>();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(0UL, ulong.MaxValue, -1)]
|
|
||||||
[InlineData(1UL, 1UL, -3)]
|
|
||||||
public void MultiplyShiftRightShiftFirst_throws_when_shift_is_negative(ulong value, ulong multiplier, int shift)
|
|
||||||
{
|
|
||||||
Action act = () => ULongExtensions.MultiplyShiftRightShiftFirst(value, multiplier, shift);
|
|
||||||
|
|
||||||
act.Should().Throw<ArgumentOutOfRangeException>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -59,22 +59,12 @@ public static class ULongExtensions
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int GetBitLength(this ulong value)
|
public static int GetBitLength(this ulong value)
|
||||||
{
|
{
|
||||||
if (value == 0UL)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 64 - BitOperations.LeadingZeroCount(value);
|
return 64 - BitOperations.LeadingZeroCount(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ulong MultiplyShiftRight(ulong value, ulong multiplier, int shift)
|
public static ulong MultiplyShiftRight(ulong value, ulong multiplier, int shift)
|
||||||
{
|
{
|
||||||
if (shift < 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(shift), "Shift must be non-negative.");
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt128 product = (UInt128)value * multiplier;
|
UInt128 product = (UInt128)value * multiplier;
|
||||||
return (ulong)(product >> shift);
|
return (ulong)(product >> shift);
|
||||||
}
|
}
|
||||||
@@ -82,21 +72,6 @@ public static class ULongExtensions
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static ulong MultiplyShiftRightShiftFirst(ulong value, ulong multiplier, int shift)
|
public static ulong MultiplyShiftRightShiftFirst(ulong value, ulong multiplier, int shift)
|
||||||
{
|
{
|
||||||
if (shift < 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentOutOfRangeException(nameof(shift), "Shift must be non-negative.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shift == 0)
|
|
||||||
{
|
|
||||||
return MultiplyShiftRight(value, multiplier, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shift >= 64)
|
|
||||||
{
|
|
||||||
return 0UL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ulong high = value >> shift;
|
ulong high = value >> shift;
|
||||||
ulong mask = (1UL << shift) - 1UL;
|
ulong mask = (1UL << shift) - 1UL;
|
||||||
ulong low = value & mask;
|
ulong low = value & mask;
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
|
- Inline the PrimeOrderGpuHeuristics capability checks at each call site and delete the temporary SupportsPrime/SupportsExponent helpers once the overflow gating is stable.
|
||||||
|
- Swap PrimeOrderGpuHeuristics.Pow2ModCpu for the existing Pow2MontgomeryModWindowed helper and plan the same windowed ladder for the GPU kernel implementation.
|
||||||
- Extend the GPU numeric type probe to cover proposed custom types such as GpuUInt256 and GpuUInt512 once their definitions are available so we can plan the wide-order heuristics on the device.
|
- Extend the GPU numeric type probe to cover proposed custom types such as GpuUInt256 and GpuUInt512 once their definitions are available so we can plan the wide-order heuristics on the device.
|
||||||
Reference in new issue
Block a user