![Intel IXP45X Developer'S Manual Download Page 196](http://html1.mh-extra.com/html/intel/ixp45x/ixp45x_developers-manual_2073092196.webp)
Intel
®
IXP45X and Intel
®
IXP46X Product Line of Network Processors—Intel XScale
®
Processor
Intel
®
IXP45X and Intel
®
IXP46X Product Line of Network Processors
Developer’s Manual
August 2006
196
Order Number: 306262-004US
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.
3.10.3.1.2
Optimizing Branches
Branches decrease application performance by indirectly causing pipeline stalls. Branch
prediction improves the performance by lessening the delay inherent in fetching a new
instruction stream. The number of branches that can accurately be predicted is limited
by the size of the branch target buffer. Since the total number of branches executed in
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;
}