When defining structs in C, there are considerations regarding padding, if struct size is a concern, its common to re-arrange the values to avoid padding. (see: Structure padding and packing)
My questions is:
Do the same (or similar) rules apply to function arguments? ... is there any advantage in arranging arguments to avoid argument padding bytes?
Assuming this isn't an
inline
(where it wont matter), orstatic
function where the compiler could re-arrange arguments.Accepting that the real world measurable improvement is likely to be small.
... in practice if function call overhead is a concern, it may be worth inlining the function. nevertheless, inlining isnt always an option (libraries or function pointers for eg).
%esp
/%rsp
and so their sizes do not matter when they are later referenced by offsets of%ebp
/%rbp
. I will leave a more complete answer to the assembly wizards though – Chunchung