Lec09 Datapath
Lec09 Datapath
Spring 2022
The Processor: Datapath & Control
• Generic implementation:
Fetch
• Use the program counter (PC) PC = PC+4
• To supply the instruction address and fetch the instruction
from memory (and update the PC) Exec Decode
• Decode the instruction (and read registers)
• Execute the instruction
2/28
Abstract Implementation View
M
Add U
Add
X
4 Shift MemWrite
Left 1
RegWrite ALUSrc
ALU Op
Read
Address
Read zero data
Instruction register 1
Memory Read M
Read data 1 U
PC Read register 2 Write X
Instruction ALU Data
address Read data
Write Memory
data 2 M
register U
Write X
data Registers
MemRead
Imm 32
Gen
Add
clock 4
Fetch Instruction
PC = PC+4 Memory
Read
PC Instruction
Address
Exec Decode
4/28
Decoding Instructions
1 Sending the fetched instruction’s opcode and function field bits to the control unit
2 Reading two values from the Register File
3 (Register File addresses are contained in the instruction)
Control
Fetch Unit
PC = PC+4
Read Addr 1
Register Read
Read Addr 2 Data 1
Exec Decode Instruction
File
Write Addr Read
Data 2
Write Data
5/28
Reading Registers “Just in Case”
• Both RegFile read ports are active for all instructions during the Decode cycle
• Using the rs1 and rs2 instruction field addresses
• Since haven’t decoded the instruction yet, don’t know what the instruction is
• Just in case the instruction uses values from the RegFile do “work ahead” by reading
the two source operands
6/28
Reading Registers “Just in Case”
• Both RegFile read ports are active for all instructions during the Decode cycle
• Using the rs1 and rs2 instruction field addresses
• Since haven’t decoded the instruction yet, don’t know what the instruction is
• Just in case the instruction uses values from the RegFile do “work ahead” by reading
the two source operands
Question
Which instructions do make use of the RegFile values?
6/28
EX-1
All instructions (except j) use the ALU after reading the registers. Please analyze
memory-reference, arithmetic, and control flow instructions.
7/28
Executing R Format Operations
R format operations: add, sub, sll, slt, xor, srl, sra, or, and
Read Addr 1
Register Read
Instruction Read Addr 2 Data 1 overflow
Fetch File zero
ALU
PC = PC+4 Write Addr
Read
Data 2
Write Data
Exec Decode
8/28
Consider the slt Instruction
• Where does the 1 (or 0) come from to store into t0 in the Register File at the end of
the execute cycle?
PC from instruction datapath
Read Read
register 2 data 1
Add Zero To branch control logic
Write Read
register data 2
Imm 32
Gen
9/28
Executing Load and Store Operations
10/28
Executing Load and Store Operations (cont.)
PCSrc
M
Add U
Add
X
4 Shift MemWrite
Left 1
RegWrite ALUSrc
ALU Op
Read
Address
Read zero data
Instruction register 1
Memory Read M
Read data 1 U
PC Read register 2 Write X
Instruction ALU Data
address Read data
Write Memory
data 2 M
register U
Write X
data Registers
MemRead
Imm 32
Gen
11/28
Executing Branch Operations
12/28
Executing Branch Operations (cont.)
Read Read
register 2 data 1
Add Zero To branch control logic
Write Read
register data 2
Imm 32
Gen
13/28
Executing Jump Operations
• jal
• The J-immediate encodes a signed offset in multiples of 2 bytes.
• The offset is sign-extended and added to the address of the jump instruction to form
the jump target address.
14/28
Creating a Single Datapath from the Parts
• Assemble the datapath elements, add control lines as needed, and design the control
path
• Fetch, decode and execute each instruction in one clock cycle – single cycle design
• no datapath resource can be used more than once per instruction, so some must
be duplicated (e.g., why we have a separate Instruction Memory and Data
Memory)
• to share datapath elements between two different instruction classes will need
multiplexors at the input of the shared elements with control lines to do the
selection
• Cycle time is determined by length of the longest path
15/28
Multiplex Insertion
Add
MemWrite
4 RegWrite
ALU Control
Read
Address
Read zero data
Instruction register 1
Memory Read
Read data 1
PC Read register 2 Write
Instruction ALU Data
address Read data
Write Memory
data 2
register
Write
data Registers
MemRead
Imm 32
Gen
16/28
Multiplex Insertion
Add MemWrite
MemToReg
4 RegWrite ALUSrc
ALU Control
Read
Address
Read zero data
Instruction register 1
Memory Read M
Read data 1 U
PC Read register 2 Write X
Instruction ALU Data
address Read data
Write Memory
data 2 M
register U
Write X
data Registers
MemRead
Imm 32
Gen
16/28
Clock Distribution
System Clock
Clock Cycle
MemWrite
RegWrite
Add
MemToReg
4 ALUSrc
ALU Control
Read
Address
Read zero data
Instruction register 1
Memory Read M
Read data 1 U
PC Read register 2 Write X
Instruction ALU Data
address Read data
Write Memory
data 2 M
register U
Write X
data Registers
MemRead
Imm 32
Gen
17/28
Adding the Branch Portion
PCSrc
M
Add U
Add
X
4 Shift MemWrite
Left 1
MemToReg
RegWrite ALUSrc
ALU Control
Read
Address
Read zero data
Instruction register 1
Memory Read M
Read data 1 U
PC Read register 2 Write X
Instruction ALU Data
address Read data
Write Memory
data 2 M
register U
Write X
data Registers
MemRead
Imm 32
Gen
18/28
Our Simple Control Structure
19/28
Summary: Adding the Control
• Selecting the operations to perform (ALU, Register File and Memory read/write)
• Controlling the flow of data (multiplexor inputs)
• Information comes from the 32 bits of the instruction
Observations:
• opcode field always in bits 6-0
• address of two registers to be read are always specified by the rs1 and rs2 fields
(bits 19–15 and 24–20)
• base register for lw and sw always in rs1 (bits 19–15)
20/28
(Almost) Complete Single Cycle Datapath
PCSrc
M
Add U
Add
X
4 Shift MemWrite
Left 1
MemToReg
RegWrite ALUSrc
ALU Control
Read
Address
Read zero data
Instruction register 1
Memory Read M
Read data 1 U
PC Read register 2 Write X
Instruction ALU Data
address Read data
Write Memory
data 2 M
register U
Write X
data Registers
MemRead
Imm 32
Gen
21/28
(Almost) Complete Single Cycle Datapath
PCSrc
M
Add U
Add
X
4 Shift MemWrite
Left 1
MemToReg
RegWrite ALUSrc
ALU Control
Read
Instruction Address
[19-15] Read zero data
Instruction register 1
Memory Instruction Read M
[24-20] Read data 1 U
PC Read register 2 Write X
Instruction ALU Data
address Instruction Read data
Write Memory
[11-7]
data 2 M
register U
Write X
data Registers
MemRead
Instruction
[31-0] Imm 32 ALU
Control
Gen ALUOp
21/28
ALU Control
1 22/28
Notice that we are using different encodings than in the book
EX: ALU Control
Controlling the ALU uses of multiple decoding levels
• main control unit generates the ALUOp bits
• ALU control unit generates ALUcontrol bits
24/28
ALU Control Truth Table
24/28
ALU Control Logic
From the truth table can design the ALU Control logic
Instr[3]
Instr[2]
Instr[1]
Instr[0]
ALUOp1
ALUOp0
ALUcontrol3
ALUcontrol2
ALUcontrol1
ALUcontrol0
25/28
(Almost) Complete Datapath with Control Unit
0
Add
M
4 U
X
Add Sum
Shift 1
Left 1 PCSrc
Branch
Instruction [6-0]
Control
ALUOp MemtoReg
ALUSrc MemWrite
RegWrite
26/28
(Almost) Complete Datapath with Control Unit
0
Add
M
4 U
X
Add Sum
Shift 1
Left 1 PCSrc
Branch
Instruction [6-0]
Control
ALUOp MemtoReg
ALUSrc MemWrite
1 RegWrite
26/28
(Almost) Complete Datapath with Control Unit
0
Add
M
4 U
X
Add Sum
Shift 1
Left 1 PCSrc
Branch
Instruction [6-0]
Control
ALUOp MemtoReg
ALUSrc MemWrite
1 RegWrite
26/28
(Almost) Complete Datapath with Control Unit
0
Add
M
4 U
X
Add Sum
Shift 1
Left 1 PCSrc
Branch
Instruction [6-0]
Control
ALUOp MemtoReg
ALUSrc MemWrite
0 RegWrite
26/28
(Almost) Complete Datapath with Control Unit
0
Add
M
4 U
X
Add Sum
Shift 1
Left 1 PCSrc
Branch
Instruction [6-0]
Control
ALUOp MemtoReg
ALUSrc MemWrite
0 RegWrite
26/28
Main Control Unit
27/28
Control Unit Logic
Instr[31]
Instr[30]
Instr[29]
Instr[28]
Instr[27]
Instr[26]
R-type lw sw beq
RegDst
ALUSrc
MemtoReg
RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOp0
28/28