It was thus said that the Great der Mouse once stated:
/* q = q
>> 3 */
/* skipped because not needed */
/* r = n - ((q << 3) + (q << 1)) */
q' = q;
q' >>= 1;
q' >>= 1;
q += q'
r = n - q;
You give no justification for the algorithm change here ((q>>3)<<3 is
not, in general, equal to q). Did you just test and find it worked for
the argument range of interest, or what?
I saw
q >> 3
q << 3
And figured it wasn't needed. But you're right, it's not quite the same,
but I would think that:
/* q = q >> 3 */
/* shift skipped because not needed */
/* r = n - ((q << 3) + (q << 1) */
q' = q & ~3;
q' >>= 1;
q' >>= 1;
q += q'
r = n - q;
But as I did the work, I found out that this wasn't all that great on a
Z80 anyway, even if it did work as I wrote it.
-spc