Switch GpuUInt128 internals to in-place shifts
This commit is contained in:
1 parent
50d2e462d7
commit
de8e769f48
1 file changed
+11
-10
@@ -753,7 +753,8 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
|
|||||||
GpuUInt128 remainder = dividend;
|
GpuUInt128 remainder = dividend;
|
||||||
GpuUInt128 shiftedDivisor = divisor;
|
GpuUInt128 shiftedDivisor = divisor;
|
||||||
shiftedDivisor.ShiftLeft(shift);
|
shiftedDivisor.ShiftLeft(shift);
|
||||||
GpuUInt128 quotientBit = One << shift;
|
GpuUInt128 quotientBit = One;
|
||||||
|
quotientBit.ShiftLeft(shift);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -1113,8 +1114,8 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
|
|||||||
// TODO: Can we modify these loops to process multiple bits at a time? E.g. 64-bit chunks.
|
// TODO: Can we modify these loops to process multiple bits at a time? E.g. 64-bit chunks.
|
||||||
for (bit = 63; bit >= 0; bit--)
|
for (bit = 63; bit >= 0; bit--)
|
||||||
{
|
{
|
||||||
remainder <<= 1;
|
remainder.ShiftLeft(1);
|
||||||
remainder = new(remainder.High, remainder.Low | ((p3 >> bit) & 1UL));
|
remainder.Low |= (p3 >> bit) & 1UL;
|
||||||
if (remainder.CompareTo(modulus) >= 0)
|
if (remainder.CompareTo(modulus) >= 0)
|
||||||
{
|
{
|
||||||
remainder.Sub(modulus);
|
remainder.Sub(modulus);
|
||||||
@@ -1123,8 +1124,8 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
|
|||||||
|
|
||||||
for (bit = 63; bit >= 0; bit--)
|
for (bit = 63; bit >= 0; bit--)
|
||||||
{
|
{
|
||||||
remainder <<= 1;
|
remainder.ShiftLeft(1);
|
||||||
remainder = new(remainder.High, remainder.Low | ((p2 >> bit) & 1UL));
|
remainder.Low |= (p2 >> bit) & 1UL;
|
||||||
if (remainder.CompareTo(modulus) >= 0)
|
if (remainder.CompareTo(modulus) >= 0)
|
||||||
{
|
{
|
||||||
remainder.Sub(modulus);
|
remainder.Sub(modulus);
|
||||||
@@ -1133,8 +1134,8 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
|
|||||||
|
|
||||||
for (bit = 63; bit >= 0; bit--)
|
for (bit = 63; bit >= 0; bit--)
|
||||||
{
|
{
|
||||||
remainder <<= 1;
|
remainder.ShiftLeft(1);
|
||||||
remainder = new(remainder.High, remainder.Low | ((p1 >> bit) & 1UL));
|
remainder.Low |= (p1 >> bit) & 1UL;
|
||||||
if (remainder.CompareTo(modulus) >= 0)
|
if (remainder.CompareTo(modulus) >= 0)
|
||||||
{
|
{
|
||||||
remainder.Sub(modulus);
|
remainder.Sub(modulus);
|
||||||
@@ -1143,8 +1144,8 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
|
|||||||
|
|
||||||
for (bit = 63; bit >= 0; bit--)
|
for (bit = 63; bit >= 0; bit--)
|
||||||
{
|
{
|
||||||
remainder <<= 1;
|
remainder.ShiftLeft(1);
|
||||||
remainder = new(remainder.High, remainder.Low | ((p0 >> bit) & 1UL));
|
remainder.Low |= (p0 >> bit) & 1UL;
|
||||||
if (remainder.CompareTo(modulus) >= 0)
|
if (remainder.CompareTo(modulus) >= 0)
|
||||||
{
|
{
|
||||||
remainder.Sub(modulus);
|
remainder.Sub(modulus);
|
||||||
@@ -1173,7 +1174,7 @@ public struct GpuUInt128 : IComparable<GpuUInt128>, IEquatable<GpuUInt128>
|
|||||||
result.MulMod(baseValue, modulus);
|
result.MulMod(baseValue, modulus);
|
||||||
}
|
}
|
||||||
|
|
||||||
exponent >>= 1;
|
exponent.ShiftRight(1);
|
||||||
baseValue.MulMod(baseValue, modulus);
|
baseValue.MulMod(baseValue, modulus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user