Data Forwarding

If a result in the DLX is used two instructions after it is generated, we need to fetch it from the registers on the same cycle that it is written to the registers. We haven't specified yet what happens in this case; it is easy to build a register set that will return the value being written. So there is no hazard in this case.

A harder case arises when we want to use the data in the instruction immediately following the instruction in which it is generated. In this case, we need to route the data directly from the ALU output to the appropriate ALU input. This is called forwarding, since the data is forwarded from one instruction to the other. CDC called the same technique bypassing, as you are bypassing the registers. The best way to try to describe the forwarding that's necessary is in the form of a table, as on page 160. Each row of the table expresses a condition in which forwarding is necessary.

Compiler Scheduling

The compiler can also schedule instructions to avoid data hazards, and thus stalls. Remember that with the MIPS, it was necessary to avoid using a register on the instruction after it was loaded. In the DLX you can use it, but it will slow the program down. An optimizing compiler can anticipate this situation, and schedule the instructions so that the data is not used on the instruction following the load.

I've commented before on the danger of tying your instruction set to your pipeline. This has much the same feeling, but without the danger: code that's optimized for a 486 won't run as well on a Pentium as Pentium-optimized code, but it will run correctly.