Chapter 5 - The Processor: Datapath and Control
Chapter 5 - The Processor: Datapath and Control
Architecture
Chapter 5 – The
Processor: Datapath
and Control
Goals in processor
implementation
Balance the rate of supply of instructions
and data and the rate at which the
execution core can consume them and can
update memory
logic
logic
Brief review of sequential logic
design
State elements are clocked devices
Flip flops, etc
Combinatorial elements hold no state
ALU, caches, multiplier, multiplexers, etc.
In edge triggered clocking, state elements
are only updated on the (rising) edge of
the clock pulse
Brief review of sequential logic
design
The same state element can be read at the
beginning of a clock cycle and updated at
the end
Example:
12 incrementing
clock the PC
8
Add input 8
PC
PC register 8 12
clock
Our processor design progression
(1) Instruction fetch, execute, and operand
reads from data memory all take place in a
single clock cycle
PC +4
Execution datapath
Focus on only a subset of all MIPS
instructions
add, sub, and, or
lw, sw
slt
beq, j
op rs rt rd shamt funct
Execution datapath
Datapath for beq instruction
31 26 25 21 20 16 15 0
Zero ALU output
op rs indicates
rt if rs=rt (branch is taken/not taken)
immediate
Branch target address is the sign extended immediate left
shifted two positions, and added to PC+4
Data memory
Used for lw, sw (I-type format)
Block diagram
3 MUXes
Registerfile operand or sign extended immediate to ALU
ALU or data memory output written to register file
PC+4 or branch target address written to PC register
Datapath for R-type instructions
001 or or
100101 or 001
Inst
<21:25>
<21:25>
<16:20>
<11:15>
<0:15>
Memory
Adr
Op Fun Rt Rs Rd Imm16
Control
DATA PATH
A Summary of Control
inst Register Transfer
Signals
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”
A Summary of Control
See
Signals We Don’t Care :-)
func 10 0000 10 0010
Appendix A 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
ALUctr<2:0> Add Subtract Or Add Add Subtract xxx
31 26 21 16 11 6 0
R-type op rs rt rd shamt funct add, sub
func
ALU ALUctr
op Main 6
ALUop Control 3
6 Control (Local)
N
ALU
The Encoding of
ALUop
func
ALU
op Main 6 ALUctr
ALUop Control
6 Control (Local) 3
N
In
this exercise, ALUop has to be 2 bits wide to
represent:
“R-type” instructions (1)
“I-type” instructions that require the ALU to perform:
(2) Or, (3) Add, and (4) Subtract
Toimplement the full MIPS ISA, ALUop has to be
3 bits to represent:
“R-type” instructions (1)
“I-type” instructions that require the ALU to perform:
(2) Or, (3) Add, (4) Subtract, and (5) And (Example: andi)
P. 286 text:
funct<5:0> Instruction Operation ALUctr ALUctr<2:0> ALU Operation
10 0000 add 000 And
10 0010 subtract 001 Or
10 0100 and
ALU
010 Add
10 0101 or 110 Subtract
10 1010 set-on-less-than 111 Set-on-less-than
The Truth Table for
ALUctr
funct<3:0> Instruction Op.
0000 add
ALUop R-type ori lw sw beq 0010 subtract
(Symbolic) “R-type” Or Add Add Subtract 0100 and
ALUop<2:0> 1 00 0 10 0 00 0 00 0 01 0101 or
1010 set-on-less-than
31 26 25 21 20 16 15 11 10 6 5 0
(0)
(34)
(43)
(4)
Adding support for jump
instructions
J-type format
31 26 25 0
2 target
IR=Mem[PC]
Instruction fetch
PC=PC+4
Instruction decode and register fetch
A=Reg[IR[25-21]], B=Reg[IR[20-16]]
Instruction decode and register fetch
Completion
Reg[IR[15-11]] = ALUOut
R-type execution cycle
ALUOut = A op B
R-type completion cycle
Reg[IR[15-11]] = ALUOut
Additional cycles for store
Address computation
ALUOut = A + sign-extend (IR[15-0])
Memory access
Memory[ALUOut] =B
Store address computation cycle
Memory[ALUOut] = B
Additional cycles for load
Address computation
ALUOut = A + sign-extend (IR[15-0])
Memory access
MDR = Memory[ALUOut]
Read completion
Reg[IR[20-16]] = MDR
Load memory access cycle
MDR = Memory[ALUOut]
Load read completion cycle
Reg[IR[20-16]] = MDR
Additional cycle for beq
Branch completion
if (A == B) PC = ALUOut
Branch completion cycle for beq
if (A == B) PC = ALUOut
Additional cycle for j
Jump completion
PC = PC[31-28] || (IR[25-0]<<2)
Jump completion cycle for j
PC = PC[31-28] || (IR[25-0]<<2)
Control logic design
Implemented as a Finite State Machine
CPI = 0.23*5+0.13*4+0.19*3+0.02*3+0.43*4=4.02
overflow
undefined
instruction
Saving exception information
Performed by hardware
We need the type of exception and the PC of
the instruction when the exception occurred
In MIPS, the Cause register holds the
exception type
Need an encoding for each exception type
Need a signal from the control unit to load it into the
Cause register
and the Exception Program Counter (EPC)
register holds the PC
Need to subtract 4 from the PC register to get the correct
PC (since we loaded PC+4 into the PC register during the
Instruction Fetch cycle)
Need a signal from the control unit to load it into EPC
Saving exception information
Saving program information
Needed in order to restart the program from the
point where the exception occurred
D2 E WB U pipe
PF D1
D2 E WB V pipe