branch prediction vs branch target prediction

邮差的信 提交于 2019-11-30 19:09:43

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.

Examples of these might be:

Unconditional branch, fixed target

  • 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

Unconditional branch, variable target

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

Conditional branch, fixed target

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

Conditional branch, variable target

  • 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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!