The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Posit on May 14, 2005, 04:54:16 AM

Title: Should Pushes and Pops be Staggered or Consecutive
Post by: Posit on May 14, 2005, 04:54:16 AM
Is there any performance reason to place other instructions between push and pop instructions when possible or, conversely, to keep pushes and pops consecutive when possible?
Title: Re: Should Pushes and Pops be Staggered or Consecutive
Post by: Posit on May 14, 2005, 05:02:07 AM
Oh, and as an aside, does anyone have any recommendation on The Software Optimization Cookbook that Intel publishes?  Looking at its table of contents, it seems to push the Vtune optimizer, but I'm wondering if it contains anything that cannot be gleaned from the free Intel docs or other online sources.
Title: Re: Should Pushes and Pops be Staggered or Consecutive
Post by: AeroASM on May 14, 2005, 06:27:26 AM
Try to pair up unrelated instructions. For example, if on one line you access memory, do a register-only operation on the next line involving different registers.
Title: Re: Should Pushes and Pops be Staggered or Consecutive
Post by: Posit on May 14, 2005, 11:03:35 AM
So for instance

     xor al,al
     pop edi
     pop esi

would be better as

     pop edi
     xor al,al
     pop esi
Title: Re: Should Pushes and Pops be Staggered or Consecutive
Post by: hutch-- on May 14, 2005, 11:26:25 AM
Posit,

The only real way to find out is to write a test piece. I suggest that it does not make much difference and when you can find another way using MOV its faster than PUSH/POP.
Title: Re: Should Pushes and Pops be Staggered or Consecutive
Post by: Posit on May 14, 2005, 08:10:16 PM
Is doing something like this a faster replacement for a push:

     mov [esp-4],esi

It seems like the subtraction in the address calculation would outweigh the increase speed of the mov instruction.