The branch prediction scheme used in a processor has a central impact on its execution. Therefore, some effort has been placed into promoting an effective scheme.
A prediction can be a fixed or a true prediction. In a fixed prediction the same guess is continually made, either ‘taken’ or ‘not-taken’. This is a one outcome guess. The ‘always not taken’ approach prefers the ‘not taken’ path, so the taken penalty (TP) is typically higher than the not-taken penalty (NTP).
The ‘not-taken’ scheme is easier to implement than the ‘taken’ scheme. A large number of pipelined microprocessors employ this scheme, including certain earlier processors like the i486 but also many processors which appeared at the beginning of the 1990s. Examples are the SuperSparc, the Power1 and Power2, and the α 21064 and α 21064A.
The taken penalty is expected to be less than the penalty for not-taken branches (NTP).
A true prediction has two possible outcomes, either ‘taken’ or ‘not-taken’ (fall through, sequential path). With true predictions, the difference between static and dynamic predictions, as shown in the figure. The prediction is known as static if it is based only on the code in question. If the prediction is subject to the preceding execution of the similar branch instruction, especially, the prediction relies upon the implementation history, they are dealing with dynamic prediction.
Static prediction is easier than dynamic prediction. In a static prediction technique, the branch is ‘always taken’ or the branch is ‘always not-taken’ approaches. It can make static predictions by investigating particular attributes of the object code.
Static prediction consists of the following components such as opcode-based predictions, displacement-based predictions, and compiler-directed predictions.
Opcode-based predictions are made by assuming that the branch will be ‘taken’ for certain opcodes and ‘not taken’ for others. This prediction technique is used, for instance, in the MC 88110 and PowerPC 601/603 processors.
Displacement-based predictions depend on the sign of the displacement. If D < 0, the prediction is ‘taken’, in the opposite case, D≥0, it is ‘not taken’. Here the underlying assumption is that a conditional branch with negative displacement is used as a loop-closing branch.
Finally, a static prediction can also be derived from a hint from the compiler. This kind of prediction is called compiler-directed prediction.
In contrast, dynamic prediction is based on branch history. The basic philosophy of dynamic prediction is that branches which were taken at their last occurrence (or last n occurrences) are also likely to be taken at their next occurrence.
Dynamic techniques have a higher performance potential than static schemes. But the price is a more complex implementation since the processor has to store and update the last outcomes of a large number of branches. By contrast, static schemes neglect branch history and instead make a code-based prediction on the fly.