___udivdi3

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

___udivdi3

Post 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
Phugoid

Re:___udivdi3

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

Re:___udivdi3

Post by GLneo »

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

Re:___udivdi3

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

Re:___udivdi3

Post 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???
Phugoid

Re:___udivdi3

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:___udivdi3

Post 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)
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:___udivdi3

Post 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.
nully
Posts: 6
Joined: Thu Nov 29, 2007 9:56 pm
Location: Perth, Western Australia
Contact:

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Why bump a three year old thread??
nully
Posts: 6
Joined: Thu Nov 29, 2007 9:56 pm
Location: Perth, Western Australia
Contact:

Post by nully »

because it became relevant to me 3 days ago,
grigori
Posts: 1
Joined: Sat Jul 16, 2011 12:06 am

Re: ___udivdi3

Post 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
Last edited by thepowersgang on Tue Feb 21, 2017 11:01 pm, edited 4 times in total.
Reason: spamspamspamspam
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: ___udivdi3

Post by piranha »

Next level old thread bump maneuver.

Actually (hahaha)...
JamesM...in this very thread... wrote:Why bump a three year old thread??
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: ___udivdi3

Post by xenos »

Guess what will happen 3 years from now...
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
zesterer
Member
Member
Posts: 59
Joined: Mon Feb 22, 2016 4:40 am
Libera.chat IRC: zesterer
Location: United Kingdom
Contact:

Re: ___udivdi3

Post 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.
Current developing Tupai, a monolithic x86 operating system
http://zesterer.homenet.org/projects.shtml
Post Reply