Skip to content
Official PYQ · 2015

GATE CS 2015 Set 3 Q47 — Pipeline Hazards

Explain with AI

Consider the following code sequence having five instructions from I1 to I5I_1 \text{ to } I_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 I2 and I5I_2 \text{ and } I_5

S2: There is an anti-dependence between instructions I2 and I4I_2 \text{ and } I_4

S3: Within an instruction pipeline an anti-dependence always creates one or more stalls

Which one of the above statements is/are correct?

Choose one option
View worked solution

Answer: B

To determine the correctness of the statements, let us first identify the registers read and written by each instruction in the sequence:

  • I1I_1: Reads {R2,R3}\{R2, R3\}, Writes to {R1}\{R1\}
  • I2I_2: Reads {R1,R3}\{R1, R3\}, Writes to {R7}\{R7\}
  • I3I_3: Reads {R1,R5}\{R1, R5\}, Writes to {R4}\{R4\}
  • I4I_4: Reads {R2,R4}\{R2, R4\}, Writes to {R3}\{R3\}
  • I5I_5: Reads {R8,R9}\{R8, R9\}, Writes to {R7}\{R7\}

An anti-dependence (Write-After-Read / WAR) exists between instruction IiI_i and a subsequent instruction IjI_j (i<ji < j) if IjI_j writes to a register that is read by IiI_i.


Analyzing the Statements:

S1: There is an anti-dependence between instructions I2I_2 and I5I_5

  • I2I_2 reads {R1,R3}\{R1, R3\}.
  • I5I_5 writes to {R7}\{R7\}.
  • There is no register read by I2I_2 and written by I5I_5. (Note: Both write to R7R7, which is an output dependence / WAW, not an anti-dependence).
  • Therefore, S1 is False.

S2: There is an anti-dependence between instructions I2I_2 and I4I_4

  • I2I_2 reads {R1,R3}\{R1, R3\}.
  • I4I_4 writes to {R3}\{R3\}.
  • Since I2I_2 reads R3R3 before I4I_4 writes to R3R3, there is a WAR (anti-dependence) between I2I_2 and I4I_4.
  • Therefore, S2 is True.

S3: Within an instruction pipeline an anti-dependence always creates one or more stalls

  • In a standard in-order pipeline, registers are read in an early stage (e.g., Instruction Decode - ID) and written in a later stage (e.g., Write Back - WB). Because instructions execute in order, the read by I2I_2 naturally completes before the write by I4I_4 occurs. Thus, no stalls are needed.
  • In out-of-order processors, techniques like register renaming are used to eliminate anti-dependencies entirely without introducing any stalls.
  • Therefore, anti-dependence does not always create stalls, making S3 is False.

Conclusion:

Only statement S2 is true. Hence, the correct option is B.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Pipeline Hazards questions