diff --git a/EvenPerfectBitScanner.Tests/ProgramTests.cs b/EvenPerfectBitScanner.Tests/ProgramTests.cs index 71408d1..785f2b4 100644 --- a/EvenPerfectBitScanner.Tests/ProgramTests.cs +++ b/EvenPerfectBitScanner.Tests/ProgramTests.cs @@ -6,6 +6,7 @@ using PerfectNumbers.Core.Gpu; using EvenPerfectBitScanner.Candidates; using EvenPerfectBitScanner.Candidates.Transforms; +using System.Numerics; namespace EvenPerfectBitScanner.Tests; @@ -15,7 +16,7 @@ public class ProgramTests [Fact] public void CountOnes_returns_correct_count() { - Program.CountOnes(0b101010UL).Should().Be(3UL); + (ulong)BitOperations.PopCount(0b101010UL).Should().Be(3UL); } [Theory] diff --git a/EvenPerfectBitScanner/Program.cs b/EvenPerfectBitScanner/Program.cs index 1b6ab17..79eb23e 100644 --- a/EvenPerfectBitScanner/Program.cs +++ b/EvenPerfectBitScanner/Program.cs @@ -546,7 +546,7 @@ internal static class Program } } - + // TODO: Move this to a new static class CalculationResultsFile under IO namespace / folder. Rename it to LoadCandidatesWithinRange. private static List LoadByDivisorCandidates(string candidateFile, UInt128 maxPrimeLimit, bool maxPrimeConfigured, out int skippedByLimit) { List candidates = []; @@ -582,6 +582,7 @@ internal static class Program { index++; } + if (Utf8CliParser.TryParseUInt64(span[start..index], out ulong parsed)) { if (!maxPrimeConfigured || (UInt128)parsed <= maxPrimeLimit) @@ -599,6 +600,7 @@ internal static class Program return candidates; } + // TODO: Move this to a new static class CalculationResultsFile under IO namespace / folder. Rename it to EnumerateCandidates. private static void LoadResultsFile(string resultsFileName, Action lineProcessorAction) { using FileStream readStream = new(resultsFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); @@ -658,6 +660,7 @@ internal static class Program } } + // TODO: Move this to a new static class CalculationResultsFile under IO namespace / folder. Rename it to BuildFileName. private static string BuildResultsFileName(bool bitInc, int threads, int block, GpuKernelType kernelType, bool useLucasFlag, bool useDivisorFlag, bool useByDivisorFlag, bool mersenneOnGpu, bool useOrder, bool useGcd, NttBackend nttBackend, int gpuPrimeThreads, int llSlice, int gpuScanBatch, ulong warmupLimit, ModReductionMode reduction, string mersenneDevice, string primesDevice, string orderDevice) { string inc = bitInc ? "bit" : "add"; @@ -731,16 +734,6 @@ internal static class Program } } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static ulong CountOnes(ulong value) - { - // TODO: Remove this wrapper once callers can invoke BitOperations.PopCount directly so the hot bit-stat path - // avoids the extra call layer. - return (ulong)BitOperations.PopCount(value); - } - - internal static bool IsEvenPerfectCandidate(ulong p, ulong divisorCyclesSearchLimit, out bool searchedMersenne, out bool detailedCheck) { searchedMersenne = false; @@ -824,6 +817,7 @@ internal static class Program return detailedCheck; } + // TODO: Move this together with the tracker to existing CandidatesCalculator class in the Candidates folder. // Use ModResidueTracker with a small set of primes to pre-filter composite p. private static bool IsCompositeByResidues(ulong p) {