2004-10-14 Joe Shaw <joeshaw@novell.com>
[mono.git] / mono / mini / basic.cs
index 5e4c2bbea4154631917c6d5fecb6483478500c65..1846cf5f8df314b4b5198d16117535b19a517701 100644 (file)
@@ -152,14 +152,21 @@ class Tests {
                return b / 2;
        }
 
+       static int test_719177_div_destreg () {
+               int year = 1970;
+               return ((365* (year-1)) + ((year-1)/4));
+       }
+
        static int test_1_remun_imm () {
                uint b = 13;
                return (int)(b % 3);
        }
 
        static int test_2_bigremun_imm () {
-               uint b = (uint)-2;
-               return (int)(b % 3);
+               unchecked {
+                       uint b = (uint)-2;
+                       return (int)(b % 3);
+               }
        }
 
        static int test_2_rem () {
@@ -173,6 +180,11 @@ class Tests {
                return b % 8;
        }
 
+       static int test_4_rem_big_imm () {
+               int b = 10004;
+               return b % 10000;
+       }
+
        static int test_9_mul () {
                int b = 3;
                int a = 3;
@@ -228,6 +240,13 @@ class Tests {
                return (int)res;
        }
 
+       static int test_0_add_un_ovf () {
+               uint n = (uint)134217728 * 16;
+               uint number = checked (n + (uint)0);
+
+               return number == n ? 0 : 1;
+       }
+
        static int test_3_or () {
                int b = 2;
                int a = 3;
@@ -314,6 +333,11 @@ class Tests {
                return b << 3;
        }
        
+       static int test_524288_shift_imm_large () {
+               int b = 2;
+               return b << 18;
+       }
+       
        static int test_12_shift_imm_inv () {
                int b = 2;
                return 3 << 2;
@@ -335,11 +359,13 @@ class Tests {
        }
        
        static int test_0_bigunrshift_imm () {
-               uint b = (uint)-1;
-               b = b >> 1;
-               if (b != 0x7fffffff)
-                       return 1;
-               return 0;
+               unchecked {
+                       uint b = (uint)-1;
+                       b = b >> 1;
+                       if (b != 0x7fffffff)
+                               return 1;
+                       return 0;
+               }
        }
        
        static int test_0_bigrshift_imm () {
@@ -363,12 +389,14 @@ class Tests {
        }
        
        static int test_0_bigunrshift () {
-               uint b = (uint)-1;
-               int a = 1;
-               b = b >> a;
-               if (b != 0x7fffffff)
-                       return 1;
-               return 0;
+               unchecked {
+                       uint b = (uint)-1;
+                       int a = 1;
+                       b = b >> a;
+                       if (b != 0x7fffffff)
+                               return 1;
+                       return 0;
+               }
        }
        
        static int test_0_bigrshift () {
@@ -428,6 +456,17 @@ class Tests {
                }
                return a + b + c;
        }
+
+       static int test_0_short_sign_extend () {
+               int t1 = 0xffeedd;
+               short s1 = (short)t1;
+               int t2 = s1;
+
+               if ((uint)t2 != 0xffffeedd) 
+                       return 1;
+               else
+                       return 0;
+       }               
        
        static int test_15_for_loop () {
                int i;
@@ -466,7 +505,7 @@ class Tests {
                        c = -128;
                        b = (sbyte)c;
                }
-               
+
                return 0;
        }
        
@@ -489,6 +528,11 @@ class Tests {
                        Int16 b = (Int16)c;
                        c = -32768;
                        b = (Int16)c;
+                       unchecked {
+                               uint u = 0xfffffffd;
+                               c = (int)u;
+                       }
+                       b = (Int16)c;
                }
                
                return 0;
@@ -626,6 +670,15 @@ class Tests {
                return 0;
        }
 
+       static unsafe int test_0_pin_string () {
+               string x = "xxx";
+               fixed (char *c = x) {
+                       if (*c != 'x')
+                               return 1;
+               }
+               return 0;
+       }
+
        static int test_3_shift_regalloc () {
                int shift = 8;
                int orig = 1;
@@ -686,5 +739,201 @@ class Tests {
                        return 1;
                return 0;
        }
+       
+       static int test_1_a_eq_b_plus_a () {
+               int a = 0, b = 1;
+               a = b + a;
+               return a;
+       }
+
+       static int test_0_comp () {
+               int a = 0;
+               int b = -1;
+               int error = 1;
+               bool val;
+
+               val = a < b;
+               if (val)
+                       return error;
+               error++;
+
+               val = a > b;
+               if (!val)
+                       return error;
+               error ++;
+
+               val = a == b;
+               if (val)
+                       return error;
+               error ++;
+
+               val = a == a;
+               if (!val)
+                       return error;
+               error ++;
+
+               return 0;
+       }
+
+       static int test_0_comp_unsigned () {
+               uint a = 1;
+               uint b = 0xffffffff;
+               int error = 1;
+               bool val;
+
+               val = a < b;
+               if (!val)
+                       return error;
+               error++;
+
+               val = a <= b;
+               if (!val)
+                       return error;
+               error++;
+
+               val = a == b;
+               if (val)
+                       return error;
+               error++;
+
+               val = a >= b;
+               if (val)
+                       return error;
+               error++;
+
+               val = a > b;
+               if (val)
+                       return error;
+               error++;
+
+               val = b < a;
+               if (val)
+                       return error;
+               error++;
+
+               val = b <= a;
+               if (val)
+                       return error;
+               error++;
+
+               val = b == a;
+               if (val)
+                       return error;
+               error++;
+
+               val = b > a;
+               if (!val)
+                       return error;
+               error++;
+
+               val = b >= a;
+               if (!val)
+                       return error;
+               error++;
+
+               return 0;
+       }
+       
+       static int test_16_cmov () 
+       {
+               int n = 0;
+               if (n == 0)
+                       n = 16;
+               
+               return n;
+       }
+       
+       static int my_flags;
+       static int test_0_and_cmp ()
+       {
+               
+               /* various forms of test [mem], imm */
+               
+               my_flags = 0x01020304;
+               
+               if ((my_flags & 0x01020304) == 0)
+                       return 1;
+               
+               if ((my_flags & 0x00000304) == 0)
+                       return 2;
+               
+               if ((my_flags & 0x00000004) == 0)
+                       return 3;
+               
+               if ((my_flags & 0x00000300) == 0)
+                       return 4;
+               
+               if ((my_flags & 0x00020000) == 0)
+                       return 5;
+               
+               if ((my_flags & 0x01000000) == 0)
+                       return 6;
+               
+               /* test esi, imm */
+               int local = 0x01020304;
+               
+               if ((local & 0x01020304) == 0)
+                       return 7;
+               
+               if ((local & 0x00000304) == 0)
+                       return 8;
+               
+               if ((local & 0x00000004) == 0)
+                       return 9;
+               
+               if ((local & 0x00000300) == 0)
+                       return 10;
+               
+               if ((local & 0x00020000) == 0)
+                       return 11;
+               
+               if ((local & 0x01000000) == 0)
+                       return 12;
+               
+               return 0;
+       }
+       
+       static int test_0_cne ()
+       {
+               int x = 0;
+               int y = 1;
+               
+               bool b = x != y;
+               bool bb = x != x;
+               
+               if (!b)
+                       return 1;
+               if (bb)
+                       return 2;
+               
+               return 0;
+       }
+       
+       static byte b;
+       static int test_0_byte_compares ()
+       {
+               b = 0xff;
+               if (b == -1)
+                       return 1;
+               b = 0;
+               if (!(b < System.Byte.MaxValue))
+                       return 2;
+               
+               if (!(b <= System.Byte.MaxValue))
+                       return 3;
+               
+               return 0;
+       }
+       static int test_0_cmp_regvar_zero ()
+       {
+               int n = 10;
+               
+               if (!(n > 0 && n >= 0 && n != 0))
+                       return 1;
+               if (n < 0 || n <= 0 || n == 0)
+                       return 1;
+               
+               return 0;
+       }
 
 }