Intel® IXP42X product line and IXC1100 control plane processors—Intel XScale® Processor
Intel® IXP42X Product Line of Network Processors and IXC1100 Control Plane Processor
DM September 2006
174 Order Number: 252480-006US
Code generated for the if condition without using an add instruction to set condition
codes is:
However, code can be optimized as follows making use of add instruction to set
condition codes:
The instructions that increment or decrement the loop counter can also be used to
modify the condition codes. This eliminates the need for a subsequent compare
instruction. A conditional branch instruction can then be used to exit or continue with
the next loop iteration.
Consider the following C code segment:
The optimized code generated for the above code segment would look like:
It is also beneficial to rewrite loops whenever possible so as to make the loop exit
conditions check against the value 0. For example, the code generated for the code
segment below will need a compare instruction to check for the loop exit condition.
If the loop were rewritten as follows, the code generated avoids using the compare
instruction to check for the loop exit condition.
if (a + b)
;Assume r0 contains the value a, and r1 contains the value b
add r0,r0,r1
cmp r0, #0
;Assume r0 contains the value a, and r1 contains the value b
adds r0,r0,r1
for (i = 10; i != 0; i--)
{do something;
}
L6:
.
.subs r3, r3, #1
bne .L6
for (i = 0; i < 10; i++)
{do something;
}
for (i = 9; i >= 0; i--)
{do something;
}