![](http://datasheet.mmic.net.cn/230000/INSTRUCTIN603EWP_datasheet_15584964/INSTRUCTIN603EWP_23.png)
RISC Microprocessor Division
Page 23
Each conditional branch instruction includes a prediction bit, which is set by the compiler or an
assembly language programmer. This bit helps specify whether the branch is predicted to be taken or
not taken. This is known as
static prediction
because the prediction behavior is encoded in the
instruction. While the branch condition is waiting to be resolved, execution continues down the
predicted path, and these subsequent instructions are marked as
speculative instructions
.
(Speculative instructions are not allowed to change the programming model, such as update register
files or memory, and may stall until the branch is resolved and they become non-speculative.)
When the branch condition is resolved, if the prediction was correct, then the speculative instructions
are marked non-speculative, and no penalty is assessed. If the prediction was incorrect, then the
speculative instructions are
flushed
(removed from the instruction pipeline) and execution resumes
along the correct execution path.
The 603e has one level of prediction, meaning that a conditional branch encountered along a
speculative path cannot itself be executed speculatively. Instead, it will stall in the pipeline until the
previous branch is resolved.
In the leftmost diagram, we have instructions A, B, C, and D in the instruction queue. Instruction C is a
branch. In the next diagram (next cycle), instruction A was dispatched and C folded out by the BPU.
However, assume that branch C cannot be resolved (perhaps it is dependent on the results of
instruction A). All subsequent instructions are then marked speculative: D and the newly fetched
instructions E and F.
In the next diagram, we see that B and D were dispatched to the CQ and G and H fetched into the IQ.
In our example, branch C is now resolved and it turns out the branch was mispredicted. In the final
diagram, the speculative instructions are flushed, and the fetcher is ready to fetch instructions from the
correct input stream. If branch C had been correctly predicted, the speculative instructions would
simply be marked non-speculative and no stall would occur.