[Mono-dev] Question about adding opcodes

Alex Rønne Petersen alex at alexrp.com
Sun Jun 1 13:16:22 UTC 2014


Hi,

On Sun, Jun 1, 2014 at 2:58 PM, Steven Bluen <sbluen153 at yahoo.com> wrote:
> Hello,
>
> I am trying to add an opcode to Mono's JIT compiler and its interpreter to allow Mono to compile and run applications so that I can make a frequently used operation in a C# program run faster. To keep things simple and avoid the need for parsing, this opcode is invoked through dynamic methods.

Adding it to the interpreter is not worth it. The interpreter is
bitrotted to the point of obscurity.

>
> I am able to get Mono's JIT compiler to stop at a breakpoint in mono/mini/method-to-ir.c at the point where the opcode is added to the method's intermediate representation. However, it would be much appreciated if someone could let me know which component, source code file, or function of Mono's interpreter is responsible for interpreting the instructions that form the body of a dynamic method.

They're parsed like any other method (from an on-disk CIL assembly).
This parsing is based on the tables in mono/cil/ and is done in
mono_method_to_ir () in mono/mini/method-to-ir.c. The CIL stream is
simply interpreted directly. If you're adding a new CIL opcode
(different from an IR opcode), add it in mono/cil/cil-opcodes.xml and
handle it in mono_method_to_ir (). If you plan to also add an IR
opcode (or several), you may want to consider intercepting an
intrinsic method call instead of using a custom CIL opcode. This'll be
portable to MS.NET as MS.NET will then just use the managed fallback.

Regards,
Alex


More information about the Mono-devel-list mailing list