How and Why Branch Predictors Work - Computer Architecture - Fall 2004 | ECE 511, Study notes of Computer Architecture and Organization

Material Type: Notes; Class: Computer Architecture; Subject: Electrical and Computer Engr; University: University of Illinois - Urbana-Champaign; Term: Fall 2004;

Typology: Study notes

Pre 2010

Uploaded on 03/10/2009

koofers-user-kol-1
koofers-user-kol-1 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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:
Loops
Function calls and returns
Exceptional conditions (always goes the same way unless an exception occurs)
o Loop invariants
o User-input validation
o System call return values
o Data structure initialization (occurs only once)
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.90
Hit Rate
mttf
pf3
pf4

Partial preview of the text

Download How and Why Branch Predictors Work - Computer Architecture - Fall 2004 | ECE 511 and more Study notes Computer Architecture and Organization in PDF only on Docsity!

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:

  • Loops
  • Function calls and returns
  • Exceptional conditions (always goes the same way unless an exception occurs) o Loop invariants o User-input validation o System call return values o Data structure initialization (occurs only once)

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