Professional Documents
Culture Documents
datapath control
• Ex: ALU
6
Sequential Elements
• Register: stores data in a circuit
– Uses a clock signal to determine when to update
the stored value
– Edge-triggered: update when Clk changes from 0
to 1
Clk
D Q
D
Clk
Q
Sequential Elements
• Register with write control
– Only updates on clock edge when write control
input is 1
– Used when stored value is required later
Clk
D Q Write
Write D
Clk
Q
Propagation Delay in Gates
9
Gate Delay (Propagation Delay)
• Time that it takes for combinational gate output to
change after inputs change
A
A
Y B
B
t gate
10
Path Delay
• Delay through a series of combinational gates:
– Specifically, the time it takes for the output of the series of
gates to change after the inputs to the path change.
• Example:
– Propagation delay for each gate is the same (1ns in this
example)
A
X
B
C
D Y
11
Path Delay
• Delay through a series of combinational gates.
– Specifically, the time it takes for the output of the series of
gates to change after the inputs to the path change.
• Example:
– Propagation delay for each gate is the same (1ns in this
example)
A 0
1 5
X
B 3
0 4
1 2
C
0
D Y
0 3 4
12
Comments on the Cct
A 0
1 5
X
B 3
0 4
1 2
C
0
D Y
0 3 4
other circuitry
other circuitry
D Q
C
Y
D Q
D Y
Q
D
D Q
14
General Structure of a Digital System
• Digital systems are made up of many stages of flip-flops
and combinational logic.
A
D Q
X
B D XQ
other circuitry
other circuitry
D Q
C
Y
D Q
D Y
Q
D
D Q
15
You’ve Seen this Before
• Finite State Machines, shift registers, counters, etc…
FSM FSM
Inputs Next State DFF Outputs
Output Logic
Logic
COUNT_INTERNAL
wire
+ D Q COUNT
1
CLK
COUNTER
16
Review: A General Sequential Circuit
Y1 y1
w
Combinational Combinational z
circuit circuit
Y2 y2
Clock
17
Review: Sequential Circuit
• In a sequential circuit, the values of the outputs
depend on the past behavior of the circuit, as well
as the present values of its inputs.
– Moore: If the outputs depend only on the present
state.
– Mealy: If the outputs depend on both the present
state and the present values of the inputs.
W Combinational Combinational
Flip-flops circuit Z
circuit Q
Clock
18
Review -- SDS and Sequential Logic
19
Clocking Methodology
• Combinational logic transforms data during
clock cycles
– Between clock edges
– Input from state elements, output to state
element
– Longest delay determines clock period
Agenda
• Datapath Overview
• Assembling the Datapath Part 1
• Processor Design Process
• Assembling the Datapath Part 2
24
Hardware Design Hierarchy
system
Today
datapath control
26
§4.3 Building a Datapath
Building a Datapath
• Datapath
– Elements that process data and addresses
in the CPU
• Registers, ALUs, mux’s, memories, …
• We will build a RISC-V datapath incrementally
– Refining the overview design
Executing an Instruction
Very generally, what steps do you take (order
matters!) to figure out the effect/result of the
next RISC-V instruction?
– Get the instruction add s0,t0,t1
– What instruction is it? add
– Gather data read R[t0], R[t1]
– Perform operation calc R[t0]+R[t1]
– Store result save into s0
28
Instruction Fetch
Increment by
4 for next
32-bit instruction
register
Basic Phases of Instruction Execution
rd
PC
Reg[]
rs1
IMEM
ALU
DMEM
rs2
+ imm
4
mux
Clock
time 30
State Required by RV32I ISA
Each instruction reads and updates this state during execution:
• Registers (x0..x31)
− Register file (or regfile) Reg holds 32 registers x 32 bits/register: Reg[0].. Reg[31]
− First register read specified by rs1 field in instruction
− Second register read specified by rs2 field in instruction
− Write register (destination) specified by rd field in instruction
− x0 is always 0 (writes to Reg[0]are ignored)
• Program Counter (PC)
− Holds address of current instruction
• Memory (MEM)
− Holds both instructions & data, in one 32-bit byte-addressed memory space
− We’ll use separate memories for instructions (IMEM) and data (DMEM)
▪ Later we’ll replace these with instruction and data caches
− Instructions are read (fetched) from instruction memory (assume IMEM read-only)
− Load/store instructions access data memory
32
Agenda
• Datapath Overview
• Assembling the Datapath Part 1
• Processor Design Process
• Assembling the Datapath Part 2
34
R-Format Instructions
• Read two register operands
• Perform arithmetic/logical operation
• Write register result
Implementing the add instruction
36
Datapath Walkthroughs (1/3)
• add x3,x1,x2 # r3 = r1+r2
1) IF: fetch this instruction, increment PC
2) ID: decode as add
then read R[1] and R[2]
3) EX: add the two values retrieved in ID
4) MEM: idle (not using memory)
5) WB: write result of EX into R[3]
37
Instruction Fetch
Increment by
4 for next
32-bit instruction
register
Example: add Instruction
add x3,x1,x2
R[1] + R[2]
R[1]
registers
3
instruction
memory
PC
memory
1
Data
ALU
2 R[2]
imm
+4
MUX
39
Datapath 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] RegWriteEnable
(RegWEn)
Control Logic
40
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
42
Datapath for add/sub
+4 Reg[]
DataD Reg[rs1]
ALU
pc IMEM
inst[11:7]
AddrD alu
pc+4 inst[19:15] AddrA DataA Reg[rs2]
inst[24:20] AddrB DataB
Control Logic
43
Implementing other R-Format instructions
44
Implementing the addi instruction
• RISC-V Assembly Instruction:
addi x15,x1,-50
45
Datapath for add/sub
+4 Reg[]
DataD Reg[rs1]
ALU
pc IMEM
inst[11:7]
AddrD alu
pc+4 inst[19:15] AddrA DataA Reg[rs2]
inst[24:20] AddrB DataB
Control Logic
46
Adding addi to datapath
+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
47
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])
48
Adding addi to datapath
+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
Control Logic
49
Why Five Stages?
• Could we have a different number of stages?
– Yes, and other architectures do
50
Administrivia
• Semester Project due on Monday 6th May 2019
− Project display schedule will be out in the coming week