From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: how to use inline push and pop Date: 10 May 2001 13:46:51 GMT Organization: Aachen University of Technology (RWTH) Lines: 54 Message-ID: <9de64b$15q$1@nets3.rz.RWTH-Aachen.DE> References: <3AF93C8E DOT 84E782F AT sci DOT kun DOT nl> <1659-Wed09May2001191455+0300-eliz AT is DOT elta DOT co DOT il> <3AFA8F0D DOT 24E276C2 AT sci DOT kun DOT nl> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 989502411 1210 137.226.32.75 (10 May 2001 13:46:51 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 10 May 2001 13:46:51 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Michiel de Bondt 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.