Pipelined Datapath and Control
Pipelined Datapath and Control
PCSrc
4
Add
P Add
C Shift
RegWrite left 2
Read Read
register 1 data 1 MemWrite
ALU
Read Instruction Zero
Read Read
address [31-0] 0
register 2 data 2 Result Address
Write
1 Data
Instruction register MemToReg
memory
memory Registers ALUOp
Write
data ALUSrc Write Read
1
data data
Instr [15 - 0] Sign
RegDst
extend MemRead
0
Instr [20 - 16]
0
Instr [15 - 11]
1
1
Pipeline registers
In pipelining, we divide instruction execution into multiple cycles
— IF ID EX MEM WB
Information computed during one cycle may be needed in a later
cycle:
— Instruction read in IF stage determines which registers are
fetched in ID stage, what immediate is used for EX stage, and
what destination register is for WB
— Register values read in ID are used in EX and/or MEM stages
— ALU output produced in EX is an effective address for MEM or
a result for WB
PCSrc
Read Read
register 1 data 1 MemWrite
ALU
Read Instruction Zero
Read Read
address [31-0] 0
register 2 data 2 Result Address
Write
1 Data
Instruction register MemToReg
memory
memory Registers ALUOp
Write
data ALUSrc Write Read
1
data data
Instr [15 - 0] Sign
RegDst
extend MemRead
0
Instr [20 - 16]
0
Instr [15 - 11]
1
3
Propagating values forward
4
The destination register
1
PCSrc
Read Read
register 1 data 1 MemWrite
ALU
Read Instruction Zero
Read Read
address [31-0] 0
register 2 data 2 Result Address
Write
1 Data
Instruction register MemToReg
memory
memory Registers ALUOp
Write
data ALUSrc Write Read
1
data data
Instr [15 - 0] Sign
RegDst
extend MemRead
0
Instr [20 - 16]
0
Instr [15 - 11]
1
5
What about control signals?
Some of the control signals will not be needed until later stages
— These signals must be propagated through the pipeline until
they reach the appropriate stage
— We just pass them in the pipeline registers, along with the
data
0
ID/EX
WB EX/MEM
PCSrc
Control M WB MEM/WB
IF/ID EX M WB
4
Add
P Add
C Shift
RegWrite left 2
Read Read
register 1 data 1 MemWrite
ALU
Read Instruction Zero
Read Read
address [31-0] 0
register 2 data 2 Result Address
Write
1 Data
Instruction register MemToReg
memory
memory Registers ALUOp
Write
data ALUSrc Write Read
1
data data
Instr [15 - 0] Sign
RegDst
extend MemRead
0
Instr [20 - 16]
0
Instr [15 - 11]
1
7
An example execution sequence
Here’s a sample sequence of instructions to execute
8
Cycle 1 (filling)
IF: lw $8, 4($29) ID: ??? EX: ??? MEM: ??? WB: ???
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P 1004
Add
C Shift
RegWrite (?) left 2
???
9
Cycle 2
IF: sub $2, $4, $5 ID: lw $8, 4($29) EX: ??? MEM: ??? WB: ???
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P 1008
Add
C Shift
RegWrite (?) left 2
29 129 ???
1004 Read Read
register 1 data 1 MemWrite (?)
ALU
Read Instruction X X ??? Zero
Read Read ???
address [31-0] 0
register 2 data 2 Result Address
??? Write ??? MemToReg
1 Data
Instruction register (?)
memory
memory ??? Registers ALUOp (???)
Write ???
data ALUSrc (?) ??? Write Read
1
data data
4 Sign ???
RegDst (?) ???
extend MemRead (?)
0
8 ???
0 ??? ??? ???
X ???
1
???
10
Cycle 3
IF: and $9, $10, $11 ID: sub $2, $4, $5 EX: lw $8, 4($29) MEM: ??? WB: ???
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P 1012
Add
C Shift
RegWrite (?) left 2
4 104 129
1008 Read Read
register 1 data 1 MemWrite (?)
ALU
Read Instruction 5 X Zero
Read Read 105 ???
address [31-0] 0
register 2 data 2 Result Address
4
??? Write 133 MemToReg
1 Data
Instruction register (?)
memory
memory ??? Registers ALUOp (add)
Write
??? Write ???
data ALUSrc (1) Read
1
data data
X Sign 4
RegDst (0)
extend MemRead (?) ???
0
X 8
0 8 ??? ???
2 X
1
???
11
Cycle 4
IF: or $16, $17, $18 ID: and $9, $10, $11 EX: sub $2, $4, $5 MEM: lw $8, 4($29) WB: ???
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P 1016
Add
C Shift
RegWrite (?) left 2
10 110 104
1012 Read Read
register 1 data 1 MemWrite (0)
ALU
Read Instruction 11 105 Zero
Read Read 111 133
address [31-0] 0
register 2 data 2 Result Address
–1
??? Write MemToReg
1 Data
Instruction register (?)
memory
memory ??? Registers ALUOp (sub)
Write
99 ???
data ALUSrc (0) X Write Read
1
data data
X Sign X
RegDst (1)
extend MemRead (1) ???
0
X X
0 2 8 ???
9 2
1
???
12
Cycle 5 (full)
IF: add $13, $14, $0 ID: or $16, $17, $18 EX: and $9, $10, $11 MEM: sub $2, $4, $5 WB:
lw $8, 4($29)
1
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P 1020
Add
C Shift
RegWrite (1) left 2
17 117 110
1016 Read Read
register 1 data 1 MemWrite (0)
ALU
Read Instruction 18 111 Zero
Read Read 118 -1
address [31-0] 0
register 2 data 2 Result Address
8 Write 110 MemToReg
1 Data
Instruction register (1)
memory
memory 99 Registers ALUOp (and)
Write
X 99
data ALUSrc (0) 105 Write Read
1
data data
X Sign X
RegDst (1)
extend MemRead (0) 133
0
X X
0 9 2 8
16 9
1
99
13
Cycle 6 (emptying)
IF: ??? ID: add $13, $14, $0 EX: or $16, $17, $18 MEM: and $9, $10, $11 WB: sub
$2, $4, $5
1
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P ???
Add
C Shift
RegWrite (1) left 2
14 114 117
1020 Read Read
register 1 data 1 MemWrite (0)
ALU
Read Instruction 0 0 118 Zero
Read Read 110
address [31-0] 0
register 2 data 2 Result Address
2 Write 119 MemToReg
1 Data
Instruction register (0)
memory
memory -1 Registers ALUOp (or)
Write
X X
data ALUSrc (0) 111 Write Read
1
data data
X Sign X
RegDst (1)
extend MemRead (0) -1
0
X X
0 16 9 2
13 16
1
-1
14
Cycle 7
IF: ??? ID: ??? EX: add $13, $14, $0 MEM: or $16, $17, $18 WB: and
$9, $10, $11
1
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P ???
Add
C Shift
RegWrite (1) left 2
110
15
Cycle 8
IF: ??? ID: ??? EX: ??? MEM: add $13, $14, $0 WB: or $16,
$17, $18
1
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P ???
Add
C Shift
RegWrite (1) left 2
119
16
Cycle 9
IF: ??? ID: ??? EX: ??? MEM: ??? WB: add
$13, $14, $0
1
0 ID/EX
WB EX/MEM
PCSrc Control M WB MEM/WB
IF/ID EX M WB
4
Add
P ???
Add
C Shift
RegWrite (1) left 2
114
17
That’s a lot of diagrams there
Clock cycle
1 2 3 4 5 6 7 8 9
lw $t0, 4($sp) IF ID EX MEM WB
sub $v0, $a0, IF ID EX ME WB
$a1 M
and $t1, $t2, $t3 IF ID EX ME WB
M
or $s0, $s1, IF ID EX MEM WB
$s2Compare the last few slides with the pipeline diagram above
add $t5, $t6, $0 IF ID EX MEM WB
— You can see how instruction executions are overlapped
— Each functional unit is used by a different instruction in each
cycle
— The pipeline registers save control and data values generated
in previous clock cycles for later use
— When the pipeline is full in clock cycle 5, all of the hardware
units are utilized. This is the ideal situation, and what makes
pipelined processors so fast
19
Note how everything goes left to right,
except …
1
PCSrc
Read Read
register 1 data 1 MemWrite
ALU
Read Instruction Zero
Read Read
address [31-0] 0
register 2 data 2 Result Address
Write
1 Data
Instruction register MemToReg
memory
memory Registers ALUOp
Write
data ALUSrc Write Read
1
data data
Instr [15 - 0] Sign
RegDst
extend MemRead
0
Instr [20 - 16]
0
Instr [15 - 11]
1
20
An example with dependencies
How would this code sequence fare in our 5-stage MIPS pipeline?
21
Data hazards in the pipeline diagram
Clock cycle
1 2 3 4 5 6 7 8 9
or $13, $6, $2 IF ID EX ME WB
M
22
Things that are okay
Clock cycle
1 2 3 4 5 6 7 8 9
or $13, $6, $2 IF ID EX ME WB
M
23
Dependency arrows
Clock cycle
1 2 3 4 5 6 7 8 9
or $13, $6, $2 IF ID EX ME WB
M
24
Bypassing the register file
The actual result $1 - $3 is computed in clock cycle 3, before it
is needed in cycles 4 and 5
or $13, $6, $2 IF ID EX ME WB
M
25
Pipleline Registers to the rescue!
Pipeline stages communicate through pipeline registers:
IF/ID ID/EX EX/MEM MEM/WB
PC ALU output
available here
ALU
Registers
Instruction
memory
Data
memory
Rt 0
0
Rd
1
26