5.2.7 · D3Processor Datapath & Pipelining

Worked examples — Load-use hazard and stalls

3,746 words17 min readBack to topic

You already met the load-use hazard in Load-use hazard and stalls. That parent note showed you one clean case: lw then add, one stall, done. But the real world throws messier shapes at you — stores, zero registers, chains of dependents, branches right after a load. This page walks through every distinct case class, one at a time, so you never meet a scenario you haven't already seen solved.

Before any example, let's name the five things every pipeline stage is and does, so no symbol sneaks up on you. Then we define stall, bubble, and the exact three-condition test — everything you need is on this page.

Read the forwarding figure this way: each stage box is drawn once, and the curved arrows show where a value born at the MEM/WB latch (the red source on the right) can be teleported. The red-highlighted WB box is where the value physically lives; the curved arrows peel off it and land on EX, MEM, or ID of a later instruction. There is no arrow pointing backwards in time — every arrow lands on a stage happening in a later cycle, which is the whole point.

Figure — Load-use hazard and stalls

Read the timeline figure below this way: the five boxes are the five stages of a single lw, laid left-to-right in cycles 1–5. Four boxes are black; only the MEM box is red, because MEM is where the memory read happens. The red arrow points at the right edge of that MEM box — the instant (end of cycle 4) when the loaded number first exists. Nothing can read this value before that edge. Memorise this "ready at end of MEM" landmark; every example measures its need-cycle against it.

Figure — Load-use hazard and stalls

The scenario matrix

Here is every case class this topic can produce. Each later example is tagged with the cell it fills.

# Case class What makes it distinct Stall?
A Load → ALU use (immediate) consumer needs data in EX, one cycle after load 1 stall
B Load → independent instr → use a gap absorbs the delay 0 stalls
C Load → store of that value consumer needs data in MEM, later than EX 0 stalls
D Load into $zero (degenerate) condition-3 guard: $0 never really changes 0 stalls
E Load → use as base address of another load lwlw chained through address register 1 stall
F Load → branch using loaded value branch resolves early → needs data even sooner 2 stalls
G Two dependents in a row after a load only the first dependent triggers the stall 1 stall
H Word problem: CPI of a real loop limiting/aggregate behaviour over many instrs
I Exam twist: which of 4 pairs stalls apply the 3-condition test coldly mixed

We'll hit all of A–I below.











Recall Quick self-test

A load produces its value at the end of which stage? ::: MEM A store consumes its data register in which stage? ::: MEM What is a bubble? ::: a NOP (do-nothing) slot inserted by a stall, sliding down the pipe Why does loading into $0 never stall? ::: $0 is hardwired to 0, so no real value is produced (condition 3 fails) Load feeding an early-resolved branch needs how many stalls? ::: 2 Two dependents right after a load cause how many total stalls? ::: 1 Where does "" in " cycles" come from? ::: pipeline fill: the first instruction needs 4 extra cycles to pass all 5 stages CPI if 30% loads and 40% of loads have immediate use? ::: 1.12