# . JIT IL, #, IL () .
Take an earlier example:
static int Func(int a, int b, int c)
{
int x = a * 2;
int y = b * 3;
int z = c * 4;
return x + y + z;
}
The emitted IL from compiler 3.5 with optimizations turned on is as follows:
.method private hidebysig static int32 Func(int32 a,
int32 b,
int32 c) cil managed
{
// Code size 18 (0x12)
.maxstack 2
.locals init (int32 V_0,
int32 V_1,
int32 V_2)
IL_0000: ldarg.0
IL_0001: ldc.i4.2
IL_0002: mul
IL_0003: stloc.0
IL_0004: ldarg.1
IL_0005: ldc.i4.3
IL_0006: mul
IL_0007: stloc.1
IL_0008: ldarg.2
IL_0009: ldc.i4.4
IL_000a: mul
IL_000b: stloc.2
IL_000c: ldloc.0
IL_000d: ldloc.1
IL_000e: add
IL_000f: ldloc.2
IL_0010: add
IL_0011: ret
} // end of method test::Func
Not very optimal? I compile it into an executable, calling it from a simple Main method, and the compiler does not insert it or does any optimizations really.
So what happens at runtime?
JIT actually points to a Func () call and gives much better code than you can imagine by looking at the IL based on the stack above:
mov edx,dword ptr [rbx+10h]
mov eax,1
cmp rax,rdi
jae 000007ff`00190265
mov eax,dword ptr [rbx+rax*4+10h]
mov ecx,2
cmp rcx,rdi
jae 000007ff`00190265
mov ecx,dword ptr [rbx+rcx*4+10h]
add edx,edx
lea eax,[rax+rax*2]
shl ecx,2
add eax,edx
lea esi,[rax+rcx]
source
share