[Done ]Improve/optimize ProcedureReturn

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

[Done ]Improve/optimize ProcedureReturn

Post 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 :)
Last edited by Rescator on Thu Sep 29, 2011 1:15 pm, edited 1 time in total.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

The JMP : 3 cycles
Your RET : 5 cycles
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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 :)
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Yeah i noticed the jmp+RET, wich of course is slower than a RET!
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

It's on my list, right.
Post Reply