If some branch point leading to this instruction was

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: *xp += v; } int square(int x) { return x*x; } Here are three code fragments that call these functions A. B. C. for (i = min(x, y); i < max(x, y); incr(&i, 1)) t += square(i); for (i = max(x, y) - 1; i >= min(x, y); incr(&i, -1)) t += square(i); int low = min(x, y); int high = max(x, y); for (i = low; i < high; incr(&i, 1)) t += square(i); Assume x equals 10 and y equals 100. Fill in the table below indicating the number of times each of the four functions is called for each of these code fragments. Code A. B. C. min max incr square 5.5 Reducing Procedure Calls As we have seen, procedure calls incur substantial overhead and block most forms of program optimization. We can see in the code for combine2 (Figure 5.6) that get vec element is called on every loop iteration to retrieve the next vector element. This procedure is especially costly since it performs bounds checking. Bounds checking might be a useful feature when dealing with arbitrary array accesses, but a simple analysis of the code for combine2 shows that all references will be valid. Suppose instead that we add a function get vec start to our abstract data type. This function returns the starting address of the data arr...
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