Worked examples — Structural hazards
This page is the exhaustive worked-example companion to Structural hazards. The parent note built the idea of a resource conflict — two pipeline stages reaching for the same piece of hardware in the same clock tick. Here we chase down every kind of scenario that idea can produce and grind through the arithmetic, so no case ever surprises you in an exam.
If any word below feels unfamiliar (stage, cycle, stall, CPI), the parent note and Pipelining Fundamentals define them from zero. We reuse only those.
The scenario matrix
Every structural-hazard problem you will ever meet is one of the cells below. A "cell" is a class of situation — a combination of which resource conflicts, how the numbers behave, and what the question is really testing.
| # | Cell (case class) | What makes it distinct | Covered by |
|---|---|---|---|
| A | Single unified memory (IF vs MEM) | Classic 2-way port conflict, non-zero load fraction | Example 1 |
| B | Zero-hazard / degenerate input | Hazard probability → no stalls at all | Example 2 |
| C | Every-instruction hazard (limiting value) | Conflict on every cycle, | Example 3 |
| D | Multi-cycle resource (penalty ) | Stall penalty bigger than one cycle | Example 4 |
| E | Two independent hazard sources added | Memory hazard and functional-unit hazard together | Example 5 |
| F | Fix-by-hardware comparison | Same program, before vs after adding a resource | Example 6 |
| G | Real-world word problem | Embedded chip, throughput in MIPS | Example 7 |
| H | Exam twist: "reorder to remove stall" | Scheduling instead of arithmetic | Example 8 |
| I | Superscalar / port-count degenerate | Ports vs demanded accesses per cycle | Example 9 |
Before the numbers, one master formula that every cell uses.
Example 1 — Cell A: single unified memory
Forecast: guess — will CPI land near , , or ? (Hold your guess; we confirm it at the end of this example.)
The figure below is a pipeline timeline: each row is one instruction, each column one clock cycle, and each rounded box shows which stage that instruction occupies that cycle. Watch column 4 — that is where the collision happens.

- Identify and . Every load/store, when in MEM, wants memory at the same tick a later instruction wants IF. So and . Why this step? The formula needs a hazard probability and a penalty — nothing else. We must translate the English (" are loads") into .
- Apply the equation. . Why this step? Direct substitution into the master formula — the whole point of building it.
- Percentage slowdown. Throughput fraction , so the pipeline keeps of ideal speed. Percentage slowdown → slower. Why this step? Performance is inversely proportional to CPI; the slowdown is the lost share, i.e. one minus the throughput fraction.
Forecast check: the answer is the middle guess — if you picked "near ", you were right.
Verify: Look at the figure — in cycle 4, I1 sits in MEM (coral) and I4 wants IF (lavender): one memory, two demands → exactly one bubble, matching . Units: CPI is cycles/instruction; the throughput fraction and slowdown are dimensionless. ✓
Example 2 — Cell B: the degenerate zero case
Forecast: does removing all memory instructions kill the hazard entirely, or is there always some residual stall? (Decide now; the answer appears below.)
- Set . No instruction ever reaches MEM wanting data memory, so IF is never blocked. Why this step? This is the boundary of the model — we must confirm the formula behaves sanely when the hazard cannot occur.
- Apply the formula. . Why this step? Shows the structural-hazard term vanishes; the pipeline is back to ideal.
Forecast check: the hazard is killed entirely — CPI drops to the ideal with zero residual stall. If you predicted "no residual stall", correct.
Verify: . A pipeline that never conflicts must have ideal CPI — the number confirms our intuition, so the model is trustworthy at its lower edge. ✓
Example 3 — Cell C: the limiting value
Forecast: if every instruction stalls once, does CPI double, or grow by less? (Guess, then read on.)
- Set , . Every instruction incurs exactly one bubble. Why this step? Testing the upper extreme completes the range — no reader should wonder "what if it's always?".
- Apply the formula. . Why this step? Confirms the worst case for a 1-cycle penalty is a doubling, not something wilder.
- Percentage slowdown. Throughput fraction ; slowdown → the pipeline runs at half speed ( slower).
Forecast check: CPI exactly doubles to — if you guessed "double", spot on.
Verify: With one bubble per instruction, effectively two cycles pass per completed instruction → CPI . Half throughput. Numbers agree. ✓
Example 4 — Cell D: a multi-cycle resource ()
Forecast: a rare event but expensive — bigger or smaller effect than Example 1's frequent-but-cheap hazard? (Predict, then check step 3.)
- Read off and . , (three bubble cycles per divide). Why this step? The penalty is no longer ; we must not assume blindly.
- Apply the formula. . Why this step? Shows the product is what matters, not either factor alone.
- Compare with Example 1. Divider stall term memory stall term , so CPI : the rare-but-costly divider hurts slightly less than the frequent memory clash. Why this step? Exams love asking "which hazard costs more?" — the answer is always whichever has the larger .
Forecast check: smaller effect — the divider () hurts less than the memory hazard (). If you guessed "smaller", correct.
Verify: ; . And , so , confirming the comparison. ✓
Example 5 — Cell E: two hazards stacked
Forecast: do the CPI increases just add, or do they multiply? (Pick one; the answer is in step 1.)
- Stall terms add. Total stalls per instruction . Here the index ranges over the two sources . Why this step? Independent bubble sources contribute independent extra cycles — bubbles are counted, so they sum (this is exactly the in the master formula).
- Apply the formula once. . Why this step? The master formula's second term is the sum of all stall sources.
Forecast check: they add (not multiply) — the two stall terms and sum to .
Verify: ; . Notice this equals Example 1's CPI () plus Example 4's extra () — additivity holds. ✓
Example 6 — Cell F: before vs after a hardware fix
Forecast: is the speedup exactly , or something smaller? (Guess, then see step 2.)
The figure below contrasts the two designs side by side: on the left, one shared memory box forces IF and MEM to fight; on the right, two separate cache boxes each serve one stage, so nothing collides.

