Intel Processor Computer Hardware User Manual


 
Developers Manual March, 2003 B-9
Intel
®
80200 Processor based on Intel
®
XScale
Microarchitecture
Optimization Guide
B.3 Basic Optimizations
This chapter outlines optimizations specific to ARM architecture. These optimizations have been
modified to suit the Intel
®
80200 processor architecture where needed.
B.3.1 Conditional Instructions
The Intel
®
80200 processor architecture provides the ability to execute instructions conditionally.
This feature combined with the ability of the Intel
®
80200 processor instructions to modify the
condition codes makes possible a wide array of optimizations.
B.3.1.1. Optimizing Condition Checks
Intel
®
80200 processor instructions can selectively modify condition codes state. When generating
code for if-else and loop conditions, it is often beneficial to make use of this feature to set condition
codes, thereby eliminating need for a subsequent compare instruction. Consider C code segment:
if (a + b)
Code generated for the if condition without using an add instruction to set condition codes is:
;Assume r0 contains the value a, and r1 contains the value b
add r0,r0,r1
cmp r0, #0
However, the code can be optimized as follows making use of the add instruction to set the
condition codes:
;Assume r0 contains the value a, and r1 contains the value b
adds r0,r0,r1
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:
for (i = 10; i != 0; i--)
{
do something;
}
The optimized code generated for the above code segment would look like:
L6:
.
.
subs r3, r3, #1
bne .L6
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 needs a compare
instruction to check for the loop exit condition.
for (i = 0; i < 10; i++)
{
do something;
}
If the loop were rewritten as follows, the code generated avoids using the compare instruction to
check for the loop exit condition.
for (i = 9; i >= 0; i--)
{
do something;
}