Question about calling convetions and registers

Yes, caller allocates space. But the part of "waste of time" was about dumping registers to that space. Allocating space does not cost anything. It's moving registers to it is what wastes time (memory accesses, cache pollution).

No idea why they talk about address taking in varargs section.


Replying to longtran2904 (#27010)

So the shadow space is before any arguments that are on the stack? And because callers already need to allocate space for some arguments, it doesn't cost them much to push a bigger size on the stack.


Replying to mmozeiko (#27019)

Allocating a constant amount of memory (no variable length array) on the stack is just an addition to the stack pointer (using negative values on Intel when the stack space is up-side-down), which will later be used to set the frame/base pointer when making calls. The frame/base pointer is the base address for a local stack space from which fixed memory locations can be found using fixed structure offsets (until you have variable length arrays). The stack pointer tells how much is allocated on the stack to allow allocating variable length arrays from runtime values.


Edited by Dawoodoz on
Replying to longtran2904 (#27020)

The stack pointer tells how much is allocated on the stack to allow allocating variable length arrays from runtime values.

Do you mean some things like printf and varargs?


Replying to Dawoodoz (#27028)

Variable length array (VLA) is when you don't know length at compile time. This is C99 feature:

void fun(int n)
{
    char arr[n]; // array for n bytes
    ...
}

Same thing can be accomplished with alloca even in C++:

void fun(int n)
{
    char* arr = (char*)alloca(n); // allocate n bytes on stack
    ...
}

Replying to longtran2904 (#27029)