分支预测与分支目标预测 [英] branch prediction vs branch target prediction

查看:827
本文介绍了分支预测与分支目标预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解这一点,如果语句更依赖于分支预测和v表查找更依赖于分支目标预测?对于v表,没有分支预测,只有目标预测?

Have I understood this right, if statements are more dependent on branch prediction and v-table look-up is more dependent on branch target prediction? Regarding v-tables, there is no "branch prediction", just the target prediction?

尝试理解CPU如何处理v表。

Trying to understand how a v-table is processed by the CPU.

推荐答案

分支预测正在预测分支是否将被占用。分支目标预测是分支将要到达的预测。这两个事件是独立的,可以在所有组合中出现。

Branch prediction is predicting whether or not the branch will be taken. Branch target prediction is prediction where the branch is going to. These two things are independent and can occur in all combinations.

这些例子可能是:


  • 无限循环

  • goto 语句

  • break continue 语句

  • if / else 语句的then子句结束(跳过 else 子句)

  • 非虚函数调用

  • Infinite loop
  • goto statement
  • break or continue statement
  • End of the 'then' clause of an if/else statement (to jump past the else clause)
  • Non-virtual function call

  • 从函数返回

  • 虚函数调用

  • 函数指针调用

  • 切换语句(如果编译为跳转表)

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

  • if / li>
  • switch 语句(如果编译成一系列 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上,编译器可以优化如 if(condition){obj-> 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.

这篇关于分支预测与分支目标预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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