Data forwarding techniques can be used to speed up the operation in presence…

2007

Data forwarding techniques can be used to speed up the operation in presence of data dependencies. Consider the following replacements of LHS with RHS.

image.png



In which of the following options, will the result of executing the RHS be the same as executing the LHS irrespective of the instructions that follow ?

  1. A.

    (i) and (iii)

  2. B.

    (i) and (iv)

  3. C.

    (ii) and (iii)

  4. D.

    (ii) and (iv)

Attempted by 52 students.

Show answer & explanation

Correct answer: B

Answer: (i) and (iv) are the safe replacements.

Explanation of each replacement:

  • (i) Original sequence: store Loc := R1; then load R2 := Loc. Replacement: R2 := R1; then store Loc := R1. Why safe: both sequences leave the same final values (Loc = R1 and R2 = R1). No later instruction can distinguish the two sequences because the same values are visible in the register and memory after completion.

  • (ii) This replacement is unsafe because it omits or changes a memory write or changes the value that ends up in memory. A subsequent instruction that reads the memory location Loc could observe a different value, so the RHS does not preserve observable behavior in all contexts.

  • (iii) This replacement is unsafe because it changes which value is ultimately stored at the memory location Loc (the RHS leaves a different final memory value than the LHS). Any later instruction that reads Loc would therefore see a different value.

  • (iv) This replacement is safe because the RHS preserves the same final memory and register values as the LHS. It does not remove or change a store in a way that a following instruction could observe; therefore the program behavior after these instructions is unchanged for any following instructions.

Summary: Replacements that preserve the final values of all registers and memory locations that subsequent code may access (i.e., do not omit or change stores or leave different values in memory/registers) are safe. Using this criterion, (i) and (iv) are safe; (ii) and (iii) are not.

Explore the full course: Gate Guidance By Sanchit Sir