Similarly any object of type int or any pointer must

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: ynamic version is somewhat more complex. It must use a multiply instruction to scale by Ò, rather than a series of shifts and adds. In modern processors, this multiplication does not incur a significant performance penalty. In many cases, the compiler can simplify the indexing computations for variable-sized arrays using the same principles as we saw for fixed-size ones. For example, Figure 3.24(a) shows C code to compute element of the product of two variable-sized matrices A and B. In Figure 3.24(b) we show an optimized version derived by reverse engineering the assembly code generated by compiling the original version. The compiler is able to eliminate the integer multiplications i*n and j*n by exploiting the sequential access pattern resulting from the loop structure. In this case, rather than generating a pointer variable Bptr, the compiler creates an integer variable we call nTjPk, for “n Times j Plus k,” since its value equals n*j+k relative to the original code. Initially nTjPk equals k, and it is incremented by n on each iteration. The assembly code for the loop is shown below....
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