Help. I cant find source for avr-libc function __divdi3

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried doing a 64-Bit divide using long long variables, my hex file grew by about 5Kand no longer fits in my mega169, in my search to find out why, it looks as though __divdi3 is called.

I have a early copy of the avr-libc source (avr-libc-20011126) but CVS, particularly the SSH connection part of it is preventing me from obtaining an up to date copy.

Quote:
cvs -z3 -d:ext:anoncvs@savannah.gnu.org:/cvsroot/avr-libc co avr-libc
cvs [checkout aborted]: the :ext: access method is not installed on this system

Does anyone know which file contains commented source for the __divdi3 function?

Nigel

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Nigel

Couldnt the "source" be helpfull :-)

I dont think there has been any major changes since 1.2.3 , and CVS chsckout might not be needed

Source
http://savannah.nongnu.org/downl...

PDF Manual
http://savannah.nongnu.org/downl...

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Bingo,

Tar very much. Ha Ha

That link was far easier than messing about with CVS.

Unfortunately I still cannot find any source references to divdi3 or indeed any other maths functions like udivmodsi4.

I might have to give up and decipher the raw LSS file instead.

Nigel

PS I don't understand your

Quote:
Couldnt the "source" be helpfull
comment ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The divdi3 function actually comes from GCC. GCC has a small library, libgcc. For the avr it usually contains a bunch of low level math functions. So you'll have to go look at the GCC sources for this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

EW wrote:
The divdi3 function actually comes from GCC. GCC has a small library, libgcc. For the avr it usually contains a bunch of low level math functions. So you'll have to go look at the GCC sources for this.

Oopzzz

So we have a avr-libc , and a libgcc :oops: :oops:

Dammm , knew i should havent shipped reading the full "GCC Source" :? :?

Well thanx EW for saving me again :lol: :lol:

/Bingo

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well this has been a learning exercise !

I downloaded a snapshot "gcc-core-3.4-20050225.tar.bz2" from one of the few mirrors which actually responded in a timely manner.

In libgcc2.c I found:

#ifdef L_divdi3
DWtype
__divdi3 (DWtype u, DWtype v)
{
  word_type c = 0;
  DWunion uu = {.ll = u};
  DWunion vv = {.ll = v};
  DWtype w;

  if (uu.s.high < 0)
    c = ~c,
    uu.ll = -uu.ll;
  if (vv.s.high < 0)
    c = ~c,
    vv.ll = -vv.ll;

  w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
  if (c)
    w = -w;

  return w;
}
#endif

This function is actually written in C. This goes some way to explain why my code grew so abominally. Some targets have this routine written in assembly using various methods but AVR doesn't so I'll have to "roll my own"

Nigel

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want to be completely accurate you need to get the released version of gcc, version 3.4.3. What you have is a recent snapshot of the 3.4 branch, which is sometime after that release. Though I doubt that the code has actually changed for that function.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And of course, if you come up with an assembler implementation of it,
submit it to the GCC folks for inclusion.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And one way to do that is to compile it, then go and hand optimize the assembly. Be sure that it follows the AVR GCC ABI as listed in the avr-libc user manual (as a FAQ item).