OSDev.org
https://forum.osdev.org/

___udivdi3
https://forum.osdev.org/viewtopic.php?f=1&t=10783
Page 1 of 2

Author:  GLneo [ Thu Aug 11, 2005 5:25 pm ]
Post subject:  ___udivdi3

hi all, when ever i compile this line:
Code:
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

Author:  Phugoid [ Thu Aug 11, 2005 5:29 pm ]
Post subject:  Re:___udivdi3

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).

Author:  GLneo [ Thu Aug 11, 2005 5:40 pm ]
Post subject:  Re:___udivdi3

thx, helper funtion makes sence, but how do i fix it???

Author:  AR [ Thu Aug 11, 2005 5:46 pm ]
Post subject:  Re:___udivdi3

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).

Author:  GLneo [ Thu Aug 11, 2005 5:55 pm ]
Post subject:  Re:___udivdi3

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:
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???

Author:  Phugoid [ Thu Aug 11, 2005 5:59 pm ]
Post subject:  Re:___udivdi3

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.

Author:  Pype.Clicker [ Fri Aug 12, 2005 1:17 am ]
Post subject:  Re:___udivdi3

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)

Author:  nick8325 [ Fri Aug 12, 2005 5:19 am ]
Post subject:  Re:___udivdi3

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.

Author:  nully [ Sat Jan 12, 2008 10:30 pm ]
Post subject: 

the way i have done it (in a shell script) is to go

Code:
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.

Author:  JamesM [ Sun Jan 13, 2008 11:03 am ]
Post subject: 

Why bump a three year old thread??

Author:  nully [ Sun Jan 13, 2008 11:12 pm ]
Post subject: 

because it became relevant to me 3 days ago,

Author:  grigori [ Sat Jul 16, 2011 12:10 am ]
Post subject:  Re: ___udivdi3

GLneo wrote:
hi all, when ever i compile this line:
Code:
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

Author:  piranha [ Sat Jul 16, 2011 12:16 am ]
Post subject:  Re: ___udivdi3

Next level old thread bump maneuver.

Actually (hahaha)...
JamesM...in this very thread... wrote:
Why bump a three year old thread??


-JL

Author:  xenos [ Sat Jul 16, 2011 12:58 am ]
Post subject:  Re: ___udivdi3

Guess what will happen 3 years from now...

Author:  zesterer [ Tue Feb 21, 2017 5:33 pm ]
Post subject:  Re: ___udivdi3

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.

Page 1 of 2 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/