Am 21.10.22 um 16:43 schrieb Basil Hussain:
On 21/10/2022 07:44, Philipp Klaus Krause wrote:
The cleanup for stack parameters is done for both: for foo by the
callee, for bar by the caller. Which one does it depends on the type
of the function. For details, see section 4.5.1.1, "SDCC calling
convention, version 1" in the manual:
Argh, $*!% me, I did not notice this was the case. I usually work with
large memory model STM8 devices, but this is for a medium-only device,
and the void-returning function meets the criteria for callee stack
adjustment. >:(
Can you briefly remind me what is the rationale behind void-returning
functions having the stack clean-up done by caller and not callee? One
of the things I prefer about the old calling convention is that it's
just so much simpler, without exceptions like this.
Typically, callee-cleanup is better for code size, while caller-cleanup
is better for speed. The speed penalty tends to be worst when returning
large types. void being the smallest type (size 0) has negligible
performance penalty, but we do get the code size gain.
However, this wasn't decided by arguments like the one I just gave.
There was a large number of experiments done, and the new calling
convention was based on the empirical results.
Now I understand why 'i' was being trampled, as in my original code
function 'foo' is in fact a __naked inline assembly function, where I am
not cleaning the function arguments from the stack.
Regards,
Basil Hussain
P.S. By the way, now I am looking at the manual again, is there not a
mistake in section 4.5.1.2 describing calling convention version 0? It
says:
All parameters are passed on the stack. The stack is not adjusted for
the parameters after the call (thus the callee has to do this
instead), unless __z88dk_callee is specified.
The second sentence is self-contradicting. Callee must adjust the stack,
unless you specify the option that says the callee will adjust the
stack!? I have never encountered functions that are attributed as
version 0 and SDCC does *not* generate stack rewind after calls to them
(i.e. caller SP rewind, not callee).
Looks like a typo there; I just fixed it.
Philipp
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user