Data Hazards - muneeb-mbytes/computerArchitectureCourse GitHub Wiki
WHAT IS DATA HAZARD
- Data hazards occur when instructions depend on the results of previous instructions, but those results have not yet been computed.
- These hazards arise when different instructions use the same storage location and must appear as if they execute in sequential order.
EXAMPLE 1
I1: ADD R1 <- R2 + R3
I2: SUB R4 <- R1 - R5
I3: AND R6 <- R1 AND R7
Handling Data Hazards
1) Stall Insertion:
Inserting no-op instructions (stalls) into the pipeline to delay execution until required operands are available.
Note: this method reduces pipeline efficiency and throughput.
MODIFIED EXAMPLE 1
I1: ADD R1 <- R2 + R3
I2: No-op
I3: No-op
I4: SUB R4 <- R1 - R5
I5: AND R6 <- R1 AND R7
2) Data Forwarding:
Forwarding of Data – Data forwarding is the process of sending a result straight to that functional unit which needs it: a result is transferred from one unit’s output to another’s input. The goal is to have the solution ready for the next instruction as soon as possible.
In this case, the ADD result can be found at the ALU output in ADD –IE, that is the t3 end. In case the control unit can control and forward this to the SUB-IE stage at t4 just before writing to the output register X3, the pipeline will proceed without halting. This necessitates additional processing to detect and respond to this data hazard. It’s worth noting that, though Operand Fetch normally occurs in the ID stage, it’s only utilised in the IE stage. As a result, the IE stage receives forwarding as an input. OR and AND instructions can also be used to forward data in a similar way.