Re: LPC900/80C51 Compiler Toolchain
- From: David Brown <david@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Jun 2007 14:17:54 +0200
CBFalconer wrote:
wilco.dijkstra@xxxxxxxxxxxx wrote:On 27 Jun, 11:52, CBFalconer <cbfalco...@xxxxxxxxx> wrote:wilco.dijks...@xxxxxxxxxxxx wrote:No. If you remove the frame pointer and don't change anything else,
... snip ...
Most compilers stopped using frame pointers a long time ago. TheyYou are confused as to the use of an 'SP'. This is a stack
are inefficient and don't actually provide any benefit. Rather
than changing SP repeatedly inside a function, SP is adjusted only
on entry and exit of the function, further improving efficiency.
This also makes it easier to track stack variables in debuggers
(as offsets from SP are fixed). The drawback is that stacksize can
grow in some circumstances. Functions containing alloca or C99
arrays could still use a frame pointer.
pointer, which is altered whenever a value is pushed or popped. It
can't be constant, so the compiler has to keep track of it. You
are probably thinking of a 'BP', or block pointer, which normally
holds specific SP values such as the value on function entry.
you're left with a constantly changing stack pointer. This makes it
harder to access variables on the stack. For example, if the SP+offset
addressing mode has a limited offset, you may be able to use that
addressing mode only if the offset is small enough. Additionally, as
David said, most debuggers can't deal with these changing offsets
(Dwarf3 can describe this, but few debuggers support this format, let
alone the builtin interpreter that can do this stuff).
The solution to this is to use fixed size stackframe across the whole
function - ie. SP does not change. This is always possible as you can
reserve space for function arguments at fixed offsets from SP and
store them rather than push. The advantage is that you avoid having to
adjust SP to undo pushes, which further improves the saving.
Although the fixed-size frame optimization is orthogonal to removing
the frame pointer, the advantages (debugging is possible and code
usually more efficient) mean that they typically go together.
IMO you are designing some ugly code generators. For example,
consider the addressing code need to push versus a dedicated
store. Something like one byte for the push, and three up for the
store.
That's very much dependent on the cpu architecture. On some architectures, storing data at (SP + offset) takes exactly the same time and space as a push - on others, it is significantly different. On superscaler 32-bit RISC cpus it is likely that the (SP + offset) store will be faster, as a push which changes SP will lead to stalls. On an AVR, the push is a single instruction which is much smaller and faster as there is no (SP + offset) mode.
And for some types of function, trying to use a single fixed-size stack frame will make a real pig's ear out of the code, and result in lots of wasted stack space - a frame pointer really does give better code for some functions.
As with anything in this field, unless you are going to give specific and tight limits on the processors and the type of code, any generalisations like this are going to be wrong.
.
- Follow-Ups:
- Re: LPC900/80C51 Compiler Toolchain
- From: wilco . dijkstra
- Re: LPC900/80C51 Compiler Toolchain
- References:
- LPC900/80C51 Compiler Toolchain
- From: eugenios
- Re: LPC900/80C51 Compiler Toolchain
- From: Chris Hills
- Re: LPC900/80C51 Compiler Toolchain
- From: Paul Taylor
- Re: LPC900/80C51 Compiler Toolchain
- From: Chris Hills
- Re: LPC900/80C51 Compiler Toolchain
- From: Paul Taylor
- Re: LPC900/80C51 Compiler Toolchain
- From: CBFalconer
- Re: LPC900/80C51 Compiler Toolchain
- From: Chris Hills
- Re: LPC900/80C51 Compiler Toolchain
- From: Eric
- Re: LPC900/80C51 Compiler Toolchain
- From: Chris Hills
- Re: LPC900/80C51 Compiler Toolchain
- From: Guy Macon
- Re: LPC900/80C51 Compiler Toolchain
- From: Chris Hills
- Re: LPC900/80C51 Compiler Toolchain
- From: wilco . dijkstra
- Re: LPC900/80C51 Compiler Toolchain
- From: Michael N. Moran
- Re: LPC900/80C51 Compiler Toolchain
- From: wilco . dijkstra
- Re: LPC900/80C51 Compiler Toolchain
- From: Paul Taylor
- Re: LPC900/80C51 Compiler Toolchain
- From: CBFalconer
- Re: LPC900/80C51 Compiler Toolchain
- From: wilco . dijkstra
- Re: LPC900/80C51 Compiler Toolchain
- From: CBFalconer
- Re: LPC900/80C51 Compiler Toolchain
- From: wilco . dijkstra
- Re: LPC900/80C51 Compiler Toolchain
- From: CBFalconer
- LPC900/80C51 Compiler Toolchain
- Prev by Date: Re: Attention : Embedded Developers, we need you!
- Next by Date: Re: Help needed with SCI interrupts (HC12)
- Previous by thread: Re: LPC900/80C51 Compiler Toolchain
- Next by thread: Re: LPC900/80C51 Compiler Toolchain
- Index(es):
Relevant Pages
|
|