<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="/rss.xsl"?><rss version="2.0"><channel><title>netasm Wiki &amp; Documentation Rss Feed</title><link>http://www.codeplex.com/netasm/Wiki/View.aspx?title=Home</link><description>netasm Wiki Rss Description</description><item><title>Updated Wiki: Home</title><link>http://netasm.codeplex.com/Wiki/View.aspx?title=Home&amp;version=25</link><description>&lt;div class="wikidoc"&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;_&lt;br /&gt;&lt;b&gt;The last update of the 3.5 SP1 seems to have broken NetAsm. There is no way to correct this (NetAsm is based on old SSCLI 2.0 source code project released in 2006).&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NetAsm project is probably dead!&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Just hope that Microsoft will improve their JIT using SIMD as it has been done for the Mono project (See &lt;a href="http://tirania.org/blog/archive/2008/Nov-03.html" class="externalLink"&gt;Mono's SIMD Support&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;).&lt;/b&gt;&lt;br /&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;i&gt;&lt;/i&gt;_
&lt;h1&gt;Project Description&lt;/h1&gt;NetAsm provides a hook to the .NET JIT compiler and enables to inject your own native code in replacement of the default CLR JIT compilation. With this library, it is possible, at runtime, to inject x86 assembler code in CLR methods with the speed of a pure CLR method call and without the cost of Interop&amp;#47;PInvoke calls.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NetAsm can be used to integrate optimized native code using CPU extended instructions (SSE,MMX) into your managed code&lt;/b&gt;. The NetAsmDemo sample provides two &lt;a href="http://netasm.codeplex.com/Wiki/View.aspx?title=benchmarks"&gt;benchmarks&lt;/a&gt; that unveil the power of using native code injection with NetAsm.&lt;br /&gt;For more information about NetAsm, code injection techniques and recommendations, please consult the &lt;a href="javascript:window.location.href='http://netasm.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=39811';"&gt;NetAsm-UserGuide&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;NetAsm wouldn't have been possible without the brilliant article “&lt;a href="http://www.ntcore.com/Files/netint_native.htm" class="externalLink"&gt;.NET Internals and Native Compiling&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;” from Daniel Pistelli.&lt;br /&gt;
&lt;h2&gt;News&lt;/h2&gt;25 july 2008, &lt;a href="http://netasm.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=15661"&gt;NetAsm 1.0&lt;/a&gt; is released.
&lt;h2&gt;Features&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;Runs on &lt;b&gt;x86 32bit Microsoft .NET platform with 2.0+ CLR runtime&lt;/b&gt; (x64 may be supported in the future).&lt;/li&gt;
&lt;li&gt;Provides three different native &lt;b&gt;code injection techniques&lt;/b&gt;: Static, DLL, and Dynamic.
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Static code injection&lt;/b&gt;: The native code is stored in an attribute of the method.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Dll code injection&lt;/b&gt; : this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Dynamic code injection&lt;/b&gt;: you can generate native code dynamically with a callback interface that is called by the JIT when compilation of a method is occurring. It means that you can compile a method “on the fly”. You have also access to the IL code of the method being compiled.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Supports for debugging&lt;/b&gt; static and dynamic code injection.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl&lt;/b&gt;. Default calling convention is CLRCall.&lt;/li&gt;
&lt;li&gt;NetAsm can be used inside &lt;b&gt;any .NET language&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;Very &lt;b&gt;small library&lt;/b&gt; &amp;lt;100Ko.&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Future plans&lt;/h2&gt;You are welcome to vote for the following features (or any new features) or even contribute to one of them if you have a good experience in such domain:
&lt;ul&gt;&lt;li&gt;Add a simplified assembler to code inject textual &lt;i&gt;&lt;/i&gt;asm instructions from CodeInjection attribute?&lt;/li&gt;
&lt;li&gt;Add support for 64bit platform?&lt;/li&gt;
&lt;li&gt;Add support for Mono platform?&lt;/li&gt;&lt;/ul&gt;
&lt;h1&gt;HelloWorld example&lt;/h1&gt;This sample is available in NetAsmDemo and is fully documented in the the NetAsm User guide.&lt;br /&gt;&lt;br /&gt;Using native code injection with NetAsm is a very simple task that can be achieved in two steps:&lt;br /&gt;1)	Specify the native code injection in a class&lt;br /&gt;2)	Install the hook in the main program of your application
&lt;h2&gt;Setup native code injection in a class&lt;/h2&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; System;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; System.Runtime.CompilerServices;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; NetAsm;

