Dependencies among four pipeline instructions
Pipelining & Hazards


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: RAW: I1→I2(r2), I1→I3(r2), I1→I4(r2), I2→I4(r4). WAR: I1→I2(r4), I1→I4(r3), I2→I4(r3). No WAW. (no official key was published)
1. List register accesses first: I1 reads r3,r4 and writes r2; I2 reads r2,r3 and writes r4; I3 reads r1,r2 and writes memory; I4 reads r4,r2 and writes r3.
2. A true (RAW) dependence connects an earlier writer to a later reader of that value. I1 supplies r2 to I2, I3 and I4. I2 supplies r4 to I4. These are the four true data dependencies.
3. For completeness, anti-dependencies (WAR) constrain later overwriting of earlier inputs: I1 reads r4 before I2 writes it; I1 and I2 read r3 before I4 writes it. These are I1→I2 on r4, I1→I4 on r3, and I2→I4 on r3.
4. No two instructions write the same register, so there are no output (WAW) dependencies. Only I3 accesses memory, so there is no inter-instruction memory dependence. WAR relations do not become hazards in this in-order five-stage pipeline, where reads precede later writes.



