Page 1 of 2
___udivdi3
Posted: Thu Aug 11, 2005 5:25 pm
by GLneo
hi all, when ever i compile this line:
Code: Select all
unsigned long long start = 0, end = 0, result;
result = (end - start) / 50000;
djgpp says: undifind reference to `___udivdi3 '
i've found it only happends when i divide???, thx
Re:___udivdi3
Posted: Thu Aug 11, 2005 5:29 pm
by Phugoid
Helper function again... this one for dividing 64-bit integers. What a coincidence that you asked this while I was replying to the other thread (
http://www.mega-tokyo.com/forum/index.php?board=1;action=display;threadid=8177).
Re:___udivdi3
Posted: Thu Aug 11, 2005 5:40 pm
by GLneo
thx, helper funtion makes sence, but how do i fix it???
Re:___udivdi3
Posted: Thu Aug 11, 2005 5:46 pm
by AR
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).
Re:___udivdi3
Posted: Thu Aug 11, 2005 5:55 pm
by GLneo
implement the division manually! thats what I want to do, but how?, i gess i could make a function "div32()" but how to make the function?
Code: Select all
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;
}
am i even close???
Re:___udivdi3
Posted: Thu Aug 11, 2005 5:59 pm
by Phugoid
Run, using a calculator, a few test cases and watch them (fail). Then pick up a pencil and some paper and make it work right, with a little ingenuity.
You will need to give the routine the name DJGPP expects it to have.
Re:___udivdi3
Posted: Fri Aug 12, 2005 1:17 am
by Pype.Clicker
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)
Re:___udivdi3
Posted: Fri Aug 12, 2005 5:19 am
by nick8325
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.
Posted: Sat Jan 12, 2008 10:30 pm
by nully
the way i have done it (in a shell script) is to go
Code: Select all
LIBGCC_FILENAME=$(gcc --print-libgcc-file-name)
...build c objects etc...
ld -nostdlib -g -T link.ld -o kernel.o <other object files> $LIBGCC_FILENAME
(note link.ld is your link script)
libgcc contains all the long long math you should need.
replace gcc with your cross-compiler gcc if you have one.
Posted: Sun Jan 13, 2008 11:03 am
by JamesM
Why bump a three year old thread??
Posted: Sun Jan 13, 2008 11:12 pm
by nully
because it became relevant to me 3 days ago,
Re: ___udivdi3
Posted: Sat Jul 16, 2011 12:10 am
by grigori
GLneo wrote:hi all, when ever i compile this line:
Code: Select all
unsigned long long start = 0, end = 0, result;
result = (end - start) / 50000;
djgpp says: undifind reference to `___udivdi3 '
i've found it only happends when i divide???, thx
No compitable for 64bit )
spam removed
Re: ___udivdi3
Posted: Sat Jul 16, 2011 12:16 am
by piranha
Next level old thread bump maneuver.
Actually (hahaha)...
JamesM...in this very thread... wrote:Why bump a three year old thread??
-JL
Re: ___udivdi3
Posted: Sat Jul 16, 2011 12:58 am
by xenos
Guess what will happen 3 years from now...
Re: ___udivdi3
Posted: Tue Feb 21, 2017 5:33 pm
by zesterer
XenOS wrote:Guess what will happen 3 years from now...
You were wrong. 6 years. Boo. I'm searching for a solution to this problem too.