ELT3047 Computer Architecture
Hoang Gia Hung
Faculty of Electronics and Telecommunications
University of Engineering and Technology, VNU Hanoi
Lecture 8: Single Cycle Processor
Design (cont.)
4.4 in textbook
Last lecture review
Inst [25:21]
Inst [15:11]
M
U
X
Inst [15:0]
M
U
X
RR1
RR2
WR
WD
RD1
RD2
Register
File
5
5
5
RegWrite
Sign
Extend
ALU
result
ALU
ALUcontrol
4
Data
Memory
Address
Read
Data
Write
Data
MemWrite
opcode
31:26
rs
25:21
rt
20:16
rd
15:11
shamt
10:6
funct
5:0
000000
01001
01010
01000
00000
100000
Left Shift
2-bit
P
C
Add
4
Add
M
U
X
PCSrc
Instruction
Memory
is0?
Address
Instruction
RegDst
MemRead
ALUSrc
MemToReg
M
U
X
tín hiệu điều khiển
Control signals from last lecture
Control Signal Execution Stage Purpose
RegDst
Decode/Operand Fetch
Select the destination register
number
RegWrite
Decode/Operand Fetch
RegWrite
Enable
writing of register
ALUSrc
ALU
Select the 2
nd
operand for ALU
ALUControl
ALU
Select the operation to be
performed
MemRead /
MemWrite
Memory
Enable reading/writing of data
memory
MemToReg
RegWrite
Select the result to be written
back to register file
PCSrc
Memory/RegWrite
Select the next PC value
How do we generate these signals?
lựa chọn toán
hạng là hằng
số hay nd t.ghi
cho phép ghi
dữ liệu hay k
chọn operand
thứ 2 cho ALU
chọn operator
chọn kết quả
lấy ra từ registe
hay alu
Generating Control Signals
The control signals are generated based on the instruction to be
executed:
Opcode Instruction Format
Example: R-Format instruction RegDst = 1 (use Inst[15:11])
R-Type instruction also has 6-bit "funct" (function code, Inst[5:0]) field
Idea:
Design a combinatorial circuit to generate these signals based on opcode
and possibly function code a control unit.
Instruction
Memory
Address
Instruction
Data
Memory
Address
Read
Data
Write
Data
ALU result
ALU
is0?
Datapath
Control unit
RegWrite
ALUcontrol
MemWrite
PCSrc
RegDst
MemRead
ALUSrc
MemToReg
Control unit: block diagram
Inst [25:21]
Inst [15:11]
M
U
X
Inst [15:0]
M
U
X
RR1
RR2
WR
WD
RD1
RD2
Register
File
5
5
5
RegWrite
Sign
Extend
ALU
result
ALU
ALUcontrol
4
Data
Memory
Address
Read
Data
Write
Data
MemWrite
opcode
31:26
rs
25:21
rt
20:16
rd
15:11
shamt
10:6
funct
5:0
000000
01001
01010
01000
00000
100000
Left Shift 2-
bit
PC
Add
4
Add
M
U
X
PCSrc
Instruction
Memory
is0?
Address
Instruction
RegDst
MemRead
ALUSrc
MemToReg
M
U
X
Control
Control unit: analysis
Approach:
Take note of the instruction subset to be implemented: opcode and function
code (if applicable)
Go through each signal: observe how the signal is generated based on the
instruction opcode and/or function code
Instruction subset:
0 rs rt rd shamt funct
31:26 5:025:21 20:16 15:11 10:6
35 or 43 rs rt address
31:26 25:21 20:16 15:0
4 rs rt address
31:26 25:21 20:16 15:0
R-type
Load/
Store
Branch
opcode
always
read
read,
except for
load
write for R-
type and load
sign-extend and
add
xét từng loại lệnh một, để xm op và func là gì
rẽ nhánh
Control unit: generating RegDst
If opcode = I-type
False (0): Write register = Inst[20:16]
True (1): Write register = Inst[15:11]
M
U
X
0
1
Signal
Control unit: generating RegWrite
If opcode = R-type || load
False (0): No register write
True (1): New value will be written
M
U
X
0
1
Signal
Control unit: generating ALUSrc
If opcode = I-type
False (0): Operand2 = Register Read Data 2
True (1): Operand2 = SignExt(Inst[15:0])
Control unit: generating MemRead
If opcode = load
False (0): Not performing memory read access
True (1): Read memory using Address
Control unit: generating MemWrite
If opcode = store
False (0): Not performing memory write operation
True (1): memory[Address] Register Read Data 2
Control unit: generating MemToReg
If opcode = load
True (1): Register write data = Memory read data
False (0): Register write data = ALU result
M
U
X
0
1
Signal
Control unit: generating PCSrc
If opcode = branch && taken
False (0): Next PC = PC + 4
True (1): Next PC = SignExt(Inst[15:0]) << 2 + (PC + 4)
M
U
X
0
1
Signal
A closer look at ALU
The ALU is a combinatorial circuit:
Capable of performing several arithmetic/logical operations in our chosen
subset
How do we design the ALUcontrol signals?
ALUcontrol Function
0000
AND
0001
OR
0010
add
0110
subtract
0111
slt
1100
NOR
ALU: One Bit At A Time
A simplified 1-bit MIPS ALU can be implemented as follows:
4 control bits are needed:
Ainvert:
1 to invert input A
Binvert:
1 to invert input B
Operation (2-bit)
To select one of the 3 results*
ALUcontrol
Function
Ainvert Binvert Operation
0 0 00
AND
0 0 01
OR
0 0 10
add
0 1 10
subtract
0 1 11
slt
1 1 00
NOR
* No circuitry for slt (and/nor, or, add/sub only)
ALU: Two-level Implementation
Now we can start to design for ALUcontrol signal, which
depends on:
Opcode (6-bit) field and Function Code (6-bit) field
Brute Force approach:
Finding expressions directly with all 12 variables (opcode & function code)
Multilevel Decoding approach:
Use some of the inputs to reduce the cases, then generate the full outputs
Simplify the design process, reduce the size of the main controller,
potentially speedup the circuit
Multilevel Decoding Basic Idea:
Instruction type
ALUop
lw / sw
00
beq
01
R-type
10
1. Use opcode to generate a 2-bit ALUop
signal representing classification of the
instructions
2. Use ALUop signal and function code field
(for R-type instructions) to generate the 4-bit
ALUcontrol signal
ALU: Two-level Implementation
opcode
31:26
rs
25:21
rt
20:16
rd
15:11
shamt
10:6
funct
5:0
6
Control
ALU
Control
6
ALU
4
ALUcontrol
ALUop
2
00: lw, sw
01: beq
10: add, sub, and, or, slt
0000: and
0001: or
0010: add
0110: sub
0111: set on less than
Step 1.
Generate 2-bit ALUop signal
from 6-bit opcode.
Step 2.
Generate
ALUcontrol
signal from ALUop
and optionally 6-bit
Funct field.
ALUcontrol & ALUop expected values
Opcode ALUop
Instruction
Operation
Funct
field
ALU
action
ALU
control
lw load word add
sw store word add
beq branch equal subtract
R-type add add
R-type subtract subtract
R-type AND AND
R-type OR OR
R-type
set on less
than
set on
less than
00
00
01
10
10
10
10
10
xxxxxx
xxxxxx
xxxxxx
10 0000
10 0010
10 0101
10 0100
10 1010
0111
0010
0010
0110
0010
0110
0001
0000
Generation of 4-bit ALUcontrol will be discussed first,
that of 2-bit ALUop signal will be discussed later
Generating ALUcontrol signals (1/2)
Input: 6-bit Funct field and 2-bit ALUop
Output: 4-bit ALUcontrol
Find the simplified expressions
ALUop
Funct Field
( F[5:0] == Inst[5:0] )
ALU
control
MSB LSB
F5
F4 F3 F2 F1 F0
lw
sw
beq
add
sub
and
or
slt
0 0
X X X X X X
0 0 1 0
0 0
X X X X X X
0 0 1 0
0 1
X X X X X X
0 1 1 0
X
1 0
1 0 0 0 0 0
0 0 1 0
1 0
1 0 0 0 1 0 0 1 1 0
1 0
1 0 0 1 0 0
0 0 0 0
1 0
1 0 0 1 0 1
0 0 0 1
1 0
1 0 1 0 1 0
0 1 1 1
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
ALUcontrol
3
= 0
ALUcontrol
2
= ?
ALUop
0
+ ALUop
1
F
1
thi có thể có
Generating ALUcontrol signals (2/2)
Simple combinational logic
ALUcontrol
ALUcontrol3
0
ALUcontrol2
ALUcontrol1
ALUcontrol0
ALU Control block
ALUop
ALUOp0 (LSB)
ALUOp1 (MSB)
F3
F2
F1
F0
F(5-0)
2
ALUcontrol
2
= ALUOp
0
+ ALUOp
1
∙F
1

