svn path=/trunk/mono/; revision=139311
[mono.git] / mono / mini / basic-calls.cs
index 2cf98185cd9fa10795113440ce989e173267669d..0bcac6dd05a5e4e3b4ba38968b524978768b458f 100644 (file)
@@ -6,7 +6,7 @@ using System.Reflection;
  *
  * Each test needs to be of the form:
  *
- * static int test_<result>_<name> ();
+ * public static int test_<result>_<name> ();
  *
  * where <result> is an integer (the value that needs to be returned by
  * the method to make it pass.
@@ -23,6 +23,18 @@ using System.Reflection;
  * the IL code looks.
  */
 
+struct Alpha {
+       public long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;
+}
+
+struct Beta {
+       public Alpha a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;
+}
+
+struct Gamma {
+       public Beta a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v;
+}
+
 class Tests {
 
        static int Main () {
@@ -32,7 +44,7 @@ class Tests {
        static void dummy () {
        }
 
-       static int test_0_return () {
+       public static int test_0_return () {
                dummy ();
                return 0;
        }
@@ -41,7 +53,7 @@ class Tests {
                return 1;
        }
 
-       static int test_2_int_return () {
+       public static int test_2_int_return () {
                int r = dummy1 ();
                if (r == 1)
                        return 2;
@@ -52,7 +64,7 @@ class Tests {
                return val + 1;
        }
 
-       static int test_1_int_pass () {
+       public static int test_1_int_pass () {
                int r = add1 (5);
                if (r == 6)
                        return 1;
@@ -63,7 +75,7 @@ class Tests {
                return val + t + b + da;
        }
 
-       static int test_1_int_pass_many () {
+       public static int test_1_int_pass_many () {
                byte b = 6;
                int r = add_many (5, 2, b, 1);
                if (r == 14)
@@ -81,7 +93,7 @@ class Tests {
                }
 
        /* bug #42134 */
-       static int test_2_inline_saved_arg_type () {
+       public static int test_2_inline_saved_arg_type () {
                float f = 100.0f;
                return GetFloat (f) == f? 2: 1;
        }
@@ -90,7 +102,7 @@ class Tests {
                return a + (int)b + c + (int)d;
        }
 
-       static int test_5_pass_longs () {
+       public static int test_5_pass_longs () {
                return pass_many_types (1, 2, -5, 7);
        }
 
@@ -98,7 +110,7 @@ class Tests {
                return a+b+c+d+e+f+g+h+i+j;
        }
 
-       static int test_55_pass_even_more () {
+       public static int test_55_pass_even_more () {
                return overflow_registers (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        }
 
@@ -106,7 +118,7 @@ class Tests {
                return (int)(a + b + c + d + e + f + g);
        }
 
-       static int test_1_sparc_argument_passing () {
+       public static int test_1_sparc_argument_passing () {
                // The 4. argument tests split reg/mem argument passing
                // The 5. argument tests mem argument passing
                // The 7. argument tests passing longs in misaligned memory
@@ -118,7 +130,7 @@ class Tests {
                return (int)(a + b + c + d + e + f + g);
        }
 
-       static int test_21_sparc_byte_argument_passing () {
+       public static int test_21_sparc_byte_argument_passing () {
                return pass_bytes (0, 1, 2, 3, 4, 5, 6);
        }
 
@@ -126,7 +138,7 @@ class Tests {
                return (int)(a + b + c + d + e + f + g);
        }
 
-       static int test_21_sparc_sbyte_argument_passing () {
+       public static int test_21_sparc_sbyte_argument_passing () {
                return pass_sbytes (0, 1, 2, 3, 4, 5, 6);
        }
 
@@ -134,7 +146,7 @@ class Tests {
                return (int)(a + b + c + d + e + f + g);
        }
 
-       static int test_21_sparc_short_argument_passing () {
+       public static int test_21_sparc_short_argument_passing () {
                return pass_shorts (0, 1, 2, 3, 4, 5, 6);
        }
 
@@ -142,7 +154,7 @@ class Tests {
                return (int)(a + b + c + d + e + f + g);
        }
 
-       static int test_721_sparc_float_argument_passing () {
+       public static int test_721_sparc_float_argument_passing () {
                return pass_floats_doubles (100.0f, 101.0, 102.0, 103.0, 104.0, 105.0f, 106.0);
        }
 
@@ -150,10 +162,21 @@ class Tests {
                return a + b + c + d + e + f + g + h + i + j;
        }
 
-       static int test_55_sparc_float_argument_passing2 () {
+       public static int test_55_sparc_float_argument_passing2 () {
                return (int)pass_floats (1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f);
        }
 
+       public static bool is_small (float value) {
+               double d = (double)value;
+               double d2 = 7.183757E-41;
+               return d - d2 < 0.000001;
+       }
+               
+       public static int test_0_float_argument_passing_precision () {
+               float f = 7.183757E-41f;
+               return is_small (f) ? 0 : 1;
+       }
+
        // The first argument must be passed on a dword aligned stack location
        static int pass_byref_ints_longs (ref long a, ref int b, ref byte c, ref short d, ref long e, ref int f, ref long g) {
                return (int)(a + b + c + d + e + f + g);
@@ -165,7 +188,7 @@ class Tests {
 
        // Test that arguments are moved to the stack from incoming registers
        // when the argument must reside in the stack because its address is taken
-       static int test_2_sparc_takeaddr_argument_passing () {
+       public static int test_2_sparc_takeaddr_argument_passing () {
                return pass_takeaddr_ints_longs (1, 2, 253, -253, System.Int64.MaxValue, 0, System.Int64.MinValue);
        }
 
@@ -177,7 +200,7 @@ class Tests {
                return pass_byref_floats_doubles (ref a, ref b, ref c, ref d, ref e, ref f, ref g);
        }
 
-       static int test_721_sparc_takeaddr_argument_passing2 () {
+       public static int test_721_sparc_takeaddr_argument_passing2 () {
                return pass_takeaddr_floats_doubles (100.0f, 101.0, 102.0, 103.0, 104.0, 105.0f, 106.0);
        }
 
@@ -186,7 +209,7 @@ class Tests {
        }
 
        // Test byref double argument passing
-       static int test_0_sparc_byref_double_argument_passing () {
+       public static int test_0_sparc_byref_double_argument_passing () {
                double d;
                pass_byref_double (out d);
                return (d == 5.0) ? 0 : 1;
@@ -199,7 +222,7 @@ class Tests {
        }
 
        // Test that assignment to long arguments work
-       static int test_0_long_arg_assign ()
+       public static int test_0_long_arg_assign ()
        {
                ulong c = 0x800000ff00000000;
                        
@@ -213,7 +236,7 @@ class Tests {
                return ptr;
        }
 
-       static unsafe int test_0_ptr_return ()
+       public static unsafe int test_0_ptr_return ()
        {
                void *ptr = new IntPtr (55).ToPointer ();
 
@@ -227,7 +250,7 @@ class Tests {
                return (f != f);
        }
 
-       static int test_0_isnan () {
+       public static int test_0_isnan () {
                float f = 1.0f;
                return isnan (f) ? 1 : 0;
        }
@@ -237,7 +260,7 @@ class Tests {
                        return -1;
                return v2;
        }
-       static int test_1_handle_dup_stloc () {
+       public static int test_1_handle_dup_stloc () {
                int index = 0;
                int val = first_is_zero (index, ++index);
                if (val != 1)
@@ -265,123 +288,59 @@ class Tests {
                return 0;
        }
 
-       // 64-bits, 32-bit aligned
-       struct struct1 {
-               public int      a;
-               public int      b;
-       };
+       static void doit (double value, out long m) {
+               m = (long) value;
+       }
 
-       static int check_struct1(struct1 x) {
-               if (x.a != 1)
-                       return 1;
-               if (x.b != 2)
+       public static int test_0_ftol_clobber () {
+               long m;
+               doit (1.3, out m);
+               if (m != 1)
                        return 2;
                return 0;
        }
 
-       static int pass_struct1(int a, int b, struct1 x) {
-               if (a != 3)
-                       return 3;
-               if (b != 4)
-                       return 4;
-               return check_struct1(x);
+       static void InitMe (out Gamma noMercyWithTheStack) {
+               noMercyWithTheStack = new Gamma ();
        }
 
-       static int pass_struct1(int a, struct1 x) {
-               if (a != 3)
-                       return 3;
-               return check_struct1(x);
+       static int FunNoInline () {
+               int x = 99;
+               if (x > 344 && x < 22)
+                       throw new Exception ("333");
+               return x;
        }
 
-       static int pass_struct1(struct1 x) {
-               return check_struct1(x);
+       static float DoNothingButDontInline (float a, int b) {
+               if (b > 0)
+                       return a;
+               else if (b < 0 && b > 10)
+                       throw new Exception ("444");
+               return a;
        }
 
-       static int test_0_struct1_args () {
-               int r;
-               struct1 x;
+       /*
+        * The local register allocator emits loadr8_membase and storer8_membase
+        * to do spilling. This code is generated after mono_arch_lowering_pass so
+        * mono_arch_output_basic_block must know how to deal with big offsets.
+        * This only happens because the call in middle forces the temp for "(float)obj"
+        * to be spilled.
+       */
+       public static int test_0_float_load_and_store_with_big_offset ()
+       {
+               object obj = 1.0f;
+               Gamma noMercyWithTheStack;
+               float res;
 
-               x.a = 1;
-               x.b = 2;
-               if ((r = check_struct1(x)) != 0)
-                       return r;
-               if ((r = pass_struct1(x)) != 0)
-                       return r + 10;
-               if ((r = pass_struct1(3, x)) != 0)
-                       return r + 20;
-               if ((r = pass_struct1(3, 4, x)) != 0)
-                       return r + 30;
-               return 0;
-       }
+               InitMe (out noMercyWithTheStack);
 
-       // 64-bits, 64-bit aligned
-       struct struct2 {
-               public long     a;
-       };
+               res = DoNothingButDontInline ((float)obj, FunNoInline ());
 
-       static int check_struct2(struct2 x) {
-               if (x.a != 1)
+               if (!(res == 1.0f)) {
+                       Console.WriteLine ("invalid number {0}", res);
                        return 1;
+               }
                return 0;
        }
-
-       static int pass_struct2(int a, int b, int c, struct2 x) {
-               if (a != 3)
-                       return 3;
-               if (b != 4)
-                       return 4;
-               if (c != 5)
-                       return 5;
-               return check_struct2(x);
-       }
-
-       static int pass_struct2(int a, int b, struct2 x) {
-               if (a != 3)
-                       return 3;
-               if (b != 4)
-                       return 4;
-               return check_struct2(x);
-       }
-
-       static int pass_struct2(int a, struct2 x) {
-               if (a != 3)
-                       return 3;
-               return check_struct2(x);
-       }
-
-       static int pass_struct2(struct2 x) {
-               return check_struct2(x);
-       }
-
-       static int test_0_struct2_args () {
-               int r;
-               struct2 x;
-
-               x.a = 1;
-               if ((r = check_struct2(x)) != 0)
-                       return r;
-               if ((r = pass_struct2(x)) != 0)
-                       return r + 10;
-               if ((r = pass_struct2(3, x)) != 0)
-                       return r + 20;
-               if ((r = pass_struct2(3, 4, x)) != 0)
-                       return r + 30;
-               if ((r = pass_struct2(3, 4, 5, x)) != 0)
-                       return r + 40;
-               return 0;
-       }
-
-       static void doit (double value, out long m) {
-               m = (long) value;
-       }
-
-       public static int test_0_ftol_clobber () {
-               long m;
-               doit (1.3, out m);
-               if (m != 1)
-                       return 2;
-               return 0;
-       }
-
 }