Академический Документы
Профессиональный Документы
Культура Документы
Nguy n Tr Thnh
Information Systems Department Faculty of Technology College of Technology ntthanh@vnu.edu.vn
11/12/2010
11/12/2010
Instruction Execution
PC instruction memory, fetch instruction Register numbers register file, read registers Depending on instruction class
Use ALU to calculate Arithmetic result Memory address for load/store Branch target address Access data memory for load/store PC target address or PC + 4
11/12/2010
Implementing MIPS
We're ready to look at an implementation of the MIPS instruction set Simplified to contain only
arithmetic-logic instructions: add, sub, and, or, slt memory-reference instructions: lw, sw control-flow instructions: beq, j
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
op
6 bits
rs
5 bits
rt
5 bits
rd
shamt funct
16 bits
R-Format
op
6 bits
11/12/2010
rs
rt
26 bits
offset
I-Format J-Format
4
op
address
ALU Control
ALU used for
Load/Store: F = add Branch: F = subtract R-type: F depends on funct field
ALU control 0000 0001 0010 0110 0111 1100
11/12/2010
ALU Control
Assume 2-bit ALUOp derived from opcode
Combinational logic derives ALU control
opcode lw sw beq R-type ALUOp 00 00 01 10 Operation load word store word branch equal add subtract AND OR set-on-less-than funct XXXXXX XXXXXX XXXXXX 100000 100010 100100 100101 101010 ALU function add add subtract add subtract AND OR set-on-less-than ALU control 0010 0010 0110 0010 0110 0000 0001 0111
11/12/2010
11/12/2010
PC
a. Instruction memory b. Program counter c. Adder
Three elements used to store and fetch instructions and increment the PC
Instruction memory
Datapath
11/12/2010 10
PC
ADDR
Memory
RD
Instruction
11/12/2010
11
5 Register numbers 5 5
ALU control
3 Read
ALU operation
ALU
Data
data 1 Read register 2 Registers Write register Read data 2 Write data RegWrite
Datapath
11/12/2010
12
Instruction op rs
5
rd
5
shamt funct
Operation
3
RN1
RN2
Register File
WD
WN RD1
ALU
Zero
RD2 RegWrite
11/12/2010
13
MemWrite
Instruction
Read register 1 Read register 2 Registers Write register Write data RegWrite 16
3 Read data 1
Address
16
Write data
Sign extend
32
Address
MemRead
Datapath
14
lw rt, offset(rs)
RN1
RN2
Register File
WD
WN RD1
ALU
Zero
RD2 RegWrite E X T N D
MemWrite ADDR WD
32
Memory
RD
16
MemRead
15
11/12/2010
sw rt, offset(rs)
RN1
RN2
Register File
WD
WN RD1
ALU
Zero
RD2 RegWrite E X T N D
MemWrite ADDR WD
32
Memory
RD
16
MemRead
16
11/12/2010
No shift hardware required: simply connect wires from input to output, each shifted left 2 bits
Read register 1 Read register 2 Registers Write register Write data RegWrite 16 Sign extend 32
Add Sum Shift left 2 3 Read data 1 ALU Zero Read data 2
Branch target
ALU operation
Instruction
11/12/2010
Datapath
17
ADD
Operation
<<2
RN1 RN2
Register File
WD
WN RD1
ALU
Zero
RD2 RegWrite E X T N D
16
32
11/12/2010
add rd,rs,rt
Operation
3
RN1
RN2
Register File
WD
WN RD1
ALU
M U X
Zero
RD2 RegWrite E X T N D
MemWrite ADDR
MemtoReg RD
M U X
16
32
ALUSrc
Data Memory
WD MemRead
11/12/2010
19
lw rt,offset(rs)
Operation
3
RN1
RN2
Register File
WD
WN RD1
ALU
M U X
Zero
RD2 RegWrite E X T N D
MemWrite ADDR
MemtoReg RD
M U X
16
32
ALUSrc
Data Memory
WD MemRead
11/12/2010
20
sw rt,offset(rs)
Operation
3
RN1
RN2
Register File
WD
WN RD1
ALU
M U X
Zero
RD2 RegWrite E X T N D
MemWrite ADDR
MemtoReg RD
M U X
16
32
ALUSrc
Data Memory
WD MemRead
11/12/2010
21
PC
ADDR RD
<<2
Operation
3
PCSrc
RN1
RN2
Register File
WD
WN RD1
ALU
M U X
Zero
RD2 RegWrite E X T N D
MemWrite ADDR
MemtoReg RD
M U X
16
32
ALUSrc
Data Memory
WD MemRead
22
Datapath Executing lw
PC
ADDR RD
<<2
Operation
3
PCSrc
RN1
RN2
Register File
WD
WN RD1
ALU
M U X
Zero
RD2 RegWrite E X T N D
MemWrite ADDR
MemtoReg RD
M U X
16
32
ALUSrc
Data Memory
WD MemRead
lw rt,offset(rs)
11/12/2010
23
Datapath Executing sw
PC
ADDR RD
<<2
Operation
3
PCSrc
RN1
RN2
Register File
WD
WN RD1
ALU
M U X
Zero
RD2 RegWrite E X T N D
MemWrite ADDR
MemtoReg RD
M U X
16
32
ALUSrc
Data Memory
WD MemRead
sw rt,offset(rs)
11/12/2010
24
PC
ADDR RD
<<2
Operation
3
PCSrc
RN1
RN2
Register File
WD
WN RD1
ALU
M U X
Zero
RD2 RegWrite E X T N D
MemWrite ADDR
MemtoReg RD
M U X
16
32
ALUSrc
Data Memory
WD MemRead
beq r1,r2,offset
11/12/2010
25
Control
Control unit takes input from
the instruction opcode bits
11/12/2010
26
ALU Control
Plan to control ALU: main control sends a 2-bit ALUOp control field to the ALU control. Based on ALUOp and funct field of instruction the ALU control generates the 3-bit ALU control field
ALU control field 000 001 010 110 111 Function and or add sub slt
Recall
Main Control
add for load/stores (ALUOp 00) sub for branches (ALUOp 01) one of and, or, add, sub, slt for R-type instructions, depending on the instructions 6-bit funct field (ALUOp 10)
11/12/2010 27
11/12/2010
ALUOp Funct field Operation ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 0 0 X X X X X X 010 0 1 X X X X X X 110 1 X X X 0 0 0 0 010 1 X X X 0 0 1 0 110 1 X X X 0 1 0 0 000 1 X X X 0 1 0 1 001 1 X X X 1 0 1 0 111 Truth table for ALU control bits
28
opcode 31-26
rs 25-21
rt 20-16
address 15-0
New multiplexor
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [20 16] 1 M u Instruction [15 11] x 0 RegDst Instruction [15 0]
Read data 1
MemWrite ALUSrc 1 M u x 0 32 ALU control Zero ALU ALU result MemtoReg Address Read data 1 M u x 0
Write data
Data memory
MemRead
Instruction [5 0] ALUOp
Adding control to the MIPS Datapath III (and a new multiplexor to select field to specify destination register): what are the functions of the 9 control signals?
11/12/2010 30
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
Instruction [5 0]
MIPS datapath with the control unit: input to control is the 6-bit instruction opcode field, output is seven 1-bit signals and the 2-bit ALUOp signal 11/12/2010
31
0 M u x ALU Add result Add 4 Instruction [31 26] RegDst Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1 Shift left 2 1
PCSrc cannot be set directly from the opcode: zero test outcome is required
PCSrc
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
Write data
1 M u x 0
Instruction [15 0]
16
Sign extend
32 ALU control
Instruction [5 0]
Determining control signals for the MIPS datapath based on instruction opcode
Memto- Reg Mem Mem Instruction RegDst ALUSrc Reg Write Read Write Branch ALUOp1 ALUp0 R-format 1 0 0 1 0 0 0 1 0 lw 0 1 1 1 1 0 0 0 0 sw X 1 X 0 0 1 0 0 0 11/12/2010 beq X 0 X 0 0 0 1 0 1
32
PC
ADDR RD
<<2
0
5
MUX
PCSrc
I 32
16 5
Value depends on
funct
RN1
RN2
Register File
WD immediate/ offset I[15:0]
WN RD1 0 RD2
M U X
ALU
Zero
0
MemtoReg 1 RD 0
M U X
RegWrite
MemWrite ADDR
1
Control signals shown in blue
11/12/2010
16
E X T N D
1
32
ALUSrc
Data Memory
WD MemRead
0
33
0
M U X
PC
ADDR RD
<<2
0
5
MUX
PCSrc
I 32
16 5
RegDst Operation
010
3
RN1
RN2
Register File
WD immediate/ offset I[15:0]
WN RD1 0 RD2
M U X
ALU
Zero
0
MemtoReg 1 RD 0
M U X
RegWrite
MemWrite ADDR
1
Control signals shown in blue
11/12/2010
16
E X T N D
1
32
ALUSrc
Data Memory
WD MemRead
1
34
0
M U X
PC
ADDR RD
<<2
0
5
MUX
PCSrc
I 32
16 5
0
1 RegDst Operation
010
3
RN1
RN2
Register File
WD immediate/ offset I[15:0]
WN RD1 0 RD2
M U X
ALU
Zero
1
MemtoReg 1 RD 0
M U X
RegWrite
MemWrite ADDR
0
Control signals shown in blue
11/12/2010
16
E X T N D
1
32
ALUSrc
Data Memory
WD MemRead
0
35
0
M U X
PC
ADDR RD
<<2
0
5
MUX
PCSrc
I 32
16 5
1 if Zero=1
1 RegDst Operation
110
3
RN1
RN2
Register File
WD immediate/ offset I[15:0]
WN RD1 0 RD2
M U X
ALU
Zero
0
MemtoReg 1 RD 0
M U X
RegWrite
MemWrite ADDR
0
Control signals shown in blue
11/12/2010
16
E X T N D
1
32
ALUSrc
Data Memory
WD MemRead
0
36
RegDst Jump Branch MemRead MemtoReg ALUOp MemWrite ALUSrc RegWrite Read register 1
Shift left 2
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
Instruction [5 0]
11/12/2010
37
MIPS datapath extended to jumps: control unit generates new Jump control bit
Datapath Executing j
28
32
<<2
1
M U X
Control Unit
ALUOp
2
0 Jump
PC
ADDR RD op 6 I[31:26]
32 funct 6 I[5:0] 5
MUX
1 PCSrc
0
5
1 RegDst Operation
3
Branch Zero
RN1
op I[31:
RN2
Register File
WD
WN RD1 0 RD2
M U X
ALU
RegWrite E X T N D 1
32
MemWrite ADDR
MemtoReg 1 RD 0
M U X
16
ALUSrc
Data Memory
WD MemRead
11/12/2010
38
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
Instruction [5 0]
11/12/2010
39
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
Instruction [5 0]
11/12/2010
40
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
Instruction [5 0]
11/12/2010
41
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
Instruction [5 0]
11/12/2010
42
3.
4.
5.
Fetch instruction and increment PC Read base register from the register file: the base register ($t2) is given by bits 25-21 of the instruction ALU computes sum of value read from the register file and the sign-extended lower 16 bits (offset) of the instruction The sum from the ALU is used as the address for the data memory The data from the memory unit is written into the register file: the destination register ($t1) is given by bits 20-16 of the instruction
43
11/12/2010
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
Instruction [5 0]
11/12/2010
44
4.
Fetch instruction and increment PC Read two register ($t1 and $t2) from the register file ALU performs a subtract on the data values from the register file; the value of PC+4 is added to the sign-extended lower 16 bits (offset) of the instruction shifted left by two to give the branch target address The Zero result from the ALU is used to decide which adder result (from step 1 or 3) to store in the PC
45
11/12/2010
Control
Instruction [25 21] PC Read address Instruction [31 0] Instruction memory Instruction [15 11] Instruction [20 16] 0 M u x 1
Read data 1 Read register 2 Registers Read Write data 2 register Write data
0 M u x 1
Address
1 M u x 0
11/12/2010
Instruction [5 0]
46
F3 F2 F (5 0) F1
F0
11/12/2010
47
Rlw format
0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 1 0 0 0 1 1 0 1 1 1 1 0 0 0 0
sw
1 0 1 0 1 1 x 1 x 0 0 1 0 0 0
beq
0 0 0 1 0 0 x 0 x 0 0 0 1 0 1
Op5 Op4 Op3 Op2 Op1 Op0 RegDst ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOP2
11/12/2010
Outputs R-format Iw sw beq RegDst ALUSrc MemtoReg RegWrite MemRead MemWrite Branch ALUOp1 ALUOpO
Outputs
Main control PLA (programmable logic array): principle underlying PLAs is that any logical expression 48 can be written as a sum-of-products
Multicycle Approach
Break up the instructions into steps
each step takes one clock cycle balance the amount of work to be done in each step/cycle so that they are about equal restrict each cycle to use at most once each major functional unit so that such units do not have to be replicated functional units can be shared between different cycles within one instruction
Between steps/cycles
At the end of one cycle store data to be used in later cycles of the same instruction need to introduce additional internal (programmer-invisible) registers for this purpose Data to be used in later instructions are stored in programmervisible state elements: the register file, PC, memory
11/12/2010 49
Multicycle Approach
PCSrc Add 4 Shift left 2 Registers Read register 1 Read Read data 1 register 2 Write register Write data RegWrite 16 Read data 2 3 ALU operation MemWrite MemtoReg Address Read data Add ALU result M u x
PC
ALUSrc
M u x
single memory for data and instructions single ALU, no extra adders extra registers to hold data between clock cycles
PC Address Memory
Data memory
M u x
MemRead
Single-cycle datapath
Instruction register
Data A Register #
ALU
ALUOut
Data
11/12/2010
50
Multicycle Datapath
PC
0 M u x 1
Address
Memory MemData Write data
Instruction [25 21] Instruction [20 16] Instruction [15 0] Instruction register Instruction [15 0] Memory data register 0 M Instruction u x [15 11] 1 0 M u x 1 16
Read register 1 Read Read register 2 data 1 Registers Write Read register data 2 Write data A
0 M u x 1
ALUOut
B 4
0 1 M u 2 x 3
Sign extend
32
Shift left 2
Basic multicycle MIPS datapath handles R-type instructions and load/stores: new internal register in red ovals, new multiplexors in blue ovals
11/12/2010 51
4. 5.
Instruction fetch and PC increment (IF) Instruction decode and register fetch (ID) Execution, memory address computation, or branch completion (EX) Memory access or R-type instruction completion (MEM) Memory read completion (WB)
11/12/2010
54
Step 1: IF 2: ID 3: EX 4:
Step name Instruction fetch Instruction decode/register fetch Execution, address computation, branch/ jump completion
Action for memory-reference Action for instructions branches IR = Memory[PC] PC = PC + 4 A = Reg [IR[25-21]] B = Reg [IR[20-16]] ALUOut = PC + (sign-extend (IR[15-0]) << 2) ALUOut = A + sign-extend (IR[15-0]) Load: MDR = Memory[ALUOut] or Store: Memory [ALUOut] = B Load: Reg[IR[20-16]] = MDR if (A ==B) then PC = ALUOut
ALUOut = A op B
PC = PC [31-28] II (IR[25-0]<<2)
5: WB
11/12/2010
59
I R PC
MemWrite ADDR
Instruction I
5 5 5
Operation
3
RN1
RN2
WN RD1
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
A ALU
Zero
ALU OUT
RD2 RegWrite
11/12/2010
60
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
Zero
ALU
RD2
RegWrite
Reg[rt]
11/12/2010
61
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Mem. Address
ALU OUT
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
Zero
ALU
RD2
RegWrite
Reg[rt]
11/12/2010
62
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
Zero
R-Type Result
ALU OUT
ALU
RD2
RegWrite
Reg[rt]
11/12/2010
63
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Memory
RD WD MemRead
M D R
Registers
WD
Zero
ALU
RD2
RegWrite
Reg[rt]
11/12/2010
64
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Memory
Jump Address
RD WD MemRead
M D R
Registers
WD
Zero
ALU
RD2
RegWrite
Reg[rt]
11/12/2010
65
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Mem. Address
ALU OUT
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
Zero
ALU
RD2
RegWrite
Mem. Data
Reg[rt]
11/12/2010
66
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
Zero
ALU
ALU OUT
RD2 RegWrite
Reg[rt]
11/12/2010
67
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
Zero
R-Type Result
ALU OUT
ALU
RD2
RegWrite
Reg[rt]
11/12/2010
68
I R PC
MemWrite ADDR
Instruction I
5 5 5
Reg[rs]
A
Operation
3
RN1
RN2
WN RD1
Memory
RD
PC + 4
WD MemRead
M D R
Registers
WD
Zero
Mem. Address
ALU OUT
ALU
RD2
RegWrite
Mem. Data
Reg[rt]
11/12/2010
69
PC
0 M u x 1
Instruction [25 21] Instruction [20 16] Instruction [15 0] Instruction register Instruction [15 0] Memory data register 0 M Instruction u x [15 11] 1 0 M u x 1 16
Read register 1 Read Read data 1 register 2 Registers Write Read register data 2 Write data A
0 M u x 1 0 1 M u 2 x 3
B 4
ALUOut
Sign extend
32
Shift left 2
ALU control
Instruction [5 0]
11/12/2010
MemtoReg
ALUSrcB ALUOp
70
with control lines and the ALU control block added not all control lines are shown
New multiplexor
PCWrite Outputs ALUOp IorD ALUSrcB MemRead ALUSrcA Control MemWrite RegWrite MemtoReg Op RegDst IRWrite [5 0] Jump address [31-0]
Instruction [25 0] Instruction [31-26] Address Memory MemData Write data Instruction [25 21] Instruction [20 16] Instruction [15 0] 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 Read register 1 Read Read register 2 data 1 Registers Write Read register data 2 Write data A 0 M u x 1 0 1 M u 2 x 3
26
Shift left 2
28
1 u
x 2
PC
0 M u x 1
PC [31-28]
B 4
ALUOut
ALU control
Instruction [5 0]
11/12/2010
Complete multicycle MIPS datapath (with branch and jump capability) and showing the main control block and all control lines
71
1
PCWr* IorD
I R
Instruction I rs rt
5 5 5
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2 1U 0
M X
0
MemWrite ADDR
32
MUX
RegDst
PC
0M
U 1X
X
A B
4
0 ALUSrcA
0M 1X
U
010 Operation
3
RN1
RN2
WN RD1
Memory
WD MemRead
RD
M D R
1M 0X MemtoReg
U
Registers
WD
Zero
PCSource
ALU
0 1M U 2X 3 ALUSrcB
ALU OUT
RD2
X 1
immediate
RegWrite
0
16
E X T N D
32
<<2
1
72
11/12/2010
0IRWrite
I R
0
PCWr*
Instruction I rs rt
5 5 5
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2
M X
X
IorD 0M
U 1X
0
MemWrite ADDR
32
MUX
RegDst
PC Memory
WD MemRead MemtoReg
0
0M
U
ALUSrcA Operation
3
010
1U 0
RN1
RN2
WN RD1
RD
M D R
1M 0X
U
Registers
WD
A B
4
1X
Zero
PCSource
ALU
0 1M U 2X 3 ALUSrcB
ALU OUT
RD2
0
immediate
RegWrite
16
11/12/2010
E X T N D
32
<<2
73
0 PCWr*
IorD
I R
Instruction I rs rt
5 5 5
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2
M X
0
MemWrite ADDR
32
MUX
RegDst
PC
0M
U 1X
X
A B
4
1 ALUSrcA
0M 1X
U
Operation
3
010
ALU
1U 0
RN1
RN2
WN RD1
Memory
WD MemRead
RD
M D R
1M 0X MemtoReg
U
Registers
WD
Zero
ALU OUT
PCSource
RD2
X 0
immediate
RegWrite
16
0 1M U 2X 3 ALUSrcB
E X T N D
32
<<2
2
74
11/12/2010
PCWr*
I R
Instruction I rs rt
5 5 5
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2
M X
X
IorD 0M
U 1X
0
MemWrite ADDR
32
MUX
RegDst
PC Memory
WD MemRead MemtoReg
X
A B
4
1
0M 1X
U
ALUSrcA Operation
3
???
ALU
1U 0
RN1
RN2
WN RD1
RD
M D R
1M 0X
U
Registers
WD
Zero
ALU OUT
PCSource
RD2
X 0
immediate
RegWrite
0 1M U 2X 3 ALUSrcB
16
E X T N D
32
<<2
0
75
11/12/2010
1 if Zero=1 PCWr* X
IorD
I R
Instruction I rs rt
5 5 5
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2
M X
0
MemWrite ADDR
32
MUX
RegDst
PC
0M
U 1X
X
A B
4
1
0M 1X
U
ALUSrcA Operation
3
011
ALU
1U 0
RN1
RN2
WN RD1
Memory
WD MemRead
RD
M D R
1M 0X MemtoReg
U
Registers
WD
Zero
ALU OUT
PCSource
RD2
X 0
immediate
RegWrite
0 1M U 2X 3 ALUSrcB
16
E X T N D
32
<<2
0
76
11/12/2010
1 PCWr*
PC
I R
IorD 0M
U 1X
Instruction I rs rt
5 5 5
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2
M X
0
MemWrite ADDR
32
MUX
RegDst
X
A B
4
ALUSrcA Operation 0M 1X
U
XXX
3
1U 0
RN1
RN2
WN RD1
Memory
WD MemRead
RD
M D R
1M 0X MemtoReg
U
Registers
WD
Zero
PCSource
ALU OUT
ALU
0 1M U 2X 3 ALUSrcB
RD2
X 0
immediate
RegWrite
16
E X T N D
32
<<2
X
77
11/12/2010
PCWr*
I R
Instruction I rs rt
5 5 5
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2
M X
1
IorD 0M
U 1X
0
MemWrite ADDR
32
MUX
RegDst
PC Memory
WD MemRead MemtoReg
X
A B
4
X
0M 1X
U
ALUSrcA Operation
3
XXX
ALU
1U 0
RN1
RN2
WN RD1
RD
M D R
1M 0X
U
Registers
WD
Zero
ALU OUT
PCSource
RD2
X 1
immediate
RegWrite
0 1M U 2X 3 ALUSrcB
0
16
E X T N D
32
<<2
X
78
11/12/2010
0
Instruction I rs rt
5 5 5
0 PCWr*
PC
I R
IorD 0M
U 1X
jmpaddr rd 1
I[25:0]
28
32
<<2
CONCAT 2
M X
1
MemWrite ADDR
32
MUX
RegDst
X
A B
4
ALUSrcA Operation 0M 1X
U
XXX
3
1U 0
RN1
RN2
WN RD1
Memory
WD MemRead
RD
M D R
1M 0X MemtoReg
U
Registers
WD
Zero
PCSource
ALU OUT
ALU
0 1M U 2X 3 ALUSrcB
RD2
X 0
immediate
RegWrite
16
E X T N D
32
<<2
X
79
11/12/2010
(Reg[Rd] = ALUOut)
0 PCWr*
IorD
I R
Instruction I rs rt
5 5 5
jmpaddr
I[25:0]
28
32
<<2
CONCAT 2
M X
rd 1 RegDst
0
MemWrite ADDR
32
MUX
PC
0M
U 1X
1
A B
4
X ALUSrcA
0M 1X
U
Operation
3
XXX
Zero
1U 0
RN1
RN2
WN RD1
Memory
WD MemRead
RD
M D R
0M 1X MemtoReg
U
Registers
WD
PCSource
ALU OUT
ALU
0 1M U 2X 3 ALUSrcB
RD2
1 0
immediate
RegWrite
16
E X T N D
32
<<2
X
80
11/12/2010
0
28 32
PCWr*
I R
Instruction I rs rt
5 5 5
jmpaddr
I[25:0]
<<2
CONCAT 2
M X
X
IorD 0M
U 1X
rd 1 RegDst
0
MemWrite ADDR
32
MUX
PC Memory
WD MemRead MemtoReg
0
A B
4
X
0M
U
ALUSrcA Operation
3
XXX
Zero
1U 0
RN1
RN2
WN RD1 1X
RD
M D R
0M 1X
U
Registers
WD
PCSource
ALU
0 1M U 2X 3 ALUSrcB
X
ALU OUT
RD2
0
immediate
RegWrite
16
E X T N D
32
<<2
X
81
11/12/2010
Simple Questions
How many cycles will it take to execute this code? lw $t2, 0($t3) lw $t3, 4($t3) beq $t2, $t3, Label #assume not equal add $t5, $t2, $t3 sw $t5, 8($t3) ...
Label:
Clock time-line
In what cycle does the actual addition of $t2 and $t3 takes place?
11/12/2010
82
Implementing Control
Value of control signals is dependent upon:
what instruction is being executed which step is being performed
Next-state function
Output function
Outputs
What is the the output of the string 100010 Build a FSM to recognize odd/even numbers
85
Start
(Op
W = 'L
(O
W')
(O
11/12/2010
(Op = 'JMP')
'B
EQ ')
86
(O
(Op = 'LW')
p = 'S ') W
Memory access 5
Memory access
3 MemRead IorD = 1
MemWrite IorD = 1
87
11/12/2010
88
11/12/2010
90
IF
Start
EQ (O p = 'B
')
ID
'SW
(Op = 'J')
Jump completion
EX
(O
(Op = 'LW')
p = 'S ') W
Memory access 5
R-type completion
MEM
MemRead IorD = 1
WB
11/12/2010
The complete FSM control for the multicycle MIPS datapath: 91 refer Multicycle Datapath with Control II
What is the CPI assuming each step requires 1 clock cycle? Solution:
Number of clock cycles from previous slide for each instruction class:
loads 5, stores 4, R-type instructions 4, branches 3, jumps 3
CPI = CPU clock cycles / instruction count = (instruction countclass i CPIclass i) / instruction count = (instruction countclass I / instruction count) CPIclass I = 0.22 5 + 0.11 4 + 0.49 4 + 0.16 3 + 0.02 3 = 4.04
11/12/2010 92
PCWrite PCWriteCond IorD MemRead MemWrite IRWrite Control logic MemtoReg PCSource ALUOp Outputs ALUSrcB ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0
Inputs
Op5
Op4
Op3
Op2
Op1
Op0
S3
S2
S1
State register
High-level view of FSM implementation: inputs to the combinational logic block are the11/12/2010 state number and instruction opcode bits; outputs are the next state93 current number and control signals to be asserted for the current state
S0
Op5 Op4
Op3 Op2 Op1 Op0 S3 S2 S1 S0 PCWrite PCWriteCond IorD MemRead MemWrite IRWrite MemtoReg PCSource1 PCSource0 ALUOp1 ALUOp0 ALUSrcB1 ALUSrcB0 ALUSrcA RegWrite RegDst NS3 NS2 NS1 NS0
Upper half is the AND plane that computes all the products. The products are carried to the lower OR plane by the vertical lines. The sum terms for each output is given by the11/12/2010 corresponding horizontal line 94 E.g., IorD = S0.S1.S2.S3 + S0.S1.S2.S3
ROM
The size of an m-input n-output ROM is 2m x n bits such a ROM can be thought of as an array of size 2m with each entry in the array being 11/12/2010 n bits
95
PLA cells usually about the size of a ROM cell (slightly bigger)
96
Microprogramming
Microprogramming is a method of specifying FSM control that resembles a programming language textual rather graphic
this is appropriate when the FSM becomes very large, e.g., if the instruction set is large and/or the number of cycles per instruction is large in such situations graphical representation becomes difficult as there may be thousands of states and even more arcs joining them a microprogram is specification : implementation is by ROM or PLA
11/12/2010
97
Microprogramming
The Sequencing field value determines the execution order of the microprogram
value Seq : control passes to the sequentially next microinstruction value Fetch : branch to the first microinstruction to begin the next MIPS instruction, i.e., the first microinstruction in the microprogram value Dispatch i : branch to a microinstruction based on control input and a dispatch table entry (called dispatching): Dispatching is implemented by means of creating a table, called dispatch table, whose entries are microinstruction labels and which is indexed by the control input. There may be multiple dispatch tables the value Dispatch i in the sequencing field indicates that the i th dispatch table is to be used
11/12/2010 98
Control Microprogram
The microprogram corresponding to the FSM control shown graphically earlier:
Labe l Fe tch M em 1 LW 2 SW 2 R form at1 BEQ1 JU M P 1 A LU control Add Add Add SRC1 SRC2 PC 4 PC E xtshft R ead A E xtend R e gister control M em ory R e ad P C P C W rite control A LU S equenc ing S eq D isp atch 1 D isp atch 2 S eq Fetch Fetch S eq Fetch Fetch Fetch
Op 100011 101011
Dispatch Table 2
99
Dispatch Table 1
Microcode: Trade-offs
Specification advantages
easy to design and write typically manufacturer designs architecture and microcode in parallel
Implementation advantages
easy to change since values are in memory (e.g., off-chip ROM) can emulate other architectures can make use of internal registers
Implementation disadvantages
control is implemented nowadays on same chip as processor so the advantage of an off-chip ROM does not exist ROM is no longer faster than on-board cache there is little need to change the microcode as general-purpose computers are used far more nowadays than computers designed for specific applications
11/12/2010 100
Summary
Techniques described in this chapter to design datapaths and control are at the core of all modern computer architecture Multicycle datapaths offer two great advantages over single-cycle
functional units can be reused within a single instruction if they are accessed in different cycles reducing the need to replicate expensive logic instructions with shorter execution paths can complete quicker by consuming fewer cycles
Modern computers, in fact, take the multicycle paradigm to a higher level to achieve greater instruction throughput:
pipelining (next topic) where multiple instructions execute simultaneously by having cycles of different instructions overlap in the datapath the MIPS architecture was designed to be pipelined
11/12/2010
101