计算机系统结构总结_Branch prediction

 Textbook:
《计算机组成与设计——硬件/软件接口》    HI
《计算机体系结构——量化研究方法》           QR


Branch Prediction

对于下面的指令:

i1:    r1 := r2 / r3
i2:    r2 := r1 / r3
i3:    r3 := r2 - r3
i4:    beq r3, 100        //if r3==0 then GOTO 100

前面i1, i2, i3都是有依赖的,计算起来就很慢。如果在i4的分支语句中使用了branch prediction,就可以不用等r3算出来,直接提前prefetch target instruction了。这在循环中会很有用。

分支预测要做到下面几点:

  • Determine whether it is a branch instruction
  • Predict whether it will be taken or not
  • Predict the target address if taken

那么如何实现branch prediction呢?有下面几种方法:

1. A branch will do exactly what it did last time

就是搞一个hash table,instruction address的least significant bit作为index,该指令有没有跳转作为value。每次新分支指令执行之前,去hash table查找一下对应的value,作为预测结果。

2. 

...

猜你喜欢

转载自www.cnblogs.com/pdev/p/11795676.html