Pipelining 375
the boundary conditions vary, imposing dif culties for smooth and continuous execution of different
cycles of various instructions available within the pipeline. The reason behind these obstructions may
be different but their result is the same, i.e., an instruction’s execution is not complete within the pre-
de ned time. In general, these reasons maybe one of the following three types:
R Data hazard
R Instruction hazard or control hazard
R Structural hazard .
Data hazard occurs due to non-availability of some data on-time. In general, it is a result of data depen-
dency. Instruction hazard (also known as control hazard ) is because of non-availability of the instruction
on-time. The reason for structural hazard is the non-availability of some hardware resource necessary for
two or more instructions. We shall now discuss these individual cases in the following sections.
12.4 DATA HAZARDS
In pipeline architecture, data hazards are, generally, encountered whenever the necessary data for pro-
cessing is not available at the stipulated time. The reason may be a data dependency or an I/O wait or
something else. In this section, we discuss the rst two.
12.4.1 Data Dependency
In most of the cases, data hazards occur whenever there is a case of data dependency. What is meant by
data dependency? It means the result of some arithmetic or logical operation is the operand of the next
instruction. As an example, we may consider the following two instructions to be executed in the same
sequence as they appear in the text.
Instruction 1: X ← X+3 [Replace X by X+3]
Instruction 2: Y ← Y+X [Replace Y by adding Y with X]
If the present value of X is 1 and Y is 7 before execution of the rst instruction, then after execution
of the rst followed by second instruction, X would be 4 and Y would be 11. However, in a 5-stage pipe-
line (Figure 12.4 ), the execution of rst instruction and operand fetch of the second instruction would
be performed concurrently by the processor. Therefore, at the time of execution of the second instruc-
tion X would be taken as 1 and not 4, resulting in an incorrect value of Y as 8. This simple example
illustrates one very important fact that whenever there is a data dependency, the related instructions
must be executed in proper sequence and the operand fetch must wait till the availability of the correct
result from the previous instruction . Therefore, in pipeline architecture, data hazards means waiting time
of the processor for the availability of correct data (generally, as a result of some previous operation)
to be used as operand(s) for the ongoing instruction’s execution. To come out from this hazard, either
software or hardware method may be adopted.
12.4.2 Solution by Software Method
In the software method, one or two NOP instructions (no-operation) are inserted by the compiler after
those critical instructions, whose results would be used by the following instruction. In our example
case, described above, this would result in a structure of
M12_GHOS1557_01_SE_C12.indd 375M12_GHOS1557_01_SE_C12.indd 375 4/29/11 5:24 PM4/29/11 5:24 PM