/* 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?
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse at rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B