22
CSCE 614 Fall 2009 1 Dynamic Hardware Branch Prediction • Goal – Allow the processor to resolve the outcome of a branch early, thus preventing control dependences from causing stalls.

Dynamic Hardware Branch Prediction

  • Upload
    keona

  • View
    44

  • Download
    0

Embed Size (px)

DESCRIPTION

Dynamic Hardware Branch Prediction. Goal Allow the processor to resolve the outcome of a branch early, thus preventing control dependences from causing stalls. Branch-Prediction Buffer. Simplest Branch history table - PowerPoint PPT Presentation

Citation preview

Page 1: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 1

Dynamic Hardware Branch Prediction

• Goal– Allow the processor to resolve the

outcome of a branch early, thus preventing control dependences from causing stalls.

Page 2: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 2

Branch-Prediction Buffer

• Simplest• Branch history table• Small memory indexed by the lower

portion of the address of the branch instruction

• 1 bit says whether the branch was taken or not.

• If the bit turns out to be wrong, the prediction bit is inverted and stored back.

Page 3: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 3

Example

• Consider a loop branch whose behavior is taken nine times in a row, then not taken once. What is the prediction accuracy for this branch?

Even if a branch is almost always taken, we predict incorrectly twice when it is not taken.

Page 4: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 4

2-bit Prediction Scheme

• A prediction must miss twice before it is changed.

Page 5: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 5

n-bit Saturating Counter

• Values: 0 ~ 2n-1

• When the counter is greater than or equal to one-half of its maximum value, the branch is predicted as taken. Otherwise, not taken.

• Studies have shown that the 2-bit predictors do almost do well, and thus most systems rely on 2-bit branch predictors.

Page 6: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 6

4096-entry 2-bitprediction buffer

Page 7: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 7

Page 8: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 8

Correlating Branch Predictor

• It may be possible to improve the accuracy if we look at the behavior of other branches.

if (aa == 2)aa = 0;

if (bb == 2)bb = 0;

if (aa != bb)

DSUBIU R3, R1, #2BNEZ (b1) R3, L1DADD R1, R0, R0

L1: DSUBIU R3, R2, #2BNEZ (b2) R3, L2DADD R2, R0, R0

L2: DSUBU R3, R1, R2BEQZ (b3) R3, L3

MIPS code

Page 9: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 9

Correlating Predictors (Two-Level Predictors)

• The behavior of b3 is correlated with the behavior of b1 and b2.– b1: not taken and b2: not taken => b3: taken

• Branch predictors that use the behavior of other branches to make a prediction

Page 10: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 10

Correlating Predictors

• Two-level predictors

if (d == 0)d = 1;

if (d == 1)

BNEZ (b1) R1, L1DADDIU R1, R0, #1

L1: DADDIU R3, R1, #-1BNEZ (b2) R3, L2

…L2:

Page 11: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 11

initial value of d

b1 value of d before b2

b2

0

1

2

Assume d = 0, 1, or 2

Page 12: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 12

1-bit Predictor (Initialized to NT)

d b1 predic

b1 action

new b1 pr

b2 predic

b2 action

new b2 pr

2

0

2

0

Page 13: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 13

(1,1) Predictor

• Every branch has two separate prediction bits.– First bit: the prediction if the last branch in the

program is not taken.– Second bit: the prediction if the last branch in

the program is taken.

• Write the pair of prediction bits together.

Page 14: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 14

Combinations & Meaning

Prediction bits Prediction if not taken

Prediction if taken

Page 15: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 15

(1,1) Predictor

d b1 predic

b1 action

new b1 pr

b2 predic

b2 action

new b2 pr

2

0

2

0

Page 16: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 16

(m,n) Predictor

• Uses the last m branches to choose from 2m branch predictors, each of which is an n-bit predictor.

• Yields higher prediction rates than 2-bit scheme

• Requires a trivial amount of additional hardware

• The global history of the most recent m branches are recorded in an m-bit shift register.

Page 17: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 17

Page 18: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 18

(m,n) Predictor

• Total number of bits:

= 2m x n x #prediction entries selected by the branch address

• Examples

Page 19: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 19

Page 20: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 20

Tournament Predictors

• Most popular form of multilevel branch predictors

• By using multiple predictors (one based on global information, one based on local information, and combining them with a selector), it can select the right predictor for the right branch.

• Alpha 21264– Uses most sophisticated branch predictor as of

2001.

Page 21: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 21

Tournament Predictors

Page 22: Dynamic Hardware Branch Prediction

CSCE 614 Fall 2009 22