[Mono-dev] mcs math performance enhancement

Marek Safar marek.safar at seznam.cz
Wed Oct 24 05:21:19 EDT 2007


Hello Jaroslav,
> problem:
> 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 (1.2.5.1 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 
operands
are same instance variables. In all other cases this would produce 
either invalid
or slower code.

I have not found such case in any of Mono source codes and because this 
kind of
optimizations should be done at JIT level, the patch is not worth applying.

Thanks
Marek



More information about the Mono-devel-list mailing list