It might be worth building a new table based on a more efficient algorithm. With that in mind, I've taken the approach from one of my recent posts and reimplemented it in C, with a slightly different approach to the task being measured. The differences from the original are:
- Instead of using every odd integer as trial divisors, a list of actual primes is kept. The complete set of 16-bit primes can easily be stored in about 13KB, which is still small enough for most 8-bit micros, and this permits testing primality relatively efficiently on any 32-bit integer.
- Instead of searching for gaps of particular sizes, the program lists all maximal prime gaps in the 32-bit integer range, and also notes how long it took to reach each one. The times printed are cumulative, so they can be compared with other approaches to the same problem.
The complete run takes about an hour and a half on my Sandy Bridge based MacBook Pro. It also takes several hours on my Raspberry Pi - so it's feasible to run overnight. Small 8-bit and 16-bit machines are unlikely to be able to perform a complete run, but they can be stopped after producing whatever they are capable of. And the algorithm is simple enough to implement in BASIC or assembly, though most BASICs will use double the memory that C does to store the list of small primes.
In the C source, I've provided programmatic hints for implementing an assembly version to use a 32/16 bit divide instruction efficiently. I suspect most C compilers for small machines won't do a good job of that by themselves. Modern CPUs can produce a 32-bit quotient without triggering overflow semantics, so don't need that special assistance.
Sample output:
Code:
Maxgap 1: 3 - 2, 0.000 sec
Maxgap 2: 5 - 3, 0.000 sec
Maxgap 4: 11 - 7, 0.000 sec
Maxgap 6: 29 - 23, 0.000 sec
Maxgap 8: 97 - 89, 0.000 sec
Maxgap 14: 127 - 113, 0.000 sec
Maxgap 18: 541 - 523, 0.000 sec
Maxgap 20: 907 - 887, 0.000 sec
Maxgap 22: 1151 - 1129, 0.000 sec
Maxgap 34: 1361 - 1327, 0.000 sec
Maxgap 36: 9587 - 9551, 0.000 sec
Maxgap 44: 15727 - 15683, 0.000 sec
Maxgap 52: 19661 - 19609, 0.001 sec
Maxgap 72: 31469 - 31397, 0.001 sec
Found 6542 16-bit primes in 0.002 secs.
Maxgap 86: 156007 - 155921, 0.006 sec
Maxgap 96: 360749 - 360653, 0.017 sec
Maxgap 112: 370373 - 370261, 0.018 sec
Maxgap 114: 492227 - 492113, 0.026 sec
Maxgap 118: 1349651 - 1349533, 0.100 sec
Maxgap 132: 1357333 - 1357201, 0.100 sec
Maxgap 148: 2010881 - 2010733, 0.165 sec
Maxgap 154: 4652507 - 4652353, 0.508 sec
Maxgap 180: 17051887 - 17051707, 2.941 sec
Maxgap 210: 20831533 - 20831323, 3.873 sec
Maxgap 220: 47326913 - 47326693, 11.763 sec
Maxgap 222: 122164969 - 122164747, 42.470 sec
Maxgap 234: 189695893 - 189695659, 77.317 sec
Maxgap 248: 191913031 - 191912783, 78.493 sec
Maxgap 250: 387096383 - 387096133, 203.349 sec
Maxgap 282: 436273291 - 436273009, 239.639 sec
Maxgap 288: 1294268779 - 1294268491, 1087.127 sec
Maxgap 292: 1453168433 - 1453168141, 1274.887 sec
Maxgap 320: 2300942869 - 2300942549, 2399.465 sec
Maxgap 336: 3842611109 - 3842610773, 4813.874 sec
Reached end of 32-bit integer space, in 5623.393 secs.
Noteworthy in the above is that my MBP finds 16-bit primes faster than a BBC Micro's CPU clock ticks!