If-Then-Else Statements in a Loop
6-88
6.8.3
Drawing a Dependency Graph
Figure 6–17 shows the dependency graph for the if-then-else C code. This
graph illustrates the following arrangement:
-
Two nodes on the graph contain sum: one for the ADD and one for the
SUB. Because some iterations are performing an ADD and others are
performing a SUB, each of these nodes is a possible input to the next itera-
tion of either node.
-
The LDH ai instruction is a parent of both ADD sum and SUB sum, be-
cause both instructions read ai.
-
CMPEQ if is also a parent to ADD sum and SUB sum, because both read
IF for the conditional execution.
-
The result of SHL mask is read on the next iteration by the AND cond
instruction.
Figure 6–17. Dependency Graph of If-Then-Else Code
ADD
cntr
LOOP
1
B
1
CMPEQ
if
sum
1
SUB
!(!(cond))
1
MVK
A side
B side
ADD
1
1
1
LDH
ai
5
5
mask
1
1
sum
1
1
SHL
cond
1
AND
1