Академический Документы
Профессиональный Документы
Культура Документы
The Processor:
Datapath & Control
Major Goals
Single-cycle implementation
Multiple-cycle implementation
Instruction count
Determined by the compiler and the ISA
Clock cycle time &
Clock cycles per instruction (CPI)
Determined by the implementation of the processor
Big Picture
add
add
PC
Data
Reg. #
Addr. Instr.
Addr.
Reg. #
Reg. #
Instruction
Memory
Registers
Data
ALU
Data
Memory
0. Fundamentals
current inputs
Sequential logic circuits: circuits whose output depends on both the
Clocks
10
State element 2
State element 1
Cycle time
Combinational
Logic
Register File
11
Reading a register:
Writing a register:
Register File with Two Read Ports & One Write Port
12
R e a d r e g is te r
nu m be r 1
Read data
port 1
R e a d r e g is te r
nu m be r 2
Register File
W r i te
r e g is te r
Write data
port
Write
Read data
port 2
13
1. Building a Datapath
14
Instruction memory:
Instruction
address
PC
Instruction
Add Sum
Instruction
memory
a. Instruction memory
b. Program counter
c. Adder
Executing Instruction
15
PC
add
read address
Instruction
Instruction Memory
Copyright Dr. Lai An Chow
16
17
18
32
000000
10001
10010
01000
00000
100000
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
instr[25-21]
17
R e ad
r e g i s te r 1
18
R e ad
r e g i s te r 2
Register
Value
s1
100
s2
200
PC
instr[20-16]
read
address
instr.
R ea d
da ta 1
R ea d
da ta 2
W rite
d at a
Instruction Memory
ALU
opera tion
Ze ro
Register
File
W rite
r e g i s te r
instr[15-11]
100
AL U
res u lt
200
300
RegWrite
17 (s1)
8 (t0)
1000 (immediate)
100011
10001
01000
5 bits
5 bits
6 bits
instr[25-21]
17
instr[20-16]
Read
register 2
Registers
Write
register
Instruction
instr[20-16]
Write
data
Read
data 1
16
200
s1
100
Memory[1100]
50
MemWrite
Zero
ALU ALU
result
Read
data 2
1100
200
(not used)
1000
(Offset)
Value
t0
ALU operation
100
RegWrite
instr[15-0]
Register
16 bits
3
Read
register 1
17
Sign
extend
Read
data
Address
50
Data
memory
Write
data
32
MemRead
Note: For load word instruction, MemWrite has to be de-asserted so that the memory will not be modified by
incoming write data.
Copyright Dr. Lai An Chow
18
Register
Value
t0
200
t1
200
PC
1000
1004
PC+4 from
Instruction datapath
Add Sum
Read
register 1
Instruction
Read
register 2
Write
register
Branch target
1012
8
3
Read
data 1
ALU operation
200
Register
File
ALU
Read
data 2
Write
data
Shift
left 2
Zero
To branch
control logic
200
RegW rite
instr[15-0]
16
Sign
extend
32
19
20
A dd
PC
R e ad
a dd res s
I n s t r u c ti o n
I n s t r u c t io n
m e m o ry
R e g is t e r s
R e ad
r e g i s te r 1
R e ad
re g i st e r 2
R e ad
d a ta 1
W r it e
r e g i s te r
R e ad
d a ta 2
A L U o p e r a tio n
M e mtoRe g
ALU Src
M
u
x
W r it e
d a ta
Z e ro
A L U A LU
re s ult
16
A d d re s s
W ri te
d a ta
R e g W r it e
M e m W rite
S ig n 3 2
e xte n d
R ea d
d a ta
M
u
x
D a ta
m e m o ry
M e m R ea d
21
PCS rc
M
u
x
Add
A d d A LU
r es u lt
4
S hift
le f t 2
PC
R e ad
a dd res s
I n s t r u c ti o n
I n s t r u c t io n
m e m o ry
R e ad
r e g i s te r 1
R e g is te r s
3
R e ad
re g i st e r 2
R e ad
d a ta 1
W r it e
r e g i s te r
R e ad
d a ta 2
W r it e
d a ta
16
S ig n
e xte n d
M e m W rite
M e mtoRe g
ALU Src
M
u
x
Z e ro
AL U A LU
re s u lt
A d d re s s
W ri te
d a ta
R e g W r it e
32
R ea d
d a ta
D a ta
m e m ory
M
u
x
M e m R ea d
22
PCS rc
M
u
x
Add
A d d A LU
r es u lt
4
S hift
le f t 2
R e ad
r e g i s te r 1
R e ad
a dd res s
PC
I n s t r u c ti o n
I n s t r u c t io n
m e m o ry
M
u
x
R e g is te r s
3
R e ad
re g i st e r 2
R e ad
d a ta 1
W r it e
r e g i s te r
R e ad
d a ta 2
A L U o p e r a tio n
M
u
x
W r it e
d a ta
Z e ro
AL U A LU
re s u lt
S ig n
Destination register:
e xte n d
For R-format: it is rd field (bits 15-11)
For lw:
it is rt field (bits 20-16)
32
R ea d
d a ta
A d d re s s
W ri te
d a ta
R e g W r it e
16
M e m W rite
M e mtoRe g
ALU Src
M
u
x
D a ta
m e m ory
M e m R ea d
23
2. Control
24
0
M
u
x
ALU
Add res ult
A dd
Shi ft
left 2
R egDst
B ranc h
1
PC S rc
M emRead
M emtoReg
Control A LUOp
M emWr ite
A LUS rc
R egWrite
Instru ction [25 21]
PC
R ea d
a ddr ess
Ins tructio n
[3 1 0 ]
Instructi on
memory
Read
r egi ster 1
0
M
u
x
1
R ead
data 1
Read
r egi ster 2
Re gisters R ead
W rite
data 2
r egi ster
0
M
u
x
1
W rite
da t a
Zer o
ALU ALU
r es ult
Add re ss
Write
data
16
Sign
e xtend
R ead
data
D a ta
me mor y
1
M
u
x
0
32
A LU
contr ol
Ins truction [5 0]
Control Unit
25
Function
0000
and
0001
or
0010
add
0110
subtract
0111
1100
NOR
26
0
M
u
x
ALU
Add res ult
A dd
Shi ft
left 2
R egDst
B ranc h
1
PC S rc
M emRead
M emtoReg
Control A LUOp
M emWr ite
A LUS rc
R egWrite
Instru ction [25 21]
PC
R ea d
a ddr ess
Read
r egi ster 1
Instructi on
memory
0
M
u
x
1
R ead
data 1
Read
r egi ster 2
Re gisters R ead
W rite
data 2
r egi ster
0
M
u
x
1
W rite
da t a
Zer o
ALU ALU
r es ult
Write
data
16
Sign
e xtend
R ead
data
Add re ss
D a ta
me mor y
1
M
u
x
0
32
ALU
control
Ins truction [5 0]
27
1-level decoding
more input bits
2-level decoding
less input bits, less complicated potentially faster logic
Opcode
6 bit
ALU Op
2 bit
Opcode
ALU Control
6 bit
4 bit
Function
code
Function
code
6 bit
6 bit
28
ALUOp (2 bits)
Function code of instruction (6 bits)
Instruction
operation
Desired ALU
action
Instruction
opcode
ALUOp
Function
code
ALU control
input
lw
add
load word
00
XXXXXX
0010
sw
add
store word
00
XXXXXX
0010
beq
subtract
branch equal
01
XXXXXX
0110
add
add
R-type
10
100000
0010
sub
subtract
R-type
10
100010
0110
and
and
R-type
10
100100
0000
or
or
R-type
10
100101
0001
slt
R-type
10
101010
0111
29
Function code
Operation
ALUOp1
ALUOp0
F5
F4
F3
F2
F1
F0
0010
lw, sw
0110
beq
0010
0110
0000
0001
0111
R-type
Instr.
30
ALUOp
ALU control block
ALUOp0
ALUOp1
F3
F (5 0)
F2
Operation2
Operation1
Operation
F1
Operation0
F0
10
31
RegDst
RegWrite
None
ALUSrc
PCSrc
MemRead
None
MemWrite
None
MemtoReg
32
set based entirely on the 6-bit opcode, with the exception of PCSrc
Zero output of ALU is true (i.e., two source operands are equal)
33
0
M
u
x
ALU
Add res ult
A dd
Shi ft
left 2
R egDst
B ranc h
1
PC S rc
M emRead
M emtoReg
Control A LUOp
M emWr ite
A LUS rc
R egWrite
Instru ction [25 21]
PC
R ea d
a ddr ess
Ins tructio n
[3 1 0 ]
Instructi on
memory
Read
r egi ster 1
0
M
u
x
1
R ead
data 1
Read
r egi ster 2
Re gisters R ead
W rite
data 2
r egi ster
0
M
u
x
1
W rite
da t a
Zer o
ALU ALU
r es ult
Add re ss
Write
data
Instru ction [15 0]
16
Sign
e xtend
R ead
data
D a ta
me mor y
1
M
u
x
0
32
A LU
contr ol
Ins truction [5 0]
11
34
Instruction
R-format
lw
sw
beq
sw & beq will not modify any register, it is ensured by making RegWrite to 0
So, we dont care what write register & write data are
Instruction
R-format
lw
35
sw
43
beq
35
0
M
u
x
ALU
Add res ult
A dd
Shi ft
left 2
R egDst
B ranc h
PC S rc
M emRead
M emtoReg
Control A LUOp
M emWr ite
A LUS rc
R egWrite
R ea d
a ddr ess
Ins tructio n
[3 1 0 ]
Instructi on
memory
Read
r egi ster 1
R ead
data 1
Read
r egi ster 2
Re gisters R ead
W rite
data 2
r egi ster
Zer o
ALU ALU
r es ult
0
M
u
x
1
W rite
da t a
16
Sign
e xtend
1
M
u
x
0
D a ta
me mor y
Write
data
0
R ead
data
Add re ss
32
A LU
contr ol
Ins truction [5 0]
10
36
0
M
u
x
ALU
Add res ult
A dd
Shi ft
left 2
R egDst
B ranc h
PC S rc
M emRead
M emtoReg
Control A LUOp
M emWr ite
A LUS rc
R egWrite
R ea d
a ddr ess
Ins tructio n
[3 1 0 ]
Instructi on
memory
Read
r egi ster 1
R ead
data 1
Read
r egi ster 2
Re gisters R ead
W rite
data 2
r egi ster
Zer o
ALU ALU
r es ult
0
M
u
x
1
W rite
da t a
Write
data
16
Ins truction [5 0]
Sign
e xtend
1
R ead
data
Add re ss
D a ta
me mor y
1
M
u
x
0
32
A LU
contr ol
00
12
37
0
M
u
x
ALU
Add res ult
A dd
Shi ft
left 2
R egDst
B ranc h
1
PC S rc
M emRead
M emtoReg
Control A LUOp
M emWr ite
A LUS rc
PC
R ea d
a ddr ess
Instructi on
memory
Read
r egi ster 1
R ead
data 1
Read
r egi ster 2
Re gisters R ead
W rite
data 2
r egi ster
R egWrite
0
M
u
x
1
Zer o
ALU ALU
r es ult
0
M
u
x
1
W rite
da t a
X
Add re ss
Write
data
16
Sign
e xtend
R ead
data
D a ta
me mor y
1
M
u
x
0
32
A LU
contr ol
Ins truction [5 0]
01
38
Signal name
R-format
lw
sw
beq
Op5
Op4
Op3
Op2
Op1
Op0
RegDst
Inputs
Outputs
ALUSrc
MemtoReg
RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOp0
Outputs
R -format
Iw
sw
beq
RegD st
ALUSrc
MemtoReg
RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOpO
13
Shift
left 2
jump addr
[31-0]
28
Add
Add
RegDst
A LU
result
40
M
u
x
M
u
x
S hift
left 2
Jmp
Branch
MemRead
MemtoReg
ALUOp
MemW rite
ALUSrc
RegWrite
Read
address
Instruction
memor y
Read
register 1
0
M
u
x
1
R ea d
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
Zero
ALU ALU
result
Write
data
Instr uction [15 0]
16
S ign
extend
Read
data
Address
Data
m emory
1
M
u
x
0
32
ALU
control
Instruction [5 0]
41
42
Motivation:
Many instructions do not involve all five functions units
Question:
Why dont vary the clock for instructions with shorter execution time?
Answer:
A variable-speed clock is very difficult to implement in hardware
The better solution:
Consider a shorter clock cycle and allow different types
of instructions to take different numbers of clock cycles
(clock cycle is derived from the basic functional unit delays)
Copyright Dr. Lai An Chow
14
Multicycle Implementation
43
Why Multicycle?
44
Key advantage:
Different types of instructions can have different number of cycles
Short instructions can complete early
e.g. R-type instruction can execute in 4 cycles instead of 5
Better performance as compared to the single-cycle implementation
Other advantage:
Better sharing of function units less hardware cheaper
A single functional unit can be used more than once per instruction
(as long as it is used at different clock cycles)
e.g. a single memory unit is used for both instructions and data
e.g. need only a single ALU, rather than one ALU and two adders
Trade-off
45
15
46
Store Branch
Jump
ALU
# of instructions
25%
10%
11%
2%
52%
# of clocks/instr.
47
IR
PC
Address
Data
A
Register #
ALU
Memory
ALUOut
Register #
Data
MDR
B
Register #
Instruction or data
memory
Register file
48
instruction
PC
instruction decode
& register read
IR
Address
ALU
Data
A
Register #
ALU
Memory
ALUOut
Register #
Data
Instruction or data
memory
Cycle 1
Copyright Dr. Lai An Chow
MDR
B
Register #
Register file
Cycle 2
Cycle 3
Cycle 4
16
49
50
All except IR hold data only between a pair of adjacent clock cycles
Thus, MDR, A, B, ALUOut do not need a write control signal
IR needs to hold the instruction until the end of instruction execution
Thus, it requires a write control signal
Since several functional units are shared for different purposes,
Multiplexors have to be added or expanded
Thus, additional control signals are needed
See next couple of slides for new multiplexors and control signals
51
PC
M
u
x
Address
Memory
Data
new
Write
data
[25-21]
Read
register 1
[20-16]
Re ad
Read
register 2 data 1
[15-0]
IR
[15-0]
MDR
[15-11]
0
M
u
x
1
Write
register
Re ad
data 2
0
M
u
x
1
Sign
e xtend
32
Zero
ALU ALU
result
ALUOut
0
4
Write
data
16
0
M
u
x
1
1 M
u
2 x
3
Shift
left 2
17
52
M
u
x
Address
Memory
Data
[25-21]
Read
register 1
Re ad
Read
register 2 data 1
[20-16]
[15-0]
[15-11]
IR
Write
data
[15-0]
0
M
u
x
1
Write
register
M
u
x
Re ad
data 2
B
4
Write
data
1
2
0
M
u
x
1
MDR
Zero
ALU ALU
result
ALUOut
M
u
x
16
32
Sign
e xtend
extended
Shift
left 2
53
P CWriteCond
PCS ource
PCWrite
IorD
O utputs
Control
ALUS rcA
Re gW rite
Me mtoReg
IRWrite
ALUO p
ALUSrcB
M emRe ad
M emWrite
54
Op
[5 0]
RegDst
0
M
26
Instruction [25 0]
S hift
left 2
Instruction
[31-26]
PC
0
M
u
x
1
Instruction
[25 21]
Address
Memory
Instruction
[15 0]
Write
data
Read
Read
register 2 data 1
Registers
Write
Read
register data 2
Instruction
register
Instruction
[15 0]
Memory
data
register
0
M
Instruction u
x
[15 11]
1
0
M
u
x
1
16
Sign
extend
32
Shift
left 2
1 u
x
2
Zero
ALU ALU
result
ALUOut
0
4
Write
data
Jump
addre ss [3 1-0 ]
PC [31- 28 ]
0
M
u
x
1
Read
register 1
Instruction
[20 16]
MemData
28
1 M
u
2 x
3
ALU
control
Instruction [5 0]
18
55
3. Multicycle Implementation
1. Instruction Fetch
56
Hardware operations:
IR = Memory[PC];
PC = PC + 4;
Send the PC to the memory as address
Read an instruction from memory
Write the instruction into the IR
Increment the PC by 4 without violating the ALU usage constraints
57
Hardware operations:
(Assume the existence of two registers and an offset field,
no harm to do the computation early even if they do not exist)
A = Reg[IR[25-21]];
B = Reg[IR[20-16]];
ALUOut = PC + (sign-extend(IR[15-0]) << 2);
Read rs & rt from register file and store them to registers A & B
Compute the branch target address (sign extension and left shift)
Store the branch target address in ALUOut
19
3. Instruction Execution
58
Hardware operations:
a) ALU operation, or
b) Memory address computation, or
c) Branch completion
Well look at them one by one in subsequent slides
59
Hardware operations:
ALUOut = A op B;
Send both registers A and B to the ALU
Perform ALU operation specified by the function code on A & B
Store the result in ALUOut
60
Hardware operations:
ALUOut = A + sign-extend(IR[15-0]);
Sign-extend the 16-bit offset to a 32-bit value
Send both register A and the 32-bit offset to the ALU
Store the result in ALUOut
20
61
62
63
Hardware operations:
a) Memory access (load / store), or
b) Instruction completion (for all R-type and some I-type)
Well look at them one by one in subsequent slides
21
64
65
66
Hardware operations:
Reg[IR[20-16]] <= MDR;
Get the data value stored in MDR during previous step
Write the value into destination register in the register file
22
67
R-type
Memory references
Branches
Jumps
IR = Memory[PC]
PC = PC + 4
Instruction
fetch
A = Reg[IR[25-21]]
B = Reg[IR[20-16]]
ALUOut = PC + (sign-extend(IR[15-0]) << 2)
Instruction
decode /
register fetch
Execution,
addr comp.,
branch/jump
completion
ALUOut = A op B
Memory
access, R-type
completion
ALUOut = A +
sign-extend(IR[15-0])
If (A == B)
PC = ALUOut
PC = PC[31-28] ||
(IR[25-0] << 2)
Load:
MDR=Memory[ALUOut]
Reg[IR[15-11]]
= ALUOut
Store:
Memory[ALUOut] = B
Load:
Reg[IR[20-16]] = MDR
Memory read
completion
Total steps
load: 5; store: 4
68
P CWriteCond
IorD
M emWrite
IorD
IRWrite
O utputs
ALUO p
ALUSrcB
Control
ALUS rcA
ALUSrcB
Re gW rite
Me mtoReg
IRWrite
PCSource
PCS ource
PCWrite
M emRe ad
Op
[5 0]
ALUSrcA
RegDst
0
M
26
Instruction [25 0]
S hift
left 2
Instruction
[31-26]
PC
0
M
u
x
1
Instruction
[25 21]
Address
Memory
Instruction
[15 0]
Write
data
Read
Read
register 2 data 1
Registers
Write
Read
register data 2
Instruction
register
Instruction
[15 0]
Memory
data
register
0
M
Instruction u
x
[15 11]
1
0
M
u
x
1
16
Sign
extend
32
Shift
left 2
1 u
x
2
Zero
ALU ALU
result
ALUOut
0
4
Write
data
Jump
addre ss [3 1-0 ]
PC [31- 28 ]
0
M
u
x
1
Read
register 1
Instruction
[20 16]
MemData
28
1 M
u
2 x
3
ALU
control
Instruction [5 0]
23
Control: IorD
70
PC
1
0
Address
IR
Instr.
or
Data
IorD
MDR
Control: IRWrite
71
IRWrite
IR
RegWrite
Data
Reg. #
Reg. #
MDR
Reg. #
72
24
73
Base case: PC + 4
Happens at step 1, while fetching instruction
PC
ALUSrcA = 0
IR
Data
Reg. #
0
1
2
3
ALUOut
Reg. #
Reg. #
ALUSrcB = 01
Copyright Dr. Lai An Chow
74
PC
ALUSrcA = 0
IR
Data
Reg. #
0
1
2
3
ALUOut
Reg. #
Reg. #
ALUSrcB = 11
Copyright Dr. Lai An Chow
75
25