Branch Optimizations And Control-Flow Simplification - Texas Instruments TMS320C2x User Manual

Optimizing c compiler digital signal processor
Hide thumbs Also See for TMS320C2x:
Table of Contents

Advertisement

What Kind of Optimization Is Being Performed?
3.8.8

Branch Optimizations and Control-Flow Simplification

Example 3−4. Copy Propagation and Control-Flow Simplification
TMS320C2x/C2xx/C5x C Compiler Output:
_fsm:
*
* AR5 assigned to variable 'input'
*
L2:
L4:
L5:
L6:
EPI0_1:
The switch statement and the state variable from this simple finite state machine example
are optimized completely away, leaving a streamlined series of conditional branches.
3-20
The compiler analyzes the branching behavior of a program and rearranges
the linear sequences of operations (basic blocks) to remove branches or
redundant conditions. Unreachable code is deleted, branches to branches are
bypassed, and conditional branches over unconditional branches are simpli-
fied to a single conditional branch. When the value of a condition can be deter-
mined at compile time (through copy propagation or other data flow analysis),
a conditional branch can be deleted. Switch case lists are analyzed in the
same way as conditional branches and are sometimes eliminated entirely.
Some simple control-flow constructs can be reduced to conditional instruc-
tions, totally eliminating the need for branches. See Example 3−4.
fsm()
{
enum { ALPHA, BETA, GAMMA, OMEGA } state = ALPHA;
int *input;
while (state != OMEGA)
switch (state)
{
case ALPHA: state = ( *input++ == 0 ) ? BETA:
case BETA : state = ( *input++ == 0 ) ? GAMMA: ALPHA; break;
case GAMMA: state = ( *input++ == 0 ) ? GAMMA: OMEGA; break;
}
}
. . .
LAC
*+
; initial state == ALPHA
BNZ
L5
; if (input != 0) go to state GAMMA
LAC
*+
; state == BETA
BZ
L4
; if (input == 0) go to state GAMMA
LAC
*+
; state == ALPHA
BZ
L2
; if (input == 0) go to state BETA
B
L5
; else
LAC
*+
; state == GAMMA
BNZ
EPI0_1
; if (input != 0) go to state OMEGA
LARP
AR5
LAC
*+
; state = GAMMA
BZ
L6
; if (input == 0) go to state GAMMA
; state == OMEGA
. . .
GAMMA; break;
go to state GAMMA

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the TMS320C2x and is the answer not in the manual?

This manual is also suitable for:

Tms320c2xxTms320c5x

Table of Contents