0
votes

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?

1

1 Answers

0
votes

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.