RISC V Datapath II
We recommend you download the PPTX and play the animation on each slide!
CS61C
Great Ideas
in�Computer Architecture
(a.k.a. Machine Structures)
UC Berkeley�Teaching Professor�Dan Garcia
cs61c.org
Garcia, FA25
20-Datapath II (1)
Our Datapath So Far: Arithmetic/Logic
Imm. Gen
inst[31:20]
addr
inst
IMEM
add
PC
R[rs1]
clk
clk
imm[31:0]
pc
+4
alu
inst[31:0]
ImmSel
?
RegWEn
?�
BSel
?
ALUSel
?
Control Logic
pc+4
0
1
Imm. Gen
A
ALU
B
Bold white wires carry data.
Thin orange wires are control logic.
R[rs2]
inst[11:7]
inst[19:15]
inst[24:20]
rdata
addr
DMEM
wdata
clk
Review
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
Edge-triggered write.
If RegWEn=1, RegFile updated with input to dataW on the next rising-clock edge.
Garcia, FA25
20-Datapath II (2)
I-Type: Immediate Block
[for next time]
Agenda
Garcia, FA25
20-Datapath II (3)
Implementing the addi Instruction
addi rd rs1 imm
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
| | funct3 | | opcode | ||||||||||||||||
imm[11:0] | rs1 | 000 | rd | 0010011 | ||||||||||||||||
12 | 5 | 3 | 5 | 7 | ||||||||||||||||
OP-IMM
“add”
Garcia, FA25
20-Datapath II (4)
1. New MUX to Select Immediate for ALU
addr
inst
IMEM
add
PC
R[rs1]
clk
clk
R[rs2]
pc
+4
alu
inst[31:0]
RegWEn
1�
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
A
ALU
B
inst[11:7]
inst[19:15]
inst[24:20]
BSel
1
inst[31:20]
imm[31:0]
ImmSel
I
Imm. Gen
ALUSel
Add
0
1
1. Control line BSel=1 selects the generated immediate imm for ALU input B.
Garcia, FA25
20-Datapath II (5)
2. New Block to Generate 32-bit Immediate
addr
inst
IMEM
add
PC
R[rs1]
clk
clk
R[rs2]
pc
+4
alu
inst[31:0]
RegWEn
1�
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
A
ALU
B
inst[11:7]
inst[19:15]
inst[24:20]
0
1
BSel
1
Split and get the upper 12 bits of inst.
inst[31:20]
imm[31:0]
ImmSel
I
Imm. Gen
ALUSel
Add
1. Control line BSel=1 selects the generated immediate imm for ALU input B.
2. Immediate Generation Block builds a 32-bit immediate imm from instruction bits.
Garcia, FA25
20-Datapath II (6)
Tracing/Lighting the addi Datapath
Imm. Gen
inst[31:20]
addr
inst
IMEM
add
PC
inst[11:7]
inst[19:15]
inst[24:20]
R[rs1]
clk
clk
R[rs2]
imm[31:0]
pc
+4
inst[31:0]
ImmSel
RegWEn�
BSel
ALUSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
0
1
Imm. Gen
A
ALU
B
alu
R[rs2]
pc
Data inst[24:20] still feeds into Reg[], which still outputs R[rs2].
However, control Bsel=1 means R[rs2] data line is ignored.
Increment PC to next instruction.
Write ALU output to destination register.
Control line BSel=1 selects the generated immediate imm for ALU input B.
Immediate Generation Block builds a 32-bit immediate imm from instruction bits.
ImmSel
I
RegWEn
1�
BSel
1
ALUSel
Add
Garcia, FA25
20-Datapath II (7)
Implementing Loads
Agenda
Garcia, FA25
20-Datapath II (8)
Implementing the lw Instruction
lw rd imm(rs1)
LOAD
“load word”
31 | | | | | | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:0] | rs1 | funct3 | rd | opcode | ||||||||||||||||
000000001000 | 00010 | 010 | 01110 | 0000011 | ||||||||||||||||
12 | 5 | 3 | 5 | 7 | ||||||||||||||||
addr = (Base register rs1)
+ (sign-extended imm offset)
Garcia, FA25
20-Datapath II (9)
Saving Memory Read to RegFile
rdata
addr
DMEM
wdata
clk
mem
1
0
alu
Imm. Gen
inst[31:20]
addr
inst
IMEM
add
PC
R[rs1]
clk
clk
imm[31:0]
pc
+4
inst[31:0]
ImmSel
RegWEn�
BSel
ALUSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
0
1
Imm. Gen
A
ALU
B
R[rs2]
inst[11:7]
inst[19:15]
inst[24:20]
Read memory at address�alu = R[rs1] + imm.
If load instruction, save mem.�Otherwise, save alu.
MemRW
Read
WBSel
0
Garcia, FA25
20-Datapath II (10)
Lighting the LOAD Datapath
Imm. Gen
inst[31:20]
addr
inst
IMEM
add
PC
inst[11:7]
inst[19:15]
inst[24:20]
R[rs1]
clk
clk
R[rs2]
imm[31:0]
pc
+4
inst[31:0]
ImmSel
RegWEn�
BSel
ALUSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
0
1
Imm. Gen
A
ALU
B
R[rs2]
pc
Increment PC to next instruction.
Write loaded memory value mem to register.
ALU computes�address alu =� R[rs1] + imm.
Immediate Generation Block builds a 32-bit immediate imm.
rdata
addr
DMEM
wdata
clk
mem
1
0
alu
ImmSel
I
RegWEn
1�
BSel
1
ALUSel
Add
MemRW
Read
WBSel
0
Load uses all five stages of the datapath!
Read memory at address alu.
Garcia, FA25
20-Datapath II (11)
RV32I Can Load Different Widths
| | funct3 | | opcode | |
imm[11:0] | rs1 | 000 | rd | 0000011 | lb |
imm[11:0] | rs1 | 001 | rd | 0000011 | lh |
imm[11:0] | rs1 | 010 | rd | 0000011 | lw |
imm[11:0] | rs1 | 100 | rd | 0000011 | lbu |
imm[11:0] | rs1 | 101 | rd | 0000011 | lhu |
[reference; see Proj3]
Garcia, FA25
20-Datapath II (12)
Implementing Stores
Agenda
Garcia, FA25
20-Datapath II (13)
Implementing the sw Instruction
sw rs2 imm(rs1)
STORE
“store word”
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:5] | rs2 | rs1 | funct3 | imm[4:0] | opcode | |||||||||||||||
0000001 | 01110 | 00010 | 010 | 00100 | 0100011 | |||||||||||||||
7 | 5 | 5 | 3 | 5 | 7 | |||||||||||||||
0000001 | 00100 |
No RegFile write!
Garcia, FA25
20-Datapath II (14)
Updated Blocks for sw
Imm. Gen
inst[31:7]
addr
inst
IMEM
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
imm[31:0]
pc
+4
mem
inst[31:0]
ImmSel
S
RegWEn
�
BSel
ALUSel
MemRW
Write
WBSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
A
ALU
B
Control MemRW=Write saves rs2 to memory on the next rising clock edge.
0
1
Imm. Gen
1
0
Control ImmSel selects how to generate immediate type: I, S.
R[rs2]
inst[11:7]
inst[19:15]
inst[24:20]
R[rs2]
(to discuss later)
Garcia, FA25
20-Datapath II (15)
How to Set sw Control Lines?
Imm. Gen
inst[31:7]
addr
inst
IMEM
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
imm[31:0]
pc
+4
mem
inst[31:0]
ImmSel
S
RegWEn
?
�
BSel
?
ALUSel
Add
MemRW
Write
WBSel
?
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
A
ALU
B
0
1
Imm. Gen
1
0
R[rs2]
inst[11:7]
inst[19:15]
inst[24:20]
RegWEn Bsel WBSel
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:5] | rs2 | rs1 | 010 | imm[4:0] | 0100011 | |||||||||||||||
Garcia, FA25
20-Datapath II (16)
Garcia, FA25
20-Datapath II (17)
How to Set sw Control Lines RegWEn, BSel, ALUSel?
Imm. Gen
inst[31:7]
addr
inst
IMEM
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
imm[31:0]
pc
+4
mem
inst[31:0]
ImmSel
S
RegWEn
?
�
BSel
?
ALUSel
Add
MemRW
Write
WBSel
?
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
A
ALU
B
0
1
Imm. Gen
1
0
R[rs2]
inst[11:7]
inst[19:15]
inst[24:20]
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:5] | rs2 | rs1 | 010 | imm[4:0] | 0100011 | |||||||||||||||
Select all that apply
Garcia, FA25
20-Datapath II (18)
Lighting the STORE Datapath
Imm. Gen
inst[31:20]
addr
inst
IMEM
add
PC
inst[11:7]
inst[19:15]
inst[24:20]
R[rs1]
clk
clk
R[rs2]
imm[31:0]
pc
+4
inst[31:0]
ImmSel
RegWEn�
BSel
ALUSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
0
1
Imm. Gen
A
ALU
B
R[rs2]
pc
Increment PC to next instruction.
ALU computes�address alu =� R[rs1] + imm.
Build imm from�S-type instruction.
rdata
addr
DMEM
wdata
clk
mem
1
0
alu
ImmSel
S
RegWEn
0�
BSel
1
ALUSel
Add
MemRW
Write
WBSel
*
Write memory at address alu.
RegWEn=0 means no write back to RegFile, so “don’t care” (*) about WBSel’s value.
RegWEn Bsel WBSel
(most unselected data lines omitted from lighting)
Garcia, FA25
20-Datapath II (19)
Adding B-Type (Branches)
Agenda
Garcia, FA25
20-Datapath II (20)
B-Type: Conditional Branch
opname rs1 rs2 Label
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[12|10:5] | rs2 | rs1 | funct3 | imm[4:1|11] | opcode | |||||||||||||||
7 | 5 | 5 | 3 | 5 | 7 | |||||||||||||||
BRANCH
Garcia, FA25
20-Datapath II (21)
What do Branches Need to Compute?
Imm. Gen
inst[31:7]
addr
inst
IMEM
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
imm[31:0]
pc
+4
mem
inst[31:0]
ImmSel
RegWEn
�
BSel
ALUSel
MemRW
WBSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
A
ALU
B
0
1
Imm. Gen
1
0
R[rs2]
inst[11:7]
inst[19:15]
inst[24:20]
PC = PC + imm
PC = PC + 4
❓
❓
Only one ALU accessible in the same clock cycle. Need more hardware!!
Compare R[rs1] , R[rs2]
✅
add
Garcia, FA25
20-Datapath II (22)
The Branch Comparator Block
Imm. Gen
inst[31:7]
addr
inst
IMEM
add
PC
dataR
addr
DMEM
dataW
clk
clk
clk
imm[31:0]
pc
+4
mem
inst[31:0]
ImmSel
RegWEn
�
BSel
ALUSel
MemRW
WBSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
Imm. Gen
1
0
inst[11:7]
inst[19:15]
inst[24:20]
BrUn: Control�BrLT, BrEq: Output back to Control
Branch Comp.
R[rs1]
alu
A
ALU
B
0
1
BrUn
BrEq
BrLT
R[rs2]
Compare R[rs1],R[rs2],�feed result to Control Logic.
PCSel
taken/not taken
0
1
Update PC based on branch result.
pc + imm
Garcia, FA25
20-Datapath II (23)
The ALU computes PC + Imm
Imm. Gen
inst[31:7]
addr
inst
IMEM
Branch Comp.
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
pc
+4
mem
alu
inst[31:0]
PCSel
ImmSel
B
RegWEn�
BrUn
BrEq
BrLT
BSel
1
ASel
1
MemRW
WBSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
1
0
0
1
A
ALU
B
1
0
inst[11:7]
inst[19:15]
inst[24:20]
alu = PC + imm
“select imm”
“select PC”
ALUSel
Add
Imm. Gen
0
1
Garcia, FA25
20-Datapath II (24)
Lighting the Branch Datapath
Imm. Gen
inst[31:7]
addr
inst
IMEM
Branch Comp.
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
pc
+4
mem
alu
inst[31:0]
PCSel
taken/not taken
BrEq
BrLT
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
1
0
0
1
1
0
Imm. Gen
inst[11:7]
inst[19:15]
inst[24:20]
If PCSel=taken, update PC to ALU output. Else, update to next instruction PC + 4.
Build imm from�B-type instruction.
ImmSel
B
BrUn
1/0
BSel
1
ASel
1
MemRW
Read
ALUSel
Add
RegWEn
0�
WBSel
*
0
1
Don’t write to registers.
A
ALU
B
Don’t write to memory.
(unselected data lines omitted from lighting)
Garcia, FA25
20-Datapath II (25)
The Branch Comparator Block
Branch Comp.
R[rs1]
R[rs2]
BrUn
BrEq
BrLT
A
B
Control Logic
PCSel
taken/not taken
inst[31:0]
[reference]
Garcia, FA25
20-Datapath II (26)
Which Section Should We Discuss?
Agenda
Garcia, FA25
20-Datapath II (27)
Garcia, FA25
20-Datapath II (28)
Designing the Immediate Generation Block
Agenda
Garcia, FA25
20-Datapath II (29)
Immediate Block? I-Type
inst[31:20]
imm[31:0]
Imm. Gen
Instruction inst[31:0]
31 | 30 | | | | | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:0] | rs1 | funct3 | rd | opcode | ||||||||||||||||
s | ... .... .... | | | | | |||||||||||||||
31 | | | | | | | | | | | | 12 | 11 | | | | | | | 0 |
imm[31:12] | imm[11:0] | |||||||||||||||||||
ssss ssss ssss ssss ssss | s... .... .... | |||||||||||||||||||
Copy upper 12 bits of instruction, inst[31:20], to lower 12 bits of immediate, imm[11:0].
Immediate imm[31:0]
Sign-extend: Copy inst[31] to upper 20 bits of immediate, imm[31:12].
Garcia, FA25
20-Datapath II (30)
I-Type, S-Type Immediates
31 | | | | | | | | | | | | 12 | 11 | 10 | | 5 | 4 | | | 0 |
imm[31:12] | | imm[10:5] | imm[4:0] | |||||||||||||||||
ssss ssss ssss ssss ssss | s | ..... | ..... | |||||||||||||||||
inst[31:20]
imm[31:0]
Imm. Gen
Sign-extend instr[31] to imm[31:12].
6
Immediate imm[31:0]
Instruction inst[31:0]
31 | 30 | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11|10:5] | imm[4:0] | rs1 | funct3 | rd | I-OPCODE | |||||||||||||||
imm[11|10:5] | rs2 | rs1 | funct3 | imm[4:0] | S-OPCODE | |||||||||||||||
| | | | | | |||||||||||||||
s | ...... | ..... | | | ..... | | ||||||||||||||
I-Type
S-Type
For now, wire instr[31]directly to imm[11] (more next slide).
Garcia, FA25
20-Datapath II (31)
I-Type, S-Type Immediates
31 | | | | | | | | | | | | 12 | 11 | 10 | | 5 | 4 | | | 0 |
imm[31:12] | | imm[10:5] | imm[4:0] | |||||||||||||||||
ssss ssss ssss ssss ssss | s | ..... | ..... | |||||||||||||||||
inst[31:20]
imm[31:0]
Imm. Gen
ImmSel
5-bit MUX selects bits of inst to fill imm[4:0].
I S
5
For now, wire instr[31]directly to imm[11] (more next slide).
Sign-extend instr[31] to imm[31:12].
5
5
6
Immediate imm[31:0]
Instruction inst[31:0]
31 | 30 | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11|10:5] | imm[4:0] | rs1 | funct3 | rd | I-OPCODE | |||||||||||||||
imm[11|10:5] | rs2 | rs1 | funct3 | imm[4:0] | S-OPCODE | |||||||||||||||
| | | | | | |||||||||||||||
s | ...... | ..... | | | ..... | | ||||||||||||||
I-Type
S-Type
Garcia, FA25
20-Datapath II (32)
B-Type Immediates
31 | | | | | | | | | | | | 12 | 11 | 10 | | 5 | 4 | | 1 | 0 |
imm[31:12] | | imm[10:5] | imm[4:0] | |||||||||||||||||
ssss ssss ssss ssss ssss | . | ...... | ... | . | ||||||||||||||||
inst[31:20]
imm[31:0]
Imm. Gen
31 | 30 | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:5] | imm[4:0] | rs1 | funct3 | rd | I-OPCODE | |||||||||||||||
imm[11|10:5] | rs2 | rs1 | funct3 | imm[4:0] | S-OPCODE | |||||||||||||||
imm[12|10:5] | | | | imm[4:1|11] | B-OPCODE | |||||||||||||||
s | ...... | ..... | | | ..... | | ||||||||||||||
I-Type
S-Type
B-Type
instr[31] is always the sign bit.
MUX for imm[11]:
MUX for imm[0]:
Immediate imm[31:0]
Instruction inst[31:0]
Garcia, FA25
20-Datapath II (33)
Adding Jumps jal, jalr
Agenda
Garcia, FA25
20-Datapath II (34)
J-Type: Unconditional Jump
BRANCH
jal rd, Label
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[20|10:5] | imm[4:1,11] | imm[19:12] | rd | opcode | ||||||||||||||||
7 | 5 | 8 | 5 | 7 | ||||||||||||||||
(see Project 3)
Save return address�to RegFile destination register.
Garcia, FA25
20-Datapath II (35)
Block Updates Needed for JAL
Imm. Gen
addr
inst
IMEM
Branch Comp.
add
PC
R[rs1]
dataR
addr
DMEM
dataW
clk
clk
alu
R[rs2]
imm[31:0]
pc
+4
mem
pc+4
alu
inst[31:0]
PCSel
�
ImmSel
J
RegWEn
BrUn
BrEq
BrLT
BSel
ASel
ALUSel
MemRW
WBSel
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
1
0
0
1
A
ALU
B
0
1
1
0
2
1
0
Immediate Generation Block needs to support J-Types: 20-bit half-words 🡪 byte offset.
inst[11:7]
inst[19:15]
inst[24:20]
inst[31:7]
To save rd = PC + 4, WBSel now controls�a 3-input MUX.
clk
Imm. Gen
WBSel
2
PC = PC + imm
rd = PC + 4
Garcia, FA25
20-Datapath II (36)
Lighting the JAL Datapath
0
1
addr
inst
IMEM
Branch Comp.
add
Imm. Gen
PC
0
1
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
pc
+4
mem
pc+4
Write PC + 4 to destination register.
2
1
0
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
1
0
alu
alu
A
ALU
B
inst[31:0]
BrEq
BrLT
PCSel�taken(1)
ImmSel
J
RegWEn�1
BrUn
*
BSel
1
ASel
1
ALUSel
Add
MemRW
Read
WBSel
2
Control Logic
For JAL, “don’t care” about branch.
inst[11:7]
inst[19:15]
inst[24:20]
pc
inst[31:7]
Compute PC + imm.
PC = PC + imm
rd = PC + 4
Don’t write to memory.
Generate byte offset imm for 20-bit PC-relative jump.
(unselected data lines omitted from lighting)
Garcia, FA25
20-Datapath II (37)
I-Type Instruction Layout: jalr
31 | | | | | | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:0] | rs1 | funct3 | rd | opcode | ||||||||||||||||
12 | 5 | 3 | 5 | 7 | ||||||||||||||||
jalr rd,rs1,imm
Control ImmSel is based on instruction format, not instruction. So far: I,S,B,J
JALR
Garcia, FA25
20-Datapath II (38)
Lighting the JALR Datapath
0
1
addr
inst
IMEM
Branch Comp.
add
Imm. Gen
PC
0
1
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
pc
+4
mem
pc+4
Write PC + 4 to destination register.
2
1
0
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
Generate 12-bit imm (I-Type).
1
0
alu
alu
A
ALU
B
inst[31:0]
PCSel�taken
BrUn
*
BrEq
BrLT
ImmSel
I
RegWEn�1
BSel
1
ASel
0
ALUSel
Add
MemRW
Read
WBSel
2
Control Logic
inst[11:7]
inst[19:15]
inst[24:20]
pc
inst[31:7]
PC = R[rs1] + imm
R[rd] = PC + 4
Don’t write to memory.
Compute�R[rs1] + imm.
(unselected data lines omitted from lighting)
Garcia, FA25
20-Datapath II (39)
Adding U-Types
Agenda
Garcia, FA25
20-Datapath II (40)
U-Type Instruction Layout
opname rd,immed
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[31:12] | rd | opcode | ||||||||||||||||||
7 | 5 | 8 | 5 | 7 | ||||||||||||||||
“Destination” Register�
Immediate represents upper 20 bits of a 32-bit immediate imm.
Review
LUI
AUIPC
(see Project 3)
[reference; see Proj3]
Garcia, FA25
20-Datapath II (41)
U-Type Block update: Immediates
addr
inst
IMEM
A
ALU
B
Branch Comp.
add
PC
0
1
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
pc
+4
mem
pc+4
alu
inst[31:0]
ImmSel
U
RegWEn
BrUn
BrEq
BrLT
BSel
ASel
ALUSel
MemRW
Read
WBSel
Control Logic
Generate imm with upper 20 bits. (U-Type)
2
1
0
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
1
0
0
1
inst[11:7]
inst[19:15]
inst[24:20]
inst[31:7]
Imm. Gen
PCSel
[reference; see Proj3]
Garcia, FA25
20-Datapath II (42)
Lighting the LUI Datapath
0
1
addr
inst
IMEM
A
ALU
B
Branch Comp.
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
+4
mem
pc+4
alu
inst[31:0]
BrEq
BrLT
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
Grab only imm!�(ALUSel=B)
pc+4
Imm. Gen
2
1
0
1
0
Increment PC to next instruction.
Write result to destination register.
0
1
inst[11:7]
inst[19:15]
inst[24:20]
pc
inst[31:7]
PC = PC + 4
R[rd] = imm
Generate imm with upper 20 bits. (U-Type)
Don’t write to memory.
(unselected data lines omitted from lighting)
ASel
*
PCSel�not taken(0)
ImmSel
U
RegWEn�1
BrUn
*
BSel
1
ALUSel
B
WBSel
1
MemRW
Read
Garcia, FA25
20-Datapath II (43)
Lighting the AUIPC Datapath
A
ALU
B
Branch Comp.
add
PC
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
+4
mem
pc+4
alu
inst[31:0]
BrEq
BrLT
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
Add PC + imm!
pc+4
Imm. Gen
2
1
0
addr
inst
IMEM
1
0
Increment PC to next instruction.
Write result to destination register.
0
1
0
1
inst[11:7]
inst[19:15]
inst[24:20]
pc
pc
inst[31:7]
PC = PC + 4
R[rd] = PC + imm
Generate imm with upper 20 bits. (U-Type)
Don’t write to memory.
(unselected data lines omitted from lighting)
ASel
1
ALUSel
Add
PCSel�not taken(0)
ImmSel
U
RegWEn�1
BrUn
*
BSel
1
WBSel
1
MemRW
Read
Garcia, FA25
20-Datapath II (44)
And in Conclusion…
Agenda
Garcia, FA25
20-Datapath II (45)
Complete RV32I Datapath!
addr
inst
IMEM
A
ALU
B
Branch Comp.
add
Imm. Gen
PC
🥳🥳🥳
R[rs1]
rdata
addr
DMEM
wdata
clk
clk
clk
alu
R[rs2]
imm[31:0]
pc
+4
mem
pc+4
alu
inst[31:0]
PCSel
taken(1),not taken(0)
ImmSel
I,S,B,J,U
RegWEn
1,0
BrUn
0,1
BrEq
BrLT
BSel
0,1
ASel
0,1
ALUSel
Add,Sub,�etc.
MemRW
Read,Write
WBSel
0,1,2
Control Logic
wdata
rd
rs1 rdata1
rs2
rdata2
Reg[]
pc+4
1
0
0
1
0
1
inst[11:7]
inst[19:15]
inst[24:20]
inst[31:7]
2
1
0
Garcia, FA25
20-Datapath II (46)
Have a Great Spring Break!
Garcia, FA25
20-Datapath II (47)
Our Single-Core Processor So Far…
C
on
t
r
ol
D
a
t
ap
at
h
P
r
o
g
r
am
C
oun
t
er (PC)
R
egi
s
t
e
r
s
A
r
i
t
hm
e
t
i
c
-Logic
U
nit
(
A
L
U)
P
r
o
c
e
s
sor
Memo
r
y
Enabl
e
?
R
ead
/
W
r
i
t
e
A
dd
r
e
s
s
W
r
i
t
e
D
a
t
a
R
ead
D
a
t
a
I
n
put
Ou
t
put
B
y
t
e
s
P
r
o
g
r
am
D
a
t
a
Garcia, FA25
20-Datapath II (48)
How to Set sw Control Lines RegWEn,Bsel,WBSel ?
Imm. Gen
inst[31:7]
addr
inst
IMEM
add
PC
R[rs1]
dataR
addr
DMEM
dataW
clk
clk
clk
imm[31:0]
pc
+4
mem
inst[31:0]
ImmSel
S
RegWEn
�
Bsel
ALUSel
Add
MemRW
Write
WBSel
Control Logic
dataW
rsW
rsR1 dataR1
rsR2
dataR2
Reg[]
pc+4
A
ALU
B
0
1
Imm. Gen
1
0
R[rs2]
inst[11:7]
inst[19:15]
inst[24:20]
31 | | | | 25 | 24 | | 20 | 19 | | 15 | 14 | 12 | 11 | | 7 | 6 | | | | 0 |
imm[11:5] | rs2 | rs1 | 010 | imm[4:0] | 0100011 | |||||||||||||||
Select all that apply.
Garcia, FA25
20-Datapath II (49)