Intel IXP42X Personal Computer User Manual


 
Intel
®
IXP42X Product Line of Network Processors and IXC1100 Control Plane Processor
September 2006 DM
Order Number: 252480-006US 177
Intel XScale
®
Processor—Intel
®
IXP42X product line and IXC1100 control plane processors
If we make the assumptions that both paths are equally likely to be taken and that
branches are mis-predicted 50% of the time, the costs of using conditional execution
Vs using branches can be computed as follows:
Cost of using conditional instructions:
Cost of using branches:
As can be seen, we get better performance by using branch instructions in the above
scenario.
3.10.3.1.3 Optimizing Complex Expressions
Conditional instructions should also be used to improve the code generated for complex
expressions such as the C shortcut evaluation feature. Consider the following C code
segment:
The optimized code for the if condition is:
Similarly, the code generated for the following C segment
is:
The use of conditional instructions in the above fashion improves performance by
minimizing the number of branches, thereby minimizing the penalties caused by branch
incorrect predictions. This approach also reduces the utilization of branch prediction
resources.
1
50
100
---------
10×
⎝⎠
⎛⎞
50
100
---------
10×
⎝⎠
⎛⎞
++ 11= cycles
1
50
100
---------
7×
⎝⎠
⎛⎞
50
100
---------
6×
⎝⎠
⎛⎞
50
100
---------
4×
⎝⎠
⎛⎞
+++ 9.5= cycles
int foo(int a, int b)
{
if (a != 0 && b != 0)
return 0;
else
return 1;
}
cmp r0, #0
cmpne r1, #0
int foo(int a, int b)
{
if (a != 0 || b != 0)
return 0;
else
return 1;
}
cmp r0, #0
cmpeq r1, #0