Pipeline Data Hazards: Example #1 - Write-Back Data Hazard
Pipeline Data Hazards: Example #1 - Write-Back Data Hazard
Observations see figure 1. o All instructions following ADD use R1 where R1 value only known after ADD instruction completed; o At what point in time does R1 appear from the pipe? o When does the SUB and AND instruction require R1s value? o OR operation requires R1s value in same cycle as ADD write-back. Can we avoid R1 read-write conflict?
Figure 4: When forwarding paths fail negative time. Need to introduce a stall or bubble into the pipe. Pipe / hardware INTERLOCK o Detects and inserts stalls into pipe o CPI increases by length of the stall. o Figure 5 summarizes the resulting stall cycle. Instruction 1 LD DSUB AND OR Figure 5: Case of stalled cycle IF 2 ID IF 3 EX ID IF 4 MEM Stall Stall Stall Clock 5 WB EX ID IF MEM EX ID WB MEM EX WB MEM WB 6 7 8 9
o Interested in producing code that avoids pipeline stalls in the following code fragment, a=b+c d=ef
o Assume a load latency of 1 clock cycle. Dependencies between the load for variables b and c and the ADD operation. Dependencies between the load for variables e and f and the SUB operation. Solution interleave load to e and f, or Target R1 R2 R3 R4 R5 a R6 d Source(s) b c e R1, R2 f R4 R3, R5 R6 Delaying the STORE avoids stalling on LOAD for f. Forward logic of the pipe avoids delay to the final STORE. Interleave load for SUB to avoid stalling on c. Comment LOAD LOAD LOAD ADD LOAD STORE SUB STORE
Instruction
Summary
Basic Data hazards and some of their solutions identified, o Forwarding applicable providing we do not need to forward results to a point in the execution pattern before the current clock count; o Interlock automatically inserts stalls when forwarding fails; o Compiler responsible for breaking up the sequential nature of program code. By doing so data dependencies are minimized and the pipe becomes more efficient.