Thursday, September 1, 2011

Data Hazards

Today I finished learning about two of the common (or were common in 1995 at any rate) methods for renaming registers.

First off I should probably explain what "renaming registers" means.  In order to have multiple instructions executing in parallel and/or executing out of order (very common nowadays) you need to prevent something called "data hazards".

We seem to have encountered yet another term, so let me define it real quick: A data hazard is a situation where there is a chance that the data will end up being incorrect due to the instructions executing out of order.  There are three kinds of data hazards: Read-After-Write (RAW), Write-After-Read (WAR) and Write-After-Write (WAW).  A RAW occurs because an instruction expects a value to have been stored in a storage location (memory or register) by a certain previous write instruction, but the write instruction hasn't been executed yet.  A WAR occurs because an instruction writes over a storage location before another instruction is able to read the previous value.  A WAW occurs because an instruction A writes over the value stored in a storage location by an instruction B, where the value written by instruction B was actually supposed to overwrite the value stored by instruction A (the value stored by B was supposed to survive this encounter, but the one written by A survives instead).

As you can probably see, data hazards occur because one instruction depends on the data of another instruction.  A RAW is considered to be the only "true" data dependency; the others are called "artificial" data dependencies.  I'll try to explain: In a WAR hazard, the write instruction doesn't depend on the value read by the read instruction, and the read instruction doesn't depend on the value written by the write instruction.  However, the read instruction does depend on the value still being there from the previous (in program order) write instruction.  Similarly, in a WAW hazard one write instruction does not depend on the value written by the other, but the following (in program order) instructions do depend on the value from the second write instruction being present, not the value from the first.

Unfortunately it looks like I am out of time for today.  I'll create a second post tomorrow where I will discuss renaming registers.

No comments:

Post a Comment