News:

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

Quick Speed Question

Started by RedXVII, February 25, 2006, 03:28:02 PM

Previous topic - Next topic

RedXVII

I keep coming across other peoples code with this in it;

push var1
pop var2


Is this faster/better than;

mov eax, var1
mov var2, eax


I know push/pop means you wouldnt have modify the eax value, but i see push/pop it alot when it really doesnt matter.
Just curious  :bg

BogdanOntanu

You are right;)

1)  push /pop is slower but it does not touch or make dirty a register... compiler have a tendecy to use this but there is an MASM macro that does the same
2) mov reg, var1 and then mov var2,reg is faster but it does need an empty register. ...

There are no special meanings hidden beneath ;)

Compiler do strange things at times because they are forced to work with a fixed set of rules and have no real knowledege about the algorithic side.
But then again hummans get lazy much easyer ;)


Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

MichaelW

Running this:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
    .586
    include timers.asm
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      var1 dd 0
      var2 dd 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    LOOP_COUNT EQU 1000000
    REPEAT_COUNT EQU 100

    REPEAT 4

      counter_begin LOOP_COUNT,HIGH_PRIORITY_CLASS
        REPEAT REPEAT_COUNT
          xor   edx, edx    ; Arbitrary separator
          push  var1
          pop   var2
          add   edx, 1      ; Arbitrary separator
        ENDM
      counter_end
      print ustr$(eax)," cycles",13,10

      counter_begin LOOP_COUNT,HIGH_PRIORITY_CLASS
        REPEAT REPEAT_COUNT
          xor   edx, edx    ; Arbitrary separator
          mov   eax, var1
          mov   var2, eax
          add   edx, 1      ; Arbitrary separator
        ENDM
      counter_end
      print ustr$(eax)," cycles",13,10

    ENDM
   
    inkey "Press any key to exit..."
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


On a P3 I get these results:

532 cycles
197 cycles
532 cycles
197 cycles
532 cycles
197 cycles
532 cycles
197 cycles


So on a P3 push/pop is much slower. Without the separator instructions I get:

399 cycles
196 cycles
398 cycles
196 cycles
398 cycles
196 cycles
398 cycles
196 cycles


I think indicating that push/pop do not combine well with other instructions.



[attachment deleted by admin]
eschew obfuscation

EduardoS

I got the same results both with separators and without on an Athlon 64:

398 cycles
196 cycles
398 cycles
196 cycles
398 cycles
196 cycles
398 cycles
196 cycles
Press any key to exit...