[Mono-dev] mcs math performance enhancement
marek.safar at seznam.cz
Wed Oct 24 05:21:19 EDT 2007
> As C# does not have an exponentiation operato, programmers will
> typically use the
> expression "x*x" to get a square of x. There is Math.Pow, but only for
> doubles and likely
> to be inefficient for this simple case. This is a fairly common idiom
> even for C/C++ math programmers who can use pow(T,int).
> Mcs (184.108.40.206 release) does not recognize this special case, and emits
> two loads for the variable (or struct or class field, which is
> longer), instead of the obvious dup-mul sequence (which can easily
> identify the "calculate square" idiom for JIT)
The only scenario which can benefit from this change is when both of
are same instance variables. In all other cases this would produce
or slower code.
I have not found such case in any of Mono source codes and because this
optimizations should be done at JIT level, the patch is not worth applying.
More information about the Mono-devel-list