Function parameters passed to registers on a 64-bit OS?

I am reading one of the Agner Fog tutorials and as an advantage for 64-bit operating systems (over 32 bits), he says:

Functional parameters are passed to registers, not to the stack. This makes the functions more efficient.

Does he say that the stack is not used to pass function parameters (64-bit OS) at all?

+6
source share
1 answer

Yes, thatโ€™s what he says, but thatโ€™s not entirely accurate. The stack can be used, but only if your function has many parameters (or you write code that causes a spill).

If you look at the Wikipedia list of 64-bit Intel calling conventions , you will see that the registers are used to pass the first few parameters. There are two main 64-bit conventions for using Intel. For Microsoft ABI:

The Microsoft x64 calling convention uses the registers RCX, RDX, R8, R9 for the first four integers or pointers (in this order from left to right), and XMM0, XMM1, XMM2, XMM3 are used for floating point arguments. Additional arguments are pushed onto the stack (from right to left). Integer return values โ€‹โ€‹(similar to x86) are returned in RAX if 64 bits or less. Returned floating point values โ€‹โ€‹are returned in XMM0. Parameters shorter than 64 bits are non-zero; high bits contain garbage.

And the V ABI system:

The first six integer or index arguments are passed to the registers RDI, RSI, RDX, RCX, R8 and R9, while XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6 and XMM7 are used for floating point arguments ... As in Microsoft x64 calling convention, additional arguments are pushed onto the stack, and the return value is stored in RAX.

+14
source

Source: https://habr.com/ru/post/948592/


All Articles