Remove heuristic hooks from PrimeTester
This commit is contained in:
1 parent
c01abbd03a
commit
9bc8fd5043
2 files changed
-120
No files matched your search
@@ -142,12 +142,6 @@ public sealed class MersenneNumberDivisorByDivisorCpuTester : IMersenneNumberDiv
|
|||||||
if (divisor.CompareTo(limit) > 0)
|
if (divisor.CompareTo(limit) > 0)
|
||||||
{
|
{
|
||||||
processedAll = true;
|
processedAll = true;
|
||||||
divisor.High = 0UL;
|
|
||||||
divisor.Low = 0UL;
|
|
||||||
step.High = 0UL;
|
|
||||||
step.Low = 0UL;
|
|
||||||
limit.High = 0UL;
|
|
||||||
limit.Low = 0UL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,12 +222,6 @@ public sealed class MersenneNumberDivisorByDivisorCpuTester : IMersenneNumberDiv
|
|||||||
{
|
{
|
||||||
// A cycle equal to the tested exponent (which is prime in this path) guarantees that the candidate divides
|
// A cycle equal to the tested exponent (which is prime in this path) guarantees that the candidate divides
|
||||||
// the corresponding Mersenne number because the order of 2 modulo the divisor is exactly p.
|
// the corresponding Mersenne number because the order of 2 modulo the divisor is exactly p.
|
||||||
divisor.High = 0UL;
|
|
||||||
divisor.Low = 0UL;
|
|
||||||
step.High = 0UL;
|
|
||||||
step.Low = 0UL;
|
|
||||||
limit.High = 0UL;
|
|
||||||
limit.Low = 0UL;
|
|
||||||
processedAll = true;
|
processedAll = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -254,12 +242,6 @@ public sealed class MersenneNumberDivisorByDivisorCpuTester : IMersenneNumberDiv
|
|||||||
}
|
}
|
||||||
|
|
||||||
processedAll = divisor.CompareTo(limit) > 0;
|
processedAll = divisor.CompareTo(limit) > 0;
|
||||||
divisor.High = 0UL;
|
|
||||||
divisor.Low = 0UL;
|
|
||||||
step.High = 0UL;
|
|
||||||
step.Low = 0UL;
|
|
||||||
limit.High = 0UL;
|
|
||||||
limit.Low = 0UL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,108 +103,6 @@ public sealed class PrimeTester
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal readonly struct HeuristicDivisorCandidate
|
|
||||||
{
|
|
||||||
private readonly HeuristicPrimeTester.HeuristicDivisorCandidate _inner;
|
|
||||||
|
|
||||||
internal HeuristicDivisorCandidate(HeuristicPrimeTester.HeuristicDivisorCandidate inner)
|
|
||||||
{
|
|
||||||
_inner = inner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ulong Value => _inner.Value;
|
|
||||||
|
|
||||||
public HeuristicPrimeTester.HeuristicDivisorGroup Group => _inner.Group;
|
|
||||||
|
|
||||||
public byte Ending => _inner.Ending;
|
|
||||||
|
|
||||||
public byte PriorityIndex => _inner.PriorityIndex;
|
|
||||||
|
|
||||||
public ushort WheelResidue => _inner.WheelResidue;
|
|
||||||
|
|
||||||
internal HeuristicPrimeTester.HeuristicDivisorCandidate AsHeuristic() => _inner;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal readonly struct HeuristicDivisorPreparation
|
|
||||||
{
|
|
||||||
private readonly HeuristicPrimeTester.HeuristicDivisorPreparation _inner;
|
|
||||||
|
|
||||||
internal HeuristicDivisorPreparation(HeuristicPrimeTester.HeuristicDivisorPreparation inner)
|
|
||||||
{
|
|
||||||
_inner = inner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HeuristicDivisorCandidate Candidate => new(_inner.Candidate);
|
|
||||||
|
|
||||||
public MontgomeryDivisorData DivisorData => _inner.DivisorData;
|
|
||||||
|
|
||||||
public ulong CycleLengthHint => _inner.CycleLengthHint;
|
|
||||||
|
|
||||||
public bool HasCycleLengthHint => _inner.HasCycleLengthHint;
|
|
||||||
|
|
||||||
public bool RequiresCycleComputation => _inner.RequiresCycleComputation;
|
|
||||||
|
|
||||||
internal HeuristicPrimeTester.HeuristicDivisorPreparation AsHeuristic() => _inner;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal ref struct MersenneHeuristicDivisorEnumerator
|
|
||||||
{
|
|
||||||
private HeuristicPrimeTester.MersenneHeuristicDivisorEnumerator _inner;
|
|
||||||
|
|
||||||
public MersenneHeuristicDivisorEnumerator(ulong exponent, ulong maxDivisor)
|
|
||||||
{
|
|
||||||
_inner = HeuristicPrimeTester.CreateMersenneDivisorEnumerator(exponent, maxDivisor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ulong ProcessedCount => _inner.ProcessedCount;
|
|
||||||
|
|
||||||
public ulong LastDivisor => _inner.LastDivisor;
|
|
||||||
|
|
||||||
public bool Exhausted => _inner.Exhausted;
|
|
||||||
|
|
||||||
public bool TryGetNext(out HeuristicDivisorCandidate candidate)
|
|
||||||
{
|
|
||||||
if (_inner.TryGetNext(out var innerCandidate))
|
|
||||||
{
|
|
||||||
candidate = new HeuristicDivisorCandidate(innerCandidate);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
candidate = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
internal static MersenneHeuristicDivisorEnumerator CreateMersenneDivisorEnumerator(ulong exponent, ulong maxDivisor)
|
|
||||||
{
|
|
||||||
return new MersenneHeuristicDivisorEnumerator(exponent, maxDivisor);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
internal static HeuristicDivisorPreparation PrepareHeuristicDivisor(in HeuristicDivisorCandidate candidate)
|
|
||||||
{
|
|
||||||
var innerCandidate = candidate.AsHeuristic();
|
|
||||||
var preparation = HeuristicPrimeTester.PrepareHeuristicDivisor(in innerCandidate);
|
|
||||||
return new HeuristicDivisorPreparation(preparation);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
internal static ulong ResolveHeuristicCycleLength(
|
|
||||||
ulong exponent,
|
|
||||||
in HeuristicDivisorPreparation preparation,
|
|
||||||
out bool cycleFromHint,
|
|
||||||
out bool cycleComputed,
|
|
||||||
out bool primeOrderFailed)
|
|
||||||
{
|
|
||||||
var innerPreparation = preparation.AsHeuristic();
|
|
||||||
return HeuristicPrimeTester.ResolveHeuristicCycleLength(
|
|
||||||
exponent,
|
|
||||||
in innerPreparation,
|
|
||||||
out cycleFromHint,
|
|
||||||
out cycleComputed,
|
|
||||||
out primeOrderFailed);
|
|
||||||
}
|
|
||||||
public static int GpuBatchSize { get; set; } = 262_144;
|
public static int GpuBatchSize { get; set; } = 262_144;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
Reference in new issue
Block a user