CS 136 Computer Architecture II Lab 12 Data

CS 136 Computer Architecture II Lab# 12 Data Hazard - Control Hazard - Homework# 10 - Apr. 12, 2005

Review: Data Hazards n n Attempt to use item before it is ready Solution q q Forwarding Software Scheduling - Thanks to Prof. Narahari for his class notes on review of pipeline.

Example: Forwarding

Solution: Forwarding

Software Scheduling n Try producing fast code for q q q A=B+C; D=E-F; assuming A, B, C, D, E, F in memory

Branch Hazards: 3 stage stall

Branch Hazards n Control Hazard: attempt to make a decision before condition is evaluated n Branch target: The next instruction to be executed n Delay slot: Time necessary to perform branching q q Loading, decoding, issuing of several next instructions lost !!! Flushing the complete pipeline

Branch Stall Impact n If CPI = 1, 30% branch, q n Stall 3 cycles CPI = 1. 9! Minimize penalty q Determine branch taken or not sooner, AND Compute taken branch address earlier q MIPS Solution: q n n n Move Zero test to ID/RF stage Adder to calculate new PC in ID/RF stage 1 clock cycle penalty for branch versus 3

Branch Hazard Alternatives n Flushing pipe q n Stall until branch direction is clear Make use of penalty q Fill delay slots with useful /safe instructions n q q q Scheduling the Branch Delay Slot Always taken Always not taken Predict branch direction n Branch history

History-based Prediction n Make prediction based on previous observation q Assumption guiding history based prediction is that historical info on direction taken by branch in previous execution can give helpful hints on direction it will take in future execution n How much history ? What prediction ? n Finite state machine algorithm q q State: history pattern in terms of taken/not-taken Transition: use actual execution

History-based Prediction n n 1 -bit predictor 2 -bit predictors taken Not taken Prediction Taken (TT) taken Prediction Taken (TN) Not taken Prediction not Taken (NT) Prediction not Taken (NN) Not taken

Homework#10 n 6. 34 Load: assume the subsequent instructions depend on the load with a probability of 1/2, 1/4, 1/8, 1/6 …

Homework#10 n 6. 36 Hit rate of Predictor q q Branch: T-T-N-T Strategy: n n n Always taken 1 -bit predictor 2 -bit predictor

Homework#10 n 6. 40 flushing vs. stall Beq $1, $2, target #assume the branch is taken Lw $3, 40($4) Add $2, $3, $4 Sw $2, 40($4) Target: or $1, $2
- Slides: 14