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.