Use bit masks for divisor heuristics

This commit is contained in:
Marek Lemańczyk committed 2025-10-24 19:50:27 +02:00
1 parent 46a2178d65
commit bbe0c02069
6 files changed
+83 -43

No files matched your search

@@ -188,7 +188,9 @@ internal static partial class PrimeOrderCalculator
private static ulong InitializeStartingOrderCpu(ulong prime, ulong phi, in MontgomeryDivisorData divisorData)
{
ulong order = phi;
if ((prime & 7UL) == 1UL || (prime & 7UL) == 7UL)
const int AcceptablePrimeResidueMask = (1 << 1) | (1 << 7);
int residue = (int)(prime & 7UL);
if (((AcceptablePrimeResidueMask >> residue) & 1) != 0)
{
ulong half = phi >> 1;
if (Pow2EqualsOneCpu(half, prime, divisorData))