简体   繁体   English

“ret”会阻止管道吗?

[英]Does “ret” stall the pipeline?

由于ret指令是间接调用,x86上的ret指令是否会使管道停止,或者它是否以某种方式进行了优化以表现得像更直接的调用?

From the Intel Optimization Reference Manual, the branch prediction unit contains a Return Stack Buffer precisely to predict ret instructions (section 2.2.2.1) more accurately. 从英特尔优化参考手册中,分支预测单元包含一个返回堆栈缓冲区,可以更准确地预测ret指令(第2.2.2.1节)。 The instruction queueing and decode unit also tracks changes in the stack pointer to improve decoding bandwidth (section 2.2.2.5). 指令排队和解码单元还跟踪堆栈指针的变化以改善解码带宽(见第2.2.2.5节)。

In more detail, section 3.4.1.4 describes some "rules", mostly directed to compiler writers, to benefit from inlining, calls & returns - the most relevant is probably that a near/far call must be paired with a near/far return, which means pushing the return address on the stack and jumping to the callee is not recommended. 更详细地说,第3.4.1.4节描述了一些“规则”,主要针对编译器编写者,受益于内联,调用和返回 - 最相关的可能是近/远调用必须与近/远返回配对,这意味着不推荐在堆栈上推送返回地址并跳转到被调用者。 Also, the call depth is recommended to not exceed 16 nested calls (the size of the RSB). 此外,建议调用深度不超过16个嵌套调用(RSB的大小)。

If those rules are followed, you can effectively treat them like indirect branches during branch selection (section 3.4.1.6), with everything that implies. 如果遵循这些规则,您可以在分支选择期间(第3.4.1.6节)有效地将它们视为间接分支,并包含所有含义。 You will most likely never encounter a stall on a ret , except on pathological cases or self-modifying code. 你很可能永远不会遇到在一个摊位ret ,除了在病理情况下或自行修改代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM