News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Which is quickest?

Started by Strobe Raver, August 12, 2009, 01:22:36 AM

Previous topic - Next topic

Strobe Raver



sinsi

Raspberry-Lemonade
Artificially flavored


hah!
Light travels faster than sound, that's why some people seem bright until you hear them.

Neil


sinsi

Isn't xchg eax,eax the exact same microcode for nop?
Light travels faster than sound, that's why some people seem bright until you hear them.

Slugsnack

it is indeed. regardless i think he wants to move/copy register contents as opposed to swap their values

sinsi

depends on the registers, the cpu mode, the cpu, the phase of the moon...
Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

with newer architectures, push/pop is often the best choice
push/pop reg32 's are single-byte instructions
that means they consume less cache space - more code fits in the cache

Astro

push x - 5 bytes
pop y - 5 bytes

10 bytes total.


mov reg,x - 5 bytes (4 bytes data, 1 byte op-code with dest encoded into op-code)
mov y,reg - 5 bytes

10 bytes total.

I think that is correct.

According to the Intel manual (Vol. 2. PDF Page 442):

QuoteA1 - MOV EAX,moffs32* Move doubleword at (seg:offset) to EAX
So A1 means MOVe to EAX in a single byte.

In terms of actual speed - great question. Even if you used more clock cycles in the mov, would the speed difference between register access vs. a memory access be quicker overall?

Best regards,
Astro.

redskull

If you run it on an OoO processor, the mov's should be faster overall.  All other things being equal, a PUSH/POP pair generates 6 uops, whereas the MOV only generates 3 (you take the extra hit for doing the stack pointer math).  Plus, since I believe they use different ports, the two MOV commands should be able to go through at the same time, assuming both values are in the cache.  The PUSH/POP use the same ones, so it would have to do them sequentially.  I'm not too sure about that, so don't quote me, I have to go look that up when I get a moment.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

Damos

I did loads of speed test on pushes and pops and found them to be slow, I posted the results here at the time.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction. - Albert Einstien