Consider the following code sequence having five instructions from . 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.
: ADD R1, R2, R3
: MUL R7, R1, R3
: SUB R4, R1, R5
: ADD R3, R2, R4
: MUL R7, R8, R9
Consider the following three statements.
S1: There is an anti-dependence between instructions
S2: There is an anti-dependence between instructions
S3: Within an instruction pipeline an anti-dependence always creates one or more stalls
Which one of the above statements is/are correct?
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:
- : Reads , Writes to
- : Reads , Writes to
- : Reads , Writes to
- : Reads , Writes to
- : Reads , Writes to
An anti-dependence (Write-After-Read / WAR) exists between instruction and a subsequent instruction () if writes to a register that is read by .
Analyzing the Statements:
S1: There is an anti-dependence between instructions and
- reads .
- writes to .
- There is no register read by and written by . (Note: Both write to , which is an output dependence / WAW, not an anti-dependence).
- Therefore, S1 is False.
S2: There is an anti-dependence between instructions and
- reads .
- writes to .
- Since reads before writes to , there is a WAR (anti-dependence) between and .
- 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 naturally completes before the write by 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.
