为什么编译器会生成入栈/出栈指令对?
我用VC++ 2010编译器编译了下面的代码:
__declspec(dllexport)
unsigned int __cdecl __mm_getcsr(void) { return _mm_getcsr(); }
生成的代码是:
push ECX
stmxcsr [ESP]
mov EAX, [ESP]
pop ECX
retn
为什么会有push ECX
/pop ECX
指令对?
I compiled the code below with the VC++ 2010 compiler:
__declspec(dllexport)
unsigned int __cdecl __mm_getcsr(void) { return _mm_getcsr(); }
and the generated code was:
push ECX
stmxcsr [ESP]
mov EAX, [ESP]
pop ECX
retn
Why is there a push ECX
/pop ECX
instruction pair?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编译器正在堆栈上腾出空间来存储 MXCSR。它本来可以同样很好地做到这一点:
但是“push ecx”可能更短或更快。
The compiler is making room on the stack to store the MXCSR. It could have equally well done this:
But "push ecx" is probably shorter or faster.
这里的push用来分配4个字节的临时空间。
[ESP]
通常会指向推送的返回地址,我们无法覆盖它。ECX
将在此处被覆盖,但是,ECX
可能是您所针对的 ABI 中的易失性寄存器,因此函数不必保留ECX< /代码>。
这里使用推送/弹出的原因是空间(也可能是速度)优化。
The push here is used to allocate 4 bytes of temporary space.
[ESP]
would normally point to the pushed return address, which we cannot overwrite.ECX
will be overwritten here, however,ECX
is a probably a volatile register in the ABI you're targeting, so functions don't have to preserveECX
.The reason a push/pop is used here is a space (and possibly speed) optimization.
它创建一个栈顶条目,ESP 现在将其称为 stmxcsr 指令的目标。然后将结果存入EAX中供返回。
It creates an top-of-stack entry that ESP now refers to as the target for the stmxcsr instruction. Then the result is stored in EAX for the return.