Lecture 11
Lecture 11
Instructor: Steven Ho
Review -- SDS and Sequential Logic
Setup Violation
CLK
FF CL FF
CLK
FF CL FF
• Ex: ALU
7/09/2018 CS61C Su18 - Lecture 11 6
Great Idea #1: Levels of
Representation & Interpretation
Higher-Level Language temp = v[k];
Program (e.g. C) v[k] = v[k+1];
v[k+1] = temp;
Compiler
lw $t0, 0($2)
Assembly Language lw $t1, 4($2)
Program (e.g. RISC-V) sw $t1, 0($2)
sw $t0, 4($2)
Assembler
0000 1001 1100 0110 1010 1111 0101 1000
Machine Language 1010 1111 0101 1000 0000 1001 1100 0110
Program (RISC-V) 1100 0110 1010 1111 0101 1000 0000 1001
0101 1000 0000 1001 1100 0110 1010 1111
Machine
Interpretation We are here
Hardware Architecture Description
(e.g. block diagrams)
Architecture
Implementation
Logic Circuit Description
(Circuit Schematic Diagrams)
7/09/2018 CS61C Su18 - Lecture 11 7
Agenda
• Datapath Overview
• Assembling the Datapath Part 1
• Administrivia
• Processor Design Process
• Assembling the Datapath Part 2
datapath control
register logic
switching
networks
7/09/2018 CS61C Su18 - Lecture 11 9
The Processor
• Processor (CPU): Instruction Set Architecture
(ISA) implemented directly in hardware
– Datapath: part of the processor that contains the
hardware necessary to perform operations
required by the processor (“the brawn”)
– Control: part of the processor (also in hardware)
which tells the datapath what needs to be done
(“the brain”)
DMEM
rd
PC
Reg[]
rs1
IMEM
ALU
DMEM
rs2
+ imm
4
mux
Clock
7/09/2018 time 14
Why Five Stages?
• Could we have a different number of stages?
– Yes, and other architectures do
• So why does RISC-V have five if instructions
tend to idle for at least one stage?
– The five stages are the union of all the operations
needed by all the instructions
– There is one instruction that uses all five stages:
load (lw/lb)
add x3,x1,x2
R[1] + R[2]
R[1]
registers
3
instruction
memory
PC
memory
1 ALU
Data
2 R[2]
imm
+4
MUX
+4 Reg[]
DataD Reg[rs1]
pc inst[11:7] alu
pc+4
IMEM AddrD
inst[19:15] AddrA DataA Reg[rs2]
+
inst[24:20] AddrB DataB
inst[31:0] RegWriteEnable
(RegWEn)
Control Logic
7/09/2018 CS61C Su18 - Lecture 11 20
Timing Diagram for add
+4 Reg[]
DataD Reg[rs1]
pc inst[11:7] alu
pc+4 IMEM AddrD
inst[19:15] AddrA DataA Reg[rs2]
+
inst[24:20] AddrB DataB
inst[31:0]
RegWEn
clock
time
Clock
PC 1000 1004
+4 Reg[]
DataD Reg[rs1]
ALU
pc inst[11:7] alu
IMEM AddrD
pc+4 inst[19:15] AddrA DataA Reg[rs2]
inst[24:20] AddrB DataB
Control Logic
7/09/2018 CS61C Su18 - Lecture 11 23
Implementing other R-Format instructions
+4 Reg[]
DataD Reg[rs1]
ALU
pc inst[11:7] alu
IMEM AddrD
pc+4 inst[19:15] AddrA DataA Reg[rs2]
inst[24:20] AddrB DataB
Control Logic
7/09/2018 CS61C Su18 - Lecture 11 26
Adding addi to datapath
+4 Reg[]
DataD
ALU
pc inst[11:7] Reg[rs1] alu
IMEM AddrD
pc+4 inst[19:15] AddrA DataA 0
Reg[rs2]
inst[24:20] AddrB DataB 1
inst[31:20]
Imm. imm[31:0]
Gen
Control Logic
7/09/2018 CS61C Su18 - Lecture 11 27
I-Format immediates
inst[31:0]
------inst[31]-(sign-extension)------- inst[30:20]
imm[31:0]
inst[31:20] imm[31:0]
Imm.
Gen • High 12 bits of instruction (inst[31:20]) copied to low 12 bits
of immediate (imm[11:0])
• Immediate is sign-extended by copying value of inst[31] to
ImmSel=I fill the upper 20 bits of the immediate value (imm[31:12])
+4 Reg[]
DataD
ALU
pc inst[11:7] Reg[rs1] alu
IMEM AddrD
pc+4 inst[19:15] AddrA DataA 0
Reg[rs2]
inst[24:20] AddrB DataB 1
Control Logic
7/09/2018 CS61C Su18 - Lecture 11 29
Agenda
• Datapath Overview
• Assembling the Datapath Part 1
• Administrivia
• Processor Design Process
• Assembling the Datapath Part 2
clock methodology
Datapath Output
3. Assemble datapath components
to meet the requirements
4. Analyze implementation of each instruction to determine
setting of control points that affect the register transfer
5. Assemble the control logic
• Formulate Logic Equations
• Design Circuits
38
Step 3: Assembling the Datapath
• Assemble datapath to meet ISA requirements
– Exact requirements will change based on ISA
– Here we must examine each instruction of RISC
• The datapath is all of the hardware
components and wiring necessary to carry out
ALL of the different instructions
– Make sure all components (e.g. RegFile, ALU) have
access to all necessary signals and buses
– Control will make sure instructions are properly
executed (the decision making)
+4 Reg[]
DataD
ALU
pc IMEM inst[11:7]
AddrD Reg[rs1] alu
pc+4 inst[19:15] AddrA DataA 0
Reg[rs2]
inst[24:20] AddrB DataB 1
inst[31:20]Imm.
imm[31:0]
Gen
Control Logic
7/09/2018 CS61C Su18 - Lecture 11 42
Adding lw to datapath
ALU
+4 Reg[]
wb
DataD
ALU DMEM 1
pc IMEM inst[11:7]
AddrD Reg[rs1]
Addr wb
pc+4 inst[19:15] AddrA DataA 0
DataR 0
Reg[rs2] mem
inst[24:20] AddrB DataB 1
inst[31:20]Imm.
imm[31:0]
Gen
inst[31:20]Imm.
imm[31:0]
Gen
inst[31:20]Imm.
imm[31:0]
Gen
*= “Don’t Care”
inst[31:0]
------inst[31]-(sign-extension)------- inst[30:20]
imm[31:0]
inst[31:20] imm[31:0]
Imm.
Gen • High 12 bits of instruction (inst[31:20]) copied to low 12 bits
of immediate (imm[11:0])
• Immediate is sign-extended by copying value of inst[31] to
ImmSel=I fill the upper 20 bits of the immediate value (imm[31:12])
5
5
1 6
I S
+4 Reg[] ALU
wb
DataD
Reg[rs1] ALU DMEM
pc IMEM inst[11:7]
AddrD
1
pc+4 Reg[rs2] Addr wb
DataR 0
inst[19:15] AddrA DataA 0
DataW mem
inst[24:20] AddrB DataB 1
+4 Reg[] pc
ALU
wb 1
DataD
alu 1 Reg[rs1] ALU DMEM
0
0
pc IMEM inst[11:7]
AddrD
1
Reg[rs2] Addr wb
pc+4 Branch DataR
0 0
inst[19:15] AddrA DataA
Comp. DataW mem
inst[24:20] AddrB DataB 1
PCSel inst[31:0] ImmSel RegWEn BrUn BrEq BrLT BSel ASel ALUSel MemRW WBSel
+4 Reg[] pc
alu
alu
wb 1
DataD
1 Reg[rs1] ALU DMEM
0
0
pc IMEM inst[11:7]
AddrD
1
Reg[rs2] Addr wb
Branch DataR 0
pc+4 inst[19:15] AddrA DataA 0
Comp. DataW mem
inst[24:20] AddrB DataB 1
PCSel=taken/not-taken inst[31:0] ImmSel=B RegWEn=0 BrUn BrEq BrLT Bsel=1 ASel=1 MemRW=Read WBSel=*
ALUSel=Add
Each instruction immediate bit can appear in one of two places in output immediate value –
so need one 2-way mux per bit
Only one bit changes position between S and B, so only need a single-bit 2-way mux
+4 Reg[] pc
alu
wb 1
DataD
alu 1 Reg[rs1] ALU DMEM
0
0
pc IMEM inst[11:7]
AddrD
1
Reg[rs2] Addr wb
pc+4 Branch DataR
0 0
inst[19:15] AddrA DataA
Comp. DataW mem
inst[24:20] AddrB DataB 1
PCSel inst[31:0] ImmSel RegWEn BrUn BrEq BrLT BSel ASel ALUSel MemRW WBSel
PCSel inst[31:0] ImmSel RegWEn BrUn BrEq BrLT BSel ASel ALUSel MemRW WBSel
WBSel=2
PCSel inst[31:0] ImmSel=B RegWEn=1 Bsel=1 Asel=0 MemRW=Read
ALUSel=Add
BrUn=* BrEq=* BrLT=*
PCSel inst[31:0] ImmSel RegWEn BrUn BrEq BrLT BSel ASel ALUSel MemRW WBSel
WBSel=2
PCSel inst[31:0] ImmSel=J RegWEn=1 Bsel=1 Asel=1 MemRW=Read
ALUSel=Add
BrUn=* BrEq=* BrLT=*
PCSel inst[31:0] ImmSel RegWEn BrUn BrEq BrLT BSel ASel ALUSel MemRW WBSel
instruction rd
memory
Register
memory
PC
rs1 ALU
Data
rs2 File
+4 imm
MUX