- New CPI. With separate caches, IF and MEM use different ports → , so . Why this step? Adding hardware removes the resource conflict, driving that hazard's to zero.
- Speedup factor. Performance , so speedup . Why this step? Comparing two designs on the same program means comparing CPI directly (clock period unchanged). Here the speedup exceeds because the new machine is faster.
Forecast check: exactly — the speedup equals the old CPI because the new CPI is .
Verify: faster. The figure shows the Harvard split: two separate memory boxes, so cycle 4 has no clash. This is the Pipeline Stalls cure by construction. ✓
Example 7 — Cell G: real-world word problem
Forecast: will the throughput be nearer 200, 160, or 100 MIPS? (Guess; confirmed at the end.)
- CPI. . Why this step? Throughput needs cycles-per-instruction first.
- MIPS = clock / (CPI ). Instructions per second . That gives instructions per second; dividing by converts "instructions per second" into "millions of instructions per second" (that is exactly what the M in MIPS means). So MIPS. Why this step? We first get raw instructions/second, then rescale by purely as a unit change so the answer reads in millions.
- Ideal MIPS. With CPI : MIPS. Hazard cost MIPS. Why this step? The "cost" is the gap between ideal and actual throughput.
Forecast check: the answer is 160 MIPS — the middle option. If you guessed "near 160", correct.
Verify: ; MIPS lost. Units: (cycles/s)/(cycles/instr) = instr/s ✓. Sanity: loss, matching . ✓
Example 8 — Cell H: the exam twist (reorder, no arithmetic)
Forecast: can clever ordering ever dodge this, or is it fundamentally a hardware shortage? (Decide, then check step 2.)
- Check if the conflict is order-dependent. IF (which computes PC ) happens for every instruction every cycle. EX happens for arithmetic instructions. Reordering changes which instruction is in EX, not the fact that some instruction is always in IF. Why this step? Instruction-Level Parallelism scheduling only helps hazards that depend on which instructions are adjacent; this one does not.
- Conclusion: not avoidable by reordering. Because IF demands the adder on every cycle, any instruction in EX collides. is structural, not schedule-dependent. Why this step? Distinguishes structural hazards (a physical shortage) from Data Hazards / Control Hazards (which reordering can soften).
- The real fix: a dedicated PC incrementer. A separate cheap 32-bit adder just for PC in the IF stage removes the sharing, dropping this hazard's to . Why this step? Matches the parent note's "add a cheap adder" resolution — cost of one adder ≪ cost of endless stalls.
Forecast check: it is fundamentally a hardware shortage — reordering cannot dodge it; only a dedicated adder does. If you guessed "hardware shortage", correct.
Verify: The logical claim: if a resource is demanded every cycle by one stage, no permutation of instructions removes the clash → reordering fails; only extra hardware works. Consistent with the parent's definition of a structural (resource) hazard. ✓ (No numeric check — this cell is conceptual by design.)
Example 9 — Cell I: superscalar port-count degenerate case
Forecast: with only 3 read ports but 4 reads demanded, does it stall, and by how much? (Guess, then follow the count.)
- Count demanded vs available reads. Demand reads this cycle; supply read ports. Shortfall read that cannot be served. Why this step? A port hazard is purely "demand supply" — count both sides.
- Stall to serialise the extra access. The one unserved read must wait, so the register access spreads over cycles instead of : penalty bubble. Why this step? Three ports can serve at most reads in one cycle; a th read has no port this cycle, so by definition it must slip to the next cycle — that slip is the single stall cycle.
- Write check. Writes demanded , write ports → supply meets demand, no write conflict this cycle. Why this step? We must cover every port type; the reader should never assume writes are fine without checking supply vs demand there too.
- Feed into the master formula. Let be the fraction of cycles this read-port shortage occurs, with . The read-port hazard contributes one term to the sum (here index ). Taking the worst case where every issue clashes, , so . Why this step? The page promised every cell routes through ; the port hazard is simply one more term, and gives its worst case.
Forecast check: yes it stalls — by exactly 1 cycle, pushing worst-case CPI to 2.0. If you guessed "stalls by 1", correct.
Verify: Reads ports → hazard, minimum stall cycle. Writes → OK. Worst-case CPI . The fix (add a 4th read port) sets demand supply, drives to , and removes the stall — matching the parent's "more ports" strategy. ✓
Recall Quick self-test on the cells
Which cell has the larger CPI, "frequent-cheap" () or "rare-costly" ()? ::: Frequent-cheap: , so CPI . Compare the products . Can instruction reordering remove a structural hazard that hits every cycle? ::: No — it is a hardware shortage, not an ordering problem; only extra hardware (or accepting the stall) helps. A program with on single-port memory has what memory-hazard CPI? ::: Exactly — the stall term vanishes.