flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Some cleanup sugestions on Fasm code

Author
Thread Post new topic Reply to topic
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas 31 Jul 2005, 21:11
I've found some odd code sequences in fasm that I think should be changed, I'm sure they will result in infinitesimal performance improvements...

This first case occurs several times in parser.inc:

Code:
        lods    byte [esi]
        mov     al,2
    


Could be changed to:

Code:
        inc     esi
        mov     al,2
    


This second case is from fromats.inc:

Code:
        lods    byte [esi]
        lods    byte [esi]
    


Could be changed to:

Code:
        inc     esi
        lods    byte [esi]
    


In expressi.inc, I've found:

Code:
        sub     esi,2
        mov     dword [edi],0
        mov     dword [edi+4],0
        inc     esi
    


sub esi,2 followed by inc esi are redundant, of course, should be dec esi.

Well, there are a few more things I'll post latter.
Post 31 Jul 2005, 21:11
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 01 Aug 2005, 07:16
don't forget that this (uncommented) code shuld be as explainative as possible, and "lods" clearly means skipping character, unlike "inc".
Post 01 Aug 2005, 07:16
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 01 Aug 2005, 13:39
Well, actually I have discovered hundreds of such repeating paterns in Fasm code, but there isn't enough space to descibe them all here. But imagine what happens when you upgrade to a new version of Fasm but with all those code fixes you nade are lost? So better don't do such changes until you told Tomasz Very Happy
Post 01 Aug 2005, 13:39
View user's profile Send private message Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas 01 Aug 2005, 16:29
I did change my fasm copy, just for testing, but this are just sugestions, I don't really mind if they are not implemented. This is just the way I would code if I was the author of Fasm. It's just that lods takes 5 cycles in 386 and uses memory bandwidth, while inc takes 2 cycles.
Post 01 Aug 2005, 16:29
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 01 Aug 2005, 16:51
Well, actually I feel ashamed I have left so many of such relicts - they are direct result of re-editing the same code pieces hundreds of times. From time to time, when I review some larger parts of code, I fix all such things - for example I have removed a lot of more or less similar ones from the X86.INC when I was upgrading it to X86_64.INC, I did review almost all the code there that time; but the PARSER.INC and EXPRESSI.INC were not generally revised for a very long time - perhaps that's why you've found such things there in the first place.
Post 01 Aug 2005, 16:51
View user's profile Send private message Visit poster's website Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 120
Location: Sunset Empire
El Tangas 01 Aug 2005, 19:48
Nothing to be ashamed of Wink
Fasm is a great piece of code, but its complexity is increasing, and this kind of leftovers will tend to accumulate...

Well, I do have a few more things to report (expressi.inc):

Code:
        dec     esi
        mov     al,[esi+1]

to

        mov     al,[esi]
        dec     esi
    

motive: saves one byte...


Code:
        shld    edx,eax,1
        shl     eax,1

and

        shl     eax,1
        rcl     edx,1

to

        add     eax,eax
        adc     edx,edx


In general:
        shl     reg,1 -> add    reg,reg
        rcl     reg,1 -> adc    reg,reg

    

motive: faster.

And finally, in preproce.inc:
Code:
      convert_line_data:
        cmp     edi,[memory_end]
        jae     out_of_memory
        lods    byte [esi]
        cmp     al,20h
        je      convert_line_data
        cmp     al,9
        je      convert_line_data
->      dec     esi
->      lods    byte [esi]
        mov     ah,al
    

the marked lines are not needed.
Post 01 Aug 2005, 19:48
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8354
Location: Kraków, Poland
Tomasz Grysztar 01 Aug 2005, 19:55
Thanks! Smile
Post 01 Aug 2005, 19:55
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.