GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A classic 5-stage pipeline (IF, ID, EX, MEM, WB) has full forwarding (EX/MEM and MEM/WB to the ALU inputs), so only a load followed immediately by a user of its result stalls, for one cycle. Branches are resolved in EX; a taken branch flushes the two instructions fetched after it and the target is fetched in the next cycle. Without hazards I1 finishes WB in cycle 5. Program: I1: LW R2, 0(R1); I2: ADD R3, R2, R2; I3: LW R4, 4(R1); I4: ADD R5, R4, R3; I5: BEQ R5, R6, L4; I6: LW R7, 0(R5); I7: ADD R8, R7, R5; I8 (label L4): SUB R9, R8, R5. The BEQ is taken. In which cycle does the last instruction finish WB?

  1. A. 14
  2. B. 15
  3. C. 18
  4. D. 16

Correct answer: A. 14

Load-use bubbles after I1 and I3; ID cycles I1 2, I2 4, I3 5, I4 7, I5 8, I8 11. The taken branch skips I6 and I7, so I8 (whose R8 is just the old value) is fetched after the branch resolves: ID 11, WB 14. Not taken, I6 → I7 adds another load-use bubble and the last WB is 15; without forwarding it would be 18.

More Computer Organization and Architecture questions

Exams that ask this topic