We also present a general principle of system

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: result cmovll %edx,%eax 252 CHAPTER 5. OPTIMIZING PROGRAM PERFORMANCE As this code shows, the strategy is to set val as a return value, compute -val, and conditionally move it to register %eax to change the return value when val is negative. Our measurements of this code shows that it runs for 13.7 cycles regardless of the data patterns. This clearly yields better overall performance than a procedure that requires between 13 and 27 cycles. Practice Problem 5.5: A friend of yours has written an optimizing compiler that makes use of conditional move instructions. You try compiling the following C code: 1 2 3 4 5 /* Dereference pointer or return 0 if null */ int deref(int *xp) { return xp ? *xp : 0; } The compiler generates the following code for the body of the procedure. 1 2 3 4 movl 8(%ebp),%edx movl (%edx),%eax testl %edx,%edx cmovll %edx,%eax Get xp Get *xp as result Test xp If 0, copy 0 to result Explain why this code does not provide a valid implementation of deref The current version of GCC does not generate any code using conditional moves. Due t...
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