Page 1 of 1

[Done ]Improve/optimize ProcedureReturn

Posted: Wed Jun 21, 2006 2:07 pm
by Rescator
I know this is not the first time this has been braught up,
but since I was messing with /COMMENTED while teaching myself more asm I noticed this and have some suggestions on improvements as well.

The following code:

Code: Select all

Procedure.l AbsL(value)
 !MOV eax,[p.v_value]
 !CDQ
 !XOR eax,edx
 !SUB eax,edx
ProcedureReturn
EndProcedure
becomes this:

Code: Select all

_Procedure0:
 PS0=4
 p.v_value equ esp+PS0+0
 MOV eax,[p.v_value]
 CDQ
 XOR eax,edx
 SUB eax,edx
 JMP _EndProcedure1
 XOR eax,eax
 _EndProcedure1:
 RET 4
ideally it should be this right?:

Code: Select all

_Procedure0:
 PS0=4
 p.v_value equ esp+PS0+0
 MOV eax,[p.v_value]
 CDQ
 XOR eax,edx
 SUB eax,edx
 RET 4
If this can't easily be done, how about this instead?:

Code: Select all

_Procedure0:
 PS0=4
 p.v_value equ esp+PS0+0
 MOV eax,[p.v_value]
 CDQ
 XOR eax,edx
 SUB eax,edx
 RET 4
 XOR eax,eax
 _EndProcedure1:
 RET 4
since as far as I can tell RET is several cpu cycles less than a JMP.

Oh in case anyone wonders this is a Abs() routine for longs I use.
Obviously it would be ideal to have the above AbsL() asm fully inline like Abs() currently is :)

Posted: Wed Jun 21, 2006 2:23 pm
by thefool
The JMP : 3 cycles
Your RET : 5 cycles

Posted: Wed Jun 21, 2006 2:29 pm
by Rescator
Hmm! (tosses away the old ASM.HLP which has cycles info) oh well.

But please note that in my RET suggestion there is just RET,
while currently there is JMP + RET :)

Posted: Wed Jun 21, 2006 2:34 pm
by thefool
Yeah i noticed the jmp+RET, wich of course is slower than a RET!

Posted: Fri Jun 23, 2006 10:49 am
by Fred
It's on my list, right.