Optimizing program performance codeoptlowerc 1 2 3 4

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ; /* Triple value at xp */ The result will be that the value at xp will be increased by a factor of 3. The compiler knows nothing about how twiddle1 will be called, and so it must assume that arguments xp and yp can be equal. Therefore it cannot generate code in the style of twiddle2 as an optimized version of twiddle1. This phenomenon is known as memory aliasing. The compiler must assume that different pointers may designate a single place in memory. This leads to one of the major optimization blockers, aspects of programs that can severely limit the opportunities for a compiler to generate optimized code. Practice Problem 5.1: The following problem illustrates the way memory aliasing can cause unexpected program behavior. Consider the following procedure to swap two values: 1 /* Swap value x at xp with value y at yp */ 206 2 3 4 5 6 7 CHAPTER 5. OPTIMIZING PROGRAM PERFORMANCE void swap(int { *xp = *xp *yp = *xp *xp = *xp } *xp, int *yp) + *yp; /* x+y */ - *yp; /* x+y-y = x */ - *yp; /* x...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online