Upload
bharavi-k-s
View
214
Download
0
Embed Size (px)
Citation preview
8/3/2019 7202_n_20121
1/21
Multi-Cycle MIPS
Implementation
Ellen Spertus
MCS 111November 4, 2003
8/3/2019 7202_n_20121
2/21
2
ComparisonSingle-cycle Each instruction
takes one clockcycle.
There is one set ofcontrol signalsforeach instruction.
The clock period isthe length of theslowest instruction.
Multi-cycle Each instruction
takes multiple clockcycles.
There is one set ofcontrol signals foreach cycle of eachinstruction.
The clock period isthe length of theslowest stage.
8/3/2019 7202_n_20121
3/21
3
Single-cycle datapath
8/3/2019 7202_n_20121
4/21
4
Sample program
Assembly code:top: add $r1, $r2, $r3
sw $r5, 0x3000($r2)beq $r2, $r5, endj top
end:
Machine code:4000: add $r1, $r2, $r3
4004: sw $r5, 0x3000($r2)4008: beq $r2, $r5,_____400C: j____
op (6 bits) target address (26 bits)
000010 00 0000 0000 0000 0001 0000 0000
8/3/2019 7202_n_20121
5/21
5
add$r1, $r2, $r3
1
2
3
Instruction Fetch Register Read ALU Register write
# Inst. Reg = Mem[PC]IorD = 0MemRead = 1IRWrite = 1# PC = PC + 4
ALUSrcA = 0ALUSrcB = 01ALUOp = add
PCSource = 00PCWrite = 1
#A = Reg[IR[25-21]]# B = Reg[IR[20-16]]
#ALUOut = A op BALUOp = functALUSrcA = 1ALUSrcB = 00
# Reg[IR[15-11] = ALUOutRegDst = 1RegWrite = 1MemToReg = 0
Multi-cycle datapath
8/3/2019 7202_n_20121
6/21
6
How to produce control bits?
Single-cycle
Input: opcode bits
Output: control bits
Multi-cycle
Input: opcode bits, cycle
Output: control bits
op2 op1 op0 RegDst
r-type 0 0 0 1lw 0 1 1 0sw 0 1 1 xbeq 1 0 0 x
(I dropped op5, op4, and op3 because theyre not needed for
the MIPS subset were examining.)
8/3/2019 7202_n_20121
7/21
7
Multi-cycle truth table (1)
op2 op1 op0 cyc1 cyc0 RegDst MemRead MemWrite
r-type 0 0 0 0 0
r-type 0 0 0 0 1
r-type 0 0 0 1 0
r-type 0 0 0 1 1
Instruction Fetch Register Read ALU Register write
# Inst. Reg = Mem[PC]IorD = 0
MemRead = 1IRWrite = 1# PC = PC + 4
ALUSrcA = 0
ALUSrcB = 01ALUOp = add
PCSource = 00PCWrite = 1
#A = Reg[IR[25-21]]# B = Reg[IR[20-16]]
#ALUOut = A op BALUOp = funct
ALUSrcA = 1ALUSrcB = 00
# Reg[IR[15-11] = ALUOutRegDst = 1
RegWrite = 1MemToReg = 0
8/3/2019 7202_n_20121
8/21
8
sw $r5, 0x3000($r2)
5
2
3000
Instruction Fetch 00 Register Read 01 ALU 10 Memory write 11
# Inst. Reg = Mem[PC]IorD = 0MemRead = 1IRWrite = 1# PC = PC + 4
ALUSrcA = 0ALUSrcB = 1ALUOp = add
PCSource = 0PCWrite = 1
#A = Reg[IR[25-21]]# B = Reg[IR[20-16]]
(Assume that $r2=2 and$r5=5.)
#ALUOut = A plus immedALUSrcA =ALUSrcB =ALUOp =
# Mem[ALUOut] = BIorD =MemWrite =
8/3/2019 7202_n_20121
9/21
9
Multi-cycle truth table (2)
op2 op1 op0 cyc1 cyc0 RegDst MemRead MemWriter-type 0 0 0 0 0r-type 0 0 0 0 1r-type 0 0 0 1 0r-type 0 0 0 1 1
sw 0 1 1 0 0sw 0 1 1 0 1sw 0 1 1 1 0sw 0 1 1 1 1
8/3/2019 7202_n_20121
10/21
10
Big picture
Can we add a counter that keeps trackof what cycle were on?
Can we come up with a booleanfunction to convert from (opcode, cycle)to control bits?
Consequence:
8/3/2019 7202_n_20121
11/21
11
Datapath with cycle counter
8/3/2019 7202_n_20121
12/21
12
beq$r2, $r5, -3
5
2
3000
Instruction Fetch 00 Register Read 01 ALU 10
# Inst. Reg = Mem[PC]IorD = 0MemRead = 1IRWrite = 1# PC = PC + 4
ALUSrcA = 0ALUSrcB = 1ALUOp = addPCSource = 0PCWrite = 1
#A = Reg[IR[25-21]]# B = Reg[IR[20-16]]
# Compute branch targetALUOp =ALUSrcA =ALUSrcB =
#ALUOut = A-BALUOp =ALUSrcA =ALUSrcB =
# If equal, PC gets new valuePCSource =PCWrite =PCWriteCond =
8/3/2019 7202_n_20121
13/21
13
j 0x4000
1000
Instruction Fetch 00 Write PC 01
(Same as for others) PCSource =PCWrite =
op (6 bits) target address (26 bits)
000010 00 0000 0000 0000 0001 0000 0000
8/3/2019 7202_n_20121
14/21
14
Details I ignored
We actually need 5 cycles (and __ bitsto represent them) for load-word.
I didnt always show the value ofdeasserted signals (such as RegWrite).
To simplify logic, the second cyclealways computes the branch target
address, even if it is not needed (e.g.,for r-type instructions).
8/3/2019 7202_n_20121
15/21
15
Actual implementation
While a giant truth table like I describedwould work, thats not how its done inpractice.
The book describes using a finite stateautomaton (although thats not veryefficient either).
The actual implementation is withmicrocode.
8/3/2019 7202_n_20121
16/21
16
8/3/2019 7202_n_20121
17/21
17
FSA big picture
current state
data input
new state
actions
8/3/2019 7202_n_20121
18/21
18
Alternative: microcode
Each microinstruction consists of a setof control signals
Every machine instruction (e.g., )leads to the execution of severalmicroinstructions
8/3/2019 7202_n_20121
19/21
19
Microcode controller (fig. 5.47)
Microprogram counter
Address select logic
Adder
1
Input
Datapathcontrol
outputs
Microcodestorage
Inputs from instruction
register opcode field
Outputs
Sequencing
control
8/3/2019 7202_n_20121
20/21
20
Levels of instructions
MIPS assembly language instructions Written by assembly language programmer
Example:
MIPS machine language instructions Created by assembler
Example:
MIPS microinstruction Created by architect
Example:
8/3/2019 7202_n_20121
21/21
21