PrimeOrderCalculator.Cpu cleaned up - hybrid & GPU related methods moved to their corresponding files.

This commit is contained in:
mlemanczyk committed 2025-12-11 00:00:12 +01:00
1 parent 5df2cc7f9b
commit 131b3265bc
5 files changed
+1304 -1301

No files matched your search

@@ -0,0 +1,39 @@
using System.Runtime.CompilerServices;
namespace PerfectNumbers.Core;
internal static partial class PrimeOrderCalculator
{
internal readonly struct PrimeOrderCalculatorConfig(uint smallFactorLimit, int pollardRhoMilliseconds, int maxPowChecks, bool strictMode)
{
private static PrimeOrderCalculatorConfig _heuristicDefault = CreateHeuristicDefault(UnboundedTaskScheduler.ConfiguredThreadCount);
public static PrimeOrderCalculatorConfig HeuristicDefault
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => _heuristicDefault;
}
public static readonly PrimeOrderCalculatorConfig StrictDefault = new(smallFactorLimit: 1_000_000, pollardRhoMilliseconds: 0, maxPowChecks: 0, true);
public static void ConfigureHeuristicDefault(int threadCount)
{
_heuristicDefault = CreateHeuristicDefault(threadCount);
}
public static PrimeOrderCalculatorConfig CreateHeuristicDefault(int threadCount)
{
int normalizedThreadCount = threadCount < 1 ? 1 : threadCount;
return new(smallFactorLimit: 100_000, pollardRhoMilliseconds: normalizedThreadCount * 24, maxPowChecks: 24, false);
}
public readonly uint SmallFactorLimit = smallFactorLimit;
public readonly int PollardRhoMilliseconds = pollardRhoMilliseconds;
public readonly int MaxPowChecks = maxPowChecks;
public readonly int MaxPowChecksCapacity = maxPowChecks << 2;
public readonly bool StrictMode = strictMode;
}
// TODO: Remove branching on the CPU / GPU paths
// TODO: Split big non-static functions into smaller / extract static code to limit JIT time
}