3
\$\begingroup\$

I'm studying how delayed branch works and I'm trying to distinguish delayed branch from branch prediction. What is the difference? Is delayed branch a means to facilitate a control hazard?

\$\endgroup\$

2 Answers 2

11
+50
\$\begingroup\$

Delayed branch and branch prediction are two different ways of mitigating the effects of a long execution pipeline. Without them, the pipeline needs to stall whenever a conditional branch is taken, because the instruction fetch mechanism can't know which instruction should be executed next after the branch instruction until the computations on which it depends are completed.

Delayed branch simply means that some number of instructions that appear after the branch in the instruction stream will be executed regardless of which way the branch ultimately goes. In many cases, a compiler can put instructions in those slots that don't actually depend on the branch itself, but if it can't, it must fill them with NOPs, which kills the performance anyway. This approach keeps the hardware simple, but puts a burden on the compiler technology.

Branch prediction is a more hardware-oriented approach, in which the instruction fetcher simply "guesses" which way the branch will go, executes instructions down that path, and if it later turns out to have guessed wrong, the results of those instructions are thrown away. Various systems have different ways of improving the accuracy of the guess. Sometimes the compiler puts a clue into the instruction stream, and sometimes the hardware keeps track of which way each branch has gone in the past.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Some ISAs support annulling branch delay slots where the instruction is dynamically converted to a nop, typically if the branch is not taken (i.e., the delay slot instruction is from the taken path). It is also possible to fill a delay slot with an instruction that is useless but not harmful on one path, such generally requires a free register to hold the (possibly unused) result of the instruction. A hint instruction like prefetch is also "safe". \$\endgroup\$
    – user15426
    Commented Aug 5, 2014 at 23:15
1
\$\begingroup\$

Delayed branch executes instructions without branch and dependency after branch to avoid wasting cycles during branch and target address calculation. Branch prediction is to assume that a branch is not-taken (static branch prediction) or to predict based on history (dynamic branch prediction) to execute instructions after the branch according to the prediction. There is a difference between executing a part irrelevant to a branch and predicting a branch to execute according to prediction.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.