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

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

问题描述

一直在阅读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?

推荐答案

预测器通常是fetch阶段的一部分,以便确定接下来要提取的指令.这发生在处理器对指令进行解码之前,因此甚至无法确定是否存在分支指令.像所有预测变量一样,返回地址预测变量的目的是更快地获得分支的方向/目标.返回指令是一个分支,因此它通常会有一个分支预测器条目来确定是否采用该指令以及目标在何处.可以使用返回地址预测变量来代替常规分支目标缓冲区.

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天全站免登陆