Question

I am reading one of Agner Fog's manuals and as an advantage for 64 bit Operating Systems (over 32 bit) he says:

Function parameters are transferred in registers rather than on the stack. This makes function calls more efficient.

Is he saying the stack is not used for passing function parameters (64bit OS) at all???

Était-ce utile?

La solution

Yes, that's what he's saying, but it's not quite accurate. The stack may be used, but only if your function has a lot of parameters (or you write code that forces a spill).

If you check out the wikipedia list of 64-bit intel calling conventions, you'll see that registers are used to pass the first several parameters. There are two major 64-bit Intel calling conventions. For the Microsoft ABI:

The Microsoft x64 calling convention uses registers RCX, RDX, R8, R9 for the first four integer or pointer arguments (in that order left to right), and XMM0, XMM1, XMM2, XMM3 are used for floating point arguments. Additional arguments are pushed onto the stack (right to left). Integer return values (similar to x86) are returned in RAX if 64 bits or less. Floating point return values are returned in XMM0. Parameters less than 64 bits long are not zero extended; the high bits contain garbage.

And the System V ABI:

The first six integer or pointer arguments are passed in 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 the Microsoft x64 calling convention, additional arguments are passed on the stack and the return value is stored in RAX.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top