gpt4 book ai didi

c++ - 函数参数在 64 位操作系统的寄存器中传输?

转载 作者:可可西里 更新时间:2023-11-01 18:17:24 26 4
gpt4 key购买 nike

我正在阅读 Agner Fog 的一本手册,作为 64 位操作系统(超过 32 位)的优势,他说:

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

他是说堆栈根本不用于传递函数参数(64 位操作系统)???

最佳答案

是的,他是这么说的,但不太准确。 可以使用堆栈,但前提是您的函数具有很多参数(或者您编写的代码强制溢出)。

如果您查看 wikipedia list of 64-bit intel calling conventions ,您会看到寄存器用于传递前几个参数。有两个主要的 64 位 Intel 调用约定。对于 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.

还有 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.

关于c++ - 函数参数在 64 位操作系统的寄存器中传输?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17437191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com