Lecture 6 - Branch Predicition Flashcards
(8 cards)
5 Stage Pipeline (IIEMR) (Why is it used)
5 Stages:
- Instruction Fetch (IF)
- Instruction Decode (ID)
- Execute (EX)
- Memory Access (MEM)
- Register Write Back (WB)
Allows us to gain Instruction Level Parallelism (ILP)
Control Hazards and Branch Prediction
[Definition, Describe process]
- Branch prediction is a technique used to reduce the performance penalty associated with branch instructions in pipelined processors.
- When a branch is taken, the program counter (PC) is set to the target branch address, usually at the end of the instruction decode (ID) phase. This requires repeating the instruction fetch (IF) stage, effectively stalling the pipeline.
- When a branch is not taken, the PC remains unchanged, and there is no need to repeat the IF stage.
- Branching can introduce a significant performance penalty, potentially impacting performance by 10-30%.
Dealing with Branches (FPP)
- Freeze (or flush): Stalling the pipeline until the branch outcome is known is simple but inefficient.
- Predicted: not taken: Continue execution, assuming the branch is not taken, and must ‘back out’ of wrong decisions.
- Predicted: taken: More costly, and only applicable if the target is known before the outcome.
Compiler should reorganise to match best option.
Branch Prediction Schemes
(Static Vs Dynamic)
- Static Branch Prediction: Simplest branch prediction technique that does not rely on information about the history of code. Predicts outcome of a branch soley on the instruction. Determined by Compiler before runtime.
- Dynamic Branch Prediction: A technique that generally provides better prediction rates than static prediction. Predicts outcome based on outcome of previous branch executions. Monitors branch behaviour and learns during runtime.
Dynamic Branch Predicition Schemes
(BHT, 1-bit, 2-bit)
- (Branch History Table): Storing whether the branch was recently taken or not.
Simplest Examples of Dynamic Predicator
- One-bit predictor: THE BHT stores 1-bit values to indicate whether the branch is predicated to be taken or not.
- (Bimodal) Two-bit predictior: The BHT stores 2-bit values to indicate whether the branch is predicated to be taken or not (requiing two mispredictions to change bit).
Four states: Strongly not taken (00), weakly not taken (01), weakly taken (10), strongly taken (11).
Correlating Predictors
- The Branch Predictor uses a shard history across all branches to predict the outcome.
- Characterized as (m, n) predictors, where m is the number of previous branches correlated, and n is the number of bits for the predictor.
- Examples: (1, 1), (2, 1), (1, 2).
Tournament Predictors
Combines a global predictor with a local predictor and use a meta-predictor to choose which to use.
fds
GShare
Combines global and local prediction by XORing the global history with the branch address to predict the outcome of the branch instruction.