返回地址预测堆栈缓冲区与堆栈存储的返回地址? [英] Return address prediction stack buffer vs stack-stored return address?

查看:48
本文介绍了返回地址预测堆栈缓冲区与堆栈存储的返回地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直在阅读 Agner Fog 的Intel、AMD 和 VIA CPU 的微体系结构",并在第 34 页描述了返回地址预测":

Have been reading Agner Fog's "The microarchitecture of Intel, AMD and VIA CPUs" and on page 34 he describes "return address prediction":

http://www.agner.org/optimize/microarchitecture.pdf

3.15 返回(除 P1 之外的所有处理器)

3.15 Returns (all processors except P1)

一种更好的方法用于退货.后进先出缓冲区,称为返回栈缓冲区,每次记住返回地址执行调用指令,并使用它来预测在哪里相应的回报就会去.这种机制确保相同子程序时正确预测返回指令从几个不同的位置调用.

A better method is used for returns. A Last-In-First-Out buffer, called the return stack buffer,remembers the return address every time a call instruction is executed, and it uses this for predicting where the corresponding return will go. This mechanism makes sure that return instructions are correctly predicted when the same subroutine is called from several different locations.

我有点不清楚这样做的必要性,因为返回地址无论如何都存储在堆栈中?

I am a little unclear what the need for this is, given that the return addresses are stored on the stack anyway?

那么如果也有这种技术,那么将返回地址存储在栈上的目的是什么?只有在这种预测技术不起作用时才使用堆栈存储值吗?

So what is the purpose of storing return addresses on the stack if there is also this technique? Is the stack-stored value only used if this prediction technique doesnt work?

推荐答案

预测器通常是获取阶段的一部分,以确定接下来要获取哪些指令.这发生在处理器解码指​​令之前,因此甚至不确定分支指令的存在.与所有预测器一样,返回地址预测器的目的是更快地获得分支的方向/目标.返回指令是一个分支,因此它通常会有一个分支预测器条目来确定它是否被采用以及目标在哪里.使用返回地址预测器代替正常的分支目标缓冲区.

Predictors are normally part of the fetch stage, in order to determine which instructions to fetch next. This takes place before the processor has decoded the instructions, and therefore doesn't even know with certainty that a branch instruction exists. Like all predictors, the intent of the return address predictor is to get the direction / target of the branch faster. A return instruction is a branch, and so it would normally have a branch predictor entry to determine whether it is taken and where the target is. The return address predictor is consulted in lieu of the normal branch target buffer.

因此,在实际执行"return 语句之前,可能还有 50 条指令,提取阶段会预测返回指令和接下来要提取的指令地址.稍后,当返回执行时,从堆栈中读取地址并与返回的预测位置进行比较.如果它们相同,则继续执行,否则回滚执行以使用正确的返回地址.

So perhaps 50 instructions before the return statement is actually "executed", the fetch stage predicts a return instruction and the instruction address to fetch next. Later, when the return is executed, the address is read from the stack and compared with where the return was predicted to go. If they are the same, execution continues, else execution is rolled back to use the proper return address.

为什么要存储在栈上?首先,处理器不知道预测器是否在不与存储在堆栈中的地址进行比较的情况下工作.其次,堆栈是官方"返回地址,可能会因合法原因而更改.第三,返回地址预测器的条目数量有限.没有空间在预测器中存储地址的返回指令需要堆栈.

Why store on the stack? First, the processor does not know if the predictor has worked without comparing against the address stored on the stack. Second, the stack is the "official" return address, which might be changed for legitimate reasons. Third, the return address predictor has a limited number of entries. The stack is needed for the return instructions for which there was not room to store the addresses in the predictor.

这篇关于返回地址预测堆栈缓冲区与堆栈存储的返回地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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