[Mono-bugs] [Bug 375249] New: Performance of Math.Max and Math.Min ( missing predicate instructions)

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Mar 30 07:27:28 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=375249

User msafar at novell.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=375249#c373269

           Summary: Performance of Math.Max and Math.Min (missing predicate
                    instructions)
           Product: Mono: Runtime
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: JIT
        AssignedTo: lupus at novell.com
        ReportedBy: msafar at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Mono JIT does not use predicated instruction (cmovle, cmovge). Those
instructions are widely available (ARM, Alpha, x86 since PPro) and should bring
quite good performance boost.

A sample and results are extracted from #373269


using System;

class Program {

        static void Main (string[] args)
        {
                long value = 0;
                for (int i = 0; i < Int16.MaxValue; i++) {
                        for (int j = Int16.MaxValue; j >= 0; j--) {
#if false
                                value += Math.Max (i, j);
                                value -= Math.Min (i, j);
#else
                                value += (i > j) ? i : j;
                                value -= (i < j) ? i : j;
#endif
                        }
                }
                Console.WriteLine (value);
        }
}


Here are the result from running same test on my machine, Intel(R) Core(TM)2
CPU T7200  @ 2.00GHz

Best of 5 runs

-- Mono runtime --

# using Math.Min|Max

~ 20.0 seconds

# using manually inlined code 

~ 24.5 seconds


-- Microsoft runtime --

# using Math.Min|Max

~ 4.8 seconds

# using manually inlined code 

~ 7.9 seconds


Those results are not consistent as you can see in #373269.


When looking at x86 code generated by Mono JIT, there are no predicate
instructions used. However, I don't know whether Mono JIT is capable to use
cmovle anywhere or whether it has to be customized for Math.Min only.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list