5.2.4 · D4Processor Datapath & Pipelining

Exercises — Pipeline registers and control signals

2,580 words12 min readBack to topic

We will keep referring to one map of the pipeline. Look at it before starting.

Figure — Pipeline registers and control signals

The four vertical bars are the four pipeline registers. The coloured chips flowing left-to-right are control signals; each drops off at the stage that uses it.


Level 1 — Recognition

(Can you name the pieces and read the map?)

Recall Solution L1.1

There are four pipeline registers (a wall sits between neighbouring stages, so 5 stages give 4 gaps):

  • IF/ID — between Fetch and Decode
  • ID/EX — between Decode and Execute
  • EX/MEM — between Execute and Memory
  • MEM/WB — between Memory and Write-back

There is no register after WB: WB writes into the register file, which is itself stateful storage. So the count is 4, not 5.

Recall Solution L1.2

Group them by the stage that uses the signal:

  • EX bundle (used in Execute): ALUSrc, ALUOp, RegDst
  • MEM bundle (used in Memory): MemRead, MemWrite, Branch
  • WB bundle (used in Write-back): RegWrite, MemtoReg

So EX consumes 3, MEM consumes 3, WB consumes 2.

Recall Solution L1.3

All signals are generated in ID (Decode). Only ID reads the opcode; by the time an instruction reaches EX/MEM/WB, the instruction word has been consumed and those stages see only data + already-latched control bits. So the decode happens once, in ID, and the results travel.


Level 2 — Application

(Trace signals and compute widths.)

Recall Solution L2.1

RegWrite is decoded in ID but used only in WB (3 stages later). It must survive every intermediate wall:

  • Latched into ID/EX (EX doesn't use it → carried).
  • Copied into EX/MEM (MEM doesn't use it → carried).
  • Copied into MEM/WB (this is the last wall before WB).
  • Used in WB to drive the register-file write-enable, writing the result into $t0.

So it lives in ID/EX, EX/MEM, MEM/WB — three registers — and is consumed in WB.

Recall Solution L2.2

Add each field that a later stage needs (anything not stored is lost when EX moves on):

Recall Solution L2.3

Note MEM/WB is narrower than EX/MEM (71 < 107): it dropped the MEM bundle, the store data, the branch target, and the Zero flag — none of those are used in WB.


Level 3 — Analysis

(Explain and diagnose behaviour.)

Recall Solution L3.1

When lw's result reaches WB, the lw instruction was fetched 4 cycles ago; IF/ID now holds a different, younger instruction. Bits 20–16 of that instruction are some unrelated register number. So WB would write the loaded word into the wrong register — not $s0.

The fix (correct design): decode the 5-bit destination in ID and latch it ID/EX → EX/MEM → MEM/WB, so WB uses the older instruction's own target. See the dest-# chip travelling all the way to WB in the figure above.

Recall Solution L3.2

The branch target is computed by an adder in EX: The value is generated in Fetch but needed in EX. If it only lived in IF/ID, it would be gone by EX and the target adder would have no first operand. So PC+4 rides IF/ID → ID/EX (→ EX/MEM if the branch is resolved in MEM), exactly like any other value produced early and consumed late.

Recall Solution L3.3

Sizes: , , .

  • ID/EX holds EX+MEM+WB control bits.
  • EX/MEM holds MEM+WB control bits (EX bundle consumed & dropped).
  • MEM/WB holds WB control bits (MEM bundle consumed & dropped).

: strictly decreasing, because each register drops the bundle just used. See the shrinking chip-stack in the figure.


Level 4 — Synthesis

(Design and combine.)

Recall Solution L4.1

Count how many registers each bundle lives in:

  • EX bundle (3 bits): stored only in ID/EX (consumed in EX) → .
  • MEM bundle (3 bits): stored in ID/EX and EX/MEM (consumed in MEM) → .
  • WB bundle (2 bits): stored in ID/EX, EX/MEM, MEM/WB (consumed in WB) → .

Total control flip-flops bits.

Cross-check with the per-register sums: . ✓

Recall Solution L4.2

This is the widest of the pipeline registers — it stands right after decode and carries everything the downstream stages will ever need.

Recall Solution L4.3

First IF/ID: Grand total: of edge-triggered storage just for the pipeline registers (data + control), independent of the register file and memories.


Level 5 — Mastery

(Reason across the whole design under constraints.)

Recall Solution L5.1

MulEnable is decoded in ID (opcode-derived, like all control) and consumed in EX. It must be preserved from ID until EX, i.e. latched into ID/EX only (1 bit). Since EX consumes it, it is dropped and never enters EX/MEM.

  • ID/EX grows by 1 bit ().
  • EX/MEM, MEM/WB: unchanged.

This mirrors the existing EX bundle: born in ID, carried one wall, dropped after use.

Recall Solution L5.2

It must survive from ID until its last use (WB). So it is latched in ID/EX, EX/MEM, and MEM/WB — the same span as a WB-only signal, because "how far it travels" is set by its latest consumer, not by how many stages read it.

  • Flip-flop cost: bits (one per register it passes through).
  • A WB-only signal costs the same 3 bits. Being read in MEM as well adds no storage — the wire is simply tapped in MEM en route.

Key principle: transport cost depends only on the last stage that needs the signal.

Recall Solution L5.3

Storage compare: carrying a 6-bit opcode in each of ID/EX, EX/MEM, MEM/WB costs bits — more than the standard 15 bits. So it doesn't even save flip-flops here. Correctness: it can be made to work (each stage re-decodes its own bundle from the carried opcode), but it duplicates the control-unit decode logic into every stage, adding combinational delay to each stage's critical path and complicating verification. The standard design decodes once in ID and merely transports the results — cheaper in bits and in logic. Verdict: the lazy scheme is worse on both axes (18 > 15 bits, plus replicated decoders). The classic "decode once, transport" wins.


Recall Master summary (open only after finishing all levels)
  • 4 registers, storing 383 bits total for 32-bit MIPS (64 + 141 + 107 + 71).
  • Control is decoded once in ID; 15 control flip-flops total across ID/EX (8), EX/MEM (5), MEM/WB (2).
  • A signal's storage span is set by its latest consumer; each register drops consumed bundles, so control width strictly shrinks .

Connections

  • Single-cycle datapath — where control was combinational and un-pipelined
  • Pipeline hazards — arise because these staggered signals and results overlap
  • Forwarding and stalling — the fix that reads values out of these very registers
  • Control unit design — how the ID-stage signals are generated in the first place
  • Clocking and edge-triggered flip-flops — why the walls latch on the clock edge