0

branch target predication(BTP) is not the same as branch predication(BP). I understand that BTP finds where the branch will jump to, where as BP just decides which branch will probably be taken.

Is BTP dependant on BP, if BTP doesn't use BP to predict which branch is taken how can it possibly know the target of the branch?

I don't understand why there is such a massive difference? Once the branch is predicted as being taken isn't finding the target as simple as reading the address in the instruction?

Jonathan.
  • 53,997
  • 54
  • 186
  • 290

1 Answers1

0

Branch targets are not always encoded in the code, you can have indirect branches or calls and returns that depends on the values of registers or memory reads. In these cases, predicting the address before actually reaching to the branch is very hard. Also keep in mind that the CPUs are usually pipelined, meaning that even when the Front-end reaches the branch (and needs to decide where to jump to), previous instructions whose outcome may be related to the branch target, are still not yet in the execution or memory read stages, so you may need to stall if there's such a dependency.

As for the prediction - I wouldn't say it's completely unrelated, but there is a huge difference, branch resolution (taken/not-taken) is a single bit, the target is much bigger and may have many different values during the program lifetime. An x86 ret for e.g. may be required to jump to anyplace that called its function (i'm giving this example since some CPUs have optimizations for this case - look up return stack buffer). The learning mechanism could also be very different, depending on the predictors you implement, but more importantly - the pattern may be different - you could have a branch that's taken in 99% of the cases, but has a different destination every time, or a branch that's taken 50% of the times but almost always jumps to the same place.

You could however track both types of predictions using the same heuristics, usually some manipulation of the branch history pattern, so most CPUs probably do maintain close relations between the predictors.

Leeor
  • 19,260
  • 5
  • 56
  • 87
  • "previous instructions whose outcome may be related to the branch target, are still not yet in the execution or memory read stages", previous instructions will have already been executed by the time the branch gets to the execution stage though.?? – Jonathan. Mar 20 '14 at 17:20
  • @Jonathan. Well, since the branch depends on them, it would get stalled until they've been executed, but that may take a long time to happen (for e.g. if they depends on memory access data), so it might cause a long stall for the branch execution. However, the front-end needs to fetch new instructions from the predicted path, so the branch execution is not the interesting point, but when does it get to the fetch stage (because the next thing to fetch depends on the prediction). – Leeor Mar 20 '14 at 18:27