[En-Nut-Discussion] Not fixed!!!: Re: confirmed!!! Re: NutOS 4.4.0 on ARM7: possibly bug in NutEnterCritical / NutExitCritical
duane ellis
ethernut at duaneellis.com
Sat Feb 23 02:50:59 CET 2008
Ole Reinhardt wrote:
>> I had to admit, that this LR used for ARM's call/ret confuses me every
>> time again. Anyone else here with a more ARM-compatible brain structure?
>>
>
> Sorry me either :(
>
>
I am very familiar with ARM.
What you are speaking about is the "frame pointer" - and 'argument
pointer', the "got" pointer, and so forth.
Just remember this:
Most other CPUs - push the return address on the stack.
Most other CPUs - pop the return address from the stack.
The same can be done in the IRQ handler.
Those are TWO memory references. The question is: Do you really need them?
Can your program be faster if you can remove those two memory references?
Think of your program execution as a "call-graph-tree" - you have LEAF
nodes at the end.
LEAF nodes *never* call any other function.
If the CPU has enough "registers" for the "leaf" function - and it often
does.
One can optimize away the PUSH/POP return address.
How much faster would your program be?
Also - how often does a "tail-call" occur?
ie: Function (A) calls (B) - then B returns and A immediately returns.
This technique, if handled well, lets the program (1) reduce stack space
and (2) not have to execute a series of pop/rts/pop/rts/pop/rts - to dig
out of some deep nested set of functions. Some of the RTS instructions
go away.
Hence, ARM does not automatically PUSH things onto the stack.
Also - when you write hardware state machines in assembler, you learn
amazing tricks using LR/R14 in amazing ways.
-Duane.
More information about the En-Nut-Discussion
mailing list