GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Identify dependencies and forwarding feasibility

3 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Read producers and consumers in the four-instruction sequence, locate operand need and result availability in IF/ID/EX/MEM/WB, and distinguish dependences from actual hazards. Register reads occur in the second half and writes in the first half.

Descriptive
Report issue

Dependencies among four pipeline instructions

Pipelining & Hazards

Question 12(a), 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: Show all data dependencies among the four instructions.
Question 12(a), 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: Show all data dependencies among the four instructions.
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: 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.

Original paper, page 8

Descriptive
Report issue

Identify pipeline data hazards

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

Descriptive
Report issue

Forwarding to avoid pipeline hazards

Pipelining & Hazards

Question 12(c), 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: Determine whether forwarding can avoid all the hazards in this sequence.
Question 12(c), 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: Determine whether forwarding can avoid all the hazards in this sequence.
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: Yes, with normal ALU forwarding and a forwarding path for the store data; no load-use stall is present. (no official key was published)

1. I1 computes its r2 result at the end of EX in cycle 3. I2 needs that value at EX in cycle 4, so forwarding from I1’s EX/MEM register to I2’s ALU input resolves the nearest RAW hazard.

2. I3 may have read a stale r2 during ID4, but its store value can be corrected by forwarding the I1 result from MEM/WB during I3’s EX5 into the store-data path. That corrected value is carried to MEM6 for the write. An equivalent appropriately staged store-data bypass also works.

3. I2 computes r4 at the end of EX4. I4 needs it during EX6; the value can be forwarded from I2’s MEM/WB register to I4’s ALU input. I4’s r2 operand is already correct from the same-cycle WB5/ID5 timing.

4. All producer results are available before their consumer execution or memory-use stages, so no bubble is required with these bypasses. None of the instructions is a load producing a value too late for an immediately following EX stage.

5. The qualification matters: an implementation forwarding only ALU inputs but not correcting the store-data path would not resolve I3’s stale store value. The yes answer assumes forwarding includes the needed store-data path, not an unspecified restricted implementation.

Original paper, page 8