Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Branch prediction:

• Branch prediction is a technique used to speed execution of instructions on processors


that use pipelining.
• Branch prediction is a technique used in CPU design that attempts to guess the outcome
of a conditional operation and prepare for the most likely result

In computer architecture, a branch predictor is the part of a processor that determines whether a
conditional branch (jump) in the instruction flow of a program is likely to be taken or not. This is called
branch prediction.

In computer architecture, a branch predictor is a digital circuit that tries to guess which way a branch
(e.g. an if-then-else structure) will go before this is known definitively. The purpose of the branch
predictor is to improve the flow in the instruction pipeline.

Static branch prediction:


• Static Branch Prediction predicts always the same direction for the same branch during
the whole program execution.
• It comprises hardware-fixed prediction and compiler-directed prediction.
• In static prediction, all decisions are made at compile time.
• This does not allow the prediction scheme to adapt to program behavior that changes
over time.

• Simple hardware-fixed direction mechanisms can be:


• Predict always not taken
• Predict always taken
• Backward branch predict taken, forward branch predict not taken
Sometimes a bit in the branch opcode allows the compiler to decide the prediction direction

• Static prediction is the simplest branch prediction technique because it does not rely on
information about the dynamic history of code executing.
• Instead it predicts the outcome of a branch based solely on the branch instruction

Dynamic branch prediction:


• Monitor branch behavior and learn
– Key assumption: past behavior indicative of future behavior
• Predict the present (current branch) using learned history
• Identify individual branches by their PC or dynamic branch history

• Predict:
-Outcome: taken or not taken
-Target: address of instruction to branch to
• Check actual outcome and update the history
• Squash incorrectly fetched instructions
• 2-bit predictor:
• This predictor changes prediction only on two successive mispredictions.
• Two bits are maintained in the prediction buffer and there are four different states.
• Two states corresponding to a taken state and two corresponding to not taken state.
• Dynamic branch prediction uses information about taken or not taken branches
gathered at run-time to predict the outcome of a branch
• Strongly not taken
• Weakly not taken
• Weakly taken
Strongly taken

• When a branch is evaluated, the corresponding state machine is updated.


• Branches evaluated as not taken decrement the state toward strongly not taken, and
branches evaluated as taken increment the state toward strongly taken.

You might also like