How to know an inline function is really inline

Started by
14 comments, last by Jan Wassenberg 16 years, 5 months ago
Is there a simply method? (without knowledge of dasm)
Advertisement
You can't 'truly' know unless you look at the generated assembly and see how it is called and appears in the target. If you need help figuring it out though in ASM, you could use something like:

__asm { __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 }// function body goes here__asm { __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 __emit 0x90 }


What that does is pad 5 NOPs around the body of the code (but will still come after prolog and end before epilog code, reference) but you can open up a free disassembler, OlylDbg for example, and use the search command for 5 NOPS in a row and see where your code is. **

The only caveat to that is the compiler might optimize out certain things like that, but I am not sure. When going between debug and release configurations the code is different anyways so no telling if this is actually will work.

** The above is not truly tested against identifying inline code and is just an idea.
just run your code with a profiler. inlined functions just don't show up there anymore.
------------------------------------------------------------Jawohl, Herr Oberst!
You could try putting a breakpoint on the line calling your function. When you run the app, you arrive at the breakpoint and tracing into the function does not actually get you into the code of that function it most probably is inlined.

But the best way is by looking at the generated code. It really isnt hard you know. Just put a breakpoint, run, right-click, get "show disassembly" and look if you see a "call ...." towards your function. If there is one, the function isnt inlined.

(all of the above was written with Visual C++ in mind as IDE ;) )
Quote:Original post by Keisni
Is there a simply method? (without knowledge of dasm)

Without looking at the assembly, I don't think you can. C++ doesn't have any way to guarantee that a function is inlined. The compiler can ignore the inline keyword if it wants to.
NextWar: The Quest for Earth available now for Windows Phone 7.
Some compilers also provide the "__forceinline" keyword (MSVC does) but, once again, I'm not sure if it's 100% garanteed to come out inlined.
Quote:Original post by Trillian
Some compilers also provide the "__forceinline" keyword (MSVC does) but, once again, I'm not sure if it's 100% garanteed to come out inlined.

It isn't, in MSVC's case. It should however output a 4714 warning at compile time when failed.

See also http://msdn2.microsoft.com/en-us/library/z8y1yy88(VS.71).aspx
TBH it's barely worth inlining anything at all. Any language directive is only a hint and without it the compiler will still do what it thinks is best.
There are a fair number of good reasons not to care.
Quote:Original post by Dave
TBH it's barely worth inlining anything at all. Any language directive is only a hint and without it the compiler will still do what it thinks is best.


Some compilers, like Visual C++, can sometimes inline functions that are not declared as inline through whole program optimization and link time code generation. In general though if you have a function that is a good candidate for inlining (generally a short and simple function that you know is called with high frequency in performance sensitive code) then it is worth declaring it as inline and defining it in a header where it is visible to all callers as the optimizer is more likely to be able to inline it where appropriate.

Game Programming Blog: www.mattnewport.com/blog

This topic is closed to new replies.

Advertisement