12 performance of pentium iii arithmetic operations

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: ay, as shown in Figure 5.9. We could then write the procedure shown as combine3 in this figure, having no function calls in the inner loop. Rather than making a function call 5.5. REDUCING PROCEDURE CALLS 217 code/opt/vec.c 1 2 3 4 data_t *get_vec_start(vec_ptr v) { return v->data; } code/opt/vec.c code/opt/combine.c 1 2 3 4 5 6 7 8 9 10 11 12 /* Direct access to vector data */ void combine3(vec_ptr v, data_t *dest) { int i; int length = vec_length(v); data_t *data = get_vec_start(v); *dest = IDENT; for (i = 0; i < length; i++) { *dest = *dest OPER data[i]; } } code/opt/combine.c Figure 5.9: Eliminating Function Calls within the Loop. The resulting code runs much faster, at some cost in program modularity. 218 CHAPTER 5. OPTIMIZING PROGRAM PERFORMANCE to retrieve each vector element, it accesses the array directly. A purist might say that this transformation seriously impairs the program modularity. In principle, the user of the vector abstract data type should not even need to know that the vector contents are stored as an arra...
View Full Document

Ask a homework question - tutors are online