Professional Documents
Culture Documents
05 SingleCycleCPU PDF
05 SingleCycleCPU PDF
Jason Mars
Tuesday, February 5, 13
The Big Picture: The Performance Perspective
Execute an
entire instruction
Tuesday, February 5, 13
The Big Picture: The Performance Perspective
Execute an
entire instruction
Tuesday, February 5, 13
The Big Picture: The Performance Perspective
Execute an
entire instruction
Tuesday, February 5, 13
The Big Picture: The Performance Perspective
Execute an
entire instruction
Tuesday, February 5, 13
Processor Datapath and Control
Tuesday, February 5, 13
Processor Datapath and Control
Tuesday, February 5, 13
Processor Datapath and Control
Tuesday, February 5, 13
Processor Datapath and Control
Tuesday, February 5, 13
Review: MIPS Instruction Formats
• 3 Formats:
6 bits 26 bits
Tuesday, February 5, 13
The MIPS Subset
Tuesday, February 5, 13
The MIPS Subset
• R-Type
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
• add rd, rs, rt opcode rs rt rd shift
funct
amount
• sub, and, or, slt
Tuesday, February 5, 13
The MIPS Subset
• R-Type
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
• add rd, rs, rt opcode rs rt rd shift
funct
amount
• sub, and, or, slt
Tuesday, February 5, 13
The MIPS Subset
• R-Type
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
• add rd, rs, rt opcode rs rt rd shift
funct
amount
• sub, and, or, slt
Tuesday, February 5, 13
Basic Steps of Execution
Tuesday, February 5, 13
Basic Steps of Execution
• Instruction Fetch
• Where is the instruction?
Tuesday, February 5, 13
Basic Steps of Execution
• Instruction Fetch
• Where is the instruction?
• Decode
• What’s the incoming instruction?
• Where are the operands in an instruction?
Tuesday, February 5, 13
Basic Steps of Execution
• Instruction Fetch
• Where is the instruction?
• Decode
• What’s the incoming instruction?
• Where are the operands in an instruction?
• Execution: ALU
• What is the function that ALU should perform?
Tuesday, February 5, 13
Basic Steps of Execution
• Instruction Fetch
• Where is the instruction?
• Decode
• What’s the incoming instruction?
• Where are the operands in an instruction?
• Execution: ALU
• What is the function that ALU should perform?
• Memory access
• Where is my data?
Tuesday, February 5, 13
Basic Steps of Execution
• Instruction Fetch
• Where is the instruction?
• Decode
• What’s the incoming instruction?
• Where are the operands in an instruction?
• Execution: ALU
• What is the function that ALU should perform?
• Memory access
• Where is my data?
• Write back results to registers
• Where to write?
Tuesday, February 5, 13
Basic Steps of Execution
• Instruction Fetch
• Where is the instruction?
• Decode
• What’s the incoming instruction?
• Where are the operands in an instruction?
• Execution: ALU
• What is the function that ALU should perform?
• Memory access
• Where is my data?
• Write back results to registers
• Where to write?
• Determine the next PC
Tuesday, February 5, 13
Basic Steps of Execution
Tuesday, February 5, 13
Basic Steps of Execution
Tuesday, February 5, 13
Basic Steps of Execution
Tuesday, February 5, 13
Basic Steps of Execution
Tuesday, February 5, 13
Basic Steps of Execution
Tuesday, February 5, 13
Basic Steps of Execution
Tuesday, February 5, 13
Where We’re Going...
Tuesday, February 5, 13
Where We’re Going...
Instruction memory
address: PC
Tuesday, February 5, 13
Where We’re Going...
Tuesday, February 5, 13
Where We’re Going...
Tuesday, February 5, 13
Where We’re Going...
Data memory
address: effective address
Tuesday, February 5, 13
Where We’re Going...
program counter
Data memory
address: effective address
Tuesday, February 5, 13
Review: Two Type of Logical Components
Tuesday, February 5, 13
Review: Two Type of Logical Components
A
Combinational
Logic
C = f(A,B)
B
Tuesday, February 5, 13
Review: Two Type of Logical Components
A
Combinational
Logic
C = f(A,B)
B
A
State C = f(A,B,state)
Element
B
clk
Tuesday, February 5, 13
Clocking Methodology
Clk
Setup Hold Setup Hold
Don t Care
. . . .
. . . .
. . . .
Tuesday, February 5, 13
Storage Element: The Register
Tuesday, February 5, 13
Storage Element: Register File
RegWrite
Read Data 1
Write Data 32 32-bit 32
32 Registers
RR1 Read Data 2
5 32
RR2
WR 5
5
Clk
Tuesday, February 5, 13
Storage Element: Register File
Read Data 1
Write Data 32 32-bit 32
32 Registers
RR1 Read Data 2
5 32
RR2
WR 5
5
Clk
Tuesday, February 5, 13
Storage Element: Register File
Read Data 1
Write Data 32 32-bit 32
32 Registers
RR1 Read Data 2
5 32
RR2
WR 5
5
Clk
Tuesday, February 5, 13
Storage Element: Register File
Tuesday, February 5, 13
Storage Element: Register File
Tuesday, February 5, 13
Storage Element: Register File
Tuesday, February 5, 13
Storage Element: Register File
Tuesday, February 5, 13
Storage Element: Register File
Tuesday, February 5, 13
Storage Element: Register File
Tuesday, February 5, 13
Storage Element: Register File
Tuesday, February 5, 13
data Write
Read register
number 1
Register 0
Register 1
M
... u Read data 1
x
Register n – 2
Register n – 1
Read register
number 2
M
u Read data 2
x
FIGURE C.8.8 The implementation of two read ports for a register file with n registers
• The implementation of two read ports register file
can be done with a pair of n-to-1 multiplexors, each 32 bits wide. The register read number
signal is used as the multiplexor selector signal. Figure C.8.9 shows how the write port is implemented.
• n registers
• done with a pair of n-to-1 multiplexors, each 32 bits wide.
AppendixC-9780123747501.indd 55 26/07/11 6:29 PM
Tuesday, February 5, 13
Storage Element: Memory
MemWrite Address
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
MemWrite Address
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
MemWrite Address
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
MemWrite Address
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
• Memory word is selected by: MemWrite Address
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
• Memory word is selected by: MemWrite Address
• Address selects the word to put on ReadData
bus
Write Data Read Data
32 32
Clk
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
• Memory word is selected by: MemWrite Address
• Address selects the word to put on ReadData
bus
Write Data Read Data
• If MemWrite = 1: address selects the memory
32 32
word to be written via the WriteData bus Clk
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
• Memory word is selected by: MemWrite Address
• Address selects the word to put on ReadData
bus
Write Data Read Data
• If MemWrite = 1: address selects the memory
32 32
word to be written via the WriteData bus Clk
• Clock input (CLK)
MemRead
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
• Memory word is selected by: MemWrite Address
• Address selects the word to put on ReadData
bus
Write Data Read Data
• If MemWrite = 1: address selects the memory
32 32
word to be written via the WriteData bus Clk
• Clock input (CLK)
• The CLK input is a factor ONLY during write MemRead
operation
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
• Memory word is selected by: MemWrite Address
• Address selects the word to put on ReadData
bus
Write Data Read Data
• If MemWrite = 1: address selects the memory
32 32
word to be written via the WriteData bus Clk
• Clock input (CLK)
• The CLK input is a factor ONLY during write MemRead
operation
• During read operation, behaves as a
combinational logic block:
Tuesday, February 5, 13
Storage Element: Memory
• Memory
• Two input buses: WriteData, Address
• One output bus: ReadData
• Memory word is selected by: MemWrite Address
• Address selects the word to put on ReadData
bus
Write Data Read Data
• If MemWrite = 1: address selects the memory
32 32
word to be written via the WriteData bus Clk
• Clock input (CLK)
• The CLK input is a factor ONLY during write MemRead
operation
• During read operation, behaves as a
combinational logic block:
• Address valid => ReadData valid after
“access time.”
Tuesday, February 5, 13
RTL: Register Transfer Language
Tuesday, February 5, 13
Instruction Fetch and Program Counter
Management
Tuesday, February 5, 13
Overview of the Instruction Fetch Unit
Tuesday, February 5, 13
Datapath for Register-Register Operations
Tuesday, February 5, 13
Datapath for Register-Register Operations
Tuesday, February 5, 13
Datapath for Register-Register Operations
Tuesday, February 5, 13
Datapath for Register-Register Operations
Tuesday, February 5, 13
Control Logic??
288 Chapter 5 The Processor: Datapath and Control
Branch
M
u
x
Add M
Add
u
x
ALU operation
Data
MemWrite
Register #
PC Address Instruction Registers ALU Address
Register # M Zero
u Data
Instruction
x memory
memory Register # RegWrite
Data
MemRead
Control
Tuesday, February 5, 13 FIGURE 5.2 The basic implementation of the MIPS subset including the necessary multiplexors and control
Control Logic??
288 Chapter 5 The Processor: Datapath and Control
Branch
M
u
x
Add M
Add
u
x
ALU operation
Data
MemWrite
Register #
PC Address Instruction Registers ALU Address
Register # M Zero
u Data
Instruction
x memory
memory Register # RegWrite
Data
MemRead
Control
Tuesday, February 5, 13 FIGURE 5.2 The basic implementation of the MIPS subset including the necessary multiplexors and control
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Load Operations
Tuesday, February 5, 13
Datapath for Store Operations
Tuesday, February 5, 13
Datapath for Store Operations
Tuesday, February 5, 13
Datapath for Store Operations
Tuesday, February 5, 13
Datapath for Store Operations
Tuesday, February 5, 13
Datapath for Store Operations
Tuesday, February 5, 13
Datapath for Store Operations
Tuesday, February 5, 13
Datapath for Store Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Datapath for Branch Operations
Tuesday, February 5, 13
Control Logic??
288 Chapter 5 The Processor: Datapath and Control
Branch
M
u
x
Add M
Add
u
x
ALU operation
Data
MemWrite
Register #
PC Address Instruction Registers ALU Address
Register # M Zero
u Data
Instruction
x memory
memory Register # RegWrite
Data
MemRead
Control
Tuesday, February 5, 13 FIGURE 5.2 The basic implementation of the MIPS subset including the necessary multiplexors and control
Control Logic??
288 Chapter 5 The Processor: Datapath and Control
Branch
M
u
x
Add M
Add
u
x
ALU operation
Data
MemWrite
Register #
PC Address Instruction Registers ALU Address
Register # M Zero
u Data
Instruction
x memory
memory Register # RegWrite
Data
MemRead
Control
Tuesday, February 5, 13 FIGURE 5.2 The basic implementation of the MIPS subset including the necessary multiplexors and control
Binary Arithmetic for the Next Address
Tuesday, February 5, 13
Binary Arithmetic for the Next Address
Tuesday, February 5, 13
Binary Arithmetic for the Next Address
Tuesday, February 5, 13
Binary Arithmetic for the Next Address
Tuesday, February 5, 13
Putting it All Together: A Single Cycle Datapath
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!!
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The R-Format (e.g. add) Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Load Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Store Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
The Branch (beq) Datapath
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
GAME: GUESS THE FUNCTION!! (Review)
Tuesday, February 5, 13
Key Points
Tuesday, February 5, 13
Key Points
Tuesday, February 5, 13
Key Points
Tuesday, February 5, 13
Key Points
Tuesday, February 5, 13
The Control Unit
Tuesday, February 5, 13
Putting it All Together: A Single Cycle Datapath
Tuesday, February 5, 13
Putting it All Together: A Single Cycle Datapath
Tuesday, February 5, 13
Putting it All Together: A Single Cycle Datapath
Tuesday, February 5, 13
Putting it All Together: A Single Cycle Datapath
Tuesday, February 5, 13
ALU Control Bits
• 5-Function ALU
ALU control input Function Operations
000 And and
001 Or or
010 Add add, lw, sw
110 Subtract sub, beq
111 Slt slt
• Note: book also has NOR, not used - and a forth bit, not used
Tuesday, February 5, 13
Full ALU
ALU operation
Zero
ALU Result
Overflow
CarryOut
ALU operation
Zero
ALU Result
Overflow
CarryOut
ALU operation
Zero
ALU Result
Overflow
CarryOut
ALU operation
Zero
ALU Result
Overflow
CarryOut
ALU operation
Zero
ALU Result
Overflow
CarryOut
ALU operation
Zero
ALU Result
Overflow
CarryOut
ALU operation
Zero
ALU Result
Overflow
CarryOut
• 5-Function ALU
ALU control input Function Operations
000 And and
001 Or or
010 Add add, lw, sw
110 Subtract sub, beq
111 Slt slt
• Based on opcode (bits 31-26) and function code (bits 5-0) from instruction
• ALU doesn’t need to know all opcodes--we will summarize opcode with
ALUOp (2 bits):
00 - lw,sw
01 - beq
10 - R-format
func
op Main 6 ALU ALUctr
6 ALUop Control 3
Control
2
Tuesday, February 5, 13
Generating ALU Control
Instruction ALUOp Instruction Function Desired ALU
opcode operation code ALU control
action input
lw 00 load word xxxxxx add 010
sw 00 store word xxxxxx add 010
beq 01 branch eq xxxxxx subtract 110
R-type 10 add 100000 add 010
R-type 10 subtract 100010 subtract 110
R-type 10 AND 100100 and 000
R-type 10 OR 100101 or 001
R-type 10 slt 101010 slt 111
ALU
Control
Logic
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Controlling the CPU
Tuesday, February 5, 13
Control Truth Table
R-format lw sw beq
Opcode 000000 100011 101011 000100
RegDst 1 0 x x
ALUSrc 0 1 1 0
MemtoReg 0 1 x x
RegWrite 1 1 0 0
Outputs MemRead 0 1 0 0
MemWrite 0 0 1 0
Branch 0 0 0 1
ALUOp1 1 0 0 0
ALUOp0 0 0 0 1
Tuesday, February 5, 13
Control
Inputs
Op5
Op4
ALUOp
Op3
ALU control block
Op2
ALUOp0 Op1
ALUOp1 Op0
Operation2
F3 Outputs
Operation R-format Iw sw beq
F2 Operation1 RegDst
F (5– 0)
ALUSrc
F1
Operation0 MemtoReg
F0 RegWrite
MemRead
MemWrite
Branch
ALUOp1
ALUOpO
Tuesday, February 5, 13
Single Cycle CPU Summary
Tuesday, February 5, 13
Single Cycle CPU Summary
Tuesday, February 5, 13
Single Cycle CPU Summary
• Which instruction takes the longest? By how much? Why is that a problem?
• ET = IC * CPI * CT
Tuesday, February 5, 13
Single Cycle CPU Summary
• Which instruction takes the longest? By how much? Why is that a problem?
• ET = IC * CPI * CT
Tuesday, February 5, 13
Single Cycle CPU Summary
• Which instruction takes the longest? By how much? Why is that a problem?
• ET = IC * CPI * CT
Tuesday, February 5, 13
Single Cycle CPU Summary
• Which instruction takes the longest? By how much? Why is that a problem?
• ET = IC * CPI * CT
• Real machines have much more variable instruction latencies than this.
Tuesday, February 5, 13