2008-01-25 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / basic-long.cs
index 1e879fa01346b07b3465970565daaeb8b79d5108..9173b789293db4526f615ff19be107ad5fc44192 100644 (file)
@@ -160,6 +160,19 @@ class Tests {
 
                return (int)a;
        }
+
+       public static int test_32_conv_to_u4 () {
+               long a = 32;
+
+               return (int)(uint)a;
+       }
+
+       public static int test_15_conv_to_u4_2 () {
+               long a = 0x10000000f;
+
+               return (int)(uint)a;
+       }
+
        public static int test_0_conv_from_i4 () {
                long a = 2;
                if (a != 2)
@@ -184,6 +197,23 @@ class Tests {
                return 0;
        }
 
+       public static int test_0_conv_to_r8 () {
+               long a = 150;
+               double b = (double) a;
+
+               if (b != 150.0)
+                       return 1;
+               return 0;
+       }
+
+       public static int test_0_conv_to_r4 () {
+               long a = 3000;
+               float b = (float) a;
+
+               if (b != 3000.0F)
+                       return 1;
+               return 0;
+       }
        /*
        public static int test_0_conv_from_r8 () {
                double b = 2.0;
@@ -285,6 +315,157 @@ class Tests {
                return (int)((a - 1) + 1);
        }
 
+       public static int test_0_add_ovf () {
+               long i, j, k;
+
+               checked {
+                       i = System.Int64.MinValue;
+                       j = 0;
+                       k = i + j;
+               }
+
+               if (k != System.Int64.MinValue)
+                       return 1;
+
+               checked {
+                       i = System.Int64.MaxValue;
+                       j = 0;
+                       k = i + j;
+               }
+
+               if (k != System.Int64.MaxValue)
+                       return 2;
+
+               checked {
+                       i = System.Int64.MinValue;
+                       j = System.Int64.MaxValue;
+                       k = i + j;
+               }
+
+               if (k != -1)
+                       return 3;
+
+               checked {
+                       i = System.Int64.MaxValue;
+                       j = System.Int64.MinValue;
+                       k = i + j;
+               }
+
+               if (k != -1)
+                       return 4;
+
+               checked {
+                       i = System.Int64.MinValue + 1234;
+                       j = -1234;
+                       k = i + j;
+               }
+
+               if (k != System.Int64.MinValue)
+                       return 5;
+
+               checked {
+                       i = System.Int64.MaxValue - 1234;
+                       j = 1234;
+                       k = i + j;
+               }
+
+               if (k != System.Int64.MaxValue)
+                       return 6;
+
+               return 0;
+       }
+
+       public static int test_0_add_un_ovf () {
+               ulong n = (ulong)134217728 * 16;
+               ulong number = checked (n + (uint)0);
+
+               return number == n ? 0 : 1;
+       }
+
+       public static int test_0_sub_ovf () {
+               long i, j, k;
+
+               checked {
+                       i = System.Int64.MinValue;
+                       j = 0;
+                       k = i - j;
+               }
+
+               if (k != System.Int64.MinValue)
+                       return 1;
+
+               checked {
+                       i = System.Int64.MaxValue;
+                       j = 0;
+                       k = i - j;
+               }
+
+               if (k != System.Int64.MaxValue)
+                       return 2;
+
+               checked {
+                       i = System.Int64.MinValue;
+                       j = System.Int64.MinValue + 1234;
+                       k = i - j;
+               }
+
+               if (k != -1234)
+                       return 3;
+
+               checked {
+                       i = System.Int64.MaxValue;
+                       j = 1234;
+                       k = i - j;
+               }
+
+               if (k != System.Int64.MaxValue - 1234)
+                       return 4;
+
+               checked {
+                       i = System.Int64.MaxValue - 1234;
+                       j = -1234;
+                       k = i - j;
+               }
+
+               if (k != System.Int64.MaxValue)
+                       return 5;
+
+               checked {
+                       i = System.Int64.MinValue + 1234;
+                       j = 1234;
+                       k = i - j;
+               }
+
+               if (k != System.Int64.MinValue)
+                       return 6;
+
+               return 0;
+       }
+
+       public static int test_0_sub_ovf_un () {
+               ulong i, j, k;
+
+               checked {
+                       i = System.UInt64.MaxValue;
+                       j = 0;
+                       k = i - j;
+               }
+
+               if (k != System.UInt64.MaxValue)
+                       return 1;
+
+               checked {
+                       i = System.UInt64.MaxValue;
+                       j = System.UInt64.MaxValue;
+                       k = i - j;
+               }
+
+               if (k != 0)
+                       return 2;
+
+               return 0;
+       }
+
        public static int test_2_neg () {
                long a = -2;            
                return (int)(-a);
@@ -298,27 +479,6 @@ class Tests {
                }
        }       
 
-       public static int test_0_shl () {
-               long a = 9;
-               int b = 1;
-               
-               if ((a >> b) != 4)
-                       return 1;
-
-
-               return 0;
-       }
-       
-       public static int test_1_rshift ()
-       {
-               long a = 9;
-               int b = 1;
-               a = -9;
-               if ((a >> b) != -5)
-                       return 0;
-               return 1;
-       }
-
        public static int test_5_shift ()
        {
                long a = 9;
@@ -363,6 +523,22 @@ class Tests {
                return count;
        }
 
+       public static int test_1_shift_u_32 ()
+       {
+               ulong a;
+               int count = 0;
+
+               a = UInt64.MaxValue;
+               // Avoid constant folding
+               for (int i = 0; i < 32; ++i)
+                       count ++;
+
+               if ((a >> count) != 0xFFFFFFFFUL)
+                       return 0;
+               else
+                       return 1;
+       }
+
        public static int test_1_simple_neg () {
                long a = 9;
                
@@ -458,6 +634,93 @@ class Tests {
                }
                return (int)res;
        }       
+
+       public static int test_0_mul_imm () {
+           long i = 4;
+
+               if ((i * 0) != 0)
+                       return 1;
+               if ((i * 1) != 4)
+                       return 2;
+               if ((i * 2) != 8)
+                       return 3;
+               if ((i * 3) != 12)
+                       return 4;
+               if ((i * 1234) != 4936)
+                       return 5;
+               if ((i * -1) != -4)
+                       return 6;
+               if ((i * -2) != -8)
+                       return 7;
+               if ((i * -3) != -12)
+                       return 8;
+               if ((i * -1234) != -4936)
+                       return 9;
+
+               return 0;
+       }
+
+       public static int test_0_mul_imm_opt ()
+       {
+               long i;
+
+               i = 1;
+               if ((i * 2) != 2)
+                       return 1;
+               i = -1;
+               if ((i * 2) != -2)
+                       return 2;
+               i = 1;
+               if ((i * 3) != 3)
+                       return 3;
+               i = -1;
+               if ((i * 3) != -3)
+                       return 4;
+               i = 1;
+               if ((i * 5) != 5)
+                       return 5;
+               i = -1;
+               if ((i * 5) != -5)
+                       return 6;
+               i = 1;
+               if ((i * 6) != 6)
+                       return 7;
+               i = -1;
+               if ((i * 6) != -6)
+                       return 8;
+               i = 1;
+               if ((i * 9) != 9)
+                       return 9;
+               i = -1;
+               if ((i * 9) != -9)
+                       return 10;
+               i = 1;
+               if ((i * 10) != 10)
+                       return 11;
+               i = -1;
+               if ((i * 10) != -10)
+                       return 12;
+               i = 1;
+               if ((i * 12) != 12)
+                       return 13;
+               i = -1;
+               if ((i * 12) != -12)
+                       return 14;
+               i = 1;
+               if ((i * 25) != 25)
+                       return 15;
+               i = -1;
+               if ((i * 25) != -25)
+                       return 16;
+               i = 1;
+               if ((i * 100) != 100)
+                       return 17;
+               i = -1;
+               if ((i * 100) != -100)
+                       return 18;
+               
+               return 0;
+       }
        
        public static int test_4_divun () {
                uint b = 12;
@@ -683,19 +946,6 @@ class Tests {
 
                return (int)res;
        }
-
-       static long position = 0;
-
-       public static int test_4_static_inc_long () {
-
-               int count = 4;
-
-               position = 0;
-
-               position += count;
-
-               return (int)position;
-       }
        
        static void doit (double value, out long m) {
                m = (long) value;
@@ -780,59 +1030,16 @@ class Tests {
                return 0;
        }
 
-       public static int test_71_long_shift_right () {
-               ulong value = 38654838087;
-               int x = 0;
-               byte [] buffer = new byte [1];
-               buffer [x] = ((byte)(value >> x));
-               return buffer [x];
-       }
-
        public static int test_0_ulong_regress () {
                ulong u = 4257145737;
                u --;
                return (u == 4257145736) ? 0 : 1;
        }
-       
-       static long x;
-       public static int test_0_addsub_mem ()
-       {
-               x = 0;
-               x += 5;
-               
-               if (x != 5)
-                       return 1;
-               
-               x -= 10;
-               
-               if (x != -5)
-                       return 2;
-               
-               return 0;
-       }
-       
-       static ulong y;
-       public static int test_0_sh32_mem ()
-       {
-               y = 0x0102130405060708;
-               y >>= 32;
-               
-               if (y != 0x01021304)
-                       return 1;
-               
-               y = 0x0102130405060708;
-               y <<= 32;
-               
-               if (y != 0x0506070800000000)
-                       return 2;
-               
-               x = 0x0102130405060708;
-               x <<= 32;
-               
-               if (x != 0x0506070800000000)
-                       return 2;
-               
-               return 0;
+
+       public static int test_0_ulong_regress2 () {
+               int p2 = 31;
+               ulong sum_p = 2897079476 + (ulong) (1 << p2);
+               return (sum_p == 749595828) ? 0 : 1;
        }
        
        public static int test_0_assemble_long ()
@@ -867,5 +1074,22 @@ class Tests {
 
                return ((a >> (b - c)) == 0) ? 0 : 1;
        }
+
+       public static int test_1234_conv_ovf_u8 () {
+               int i = 1234;
+
+               checked {
+                       ulong l = (ulong)i;
+                       return (int)l;
+               }
+       }
+
+       public static int test_0_regress_cprop_80738 () {
+               int hours = Int32.MinValue;
+               int hrssec = (hours * 3600);
+               long t = ((long)(hrssec) * 1000L);
+
+               return t == 0 ? 0 : 1;
+       }
 }