flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > What is faster and what is less greedy to memory resources

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 04 Mar 2023, 20:52
Code:
macro via_sp instruction& {
        local temp
        temp=no@frame
        no@frame=1
        instruction
        no@frame=temp }    


Code:
macro via_sp instruction& { match no@frame,1 \{ instruction \} }    


if I test both on fasm with memory limited to 65536kB
Code:
no@frame=0
MAX_REPEATS=1143651
repeat MAX_REPEATS
        virtual
                via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
        end virtual
end repeat
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)     

1st one compiled 0.4 seconds via 0.3 for 2nd one macro
and MAX_REPEATS for second one could be 1143731, and with more instruction have to be produced to output not virtual this tendention grouth

could I expect that 2nd variant of parameter replacement is always memory shorter,faster & preferable? or it(2nd variant) has it`s own limit where it can`t be applied while 1st one could and my test missed such limitation?

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 04 Mar 2023, 20:52
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20422
Location: In your JS exploiting you and your system
revolution 04 Mar 2023, 21:10
There is no definitive answer because it depends upon your systems, the input sources, and the fasm version.

In general macros are slow, but run only once. Whereas assembly passes are fast but run many times. Not always true, but a good rule of thumb IMO.

So if you have a lot of passes then option one might be slower. If you have few passes then option two might be slower.

As with all optimisations, you will have to test it on each of your systems to know how it will turn out for you. And someone else might see different results even for the same inputs.
Post 04 Mar 2023, 21:10
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 802
Location: Russian Federation, Sochi
ProMiNick 04 Mar 2023, 21:38
test on 34192 lines of
Code:
via_sp add      eax,(1+2)*no@frame+6*(1-no@frame)    
after line
Code:
no@frame=0    

1st one algo - 1 pases, 0.1..0.2 seconds randomly
2nd one algo - 1 passes, 0.0..0.1 seconds randomly (no sumary info about sec I suppose as 0.0 sec)

so. as sayed above 2nd algo should be faster on multypass, but even on single pass it 2 times faster.
So 2nd one is preferrable or it have some hidden limitation that 1st one havn`t?
Post 04 Mar 2023, 21:38
View user's profile Send private message Send e-mail 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.