OPTIMIZATION !

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Progs
User
User
Posts: 21
Joined: Sun Sep 19, 2004 12:42 pm
Location: Russia/Moscow

OPTIMIZATION !

Post by Progs »

I wish to see better assembler output....
I suppose that now ther is no optimization at all... only Line by line translation to asm.

Here PureBasic generated code

Code: Select all

; *mae_selectedlinkedlist\count = *mae_selectedlinkedlist\count - 1 
MOV    ebp,dword [p_mae_selectedlinkedlist]
MOV    ebx,dword [ebp+20]
ADD    ebx,-1
PUSH   ebx
MOV    ebp,dword [p_mae_selectedlinkedlist]
POP    eax
MOV    dword [ebp+20],eax
i think this code is bad....
it should be like

Code: Select all

MOV ebp,dword [p_mae_selectedlinkedlist]
MOV eax,dword [ebp + 20]
DEC eax
MOV dword [ebp + 20], eax
or even like

Code: Select all

MOV ebp,dword [p_mae_selectedlinkedlist]
DEC dword [ebp + 20]
sorry if im wrong...
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

I wonder if a thirty party asm-optimized can be added to the compiling pipeline...
Or can already be done manually?
Progs
User
User
Posts: 21
Joined: Sun Sep 19, 2004 12:42 pm
Location: Russia/Moscow

Post by Progs »

You can write directly in asm :D

Example... pure function

Code: Select all

Procedure.l mae_linkedlist_next()
    If *mae_selectedlinkedlist\nxt = 0 
        *mae_selectedlinkedlist\pointer = 0
        ProcedureReturn 0
    EndIf 
    
    *mae_selectedlinkedlist\pointer = *mae_selectedlinkedlist\nxt
    *mae_selectedlinkedlist\nxt = *mae_selectedlinkedlist\pointer\nxt

    ProcedureReturn (*mae_selectedlinkedlist\pointer-*mae_selectedlinkedlist\datasize)
EndProcedure
My asm version

Code: Select all

Procedure.l mae_linkedlist_next() 
    !MOV ebp,dword [p_mae_selectedlinkedlist] 
    !MOV ebx,dword [ebp+12]
    !CMP ebx, 0
    !JNE _my_ok 
    !MOV dword [ebp+8],0
    !XOR eax,eax
    !JMP _my_end 
    !_my_ok: 
    ;*mae_selectedlinkedlist\pointer = *mae_selectedlinkedlist\nxt 
    !MOV eax,dword [ebp+12]
    !MOV dword [ebp+8],eax 
    ;*mae_selectedlinkedlist\nxt = *mae_selectedlinkedlist\pointer\nxt   
    !MOV ebp,dword [ebp+8] 
    !MOV eax,dword [ebp] ;eax = *nxt 
    !MOV ebp,dword [p_mae_selectedlinkedlist];ebx 
    !MOV dword [ebp+12], eax 
    ;return
    !MOV eax,dword [ebp+8] 
    !NOP
    !SUB eax,dword [ebp+16]
    ProcedureReturn
    !_my_end:
EndProcedure
ASM version is about 50% faster !
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Well, PureBasic's website states:
  • The key features of PureBasic are portability (Windows, AmigaOS and Linux are currently fully supported), the production of very fast and highly optimized executables and, of course, the very simple BASIC syntax.
I'm not a asm pro (so are most of pb users...), so I can't say if this is true with every bit of code pb produces.
But if you find some stuff just post it... it's appreciated.
Good hunting :wink:
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

On Amiga there was a small program that would optimize assembler source code.

You would just select the source, and it would parse it and compare it against a built in optimization database, and would replace has much code has possible.
Moonshine
Enthusiast
Enthusiast
Posts: 263
Joined: Tue May 25, 2004 12:13 am
Location: UK

Post by Moonshine »

Is there anything that wll do the same for x86 on a PC though?
Mark my words, when you least expect it, your uppance will come...
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Moonshine wrote:Is there anything that wll do the same for x86 on a PC though?
Image

:D
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

:mrgreen:

Oh, that is an evil one!
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

lol. Cruel.

There is always a downside to a post like that - your own questions could end up get links back to that post! :D
@}--`--,-- A rose by any other name ..
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Dare2 wrote:lol. Cruel.

There is always a downside to a post like that - your own questions could end up get links back to that post! :D
I never ask questions, do I???? :lol:
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

@freedimension:

At least from now on, you've laid a lot of pressure on yourself before you
can ask a question :lol:
regards,
benny!
-
pe0ple ar3 str4nge!!!
Post Reply