flat assembler
Message board for the users of flat assembler.

flat assembler > Main > iCall somthing like inline function in fasm.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 497
How about macro iCall ?
Code:
InlineFlag EQU 1 ;yes inline and not call proc.
NoInline   EQU 0 ;no and Call proc

proc Proc1
  mov eax,2 ;this for example because code might be more big ! 100 asm commands
  ret
endp

proc Proc2
  add eax,ebx
  ret
endp

iCall InlineFlag,Proc1
iCall InlineFlag,Proc2
iCall NoInline,Proc1    


This generate next code:
Code:
mov eax,2
add  eax,ebx
Call  Proc1
    
Post 25 Jul 2019, 11:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16737
Location: In your JS exploiting you and your system
Inline would generally just be a macro.
Code:
macro do_something { xor eax,eax }

proc do_it
  do_something
  ret
endp

call do_it ;function call
do_something ;inline    
Post 25 Jul 2019, 15:59
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 497
I suggest such:
Code:
macro do_something { xor eax,eax }

proc do_somethingProc
  do_something
  ret
endp

;I do not know whether this macro will work right
macro iCall flg,chMacr {
if flg=1
chMacr
endif
if flg=0
Call chMacr#Proc
endif
}
    

Use in code:

Code:
inlineFlagProc1 EQU 1
;iCall might call many procs ! One iCall do many macros or Call procs.
iCall inlineFlagProc1,do_something 
iCall inlineFlagProc1,do_something,do_something2,do_something3
    


Last edited by Roman on 26 Jul 2019, 08:13; edited 3 times in total
Post 26 Jul 2019, 06:11
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 570
Location: Belarus
So, what’s the purpose? Inlining as one of optimization techniques is not only about putting the procedure body at the call site (although it’s definitely the way to start) but also certain changes at the machine-code level that make such placement efficient: reusing values in registers thus avoiding unnecessary stack/memory accesses, etc. It’s not what can generally be achieved without serious analysis. Just try to write such macro + proc with a few parameters and see how your code gets bloated with useless stuff like moving data between and pushing/popping it (either in caller or callee).
Post 26 Jul 2019, 07:11
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 497
Quote:
So, what’s the purpose?

If i using many procs i need fast way change Call on code to macro !


Very hard find many procs in differents places of code.

iCall very helpfull.

Only change inlineFlag on null or 1 thats all.

I agree, some times proc optimization is needed and gives short and fast code.
Post 26 Jul 2019, 08:04
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 570
Location: Belarus
But you gain little to nothing by simply putting procedure body in the caller. The only thing you might gain by blindly copying the body is to remove procedure call overhead but this stuff is quite optimized in hardware these days and, due to speculative execution, the overhead might sometimes even become invisible, so in such cases you would gain larger executable and worse data locality (remember caches and prefetcher). And again, when writing some piece of code in such a way that it is usable as both separate and inlined procedure you might introduce overheads for both cases. Chasing two rabbits usually gets nothing.
Post 27 Jul 2019, 08:29
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 497
Quote:
Chasing two rabbits usually gets nothing.

Hm !
Rabbits very tasty Smile
When you know how to cook them !
Post 27 Jul 2019, 08:32
View user's profile Send private message 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-2019, Tomasz Grysztar.

Powered by rwasa.