Lukas' Notes

computer-architecture

Definition

Read-after-Write Dependency

A read-after-write (RAW) dependency (also true dependency) is a data hazard in which an instruction reads a register that a preceding instruction writes.

If enters the execute stage before has completed write-back, reads a stale value. This is a true dependency: genuinely requires the value that produces.

Unlike WAR and WAW dependencies, a RAW dependency cannot be eliminated by register renaming — the data flow between and is real. In out-of-order execution, must wait in the issue buffer until produces its result.

Examples

XOR / ADD Chain

XOR a1, a2, a4    # writes a1
ADD a3, a1, t1    # reads a1

ADD requires the result of XOR. If the pipeline proceeds without a stall or forwarding, ADD reads the old value of a1.

Vector Addition Loop

Consider a loop body that computes :

LW  t1, 0(a0)     # writes t1
LW  t2, 0(a1)     # writes t2
ADD t1, t1, t2    # reads t1, t2; writes t1
SW  t1, 0(a2)     # reads t1
ADDI a0, a0, 4
ADDI a1, a1, 4
ADDI a2, a2, 4
ADDI t0, t0, 1    # writes t0
BLTU t0, t3, vec_add_for  # reads t0, t3

Four RAW dependencies exist:

WriteReadRegister
LW t1, 0(a0)ADD t1, t1, t2t1
LW t2, 0(a1)ADD t1, t1, t2t2
ADD t1, t1, t2SW t1, 0(a2)t1
ADDI t0, t0, 1BLTU t0, t3, vec_add_fort0

Multi-Cycle Functional Unit

When a load is followed by an arithmetic instruction that uses the loaded value:

LW   t1, 0(a3)     # memory access takes multiple cycles
ADDI t1, t1, 4     # needs t1

The load completes its memory access in a later cycle than a single-cycle ALU operation. ADDI must stall in the decode stage until the load writes back, unless forwarding from the memory stage is available.

With a multi-cycle divider (e.g. 64 cycles in the CVA6 processor), a dependent instruction may be blocked in the issue buffer for dozens of cycles.