Optimization Types and Functions
SC100 C Compiler
5-21
5.3.3.1 Instruction scheduling
The main purpose of this optimization is to execute as many instructions as possible from the same
instruction stream in the same cycle. The amount of dependency between the instructions limits the extent
to which this can be achieved.
The instruction scheduling optimization organizes instructions into execution sets wherever it is possible to
do so, making best use of the Data Arithmetic Units and Address Generation Units provided by the SC100
architecture.
Example 5-21 illustrates the use of instruction scheduling:
Instruction scheduling serves two further purposes:
Filling delay slots when branch instructions are executed, as described below
Rescheduling operations that are not dependent on pipeline restricted instructions, as described in
Section 5.3.3.1.2,
“
Avoiding pipeline restrictions,
”
on page 5-22
5.3.3.1.1 Filling delay slots
A branch instruction requires three cycles to execute if the branch is taken. When a branch executes, the
prefetch queue is lost, and the cycles used for the other instructions are wasted, since they cannot execute
until the branch instruction has completed. The wasted cycles are termed
delay slots
.
The instruction scheduling optimization checks whether other operations can be executed at the same time
as the branch instruction. This is not possible if there are limiting factors, for example:
The branch instruction is directly affected by the instructions which precede it.
There are specific dependencies between the branch and the other instructions.
If there are no limiting factors, the scheduler rearranges the code, in order to use the delay slots efficiently.
In the following example, the code has been reorganized to enable three instructions to execute during the
time that the branch requires to complete its operation.
Example 5-21. Instruction scheduling
Before optimization
After optimization
move.l d0,(r0)
inc
d0
tfra r3,r0
adda #12,r3
move (r1)+,d1
move.l d0,(r0)
tfra r3,r0
adda #12,r3
inc
move
d0
(r1)+,d1
Example 5-22. Filling delay slots
Before optimization
After optimization
move.l d0,(r0)
inc
d0
tfr
d5,d2
rts
rtsd
move.l
d0,(r0)
inc
d0
tfr d5,d2