Preview text:

ELT3047 Computer Architecture 4.4 in textbook
Lecture 8: Single Cycle Processor Design (cont.) Hoang Gia Hung
Faculty of Electronics and Telecommunications
University of Engineering and Technology, VNU Hanoi Last lecture review Instruction P Memory Add M C 4 Instruction U Left Shift Add X Address 2-bit o 31:26 0 p 0
PCSrc tín hiệu điều khiển c 0 o 0 d 0 e 0 25:21 01001 ALUcontrol rs Inst [25:21] 5 4 RR1 RD1 20:16 01010 5 is0? MemWrite RR2 rt Register ALU 5 ALUSrc 15:11 01000 M WR File ALU Address rd RD2 M result U WD Data MemToReg Inst [15:11] U X Memory shamt 00000 10:6 X RegWrite Read M RegDst Data Write U Data funct 1 Sign 0 Inst [15:0] 5:0 X 0 0 Extend 0 MemRead 0
Control signals from last lecture Control Signal Execution Stage Purpose
Select the destination register lựa chọn toán RegDst Decode/Operand Fetch hạng là hằng number số hay nd t.ghi Decode/Operand Fetch cho phép ghi RegWrite Enable writing of register RegWrite dữ liệu hay k chọn operand ALUSrc ALU
Select the 2nd operand for ALU thứ 2 cho ALU Select the operation to be chọn operator ALUControl ALU performed MemRead /
Enable reading/writing of data Memory MemWrite memory chọn kết quả
Select the result to be written MemToReg RegWrite lấy ra từ registe back to register file hay alu PCSrc Memory/RegWrite Select the next PC value lựa chọn địa chỉ tiếp theo là PC + 4 hay ...
❑ How do we generate these signals? Generating Control Signals
❑ The control signals are generated based on the instruction to be executed:
➢ Opcode → Instruction Format
➢ Example: R-Format instruction → RegDst = 1 (use Inst[15:11])
➢ R-Type instruction also has 6-bit "funct" (function code, Inst[5:0]) field ❑ Idea:
➢ Design a combinatorial circuit to generate these signals based on opcode
and possibly function code → a control unit. Datapath Instruction Address Memory is0? Data Address ALU Memory ALU result Write Read Instruction Data Data l e e t ro t t n rc Reg Dst Wri USrc co S L mRead U A e PC Reg mTo Reg e AL M MemWri M Control unit Control unit: block diagram Instruction Memory PC Add M 4 Instruction U Add X Co Left Shift 2- Address bit PCSrc n opcode 000000 31:26 trol 25:21 01001 ALUcontrol rs Inst [25:21] 4 5 RR1 RD1 5 20:16 01010 MemWrite is0? RR2 rt Register ALU 5 ALUSrc WR File ALU 15:11 01000 M result Address RD2 rd U M WD Data MemToReg Inst [15:11] X U Memory shamt 00000 X 10:6 RegWrite Read Data M Write RegDst Data U funct 100000 X Inst [15:0] Sign 5:0 Extend MemRead Control unit: analysis ❑ Approach:
➢ Take note of the instruction subset to be implemented: opcode and function
code (if applicable) xét từng loại lệnh một, để xm op và func là gì
➢ Go through each signal: observe how the signal is generated based on the
instruction opcode and/or function code ❑ Instruction subset: R-type 0 rs rt rd shamt funct 31:26 25:21 20:16 15:11 10:6 5:0 Load/ 35 or 43 rs rt address Store 31:26 25:21 20:16 15:0 Branch 4 rs rt address rẽ nhánh 31:26 25:21 20:16 15:0 opcode always read, write for R- sign-extend and read except for type and load add load
Control unit: generating RegDst ❑ If opcode = I-type ➢ 0 False (0): Write register = Inst[20:16] M U 1 ➢ True (1): Write register = Inst[15:11] X Signal
Control unit: generating RegWrite ❑ If opcode = R-type || load ➢ False (0): No register write ➢ True (1): New value will be written
Control unit: generating ALUSrc ❑ If opcode = I-type 0 M ➢ False (0):
Operand2 = Register Read Data 2 U 1 X ➢ True (1): Operand2 = SignExt(Inst[15:0]) Signal
Control unit: generating MemRead ❑ If opcode = load ➢ False (0):
Not performing memory read access ➢ True (1): Read memory using Address
Control unit: generating MemWrite ❑ If opcode = store ➢ False (0):
Not performing memory write operation ➢ True (1):
memory[Address] ← Register Read Data 2
Control unit: generating MemToReg ❑ If opcode = load ➢ 0 True (1):
Register write data = Memory read data M U 1 ➢ False (0):
Register write data = ALU result X Signal Control unit: generating PCSrc
❑ If opcode = branch && taken ➢ 0 M False (0): Next PC = PC + 4 U ➢ True (1):
Next PC = SignExt(Inst[15:0]) << 2 + (PC + 4) 1 X Signal A closer look at ALU
❑ The ALU is a combinatorial circuit:
➢ Capable of performing several arithmetic/logical operations in our chosen subset
❑ How do we design the ALUcontrol signals? ALUcontrol Function 0000 AND 0001 OR 0010 add 0110 subtract 0111 slt 1100 NOR ALU: One Bit At A Time
➢ A simplified 1-bit MIPS ALU can be implemented as follows: ▪ 4 control bits are needed: ▪ ALUcontrol Ainvert: FunctionAinvert Binvert Operation 1 to invert input A ▪ Binvert: 0 0 00 AND ▪ 1 to invert input B 0 0 01 OROperation (2-bit) 0 0 10 add
To select one of the 3 results* 0 1 10 subtract 0 1 11 slt 1 1 00 NOR
* No circuitry for slt (and/nor, or, add/sub only) ALU: Two-level Implementation
❑ Now we can start to design for ALUcontrol signal, which depends on:
➢ Opcode (6-bit) field and Function Code (6-bit) field ❑ Brute Force approach:
➢ Finding expressions directly with all 12 variables (opcode & function code)
❑ Multilevel Decoding approach:
➢ Use some of the inputs to reduce the cases, then generate the full outputs
Simplify the design process, reduce the size of the main controller,
potentially speedup the circuit
❑ Multilevel Decoding Basic Idea:
1. Use opcode to generate a 2-bit ALUop Instruction type ALUop
signal representing classification of the lw / sw 00 instructions beq 01
2. Use ALUop signal and function code field
(for R-type instructions) to generate the 4-bit R-type 10 ALUcontrol signal ALU: Two-level Implementation Step 1. Generate 2-bit ALUop signal opc Co 31: from 6-bit opcode. 6 ode 26 ntr 25: ol rs 21 Step 2. 20: ALUop Generate rt 2 16 ALUcontrol 00: lw, sw 01: beq signal from ALUop 15: ALU 10: add, sub, and, or, slt rd and optionally 6-bit 11 Funct field. sha 4 10: ALUcontrol mt 6 0000: and fun 5:0 0001: or 6 ALU ct 0010: add Control 0110: sub 0111: set on less than
ALUcontrol & ALUop expected values Instruction Funct ALU ALU Opcode ALUop Operation field action control lw 00 load word xxxxxx add 0010 sw 00 store word xxxxxx add 0010 beq 01 branch equal xxxxxx subtract 0110 R-type 10 add 10 0000 add 0010 R-type 10 subtract 10 0010 subtract 0110 R-type 10 AND 10 0100 AND 0000 R-type 10 OR 10 0101 OR 0001 set on less set on R-type 10 10 1010 0111 than less than
Generation of 4-bit ALUcontrol will be discussed first,
that of 2-bit ALUop signal will be discussed later
Generating ALUcontrol signals (1/2)
▪ Input: 6-bit Funct field and 2-bit ALUop ALUcontrol = 0 3
▪ Output: 4-bit ALUcontrol ALUcontrol = ? 2
▪ Find the simplified expressions
ALUop + ALUop F 0 1 1 thi có thể có Funct Field ALUop
( F[5:0] == Inst[5:0] ) ALU control MSB LSB F5 F4 F3 F2 F1 F0 lw 0 0 X X X X X X 0 0 1 0 sw 0 0 X X X X X X 0 0 1 0 beq 0 X 1 X X X X X X 0 1 1 0 add 1 0 X 1 X 0 X 0 0 0 0 0 0 1 0 sub 1 0 X 1 X 0 X 0 0 1 0 0 1 1 0 and 1 0 X 1 X 0 X 0 1 0 0 0 0 0 0 or 1 0 X 1 X 0 X 0 1 0 1 0 0 0 1 slt 1 0 X 1 X 0 X 1 0 1 0 0 1 1 1
Generating ALUcontrol signals (2/2) ▪ Simple combinational logic ALUop ALUcontrol = ALUOp 2 0 ∙F 2 + ALUOp ALU Control block 1 1 ALUOp0 (LSB) ALUcontrol3 ALUOp1 (MSB) 0 ALUcontrol2 F3 ALUcontrol ALUcontrol1 F2 F(5-0) F1 ALUcontrol0 F0