Professional Documents
Culture Documents
8 - RISCV - Pipelined - Arch2
8 - RISCV - Pipelined - Arch2
Muhammad Tahir
Lecture 10-11
Contents
1 Structural Hazards
2 Data Hazards
Pipeline Forwarding
4 Performance Evaluation
2/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Pipeline Limitations
3/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Pipeline Limitations
3/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Structural Hazards
• A Structural Hazard arises when two instructions (in the
pipeline) vie for the same (hardware) resource
4/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Structural Hazards
• A Structural Hazard arises when two instructions (in the
pipeline) vie for the same (hardware) resource
• Consider the pipelined execution of the following program
(assuming single memory for instructions and data)
4/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Structural Hazards
• A Structural Hazard arises when two instructions (in the
pipeline) vie for the same (hardware) resource
• Consider the pipelined execution of the following program
(assuming single memory for instructions and data)
Example program.
lw x1, 8(x2)
sw x3, 24(x4)
or x5, x6, x7
add x8, x6, x7
lw x1, 4(x2)
4/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Instruction Execution
lw x1, 8(x2) sw x3, 24(x2) or x5, x6, x7 add x8, x6, x7 lw x1, 0(x2)
clock
5/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
lw x1, 8(x2) sw x3, 24(x2) or x5, x6, x7 add x8, x6, x7 lw x1, 0(x2)
clock
6/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
lw x1, 8(x2) sw x3, 24(x2) or x5, x6, x7 add x8, x6, x7 lw x1, 0(x2)
clock
7/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
lw x1, 8(x2) sw x3, 24(x2) or x5, x6, x7 add x8, x6, x7 lw x1, 0(x2)
clock
8/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
lw x1, 8(x2) sw x3, 24(x2) or x5, x6, x7 add x8, x6, x7 lw x1, 0(x2)
clock
9/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
+ 4 PC PC PC PC + 4
Register File
IR [19:15]
raddr1
IR [24:20] ALU
raddr2 rs1
Imm WD
Immediate
Gen.
Branch
Cond. br_taken
IR [31:0]
IR IR IR
clock
10/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
+ 4 PC PC PC PC + 4
Register File
IR [19:15]
raddr1
IR [24:20] ALU
raddr2 rs1
Imm WD
Immediate
Gen.
Branch
Cond. br_taken
IR [31:0]
IR IR IR
clock
11/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Data Hazards
12/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
13/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
RAW Hazard
RAW Hazard
14/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
15/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Example program.
16/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Instructions Execution
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI x4,0(x2)
lw x1, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
17/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI x4,0(x2)
lw x1, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
18/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Hazard
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI x4,0(x2)
lw x1, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
19/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Hazard
detection unit
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI x4,0(x2)
lw x1, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
20/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Hazard
detection unit
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI x4,0(x2)
lw x1, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
21/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Hazard
detection unit
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI x4,0(x2)
lw x1, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
22/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI
lw x1,
x4,0(x2)
x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
23/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI
lw x1,
x4,0(x2)
x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
24/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI
lw x1,
x4,0(x2)
x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
25/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
Bubble
Bubble
ALU
Memory
Bubble
Fetch
Decode
Bubble
Bubble
Fetch
Decode
Bubble
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Fetch
Decode
ALU
ADD x3, x2, x1 ADDI x4, x3, 5 ADDI x4, x3, 5 ADDI x4,x6,
add x8, x3,x7
5 ADDI
lw x1,
x4,0(x2)
x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
Stall Stall Stall
26/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
t1 t2 t3 t4 t5 t6 t7 t8 t9
I1 IF1 ID1 EX1 MA1 WB1
I2 IF2 ID2 ID2 ID2 ID2 EX2 MA2 WB2
I3 IF3 IF3 IF3 IF3 ID3 EX3 MA3
27/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Stalling Drawback
28/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Stalling Drawback
28/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
29/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
Hazard
detection unit
ADD x3, x2, x1 ADDI x4, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
30/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
Forwarding
Hazard
detection unit
ADD x3, x2, x1 ADDI x4, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
31/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
ADD x3, x2, x1 ADDI x4, x3, 5 SUB x7, x6, x8 AND x9, x6, x8
clock
32/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
33/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch Decode
Bubble
ALU
Bubble
Memory
Bubble
Writeback
Bubble
Fetch
Decode
ALU
Memory
Writeback
34/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Fetch
Decode
ALU
Memory
Writeback
Fetch Decode
Bubble
ALU
Bubble
Memory
Bubble
Writeback
Bubble
Fetch
Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
Fetch Decode
ALU
Memory
Writeback
Fetch
Decode
ALU
Memory
Writeback
34/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
35/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
+ 4 PC PC PC PC + 4
Register File
IR [19:15]
raddr1
IR [24:20] ALU
raddr2 rs1
Imm WD
Immediate
Gen.
Branch
Cond. br_taken
IR [31:0]
IR IR IR
clock
36/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
+ 4 PC PC PC PC + 4
Register File
IR [19:15]
raddr1
IR [24:20] ALU
raddr2 rs1
Imm WD
Immediate
Gen.
Branch
Cond. br_taken
IR [31:0]
IR IR IR
clock
37/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
+ 4 PC PC PC PC + 4
Register File
IR [19:15]
raddr1
IR [24:20] ALU
raddr2 rs1
Imm WD
Immediate
Gen.
Branch
Cond. br_taken
IR [31:0]
IR IR IR
clock
38/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
+ 4 PC PC PC PC + 4
Register File
IR [19:15]
raddr1
IR [24:20] ALU
raddr2 rs1
Imm WD
Immediate
Gen.
Branch
Cond. br_taken
IR [31:0]
IR IR IR
clock
39/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
40/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
lw x3, 0(x10)
lw x4, 4(x10)
add x5 x3, x4
sw x5, 12(x10)
lw x6, 8(x10)
add x7 x3, x6
sw x7, 16(x10)
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
41/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
42/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
42/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
43/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Pipeline Performance
k + (n − 1)
CPIpiplined =
n
k + (n − 1)
CPIpiplined ≈ lim
n→∞ n
≈ 1.
44/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
• Recall
time
Execution Time = N × CPI ×
cycle
45/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
where
Cycle timeunpipelined
Pipeline depth ≈
Cycle timepipelined
46/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Suggested Reading
47/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
Acknowledgment
48/49
Structural Hazards Data Hazards Resolving Data Hazards Performance Evaluation
References
49/49