Single __smallc or multiple __z88dk_fastcall?

Other misc things
Post Reply
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Single __smallc or multiple __z88dk_fastcall?

Post by DarkSchneider »

Hi, I have a function like this:

Code: Select all

void function(uint16_t param1, uint32_t param2, uint32_t param3) __smallc;
Those are 5 pushes into the stack, and then the function does not make much with that data, usually only reads them once.
Maybe some more experienced z88dk programmers could tell me if making this would improve performance, spliting into:

Code: Select all

void func1(uint16_t param1) __z88dk_fastcall;
void func2(uint32_t param2) __z88dk_fastcall;
void func3(uint32_t param3) __z88dk_fastcall;
And then call those 3 instead the single __smallc one. The parameter is always copied into DEHL (DE when required) and the funcX then could read it from registers directly.
But not sure if it compensates the 27T used in each extra call/ret.
User avatar
jorgegv
Well known member
Posts: 287
Joined: Wed Nov 18, 2020 5:08 pm

Re: Single __smallc or multiple __z88dk_fastcall?

Post by jorgegv »

I would compile both with --list and --c-code-in-asm options and see the generated code to compare.

Interesting. :)
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Re: Single __smallc or multiple __z88dk_fastcall?

Post by DarkSchneider »

Didn’t “benchmarked“ but the code has clearly more cumbersome with more size on stack paramenters. What I am doing is moving the uint32_t to uint32_t *, these are references. So we have:
- Passing as uint32_t: the data must be read into registers, then pushed into stack, in function the data must be again read into registers.
- Passing as uint32_t *: only pushing addresses so no need to read the data itself, then in function we read the data from its source so we already have it into registers for operation.

Code: Select all

void function(uint16_t param1, uint32_t *param2, …) {
uint32_t result = param1 + *param2;
}
When doing this the size of the executable is visibly smaller, in my case can save about 30-50 bytes depending the function, what means also less instructions, so faster (compiled with inline optimizations).

So unless you want explicitly to be able to hardwrite values as parameters, the recommended is to pass parameters larger than the stack alignment size as references.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Single __smallc or multiple __z88dk_fastcall?

Post by Timmy »

My opinion is that if you need all 3 parameters then it really doesn't matter how you do it.

I'd probably just leave it as 3 parameters in the function for readability.
Post Reply