Page 1 of 4

Just another Purebasic Optimizer - New release - JaPBo v1.14

Posted: Sun Oct 02, 2005 4:44 pm
by va!n
Deeem2031 strikes back with another great release :D And yes, you can use remi_meier“s optimizer with this tool too.
For more infos just follow this thread ot take a look to the german forum: http://forums.purebasic.com/german/view ... 6423#56423 :D

Download at: http://www.deeem2031.de/PB/D_Optimizer.zip


Update v1.14
-You can also set "Optimize_CMPNullString" to 0 if you dont want to download the new version


Features of v1.13:
(for procedures)
- delete unnecessary push/pops of procedure calls
- the ClearLoop will be replaced by a faster routinet
- Ecx will be deleted everytime from stack
- When possible, Esi will be replaced by using Esp
- when having a ProcedureReturn at the end of a procedure, undo (putting back) of the result will be deleted

(others)
- For-Next Loops will be multiplies if possible (the code will go larger, however it runs a little bit faster)
- replacing of SYS_StringEqual with null strings by direct processing

Installations-Guide:
- without remis Optimizer:
-> rename "...\Purebasic\Compilers\Fasm.exe" to "Fasm2.exe"
-> Unpack the zip content to "...\Purebasic\Compilers\"-folder
-> be happy ;-)

- with remis Optimizer:
-> rename "...\Purebasic\Compilers\Fasm.exe" to "Remis_Optimierer.exe" (you can use any other name for the exe too)
-> Unpack the zip content to "...\Purebasic\Compilers\"-folder
-> Open "D_Optimierer.ini" and change "FasmExe" to "Remis_Optimierer.exe" -> "FasmExe = Remis_Optimierer.exe"
-> be happy ;-)

Example:

Code: Select all

Procedure a(x)
  Protected a,b,c
  a = x
  ProcedureReturn a
EndProcedure

#r = 40000000

s.s = ":)"

st1 = GetTickCount_()
For i = 1 To #r
  If s
    a(2)
  EndIf
Next
t1 = GetTickCount_()-st1

MessageRequester("",Str(t1))
Results:
- no optimizing: 1172 ms
- with optimizing: 438ms

; --------------------------------------------------

New in jaPBo v1.13 - 09-November-2005
hopefully the last bug of the beta version has been fixed, so you will get v1.13 now ;)

; --------

New in jaPBo v1.12 - 13-October-2005 - 23:38
Nothing worldmoving new! Deeem2031 has only changed the statistics and optimisations for size of the source/sources/exe a bit! Just give it a try :wink:

NTQ from the german forum was so friendly and compared the speed difference of his raytracer engine: From slow 60 seconds it was optimized up to fast 51 seconds ( :D )with Deeem2031 optimizer! It brings something in finished programs! :wink:

- eliminate double string-ends (optimize the size / doesnt affect on speed)
- some other little thinks

; --------

New in jaPBo v1.11 - 08-October-2005 - 17:50
Deeem2031 still found a way to implent his old optimisations again! Callsbacks and such things will be ignored.

; --------

New in jaPBo v1.10 - 08-October-2005 - 13:15
Due fact of some internaly purebasic coding reasons, you get a fixed/compatible v1.10 (but its no longer so fast as before)

; --------

New in jaPBo v1.07 - 08-October-2005 - 00:05
- bugfix of deleting the unnecesary register pushs
- when having a ProcedureReturn at the end of a procedure, undo (putting back) of the result will be deleted

; --------

New in jaPBo v1.06 - 07-October-2005
- replacing of SYS_StringEqual with null strings by direct processing
i.e. all comparisons of strings with a null string, like "If string.s" will run faster. (' If string.s < > "" ' will not be improved)

Example:

Code: Select all

Procedure a(x)
  Protected a,b,c
  a = x
EndProcedure

#r = 40000000

s.s = ""

st1 = ElapsedMilliseconds()
For i = 1 To #r
  a(2)
  If s
  EndIf
