“进入"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"
问题描述
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屋!