Академический Документы
Профессиональный Документы
Культура Документы
Montek Singh
Wed, Sep 21, 2005 Topic: Pipelining -- Intermediate Concepts (Control Hazards)
1
Control Hazard
A peculiar kind of RAW hazard involving the program
counter
PC written by branch instruction PC read by instruction fetch unit (not another instruction)
executed after the branch instruction are not the ones specified by the branch instruction
D X M W
Br PC = BTA Br
Unpipelined implementation
D X M W
1 2 3 4 5 6 Read PC Read PC Read PC Read PC Read PC Read PC Fetch Br-1 Fetch Br Fetch Br+1 Fetch Br+2 Fetch Br+3 Fetch T PC += 4 PC += 4 PC += 4 PC += 4 PC += 4 PC += 4 Br-1 Br Br+1 Br+2 annul Br-1 Br Br+1 annul Br-1 Br annul PC = BTA Br-1 Br
instruction)
4
go:
+
Rs
PC
Instruction Memory Rt
Registers
Imm
sign Extend
+
Bus A =
<<2 Rt Rd
IF/ID
ID/EX
Bus B
Stall Strategy: 12-Stage Pipeline 12Clock 1 Stage 1 1 Opcode Stage 2 Stage 3 BTA Stage 4 Stage 5 Branch outcome Stage 6 Stage 7 Stage 8 Stage 9 Stage 10 Stage 11 Stage 12 2 2 1 3 2 1 1 1 1 1 1 1 1 1 1 4 2 5 2 6 2 7 3 2 8 4 3 2 9 10 11 5 6 7 4 5 6 3 4 5 2 3 4 2 3 2 12 8 7 6 5 4 3 2 13 9 8 7 6 5 4 3 2 14 15 16 17 18 19 9 9 9 9 u u 8 7 8 6 7 8 5 6 7 8 4 5 6 7 8 3 4 5 6 7 8 2 3 4 5 6 7 2 3 4 5 6 2 3 4 5 2 3 4 20 21 22 23 24 25 26 27 28 29 u u u u u u 8 7 6 5 u 8 7 6 u 8 7 u 8 u
Opcode determination in stage 2 stalls pipeline Branch outcome determination in stage 6 restarts pipeline from IF or ID BTA determination in stage 4 would restart pipeline from IF for jumps PU = 3, PT = 5, PNT = 4
7
PNT Strategy: 12-Stage Pipeline 12Clock 1 Stage 1 1 Opcode Stage 2 Stage 3 BTA Stage 4 Stage 5 Branch outcome Stage 6 Stage 7 Stage 8 Stage 9 Stage 10 Stage 11 Stage 12 2 2 1 3 3 2 1 4 4 3 2 1 5 5 4 3 2 1 6 6 5 4 3 2 1 7 7 6 5 4 3 2 1 8 8 7 6 5 4 3 2 1 9 10 11 12 13 14 15 16 17 18 19 9 10 11 12 13 14 15 16 17 u 8 9 10 11 12 13 14 15 16 u 7 8 9 10 11 12 13 14 15 6 7 8 9 10 11 12 13 14 5 6 7 8 9 10 11 12 13 4 5 6 7 8 9 10 11 12 3 4 5 6 7 8 9 10 11 12 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 20 21 22 23 24 25 26 27 28 29 u u u u u u 12 11 12 10 11 12 9 10 11 12 u u u u
Pipeline continues execution assuming that the branch will fall through Instructions 1 and 12 are branches
1 is not taken, 12 is taken
taken branches (cancelling instructions already in pipeline) (cancelling BTA determination in stage 4 would restart pipeline from IF for jumps PU = 3, PT = 5, PNT = 0
8
PTA Strategy: 12-Stage Pipeline 12Opcode BTA Branch outcome Clock 1 Stage 1 1 Stage 2 Stage 3 Stage 4 Stage 5 Stage 6 Stage 7 Stage 8 Stage 9 Stage 10 Stage 11 Stage 12 2 2 1 3 3 2 1 4 4 3 2 1 5 6 7 u u+1 2 u 8 3 2 9 4 3 2 10 5 4 3 2 1 1 1 1 1 1 1 1 11 6 5 4 3 2 12 7 6 5 4 3 2 13 8 7 6 5 4 3 2 14 9 8 7 6 5 4 3 2 15 10 9 8 7 6 5 4 3 2 16 17 18 19 20 v v+1 v+2 v v+1 v+2 v v+1 v+2 v v+1 7 v 6 7 5 6 7 4 5 6 7 3 4 5 6 7 2 3 4 5 6 2 3 4 5 2 3 4 21 22 23 24 25 26 27 28 29 v+2 v+1 v+2 v v+1 v+2 v v+1 v+2 v v+1 v+2 v v+1 v+2 7 v v+1 v+2 6 7 v v+1 v+2 5 6 7 v v+1 v+2
BTA as soon as BTA is known (cancelling instructions already in pipe) (cancelling Instructions 1 and 7 are branches
1 is not taken, 7 is taken
PTB Strategy: 12-Stage Pipeline 12Opcode BTA Branch outcome Clock 1 Stage 1 1 Stage 2 Stage 3 Stage 4 Stage 5 Stage 6 Stage 7 Stage 8 Stage 9 Stage 10 Stage 11 Stage 12 2 2 1 3 3 2 1 4 4 3 2 1 5 6 7 u u+1 5 4 u 3 4 2 3 4 1 2 3 1 2 1 8 6 5 4 3 2 1 9 10 11 7 8 9 6 7 8 5 6 7 5 6 5 4 3 4 2 3 4 1 2 3 1 2 1 12 10 9 8 7 6 5 13 11 10 9 8 7 6 5 14 12 11 10 9 8 7 6 5 15 13 12 11 10 9 8 7 6 5 16 v 13 12 11 10 9 8 7 6 5 17 v+1 v 13 12 11 10 9 8 7 6 5 18 19 20 21 22 v+2 v+1 v+2 v v+1 v+2 v v+1 v+2 v v+1 v+2 v v+1 10 v 9 10 8 9 10 7 8 9 10 6 7 8 9 10 5 6 7 8 9 23 24 25 26 27 28 29
4 3 2 1
4 3 2
4 3
v+2 v+1 v+2 v v+1 v+2 v v+1 v+2 v v+1 v+2 v v+1 v+2 10 v v+1 v+2
Pipeline predicts all instructions to be taken and starts fetching from BTA
as soon as it is known in stage 4 (but without cancelling instructions already in pipeline) Instructions 1 and 10 are branch instructions
1 is not taken, 10 is taken
10
Branch penalty !
5 15 v PU v T v PT - T v PNT 1 20 20
11
Solution for 12-Stage Pipeline 12 Stall: 0.25*3+0.75*(T*5+(1-T)*4) = 3.75+0.75T Stall: 0.25*3+0.75*(T*5+(1 PTA: 0.25*3+0.75*(T*3+(1-T)*5) = 4.5-1.5T PTA: 0.25*3+0.75*(T*3+(14.5-
12
(irrespective of branch outcome) Question: What instruction do we put in the branch Question: delay slot?
Fill with NOP (always possible, penalty = 1) Fill from before (not always possible, penalty = 0) Fill from target (not always possible, penalty = 1-T) 1 BTA is dynamic BTA is another branch Fill from fall-through (not always possible, penalty = T) fall-
13
X: cond
M N P Q
A A A A A
B B B B B
Should not cancel instruction if it may cause exception A bit in the instruction set by compiler makes the choice
MIPS, SPARC, PA-RISC: delayed (0), canceling (1) PA M 88000, i860: delayed (0), plain (1)
15
16
17