News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to optimize execution speed

Started by kcvinu, June 09, 2024, 07:59:47 AM

Previous topic - Next topic

zedd151

Quote from: NoCforMe on June 09, 2024, 11:59:08 AMOh, come on: you can't be serious.
A simple comparison isn't going to take any time at all.
While I cannot speak for every .dll ever written, all of my qEditor plugins use

mov eax, TRUE ; analogous to 'mov rax, TRUE' here...
ret

With no detrimental effects. Saves a couple bytes though.
So I thought it was worth a try, as he is trying to speed up the .dll loading time.
Ventanas diez es el mejor.  :azn:

kcvinu

@NoCforMe

QuoteYou might want to set it to zero in that case. (Remember, you're going to return something no matter what, meaning whatever is in RAX.)

Got the point.

kcvinu

It's my bed time here. See you all later. Thanks for help. I hope we can find the issue. Goodnight to all.

NoCforMe

Quote from: sudoku on June 09, 2024, 12:06:36 PM
Quote from: NoCforMe on June 09, 2024, 11:59:08 AMOh, come on: you can't be serious.
A simple comparison isn't going to take any time at all.
While I cannot speak for every .dll ever written, all of my qEditor plugins use

mov eax, TRUE ; analogous to 'mov rax, TRUE' here...
ret

With no detrimental effects. Saves a couple bytes though.
No, that's fine, the assumption here being that the only "reason" you really care about in LibMain() is DLL_PROCESS_ATTACH, which requires a return value of TRUE in order for the DLL to load. So no problem there.

What I was objecting to was the idea that eliminating the check for the value of "reason" would make any discernible improvement in execution speed. It won't. As an old programming teacher of mine would put it, it's "in the noise". In other words, of no consequence.
Assembly language programming should be fun. That's why I do it.

TimoVJL

DLL_PROCESS_ATTACH gives oppornity to save dll's HINSTANCE and return TRUE
In other occasions return value isn't used.

DllMain entry point

Dynamic-Link Library Entry-Point Function

If you return FALSE from DLL_PROCESS_ATTACH, will you get a DLL_PROCESS_DETACH?

For data / recource only dll:
/NOENTRY (No Entry Point)
May the source be with you

Vortex

Hi kcvinu,

You would like to specify relative paths as the Masm32\64 setup can be on different root partitions :

Instead of this :

include C:\masm64\include64\masm64rt.inc
this one is preferable :

include \masm64\include64\masm64rt.inc

kcvinu

@TimoVJL,
Thanks for the links. Let me check that.
QuoteDLL_PROCESS_ATTACH gives oppornity to save dll's HINSTANCE and return TRUE
That's a nice idea, I can avoid the GetModuleHandle call.

kcvinu

@Vortex,
Is it ? Thanks, let me try. But one problem. I have installed VS2022. So When I type ml64 in cmd, it starts the ml64.exe from VS's tools directory.

NoCforMe

;====================================
; DLL main entry point proc
;====================================

DLLmain PROC hInstDLL:HINSTANCE, reason:DWORD, reserved:DWORD
; Store instance handle where we can get at it:
MOV EAX, hInstDLL
MOV InstanceHandle, EAX
MOV EAX, TRUE
RET

DLLmain ENDP

Since the instance handle is one of the parameters to that function, might as well use it.
Assembly language programming should be fun. That's why I do it.

kcvinu

Oh, but I was used this.
LibMain proc instance:QWORD,reason:QWORD,unused:QWORD
    .if reason == DLL_PROCESS_ATTACH
mov hInstance, rcx
mov rax, TRUE                         
.endif
ret
LibMain endp

TimoVJL

Quote from: kcvinu on June 10, 2024, 05:10:48 AMOh, but I was used this.
LibMain proc instance:QWORD,reason:QWORD,unused:QWORD
    .if reason == DLL_PROCESS_ATTACH
        mov hInstance, rcx
        mov rax, TRUE                       
    .endif
    ret
LibMain endp
normal way to handle it, but mov rax, TRUE can be after .endif

May the source be with you

NoCforMe

Quote from: kcvinu on June 10, 2024, 05:10:48 AMOh, but I was used this.
LibMain proc instance:QWORD,reason:QWORD,unused:QWORD
    .if reason == DLL_PROCESS_ATTACH
        mov hInstance, rcx
        mov rax, TRUE                       
    .endif
    ret
LibMain endp
Yeah, that's probably safer.
Though my code works fine for me, since by the time any "reason" other than DLL_PROCESS_ATTACH is called, the instance handle has been safely stored and isn't used again. But this way is better.

But move the mov rax, TRUE to after the .endif as Timo suggested.
Assembly language programming should be fun. That's why I do it.

Vortex

Hi kcvinu,

You can copy ml64.exe to the \masm64\bin64 folder and use a batch file to build your project :

\masm64\bin64\ml64 /c Source.asm
\masm64\bin64\polink /SUBSYSTEM:WINDOWS /LARGEADDRESSAWARE /ENTRY:start Source.obj

kcvinu

@NoCforMe,
QuoteBut move the mov rax, TRUE to after the .endif as Timo suggested.

Okay.

@Vortex
QuoteYou can copy ml64.exe to the \masm64\bin64 folder and use a batch file to build your project :
Yeah, but I am using cmder. We can use aliases in cmder or even make a Task. Tasks are more like batch files. But most of the time, I like to use aliases. Since we can club the two commands with "&&" operator, we can easily make our alias for this. Since commands contains absolute paths, we can run this aliases from any where. We don't need "CD" to go to project dir, or neither need to start the cmd window from project folder. 

NoCforMe

Assembly language programming should be fun. That's why I do it.