!pr1
Updating the 6502 Prime Sifter.............Bob Sander-Cederlof

I spent a half day applying Peter's algorithm improvements to the November 1982 6502 version, and refining the program as much as I could.  It now runs in 175 milliseconds per iteration, or 1000 iterations in 175 seconds.  Still way behind the 68000, of course.  On the other hand, a 6MHz 6502, with fast enough RAM for no wait states, would be faster than a 12.5 MHz 68000.  And it remains to be seen what the 65802 could do.

In the process of running various versions and various tests, I discovered that the innermost loop, at lines 1820-1850, is executed 10277 times.  This means that, while marking out the odd non-primes between 1 and 16383, a total of 10277 such marks are made.  Since only odd numbers are assigned slots in the working array, giving only 8192 such slots, you can see that some numbers get stricken more than once.  These are the numbers with more than one prime factor.  The most-stricken number is 3*5*7*11*13 = 15015, which gets five strikes.  The loop takes 11 cycles as written, and I don't see any way to shorten it any further or to reduce the number of times it is used.  Do you?

The loop time is 11*10277 is 121297 cycles, or about 120 msec out of the total 175.  The array clearing accounts for another 41 msecs, leaving only 14 msec for all the rest of the program.  Not bad!

Here is a little Applesoft program which will make a nice neat listing of primes from the working array, assuming it runs from $6000 through $7FFF.

!lm+5
100 HIMEM:24576
110 FOR A = 24576 TO 32767
120 IF PEEK (A) = 0 THEN
    PRINT RIGHT$("     "+STR$((A-24576)*2+1,7);:
    N = N + 1
130 IF N = 10 THEN PRINT : N = 0
140 NEXT
!lm-5

