GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A classic 5-stage pipeline (IF, ID, EX, MEM, WB) has no forwarding; the register file is written in the first half of a cycle and read in the second half, so a consumer can be in ID in the same cycle as its producer's WB. Branches are resolved in EX; when a branch is taken, the two instructions fetched after it are flushed and the target is fetched in the next cycle. Without hazards I1 is in ID in cycle 2 and finishes WB in cycle 5. Program: I1: LW R1, 0(R2); I2: ADD R3, R1, R4; I3: SUB R5, R3, R1; I4: SW R5, 0(R2); I5: BEQ R5, R6, L1; I6: ADD R7, R7, R1; I7 (label L1): OR R8, R5, R3. The BEQ is taken. In which cycle does the last instruction complete WB?

  1. A. 17
  2. B. 21
  3. C. 13
  4. D. 18

Correct answer: D. 18

A consumer's ID may coincide with its producer's WB (= producer ID + 3). ID cycles: I1 2, I2 5, I3 8, I4 11, I5 12, I7 15. I6 is flushed, and the target I7 reaches ID 3 cycles after the BEQ's ID; its sources R5 and R3 were written long before. WB = ID + 3 = 18. Not taken (I6 then I7) gives 17; without the split-cycle register file 21; with full forwarding 13.

More Computer Organization and Architecture questions

Exams that ask this topic