Chapter 4 Part 2
Chapter 4 Part 2
Edition
The Hardware/Software Interface
Chapter 4
The Processor
Part-2
§4.5 An Overview of Pipelining
Pipelining Analogy
n Pipelined laundry: overlapping execution
n Parallelism improves performance
n Four loads:
n Speedup
= 8/3.5 = 2.3
n Non-stop:
n Speedup
= 2n/0.5n + 1.5 ≈ 4
= number of stages
x19 ready
Chapter 4 — The Processor — 10
Forwarding (aka Bypassing)
n Use result when it is computed
n Don’t wait for it to be stored in a register
n Requires extra connections in the Datapath
x1
ready
n In RISC-V pipeline
n Need to compare registers and compute
target early in the pipeline
n Add hardware to do it in ID stage
MEM
Right-to-left WB
flow leads to
hazards
Pipeline registers
n Need registers between stages
n To hold information produced in previous cycle
IF/ID ID/EX EX/MEM MEM/WB
Pipeline Operation
n Cycle-by-cycle flow of instructions through
the pipelined Datapath
n “Single-clock-cycle” pipeline diagram
n Shows pipeline usage in a single cycle
n Highlight resources used
n c.f. “multi-clock-cycle” diagram
n Graph of operation over time
n We’ll look at “single-clock-cycle” diagrams
for load & store
Wrong
register
number
EX:
01
10
00
01
10
Forwarding Conditions
Mux control Source Explanation
ForwardA = 00 ID/EX The first ALU operand comes from the register file.
ForwardA = 10 EX/MEM The first ALU operand is forwarded from the prior
ALU result.
ForwardA = 01 MEM/WB The first ALU operand is forwarded from data
memory or an earlier ALU result.
ForwardB = 00 ID/EX The second ALU operand comes from the register
file.
ForwardB = 10 EX/MEM The second ALU operand is forwarded from the prior
ALU result.
ForwardB = 01 MEM/WB The second ALU operand is forwarded from data
memory or an earlier ALU result.
and (MEM/WB.RegisterRd ≠ 0)
and not(EX/MEM.RegWrite and (EX/MEM.RegisterRd ≠ 0)
and (EX/MEM.RegisterRd ≠ ID/EX.RegisterRs1))
and (MEM/WB.RegisterRd = ID/EX.RegisterRs1)) ForwardA = 01
n if (MEM/WB.RegWrite
and (MEM/WB.RegisterRd ≠ 0)
and not(EX/MEM.RegWrite and (EX/MEM.RegisterRd ≠ 0)
and (EX/MEM.RegisterRd ≠ ID/EX.RegisterRs2))
and (MEM/WB.RegisterRd = ID/EX.RegisterRs2)) ForwardB = 01
Stall inserted
here
Datapath with Hazard Detection
0
Stalls and Performance
The BIG Picture