In fact running measurements on this operation we nd

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: ance. 240 combine4: type=INT, OPER = ’+’ CHAPTER 5. OPTIMIZING PROGRAM PERFORMANCE data in %eax, x in %ecx, i in %edx, length in %esi 1 2 3 4 5 .L24: addl (%eax,%edx,4),%ecx incl %edx cmpl %esi,%edx jl .L24 loop: Add data[i] to x i++ Compare i:length If <, goto loop (a) Array code combine4p: type=INT, OPER = ’+’ data in %eax, x in %ecx, dend in %edx 1 2 3 4 5 .L30: addl (%eax),%ecx addl $4,%eax cmpl %edx,%eax jb .L30 loop: Add data[0] to x data++ Compare data:dend If <, goto loop (b) Pointer code Figure 5.23: Pointer Code Performance Anomaly. Although the two programs are very similar in structure, the array code requires two cycles per iteration, while the pointer code requires three. 1 2 3 4 5 6 7 8 9 10 11 12 13 .L6: addl (%eax),%edx addl 4(%eax),%edx addl 8(%eax),%edx addl 12(%eax),%edx addl 16(%eax),%edx addl 20(%eax),%edx addl 24(%eax),%edx addl 28(%eax),%edx addl $32,%eax addl $8,%ecx cmpl %esi,%ecx jl .L6 Observe how register %eax is being incremented by 32 on each iteration. Write C code for a procedure combine5px8 that shows how pointers, loop variables, and termination conditions are being computed by this code. Show the general form with arbitrary data and combining operation in the style of Figure 5.19. Describe how it differs from our handwritten point...
View Full Document

Ask a homework question - tutors are online