whose 8051 cc overlays static inline stack frames - Page 2

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: whose 8051 cc overlays static inline stack frames
Quoted text here. Click to load it


(-- top-posting corrected, TV --)

Quoted text here. Click to load it
of
to

Before you devote a considerable amount of effort into this optimisation,
check compiler writer's literature for 'tail recursion'. It's a well-known
method.

If there are separate stack frames for the functions, the advantage of the
tail recursion gets questionable due to the effort needed for stack
maintenenace.

HTH

Tauno Voipio
tauno voipio @ iki fi



Re: whose 8051 cc overlays static inline stack frames
Quoted text here. Click to load it

However, Fortran folk often choose to annoy Lisp folk by not
translating tail calls as a form of goto, no matter how academically
well known the equivalence has been since the 1950's Fortran/ Lisp
split.

What brought Me to c.a.e. was comp.lang.forth talk of a claim I
inferred from cuj, specifically: gcc is only now (2004!!) learning to
see tail calls as goto's:

---
http://groups.google.com/groups?threadm26%95edf1.0401121022.33c95ecd%40posting.google.com
Newsgroups: comp.lang.forth
We've slightly trimmed the long signature. Click to see the full one.
Re: whose 8051 cc overlays static inline stack frames

Quoted text here. Click to load it

That's crap.  I checked for and found that GCC handled tail recursive calls
properly in 1996.  Likely it handled them correctly before then, but I never
checked it them before them.  x86 code generator, although it shouldn't make
a difference...

Kelly



Re: whose 8051 cc overlays static inline stack frames
Quoted text here. Click to load it

1) How do you define "handled ... properly"?

2) Not all tail calls are recursive.  Did you check only tail
recursive calls?

comp.lang.forth more specifically said:

---

[M. Anton] Ertl ...

http://www.complang.tuwien.ac.at/forth/threaded-code.html

We've slightly trimmed the long signature. Click to see the full one.
Re: whose 8051 cc overlays static inline stack frames

Quoted text here. Click to load it

It's been a few years, but I believe my test function was:

int factHelper( int x, int acc ) {
  return factHelper( x-1, x*acc );
}

I was checking to make sure GCC correctly implemented the tail recursive
call as a branch.  It did so for -O3 and -O4.

I was only checking for proper handling of tail recursive calls.  If you
care about tail calls in general, your mileage may vary.

After spending the better part of a decade using GCC, using the usual
compilers for 8-bit embedded chips has been a let down.

Kelly



Re: whose 8051 cc overlays static inline stack frames
Quoted text here. Click to load it

Clear now, thank you.

Quoted text here. Click to load it

Do you have any concrete examples?  I ask because I know the feeling,
but I did not retain my examples.

Pat LaVarre

Re: whose 8051 cc overlays static inline stack frames

Quoted text here. Click to load it

I've been doing my recent work on a Rabbit using Dynamic C.  There's no
optimization beyond simple expressions as near as I can tell.

Kelly



Re: whose 8051 cc overlays static inline stack frames
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it

How can you compare translations of invalid source?

--
Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.
Re: whose 8051 cc overlays static inline stack frames
Quoted text here. Click to load it
... snip ...
Quoted text here. Click to load it

Hunh?  One or more of us is confused.  Optimizing tail recursion
avoids creating further stack frames, which can be a heavy
advantage.  Example:

    void treewalk(nodeptr tree)
    {
       char biglocalbuffer[SIZE];

       if (tree) {
          treewalk(tree->left);
          extractdatafrom(tree, biglocalbuffer);
          puts(biglocalbuffer);
          treewalk(tree->right);
       }
    }

which may, especially with unbalanced trees, assign lots of space
to biglocalbuffer(s).  The tail recursion optimized version is:

    void treewalk(nodeptr tree)
    {
       char biglocalbuffer[SIZE];

       while (tree) {
          treewalk(tree->left);
          extractdatafrom(tree, biglocalbuffer);
          puts(biglocalbuffer);
          tree = tree->right;
       }
    }

avoiding all extra space assignments and stack markers while
investigating the right branches.  Only the last statement and the
loop condition were changed.  There are other ways of avoiding
that extra space usage in this case, but that doesn't affect the
general case.

I'm sure you know all this, so this may clear things for others.

--
Chuck F ( snipped-for-privacy@yahoo.com) ( snipped-for-privacy@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
We've slightly trimmed the long signature. Click to see the full one.
Re: whose 8051 cc overlays static inline stack frames
Quoted text here. Click to load it

Aye, the linker can, and self-modifying code can, but the compiler
cannot.

Quoted text here. Click to load it

Only between separately compiled modules.

Quoted text here. Click to load it

Sorry I cannot know.

Back when I was paid to work 8051, I could not easily talk here: NDA,
pre-assigned IP, etc.  Now that I am not paid to work 8051, I no
longer own any 8051 tools.

E-mail tells me Keil offers, gratis, unlimited evaluation time for
compilation of code images up to 2 KiB.  Also fun 8051 kits at
something like US$60 each.

I'm unlikely to try that myself simply to keep the IP unentangled as I
try to invent and write and simultaneously publish a new kind of
compiler myself.  Left to myself, I'll be targetting JVM, PPC, x86,
...  I first started this hobby in about 1982, but I might release a
usable version this time around, who knows.

Pat LaVarre
http://members.aol.com/ppaatt/losslessc /

Site Timeline