1. Explain the data dependences and hazards in
detail with examples. (16)
Various
types of Dependences in ILP. Data Dependence and Hazards:
To
exploit instruction-level parallelism, determine which instructions can be
executed in parallel. If two instructions are parallel, they can execute
simultaneously in a pipeline without causing any stalls. If two instructions
are dependent they are not parallel and must be executed in order.
There
are three different types of dependences: data dependences (also called true
data dependences), name dependences, and control dependences.
Data
Dependences:
An
instruction j is data dependent on instruction i if either of the following
holds:
•
Instruction i produces a result that may be used by instruction j, or
•
Instruction j is data dependent on instruction k, and instruction k is data
dependent on instruction i.
The
second condition simply states that one instruction is dependent on another if
there exists a chain of dependences of the first type between the two
instructions. This dependence chain can be as long as the entire program.
The
importance of the data dependences is that a dependence
(1)
indicates the possibility of a hazard,
(2)
Determines the order in which results must be calculated, and
(3)
Sets an upper bound on how much parallelism can possibly be exploited.
Name
Dependences
The
name dependence occurs when two instructions use the same register or memory
location, called a name, but there is no flow of data between the instructions
associated with that name.
There
are two types of name dependences between an instruction i that precedes
instruction j in program order:
•
An antidependence between instruction i and instruction j occurs when
instruction j writes a register or memory location that instruction i reads.
The original ordering must be preserved to ensure that i reads the correct
value.
•
An output dependence occurs when instruction i and instruction j write the same
register or memory location. The ordering between the instructions must be
preserved to ensure that the value finally written corresponds to instruction
j.
Both
anti-dependences and output dependences are name dependences, as opposed to
true data dependences, since there is no value being transmitted between the
instructions. Since a name dependence is not a true dependence, instructions
involved in a name dependence can execute simultaneously or be reordered, if
the name (register number or memory location) used in the instructions is
changed so the instructions do not conflict.
Control
Dependences:
A
control dependence determines the ordering of an instruction, i, with respect
to a branch instruction so that the instruction i is executed in correct
program order. Every instruction, except for those in the first basic block of
the program, is control dependent on some set of branches, and, in general,
these control dependences must be preserved to preserve program order. One of
the simplest examples of a control dependence is the dependence of the
statements in the “then” part of an if statement on the branch. For example, in
the co de segment:
if
p1 { S1;
};
if
p2
{ S2;
}
S1
is control dependent on p1, and S2is control dependent on p2 but not on p1. In
general, there are two constraints imposed by control dependences:
1.
An instruction that is control dependent on a branch cannot be moved before the
branch so that its execution is no longer controlled by the branch. For
example, we cannot take an instruction from the then-portion of an if-statement
and move it before the if- statement.
2.
An instruction that is not control dependent on a branch cannot be moved after
the branch so that its execution is controlled by the branch. For example, we
cannot take a statement before the if-statement and move it into the
then-portion.
No comments:
Post a Comment