L117-19 MIPS Pipeline Implementation
L117-19 MIPS Pipeline Implementation
Program
executio 2 4 6 8 1 1 14 16 1
n order Tim 0 2 8
(in e
instructions) Instructio Data Single-
lw $1, Reg ALU Reg
100($0)
n
fetch
access
cycle
Instructio Data
lw $2, 8 Reg ALU Reg
n acces
200($0) ns fetch s
Instructio
lw $3, 300($0) 8 n
ns fetch ...
8 ns
2 ns
2 ns
2 ns
2 ns
Pipelined Datapath
ADD
4 ADD
PC <<2
ADDR RD 32 Instruction I
1 3
5 5 5
Instruction 6 2
Memory RN1 RN2 WN
RD1 Zer
Register File ALU o
WD
RD2 M
U ADDR
X
Data
E MemoryRD M
U
1 X X
6 32 WD
T
N
D
EX
IF ID Execute/ Address MEM WB
Instruction Fetch Instruction Decode Calc. Memory Access Write Back
Pipelining the datapath requires values passed from one
pipestage to next - need pipeline registers.
4 ADD
64 128
PC bits bits 97 64
<<2
ADDR RD
Instruction I bits bits
32 16 32
5 5 5
Instruction
Memory RN1 RN2
WN
Zero
RD1 ALU
Register File
WD
M
RD2 U ADDR
X
Data
E Memory RD M
U
16 X 32 X
T WD
N
D
4 ADD
64 128
bits bits
PC <<2 97 64
ADDR RD
Instruction I bits bits
32 16 32
Instruction 5 5 5
Wrong
registe
r
numb
er
Corrected Datapath
ADD
ADD
4 64 133
bits bits 102 69
<<2 bits
bits
PC
ADDR RD 5
RN1 RD1
32 Zero
Instruction RN2
ALU
5
Memory Register
5
WN File RD2 M
WD U ADDR
X
Data
E Memory RD M
U
16 X 32 X
T WD
N
5 D
ID/EX.A Regs[IF/ID.IR[rs]]
ID/EX.B Regs[IF/ID.IR[rt]]
RegDst The register destination number for the The register destination number for the
Write register comes from the rt field (bits Write register comes from the rd field (bits 15-
20-16) 11)
RegWrite None The register on the Write register input is
written with the value on the Write data
input
AlLUSrc The second ALU operand comes The second ALU operand is the sign-
from the second register file output extended, lower 16 bits of the instruction
(Read data 2)
PCSrc The PC is replaced by the output of the adder The PC is replaced by the output of the adder
that computes the value of PC + 4 that computes the branch target
MemRead None Data memory contents designated by the
address input are put on the first Read data
output
MemWrite None Data memory contents designated by the
Memto- Reg Mem Mem
address input are replaced by the value of the
Deter- Instruction RegDst ALUSrc Reg Write Read Write
Write data
Branch ALUOp1 ALUp0
input
minin R-format
MemtoReg 1 to the register
The value fed 0 0 data input
Write 1 0 value0fed to the
The 0 register Write
1 0
data input
g lw comes from 0the ALU 1 1 1 1 from
comes 0 the data
0 memory 0 0
contr sw X 1 X 0 0 1 0 0 0
ol bits beq X 0 X 0 0 0 1 0 1
Pipeline
Control
Initial design – motivated by single-cycle datapath
control –
use the same control signals
Observe:
No separate write signal for the PC as it is written
modified
Will
by be
every cycle hazard
No separate write signals for the pipeline registers as detectio
n unit!!
they are written
No separate every
read cycle
signal for instruction memory as it is read
every
clock cycle
No separate read signal for register file as it is read every
clock cycle
Need to set control signals during each pipeline stage
Since control signals are associated with components
active during a single pipeline stage, can group
control lines into five groups according to pipeline
stage
Pipelined Datapath with
Control I
PCSrc
0
M
u
x
1
Add
Add
4 Ad result
d Branch
Shift
RegWrite left
2
Read MemWrite
Instruction
R-format 1 1 0 0 0 0 0 1 0
lw 0 0 0 1 0 1 0 1 1
sw X 0 0 1 0 0 1 0 X
beq X 0 1 0 1 0 0 0 X
Pipeline Control
Implementation
Pass control signals along just like the data – extend
each pipeline register to hold needed control bits for
succeeding stages
WB
Instruction
Control M WB
EX M WB
uPCSrc WB
x EX/MEM
1
Control M WB
MEM/WB
EX M WB
IF/ID
Add
Add
4 Add result
RegWrite
Branch
Shift
left 2
MemWrite
ALUSrc
MemtoReg
Read
Instructio
PC Address register 1
Read
Read data 1
register 2 Zero
n
Instruction
[15– 0] 16 32 6
Sign ALU MemRead
extend contro
Control Instruction
l
[20– 16]
signals 0
M
ALUOp
emanate Instruction
[15– 11]
u
x
from the 1
RegDst
control
pipeline
portions of
registers
Pipelined Execution and
Control
Instruction
sequence:
lw $10, 20($1)
sub $11, $2, $3
and $12, $4, $7
or $13, $6, $7
add $14, $8, $9
lw $10, 20($1)
sub $11, $2, $3
and $12, $4, $7
or $13, $6, $7
add $14, $8, $9
I F : lw $ 1 0 , 2 0 ( $ I D : b e fo r e < 1 E X : before<2 M E M : b e fo r e < 3 W B : b e fo re < 4 >
1) > > >
Add
Add
4 Addresult
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
Read
MemtoReg
Instruction
Instruction
[15– 0] Sign ALU MemRead
extend control
Instruction
[20– 16]
0 ALUOp
M
Instruction u
[15– 11] x
C lo c k 1 1
RegDst
IF : sub $11, $2, $ ID : lw $10, 20($ E X : before<1 M E M : b e fo r e < 2 W B : b e fo re < 3 >
3 1) > >
Add
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
1
MemtoReg
Read
Instruction
PC Address register
1 Read $1
X data 1
Read
register 2 Zero
Instruction Registers Read $X
memory Write 0 ALU ALU Read
data 2 Address 1
register M result data
Data M
u
Write memory u
x x
data 1
0
Write
data
Instruction
20 [15– 0] Sign 20 ALU MemRead
extend control
Instruction
10 [20– 16] 10
0 ALUOp
M
Instruction u
X [15– 11] X x
C lo c k 2 1
RegDst
IF: and $12, $4, $ ID : sub $11, $2, $ E X : lw $ 1 0 , . . . M E M : b e fo r e < 1 W B : b e fo r e < 2
5 3 > >
Add
4 Add
Add result
RegWri
Shift Branch
left 2
te
ALUSrc
MemW
2 Read
Instruction
M emtoRe g
rite
PC Address register $1
1 Read $2
3 data 1
register
Read Zero
Instruction Registers Read $3
memory 2 ALU ALU
Write 0 Address Read
data 2 1
register M result data
Data M
u
Write memory u
x x
data 1
0
Write
data
Instruction
X [15–0] Sign X 20 ALU MemRead
extend contro
l
Instruction
X [20–16] X 10
0 ALUOp
M
Instruction u
11 [15–11] 11 x
C lo c k 3 1
RegDst
IF: or $13, $6, $ ID: and $12, $2, $ E X: sub $11, . . . M E M : lw $ 1 0 , . . . W B : b e fo r e < 1
7 3 >
Ad
d
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
4 Read
MemtoReg
Instruction
PC Address register 1 $2
Read $4
5 data 1
Read
register Zero
Instruction Registers Read $5
2 $3
memory Write 0 ALU ALU Read
data 2 Address 1
registe M result data
Data M
r u
memory u
x x
Write 1
data 0
Write
data
Instruction
X [15–0] Sign X ALU MemRead
extend control
Instruction
X [20–16] X
0 ALUO
M p 10
Instruction u
12 [15–11] 12 11 x
C lo c k 4 1
RegDs
t
IF: add $14, $8, $ ID: or $13, $6, $ EX : and $12, . . . M E M : sub $1 W B : lw $ 1 0 , . . .
9 7 1, . . .
Ad
d
Add
4 Addresult
RegWrite
Branch
Shift
left 2
MemWrite
ALUSrc
6 Read
MemtoReg
Instruction
PC Address register $4
1 Read $6
7 data 1
Read
register Zero
Instruction Registers Read $7 $5
memor 10 2 ALU ALU
Write 0 Address Read
data 2 1
y register M result data
Data M
u
Write memory u
x x
data 1
0
Write
data
Instruction
X [15–0] Sign X AL MemRead
extend U
contro
l
Instruction
X [20–16] X
0 ALUOp
M 11 10
Instruction u
13 [15–11] 13 12 x
C lock 1
5
RegDst
I F : a fte r< 1 > ID: add $14, $8, $ EX : or $13, . . . M E M : and $12, . . . W B: sub $1
9 1, . . .
Ad
d
4 Add
Addresult
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
8
MemtoReg
Read
Instruction
PC Address register $6
1 Read $8
data
9
Read
register 1 Zero
Instruction Registers Read $9
2 $7
memory 11 Write 0 ALU ALU Read
data Address 1
register M result data
2 Data M
u
Write memor u
x x
data 1 y
0
Write
data
Instruction
X [15–0] Sign X AL MemRead
extend control
U
Instruction
X [20–16] X
0 ALUO
M p 12 11
Instruction u
14 [15–11] 14 13 x
C lock 1
6 RegDst
I F : a fte r< 2 ID : a fte r< 1 > EX: add $1 M EM : or $1 W B: and $1
> 4, . . . 3, . . . 2, . . .
Ad
d
4 Add
Add result
RegWrite
Shift Branch
left
MemWrite
2 ALUSrc
Read
MemtoReg
Instruction
Instruction
[15–0] Sign ALU MemRead
extend control
Instruction
[20–16]
0 ALUOp
M 13 12
Instruction u
[15–11] 14 x
C lo c k 7 1
RegDst
I F : a fte r< 3 > I D : a fte r< 2 > E X : a fte r< 1 > M EM : add $1 W B: or $1
4, . . . 3, . . .
Ad
d
4 Add
Add result
RegWrite
Shift Branch
left
MemWrite
2 ALUSrc
MemtoReg
Read
Instruction
PC Address register
1 Read
data 1
Read
register 2 Zero
Instruction Registers Read
memory 13 Write 0 ALU ALU Read
data Address 1
register M result data
2 Data M
u
Write x memory u
data x
1
0
Write
data
Instruction
[15–0] Sign ALU MemRead
extend control
Instruction
[20–16]
0 ALUOp
M 14 13
Instruction u
[15–11] x
C lo c k 8 1
RegDst
Pipelined Execution and
Control
I F : a fte r < 4 > I D : a fte r< 3 > E X : a f te r < 2 > M E M : a f te r < 1 > W B: add $1
4, . . .
Add
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrit
ALUSrc
Read
Instruction
MemtoRe
PC Address register 1
e
Read
Read data 1
register 2 Zero
g
Instruction Registers Read ALU ALU
memory 14 Write 0 Read 1
data 2 result Address data
register M M
u Data
Write x memory u
data x
1
0
Write
data
Instruction
[15–0] Sign ALU MemRead
extend control
Instruction
[20–16]
0 ALUOp
M 14
Instruction u
[15–11] x
C lo ck 1
9 RegDst