Added 3 new files
[mono.git] / mono / mini / basic-long.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                 long a = 0xffffffffff;
34                 if (a != 0xffffffffff)
35                         return 1;
36                 return 0;
37         }
38
39         static int test_0_bne_un () {
40                 long a = 0xffffffffff;
41                 if (a == 0xfffffffffe)
42                         return 1;
43                 return 0;
44         }
45
46         static int test_0_ble () {
47                 long a = 0xffffffffff;
48                 if (a > 0xffffffffff)
49                         return 1;
50                 return 0;
51         }
52
53         static int test_0_ble_un () {
54                 ulong a = 0xffffffffff;
55                 if (a > 0xffffffffff)
56                         return 1;
57                 return 0;
58         }
59
60         static int test_0_bge () {
61                 long a = 0xffffffffff;
62                 if (a < 0xffffffffff)
63                         return 1;
64                 return 0;
65         }
66
67         static int test_0_bge_un () {
68                 ulong a = 0xffffffffff;
69                 if (a < 0xffffffffff)
70                         return 1;
71                 return 0;
72         }
73
74         static int test_0_blt () {
75                 long a = 0xfffffffffe;
76                 if (a >= 0xffffffffff)
77                         return 1;
78                 return 0;
79         }
80
81         static int test_0_blt_un () {
82                 ulong a = 0xfffffffffe;
83                 if (a >= 0xffffffffff)
84                         return 1;
85                 return 0;
86         }
87
88         static int test_0_bgt () {
89                 long a = 0xffffffffff;
90                 if (a <= 0xfffffffffe)
91                         return 1;
92                 return 0;
93         }
94
95         static int test_0_conv_to_i4 () {
96                 long a = 0;
97
98                 return (int)a;
99         }
100         static int test_0_conv_from_i4 () {
101                 long a = 2;
102                 if (a != 2)
103                         return 1;
104
105                 int b = 2;
106
107                 if (a != b)
108                     return 2;
109                 return 0;
110         }
111
112         static int test_0_conv_from_i4_negative () {
113                 long a = -2;
114                 if (a != -2)
115                         return 1;
116
117                 int b = -2;
118
119                 if (a != b)
120                     return 2;
121                 return 0;
122         }
123
124         /*
125         static int test_0_conv_from_r8 () {
126                 double b = 2.0;
127                 long a = (long)b;
128
129                 if (a != 2)
130                         return 1;
131                 return 0;
132         }
133
134         static int test_0_conv_from_r4 () {
135                 float b = 2.0F;
136                 long a = (long)b;
137
138                 if (a != 2)
139                         return 1;
140                 return 0;
141         }
142         */
143         
144         static int test_8_and () {
145                 long a = 0xffffffffff;
146                 long b = 8;             
147                 return (int)(a & b);
148         }
149
150         static int test_8_and_imm () {
151                 long a = 0xffffffffff;
152                 return (int)(a & 8);
153         }
154
155         static int test_10_or () {
156                 long a = 8;
157                 long b = 2;             
158                 return (int)(a | b);
159         }
160
161         static int test_10_or_imm () {
162                 long a = 8;
163                 return (int)(a | 2);
164         }
165
166         static int test_5_xor () {
167                 long a = 7;
168                 long b = 2;             
169                 return (int)(a ^ b);
170         }
171
172         static int test_5_xor_imm () {
173                 long a = 7;
174                 return (int)(a ^ 2);
175         }
176
177         static int test_5_add () {
178                 long a = 2;
179                 long b = 3;             
180                 return (int)(a + b);
181         }
182
183         static int test_5_add_imm () {
184                 long a = 2;
185                 return (int)(a + 3);
186         }
187
188         static int test_0_add_imm_no_inc () {
189                 // we can't blindly convert an add x, 1 to an inc x
190                 long a = 0x1ffffffff;
191                 long c;
192                 c = a + 2;
193                 if (c == ((a + 1) + 1))
194                         return 0;
195                 return 1;
196         }
197
198         static int test_5_sub () {
199                 long a = 8;
200                 long b = 3;             
201                 return (int)(a - b);
202         }
203
204         static int test_5_sub_imm () {
205                 long a = 8;
206                 return (int)(a - 3);
207         }
208
209         static int test_2_neg () {
210                 long a = -2;            
211                 return (int)(-a);
212         }       
213
214         static int test_0_shl () {
215                 long a = 9;
216                 int b = 1;
217                 
218                 if ((a >> b) != 4)
219                         return 1;
220
221
222                 return 0;
223         }
224         
225         static int test_1_rshift ()
226         {
227                 long a = 9;
228                 int b = 1;
229                 a = -9;
230                 if ((a >> b) != -5)
231                         return 0;
232                 return 1;
233         }
234
235         static int test_5_shift ()
236         {
237                 long a = 9;
238                 int b = 1;
239                 int count = 0;
240                 
241                 if ((a >> b) != 4)
242                         return count;
243                 count++;
244
245                 if ((a >> 63) != 0)
246                         return count;
247                 count++;
248
249                 if ((a << 1) != 18)
250                         return count;
251                 count++;
252
253                 if ((a << b) != 18)
254                         return count;
255                 count++;
256
257                 a = -9;
258                 if ((a >> b) != -5)
259                         return count;
260                 count++;
261
262                 return count;
263         }
264
265         static int test_1_simple_neg () {
266                 long a = 9;
267                 
268                 if (-a != -9)
269                         return 0;
270                 return 1;
271         }
272
273         static int test_2_compare () {
274                 long a = 1;
275                 long b = 1;
276                 
277                 if (a != b)
278                         return 0;
279                 return 2;
280         }
281
282         static int test_9_alu ()
283         {
284                 long a = 9, b = 6;
285                 int count = 0;
286                 
287                 if ((a + b) != 15)
288                         return count;
289                 count++;
290                 
291                 if ((a - b) != 3)
292                         return count;
293                 count++;
294
295                 if ((a & 8) != 8)
296                         return count;
297                 count++;
298
299                 if ((a | 2) != 11)
300                         return count;
301                 count++;
302
303                 if ((a * b) != 54)
304                         return count;
305                 count++;
306                 
307                 if ((a / 4) != 2)
308                         return count;
309                 count++;
310                 
311                 if ((a % 4) != 1)
312                         return count;
313                 count++;
314
315                 if (-a != -9)
316                         return count;
317                 count++;
318
319                 b = -1;
320                 if (~b != 0)
321                         return count;
322                 count++;
323
324                 return count;
325         }
326         
327         static int test_24_mul () {
328                 long a = 8;
329                 long b = 3;             
330                 return (int)(a * b);
331         }       
332         
333         static int test_24_mul_ovf () {
334                 long a = 8;
335                 long b = 3;
336                 long res;
337                 
338                 checked {
339                         res = a * b;
340                 }
341                 return (int)res;
342         }       
343
344         static int test_24_mul_un () {
345                 ulong a = 8;
346                 ulong b = 3;            
347                 return (int)(a * b);
348         }       
349         
350         static int test_24_mul_ovf_un () {
351                 ulong a = 8;
352                 ulong b = 3;
353                 ulong res;
354                 
355                 checked {
356                         res = a * b;
357                 }
358                 return (int)res;
359         }       
360         
361         static int test_4_divun () {
362                 uint b = 12;
363                 int a = 3;
364                 return (int)(b / a);
365         }
366
367         static int test_1431655764_bigdivun_imm () {
368                 uint b = (uint)-2;
369                 return (int)(b / 3);
370         }
371
372         static int test_1431655764_bigdivun () {
373                 uint b = (uint)-2;
374                 int a = 3;
375                 return (int)(b / a);
376         }
377
378         static int test_1_remun () {
379                 uint b = 13;
380                 int a = 3;
381                 return (int)(b % a);
382         }
383
384         static int test_2_bigremun () {
385                 uint b = (uint)-2;
386                 int a = 3;
387                 return (int)(b % a);
388         }
389
390         static int test_0_ceq () {
391                 long a = 2;
392                 long b = 2;
393                 long c = 3;
394                 long d = 0xff00000002;
395                 
396                 bool val = (a == b); // this should produce a ceq
397                 if (!val)
398                         return 1;
399                 
400                 val = (a == c); // this should produce a ceq
401                 if (val)
402                         return 2;
403                 
404                 val = (a == d); // this should produce a ceq
405                 if (val)
406                         return 3;
407                 
408                 return 0;
409         }
410         
411         static int test_0_clt () {
412                 long a = 2;
413                 long b = 2;
414                 long c = 3;
415                 long d = 0xff00000002L;
416                 long e = -1;
417                 
418                 bool val = (a < b); // this should produce a clt
419                 if (val)
420                         return 1;
421                 
422                 val = (a < c); // this should produce a clt
423                 if (!val)
424                         return 2;
425                 
426                 val = (c < a); // this should produce a clt
427                 if (val)
428                         return 3;
429                 
430                 val = (e < d); // this should produce a clt
431                 if (!val)
432                         return 4;
433                 
434                 val = (d < e); // this should produce a clt
435                 if (val)
436                         return 5;
437                 
438                 return 0;
439         }
440         
441         static int test_0_clt_un () {
442                 ulong a = 2;
443                 ulong b = 2;
444                 ulong c = 3;
445                 ulong d = 0xff00000002;
446                 ulong e = 0xffffffffffffffff;
447                 
448                 bool val = (a < b); // this should produce a clt_un
449                 if (val)
450                         return 1;
451                 
452                 val = (a < c); // this should produce a clt_un
453                 if (!val)
454                         return 1;
455                 
456                 val = (d < e); // this should produce a clt_un
457                 if (!val)
458                         return 1;
459                 
460                 val = (e < d); // this should produce a clt_un
461                 if (val)
462                         return 1;
463                 
464                 return 0;
465         }
466
467         static int test_0_cgt () {
468                 long a = 2;
469                 long b = 2;
470                 long c = 3;
471                 long d = 0xff00000002L;
472                 long e = -1;
473                 
474                 bool val = (a > b); // this should produce a cgt
475                 if (val)
476                         return 1;
477                 
478                 val = (a > c); // this should produce a cgt
479                 if (val)
480                         return 2;
481                 
482                 val = (c > a); // this should produce a cgt
483                 if (!val)
484                         return 3;
485                 
486                 val = (e > d); // this should produce a cgt
487                 if (val)
488                         return 4;
489                 
490                 val = (d > e); // this should produce a cgt
491                 if (!val)
492                         return 5;
493                 
494                 return 0;
495         }
496
497         static int test_0_cgt_un () {
498                 ulong a = 2;
499                 ulong b = 2;
500                 ulong c = 3;
501                 ulong d = 0xff00000002;
502                 ulong e = 0xffffffffffffffff;
503                 
504                 bool val = (a > b); // this should produce a cgt_un
505                 if (val)
506                         return 1;
507                 
508                 val = (a > c); // this should produce a cgt_un
509                 if (val)
510                         return 1;
511                 
512                 val = (d > e); // this should produce a cgt_un
513                 if (val)
514                         return 1;
515                 
516                 val = (e > d); // this should produce a cgt_un
517                 if (!val)
518                         return 1;
519                 
520                 return 0;
521         }
522
523         static long return_5low () {
524                 return 5;
525         }
526         
527         static long return_5high () {
528                 return 0x500000000;
529         }
530
531         static int test_3_long_ret () {
532                 long val = return_5low ();
533                 return (int) (val - 2);
534         }
535
536         static int test_1_long_ret2 () {
537                 long val = return_5high ();
538                 if (val > 0xffffffff)
539                         return 1;
540                 return 0;
541         }
542
543         static int test_3_byte_cast () {
544                 ulong val = 0xff00ff00f0f0f0f0;
545                 byte b;
546                 b = (byte) (val & 0xFF);
547                 if (b != 0xf0)
548                         return 1;
549                 return 3;
550         }
551         
552         static int test_4_ushort_cast () {
553                 ulong val = 0xff00ff00f0f0f0f0;
554                 ushort b;
555                 b = (ushort) (val & 0xFFFF);
556                 if (b != 0xf0f0)
557                         return 1;
558                 return 4;
559         }
560
561         static int test_500_mul_div () {
562                 long val = 1000;
563                 long exp = 10;
564                 long maxexp = 20;
565                 long res = val * exp / maxexp;
566
567                 return (int)res;
568         }
569
570         static long position = 0;
571
572         static int test_4_static_inc_long () {
573
574                 int count = 4;
575
576                 position = 0;
577
578                 position += count;
579
580                 return (int)position;
581         }
582         
583         static void doit (double value, out long m) {
584                 m = (long) value;
585         }
586         
587         static int test_0_ftol_clobber () {
588                 long m;
589                 doit (1.3, out m);
590                 if (m != 1)
591                         return 2;
592                 return 0;
593         }
594 }
595