CS61C : Machine Structures – Lecture 27 Single Cycle CPU Control I

advertisement
inst.eecs.berkeley.edu/~cs61c
CS61C : Machine Structures
Lecture 27 –
Single Cycle CPU Control I
Lecturer PSOE Dan Garcia
www.cs.berkeley.edu/~ddgarcia
Brain-computer interfaces! 
Paralyzed people can now control
artificial limbs! There are two brain connection
techniques, implants requiring significant
surgery (& brain inflammation) and the noninvasive “swimming cap”. You adapt to either.
www.guardian.co.uk/life/feature/story/0,13026,1448140,00.html
CS61C L27 Single Cycle CPU Control I (1)
Garcia, Fall 2004 © UCB
Summary: A Single Cycle Datapath
• Rs, Rt, Rd, Imed16 connected to datapath
• We have everything except control signals
Instruction<31:0>
MemWr
Clk
MemtoReg
0
32
Data In32
ALUSrc
Rs Rd Imm16
WrEn Adr
Data
Memory
32
Mux
32
1
<0:15>
Extender
16
ALU
busA
Rw Ra Rb
32
32 32-bit
Registers busB
0
32
imm16
Rt
Zero
ALUctr
Mux
busW
32
Clk
Clk
<11:15>
Rt
RegDst
1 Mux0
Rs Rt
RegWr 5 5 5
<16:20>
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel
1
ExtOp
CS61C L27 Single Cycle CPU Control I (2)
Garcia, Fall 2004 © UCB
An Abstract View of the Critical Path
Critical Path (Load Operation) =
• This affects
Delay clock through PC (FFs) +
how much you Instruction Memory’s Access Time +
can overclock
Register File’s Access Time, +
your PC!
ALU to Perform a 32-bit Add +
Data Memory Access Time +
Ideal
Stable Time for Register File Write
Instruction
Instruction
Memory
Rd Rs Rt
5 5
5
PC
Clk
A
32
Rw Ra Rb
32 32-bit 32
Registers B
Clk
CS61C L27 Single Cycle CPU Control I (3)
ALU
Next Address
Instruction
Address
Imm
16
32
Data
32 Address
Data
In
Ideal
Data
Memory
Clk
Garcia, Fall 2004 © UCB
Recap: Meaning of the Control Signals
0  PC <– PC + 4
1  PC <– PC + 4 +
“n”=next
{SignExt(Im16) , 00 }
• Later in lecture: higher-level connection
between mux and branch cond
• nPC_MUX_sel:
nPC_MUX_sel
Inst
Adr Memory
Adder
imm16
PC
Mux
Adder
PC Ext
CS61C L27 Single Cycle CPU Control I (4)
00
4
Clk
Garcia, Fall 2004 © UCB
Recap: Meaning of the Control Signals
° MemWr: 1  write memory
• ExtOp: “zero”, “sign”
° MemtoReg: 0  ALU; 1  Mem
• ALUsrc: 0  regB;
1  immed
° RegDst: 0  “rt”; 1  “rd”
• ALUctr: “add”, “sub”, “or” ° RegWr: 1  write register
RegDst
ALUctr MemWr MemtoReg
=
32
WrEn Adr
Data In
Data
Clk Memory
ExtOp ALUSrc
CS61C L27 Single Cycle CPU Control I (5)
32
0
Mux
ALU
Mux
Extender
Equal
Rd Rt
1 0
Rs Rt
RegWr 5 5 5
busA
Rw
Ra
Rb
busW
32
32 32-bit
32
Registers busB
0
32
Clk
1
imm16
32
16
1
Garcia, Fall 2004 © UCB
Administrivia
• Steven & Andy moved today’s OH to
11-noon before lecture
CS61C L27 Single Cycle CPU Control I (6)
Garcia, Fall 2004 © UCB
RTL: The Add Instruction
31
26
op
6 bits
21
rs
5 bits
16
rt
5 bits
11
6
0
rd
shamt
funct
5 bits
5 bits
6 bits
add rd, rs, rt
• MEM[PC]
Fetch the instruction
from memory
• R[rd] = R[rs] + R[rt] The actual operation
• PC = PC + 4
Calculate the next
instruction’s address
CS61C L27 Single Cycle CPU Control I (7)
Garcia, Fall 2004 © UCB
Instruction Fetch Unit at the Beginning of Add
• Fetch the instruction from Instruction
memory: Instruction = MEM[PC]
• same for
all instructions
Inst
Memory
Adr
Instruction<31:0>
nPC_MUX_sel
Adder
imm16
PC
Mux
Adder
PC Ext
CS61C L27 Single Cycle CPU Control I (8)
00
4
Clk
Garcia, Fall 2004 © UCB
The Single Cycle Datapath during Add
31
26
21
op
rs
16
11
rt
6
rd
shamt
• R[rd] = R[rs] + R[rt]
5
Zero
ALU
16
Extender
imm16
1
32
Rd
Clk
Imm16
MemtoReg = 0
MemWr = 0
0
32
Data In 32
ALUSrc = 0
Rs
WrEn Adr
32
Mux
busA
Rw Ra Rb
32
32 32-bit
Registers
busB
0
32
Rt
<0:15>
5
ALUctr = Add
Rt
<11:15>
5
Rs
Mux
32
Clk
Clk
1 Mux 0
RegWr = 1
busW
Rt
Instruction
Fetch Unit
<16:20>
RegDst = 1
Rd
funct
Instruction<31:0>
<21:25>
nPC_sel= +4
0
1
Data
Memory
ExtOp = x
CS61C L27 Single Cycle CPU Control I (9)
Garcia, Fall 2004 © UCB
Instruction Fetch Unit at the End of Add
• PC = PC + 4
• This is the same for all instructions except:
Branch and Jump
Inst
Memory
Adr
Instruction<31:0>
nPC_MUX_sel
CS61C L27 Single Cycle CPU Control I (10)
PC
Mux
Adder
imm16
Adder
0
00
4
1
Clk
Garcia, Fall 2004 © UCB
Single Cycle Datapath during Or Immediate?
31
26
op
21
rs
16
0
rt
immediate
• R[rt] = R[rs] OR ZeroExt[Imm16]
Instruction<31:0>
Zero MemWr =
32
ALUSrc =
0
32
Data In32
Clk
Imm16
MemtoReg =
WrEn Adr
32
Mux
ALU
Extender
16
1
Rs Rd
<0:15>
busA
Rw Ra Rb
32
32 32-bit
Registers busB
0
32
imm16
Rt
ALUctr =
<11:15>
5
Rs Rt
5
5
Mux
32
Clk
Clk
1 Mux 0
RegWr =
busW
Rt
<16:20>
RegDst =
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel =
1
Data
Memory
ExtOp =
CS61C L27 Single Cycle CPU Control I (11)
Garcia, Fall 2004 © UCB
Single Cycle Datapath during Or Immediate?
31
26
op
21
16
rs
0
rt
immediate
• R[rt] = R[rs] OR ZeroExt[Imm16]
1
32
Imm16
MemtoReg = 0
MemWr = 0
0
32
Data In32
ALUSrc = 1
Rs Rd
Clk
WrEn Adr
32
Mux
ALU
Extender
16
Zero
<0:15>
busA
Rw Ra Rb
32
32 32-bit
Registers busB
0
32
imm16
Rt
ALUctr = Or
<11:15>
Rs Rt
5
5
Mux
32
Clk
Clk
1 Mux 0
RegWr = 15
busW
Rt
<16:20>
RegDst = 0
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel= +4
Instruction<31:0>
1
Data
Memory
ExtOp = 0
CS61C L27 Single Cycle CPU Control I (12)
Garcia, Fall 2004 © UCB
The Single Cycle Datapath during Load?
31
26
21
op
rs
16
0
rt
immediate
• R[rt] = Data Memory {R[rs] + SignExt[imm16]}
Instruction<31:0>
5
busA
Rw Ra Rb
32
32 32-bit
Registers
busB
0
32
Rt
Zero
32
Imm16
MemtoReg =
MemWr =
0
32
Data In 32
ALUSrc =
Rd
Clk
Mux
ALU
16
Extender
imm16
1
Rs
<0:15>
5
ALUctr
=
Rt
<11:15>
5
Rs
Mux
32
Clk
Clk
1 Mux 0
RegWr =
busW
Rt
<21:25>
RegDst =
Rd
Instruction
Fetch Unit
<16:20>
nPC_sel=
1
WrEn Adr
Data
Memory
32
ExtOp =
CS61C L27 Single Cycle CPU Control I (13)
Garcia, Fall 2004 © UCB
The Single Cycle Datapath during Load
31
26
21
op
rs
16
0
rt
immediate
• R[rt] = Data Memory {R[rs] + SignExt[imm16]}
busA
Rw Ra Rb
32
32 32-bit
Registers
busB
0
32
Rt
Zero
32
Imm16
MemtoReg = 1
MemWr = 0
0
32
Data In 32
ALUSrc = 1
Rd
Clk
Mux
ALU
16
Extender
imm16
1
Rs
<0:15>
5
ALUctr
= Add
Rt
<11:15>
5
Rs
Mux
32
Clk
Clk
1 Mux 0
RegWr = 1 5
busW
Rt
<16:20>
RegDst = 0
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel= +4
Instruction<31:0>
1
WrEn Adr
Data
Memory
32
ExtOp = 1
CS61C L27 Single Cycle CPU Control I (14)
Garcia, Fall 2004 © UCB
The Single Cycle Datapath during Store?
31
26
op
21
rs
16
0
rt
immediate
• Data Memory {R[rs] + SignExt[imm16]} = R[rt]
1 Mux 0
RegWr = 5
Rs Rt
5
5
Rt
ALUctr =
busA
16
Extender
imm16
1
32
ALUSrc =
Clk
MemtoReg =
0
32
Data In32
Imm16
WrEn Adr
32
Mux
Rw Ra Rb
32
32 32-bit
Registers busB
0
32
Mux
32
Clk
Zero MemWr =
ALU
busW
Rs Rd
<0:15>
Clk
<11:15>
Rt
<16:20>
RegDst =
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel =
Instruction<31:0>
1
Data
Memory
ExtOp =
CS61C L27 Single Cycle CPU Control I (15)
Garcia, Fall 2004 © UCB
The Single Cycle Datapath during Store
31
26
op
21
rs
16
0
rt
immediate
• Data Memory {R[rs] + SignExt[imm16]} = R[rt]
32
0
32
Data In 32
ALUSrc = 1
Rs Rd
Clk
WrEn Adr
Data
Memory
32
Mux
1
<0:15>
16
Extender
imm16
Imm16
MemtoReg = x
Zero MemWr = 1
ALU
busA
Rw Ra Rb
32
32 32-bit
Registers busB
0
32
Rt
<11:15>
ALUctr
= Add
Rs Rt
5
5
Mux
32
Clk
Clk
1 Mux 0
RegWr = 0 5
busW
Rt
<16:20>
RegDst = x
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel= +4
Instruction<31:0>
1
ExtOp = 1
CS61C L27 Single Cycle CPU Control I (16)
Garcia, Fall 2004 © UCB
The Single Cycle Datapath during Branch?
31
26
op
21
16
rs
0
rt
immediate
• if (R[rs] - R[rt] == 0) then Zero = 1 ; else Zero = 0
Instruction<31:0>
Data In32
ALUSrc =
0
32
Clk
WrEn Adr
32
Mux
32
Imm16
MemtoReg = x
Zero MemWr =
ALU
16
Extender
imm16
1
Rs Rd
<0:15>
busA
Rw Ra Rb
32
32 32-bit
Registers busB
0
32
<11:15>
5
Rt
ALUctr =
Rs Rt
5
5
Mux
32
Clk
Clk
1 Mux 0
RegWr =
busW
Rt
<16:20>
RegDst =
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel=
1
Data
Memory
ExtOp =
CS61C L27 Single Cycle CPU Control I (17)
Garcia, Fall 2004 © UCB
The Single Cycle Datapath during Branch
31
26
op
21
16
rs
0
rt
immediate
• if (R[rs] - R[rt] == 0) then Zero = 1 ; else Zero = 0
Instruction<31:0>
32
0
32
Data In32
ALUSrc = 0
Rs Rd
Clk
WrEn Adr
32
Mux
1
<0:15>
16
Extender
imm16
Imm16
MemtoReg = x
Zero MemWr = 0
ALU
busA
Rw Ra Rb
32
32 32-bit
Registers busB
0
32
<11:15>
5
Rt
ALUctr =Sub
Rs Rt
5
5
Mux
32
Clk
Clk
1 Mux 0
RegWr = 0
busW
Rt
<16:20>
RegDst = x
Rd
Instruction
Fetch Unit
<21:25>
nPC_sel= “Br”
1
Data
Memory
ExtOp = x
CS61C L27 Single Cycle CPU Control I (18)
Garcia, Fall 2004 © UCB
Instruction Fetch Unit at the End of Branch
31
26
21
op
rs
16
rt
0
immediate
• if (Zero == 1) then PC = PC + 4 + SignExt[imm16]*4 ;
else PC = PC + 4
Inst
Memory
nPC_sel
Adr
Zero
Instruction<31:0>
• What is encoding of
nPC_sel?
• Direct MUX select?
nPC_MUX_sel
• Branch / not branch
PC
Adder
imm16
Mux
Adder
0
00
4
1
Clk
CS61C L27 Single Cycle CPU Control I (19)
• Let’s pick 2nd option
nPC_sel
0
1
1
zero?
x
0
1
MUX
0
0
1
Q: What
logic gate?
Garcia, Fall 2004 © UCB
Step 4: Given Datapath: RTL -> Control
Instruction<31:0>
Rd
<0:15>
Rs
<11:15>
Rt
<16:20>
Op Fun
<21:25>
<0:5>
Adr
<26:31>
Inst
Memory
Imm16
Control
nPC_sel RegWr RegDst ExtOp ALUSrc ALUctr MemWr MemtoReg
Zero
DATA PATH
CS61C L27 Single Cycle CPU Control I (20)
Garcia, Fall 2004 © UCB
A Summary of the Control Signals (1/2)
inst
Register Transfer
ADD
R[rd] <– R[rs] + R[rt];
PC <– PC + 4
ALUsrc = RegB, ALUctr = “add”, RegDst = rd, RegWr, nPC_sel = “+4”
SUB
R[rd] <– R[rs] – R[rt];
PC <– PC + 4
ALUsrc = RegB, ALUctr = “sub”, RegDst = rd, RegWr, nPC_sel = “+4”
ORi
R[rt] <– R[rs] + zero_ext(Imm16);
PC <– PC + 4
ALUsrc = Im, Extop = “Z”, ALUctr = “or”, RegDst = rt, RegWr, nPC_sel =“+4”
LOAD
R[rt] <– MEM[ R[rs] + sign_ext(Imm16)]; PC <– PC + 4
ALUsrc = Im, Extop = “Sn”, ALUctr = “add”,
MemtoReg, RegDst = rt, RegWr,
nPC_sel = “+4”
STORE MEM[ R[rs] + sign_ext(Imm16)] <– R[rs]; PC <– PC + 4
ALUsrc = Im, Extop = “Sn”, ALUctr = “add”, MemWr, nPC_sel = “+4”
BEQ
if ( R[rs] == R[rt] ) then PC <– PC + sign_ext(Imm16)] || 00 else PC <– PC + 4
nPC_sel = “Br”, ALUctr = “sub”
CS61C L27 Single Cycle CPU Control I (21)
Garcia, Fall 2004 © UCB
A Summary of the Control Signals (2/2)
See
Appendix A
func 10 0000 10 0010
We Don’t Care :-)
op 00 0000 00 0000 00 1101 10 0011 10 1011 00 0100 00 0010
add
sub
ori
lw
sw
beq
jump
RegDst
1
1
0
0
x
x
x
ALUSrc
0
0
1
1
1
0
x
MemtoReg
0
0
0
1
x
x
x
RegWrite
1
1
1
1
0
0
0
MemWrite
0
0
0
0
1
0
0
nPCsel
0
0
0
0
0
1
0
Jump
0
0
0
0
0
0
1
ExtOp
x
x
0
1
1
x
x
Add
Subtract
Or
Add
Add
Subtract
xxx
ALUctr<2:0>
31
26
21
16
R-type
op
rs
rt
I-type
op
rs
rt
J-type
op
CS61C L27 Single Cycle CPU Control I (22)
11
rd
6
shamt
immediate
target address
0
funct
add, sub
ori, lw, sw, beq
jump
Garcia, Fall 2004 © UCB
Peer Instruction
A. Our ALU is a synchronous device
B. We could have used tri-state
devices instead of a MUX to feed
busW, the register write data line
C. The ALU is inactive for memory
reads or writes.
CS61C L27 Single Cycle CPU Control I (23)
1:
2:
3:
4:
5:
6:
7:
8:
ABC
FFF
FFT
FTF
FTT
TFF
TFT
TTF
TTT
Garcia, Fall 2004 © UCB
Summary: Single cycle datapath
°5 steps to design a processor
• 1. Analyze instruction set => datapath requirements
• 2. Select set of datapath components & establish clock
methodology
• 3. Assemble datapath meeting the requirements
• 4. Analyze implementation of each instruction to
determine setting of control points that effects the
register transfer.
Processor
Input
• 5. Assemble the control logic
Control
°Control is the hard part
°MIPS makes that easier
Memory
Datapath
• Instructions same size
• Source registers always in same place
• Immediates same size, location
• Operations always on registers/immediates
CS61C L27 Single Cycle CPU Control I (24)
Output
Garcia, Fall 2004 © UCB
Download