Question

Consider the following code sequence having five instructions I1I_1 to I5I_5. Each of these instructions has the following format.
OP Ri, Rj, Rk
where operation OP is performed on contents of registers Rj and Rk and the result is stored in register Ri.

I1I_1: ADD R1, R2, R3
I2I_2: MUL R7, R1, R3
I3I_3: SUB R4, R1, R5
I4I_4: ADD R3, R2, R4
I5I_5: MUL R7, R8, R9

Consider the following three statements.
S1: There is an anti-dependence between instructions I1I_1 and I5I_5
S2: There is an anti-dependence between instructions I2I_2 and I4I_4
S3: Within an instruction pipeline an anti-dependence always creates one or more stalls

Which one of above statements is/are correct?

Choose one option
Official answer and solution
Official answer
B
From
Official GATE 2015 answer key

Solution

Identify Read-After-Write, Write-After-Read, and Write-After-Write dependencies across the instruction sequence.

Instructions format: OP Destination, Source1, Source2

  • I1I_1: ADD R1, R2, R3 (reads R2, R3; writes R1)
  • I2I_2: MUL R7, R1, R3 (reads R1, R3; writes R7)
  • I3I_3: SUB R4, R1, R5 (reads R1, R5; writes R4)
  • I4I_4: ADD R3, R2, R4 (reads R2, R4; writes R3)
  • I5I_5: MUL R7, R8, R9 (reads R8, R9; writes R7)

An anti-dependence (Write-After-Read, WAR) occurs between instruction IjI_j and subsequent instruction IkI_k (j<kj < k) if IjI_j reads a register that IkI_k writes.

Evaluate statements:

  • S1: Anti-dependence between I1I_1 and I5I_5. I1I_1 reads R2, R3; I5I_5 writes R7. No register conflict exists. Statement S1 is False.
  • S2: Anti-dependence between I2I_2 and I4I_4. I2I_2 reads R3; I4I_4 writes R3. Since I2I_2 reads R3 before I4I_4 writes to R3, there is a WAR anti-dependence on R3. Statement S2 is True.
  • S3: In standard in-order pipelined processors, operands are read in the ID stage while results are written in the later WB stage; hence reads naturally complete before later instructions write back, so anti-dependencies do not cause stalls in an in-order pipeline. Statement S3 is False.

Thus, only statement S2 is true (Option B).

Final answer

B

Common trap

Confusing true data dependencies (RAW, which can cause stalls) with anti-dependencies (WAR, which are hazards only in out-of-order execution).

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 3
Question
57 of 65, printed as CS Q.47
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.