Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Store-after-load data dependence. Consider copying an array of n words from one

ID: 3606261 • Letter: S

Question

Store-after-load data dependence. Consider copying an array of n words from one address in memory to another. This can be accomplished by placing a sequence of lw and sw instructions in a loop, with each loop iteration copying one word. In the current pipelined implementation shown in the lecture slides, this leads to one bubble (stall cycle) between lw and sw. Is it possible to avoid this stalling via additional data forwarding hardware? Discuss how this can be done or explain how the bubble is unavoidable.

Explanation / Answer

Yes, forwarding is possible and we can avoid stalling the pipeline.

Consider:

LW $8, ... # LW instruction writes $8

SW $8, ... # SW instruction uses $8

We need a multiplexer at the input of EX/MEM.B register as show below. The data read from the data memory in the MEM stage should be fed back at the input of this multiplexer. A control signal “ForwardC” is needed to control the selection of this multiplexer. The Forwarding unit in the DECODE stage will generate the “ForwardC” signal and pipeline it, after detecting the dependency between a SW and a previous LW instruction. The SW instruction is currently in the DECODE stage (MemWrite = 1). The LW instruction is in the EXE stage (ID/EX.MemRead = 1). The ID/EX.RW register for the LW instruction contains the same register number as Rt for the SW instruction. The Forwarding Unit can detect this situation and generate the ForwardC signal.