Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Artoria2e5
Copy link

@Artoria2e5 Artoria2e5 commented Nov 9, 2025

The seven base version uses five fewer bases than the twelve-base version. That's 5 fewer binpower calls in the positive case, a 41.7% reduction. Based on that I think including the (very trivial) code for it is worthwhile.

Well, since we're already there, perhaps adding trial division with, say, the first 25 primes would greatly speed up the average case... nope, not going down that path.

Actually we should perhaps do go down that path. That's what every practical implementation does.


Most obvious place to add TD without adding another list of primes is after the (n == a) test. Just return false on (n % a == 0)!

But then you check godbolt gcc 15.2 -O3 and --- what? it's using div? What happened to division by constants being turned to some kind of mul? Turns out it only does that if you put the (n % a == 0) test in a separate loop from the check_composite test. And it never happens at -O2 possibly due to lack of loop unrolling. The more you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant