Professional Documents
Culture Documents
Computer Architecture
Readings
• Digital Design and Computer Architecture – David
Harris & Sarah Harris
• Chapter 8
Page Replacement Algorithms
• If physical memory is full (i.e., list of free physical pages is empty),
which physical frame to replace on a page fault?
CONTROL UNIT
PC or IP Inst Register
Recall: LC-3: A Von Neumann Machine
17
Recall: The Instruction Cycle
• FETCH
• DECODE
• EVALUATE ADDRESS
• FETCH OPERANDS
• EXECUTE
• STORE RESULT
Recall: The Instruction Set Architecture
◼The ISA is the interface between what the software
commands and what the hardware carries out
Problem
◼The ISA specifies Algorithm
❑The memory organization
◼ Address space (LC-3: 216, MIPS: 232) Program
◼ Addressability (LC-3: 16 bits, MIPS: 32 bits) ISA
◼ Word- or Byte-addressable
Microarchitecture
❑The register set Circuits
◼ R0 to R7 in LC-3 Electrons
◼ 32 registers in MIPS
• Remember
• Microarchitecture: Implementation of the ISA under
specific design constraints and goals
Implementing the ISA:Basics
Microarchitecture
Now That We Have an ISA
• How do we implement it?
Process instruction
Stored program
AS’ Sequential AS
Combinational
Logic
Logic
(State)
M[0]
M[1]
M[2]
M[3] Registers
M[4] - given special names in the ISA
(as opposed to addresses)
- general vs. special purpose
M[N-1]
Memory Program Counter
array of storage locations memory address
indexed by an address of the current instruction
• Multi-cycle machines
• Instruction processing broken into multiple cycles/stages
• State updates can be made during an instruction’s execution
• Architectural state updates made at the end of an instruction’s execution
• Advantage over single-cycle: The slowest “stage” determines cycle time
• Fetch
• Decode
• Evaluate Address
• Fetch Operands
• Execute
• Store Result
• Single-cycle machine:
• All six phases of the instruction processing cycle take a single
machine clock cycle to complete
• Multi-cycle machine:
• All six phases of the instruction processing cycle can take
multiple machine clock cycles to complete
• In fact, each phase can take multiple clock cycles to complete
Instruction Processing Viewed Another Way
• Single-cycle machine:
• Control signals are generated in the same clock cycle as the one
during which data signals are operated on
• Everything related to an instruction happens in one clock cycle
(serialized processing)
• Multi-cycle machine:
• Control signals needed in the next cycle can be generated in the
current cycle
• Latency of control processing can be overlapped with latency of
datapath operation (more parallelism)
Flash-Forward: Performance Analysis
• Execution time of an instruction
• {CPI} x {clock cycle time}
• Execution time of a program
• Sum over all instructions [{CPI} x {clock cycle time}]
• {# of instructions} x {Average CPI} x {clock cycle time}
AS’ Sequential AS
Combinational
Logic
Logic
(State)
Let’s Start with the State Elements
• Data and control inputs ALU control
5 Read 3
register 1
Read
Instruction Register 5 data 1
address Read
numbers register 2 Zero
Registers Data ALU ALU
PC 5 Write
Instruction Add Sum register result
Read
Instruction Write data 2
memory Data data
RegWrite
Instruction
address
Address Read
PC data 16 32
Sign
Instruction Add Sum
extend
Write Data
Instruction
data memory
memory
MemRead
a. Instruction memory b. Program counter c. Adder
MIPS State Elements
CLK CLK CLK
PC' PC WE3 WE
32 32 5
A1 RD1 32
32
A RD 32
5
A2 RD2 32 A RD
Instruction 32 32
Memory Data
5
A3 Memory
Register
WD3 WD
32 File 32
• Program counter:
32-bit register
• Instruction memory:
Takes input 32-bit address A and reads the 32-bit data (i.e., instruction)
from that address to the read data output RD.
• Register file:
The 32-element, 32-bit register file has 2 read ports and 1 write port
• Data memory:
Has a single read/write port. If the write enable, WE, is 1, it writes data
WD into address A on the rising edge of the clock. If the write enable is 0,
it reads address A onto RD.
Instruction Processing
• 5 generic steps
• Instruction fetch (IF)
• Instruction decode and register operand fetch (ID/RF)
• Execute/Evaluate memory address (EX/AG)
• Memory operand fetch (MEM)
• Store/writeback result (WB)
WB
IF Data
Register #
PC Address Instruction Registers ALU Address
Instruction Register #
memory ID/RF Data
Register # EX/AG memory
Data
MEM
What Is To Come: The Full MIPS Datapath
PCSrc1=Jump
Instruction [25– 0] Shift Jump address [31– 0]
left 2
26 28 0 1
Instruction [5– 0]
CLK CLK
CLK
25:21 WE3 SrcA Zero WE
0 PC' PC Instr A1 RD1 0
A RD
ALU
1 ALUResult ReadData
A RD 1
Instruction 20:16
A2 RD2 0 SrcB Data
Memory
A3 1 Memory
Register WriteData
WD3 WD
File
20:16
0
15:11
1
WriteReg4:0
PCPlus4
+
SignImm
4 15:0
<<2
Sign Extend PCBranch
+
Result
Single-Cycle Datapath for
Arithmetic and Logical Instructions
R-Type ALU Instructions
• R-type: 3 register operands
MIPS assembly (e.g., register-register signed addition)
add $s0, $s1, $s2 #$s0=rd, $s1=rs, $s2=rt
Machine Encoding
• Semantics
if MEM[PC] == add rd rs rt
GPR[rd] GPR[rs] + GPR[rt]
PC PC + 4
(R-Type) ALU Datapath
Add
4
ALU operation
25:21 Read 3
Read register 1
PC address Read
20:16 Read data 1
register 2 Zero
Instruction
Instruction Registers ALU ALU
15:11 Write result
Instruction register
Read
memory data 2
Write
data
RegWrite
1
IF ID EX MEM WB
if MEM[PC] == ADD rd rs rt
GPR[rd] GPR[rs] + GPR[rt]
Combinational
PCfrom
**Based on original figure [P&HPC + 4 2004 Elsevier. ALL RIGHTS RESERVED.]
CO&D, COPYRIGHT
state update logic
Example: ALU Design
◼ ALU operation (F2:0) comes from the control logic
A B
N N
0
F2
N
Cout +
[N-1] S
Extend
Zero
N N N N
1
0
3
2 F1:0
N
Y
I-Type ALU Instructions
• I-type: 2 register operands and 1 immediate
MIPS assembly (e.g., register-immediate signed addition)
addi $s0, $s1, 5 #$s0=rt, $s1=rs
Machine Encoding
• Semantics
if MEM[PC] == addi rs rt immediate
PC PC + 4
GPR[rt] GPR[rs] + sign-extend(immediate)
Datapath for R and I-Type ALU Insts.
Add
4
3 ALU operation
Read
Read 25:21
PC register 1 MemWrite
address Read
data 1
Read
20:16 Zero
Instruction register 2
Instruction Registers ALU ALU
Write Read
15:11 result Address
Instruction register data
Read
memory data 2
Write Data
RegDest data
memory
Write
isItype RegWrite
ALUSrc data
116 32
Sign isItype MemRead
extend
IF ID EX MEM WB
if MEM[PC] == ADDI rt rs immediate
GPR[rt] GPR[rs] + sign-extend (immediate)
Combinational
PC PC + 4 state update logic
Recall: ADD with one Literal in LC-3
• ADD assembly and machine code
SR
Field Values
Sign-ext
OP DR SR imm5 end
1 1 4 1 -2
Machine Code
OP DR SR imm5
From
0001 001 100 1 11110 FSM
15 12 11 9 8 6 5 4 0
Single-Cycle Datapath for
Data Movement Instructions
Load Instructions
• Load 4-byte word
MIPS assembly
lw $s3, 8($s0) #$s0=rs, $s3=rt
Machine Encoding
op rs=base rt imm=offset
• Semantics
if MEM[PC] == lw rt offset16 (base)
PC PC + 4
EA = sign-extend(offset) + GPR(base)
GPR[rt] MEM[ translate(EA) ]
LW Datapath
Add
0
4 add
ALU operation MemWrite
Read 3
Read register 1 MemWrite
PC address Read
data 1
Read
Instruction register 2 Zero Address Read
Instruction Registers ALU ALU data 16 32
Write Read Sign
result Address
Instruction register data extend
Read Data
memory data 2 Write
Write data Data memory
data
memory
RegDest RegWrite Write
data
isItype 116
ALUSrc
MemRead
Sign
32
isItype MemRead
extend
1
a. Data memory unit b. Sign-extension unit
Machine Encoding
op rs=base rt imm=offset
• Semantics
if Mem[PC] == sw rt offset16 (base)
PC PC + 4
EA = sign-extend(offset) + GPR(base)
MEM[ translate(EA) ] GPR[rt]
SW Datapath
Add
1
4 add
ALU operation MemWrite
Read 3
Read register 1 MemWrite
PC address Read
data 1
Read
Instruction register 2 Zero Address Read
Instruction Registers ALU ALU data 16 32
Write Read Sign
result Address
Instruction register data extend
Read Data
memory data 2 Write
Write data Data memory
data
memory
RegDest RegWrite Write
data
isItype 016 ALUSrc MemRead
Sign
32
isItype MemRead
extend
0
a. Data memory unit b. Sign-extension unit
Add
4
add
Read 3 ALU operation isStore
Read register 1 MemWrite
PC address Read
data 1
Read
Instruction register 2 Zero
Instruction Registers ALU ALU
Write Read
result Address
Instruction register data
Read
memory data 2
Write Data
data
memory
RegDest RegWrite Write
data
isItype !isStore
16 32
ALUSrc
Sign isItype MemRead
extend
isLoad
Datapath for Non-Control-Flow Insts.
Add
MemtoReg
isLoad
Single-Cycle Datapath for
Control Flow Instructions
Jump Instruction
• Unconditional branch or jump
j target
• 2 = opcode
• immediate (target) = target address
• Semantics
if MEM[PC]== j immediate26
target = { PC ✝[31:28], immediate26, 2’b00 }
PC target
✝This is the incremented PC
Unconditional Jump Datapath
isJ Add
PCSrc
4
XALU operation
Read 3 0
Read register 1 MemWrite
PC address Read
data 1
Read
Instruction register 2 Zero
Instruction Registers ALU ALU
Write Read
result Address
Instruction register data
Read
memory data 2
concat Write Data
data
memory
? RegWrite Write
data
ALUSrc
0 16 32
Sign X MemRead
extend
0
if MEM[PC]==J immediate26
60
PC = { PC[31:28], immediate26, 2’b00 } What about JR, JAL, JALR?
Other Jumps in MIPS
• jal: jump and link (function calls)
◼ Semantics
if MEM[PC]== jal immediate26
$ra PC + 4
target = { PC ✝[31:28], immediate26, 2’b00 }
PC target
watch out
PC + 4 from instruction datapath
Add
PCSrc Add Sum Branch target
4
Shift
left 2
Read
PC address sub
ALU operation
Read 3
Instruction register 1
Read
Instruction data 1
Read
Instruction register 2 To branch
memory Registers Zero
ALU bcond
concat Write control logic
register
Read
data 2
Write
data
RegWrite
16 0 32
Sign
extend
Instruction [5– 0]