2010-04-06 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / mini / basic-calls.cs
blob5ad874b3dfaf90d4ab35b0f176b809ef6b29b5c2
1 using System;
2 using System.Reflection;
4 /*
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * public static int test_<result>_<name> ();
11 * where <result> is an integer (the value that needs to be returned by
12 * the method to make it pass.
13 * <name> is a user-displayed name used to identify the test.
15 * The tests can be driven in two ways:
16 * *) running the program directly: Main() uses reflection to find and invoke
17 * the test methods (this is useful mostly to check that the tests are correct)
18 * *) with the --regression switch of the jit (this is the preferred way since
19 * all the tests will be run with optimizations on and off)
21 * The reflection logic could be moved to a .dll since we need at least another
22 * regression test file written in IL code to have better control on how
23 * the IL code looks.
26 class Tests {
28 static int Main () {
29 return TestDriver.RunTests (typeof (Tests));
32 static void dummy () {
35 public static int test_0_return () {
36 dummy ();
37 return 0;
40 static int dummy1 () {
41 return 1;
44 public static int test_2_int_return () {
45 int r = dummy1 ();
46 if (r == 1)
47 return 2;
48 return 0;
51 static int add1 (int val) {
52 return val + 1;
55 public static int test_1_int_pass () {
56 int r = add1 (5);
57 if (r == 6)
58 return 1;
59 return 0;
62 static int add_many (int val, short t, byte b, int da) {
63 return val + t + b + da;
66 public static int test_1_int_pass_many () {
67 byte b = 6;
68 int r = add_many (5, 2, b, 1);
69 if (r == 14)
70 return 1;
71 return 0;
74 unsafe static float GetFloat (byte *ptr) {
75 return *(float*)ptr;
78 unsafe public static float GetFloat(float value)
80 return GetFloat((byte *)&value);
83 /* bug #42134 */
84 public static int test_2_inline_saved_arg_type () {
85 float f = 100.0f;
86 return GetFloat (f) == f? 2: 1;
89 static int pass_many_types (int a, long b, int c, long d) {
90 return a + (int)b + c + (int)d;
93 public static int test_5_pass_longs () {
94 return pass_many_types (1, 2, -5, 7);
97 static int overflow_registers (int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
98 return a+b+c+d+e+f+g+h+i+j;
101 public static int test_55_pass_even_more () {
102 return overflow_registers (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
105 static int pass_ints_longs (int a, long b, long c, long d, long e, int f, long g) {
106 return (int)(a + b + c + d + e + f + g);
109 public static int test_1_sparc_argument_passing () {
110 // The 4. argument tests split reg/mem argument passing
111 // The 5. argument tests mem argument passing
112 // The 7. argument tests passing longs in misaligned memory
113 // The MaxValues are needed so the MS word of the long is not 0
114 return pass_ints_longs (1, 2, System.Int64.MaxValue, System.Int64.MinValue, System.Int64.MaxValue, 0, System.Int64.MinValue);
117 static int pass_bytes (byte a, byte b, byte c, byte d, byte e, byte f, byte g) {
118 return (int)(a + b + c + d + e + f + g);
121 public static int test_21_sparc_byte_argument_passing () {
122 return pass_bytes (0, 1, 2, 3, 4, 5, 6);
125 static int pass_sbytes (sbyte a, sbyte b, sbyte c, sbyte d, sbyte e, sbyte f, sbyte g) {
126 return (int)(a + b + c + d + e + f + g);
129 public static int test_21_sparc_sbyte_argument_passing () {
130 return pass_sbytes (0, 1, 2, 3, 4, 5, 6);
133 static int pass_shorts (short a, short b, short c, short d, short e, short f, short g) {
134 return (int)(a + b + c + d + e + f + g);
137 public static int test_21_sparc_short_argument_passing () {
138 return pass_shorts (0, 1, 2, 3, 4, 5, 6);
141 static int pass_floats_doubles (float a, double b, double c, double d, double e, float f, double g) {
142 return (int)(a + b + c + d + e + f + g);
145 public static int test_721_sparc_float_argument_passing () {
146 return pass_floats_doubles (100.0f, 101.0, 102.0, 103.0, 104.0, 105.0f, 106.0);
149 static float pass_floats (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j) {
150 return a + b + c + d + e + f + g + h + i + j;
153 public static int test_55_sparc_float_argument_passing2 () {
154 return (int)pass_floats (1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f);
157 public static bool is_small (float value) {
158 double d = (double)value;
159 double d2 = 7.183757E-41;
160 return d - d2 < 0.000001;
163 public static int test_0_float_argument_passing_precision () {
164 float f = 7.183757E-41f;
165 return is_small (f) ? 0 : 1;
168 // The first argument must be passed on a dword aligned stack location
169 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) {
170 return (int)(a + b + c + d + e + f + g);
173 static int pass_takeaddr_ints_longs (long a, int b, byte c, short d, long e, int f, long g) {
174 return pass_byref_ints_longs (ref a, ref b, ref c, ref d, ref e, ref f, ref g);
177 // Test that arguments are moved to the stack from incoming registers
178 // when the argument must reside in the stack because its address is taken
179 public static int test_2_sparc_takeaddr_argument_passing () {
180 return pass_takeaddr_ints_longs (1, 2, 253, -253, System.Int64.MaxValue, 0, System.Int64.MinValue);
183 static int pass_byref_floats_doubles (ref float a, ref double b, ref double c, ref double d, ref double e, ref float f, ref double g) {
184 return (int)(a + b + c + d + e + f + g);
187 static int pass_takeaddr_floats_doubles (float a, double b, double c, double d, double e, float f, double g) {
188 return pass_byref_floats_doubles (ref a, ref b, ref c, ref d, ref e, ref f, ref g);
191 public static int test_721_sparc_takeaddr_argument_passing2 () {
192 return pass_takeaddr_floats_doubles (100.0f, 101.0, 102.0, 103.0, 104.0, 105.0f, 106.0);
195 static void pass_byref_double (out double d) {
196 d = 5.0;
199 // Test byref double argument passing
200 public static int test_0_sparc_byref_double_argument_passing () {
201 double d;
202 pass_byref_double (out d);
203 return (d == 5.0) ? 0 : 1;
206 static void shift_un_arg (ulong value) {
207 do {
208 value = value >> 4;
209 } while (value != 0);
212 // Test that assignment to long arguments work
213 public static int test_0_long_arg_assign ()
215 ulong c = 0x800000ff00000000;
217 shift_un_arg (c >> 4);
219 return 0;
222 static unsafe void* ptr_return (void *ptr)
224 return ptr;
227 public static unsafe int test_0_ptr_return ()
229 void *ptr = new IntPtr (55).ToPointer ();
231 if (ptr_return (ptr) == ptr)
232 return 0;
233 else
234 return 1;
237 static bool isnan (float f) {
238 return (f != f);
241 public static int test_0_isnan () {
242 float f = 1.0f;
243 return isnan (f) ? 1 : 0;
246 static int first_is_zero (int v1, int v2) {
247 if (v1 != 0)
248 return -1;
249 return v2;
251 public static int test_1_handle_dup_stloc () {
252 int index = 0;
253 int val = first_is_zero (index, ++index);
254 if (val != 1)
255 return 2;
256 return 1;
259 static long return_5low () {
260 return 5;
263 static long return_5high () {
264 return 0x500000000;
267 public static int test_3_long_ret () {
268 long val = return_5low ();
269 return (int) (val - 2);
272 public static int test_1_long_ret2 () {
273 long val = return_5high ();
274 if (val > 0xffffffff)
275 return 1;
276 return 0;
279 public static void use_long_arg (ulong l) {
280 for (int i = 0; i < 10; ++i)
281 l ++;
284 public static ulong return_long_arg (object o, ulong perm) {
285 use_long_arg (perm);
287 perm = 0x8000000000000FFF;
289 use_long_arg (perm);
291 return perm;
294 public static int test_0_sparc_long_ret_regress_541577 () {
295 ulong perm = 0x8000000000000FFF;
297 ulong work = return_long_arg (null, perm);
299 return work == perm ? 0 : 1;
302 static void doit (double value, out long m) {
303 m = (long) value;
306 public static int test_0_ftol_clobber () {
307 long m;
308 doit (1.3, out m);
309 if (m != 1)
310 return 2;
311 return 0;