Mail Archives: djgpp/2001/05/10/10:00:07
Michiel de Bondt <michielb AT sci DOT kun DOT nl> wrote:
> int myfunction ()
> {
> register int a,b,c,d,S,D
> int mysubfunction ()
> {
Oha! --- Nested functions. You should be aware that this feature creates
an additional bit of overhead, in most cases (--> "trampolines"), which may
easily eat any speedup you're after.
[...]
> But a declaration of mysubfunction as above is only allowed in plain C.
It's not even allowed in plain C --- this is a GCC extension to the C
language, and not available on other compilers.
If portability is any issue at all, for you application, forget about
nested functions.
> But on the other hand: not only the stack pointer and the base
> pointer are manipulated by a call: but also all vars are pushed on
> and popped from the stack. There is no need to do this, as you see
> in the example above.
You really should rethink your strategy all the way since you started
at square one. What you're doing here, actually, is to avoid the usual
overhead involved in recursive function calling --- but you're doing
it the wrong way. To avoid having more than absolutely necessary
pushed to the stack in recursive calls, use the following recipe,
instead:
1) Remove as many as possible of the arguments of the recursive function
2) Remove as many as possible of the recursive function's local variables
in scope at the time of the resursion call(s). Block-scope variables
of blocks without a recursion call in them can stay as they are.
3) Replace them by a manually implemented stack of 'status structs', where
the status struct holds *exactly* those variables that have to be
preserved across a recursion call.
4) Compile the whole stuff with -save-temps -fverbose-asm -O6 and see if
you can really beat GCC in assembly hacking :-)
> My general macros (push, pop, call, ret) only use pushl and popl. Aren't
> these instructions machine independent?
No, they aren't. Hardly any opcode is.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -