Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
long long div32(long long first, long long second)
{
int dlow, dhigh, ret;
dlow = (long)first / (long)second;
dhigh = (long)first >> 32 / (long)second >> 32;
ret = ???;
return ret;
}
some hints :
- you may have two 64 bits quantities, but their difference is always 32 bits (e.g. that could be the case if your computing something out of RDTSC, for instance). In that case, just cast the difference to an (unsigned long) and you'll be fine.
- you may have a divisor that is 2^n * m in which case you can shift by n before you actually divide by m
otherwise try to put it as (m*4GB + n) / D == (m/D) * 4GB + (n/D), which should ease further transformations (beware, this is true only if you're operating on real numbers)
AR wrote:
You need to either implement the division manually or not use a 64bit division - you can try explicitly casting the 50000 to "unsigned long"(32bit).
You can also link against libgcc.a, which should contain that function. For DJGPP I think it's in <DJGPP DIR>\lib\gcc\djgpp\<gcc version>\libgcc.a. Something like that anyway. Put that as the last file in the link command, and you won't need to write your own ___udivdi3.