[Mono-devel-list] ilasm questions

Bart Van Rompaey bart at perfectpc.be
Thu Jan 15 16:52:02 EST 2004

I hope this is the right newsgroup.
While looking into ilasm generated by Mono and ms.NET, I noticed two
major differences:
1) Mono doesn't make use of the short branch instructions (ex. bge.s). I
presume using this could mean some runtime performance improvement?
2) ms.net generates some weird code in case of branches. Let me give an

public static int fib (int n) {
	if (n < 2)
		return 1;
	return fib(n-2)+fib(n-1);

The if structures translates to:


IL_0000:  ldarg.0
IL_0001:  ldc.i4.2
IL_0002:  bge.s IL_0008
IL_0004:  ldc.i4.1
IL_0005:  stloc.0
IL_0006:  br.s IL_001c
IL_0008:  ldarg.0
IL_001c:  ldloc.0
IL_001d:  ret

IL_0000:  ldarg.0
IL_0001:  ldc.i4.2
IL_0002:  bge IL_0009
IL_0007:  ldc.i4.1
IL_0008:  ret
IL_0009:  ldarg.0
... (rest of method)

Why would ms.net compile into that sequence of instructions? It has an
extra store/load and and an extra branch instruction? Does anyone see
some advantages of that?


More information about the Mono-devel-list mailing list