Next
t1 = ElapsedMilliseconds()-st1

MessageRequester("",Str(t1))
with optimizing: ca. 1030 ms
no optimizing: ca. 375 ms

; --------

New in jaPBo v1.05 - 07-October-2005 - 00:55
- Nothing, it's just a bug-fix release ;-)

; --------

New in jaPBo v1.04 - 03-October-2005 - 11:55
- LogFiles can now be overwritten
- Log-Output has been a bit improved
- For-Next Loops will be multiplies if possible (the code will go larger, however it runs a little bit faster)

So i have saved once again 30 ms -> 170 ms

; --------

New in jaPBo v1.03 - 03-October-2005 - 01:00
- starting the exe will display a few infos
- Ecx will always deleted from stack
- Esi will be replaced by Esp if possible
- so the example is once again about 30 ms faster! -> ca 200 ms

So i am at the end with procedure optimisations, anyway i dont noticed anything more to optimize the procedures... but i saw something... later..
For those, who are to lazy to take a look but wanted to know what has been optimized:

Original:

Code: Select all

_Procedure0:
  PUSH   ebx
  PUSH   ecx
  PUSH   ebp
  PUSH   esi
  PUSH   edi
         MOV esi,esp
  SUB    esp,16
  MOV    eax,esp
  MOV    edx,eax
  ADD    edx,16
_ClearLoop0:
  MOV    dword [eax],0
  ADD    eax,4
  CMP    eax,edx
  JNE   _ClearLoop0
  MOV    eax, dword [esi+24]
  MOV    dword [esp+0],eax
; Protected a,b,c
; a = x
  MOV    eax,dword [esp]
  MOV    dword [esp+4],eax
; EndProcedure
  XOR    eax,eax
_EndProcedure1:
  ADD    esp,16
  POP    edi
  POP    esi
  POP    ebp
  POP    ecx
  POP    ebx
  RET    4
_EndProcedure0: 
Optimized:

Code: Select all

_Procedure0:
PUSH  0
PUSH  0
PUSH  0
PUSH  0
mov eax, dword [Esp-20+16+24]
 MOV dword [esp+0],eax
 MOV eax,dword [esp]
 MOV dword [esp+4],eax
 XOR eax,eax
_EndProcedure1:
 ADD esp,16
 RET 4
_EndProcedure0:
"mov eax, dword [Esp-20+16+24]" does not really looks intelligent but it work as it should! :wink:

; --------

New in jaPBo v1.02 - 02-October-2005 - 22:45
- example runs now 20ms faster!

The "possibility to delete the ClearLoop of procedures. (it set all protected vars back to 0... mostly unnecessarily )" does not happen, because PB strings strongly require to set back setting. It would only work if sont use use strings in procedures - but therfor the loop will be relaced. So the example will from the first posting will speed up from 500 to 234 ms, smile.

PLEASE NOTE: please dont change "Optimize_ReplaceEsi = 0" in the ini file!!!

; --------

New in jaPBo v1.01 - 02-October-2005
- ASM-ErrorMessages will displayed correctly now (thx to remi_meier)
- ClearLoop will be replaced by a faster routine

; --------

New in jaPBo v1.00 - 02-October-2005
- removes unused Push/Pops of procedure calls

Posted: Sun Oct 02, 2005 4:53 pm
by Polo
I haven't looked at it yet, but if it does optimize, Fred should take some optimizing tricks used here and include them in the PBCompiler 8)

Posted: Sun Oct 02, 2005 4:59 pm
by va!n
yes, thats true! but i think fred and his team will implent / change some compiler related things for v4.0 - just be patienced and let us wait :-)

Posted: Sun Oct 02, 2005 5:04 pm
by Brice Manuel
Awesome! THanks a million :D

Posted: Sun Oct 02, 2005 9:52 pm
by va!n
Version 1.02 is now online!

here are my results:

Without Opt.... 296 - 313 ms
With Opt v1.01: 218 - 234 ms
With Opt v1.02: 140 ms, WOOOOW

