Related articles |
---|
When/why did function calls get cheap? peter@javamonkey.com (Peter Seibel) (2003-02-12) |
Re: When/why did function calls get cheap? strohm@airmail.net (John R. Strohm) (2003-02-13) |
Re: When/why did function calls get cheap? gah@ugcs.caltech.edu (Glen Herrmannsfeldt) (2003-02-13) |
Re: When/why did function calls get cheap? bje@redhat.com (Ben Elliston) (2003-02-21) |
Re: When/why did function calls get cheap? joachim_d@gmx.de (Joachim Durchholz) (2003-02-21) |
Re: When/why did function calls get cheap? marcov@toad.stack.nl (Marco van de Voort) (2003-02-21) |
Re: When/why did function calls get cheap? firefly@diku.dk (Peter Finderup Lund) (2003-02-21) |
Re: When/why did function calls get cheap? firefly@diku.dk (Peter Finderup Lund) (2003-02-21) |
Re: When/why did function calls get cheap? anton@mips.complang.tuwien.ac.at (2003-02-21) |
Re: When/why did function calls get cheap? jplevyak@yahoo.com (John Plevyak) (2003-02-21) |
Re: When/why did function calls get cheap? {spamtrap}@qeng-ho.org (Arthur Chance) (2003-02-24) |
Re: When/why did function calls get cheap? gah@ugcs.caltech.edu (Glen Herrmannsfeldt) (2003-02-24) |
Re: When/why did function calls get cheap? alexc@std.com (Alex Colvin) (2003-02-24) |
[10 later articles] |
From: | Peter Finderup Lund <firefly@diku.dk> |
Newsgroups: | comp.compilers |
Date: | 21 Feb 2003 00:48:01 -0500 |
Organization: | Department of Computer Science, University of Copenhagen |
References: | 03-02-073 |
Keywords: | performance, practice |
Posted-Date: | 21 Feb 2003 00:48:01 EST |
On 12 Feb 2003, Peter Seibel wrote:
> My understanding is that in Olden Times, Real Programmers avoided
> using lots of small functions because the overhead of a function call
> was considered high.
> the actual work--are there deep black-magic optimizations or did the
> relative costs of something change or something else entirely?
Small functions are usually leaf functions which mean they are easier
to inline. It is also easier to get away with simpler parameter
passing and call/return stuff.
Example:
Many RISCs don't have a call instruction that pushes a return address
onto the stack. They have a specialized jump instruction that stores
the address of the instruction following the call into a register.
Non-leaf procedures would then store that register value someplace
else while they made their own calls. Leaf functions don't have to.
So, less (or no) stack manipulation for leaf functions. The idea of
separating registers into callee-save and caller-save + passing
parameters in registers also helped immensely.
The implementations of the ISAs has also improved: many provide an
internal, hidden return stack so all calls and returns are correctly
predicted (unless you try to play tricks and don't match them up).
Some also provide forwarding paths for the typical stores to
memory/reads from memory used for parameter passing and for the
spill/load code necessary on register starved ISAs (IA-32).
And there are the caches. If you call small functions instead of
inlining them, you reduce your icache pressure. Inlining is usually
only a good idea if it enables other optimizations on the code in the
body of the inlined function (strength reduction, cse, dead code
elimination).
-Peter
Return to the
comp.compilers page.
Search the
comp.compilers archives again.