Forwarding ALU Result


Another way to solve the data hazards is by using forwarding or bypassing. It is to retrieve the missing data element from internal buffers rather than waiting for it to arrive from programmer-visible registers or memory. For example, consider the following instructions:
   sub   $1, $2, $3     # $1=$2–$3
   andi  $2, $1, 3      # $2=$1∧3
As soon as the ALU creates the difference for the subtraction, we can supply it as an input for the andi. It requires to add extra hardware to retrieve the missing item early from the internal resources. The following figure shows the data hazard caused by reading $2 after writing it.

The connection shows the forwarding path from the output of the EX stage of sub to the input of the EX stage for and.

It replaces the value from register $2 read in the second stage of and. No bubbles are inserted into the pipeline and therefore no cycles are wasted. Forwarding paths are valid only if the destination stage is later in time than the source stage. For example, there cannot be a valid forwarding path from the output of the memory access stage in the first instruction to the input of the execution stage of the following, since that would mean going backward in time.




      Feeling excited today. Just graduated from the police academy    
      and also read in my horoscope that I’m gonna be meeting a tall dark stranger.    
      Looking forward to trying out my new taser.