COA Notes
Important pipelining questions for exams and interviews with detailed solutions.
Introduction
Pipelining questions are among the most frequently asked in computer architecture exams, GATE papers, and technical interviews. They test your ability to trace instruction execution through pipeline stages, identify hazards, apply forwarding, and calculate performance metrics. This page covers the most important question types with step-by-step solutions. Master these patterns, and you will handle any pipeline question thrown at you.
Question Type 1: Basic Pipeline Timing
Q1: Calculate execution time and speedup
Problem: A non-pipelined processor takes 50 ns per instruction (5 stages × 10 ns each). The pipelined version has 5 stages with 12 ns clock cycle (10 ns + 2 ns overhead). Calculate time for 100 instructions and speedup.
Solution:
Note: Ideal speedup would be 5× (number of stages). The 2 ns register overhead and pipeline fill time reduce it slightly.
Q2: Unbalanced pipeline stages
Problem: A 4-stage pipeline has stage delays: 15 ns, 10 ns, 12 ns, 8 ns. Pipeline register delay is 1 ns. What is the clock cycle time? What would be ideal if stages were balanced?
Solution:
This shows why pipeline stage balancing matters — the slowest stage determines clock speed for the entire pipeline.
Question Type 2: Hazard Detection
Q3: Identify all hazards
Problem: Identify hazards in this instruction sequence for a 5-stage pipeline:
| I1 | ADD R1, R2, R3 |
| I2 | SUB R4, R1, R5 |
| I3 | LW R6, 100(R1) |
| I4 | AND R7, R6, R8 |
| I5 | OR R9, R6, R1 |
Solution:
RAW (Read After Write) Hazards:
- I1 → I2: R1 (I1 writes R1, I2 reads R1) — EX-EX forwarding resolves
- I1 → I3: R1 (I1 writes R1, I3 reads R1) — MEM-EX forwarding resolves
- I3 → I4: R6 (I3 loads R6, I4 reads R6) — Load-use hazard! 1 stall required
- I3 → I5: R6 (I3 loads R6, I5 reads R6) — MEM-EX forwarding resolves (after stall for I4)
No WAR or WAW hazards in this in-order pipeline.
Q4: Pipeline diagram with stalls
Problem: Draw the pipeline timing diagram for Q3's instructions with forwarding.
Solution:
| Cycle | 1 2 3 4 5 6 7 8 9 10 |
| I1 | IF ID EX MEM WB |
| I2 | IF ID EX MEM WB [EX-EX fwd: R1] |
| I3 | IF ID EX MEM WB [MEM-EX fwd: R1] |
| I4 | IF ID ██ EX MEM WB [1 stall, MEM-EX fwd: R6] |
| I5 | IF ██ ID EX MEM WB |
██ = stall/bubble
Total: 10 cycles for 5 instructions. CPI = 10/5 = 2.0 (ideal would be 9/5 = 1.8 without load-use).
Question Type 3: Forwarding Path Identification
Q5: Which forwarding paths are active?
Problem: For each dependent pair in the sequence below, identify the forwarding path used:
| I1 | MUL R1, R2, R3 (result at end of EX) |
| I2 | ADD R4, R1, R5 (needs R1 at start of EX) |
| I3 | SW R4, 0(R6) (needs R4 at start of EX) |
| I4 | LW R7, 4(R6) (independent) |
| I5 | SUB R8, R7, R1 (needs R7 from load, needs R1) |
Solution:
| Dependency | Forwarding Path | Explanation |
|---|---|---|
| I1 → I2 (R1) | EX/MEM → EX | I1's result in EX/MEM pipeline reg forwarded to I2's EX input |
| I2 → I3 (R4) | EX/MEM → EX | I2's result forwarded to I3's EX input for address calc |
| I4 → I5 (R7) | MEM/WB → EX (with 1 stall) | Load-use: stall 1 cycle, then forward from MEM/WB |
| I1 → I5 (R1) | Register file | By time I5 reaches ID, I1 has completed WB (>2 cycles apart) |
Question Type 4: Branch Prediction
Q6: 2-bit predictor state transitions
Problem: A 2-bit saturating counter starts at state "Weakly Taken" (10). The actual branch outcomes are: T, T, NT, NT, T, NT, T, T. Show state after each branch and count mispredictions.
Solution:
| Branch | Actual | State Before | Prediction | Correct? | State After |
|---|---|---|---|---|---|
| 1 | T | 10 | Taken | ✓ | 11 |
| 2 | T | 11 | Taken | ✓ | 11 |
| 3 | NT | 11 | Taken | ✗ | 10 |
| 4 | NT | 10 | Taken | ✗ | 01 |
| 5 | T | 01 | Not Taken | ✗ | 10 |
| 6 | NT | 10 | Taken | ✗ | 01 |
| 7 | T | 01 | Not Taken | ✗ | 10 |
| 8 | T | 10 | Taken | ✓ | 11 |
This irregular pattern is hard for any predictor. Real branch patterns (loops) are much more predictable.
Question Type 5: Performance with Hazards
Q7: Calculate effective CPI
Problem: In a processor's instruction mix: 25% are loads (40% of which are followed by dependent instructions causing 1 stall each), 15% are branches (branch penalty = 2 cycles, predictor accuracy = 85%). Calculate effective CPI.
Solution:
Q8: Impact of deeper pipeline
Problem: Compare a 5-stage pipeline (branch penalty = 2) with a 12-stage pipeline (branch penalty = 7). Branch frequency = 20%, prediction accuracy = 90%.
Solution:
The deeper pipeline is faster overall despite higher branch penalty because the clock is much faster.
Question Type 6: Structural Hazards
Q9: Unified memory structural hazard
Problem: A pipeline has unified instruction/data memory (single port). When a LOAD/STORE is in MEM stage, no instruction can be fetched. What is the CPI if 30% of instructions are loads/stores?
Solution:
Question Type 7: Pipeline Scheduling
Q10: Reorder instructions to minimize stalls
Problem: Schedule these instructions to eliminate stalls (with forwarding):
Solution:
| Cycles saved | 2 stall cycles eliminated |
| Original | 5 + 2 stalls = 7 cycles for pipeline completion |
| Optimized | 5 + 0 stalls = 5 cycles (after pipeline fills) |
This is exactly what optimizing compilers do — instruction scheduling fills load delay slots with independent instructions.
Common Mistakes to Avoid
- Forgetting pipeline fill time: Total time = (k + n - 1) × cycle, not just n × cycle
- Wrong forwarding path: EX-EX forwarding serves the immediately next instruction, MEM-EX serves two instructions later
- Assuming loads have no penalty with forwarding: Load-use ALWAYS costs 1 stall even with full forwarding
- Miscounting branch penalty: Penalty = cycles wasted = number of instructions flushed
- Ignoring register 0: In MIPS, writes to $0 are discarded — no forwarding needed from R0
- Confusing CPI components: Each hazard type contributes independently to CPI; add them all up
Key Takeaways
- Pipeline performance = ideal CPI (1) + stalls from all hazard sources
- Data hazards: solved by forwarding (except load-use which needs 1 stall)
- Control hazards: penalty = misprediction_rate × pipeline_stages_wasted × branch_frequency
- Deeper pipelines give faster clock but higher hazard penalties — there is an optimal depth
- Compiler scheduling can eliminate many stalls by reordering independent instructions
- Always draw the timing diagram — visual representation prevents calculation errors
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Pipelining Questions.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Computer Organization & Architecture topic.
Search Terms
computer-organization, computer organization & architecture, computer, organization, interview, preparation, pipelining, questions
Related Computer Organization & Architecture Topics