Merge pull request #601 from knocte/sock_improvements
[mono.git] / mono / mini / basic.cs
index 9ef9afef1369a754ae0ffb7e87c81e6a1f7f3795..b9cf91347b2cf11ec9c5cbc8f0071809989fec5d 100644 (file)
@@ -25,8 +25,8 @@ using System.Reflection;
 
 class Tests {
 
-       static int Main () {
-               return TestDriver.RunTests (typeof (Tests));
+       public static int Main (string[] args) {
+               return TestDriver.RunTests (typeof (Tests), args);
        }
        
        public static int test_0_return () {
@@ -152,6 +152,16 @@ class Tests {
                return b / 2;
        }
 
+       public static int test_2_div_fold4 () {
+               int b = -8;
+               return -(b / 4);
+       }
+
+       public static int test_2_div_fold16 () {
+               int b = 32;
+               return b / 16;
+       }
+
        public static int test_719177_div_destreg () {
                int year = 1970;
                return ((365* (year-1)) + ((year-1)/4));
@@ -180,6 +190,16 @@ class Tests {
                return b % 8;
        }
 
+       public static int test_0_rem_imm_0 () {
+               int b = 12;
+               return b % 1;
+       }
+
+       public static int test_0_rem_imm_0_neg () {
+               int b = -2;
+               return b % 1;
+       }
+
        public static int test_4_rem_big_imm () {
                int b = 10004;
                return b % 10000;
@@ -240,7 +260,7 @@ class Tests {
                return (int)res;
        }
 
-       public static int test_0_add_ovf () {
+       public static int test_0_add_ovf1 () {
                int i, j, k;
 
                checked {
@@ -251,6 +271,11 @@ class Tests {
 
                if (k != System.Int32.MinValue)
                        return 1;
+               return 0;
+       }
+
+       public static int test_0_add_ovf2 () {
+               int i, j, k;
 
                checked {
                        i = System.Int32.MaxValue;
@@ -260,6 +285,11 @@ class Tests {
 
                if (k != System.Int32.MaxValue)
                        return 2;
+               return 0;
+       }
+
+       public static int test_0_add_ovf3 () {
+               int i, j, k;
 
                checked {
                        i = System.Int32.MinValue;
@@ -269,6 +299,11 @@ class Tests {
 
                if (k != -1)
                        return 3;
+               return 0;
+       }
+
+       public static int test_0_add_ovf4 () {
+               int i, j, k;
 
                checked {
                        i = System.Int32.MaxValue;
@@ -278,6 +313,11 @@ class Tests {
 
                if (k != -1)
                        return 4;
+               return 0;
+       }
+
+       public static int test_0_add_ovf5 () {
+               int i, j, k;
 
                checked {
                        i = System.Int32.MinValue + 1234;
@@ -287,6 +327,11 @@ class Tests {
 
                if (k != System.Int32.MinValue)
                        return 5;
+               return 0;
+       }
+
+       public static int test_0_add_ovf6 () {
+               int i, j, k;
 
                checked {
                        i = System.Int32.MaxValue - 1234;
@@ -307,7 +352,7 @@ class Tests {
                return number == n ? 0 : 1;
        }
 
-       public static int test_0_sub_ovf () {
+       public static int test_0_sub_ovf1 () {
                int i, j, k;
 
                checked {
@@ -319,6 +364,12 @@ class Tests {
                if (k != System.Int32.MinValue)
                        return 1;
 
+               return 0;
+       }
+
+       public static int test_0_sub_ovf2 () {
+               int i, j, k;
+
                checked {
                        i = System.Int32.MaxValue;
                        j = 0;
@@ -328,6 +379,12 @@ class Tests {
                if (k != System.Int32.MaxValue)
                        return 2;
 
+               return 0;
+       }
+
+       public static int test_0_sub_ovf3 () {
+               int i, j, k;
+
                checked {
                        i = System.Int32.MinValue;
                        j = System.Int32.MinValue + 1234;
@@ -337,6 +394,12 @@ class Tests {
                if (k != -1234)
                        return 3;
 
+               return 0;
+       }
+
+       public static int test_0_sub_ovf4 () {
+               int i, j, k;
+
                checked {
                        i = System.Int32.MaxValue;
                        j = 1234;
@@ -346,6 +409,12 @@ class Tests {
                if (k != System.Int32.MaxValue - 1234)
                        return 4;
 
+               return 0;
+       }
+
+       public static int test_0_sub_ovf5 () {
+               int i, j, k;
+
                checked {
                        i = System.Int32.MaxValue - 1234;
                        j = -1234;
@@ -355,6 +424,12 @@ class Tests {
                if (k != System.Int32.MaxValue)
                        return 5;
 
+               return 0;
+       }
+
+       public static int test_0_sub_ovf6 () {
+               int i, j, k;
+
                checked {
                        i = System.Int32.MinValue + 1234;
                        j = 1234;
@@ -610,7 +685,21 @@ class Tests {
                        return 1;
                else
                        return 0;
-       }               
+       }
+
+       public static int test_127_iconv_to_i1 () {
+               int i = 0x100017f;
+               sbyte s = (sbyte)i;
+
+               return s;
+       }
+
+       public static int test_384_iconv_to_i2 () {
+               int i = 0x1000180;
+               short s = (short)i;
+
+               return s;
+       }
        
        public static int test_15_for_loop () {
                int i;
@@ -1145,4 +1234,131 @@ class Tests {
 
                return (int)(i % j);
        }
+
+       public static int test_0_div_opt () {
+               int i;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 567; ++j)
+                       i ++;
+               i += 1234000;
+               if ((i / 2) != 617283)
+                       return 1;
+               if ((i / 4) != 308641)
+                       return 2;
+               if ((i / 8) != 154320)
+                       return 3;
+               if ((i / 16) != 77160)
+                       return 4;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 567; ++j)
+                       i --;
+               i -= 1234000;
+               if ((i / 2) != -617283)
+                       return 5;
+               if ((i / 4) != -308641)
+                       return 6;
+               if ((i / 8) != -154320)
+                       return 7;
+               if ((i / 16) != -77160)
+                       return 8;
+
+               return 0;
+       }
+
+       public static int test_0_rem_opt () {
+               int i;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 29; ++j)
+                       i ++;
+               if ((i % 2) != 1)
+                       return 1;
+               if ((i % 4) != 1)
+                       return 2;
+               if ((i % 8) != 5)
+                       return 3;
+               if ((i % 16) != 13)
+                       return 4;
+
+               // Avoid cfolding this
+               i = 0;
+               for (int j = 0; j < 29; ++j)
+                       i --;
+               if ((i % 2) != -1)
+                       return 5;
+               if ((i % 4) != -1)
+                       return 6;
+               if ((i % 8) != -5)
+                       return 7;
+               if ((i % 16) != -13)
+                       return 8;
+
+               return 0;
+       }
+
+       public static int cmov (int i) {
+               int j = 0;
+
+               if (i > 0)
+                       j = 1;
+
+               return j;
+       }
+
+       public static int cmov2 (int i) {
+               int j = 0;
+
+               if (i <= 0)
+                       ;
+               else
+                       j = 1;
+
+               return j;
+       }
+               
+       public static int test_0_branch_to_cmov_opt () {
+               if (cmov (0) != 0)
+                       return 1;
+               if (cmov (1) != 1)
+                       return 2;
+               if (cmov2 (0) != 0)
+                       return 1;
+               if (cmov2 (1) != 1)
+                       return 2;
+               return 0;
+       }
+
+       public static unsafe int test_0_ishr_sign_extend () {
+               // Check that ishr does sign extension from bit 31 on 64 bit platforms
+               uint val = 0xF0000000u;
+
+               uint *a = &val;
+               uint ui = (uint)((int)(*a) >> 2);
+
+               if (ui != 0xfc000000)
+                       return 1;
+
+               // Same with non-immediates
+               int amount = 2;
+
+               ui = (uint)((int)(*a) >> amount);
+
+               if (ui != 0xfc000000)
+                       return 2;
+
+               return 0;
+       }
+
+       public static unsafe int test_0_ishr_sign_extend_cfold () {
+               int i = 32768;
+               int j = i << 16;
+               int k = j >> 16;
+
+               return k == -32768 ? 0 : 1;
+       }
 }