Data Forwarding
Notes
- We have discovered the sources of data hazards in our pipelined machine
- Data is produced
- At the end of the EX phase
- At the end of the MEM phase
- Data is consumed
- Two places at the beginning of the EX phase
- One place at the beginning of the MEM phase.
- If we associate the hazard with the consuming instruction, it is not hard to detect.
- We need to transfer the register destination of the producing instruction along in the data latches as that instruction executes.
- We can check this against the data source registers in the following instructions.
- When the consuming instruction is in ID, we can check "ahead" in the pipeline for the next two instructions.
- By the way, this is called hazard detection and is handled by a hazard detection unit.
- If there is a hazard, for each data source we can note
- Which instruction will be producing this data
- Note for all EX->EX we can simply Forward the data.
- For a MEM->MEM we can forward as well.
- This is handled by the forwarding unit
- But a MEM->EX might be a problem.
- In MIPS
- the programmer/compiler/assembler was responsible for filling the load delay slot with a non-hazard producing instruction,
- Possibly nop
- If I recall correctly, there was no hazard detection, do this wrong and the program fails.
- I remember saying "Put a nop after every load".
- This was apparently fixed in later versions of the chip.
- For ARM
- The have hazard detection that will insert a bubble if necessary
- But they would like the compiler to "fix" the code.
- If you care, Tomsulo's Algorithm can perform dynamic scheduling in hardware.
- This will reorder the instructions at the hardware level.
- It is not appropriate for this class.
- But versions of this algorithm are apparently still in use.
- The modification is not a surprise since the original algorithm is from 1967.