Page 1 of 1

__umoddi3 error

Posted: Sat Jan 19, 2008 10:29 am
by AlfaOmega08
I'm writing down a pit driver.
about each 18 ticks, a second is past.

If i put

Code: Select all

if (ticks % 18 == 0) {
      puts("one second has past\n");
}
ticks is an unsigned long long

when linking. I've the following error:
undefined reference to `__umoddi3'

if I put only

Code: Select all

puts("the pit has fired\n");
it works!!!

so the "if (ticks % 18 == 0)" create the problem...

why?

Posted: Sat Jan 19, 2008 11:14 am
by Brynet-Inc
Looks like you're trying to do 64bit arithmetic, the support functions for that are in libgcc...
(umoddi3 for multiplication and udivdi3 for division..)

I'm not entirely sure what licence libgcc is under, so personally I keep away from it.. ;)

A BSD/ISC licenced implementation exists though...
http://www.openbsd.org/cgi-bin/cvsweb/s ... libc/quad/

Good luck 8)

Posted: Sat Jan 19, 2008 12:31 pm
by JamesM
Either: Don't do 64 bit division, or add "-lgcc" at the end of your linker line.

Posted: Sat Jan 19, 2008 12:55 pm
by Cemre
I am curious... ( out of subject )
why doesn't gcc developpers include native support for "mod" or "div" for 64bit numbers ?

Posted: Sat Jan 19, 2008 1:14 pm
by Brynet-Inc
Cemre wrote:I am curious... ( out of subject )
why doesn't gcc developpers include native support for "mod" or "div" for 64bit numbers ?
http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html wrote:Most of the routines in libgcc handle arithmetic operations that the target processor cannot perform directly.
So I'm assuming on 64bit architectures, it might not even be used at all....

Does anyone here know for sure? :?

Posted: Sat Jan 19, 2008 1:52 pm
by Korona
Inlining 64 bit multiplication and division code would produce very huge code, so gcc inserts a call to its library instead. On amd64 cpus gcc produces usual div and mul instructions. 64 bit addition and substraction is always inlined.

Posted: Sat Jan 19, 2008 2:51 pm
by lukem95
you should change the frequency to get a more accurate timer.

i use 100, one every ms. ABOUT 18 isnt very accurate.