2003-08-26 Martin Baulig <martin@ximian.com>
[mono.git] / mono / mini / basic-float.cs
1 using System;
2 using System.Reflection;
3
4 /*
5  * Regression tests for the mono JIT.
6  *
7  * Each test needs to be of the form:
8  *
9  * static int test_<result>_<name> ();
10  *
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.
14  *
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)
20  *
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.
24  */
25
26 class Tests {
27
28         static int Main () {
29                 return TestDriver.RunTests (typeof (Tests));
30         }
31         
32         static int test_0_beq () {
33                 double a = 2.0;
34                 if (a != 2.0)
35                         return 1;
36                 return 0;
37         }
38
39         static int test_0_bne_un () {
40                 double a = 2.0;
41                 if (a == 1.0)
42                         return 1;
43                 return 0;
44         }
45
46         static int test_0_conv_r8 () {
47                 double a = 2;
48                 if (a != 2.0)
49                         return 1;
50                 return 0;
51         }
52
53         static int test_0_conv_i4 () {
54                 double a = 2.0;
55                 int b = (int)a;
56                 if (b != 2)
57                         return 1;
58                 return 0;
59         }
60
61         static int test_5_add () {
62                 double a = 2.0;
63                 double b = 3.0;         
64                 return (int)(a + b);
65         }
66
67         static int test_5_sub () {
68                 double a = 8.0;
69                 double b = 3.0;         
70                 return (int)(a - b);
71         }       
72
73         static int test_24_mul () {
74                 double a = 8.0;
75                 double b = 3.0;         
76                 return (int)(a * b);
77         }       
78
79         static int test_4_div () {
80                 double a = 8.0;
81                 double b = 2.0;         
82                 return (int)(a / b);
83         }       
84
85         static int test_2_rem () {
86                 double a = 8.0;
87                 double b = 3.0;         
88                 return (int)(a % b);
89         }       
90
91         static int test_2_neg () {
92                 double a = -2.0;                
93                 return (int)(-a);
94         }
95         
96         static int test_46_float_spill () {
97                 // we overflow the FP stack
98                 double a = 1;
99                 double b = 2;
100                 double c = 3;
101                 double d = 4;
102                 double e = 5;
103                 double f = 6;
104                 double g = 7;
105                 double h = 8;
106                 double i = 9;
107
108                 return (int)(1.0 + (a + (b + (c + (d + (e + (f + (g + (h + i)))))))));
109         }
110
111         static int test_4_long_cast () {
112                 long a = 1000;
113                 double d = (double)a;
114                 long b = (long)d;
115                 if (b != 1000)
116                         return 0;
117                 return 4;
118         }
119
120         static unsafe int test_2_negative_zero () {
121                 int result = 0;
122                 double d = -0.0;
123                 float f = -0.0f;
124
125                 byte *ptr = (byte*)&d;
126                 if (ptr [7] == 0)
127                         return result;
128                 result ++;
129
130                 ptr = (byte*)&f;
131                 if (ptr [3] == 0)
132                         return result;
133                 result ++;
134
135                 return result;
136         }
137
138         static int test_15_float_cmp () {
139                 double a = 2.0;
140                 double b = 1.0;
141                 int result = 0;
142                 bool val;
143                 
144                 val = a == a;
145                 if (!val)
146                         return result;
147                 result++;
148
149                 val = a < a;
150                 if (val)
151                         return result;
152                 result++;
153
154                 val = a > a;
155                 if (val)
156                         return result;
157                 result++;
158
159                 val = a <= a;
160                 if (!val)
161                         return result;
162                 result++;
163
164                 val = a >= a;
165                 if (!val)
166                         return result;
167                 result++;
168
169                 val = b == a;
170                 if (val)
171                         return result;
172                 result++;
173
174                 val = b < a;
175                 if (!val)
176                         return result;
177                 result++;
178
179                 val = b > a;
180                 if (val)
181                         return result;
182                 result++;
183
184                 val = b <= a;
185                 if (!val)
186                         return result;
187                 result++;
188
189                 val = b >= a;
190                 if (val)
191                         return result;
192                 result++;
193
194                 val = a == b;
195                 if (val)
196                         return result;
197                 result++;
198
199                 val = a < b;
200                 if (val)
201                         return result;
202                 result++;
203
204                 val = a > b;
205                 if (!val)
206                         return result;
207                 result++;
208
209                 val = a <= b;
210                 if (val)
211                         return result;
212                 result++;
213
214                 val = a >= b;
215                 if (!val)
216                         return result;
217                 result++;
218
219                 return result;
220         }
221
222         static int test_15_float_cmp_un () {
223                 double a = Double.NaN;
224                 double b = 1.0;
225                 int result = 0;
226                 bool val;
227                 
228                 val = a == a;
229                 if (val)
230                         return result;
231                 result++;
232
233                 val = a < a;
234                 if (val)
235                         return result;
236                 result++;
237
238                 val = a > a;
239                 if (val)
240                         return result;
241                 result++;
242
243                 val = a <= a;
244                 if (val)
245                         return result;
246                 result++;
247
248                 val = a >= a;
249                 if (val)
250                         return result;
251                 result++;
252
253                 val = b == a;
254                 if (val)
255                         return result;
256                 result++;
257
258                 val = b < a;
259                 if (val)
260                         return result;
261                 result++;
262
263                 val = b > a;
264                 if (val)
265                         return result;
266                 result++;
267
268                 val = b <= a;
269                 if (val)
270                         return result;
271                 result++;
272
273                 val = b >= a;
274                 if (val)
275                         return result;
276                 result++;
277
278                 val = a == b;
279                 if (val)
280                         return result;
281                 result++;
282
283                 val = a < b;
284                 if (val)
285                         return result;
286                 result++;
287
288                 val = a > b;
289                 if (val)
290                         return result;
291                 result++;
292
293                 val = a <= b;
294                 if (val)
295                         return result;
296                 result++;
297
298                 val = a >= b;
299                 if (val)
300                         return result;
301                 result++;
302
303                 return result;
304         }
305
306         static int test_15_float_branch () {
307                 double a = 2.0;
308                 double b = 1.0;
309                 int result = 0;
310                 
311                 if (!(a == a))
312                         return result;
313                 result++;
314
315                 if (a < a)
316                         return result;
317                 result++;
318
319                 if (a > a)
320                         return result;
321                 result++;
322
323                 if (!(a <= a))
324                         return result;
325                 result++;
326
327                 if (!(a >= a))
328                         return result;
329                 result++;
330
331                 if (b == a)
332                         return result;
333                 result++;
334
335                 if (!(b < a))
336                         return result;
337                 result++;
338
339                 if (b > a)
340                         return result;
341                 result++;
342
343                 if (!(b <= a))
344                         return result;
345                 result++;
346
347                 if (b >= a)
348                         return result;
349                 result++;
350
351                 if (a == b)
352                         return result;
353                 result++;
354
355                 if (a < b)
356                         return result;
357                 result++;
358
359                 if (!(a > b))
360                         return result;
361                 result++;
362
363                 if (a <= b)
364                         return result;
365                 result++;
366
367                 if (!(a >= b))
368                         return result;
369                 result++;
370
371                 return result;
372         }
373
374         static int test_15_float_branch_un () {
375                 double a = Double.NaN;
376                 double b = 1.0;
377                 int result = 0;
378                 
379                 if (a == a)
380                         return result;
381                 result++;
382
383                 if (a < a)
384                         return result;
385                 result++;
386
387                 if (a > a)
388                         return result;
389                 result++;
390
391                 if (a <= a)
392                         return result;
393                 result++;
394
395                 if (a >= a)
396                         return result;
397                 result++;
398
399                 if (b == a)
400                         return result;
401                 result++;
402
403                 if (b < a)
404                         return result;
405                 result++;
406
407                 if (b > a)
408                         return result;
409                 result++;
410
411                 if (b <= a)
412                         return result;
413                 result++;
414
415                 if (b >= a)
416                         return result;
417                 result++;
418
419                 if (a == b)
420                         return result;
421                 result++;
422
423                 if (a < b)
424                         return result;
425                 result++;
426
427                 if (a > b)
428                         return result;
429                 result++;
430
431                 if (a <= b)
432                         return result;
433                 result++;
434
435                 if (a >= b)
436                         return result;
437                 result++;
438
439                 return result;
440         }
441
442 }
443