本文介绍了在分支prediction结合分支目标prediction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我的困惑的产生是因为肯定由分支进行predicting,你正在做有效的目标prediction太??

My confusion arises because surely by predicting which branch is taken, you are effectively doing the target prediction too??

此问题是内在的联系,我对题目的第一个问题:

This question is intrinsically linked to my first question on the topic:

<一个href=\"http://stackoverflow.com/questions/21608874/branch-$p$pdiction-vs-branch-target-$p$pdiction\">branch prediction VS分支目标prediction

综观接受的答案:


      
  • 无限循环

  •   
  • 转到语句

  •   
  • 继续语句

  •   
  • 结束了,然后的第一个的if / else 语句(跳过去其他子句)

  •   
  • 非虚函数调用

  •   

      
  • 从函数返回

  •   
  • 虚拟函数调用

  •   
  • 函数指针调用

  •   
  • 开关语句(如编译成一个跳转表)

  •   
  • Returning from a function
  • Virtual function call
  • Function pointer call
  • switch statement (if compiled into a jump table)

      
  • 如果语句

  •   
  • 开关语句(如编译成一系列中的if / else 语句)

  •   
  • 循环条件测试

  •   
  • &放大器;&安培; || 运营商

  •   
  • 三元运营商

  •   
  • if statement
  • switch statement (if compiled into a series of if/else statements)
  • Loop condition tests
  • The && and || operators
  • The ternary ?: operator

      
  • 不太可能在正常情况下展现出来,但是编译器可以合成一个作为一种优化,结合两个以上的情况下。
      例如,在x86,编译器可以优化code像如果
      (条件){obj-&GT; VirtualFunctionCall(); }
    进入条件
      间接跳转像 JNE *%EAX 如果它出现在一个函数结束
      由于尾部调用优化。

  •   
  • Less likely to show up under normal conditions, but the compiler may synthesize one as an optimization, combining two of the above cases. For example, on x86, the compiler may optimize code like if (condition) { obj->VirtualFunctionCall(); } into a conditional indirect jump like jne *%eax if it appears at the end of a function due to tail call optimization.

如果我有以下的code:

If I have the following code:

if(something){
    //a
}
else{
    //b
}

(BP =科prediction和BTP =分支目标prediction)

(BP = "Branch Prediction" and BTP = "Branch Target Prediction")

其pretty明显BP用于评估条件的东西。不过,我想了解是否BTP也参与了确定分支发生了什么 A 。是否BTP也正好来确定位于分支code的地址 A / B ,视BP的结果?

Its pretty obvious BP is used to evaluate the conditional something. However I am trying to understand whether BTP is also involved in determine what happens in branch a. Does BTP also happen to determine the address of the code located at branch a/b, depending on the result of the BP?

请问这becase的维基百科页面上(<一href=\"http://en.wikipedia.org/wiki/Branch_target_$p$pdictor\">http://en.wikipedia.org/wiki/Branch_target_$p$pdictor):

I ask becase on this wikipedia page (http://en.wikipedia.org/wiki/Branch_target_predictor):

在计算机体系结构,分支目标predictor是的一部分
  处理器predicts所拍摄的条件分支或目标
  分支的目标之前无条件转移指令
  指令由处理器的执行单元计算

它表明BTP用于predict目标后,有条件的已经pdicted $ P $。

it suggests BTP is used to predict the target after the conditional has been predicted.

1)可能有人澄清上述好吗?

第二个相关的问卷怎样BP和BTP在他们和获取/德code交互的方式不同/执行的CPU /回写管道? BP是否开始在获取或去code阶段?有条件code的执行阶段后,我们可以检查prediction是否正确,并更新分支prediction缓存。

A second related question- how do BP and BTP differ in the way they interact with the fetch/decode/execute/write-back pipeline of the CPU? Does BP begin at the fetch or decode stage? After the execution stage of the conditional code we can check whether the prediction was correct and update the branch prediction cache.

2)如何BTP与问候抓取/德code工作/执行/写回CPU阶段?

推荐答案

做的英特尔优化手册陪读,当前下载位置is这里。当陈旧的(他们走动的所有时间的东西),然后搜索英特尔网站架构优化手册。记住信息有相当通用的,他们只公开根据需要允许写入效率code之多。科prediction实现细节都被认为是商业秘密的的体系结构之间的变化。搜索手册分支prediction中找到引用,它是章节之间公平US $ p $垫。

Do read along with the Intel optimization manual, current download location is here. When stale (they move stuff around all the time) then search the Intel site for "Architectures optimization manual". Keep in mind the info there is fairly generic, they disclose only as much as needed to allow writing efficient code. Branch prediction implementation details are considered a trade secret and do change between architectures. Search the manual for "branch prediction" to find references, it is fairly spread among the chapters.

我给一个什么样的手册中发现了一个总结,细节增添酌情:

I'll give a summary of what's found in the manual, adding details where appropriate:

科prediction是BPU单元的核心(分公司prediction单元)的工作。大致关联到你的问题BP。它包含几个子单元:

Branch prediction is the job of the BPU unit in the core (Branch Prediction Unit). Roughly correlates to "BP" in your question. It contains several sub-units:


  • 该分支历史表。此表跟踪$ P $的pviously采取的条件的分支机构,由predictor协商,以决定是否分支很可能采取。是被供给由指令退役单元,它知道该分支是否实际采取一个条目。这是亚单位已更改的最改进的架构,越来越深,更聪明更楼盘面世。

  • The branch history table. This table keeps track of previously taken conditional branches and is consulted by the predictor to decide if a branch is likely to be taken. Is is fed with entries by the instruction retirement unit, the one that knows whether the branch was actually taken. This is the sub-unit that has changed the most as the architectures improved, getting deeper and smarter as more real estate became available.

在BTB,分支目标缓冲器。这个缓冲区存储$ P $的目标地址pviously采取间接跳转或调用。这在你的问题关联到BTP。该手册没有说明缓冲区是否可以存储每个地址多个目标,由历史表索引,我认为这是可能的供以后架构。

The BTB, Branch Target Buffer. This buffer stores the target address of a previously taken indirect jump or call. This correlates to "BTP" in your question. The manual does not state whether the buffer can store multiple targets per address, indexed by the history table, I consider it likely for later architectures.

返回堆栈缓冲区。这个缓冲区的作用影子栈,存储返回地址CALL指令,使得可用的RET指令具有高度的信心的目标,而不必依赖BTB,不可能进行通话有效处理器。据记载是16级。

The Return Stack Buffer. This buffer acts a "shadow" stack, storing the return address for CALL instructions, making the target of a RET instruction available with a high degree of confidence without the processor having to rely on the BTB, unlikely to be as effective for calls. It is documented to be 16 levels deep.

子弹2)有点难以准确回答,手动大约只有前端会谈,并没有打破管道的细节。够合适的,它在很大程度上依赖于体系结构。在第2.2.5图可能是说明性的。执行追踪缓存起到了重要作用,它存储previously德$ C $光盘说明书等是BPU协商的主要来源。指令翻译后否则权(又名德codeR)。

Bullet 2) in a bit difficult to answer accurately, the manual only talks about the "Front End" and does not break down the details of the pipeline. Appropriate enough, it is heavily architecture dependent. The diagram in section 2.2.5 is possibly illustrative. The execution trace cache plays a role, it stores previously decoded instructions so is the primary source of BPU consultations. Otherwise right after the instruction translator (aka decoder).

这篇关于在分支prediction结合分支目标prediction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 14:00