[Mono-dev] JIT floating point behaviour change between 2.4.2 and 2.6

Lucas Meijer lucas at lucasmeijer.com
Tue Jan 12 10:27:22 EST 2010


Hi,

In our process to upgrade to mono 2.6, we've hit a snag where floating 
point behaviour of the JIT is slightly differently. This program prints 
"PASS" on mono2.6, and "FAIL" on mono2.4, on both osx, and win32.

using System;

public class Test
{
         static private float x;
         static private float y;

         private static void Main()
         {
                 //input
                 float a = DecodeSingle(0x3070787f);
                 float b = DecodeSingle(0x48a296ba);
                 float c = DecodeSingle(0x3ddc0d93);

                 x = DecodeSingle(0xbfc2f2e5);
                 y = DecodeSingle(0xbd35e18b);

                 // test
                 float abc = (a * b * c);

                 float s = ((a * b * c) / sqrMagnitude);
//same calculation,just using a temporary variable, which seems to matter
                 float t = ((abc) / sqrMagnitude);

                 Console.WriteLine("Test: {0}", ((s == t) ? "PASSED" : 
"FAILED"));
         }

         static private float sqrMagnitude
         {
                 get { return ((x * x) + (y * y)); }
         }

         private static float DecodeSingle(uint value)
         {
                 return 
BitConverter.ToSingle(BitConverter.GetBytes(value), 0);
         }
}

The good news is that mono2.6 behaviour looks correct, and Mono2.4 
behaviour wrong. I would really like to find out which svn revision has 
caused this change. We like the new behaviour, but want to temporarily 
get the old behaviour back, so we can succesfully run all our 
integrationtests, and feel confident that the mono upgrade didn't break 
anything. Because of the floating point difference, it's causing a lot 
of games in our regression suite to play back completely differently, 
which makes it hard to see if something else changed as well, or if the 
different playback is purely due to the floating point differences.

I hope one of the JIT guys has a rough guess where this change might 
have been introduced,  if not I'll start a the big boring svn based 
binary search.

Thanks in advance,

   Lucas


More information about the Mono-devel-list mailing list