GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 12(b)

Identify pipeline data hazards

Computer Organization & Architecture · Pipelining & Hazards · Full GATE CSE 2001 paper

GATE 2001, Q12(b) Descriptive
Report issue

Pipelining & Hazards

Question 12(b), GATE 2001: Five stages IF, ID, EX, MEM, WB; reads occur in second half of cycle, writes in first half. I1: sub r2,r3,r4; I2: sub r4,r2,r3; I3: sw r2,100(r1); I4: sub r3,r4,r2.

Task: Identify the data hazards.
Question 12(b), GATE 2001: Five stages IF, ID, EX, MEM, WB; reads occur in second half of cycle, writes in first half. I1: sub r2,r3,r4; I2: sub r4,r2,r3; I3: sw r2,100(r1); I4: sub r3,r4,r2.

Task: Identify the data hazards.
Tap to enlarge
Shared context

Five stages IF, ID, EX, MEM, WB; reads occur in second half of cycle, writes in first half. I1: sub r2,r3,r4; I2: sub r4,r2,r3; I3: sw r2,100(r1); I4: sub r3,r4,r2.

Answer & solution

Answer: Without forwarding, RAW hazards: I1→I2 on r2, I1→I3 on r2, I2→I4 on r4. I1→I4 is not a timing hazard. (no official key was published)

Step through it (6 steps)

1. Write the unstalled stage schedule. I1: IF1 ID2 EX3 MEM4 WB5; I2: IF2 ID3 EX4 MEM5 WB6; I3: IF3 ID4 EX5 MEM6 WB7 (store has no register write); I4: IF4 ID5 EX6 MEM7 WB8.

2. I1 writes r2 in cycle 5. I2 tries to read it in cycle 3 and I3 in cycle 4, both too early without forwarding. These two true dependencies create RAW hazards.

3. I2 writes r4 in cycle 6, while I4 reads r4 in cycle 5, producing the third RAW hazard.

4. I4 also depends on I1 for r2, but reads in the second half of cycle 5 after I1 writes in its first half. Therefore this dependency is safe under the explicit half-cycle timing.

5. WAR and WAW hazards do not arise in the given ordered pipeline. This list describes the original unstalled timing; adding stalls can incidentally eliminate later conflicts, so dependency and hazard should not be conflated.

Original paper, page 8