2003-12-23 Patrik Torstensson <p@rxc.se>
[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_add_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_362880_float_mul_spill () {
112                 // we overflow the FP stack
113                 double a = 1;
114                 double b = 2;
115                 double c = 3;
116                 double d = 4;
117                 double e = 5;
118                 double f = 6;
119                 double g = 7;
120                 double h = 8;
121                 double i = 9;
122
123                 return (int)(1.0 * (a * (b * (c * (d * (e * (f * (g * (h * i)))))))));
124         }
125
126         static int test_4_long_cast () {
127                 long a = 1000;
128                 double d = (double)a;
129                 long b = (long)d;
130                 if (b != 1000)
131                         return 0;
132                 return 4;
133         }
134
135         static unsafe int test_2_negative_zero () {
136                 int result = 0;
137                 double d = -0.0;
138                 float f = -0.0f;
139
140                 byte *ptr = (byte*)&d;
141                 if (ptr [7] == 0)
142                         return result;
143                 result ++;
144
145                 ptr = (byte*)&f;
146                 if (ptr [3] == 0)
147                         return result;
148                 result ++;
149
150                 return result;
151         }
152
153         static int test_15_float_cmp () {
154                 double a = 2.0;
155                 double b = 1.0;
156                 int result = 0;
157                 bool val;
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 = a > a;
170                 if (val)
171                         return result;
172                 result++;
173
174                 val = a <= a;
175                 if (!val)
176                         return result;
177                 result++;
178
179                 val = a >= 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 = b > a;
195                 if (val)
196                         return result;
197                 result++;
198
199                 val = b <= a;
200                 if (!val)
201                         return result;
202                 result++;
203
204                 val = b >= a;
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                 val = a > b;
220                 if (!val)
221                         return result;
222                 result++;
223
224                 val = a <= b;
225                 if (val)
226                         return result;
227                 result++;
228
229                 val = a >= b;
230                 if (!val)
231                         return result;
232                 result++;
233
234                 return result;
235         }
236
237         static int test_15_float_cmp_un () {
238                 double a = Double.NaN;
239                 double b = 1.0;
240                 int result = 0;
241                 bool val;
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 = a > a;
254                 if (val)
255                         return result;
256                 result++;
257
258                 val = a <= a;
259                 if (val)
260                         return result;
261                 result++;
262
263                 val = a >= 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 = b > a;
279                 if (val)
280                         return result;
281                 result++;
282
283                 val = b <= a;
284                 if (val)
285                         return result;
286                 result++;
287
288                 val = b >= a;
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                 val = a > b;
304                 if (val)
305                         return result;
306                 result++;
307
308                 val = a <= b;
309                 if (val)
310                         return result;
311                 result++;
312
313                 val = a >= b;
314                 if (val)
315                         return result;
316                 result++;
317
318                 return result;
319         }
320
321         static int test_15_float_branch () {
322                 double a = 2.0;
323                 double b = 1.0;
324                 int result = 0;
325                 
326                 if (!(a == a))
327                         return result;
328                 result++;
329
330                 if (a < a)
331                         return result;
332                 result++;
333
334                 if (a > a)
335                         return result;
336                 result++;
337
338                 if (!(a <= a))
339                         return result;
340                 result++;
341
342                 if (!(a >= a))
343                         return result;
344                 result++;
345
346                 if (b == a)
347                         return result;
348                 result++;
349
350                 if (!(b < a))
351                         return result;
352                 result++;
353
354                 if (b > a)
355                         return result;
356                 result++;
357
358                 if (!(b <= a))
359                         return result;
360                 result++;
361
362                 if (b >= a)
363                         return result;
364                 result++;
365
366                 if (a == b)
367                         return result;
368                 result++;
369
370                 if (a < b)
371                         return result;
372                 result++;
373
374                 if (!(a > b))
375                         return result;
376                 result++;
377
378                 if (a <= b)
379                         return result;
380                 result++;
381
382                 if (!(a >= b))
383                         return result;
384                 result++;
385
386                 return result;
387         }
388
389         static int test_15_float_branch_un () {
390                 double a = Double.NaN;
391                 double b = 1.0;
392                 int result = 0;
393                 
394                 if (a == a)
395                         return result;
396                 result++;
397
398                 if (a < a)
399                         return result;
400                 result++;
401
402                 if (a > a)
403                         return result;
404                 result++;
405
406                 if (a <= a)
407                         return result;
408                 result++;
409
410                 if (a >= a)
411                         return result;
412                 result++;
413
414                 if (b == a)
415                         return result;
416                 result++;
417
418                 if (b < a)
419                         return result;
420                 result++;
421
422                 if (b > a)
423                         return result;
424                 result++;
425
426                 if (b <= a)
427                         return result;
428                 result++;
429
430                 if (b >= a)
431                         return result;
432                 result++;
433
434                 if (a == b)
435                         return result;
436                 result++;
437
438                 if (a < b)
439                         return result;
440                 result++;
441
442                 if (a > b)
443                         return result;
444                 result++;
445
446                 if (a <= b)
447                         return result;
448                 result++;
449
450                 if (a >= b)
451                         return result;
452                 result++;
453
454                 return result;
455         }
456
457 }
458