**Subject:** 64 bit by 16 bit divide.

**To:** None *<tech-kern@netbsd.org>*

**From:** Wojciech Puchar *<wojtek@tensor.3miasto.net>*

**List:** tech-kern

**Date:** 04/10/2003 12:57:37
how about this?
AFAIK boot loaders procedures needs to divide 64-bit value by not-as-large
value (16-bit should be enough).
in this case below works giving much less than 100 byte code which is
enough fast. as least on CPU that has 32 by 16 division (i386).
unsigned long long div6416(unsigned long long value,unsigned short divisor) {
unsigned tmp=0,a=4;
unsigned long long result=0;
while(a--) {
tmp+=(value>>48);
value<<=16;
result=(result<<16)|(tmp/divisor);
tmp=(tmp%divisor)<<16;
}
return result;
}
#include <stdio.h>
main() {
printf("%qu\n",div6416(1000000000000LL,10000));}