5.0 Branch prediction Flashcards
What stage is branch prediction a part of?
Instruction fetch.
This is to allow the stage to fetch as many, and as useful, instructions as possible at the same time.
What two things does branch prediction do?
Predict if branch is taken, and the target address
How does pipeline depth affect cost of mispredicted branches?
Cost is proportional to pipeline depth
What are the two ways of doing branch direction prediction
Statically: Before program execution, done by compiler/programmer inserting a hint
Dynamically: during program execution, use global and local history to make predictions, done in hardware
What are some advantages with static branch prediction?
Easy to implement, little hardware needed.
What are a disadvantage with static branch prediction
Prediction is the same regardless of dynamic behaviour
What are the three types of static prediction?
Rule, program, profile-based
Define rule-based static prediction
Implement a rule that is always used, in the pipeline
Rules:
- Not taken (sequential fetch)
- Always taken (requires compute branch target, a little more complex, branch target known at decode stage)
- Back taken forward not taken (combine these two, loops are typically taken)
Define program-based prediction
Typically more accurat then rule-based
requires a hint in opcode, specifying behaviour for different branch-types:
- If branch is loop - take
- if compare pointer to NULL - not take
- if compare pointers - take branch to inequality
What is profile based prediction?
When you first compile and execute a binary with a certain set of training input data.
This run collects profile data that defines how branching is taken statistically
Use this to predict branches. over 50% - taken, under - not taken
What context can dynamic branch prediction use to predict branches?
Local history: The branch’s own history
Global history: Other branches’ history
what is a bimodal predictor
The hash of the PC is used as a pointer into a buffer holding a counter that defines branch outcomes
Using a two bit predictor, predict taken if 11 or 10, and not taken if 01 or 00. if branch was actually taken +1, if not taken -1.
What are the components of 2-level predictors?
How does a global 2-level predictor work?
Uses two levels of branch history to make predictions (bimodal only uses the branch address)
Two level use local history or global history
History: Outcome of prior branch executions
History acts as shift register. Newest outcome is inserted, oldest is discarded
1st level for a global predictor is a Branch History Register containing h bits and the global history. h bits shows branch outcome of last h branches
Then take the hash of the branch address and concatenate with the global history and use this as index to a pattern history table containing counters.
Why does a two-level global predictor work?
Because there is correlation between branches.
If a branch is taken - it is probable that the next also will be taken
What is a two level predictor using local history?
Have a 1st level branch history table containing local history.
Hash the PC and use this as index to the BHT.
Concat the PC hash with the entry from BHT and index into pattern history table that contains counter.