[chbot] Very OT - Fast division on hardware without a hardware divider....

hamster hamster at snap.net.nz
Wed Oct 26 04:08:22 BST 2011


I found something that might be of interest to members of this group who
use low end micro-controllers or are fiddling with FPGAs)

The pdf at http://www.hackersdelight.org/divcMore.pdf contains many ways
to perform speedy division using bitshifts... 

unsigned divu7(unsigned n) {
   unsigned q, r;
   q = (n >> 1) + (n >> 4);
   q = q + (q >> 6);
   q = q + (q>>12) + (q>>24);
   q = q >> 2;
   r = n - q*7;
   return q + (r > 6);
}

As an aside, if anybody can make a better way to divide integers than "SRT
Division" you could get very rich very quick - I didn't realise it takes
30+ clock cycles for a 64 bit divide... 

Mike





More information about the Chchrobotics mailing list