“进入"与“push ebp;"mov ebp, esp;sub esp, imm"和“离开"与“mov esp,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.
这篇关于“进入"与“push ebp;"mov ebp, esp;sub esp, imm"和“离开"与“mov esp,ebp;流行音乐"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!