&lt;span style="color:Blue;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    [AllowCodeInjection]
    &lt;span style="color:Blue;"&gt;class&lt;/span&gt; TestHelloWorld
    {
        [CodeInjection(&lt;span style="color:Blue;"&gt;new&lt;/span&gt; &lt;span style="color:Blue;"&gt;byte&lt;/span&gt;[] { 0xC3 }), MethodImpl(MethodImplOptions.NoInlining)]
        &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;public&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; NetAsmReturn()
        {
            &lt;span style="color:Blue;"&gt;throw&lt;/span&gt; &lt;span style="color:Blue;"&gt;new&lt;/span&gt; Exception(&lt;span style="color:#A31515;"&gt;&amp;quot;With NetAsm, You should not have an exception!&amp;quot;&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The steps to allow and use code injection on a method in a class are:&lt;br /&gt;&lt;br /&gt;1.	Set &lt;b&gt;AllowCodeInjection&lt;/b&gt; attribute on the class you want to do code injection.&lt;br /&gt;2.	Set &lt;b&gt;CodeInjection&lt;/b&gt; attribute on the method that will be injected with native code&lt;br /&gt;3.	For void NetAsmReturn() method in TestHelloWorld, the native code used is : new byte[] { 0xC3 }. In x86 assembler, it’s the “RET” (return) command. This method does nothing more than immediately returning after a call. &lt;br /&gt;4.	In our example, we have set the attribute MethodImpl(MethodImplOptions.NoInlining) : This attribute force the JIT to not inline the IL code inside the method. This is for the purpose of the demonstration but should be used with caution (see usage recommendation chapter).&lt;br /&gt;&lt;br /&gt;That’s all to use code injection! &lt;br /&gt;In NetAsm, this kind of native code injection is called static native code injection. TestHelloWorld only use static code injection at the method level. We will see later that NetAsm provides other code injection techniques.&lt;br /&gt;Now, to run this code injection test, we need to install NetAsm &lt;b&gt;JITHook.Install()&lt;/b&gt;.
&lt;h2&gt;Install the hook and run the code injection&lt;/h2&gt;To call the &lt;b&gt;TestHelloWorld&lt;/b&gt; method, the main program has to initialize NetAsm:&lt;br /&gt;&lt;div style="color:Black;background-color:White;"&gt;&lt;pre&gt;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; System;
&lt;span style="color:Blue;"&gt;using&lt;/span&gt; NetAsm;

&lt;span style="color:Blue;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    &lt;span style="color:Blue;"&gt;class&lt;/span&gt; Program
    {
        &lt;span style="color:Blue;"&gt;static&lt;/span&gt; &lt;span style="color:Blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color:Blue;"&gt;string&lt;/span&gt;[] args)
        {
            &lt;span style="color:Green;"&gt;// Install the JIT Hook&lt;/span&gt;
            JITHook.Install();
            &lt;span style="color:Green;"&gt;// Run TestHelloWorld Method&lt;/span&gt;
            TestHelloWorld.NetAsmReturn();
            &lt;span style="color:Green;"&gt;// Remove the JIT Hook&lt;/span&gt;
            JITHook.Remove();
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;If you run this program, it will return without any exception. While executing this code, the CLR Virtual Machine use our native code “RET” command instead of the IL code inside the method. It means that the original IL code is not compiled by the default JIT compiler.&lt;br /&gt;&lt;br /&gt;Additionnal information and other code injection techniques are available in the NetAsm User Guide.&lt;br /&gt;&lt;br /&gt;Blog : &lt;a href="http://code4k.blogspot.com" class="externalLink"&gt;Code4k&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="ClearBoth"&gt;&lt;/div&gt;</description><author>alexandre_mutel</author><pubDate>Tue, 13 Oct 2009 08:44:44 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20091013084444A</guid></item><item><title>Updated Wiki: Home</title><link>http://www.codeplex.com/netasm/Wiki/View.aspx?title=Home&amp;version=24</link><description>&lt;div class="wikidoc"&gt;
___________________________________________________________________________________________________________________________&lt;br /&gt;&lt;b&gt;The last update of the 3.5 SP1 seems to have broken NetAsm. There is no way to correct this (NetAsm is based on old SSCLI 2.0 source code project released in 2006).&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;NetAsm project is probably dead!&lt;/b&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Just hope that Microsoft will improve their JIT using SIMD as it has been done for the Mono project (See &lt;a href="http://tirania.org/blog/archive/2008/Nov-03.html" class="externalLink"&gt;Mono's SIMD Support&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;).&lt;/b&gt;&lt;br /&gt;___________________________________________________________________________________________________________________________&lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;NetAsm provides a hook to the .NET JIT compiler and enables to inject your own native code in replacement of the default CLR JIT compilation. With this library, it is possible, at runtime, to inject x86 assembler code in CLR methods with the speed of a pure CLR method call and without the cost of Interop&amp;#47;PInvoke calls.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;NetAsm can be used to integrate optimized native code using CPU extended instructions (SSE,MMX) into your managed code&lt;/b&gt;. The NetAsmDemo sample provides two &lt;a href="http://www.codeplex.com/netasm/Wiki/View.aspx?title=benchmarks&amp;amp;referringTitle=Home"&gt;benchmarks&lt;/a&gt; that unveil the power of using native code injection with NetAsm.&lt;br /&gt;For more information about NetAsm, code injection techniques and recommendations, please consult the &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=netasm&amp;amp;DownloadId=39811';"&gt;NetAsm-UserGuide&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;NetAsm wouldn't have been possible without the brilliant article “&lt;a href="http://www.ntcore.com/Files/netint_native.htm" class="externalLink"&gt;.NET Internals and Native Compiling&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;” from Daniel Pistelli.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
News
&lt;/h2&gt;25 july 2008, &lt;a href="http://www.codeplex.com/netasm/Release/ProjectReleases.aspx?ReleaseId=15661"&gt;NetAsm 1.0&lt;/a&gt; is released.&lt;br /&gt;&lt;h2&gt;
Features
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Runs on &lt;b&gt;x86 32bit Microsoft .NET platform with 2.0+ CLR runtime&lt;/b&gt; (x64 may be supported in the future).&lt;/li&gt;&lt;li&gt;Provides three different native &lt;b&gt;code injection techniques&lt;/b&gt;: Static, DLL, and Dynamic.&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Static code injection&lt;/b&gt;: The native code is stored in an attribute of the method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dll code injection&lt;/b&gt; : this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dynamic code injection&lt;/b&gt;: you can generate native code dynamically with a callback interface that is called by the JIT when compilation of a method is occurring. It means that you can compile a method “on the fly”. You have also access to the IL code of the method being compiled.&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Supports for debugging&lt;/b&gt; static and dynamic code injection.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl&lt;/b&gt;. Default calling convention is CLRCall.&lt;/li&gt;&lt;li&gt;NetAsm can be used inside &lt;b&gt;any .NET language&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Very &lt;b&gt;small library&lt;/b&gt; &amp;lt;100Ko.&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;
Future plans
&lt;/h2&gt;You are welcome to vote for the following features (or any new features) or even contribute to one of them if you have a good experience in such domain:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Add a simplified assembler to code inject textual __asm instructions from CodeInjection attribute?&lt;/li&gt;&lt;li&gt;Add support for 64bit platform?&lt;/li&gt;&lt;li&gt;Add support for Mono platform?&lt;/li&gt;
&lt;/ul&gt;&lt;h1&gt;
HelloWorld example
&lt;/h1&gt;This sample is available in NetAsmDemo and is fully documented in the the NetAsm User guide.&lt;br /&gt; &lt;br /&gt;Using native code injection with NetAsm is a very simple task that can be achieved in two steps:&lt;br /&gt;1)	Specify the native code injection in a class&lt;br /&gt;2)	Install the hook in the main program of your application&lt;br /&gt;&lt;h2&gt;
Setup native code injection in a class
&lt;/h2&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System.Runtime.CompilerServices;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    [AllowCodeInjection]
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; TestHelloWorld
    {
        [CodeInjection(&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;byte&lt;/span&gt;[] { 0xC3 }), MethodImpl(MethodImplOptions.NoInlining)]
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; NetAsmReturn()
        {
            &lt;span style="color:#0000FF;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; Exception(&lt;span style="color:#A31515;"&gt;&amp;quot;With NetAsm, You should not have an exception!&amp;quot;&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The steps to allow and use code injection on a method in a class are:&lt;br /&gt; &lt;br /&gt;1.	Set &lt;b&gt;AllowCodeInjection&lt;/b&gt; attribute on the class you want to do code injection.&lt;br /&gt;2.	Set &lt;b&gt;CodeInjection&lt;/b&gt; attribute on the method that will be injected with native code&lt;br /&gt;3.	For void NetAsmReturn() method in TestHelloWorld, the native code used is : new byte[] { 0xC3 }. In x86 assembler, it’s the “RET” (return) command. This method does nothing more than immediately returning after a call. &lt;br /&gt;4.	In our example, we have set the attribute MethodImpl(MethodImplOptions.NoInlining) : This attribute force the JIT to not inline the IL code inside the method. This is for the purpose of the demonstration but should be used with caution (see usage recommendation chapter).&lt;br /&gt; &lt;br /&gt;That’s all to use code injection! &lt;br /&gt;In NetAsm, this kind of native code injection is called static native code injection. TestHelloWorld only use static code injection at the method level. We will see later that NetAsm provides other code injection techniques.&lt;br /&gt;Now, to run this code injection test, we need to install NetAsm &lt;b&gt;JITHook.Install()&lt;/b&gt;.&lt;br /&gt;&lt;h2&gt;
Install the hook and run the code injection
&lt;/h2&gt;To call the &lt;b&gt;TestHelloWorld&lt;/b&gt; method, the main program has to initialize NetAsm:&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; Program
    {
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;[] args)
        {
            &lt;span style="color:#008000;"&gt;// Install the JIT Hook&lt;/span&gt;
            JITHook.Install();
            &lt;span style="color:#008000;"&gt;// Run TestHelloWorld Method&lt;/span&gt;
            TestHelloWorld.NetAsmReturn();
            &lt;span style="color:#008000;"&gt;// Remove the JIT Hook&lt;/span&gt;
            JITHook.Remove();
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;If you run this program, it will return without any exception. While executing this code, the CLR Virtual Machine use our native code “RET” command instead of the IL code inside the method. It means that the original IL code is not compiled by the default JIT compiler.&lt;br /&gt; &lt;br /&gt;Additionnal information and other code injection techniques are available in the NetAsm User Guide.&lt;br /&gt;
&lt;/div&gt;</description><author>alexandre_mutel</author><pubDate>Mon, 09 Feb 2009 21:17:29 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20090209091729P</guid></item><item><title>Updated Wiki: Home</title><link>http://www.codeplex.com/netasm/Wiki/View.aspx?title=Home&amp;version=23</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Project Description
&lt;/h1&gt;NetAsm provides a hook to the .NET JIT compiler and enables to inject your own native code in replacement of the default CLR JIT compilation. With this library, it is possible, at runtime, to inject x86 assembler code in CLR methods with the speed of a pure CLR method call and without the cost of Interop&amp;#47;PInvoke calls.&lt;br /&gt; &lt;br /&gt;&lt;b&gt;NetAsm can be used to integrate optimized native code using CPU extended instructions (SSE,MMX) into your managed code&lt;/b&gt;. The NetAsmDemo sample provides two &lt;a href="http://www.codeplex.com/netasm/Wiki/View.aspx?title=benchmarks&amp;amp;referringTitle=Home"&gt;benchmarks&lt;/a&gt; that unveil the power of using native code injection with NetAsm.&lt;br /&gt;For more information about NetAsm, code injection techniques and recommendations, please consult the &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=netasm&amp;amp;DownloadId=39811';"&gt;NetAsm-UserGuide&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;NetAsm wouldn't have been possible without the brilliant article “&lt;a href="http://www.ntcore.com/Files/netint_native.htm" class="externalLink"&gt;.NET Internals and Native Compiling&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;” from Daniel Pistelli.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
News
&lt;/h2&gt;25 july 2008, &lt;a href="http://www.codeplex.com/netasm/Release/ProjectReleases.aspx?ReleaseId=15661"&gt;NetAsm 1.0&lt;/a&gt; is released.&lt;br /&gt;&lt;h2&gt;
Features
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Runs on &lt;b&gt;x86 32bit Microsoft .NET platform with 2.0+ CLR runtime&lt;/b&gt; (x64 may be supported in the future).&lt;/li&gt;&lt;li&gt;Provides three different native &lt;b&gt;code injection techniques&lt;/b&gt;: Static, DLL, and Dynamic.&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Static code injection&lt;/b&gt;: The native code is stored in an attribute of the method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dll code injection&lt;/b&gt; : this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dynamic code injection&lt;/b&gt;: you can generate native code dynamically with a callback interface that is called by the JIT when compilation of a method is occurring. It means that you can compile a method “on the fly”. You have also access to the IL code of the method being compiled.&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Supports for debugging&lt;/b&gt; static and dynamic code injection.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl&lt;/b&gt;. Default calling convention is CLRCall.&lt;/li&gt;&lt;li&gt;NetAsm can be used inside &lt;b&gt;any .NET language&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Very &lt;b&gt;small library&lt;/b&gt; &amp;lt;100Ko.&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;
Future plans
&lt;/h2&gt;You are welcome to vote for the following features (or any new features) or even contribute to one of them if you have a good experience in such domain:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Add a simplified assembler to code inject textual __asm instructions from CodeInjection attribute?&lt;/li&gt;&lt;li&gt;Add support for 64bit platform?&lt;/li&gt;&lt;li&gt;Add support for Mono platform?&lt;/li&gt;
&lt;/ul&gt;&lt;h1&gt;
HelloWorld example
&lt;/h1&gt;This sample is available in NetAsmDemo and is fully documented in the the NetAsm User guide.&lt;br /&gt; &lt;br /&gt;Using native code injection with NetAsm is a very simple task that can be achieved in two steps:&lt;br /&gt;1)	Specify the native code injection in a class&lt;br /&gt;2)	Install the hook in the main program of your application&lt;br /&gt;&lt;h2&gt;
Setup native code injection in a class
&lt;/h2&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System.Runtime.CompilerServices;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    [AllowCodeInjection]
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; TestHelloWorld
    {
        [CodeInjection(&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;byte&lt;/span&gt;[] { 0xC3 }), MethodImpl(MethodImplOptions.NoInlining)]
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; NetAsmReturn()
        {
            &lt;span style="color:#0000FF;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; Exception(&lt;span style="color:#A31515;"&gt;&amp;quot;With NetAsm, You should not have an exception!&amp;quot;&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The steps to allow and use code injection on a method in a class are:&lt;br /&gt; &lt;br /&gt;1.	Set &lt;b&gt;AllowCodeInjection&lt;/b&gt; attribute on the class you want to do code injection.&lt;br /&gt;2.	Set &lt;b&gt;CodeInjection&lt;/b&gt; attribute on the method that will be injected with native code&lt;br /&gt;3.	For void NetAsmReturn() method in TestHelloWorld, the native code used is : new byte[] { 0xC3 }. In x86 assembler, it’s the “RET” (return) command. This method does nothing more than immediately returning after a call. &lt;br /&gt;4.	In our example, we have set the attribute MethodImpl(MethodImplOptions.NoInlining) : This attribute force the JIT to not inline the IL code inside the method. This is for the purpose of the demonstration but should be used with caution (see usage recommendation chapter).&lt;br /&gt; &lt;br /&gt;That’s all to use code injection! &lt;br /&gt;In NetAsm, this kind of native code injection is called static native code injection. TestHelloWorld only use static code injection at the method level. We will see later that NetAsm provides other code injection techniques.&lt;br /&gt;Now, to run this code injection test, we need to install NetAsm &lt;b&gt;JITHook.Install()&lt;/b&gt;.&lt;br /&gt;&lt;h2&gt;
Install the hook and run the code injection
&lt;/h2&gt;To call the &lt;b&gt;TestHelloWorld&lt;/b&gt; method, the main program has to initialize NetAsm:&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; Program
    {
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;[] args)
        {
            &lt;span style="color:#008000;"&gt;// Install the JIT Hook&lt;/span&gt;
            JITHook.Install();
            &lt;span style="color:#008000;"&gt;// Run TestHelloWorld Method&lt;/span&gt;
            TestHelloWorld.NetAsmReturn();
            &lt;span style="color:#008000;"&gt;// Remove the JIT Hook&lt;/span&gt;
            JITHook.Remove();
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;If you run this program, it will return without any exception. While executing this code, the CLR Virtual Machine use our native code “RET” command instead of the IL code inside the method. It means that the original IL code is not compiled by the default JIT compiler.&lt;br /&gt; &lt;br /&gt;Additionnal information and other code injection techniques are available in the NetAsm User Guide.&lt;br /&gt;
&lt;/div&gt;</description><author>alexandre_mutel</author><pubDate>Fri, 16 Jan 2009 17:10:45 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20090116051045P</guid></item><item><title>Updated Wiki: Home</title><link>http://www.codeplex.com/netasm/Wiki/View.aspx?title=Home&amp;version=22</link><description>&lt;div class="wikidoc"&gt;
&lt;b&gt;In order to support x64, i need to buy a windows vista 64 licence. You can help me and make a&lt;/b&gt; &lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;amp;business=alexandre_mutel%40yahoo%2efr&amp;amp;item_name=NetAsm&amp;amp;no_shipping=0&amp;amp;no_note=1&amp;amp;tax=0&amp;amp;currency_code=EUR&amp;amp;lc=FR&amp;amp;bn=PP%2dDonationsBF&amp;amp;charset=UTF%2d8" class="externalLink"&gt;donation for NetAsm&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;!&lt;br /&gt;&lt;h1&gt;
Project Description
&lt;/h1&gt;NetAsm provides a hook to the .NET JIT compiler and enables to inject your own native code in replacement of the default CLR JIT compilation. With this library, it is possible, at runtime, to inject x86 assembler code in CLR methods with the speed of a pure CLR method call and without the cost of Interop&amp;#47;PInvoke calls.
&lt;br /&gt; &lt;br /&gt;&lt;b&gt;NetAsm can be used to integrate optimized native code using CPU extended instructions (SSE,MMX) into your managed code&lt;/b&gt;. The NetAsmDemo sample provides two &lt;a href="http://www.codeplex.com/netasm/Wiki/View.aspx?title=benchmarks&amp;amp;referringTitle=Home"&gt;benchmarks&lt;/a&gt; that unveil the power of using native code injection with NetAsm.&lt;br /&gt;For more information about NetAsm, code injection techniques and recommendations, please consult the &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=netasm&amp;amp;DownloadId=39811';"&gt;NetAsm-UserGuide&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;NetAsm wouldn't have been possible without the brilliant article “&lt;a href="http://www.ntcore.com/Files/netint_native.htm" class="externalLink"&gt;.NET Internals and Native Compiling&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;” from Daniel Pistelli.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
News
&lt;/h2&gt;25 july 2008, &lt;a href="http://www.codeplex.com/netasm/Release/ProjectReleases.aspx?ReleaseId=15661"&gt;NetAsm 1.0&lt;/a&gt; is released.&lt;br /&gt;&lt;h2&gt;
Features
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Runs on &lt;b&gt;x86 32bit Microsoft .NET platform with 2.0+ CLR runtime&lt;/b&gt; (x64 may be supported in the future).&lt;/li&gt;&lt;li&gt;Provides three different native &lt;b&gt;code injection techniques&lt;/b&gt;: Static, DLL, and Dynamic.&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Static code injection&lt;/b&gt;: The native code is stored in an attribute of the method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dll code injection&lt;/b&gt; : this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dynamic code injection&lt;/b&gt;: you can generate native code dynamically with a callback interface that is called by the JIT when compilation of a method is occurring. It means that you can compile a method “on the fly”. You have also access to the IL code of the method being compiled.&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Supports for debugging&lt;/b&gt; static and dynamic code injection.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl&lt;/b&gt;. Default calling convention is CLRCall.&lt;/li&gt;&lt;li&gt;NetAsm can be used inside &lt;b&gt;any .NET language&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Very &lt;b&gt;small library&lt;/b&gt; &amp;lt;100Ko.&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;
Future plans
&lt;/h2&gt;You are welcome to vote for the following features (or any new features) or even contribute to one of them if you have a good experience in such domain:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Add a simplified assembler to code inject textual __asm instructions from CodeInjection attribute?&lt;/li&gt;&lt;li&gt;Add support for 64bit platform?&lt;/li&gt;&lt;li&gt;Add support for Mono platform?&lt;/li&gt;
&lt;/ul&gt;&lt;h1&gt;
HelloWorld example
&lt;/h1&gt;This sample is available in NetAsmDemo and is fully documented in the the NetAsm User guide.&lt;br /&gt; &lt;br /&gt;Using native code injection with NetAsm is a very simple task that can be achieved in two steps:&lt;br /&gt;1)	Specify the native code injection in a class&lt;br /&gt;2)	Install the hook in the main program of your application&lt;br /&gt;&lt;h2&gt;
Setup native code injection in a class
&lt;/h2&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System.Runtime.CompilerServices;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    [AllowCodeInjection]
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; TestHelloWorld
    {
        [CodeInjection(&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;byte&lt;/span&gt;[] { 0xC3 }), MethodImpl(MethodImplOptions.NoInlining)]
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; NetAsmReturn()
        {
            &lt;span style="color:#0000FF;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; Exception(&lt;span style="color:#A31515;"&gt;&amp;quot;With NetAsm, You should not have an exception!&amp;quot;&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The steps to allow and use code injection on a method in a class are:&lt;br /&gt; &lt;br /&gt;1.	Set &lt;b&gt;AllowCodeInjection&lt;/b&gt; attribute on the class you want to do code injection.&lt;br /&gt;2.	Set &lt;b&gt;CodeInjection&lt;/b&gt; attribute on the method that will be injected with native code&lt;br /&gt;3.	For void NetAsmReturn() method in TestHelloWorld, the native code used is : new byte[] { 0xC3 }. In x86 assembler, it’s the “RET” (return) command. This method does nothing more than immediately returning after a call. &lt;br /&gt;4.	In our example, we have set the attribute MethodImpl(MethodImplOptions.NoInlining) : This attribute force the JIT to not inline the IL code inside the method. This is for the purpose of the demonstration but should be used with caution (see usage recommendation chapter).&lt;br /&gt; &lt;br /&gt;That’s all to use code injection! &lt;br /&gt;In NetAsm, this kind of native code injection is called static native code injection. TestHelloWorld only use static code injection at the method level. We will see later that NetAsm provides other code injection techniques.&lt;br /&gt;Now, to run this code injection test, we need to install NetAsm &lt;b&gt;JITHook.Install()&lt;/b&gt;.&lt;br /&gt;&lt;h2&gt;
Install the hook and run the code injection
&lt;/h2&gt;To call the &lt;b&gt;TestHelloWorld&lt;/b&gt; method, the main program has to initialize NetAsm:&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; Program
    {
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;[] args)
        {
            &lt;span style="color:#008000;"&gt;// Install the JIT Hook&lt;/span&gt;
            JITHook.Install();
            &lt;span style="color:#008000;"&gt;// Run TestHelloWorld Method&lt;/span&gt;
            TestHelloWorld.NetAsmReturn();
            &lt;span style="color:#008000;"&gt;// Remove the JIT Hook&lt;/span&gt;
            JITHook.Remove();
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;If you run this program, it will return without any exception. While executing this code, the CLR Virtual Machine use our native code “RET” command instead of the IL code inside the method. It means that the original IL code is not compiled by the default JIT compiler.&lt;br /&gt; &lt;br /&gt;Additionnal information and other code injection techniques are available in the NetAsm User Guide.&lt;br /&gt;
&lt;/div&gt;</description><author>alexandre_mutel</author><pubDate>Thu, 07 Aug 2008 08:54:35 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20080807085435A</guid></item><item><title>Updated Wiki: Home</title><link>http://www.codeplex.com/netasm/Wiki/View.aspx?title=Home&amp;version=21</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Project Description
&lt;/h1&gt;NetAsm provides a hook to the .NET JIT compiler and enables to inject your own native code in replacement of the default CLR JIT compilation. With this library, it is possible, at runtime, to inject x86 assembler code in CLR methods with the speed of a pure CLR method call and without the cost of Interop&amp;#47;PInvoke calls.
&lt;br /&gt; &lt;br /&gt;&lt;b&gt;NetAsm can be used to integrate optimized native code using CPU extended instructions (SSE,MMX) into your managed code&lt;/b&gt;. The NetAsmDemo sample provides two &lt;a href="http://www.codeplex.com/netasm/Wiki/View.aspx?title=benchmarks&amp;amp;referringTitle=Home"&gt;benchmarks&lt;/a&gt; that unveil the power of using native code injection with NetAsm.&lt;br /&gt;For more information about NetAsm, code injection techniques and recommendations, please consult the &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=netasm&amp;amp;DownloadId=39811';"&gt;NetAsm-UserGuide&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;NetAsm wouldn't have been possible without the brilliant article “&lt;a href="http://www.ntcore.com/Files/netint_native.htm" class="externalLink"&gt;.NET Internals and Native Compiling&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;” from Daniel Pistelli.&lt;br /&gt;In order to support x64, i need to buy a windows vista 64 licence. You can help me and make a &lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;amp;business=alexandre_mutel%40yahoo%2efr&amp;amp;item_name=NetAsm&amp;amp;no_shipping=0&amp;amp;no_note=1&amp;amp;tax=0&amp;amp;currency_code=EUR&amp;amp;lc=FR&amp;amp;bn=PP%2dDonationsBF&amp;amp;charset=UTF%2d8" class="externalLink"&gt;donation for NetAsm&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;!&lt;br /&gt;&lt;h2&gt;
News
&lt;/h2&gt;25 july 2008, &lt;a href="http://www.codeplex.com/netasm/Release/ProjectReleases.aspx?ReleaseId=15661"&gt;NetAsm 1.0&lt;/a&gt; is released.&lt;br /&gt;&lt;h2&gt;
Features
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Runs on &lt;b&gt;x86 32bit Microsoft .NET platform with 2.0+ CLR runtime&lt;/b&gt; (x64 may be supported in the future).&lt;/li&gt;&lt;li&gt;Provides three different native &lt;b&gt;code injection techniques&lt;/b&gt;: Static, DLL, and Dynamic.&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Static code injection&lt;/b&gt;: The native code is stored in an attribute of the method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dll code injection&lt;/b&gt; : this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dynamic code injection&lt;/b&gt;: you can generate native code dynamically with a callback interface that is called by the JIT when compilation of a method is occurring. It means that you can compile a method “on the fly”. You have also access to the IL code of the method being compiled.&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Supports for debugging&lt;/b&gt; static and dynamic code injection.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl&lt;/b&gt;. Default calling convention is CLRCall.&lt;/li&gt;&lt;li&gt;NetAsm can be used inside &lt;b&gt;any .NET language&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Very &lt;b&gt;small library&lt;/b&gt; &amp;lt;100Ko.&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;
Future plans
&lt;/h2&gt;You are welcome to vote for the following features (or any new features) or even contribute to one of them if you have a good experience in such domain:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Add a simplified assembler to code inject textual __asm instructions from CodeInjection attribute?&lt;/li&gt;&lt;li&gt;Add support for 64bit platform?&lt;/li&gt;&lt;li&gt;Add support for Mono platform?&lt;/li&gt;
&lt;/ul&gt;&lt;h1&gt;
HelloWorld example
&lt;/h1&gt;This sample is available in NetAsmDemo and is fully documented in the the NetAsm User guide.&lt;br /&gt; &lt;br /&gt;Using native code injection with NetAsm is a very simple task that can be achieved in two steps:&lt;br /&gt;1)	Specify the native code injection in a class&lt;br /&gt;2)	Install the hook in the main program of your application&lt;br /&gt;&lt;h2&gt;
Setup native code injection in a class
&lt;/h2&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System.Runtime.CompilerServices;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    [AllowCodeInjection]
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; TestHelloWorld
    {
        [CodeInjection(&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;byte&lt;/span&gt;[] { 0xC3 }), MethodImpl(MethodImplOptions.NoInlining)]
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; NetAsmReturn()
        {
            &lt;span style="color:#0000FF;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; Exception(&lt;span style="color:#A31515;"&gt;&amp;quot;With NetAsm, You should not have an exception!&amp;quot;&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The steps to allow and use code injection on a method in a class are:&lt;br /&gt; &lt;br /&gt;1.	Set &lt;b&gt;AllowCodeInjection&lt;/b&gt; attribute on the class you want to do code injection.&lt;br /&gt;2.	Set &lt;b&gt;CodeInjection&lt;/b&gt; attribute on the method that will be injected with native code&lt;br /&gt;3.	For void NetAsmReturn() method in TestHelloWorld, the native code used is : new byte[] { 0xC3 }. In x86 assembler, it’s the “RET” (return) command. This method does nothing more than immediately returning after a call. &lt;br /&gt;4.	In our example, we have set the attribute MethodImpl(MethodImplOptions.NoInlining) : This attribute force the JIT to not inline the IL code inside the method. This is for the purpose of the demonstration but should be used with caution (see usage recommendation chapter).&lt;br /&gt; &lt;br /&gt;That’s all to use code injection! &lt;br /&gt;In NetAsm, this kind of native code injection is called static native code injection. TestHelloWorld only use static code injection at the method level. We will see later that NetAsm provides other code injection techniques.&lt;br /&gt;Now, to run this code injection test, we need to install NetAsm &lt;b&gt;JITHook.Install()&lt;/b&gt;.&lt;br /&gt;&lt;h2&gt;
Install the hook and run the code injection
&lt;/h2&gt;To call the &lt;b&gt;TestHelloWorld&lt;/b&gt; method, the main program has to initialize NetAsm:&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; Program
    {
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;[] args)
        {
            &lt;span style="color:#008000;"&gt;// Install the JIT Hook&lt;/span&gt;
            JITHook.Install();
            &lt;span style="color:#008000;"&gt;// Run TestHelloWorld Method&lt;/span&gt;
            TestHelloWorld.NetAsmReturn();
            &lt;span style="color:#008000;"&gt;// Remove the JIT Hook&lt;/span&gt;
            JITHook.Remove();
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;If you run this program, it will return without any exception. While executing this code, the CLR Virtual Machine use our native code “RET” command instead of the IL code inside the method. It means that the original IL code is not compiled by the default JIT compiler.&lt;br /&gt; &lt;br /&gt;Additionnal information and other code injection techniques are available in the NetAsm User Guide.&lt;br /&gt;
&lt;/div&gt;</description><author>alexandre_mutel</author><pubDate>Thu, 07 Aug 2008 08:53:29 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20080807085329A</guid></item><item><title>Updated Wiki: Home</title><link>http://www.codeplex.com/netasm/Wiki/View.aspx?title=Home&amp;version=20</link><description>&lt;div class="wikidoc"&gt;
&lt;h1&gt;
Project Description
&lt;/h1&gt;NetAsm provides a hook to the .NET JIT compiler and enables to inject your own native code in replacement of the default CLR JIT compilation. With this library, it is possible, at runtime, to inject x86 assembler code in CLR methods with the speed of a pure CLR method call and without the cost of Interop&amp;#47;PInvoke calls.
&lt;br /&gt; &lt;br /&gt;&lt;b&gt;NetAsm can be used to integrate optimized native code using CPU extended instructions (SSE,MMX) into your managed code&lt;/b&gt;. The NetAsmDemo sample provides two &lt;a href="http://www.codeplex.com/netasm/Wiki/View.aspx?title=benchmarks&amp;amp;referringTitle=Home"&gt;benchmarks&lt;/a&gt; that unveil the power of using native code injection with NetAsm.&lt;br /&gt;For more information about NetAsm, code injection techniques and recommendations, please consult the &lt;a href="javascript:window.location.href='http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=netasm&amp;amp;DownloadId=39811';"&gt;NetAsm-UserGuide&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;NetAsm wouldn't have been possible without the brilliant article “&lt;a href="http://www.ntcore.com/Files/netint_native.htm" class="externalLink"&gt;.NET Internals and Native Compiling&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;” from Daniel Pistelli.&lt;br /&gt;In order to support x64, i need to buy a windows vista 64 licence. You can help me and make a &lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;amp;business=alexandre_mutel%40yahoo%2efr&amp;amp;item_name=NetAsm&amp;amp;no_shipping=0&amp;amp;no_note=1&amp;amp;tax=0&amp;amp;currency_code=EUR&amp;amp;lc=FR&amp;amp;bn=PP%2dDonationsBF&amp;amp;charset=UTF%2d8" class="externalLink"&gt;https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;amp;business=alexandre_mutel%40yahoo%2efr&amp;amp;item_name=NetAsm&amp;amp;no_shipping=0&amp;amp;no_note=1&amp;amp;tax=0&amp;amp;currency_code=EUR&amp;amp;lc=FR&amp;amp;bn=PP%2dDonationsBF&amp;amp;charset=UTF%2d8&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;donation for NetAsm&lt;a href="http://www.codeplex.com/netasm/Wiki/View.aspx?title=%2furl&amp;amp;referringTitle=Home"&gt;/url&lt;/a&gt;!&lt;br /&gt;&lt;h2&gt;
News
&lt;/h2&gt;25 july 2008, &lt;a href="http://www.codeplex.com/netasm/Release/ProjectReleases.aspx?ReleaseId=15661"&gt;NetAsm 1.0&lt;/a&gt; is released.&lt;br /&gt;&lt;h2&gt;
Features
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Runs on &lt;b&gt;x86 32bit Microsoft .NET platform with 2.0+ CLR runtime&lt;/b&gt; (x64 may be supported in the future).&lt;/li&gt;&lt;li&gt;Provides three different native &lt;b&gt;code injection techniques&lt;/b&gt;: Static, DLL, and Dynamic.&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Static code injection&lt;/b&gt;: The native code is stored in an attribute of the method.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dll code injection&lt;/b&gt; : this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Dynamic code injection&lt;/b&gt;: you can generate native code dynamically with a callback interface that is called by the JIT when compilation of a method is occurring. It means that you can compile a method “on the fly”. You have also access to the IL code of the method being compiled.&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;&lt;b&gt;Supports for debugging&lt;/b&gt; static and dynamic code injection.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl&lt;/b&gt;. Default calling convention is CLRCall.&lt;/li&gt;&lt;li&gt;NetAsm can be used inside &lt;b&gt;any .NET language&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Very &lt;b&gt;small library&lt;/b&gt; &amp;lt;100Ko.&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;
Future plans
&lt;/h2&gt;You are welcome to vote for the following features (or any new features) or even contribute to one of them if you have a good experience in such domain:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Add a simplified assembler to code inject textual __asm instructions from CodeInjection attribute?&lt;/li&gt;&lt;li&gt;Add support for 64bit platform?&lt;/li&gt;&lt;li&gt;Add support for Mono platform?&lt;/li&gt;
&lt;/ul&gt;&lt;h1&gt;
HelloWorld example
&lt;/h1&gt;This sample is available in NetAsmDemo and is fully documented in the the NetAsm User guide.&lt;br /&gt; &lt;br /&gt;Using native code injection with NetAsm is a very simple task that can be achieved in two steps:&lt;br /&gt;1)	Specify the native code injection in a class&lt;br /&gt;2)	Install the hook in the main program of your application&lt;br /&gt;&lt;h2&gt;
Setup native code injection in a class
&lt;/h2&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System.Runtime.CompilerServices;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    [AllowCodeInjection]
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; TestHelloWorld
    {
        [CodeInjection(&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;byte&lt;/span&gt;[] { 0xC3 }), MethodImpl(MethodImplOptions.NoInlining)]
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; NetAsmReturn()
        {
            &lt;span style="color:#0000FF;"&gt;throw&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; Exception(&lt;span style="color:#A31515;"&gt;&amp;quot;With NetAsm, You should not have an exception!&amp;quot;&lt;/span&gt;);
        }
    }
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The steps to allow and use code injection on a method in a class are:&lt;br /&gt; &lt;br /&gt;1.	Set &lt;b&gt;AllowCodeInjection&lt;/b&gt; attribute on the class you want to do code injection.&lt;br /&gt;2.	Set &lt;b&gt;CodeInjection&lt;/b&gt; attribute on the method that will be injected with native code&lt;br /&gt;3.	For void NetAsmReturn() method in TestHelloWorld, the native code used is : new byte[] { 0xC3 }. In x86 assembler, it’s the “RET” (return) command. This method does nothing more than immediately returning after a call. &lt;br /&gt;4.	In our example, we have set the attribute MethodImpl(MethodImplOptions.NoInlining) : This attribute force the JIT to not inline the IL code inside the method. This is for the purpose of the demonstration but should be used with caution (see usage recommendation chapter).&lt;br /&gt; &lt;br /&gt;That’s all to use code injection! &lt;br /&gt;In NetAsm, this kind of native code injection is called static native code injection. TestHelloWorld only use static code injection at the method level. We will see later that NetAsm provides other code injection techniques.&lt;br /&gt;Now, to run this code injection test, we need to install NetAsm &lt;b&gt;JITHook.Install()&lt;/b&gt;.&lt;br /&gt;&lt;h2&gt;
Install the hook and run the code injection
&lt;/h2&gt;To call the &lt;b&gt;TestHelloWorld&lt;/b&gt; method, the main program has to initialize NetAsm:&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; System;
&lt;span style="color:#0000FF;"&gt;using&lt;/span&gt; NetAsm;
&lt;span style="color:#0000FF;"&gt;namespace&lt;/span&gt; NetAsmDemo
{
    &lt;span style="color:#0000FF;"&gt;class&lt;/span&gt; Program
    {
        &lt;span style="color:#0000FF;"&gt;static&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;void&lt;/span&gt; Main(&lt;span style="color:#0000FF;"&gt;string&lt;/span&gt;[] args)
        {
            &lt;span style="color:#008000;"&gt;// Install the JIT Hook&lt;/span&gt;
            JITHook.Install();
            &lt;span style="color:#008000;"&gt;// Run TestHelloWorld Method&lt;/span&gt;
            TestHelloWorld.NetAsmReturn();
            &lt;span style="color:#008000;"&gt;// Remove the JIT Hook&lt;/span&gt;
            JITHook.Remove();
        }
    }
}
&lt;/pre&gt;&lt;/div&gt;If you run this program, it will return without any exception. While executing this code, the CLR Virtual Machine use our native code “RET” command instead of the IL code inside the method. It means that the original IL code is not compiled by the default JIT compiler.&lt;br /&gt; &lt;br /&gt;Additionnal information and other code injection techniques are available in the NetAsm User Guide.&lt;br /&gt;
&lt;/div&gt;</description><author>alexandre_mutel</author><pubDate>Thu, 07 Aug 2008 08:52:27 GMT</pubDate><guid isPermaLink="false">Updated Wiki: Home 20080807085227A</guid></item><item><title>Updated Wiki: benchmarks</title><link>http://www.codeplex.com/netasm/Wiki/View.aspx?title=benchmarks&amp;version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;h2&gt;
Benchmarks
&lt;/h2&gt;NetAsmDemo provides two micro-benchmarks to explicit performance gains using NetAsm:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Simple Add Benchmark&lt;/b&gt; is a benchmark that demonstrates the overhead of calling methods using different managed, interop techniques against NetAsm.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Matrix Multiplication Benchmark SSE2&lt;/b&gt; is a benchmark that demonstrates the use of SSE2 for optimized methods and compare different calling techniques (interop, mixed, managed and NetAsm).&lt;/li&gt;
&lt;/ul&gt;The main results are:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;For calling overhead, NetAsm can perform as fast as pure managed calls and is two times faster than fast interop&lt;/b&gt; (no security checks).&lt;/li&gt;&lt;li&gt;In the case of using optimized instructions not available in .NET (like SSE2 in the matrix benchmark), &lt;b&gt;NetAsm was able to be 50-60% faster than managed code&lt;/b&gt;.&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Although, be aware that micro-benchmarks are always subject to issues and should not be considered as a proof for any other benchmarks. All the benchmarks here use a warm-up loop to avoid the cost of any compilation effects at startup and run the test several times.&lt;br /&gt;&lt;h2&gt;
Simple Add benchmark
&lt;/h2&gt;This benchmark consists in measuring the processing time for adding 2 integers. This benchmark measure the performance between several implementations:&lt;br /&gt;• Managed and Managed Inline : we test both managed with NoInline  (with the attribute &lt;b&gt;MethodImpl(MethodImplOptions.NoInlining)&lt;/b&gt;)  and the default managed code inline.&lt;br /&gt;• Interop and Interop NoSecurity : we test default Interop technique and Interop with no security attribute flag (&lt;b&gt;SuppressUnmanagedCodeSecurity&lt;/b&gt;)&lt;br /&gt;• Mixed Cpp/CLI : we test  the use of an external Mixed Cpp/CLI using native code.&lt;br /&gt;• NetAsm : we use NetAsm with a static native code injection.&lt;br /&gt; &lt;br /&gt;For example, the implementation of the Managed Inline is like:&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
        &lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; ManagedAddInlined(&lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; y)
        {
            &lt;span style="color:#0000FF;"&gt;return&lt;/span&gt; x + y;
        }
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;The NetAsm code of the Add method is:&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
[CodeInjection(&lt;span style="color:#0000FF;"&gt;new&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;byte&lt;/span&gt;[] { 0x8b, 0x44, 0x24, 0x04, 0x03, 0xc2, 0xc2, 0x04, 0x00 }), MethodImpl(MethodImplOptions.NoInlining)]
&lt;span style="color:#0000FF;"&gt;public&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; NetAsmAdd(&lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; y)
{
    &lt;span style="color:#008000;"&gt;// This method is compiled using the native code from the CodeInjection Attribute&lt;/span&gt;
    &lt;span style="color:#008000;"&gt;// The IL code of this method is never compiled by the JIT &lt;/span&gt;
    &lt;span style="color:#008000;"&gt;// ADD +1 to check that this method is not used.&lt;/span&gt;
    &lt;span style="color:#0000FF;"&gt;return&lt;/span&gt; x + y + 1;
}
&lt;/pre&gt;&lt;/div&gt; &lt;br /&gt;It was generated from the C method and the assembler code was copied from the *.cod output assembler listing files generated by Microsoft visual C++ :&lt;br /&gt;&lt;div style="color:#000000;background-color:#FFFFFF;"&gt;&lt;pre&gt;
&lt;span style="color:#0000FF;"&gt;extern&lt;/span&gt; &lt;span style="color:#A31515;"&gt;&amp;quot;C&amp;quot;&lt;/span&gt; &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; __fastcall NetAsmAddInC(&lt;span style="color:#0000FF;"&gt;void&lt;/span&gt;* pThis, &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; x, &lt;span style="color:#0000FF;"&gt;int&lt;/span&gt; y) {
	&lt;span style="color:#0000FF;"&gt;return&lt;/span&gt; x + y;
}
&lt;span style="color:#008000;"&gt;// The generated native code of this method is :&lt;/span&gt;
  00000	8b 44 24 04	 mov	 eax, DWORD PTR _y$[esp-4]
  00004	03 c2		 add	 eax, edx
  00006	c2 04 00	 ret	 4
&lt;/pre&gt;&lt;/div&gt;Results are indexed on a 100 time based. The default base is managed inline. Lower is better. &lt;br /&gt;&lt;img src="http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=netasm&amp;amp;DownloadId=39809" alt="SimpleAddBenchmark.png" /&gt;&lt;br /&gt; &lt;br /&gt;As we can see, NetAsm performs almost as fast as Managed Inline and is twice faster than the Interop (with no security checks).&lt;br /&gt;This result was expected, as NetAsm native code is considered by the CLR VM as pure managed code compiled by the JIT. Therefore, the performance should be the same than managed code.&lt;br /&gt; &lt;br /&gt;See TestSimpleAddBenchmark.cs in NetAsmDemo for the code of this benchmark.&lt;br /&gt; &lt;br /&gt;&lt;h2&gt;
Matrix Multiplication benchmark using SSE2
&lt;/h2&gt;This benchmark is based on the work of scapecode in the article &lt;a href="http://scapecode.com/archive/2007/04/28/Playing-with-the-.NET-JIT-Part-3.aspx" class="externalLink"&gt;&amp;quot;Playing with the .NET JIT Part3&amp;quot;&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt; : it measures the performance between different matrix multiplications implementations using standard CLR, standard C and SSE2 instructions.&lt;br /&gt;As for SimpleAddBenchmark, this benchmark compares different implementations:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Managed Std&lt;/b&gt; and &lt;b&gt;Managed Unsafe&lt;/b&gt;: we test both standard managed code and unsafe managed code (using pointers on matrix array instead of CLR arrays).&lt;/li&gt;&lt;li&gt;&lt;b&gt;Interop Std&lt;/b&gt; and &lt;b&gt;Interop SSE2&lt;/b&gt;, and &lt;b&gt;Interop SSE2 NoSecurity&lt;/b&gt; : we test default Interop technique with a C implementation (without using any SSE2 instructions), and two interop using SSE2 (with one using the no security attribute flag &lt;b&gt;SuppressUnmanagedCodeSecurity&lt;/b&gt; )&lt;/li&gt;&lt;li&gt;&lt;b&gt;Mixed SSE2 Cpp/CLI&lt;/b&gt; : we test  the use of an external Mixed Cpp/CLI using native code.&lt;/li&gt;&lt;li&gt;&lt;b&gt;NetAsm Std&lt;/b&gt; and &lt;b&gt;NetAsm SSE2&lt;/b&gt;: we use NetAsm with a standard C matrix multiplication and a SSE2 implementations.&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;Results are indexed on a 100 time based. The default base is managed inline. Lower is better.&lt;br /&gt;&lt;img src="http://www.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=netasm&amp;amp;DownloadId=39810" alt="MatrixMultiplicationBenchmark.png" /&gt;&lt;br /&gt; &lt;br /&gt;There are several remarks concerning the results:&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;First, &lt;b&gt;NetAsm SSE2 outperforms any other implementations&lt;/b&gt;, ranging from 10% to 300% in speed gain (70% faster than the default managed code).&lt;/li&gt;&lt;li&gt;&lt;b&gt;Managed Unsafe and NetAsm unsafe are often equivalent&lt;/b&gt;: it means that the default JIT compiler is performing very well in optimizing the C# code (as fast as C code). Consequently, you should always test if it is relevant to replace managed code with c code, as the JIT compiler can generate a fast native code.&lt;/li&gt;&lt;li&gt;&lt;b&gt;NetAsm SSE2 is only 10% faster than Interop SSE2&lt;/b&gt;: this result is different from SimpleAddBenchmark. The reason is the cost of calling the interop code is negligible compare to the time used for computing the result.&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;See TestMatrixMulBenchmark.cs, NetAsmDemoCLib.dll and NetAsmDemoMixedLib.dll in NetAsmDemo for the code of this benchmark.&lt;br /&gt;
&lt;/div&gt;</description><author>alexandre_mutel</author><pubDate>Fri, 25 Jul 2008 22:02:39 GMT</pubDate><guid isPermaLink="false">Updated Wiki: benchmarks 20080725100239P</guid></item></channel></rss>