Control hazards, also called branch hazards, occur when the proper instruction cannot execute in the proper pipeline clock cycle because the instruction that was fetched is not the one that is needed.Branch instructions can cause great performance loss if they are not handled accordingly. Two issues related to branch instructions are
⇒
Taken or not taken
PC+4
if branch is not taken or
(PC+4)+(4×immediate)
if branch is taken.
zero
flag).
nop
) is inserted into clock cycle 3 and the next instruction is re-fetched at clock cycle 4.
Clock cycle
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
---|---|---|---|---|---|---|---|---|---|
Branch |
IF | ID | EX | MEM | WB | ||||
Branch successor |
IF (stall) | stall | IF | ID | EX | MEM | WB | ||
Branch successor+1 |
IF | ID | EX | MEM | WB |
“I will no longer mutilate and destroy myself in order to find a secret behind the ruins.” ― Hermann Hesse, Siddhartha |