In some designs there can be 80 or more instructions

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: igh cycle counts for multiplication are due to an anomaly in our benchmark data. Identifying such anomalies is an important component of performance analysis and optimization. We return to this issue in Section 5.11.1. We will see that we can improve on this performance considerably. 5.4 Eliminating Loop Inefficiencies Observe that procedure combine1, as shown in Figure 5.5, calls function vec_length as the test condition of the for loop. Recall from our discussion of loops that the test condition must be evaluated on every iteration of the loop. On the other hand, the length of the vector does not change as the loop proceeds. We could therefore compute the vector length only once and use this value in our test condition. Figure 5.6 shows a modified version, called combine2, that calls vec length at the beginning and assigns the result to a local variable length. This local variable is then used in the test condition of the for loop. Surprisingly, this small change has a significant effect on program performance. Funct...
View Full Document

Ask a homework question - tutors are online