c# - How does .NET JIT determine how to add numbers -


cil has single opcode adding numbers without overflow check - add.

this c# code:

int = 10; int b = 20; int c = + b; 

produces following il code:

il_0000:  ldc.i4.s   10 il_0002:  stloc.0 il_0003:  ldc.i4.s   20 il_0005:  stloc.1 il_0006:  ldloc.0 il_0007:  ldloc.1 il_0008:  add il_0009:  stloc.2 

how jit @ run-time determine, type of x86 addition should use (fpu opcode faddp floats or add integers)?

the clr tracks types of values on evaluation stack, knows right before add instruction, types of 2 topmost values on stack int32 in code. means knows has emit instruction adding 32-bit integers.

if write code clr won't able figure out types of operands of add, code unverifiable , result in garbage native code.


Popular posts from this blog