5.2.3Processor Datapath & Pipelining

Classic 5-stage pipeline (IF - ID - EX - MEM - WB)

2,038 words9 min readdifficulty · medium

The five stages (WHAT each one does)

Figure — Classic 5-stage pipeline (IF - ID - EX - MEM - WB)

Pipeline registers (HOW the stages stay separate)

The four inter-stage registers are named IF/ID, ID/EX, EX/MEM, MEM/WB. They carry data (operands, immediate, ALU result) and control signals (RegWrite, MemRead, MemWrite, ...) forward, because control decisions made in ID must reach WB four cycles later.


Timing: deriving throughput & speedup from scratch


Worked examples


Common mistakes (Steel-man + fix)


Recall Feynman: explain it to a 12-year-old

Imagine washing dishes with 5 steps: scrape, wash, rinse, dry, stack. If one kid does all 5 for a plate before touching the next plate, four steps are always doing nothing. Instead, put 5 kids in a line — as soon as the "scrape" kid finishes plate 1 and passes it on, they grab plate 2. Now a clean plate pops out at the end every few seconds even though each plate still takes 5 steps to travel the line. The little trays between kids that hold the half-done plate are the "pipeline registers." That's exactly how a CPU pipelines instructions.


Active recall

What are the five classic pipeline stages in order?
IF (fetch), ID (decode/register read), EX (execute/address calc), MEM (memory access), WB (write back).
In which stage are source registers read, and in which are results written?
Read in ID; written in WB.
Why must the clock period equal the slowest stage delay plus latch overhead?
All stages share one clock; the pipeline advances every cycle so it is paced by its slowest stage, and each stage must latch its result (delay d). Tclk=max(ti)+dT_{clk}=\max(t_i)+d.
How many cycles to run N instructions through a k-stage pipeline (no stalls)?
k+(N1)k + (N-1) — k to fill, then one completes each subsequent cycle.
What is the ideal speedup limit of a k-stage pipeline as N→∞?
k× (throughput bounded by number of stages).
Does pipelining reduce the latency of a single instruction?
No — single-instruction latency slightly increases; it improves throughput (instructions per second).
What do pipeline registers (IF/ID, ID/EX, EX/MEM, MEM/WB) carry?
Data (operands, immediate, ALU result) AND control signals forward to the correct stage/cycle.
Which stages does a store (sw) actually use for its purpose?
IF, ID (read base+data), EX (address = base+offset), MEM (write); no WB.
Why do add-type instructions still pass through MEM and WB even though MEM is idle?
To keep all instructions the same 5-stage shape, so control is uniform and one instruction can finish every cycle.

Connections

Concept Map

goal

analogy

divides work into

step 1

feeds

feeds

feeds

feeds

separated by

named

carry data plus

clock set by

5-Stage Pipeline

Higher throughput

Assembly line

5 stages

IF Fetch from PC

ID Decode read regs

EX ALU compute

MEM Load or store

WB Write register file

Pipeline registers

IF/ID ID/EX EX/MEM MEM/WB

Control signals

T_clk = max stage + latch d

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Socho ek instruction ko complete karne ke liye 5 chhote kaam karne padte hain: instruction fetch karna (IF), decode + register padhna (ID), ALU se calculation (EX), memory access (MEM), aur result wapas register me likhna (WB). Agar hum ek instruction ke saare 5 kaam pehle poore karein phir agla shuru karein, to baaki hardware bekaar khadi rehti hai. Pipelining ek assembly line ki tarah kaam karti hai — jaise hi ek instruction IF se aage badhta hai, agla instruction turant IF me ghus jaata hai. Isse har clock cycle me ek naya instruction complete hone lagta hai.

Yaad rakho: pipelining ek single instruction ko tez nahi banati — uski latency thodi badh bhi jaati hai (5 stage + latch delay). Jo cheez sudhaarti hai wo hai throughput, matlab per second kitne instructions khatam ho rahe hain. Clock period slowest stage ke barabar hota hai (plus latch overhead dd), kyunki saari stages ek hi clock pe chalti hain — line utni hi tez jitni sabse dheemi worker.

Formula bilkul simple hai: NN instructions ke liye cycles =k+(N1)= k + (N-1) — pehle kk cycle pipe "bharne" me, phir har cycle me ek result. Bada NN hone par speedup kk (yahan 5) ke kareeb pahunch jaata hai, par practically hazards aur latch overhead ki wajah se thoda kam milta hai. Ye baat exam me bahut poochhi jaati hai, isliye latency vs throughput ka fark aur k+(N1)k+(N-1) formula pakka rat lo.

Go deeper — visual, from zero

Test yourself — Processor Datapath & Pipelining

Connections