News:

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

call instead of invoke!

Started by LAS3R, February 12, 2005, 04:57:15 PM

Previous topic - Next topic

Ratch

pbrennick,

Quote'What difference does it make whether you get the answer in picoseconds or nanoseconds as long as the answer is correct, because for all intents and purposes; we cannot tell the difference.'

Those pico's and nano's add up when the load is heavy.  My Windows boots up correctly, but it sure takes a long time to do so.  I sure can tell the difference using MATHCAD between my old slow and new fast machine.  Ratch

MichaelW

Running on my P3, this shows only a few cycles of variation from run to run, and the "horror" code is no faster than the sensible code.

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .586                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    include \masm32\macros\macros.asm
    include timers.asm
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    LOOPCOUNT EQU 5000000

    counter_begin LOOPCOUNT, HIGH_PRIORITY_CLASS
      invoke PostMessage,0,EM_LIMITTEXT,256,0
      invoke PostMessage,0,EM_LIMITTEXT,256,0
      invoke PostMessage,0,EM_LIMITTEXT,256,0
    counter_end
    print ustr$(eax)
    print chr$(" cycles",13,10)

    counter_begin LOOPCOUNT, HIGH_PRIORITY_CLASS
        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET Label_1

        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET PostMessage

        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET PostMessage
        jmp  PostMessage

      Label_1:

    counter_end
    print ustr$(eax)
    print chr$(" cycles",13,10)

    mov   eax,input(13,10,"Press enter to exit...")
    exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


2151 cycles
2152 cycles

eschew obfuscation

Vortex

Hi MichaelW,

After three consecutive tests on my PIV, I got these results:

3244 cycles
3301 cycles

3284 cycles
3382 cycles

3225 cycles
3291 cycles

Grincheux

Ok, You all are right.

I thought that I could win more cycles. I knew that this code would be hard to modify... later.
It was a test.

And if the push were replaced by the "mov ESP+XXX,data". Would this code be quick ?

I have to search an other method.

Thanks for your help. Sincerely

Kenavo
Kenavo

Grincheux
_____________________________________________________
http://www.phrio.biz

MichaelW

In this case, optimizing the instructions that call the API code will make no significant difference because almost all of the execution time (~99.3%) is spent in the API code.

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .586                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\masm32.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    includelib \masm32\lib\masm32.lib
    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    include \masm32\macros\macros.asm
    include timers.asm
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
    .code
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    LOOPCOUNT EQU 5000000

    counter_begin LOOPCOUNT, HIGH_PRIORITY_CLASS
      invoke PostMessage,0,EM_LIMITTEXT,256,0
      invoke PostMessage,0,EM_LIMITTEXT,256,0
      invoke PostMessage,0,EM_LIMITTEXT,256,0
    counter_end
    print ustr$(eax)
    print chr$(" cycles",13,10)

    counter_begin LOOPCOUNT, HIGH_PRIORITY_CLASS
        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET Label_1

        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET PostMessage

        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET PostMessage
        jmp  PostMessage
      Label_1:
    counter_end
    print ustr$(eax)
    print chr$(" cycles",13,10)

    counter_begin LOOPCOUNT, HIGH_PRIORITY_CLASS
        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET Label_1

        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET PostMessage

        push 0
        push 256
        push EM_LIMITTEXT
        push 0
        push OFFSET PostMessage
        ;jmp  PostMessage
        REPEAT 15
          pop   eax
        ENDM
    counter_end
    print ustr$(eax)
    print chr$(" cycles",13,10)

    mov   eax,input(13,10,"Press enter to exit...")
    exit
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


2141 cycles
2144 cycles
30 cycles

eschew obfuscation

rea

But in the case that the majority is my own code, would matter if I use movs instead of pushes???, altought that will require take care of the movement of memory to memory that push can do and mov cant.