Skip to main content
gamedev.net
🔒 Locked

C# inline functions, and inline assembly code...

Started by Yratelev 3 replies 4.2k views
Original Post
Yratelev
Yratelev
Are they possible? Yratelev
Yratelev
VizOne
VizOne
Whether a function is inlined or not is decided by the JIT-compiler. You have little influence on that. There are some criteria that make methods candidates for inlining (method-size < 32, simply structured etc., properties are quite good candidates) but there is no possibility to force the JIT to inline (on the other hand, you can force the jit NOT to inline: MethodImplAttribute + MethodImplOptions.NoInlining). If you want to check whether the JIT-compiler inlined a piece of code use cordbg to step through the generated asm code.

Inline assembly is not possible with C#. However, you can use it with Managed C++ (the method with inline asm, however, must not be compiled with /CLR). Then, you can link to the MC++ assembly from C#

Regards,
VizOne
Yratelev
Yratelev
ah cool just wanted to see if my one liners get and set were going to be inlined thats cool. As for asm managed C++ gives me something to think about..
cheers

Yratelev
Yratelev
Arild Fines
Arild Fines
quote:
Original post by VizOne
(the method with inline asm, however, must not be compiled with /CLR)


Not sure what you meant by this, since /CLR is a global switch. However, the MC++ compiler will automatically switch to generate native code instead of CIL whenever it encounters an inline asm block, so you generally don''t have to think about it. I believe there is a pragma to force unmanaged compilation as well.

The MC++ docs have a table of situations in which it will refuse to emit CIL.



--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
VizOne
VizOne
quote:
Original post by Arild Fines
Not sure what you meant by this, since /CLR is a global switch.


Actually I did not really mean /CLR but compiled as managed code in general. Btw: actually /CLR is only global per file (ie you can have some .cpps compiled with /CLR and some without). Don''t know if you meant this :D

quote:

However, the MC++ compiler will automatically switch to generate native code instead of CIL whenever it encounters an inline asm block, so you generally don''t have to think about it.


Ah, you are right. For some reason I unnecessarily always used #pragma unmanaged/managed around functions with inline asm. Stupid me :D

Maybe interesting:
http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=76937
http://support.microsoft.com/servicedesks/webcasts/wc050102/WC050102.ppt

Regards,
Andre Loker

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.