News:

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

Main Menu

Optimizing code & codings

Started by Grincheux, December 24, 2015, 06:45:19 AM

Previous topic - Next topic

Grincheux

I search for tips that would improve the generated opcodes, the lines of codes and the timings.
We know :
Quote
lea for multiply
shr / shl for dividing / multipltying
mul for in some case replace a div
and for dividing
Replace 2 concecutive calls by 1 jump
In 64 bits the stack can be a friend when a call follows an other call

Is there others tips you know.
I know the way I am coding is strange, I know don't tell it once again.

We can't do :

Quote
push EAX ; It is not the result of LSTRCPY
push OFFSET @F
push OFFSET szSrc
push OFFSET szDst
push OFFSET DoSomething
call lstrcpy

@@ :

But in some case pushing arguments onto the stack (without INVOKE) permits to make an other call. The result of this call is then pushed onto the stack as a parameter of the final call

push  dwSomething
push OFFSET szString
call lstrlen
push EAX
push dwOtherParam
call MyFunction

In fact MyFunction is defined as

MyFunction PROTO :DWord,:DWord,:DWord

PUSH dwSomething is the THIRD parameter
PUSH EAX is the SECOND parameter
PUSH dwOtherParam is the first parameter

Between the third and the second push I have called lstrlen to compute a result

If you have other ideas, think to me.


PS : Hutch why do I have to edit every post twice before it is correct?

jj2007

There are many little tricks to optimise code, but make sure to comment them well, because often readability suffers from such obscure tricks. Or use colour, if your editor allows it:

   invoke LoadLibrary, chr$("somelib.dll")
   .if eax
      push eax
      invoke GetProcAddress, eax, chr$("somefunction")
      ... do useful things with "somefunction"
      call FreeLibrary  ; invoke FreeLibrary, eax
   .endif

Grincheux

Idem with BeginPaint and EndPaint
Using shr/shl for other operations than x ou / but I have no idea.