分支预测变量和分支目标缓冲区如何共存? [英] How branch predictor and branch target buffer co-exist?

查看:64
本文介绍了分支预测变量和分支目标缓冲区如何共存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是它们如何在现代CPU体系结构中共存并协同工作?

My question is how they co-exist and work together in modern CPU architecture?

推荐答案

您已经略微颠倒了它.在每次获取时,您都会索引到分支预测器中,该分支预测器会告诉您刚收到的指令是否将解码为采用分支.如果不是,则获取下一个顺序地址.但是,如果您的分支预测器说它将是一个采用的分支,则您不知道下一步要提取哪一条指令,因为您尚未对该指令进行解码.因此,为了不浪费等待分支解决的周期,您可以使用分支目标缓冲区(或BTB).BTB存储以前的地址,分支将控制流重定向到该地址.使用这种机制,您正在尝试预测这次控制流将重定向到的位置.该技术对于无条件分支,函数调用和与返回地址栈配对时返回的成功率为100%.在条件分支上,成功率略低,但鉴于分支目标的时间局部性较高,其成功率仍然很高.例如,您可以考虑循环的向后分支,该分支将始终分支到同一位置.

You've got it slightly reversed. On every fetch you index into your branch predictor, which tells you whether the instruction that you have just received will be decoded into a taken branch. If not, you fetch the next sequential address. But if your branch predictor says that it will be a taken branch, you don't know which instruction to fetch next, since you haven't decoded this instruction yet. So in order to not waste cycles waiting for the branch to resolve, you would use a Branch Target Buffer(or BTB). A BTB stores previous addresses where branch redirected the control flow. Using this mechanism you are trying to predict where the control flow will be redirected this time. This technique has 100% success rate for unconditional branches, function calls, and returns when paired with a Return Address Stack. On conditional branches the success rate is slightly lower, but is still really good given high temporal locality of branch targets. As an example you could consider a backwards branch of a loop, which will always branch to the same location.

当实际解决了分支指令时(通常在流水线的解码"或执行"阶段,具体取决于实现),您将调整分支预测器和BTB中的值,以获取有关最新信息.未来的预测.

When the branch instruction is actually resolved (usually in Decode or Execute stage of the pipeline, depending on the implementation), you will adjust the values in both the branch predictor and the BTB in order to have more up to date information for future predictions.

以下是图片说明,说明BTB查找和更新是如何发生的:

Here is a pictorial explanation how BTB lookup and update happen:

http://www-ee.eng.hawaii.edu/~tep/EE461/Notes/ILP/buffer.html

这篇关于分支预测变量和分支目标缓冲区如何共存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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