What is the difference between call4, call8 and call12, and how does the compiler choose?
The number is how far the window shifts, which is how many of the caller's registers are hidden and kept safe across the call: a0–a3, a0–a7 or a0–a11.
Everything below the shift stays with the caller. Everything from the shift upwards overlaps with the callee's window:
| Call | Caller's registers kept safe | Arguments go in caller's | Room for arguments |
|---|---|---|---|
call4 |
a0–a3 |
a6 onwards |
up to six (a6–a11 → callee a2–a7) |
call8 |
a0–a7 |
a10 onwards |
up to six (a10–a15 → callee a2–a7) |
call12 |
a0–a11 |
a14 onwards |
only two (a14–a15 → callee a2–a3) |
So the choice is a trade-off. A bigger shift protects more of the caller's live values, so fewer of them need to go on the stack, but it leaves fewer overlapping registers for arguments. The compiler picks the shift from how many values the caller still needs after the call. call8 is a common middle ground.
A larger shift also uses up the 64 physical registers faster, so deep chains of call12 hit window overflow sooner.
There are register-indirect versions (callx4, callx8, callx12) that jump to an address in a register, used for function pointers.
Go deeper:
Xtensa ISA Reference Manual, §4.7.1.5 "Windowed Procedure-Call Protocol" (PDF) — which call sizes allow how many argument registers.