“进入"vs“推送ebp;移动 ebp,特别是;sub esp, imm"和“离开"vs "mov esp, ebp;弹出 ebp" [英] "enter" vs "push ebp; mov ebp, esp; sub esp, imm" and "leave" vs "mov esp, ebp; pop ebp"

查看:29
本文介绍了“进入"vs“推送ebp;移动 ebp,特别是;sub esp, imm"和“离开"vs "mov esp, ebp;弹出 ebp"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

enter

push ebp
mov  ebp, esp
sub  esp, imm

说明?有性能差异吗?如果是这样,哪个更快,为什么编译器总是使用后者?

instructions? Is there a performence difference? If so, which is faster and why do compilers always use the latter?

leave

mov  esp, ebp
pop  ebp

说明.

推荐答案

存在性能差异,尤其是enter.在现代处理器上,这解码到大约 10 到 20 µops,而三个指令序列大约是 4 到 6,具体取决于架构.有关详细信息,请参阅 Agner Fog 的 说明表.

There is a performance difference, especially for enter. On modern processors this decodes to some 10 to 20 µops, while the three instruction sequence is about 4 to 6, depending on the architecture. For details consult Agner Fog's instruction tables.

此外,enter 指令通常具有相当高的延迟,例如,与三个指令序列的 3 个时钟依赖链相比,一个 core2 上有 8 个时钟.

Additionally the enter instruction usually has a quite high latency, for example 8 clocks on a core2, compared to the 3 clocks dependency chain of the three instruction sequence.

此外,编译器可能会出于调度目的将这三个指令序列展开,这当然取决于周围的代码,以允许指令的更多并行执行.

Furthermore the three instruction sequence may be spread out by the compiler for scheduling purposes, depending on the surrounding code of course, to allow more parallel execution of instructions.

这篇关于“进入"vs“推送ebp;移动 ebp,特别是;sub esp, imm"和“离开"vs "mov esp, ebp;弹出 ebp"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