
5-22
SC100 C Compiler
Optimization Techniques and Hints
5.3.3.1.2 Avoiding pipeline restrictions
Certain instructions, for example, a move to an Rn register, are subject to pipeline restrictions. The effect
of these instructions may not be implemented until two or more cycles after the instruction executes. In
such cases, an operation which is dependent on the result of such an instruction, and which follows it
immediately, must wait until the result is available.
The instruction scheduling optimization rearranges the sequence of such instructions where possible, using
the cycle(s) which would otherwise be wasted to implement one or more operations that are not dependent
on the restricted instruction.
In Example 5-23, the
clr
instruction has been rescheduled, since it can execute before the effect of the
move.l
instruction is implemented, whereas the
move.w
instruction must wait for the results of the
move.l
operation.
5.3.3.2 Low-level software pipelining
Software pipelining provides a further level of loop optimization, in addition to the high-level
optimizations which operate on loops.
The software pipelining optimization attempts to rearrange the sequence of instructions inside a loop, in
order to minimize dependencies between such instructions, and thus increase the level of parallelization.
For example, a segment of code may consist of three instructions, A, B and C, within a loop which iterates
4 times. In some cases, the code may be reorganized into a different sequence without affecting its result,
for example:
1.
Instruction A
2.
Instructions B, C, A, in a loop which iterates 3 times
3.
Instruction B
4.
Instruction C
The revised arrangement of the instructions results in fewer dependencies than in the original code.
This optimization is applied only to innermost loops of small or moderate size, which contain no branches
or function calls within the loop. It is most effective when applied to loops that execute a large number of
times.
Each iteration of a software pipelined loop may contain instructions from a different iteration of the
original loop.
Software pipelining increases code size in almost all circumstances. When optimization for size is
specified, software pipelining is suppressed entirely. See
Section 5.3.4,
“
Time Optimizations,
”
for further
details.
Example 5-23. Avoiding pipeline restrictions
Before optimization
After optimization
move.l d0,(r0)
nop
move.w (r0),dl
clr
d0
move.l d0,(r0)
clr
d0
move.w (r0),dl