In: Computer Science
Write in full sentence please be descriptive
What are the three different ways to solve a Data Hazard (including ALU+ ALU data Hazard and LW+ALU data Hazard)?
Data Hazards occur when an instruction depends on the result of previous instruction and that result of instruction has not yet been computed. whenever two different instructions use the same storage. They course imperfection in pipelining. It attempt use item before it is ready.
Following is a simple example to explain data hazard b/w two instructions.
ADD R5, R3, R4
SUB R7, R5, R6
here R5 is used in the second instruction which is the result of first instruction.
We should eliminate this kind of data hazard. For that we have 3 ways. And they are;
1. Give responsibility to the software- This puts the responsibility of removing hazards onto the compiler writer, and involves no extra hardware.
2.Eliminate by implement hardware to detect hazards, if they exist, and to insert a delay in the circuit which is called stalls.
Stalls are inserted to skip one stall cycle and instruction is waiting until other same instruction or depended instruction complete or data hazard is chance is leave. The simplest way to fix the hazard is to stall the pipeline. Stalling involves blocking flow of instructions until the result is ready to be used.
3. Instruction Reordering
For example:
ADD R5, R3, R4
SUB R7, R5, R6
ADD R1, R0
This can be resolved by re ordering the instruction as
ADD R5, R3, R4
ADD R1, R0
SUB R7, R5, R6