Software Optimization Guide for AMD64 Processors

25112 Rev. 3.06 September 2005

Because the odds that the animal name begins with a ‘y’ are comparatively low, it is better to put that operand first:

if ((*p == 'y') && (strlen(p) > 4)) { ... }

Example 2

In the following code (assuming a uniform random distribution of i), the operands of are not arranged for quick expression evaluation because the first operand is not the condition most likely to be true:

unsigned int i;

if ((i < 4) (i & 1)) { ... }

Because it is more likely for the least-significant bit of i to be 1, it is better to put that operand first:

if ((i & 1) (i < 4)) { ... }

18

C and C++ Source-Level Optimizations

Chapter 2

Page 34
Image 34
AMD 250 manual If *p == y && strlenp