Align bit transform comments with original implementation

This commit is contained in:
Marek Lemańczyk committed 2025-10-19 00:54:58 +02:00
1 parent 7f468de485
commit 56c8e84c19
8 files changed
+417 -370

No files matched your search

@@ -0,0 +1,30 @@
using System.Runtime.CompilerServices;
using System.Threading;
using EvenPerfectBitScanner.Candidates;
namespace EvenPerfectBitScanner.Candidates.Transforms;
internal static class CandidateAddTransform
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static ulong Transform(ulong value, ref ulong remainder, ref bool limitReached)
{
ulong next = value;
ulong diff = remainder.GetNextAddDiff();
if (next > ulong.MaxValue - diff)
{
Volatile.Write(ref limitReached, true);
return next;
}
remainder += diff;
// Retain direct modulo because the Mod6 helper underperforms on 64-bit operands.
while (remainder >= 6UL)
{
remainder -= 6UL;
}
return next + diff;
}
}