I would like to share with the .NET community, the NetAsm opensource project available on codeplex.
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/PInvoke calls. With this library, it is possible for example to inject highly optimized code (using SSE, MMX) inside a method, in replacement of the default generated native code by the JIT compiler.
This library could be particularly useful for game using .NET platform (XNA for example), as it provides a way to integrate fast native code for methods that need highly optimized native code.
The current features of NetAsm are:
- Runs on x86 32bit Microsoft .NET platform with 2.0+ CLR runtime (x64 may be supported in the future
- Provides three different native code injection techniques: Static, DLL, and Dynamic
- Static code injection: The native code is stored in an attribute of the method.
- Dll code injection: this method is similar to the DllImport mechanism but CLR methods are directly bind to the DLL function, without going through the interop layers.
- Dynamic code injection: 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.
- Supports for debugging static and dynamic code injection.
- Supports for different calling conventions: StdCall, FastCall, ThisCall, Cdecl. Default calling convention is CLRCall
- NetAsm can be used inside any .NET language (you can run assembler code inside VB!)
- Very small library <100Ko.
For additional information and documentation, please visit the NetAsm codeplex site.
Alexandre