Posted: Sun Oct 02, 2005 10:06 pm
by Xombie
va!n, the idea of code optimizations is awesome to me :D I love trying to get something as fast as possible. Excellent! :D

However, I have a question - how can I safely combine your optimization with remi_meier's optimization? You both include a fasm.exe in your optimizations so I'm not sure how to put them together. Is it possible for them to coexist happily together and both optimize the same source?

Help! ^_^

Posted: Sun Oct 02, 2005 10:27 pm
by va!n
@Xombie:
Thanks for your feedback! Its not my score! You have to thank Deeem2031 for his great tool! ;) Btw, you can chang the ini file to use remi_meiers optimizer too! ;) (if you have problems i will explain it here more advanced... :wink:

Posted: Sun Oct 02, 2005 11:32 pm
by Xombie
va!n wrote:@Xombie:
Thanks for your feedback! Its not my score! You have to thank Deeem2031 for his great tool! ;) Btw, you can chang the ini file to use remi_meiers optimizer too! ;) (if you have problems i will explain it here more advanced... :wink:
Yes please ^_^ I'm clueless :D

It'd be great if the ASM masters around here got together and did a large optimization project but until then, this is awesome :D

Posted: Sun Oct 02, 2005 11:40 pm
by va!n
Version 1.03 is now online!

[edited]
@zombie: i will explain it here after i have sleep a bit.. sorry but i am to tired and to unconcentrated atm... hope its ok for you!? here its 01:52am - good n8

Posted: Mon Oct 03, 2005 10:36 am
by remi_meier
I'll explain it :wink:
Just rename my optimizer to something like Optimizer2.exe, install Deeem's
one and look into D_Optimizer.ini. There you can redirect FasmExe to my
optimizer like:
FasmExe = Optimizer2.exe

So you have Fasm.exe (Deeem's one), Fasm2.exe (the real one) and
Optimizer2.exe (mine).

I hope this was detailed enough.

greetz
Remi

Posted: Mon Oct 03, 2005 12:20 pm
by va!n
@remi_meier:
good morning and thanks a lot for explaining it how to get it work ;-)

Posted: Mon Oct 03, 2005 4:04 pm
by DoubleDutch
I think there is a bug, anyone else experienced this type of code being generated:

Code: Select all

JNE _AO_Ok27
cmp dword [v_forcerEsp-8+8ze],0
JNE _AO_Ok27
I think the +8ze is a mistake???

-Anthony

Posted: Mon Oct 03, 2005 4:12 pm
by DoubleDutch
I compiled it with a log, here is the result:

Code: Select all

Access:  CMP dword [v_ForceResize],0
Modify: " CMP dword [v_ForceResize],0" -> "cmp dword [v_forcerEsp-8+8ze],0" (Pos: 10364684)
Access:  JNE _AO_Ok27
Access:  JMP _AO_No27
Access: _AO_Ok27:
Access:  MOV eax,1
Access:  JMP _AO27
I don't know if this is any help???

Posted: Mon Oct 03, 2005 4:19 pm
by DoubleDutch
Here is some more log output... See the 8ze???

Code: Select all

-> removed 2 unused register
--> modify stack
Modify: "  MOV esi,esp" -> "LEA Esi,[Esp-8]" (Pos: 10364774)
-> replace Esi with Esp (Version 1.0)
--> Modify Esi-commands
Modify: " CMP dword [v_ForceResize],0" -> "cmp dword [v_forcerEsp-8+8ze],0" (Pos: 10365165)
Modify: " MOV dword [v_ForceResize],0" -> "mov dword [v_forcerEsp-8+8ze],0" (Pos: 10365485)
--> Remove Esi-commands
Remove: " PUSH esi" (Pos: 10364754)

Posted: Tue Oct 04, 2005 2:45 am
by va!n
@DoubleDutch:
Deeem2031 noticed the bugs and try to fix it! :wink: