


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Computer Architecture; Subject: Electrical and Computer Engr; University: University of Illinois - Urbana-Champaign; Term: Fall 2004;
Typology: Study notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Lecture 5: How and Why Branch Predictors Work 13 Sep 2004
Major Topics Why do branch predictors work? Why do BTB’s work? How do branch predictors work? Dynamic Paths
Recap of Last Lecture The important metric in branch prediction is the mean time between failures of the branch predictor. Mean time to failure (mttf) = 1 / (miss rate) = 1 / (1 – hit rate). Therefore, we can realize significant gains in performance by maximizing the hit rate, even when the hit rate is already greater than 90%.
Why Do Branch Predictors Work? In general, most branches are highly biased – a given branch goes the same way 80% or 90% of the time. Highly predictable branches / jumps include:
Mean Time to Failure
0
10
20
30
40
50
60
70
80
90
100
0.00 0.10 0.20 0.30 0.40 0.50 0.60 0.70 0.80 0. Hit Rate
mttf
Example: If p represents the probability that the loop branch is taken, then the number of basic blocks executed on average is: = 5 + p (3 + p (3 + p ( 3 … )
∞
= 0
i
p i
Thus, the probability that a loop branch is taken can play a signifcant role in accurate branch prediction.
Even without branches, functions give us code duplication. Code duplication is an essential component of the usefulness of programmable computers, because code duplication allows the number of dynamic (executed) instructions to greatly exceed the number of static (assembled) instructions. Therefore, the very nature of programming “abstraction” yields biased branches.
Any high-level if-then-else statement is assembled into code that resembles the code below. Thus, if-then-else statements introduce branches and unconditional jumps into code. This branch / jump construct isn’t something that can be optimized away – it’s a fundamental necessity of programmable computers.
r1 cmp(r2, r3) br r1, target
jmp end target: ----
end: ----
How Do Branch Predictors Work? The previous lecture described a BTB as a cache-like map from branch PC to target PC. How large should the BTB be? There are two tradeoffs to consider: access time and chip area. As the size of the BTB increases, the access time increases. Because the BTB is on the critical path, increasing the BTB’s access time may require a reduction in the maximum clock frequency. Furthermore, as the size of the BTB increases, the number of transistors that can be used to implement other features of the architecture decreases. However, as a general rule, the BTB should be as big and as associative as possible.
start
end
p (1-p)
The 2-Bit Local Predictor The only difference between the 2-bit local predictor and the 1-bit local predictor is the state machine used to implement each entry in the predictor table. The 2-bit predictor is accessed and updated in the same manner as the 1-bit predictor. Only the differences between the 2-bit predictor and the 1-bit predictor are discussed below.
Each entry in the 2-bit predictor table is actually a 2-bit saturating counter, rather than a single bit. If the counter value is 10 or 11, the branch will be predicted taken. If the counter value is 00 or 01, the branch will be predicted not taken. When the predictor is updated following the execution of a branch, if the branch was taken, then the corresponding 2-bit saturating counter is incremented. If the branch was not taken, then the corresponding 2-bit saturating counter is decremented. The state machine for the 2-bit saturating counter is shown below.
taken taken taken taken
not taken not taken not taken not taken
00 = strong not taken 10 = weak taken 01 = weak not taken 11 = weak not taken