Programming Itanium-based Systems: Developing High Performance Applications for Intel's New Architecture

Code Experimentation

It is not always obvious when a small rearrangement of source code might make a significant difference in execution speed. Subtle changes in the order of evaluation of expressions can sometimes tip the balance. As an example, consider the C code and associated assembly language inner loop shown in Figure 11.16. The function is a straightforward null-terminated string comparison with a controlling while condition that evaluates two simple expressions joined by a logical AND operator. Starting at the top of the assembly language loop, the value of *p is loaded nonspeculatively, and three instructions later the value of *q is loaded speculatively. The compiler is respecting the fact that the expression (*p == *q) might not need to be evaluated if the expression (*p != 0) is false. It therefore makes the load off the q pointer speculative, just in case it is not found to be necessary. The resulting loop takes a minimum of four cycles per string character comparison to execute, as evidenced by counting the double-colon stops in the assembly language code. Not bad, but perhaps it is possible to do better.

<a name="666"></a><a name="beginpage.5FAB51E7-CB11-4924-8D39-186F3F673641"></a>intstrcmp(unsigned char *p, unsigned char *q){    while ((*p != 0) && (*p == *q)) {        p++;        q++;    }    if (*p > *q)        return 1;    if...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Vacuum Pumps and Vacuum Generators
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.