Search code examples
assemblypipelinecpu-architecturemicroprocessors

What is WAW Hazard?


Wikipedia's Hazard (computer architecture) article:

Write after write (WAW) (i2 tries to write an operand before it is written by i1) A write after write (WAW) data hazard may occur in a concurrent execution environment.

Example For example:

i1. R2 <- R4 + R7   
i2. R2 <- R1 + R3   

The write back (WB) of i2 must be delayed until i1 finishes executing.

I haven't understood this.

What is the problem if i2 is executed before i1?


Solution

  • Both operations affect R2. If i2 write back occurs before the write back of i1, but the write back of i1 does eventually occur, then R2 will have the result of R4 + R7 instead of the value of R1 + R3.

    The WAW Hazard is about result values being overwritten by a subsequent write that should not have overwritten that value.