2008-08-22 Zoltan Varga <vargaz@gmail.com>
[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  * public 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         public static int Main () {
29                 return TestDriver.RunTests (typeof (Tests));
30         }
31
32         public static int test_10_simple_cast () {
33                 long a = 10;
34                 return (int)a;
35         }
36
37         public static int test_1_bigmul1 () {
38                 int a;
39                 int b;
40                 long c;
41                 a = 10;
42                 b = 10;
43                 c = (long)a * (long)b;
44                 if (c == 100)
45                         return 1;
46                 return 0;
47         }
48
49         public static int test_1_bigmul2 () {
50                 int a = System.Int32.MaxValue, b = System.Int32.MaxValue;
51                 long s = System.Int64.MinValue;
52                 long c;
53                 c = s + (long) a * (long) b;
54                 if (c == -4611686022722355199)
55                         return 1;
56                 return 0;
57         }
58         
59         public static int test_1_bigmul3 () {
60                 int a = 10, b = 10;
61                 ulong c;
62                 c = (ulong) a * (ulong) b;
63                 if (c == 100)
64                         return 1;
65                 return 0;
66         }
67
68         public static int test_1_bigmul4 () {
69                 int a = System.Int32.MaxValue, b = System.Int32.MaxValue;
70                 ulong c;
71                 c = (ulong) a * (ulong) b;
72                 if (c == 4611686014132420609)
73                         return 1;
74                 return 0;
75         }
76         
77         public static int test_1_bigmul5 () {
78                 int a = System.Int32.MaxValue, b = System.Int32.MinValue;
79                 long c;
80                 c = (long) a * (long) b;
81                 if (c == -4611686016279904256)
82                         return 1;
83                 return 0;
84         }
85         
86         public static int test_1_bigmul6 () {
87                 uint a = System.UInt32.MaxValue, b = System.UInt32.MaxValue/(uint)2;
88                 ulong c;
89                 c = (ulong) a * (ulong) b;
90                 if (c == 9223372030412324865)
91                         return 1;
92                 return 0;
93         }
94         
95         public static int test_0_beq () {
96                 long a = 0xffffffffff;
97                 if (a != 0xffffffffff)
98                         return 1;
99                 return 0;
100         }
101
102         public static int test_0_bne_un () {
103                 long a = 0xffffffffff;
104                 if (a == 0xfffffffffe)
105                         return 1;
106                 if (a == 0xfeffffffff)
107                         return 2;
108                 return 0;
109         }
110
111         public static int test_0_ble () {
112                 long a = 0xffffffffff;
113                 if (a > 0xffffffffff)
114                         return 1;
115
116                 if (a > 0x1ffffffffff)
117                         return 2;
118
119                 if (a > 0xff00000000) {} else
120                         return 3;
121
122                 if (a > 0xfeffffffff) {} else
123                         return 4;
124
125                 a = 0xff00000000;
126                 if (a > 0xffffffffff)
127                         return 5;
128
129                 return 0;
130         }
131
132         public static int test_0_ble_un () {
133                 ulong a = 0xffffffffff;
134                 if (a > 0xffffffffff)
135                         return 1;
136
137                 if (a > 0x1ffffffffff)
138                         return 2;
139
140                 if (a > 0xff00000000) {} else
141                         return 3;
142
143                 if (a > 0xfeffffffff) {} else
144                         return 4;
145
146                 a = 0xff00000000;
147                 if (a > 0xffffffffff)
148                         return 5;
149
150                 return 0;
151         }
152
153         public static int test_0_bge () {
154                 long a = 0xffffffffff;
155                 if (a < 0xffffffffff)
156                         return 1;
157
158                 if (a < 0x1ffffffffff) {} else
159                         return 2;
160
161                 if (a < 0xff00000000)
162                         return 3;
163
164                 if (a < 0xfeffffffff)
165                         return 4;
166
167                 a = 0xff00000000;
168                 if (a < 0xffffffffff) {} else
169                         return 5;
170
171                 return 0;
172         }
173
174         public static int test_0_bge_un () {
175                 ulong a = 0xffffffffff;
176                 if (a < 0xffffffffff)
177                         return 1;
178
179                 if (a < 0x1ffffffffff) {} else
180                         return 2;
181
182                 if (a < 0xff00000000)
183                         return 3;
184
185                 if (a < 0xfeffffffff)
186                         return 4;
187
188                 a = 0xff00000000;
189                 if (a < 0xffffffffff) {} else
190                         return 5;
191
192                 return 0;
193         }
194
195         public static int test_0_blt () {
196                 long a = 0xfffffffffe;
197                 if (a >= 0xffffffffff)
198                         return 1;
199
200                 if (a >= 0x1fffffffffe)
201                         return 2;
202
203                 if (a >= 0xff00000000) {} else
204                         return 3;
205
206                 if (a >= 0xfefffffffe) {} else
207                         return 4;
208
209                 a = 0xff00000000;
210                 if (a >= 0xffffffffff)
211                         return 5;
212
213                 return 0;
214         }
215
216         public static int test_0_blt_un () {
217                 ulong a = 0xfffffffffe;
218                 if (a >= 0xffffffffff)
219                         return 1;
220
221                 if (a >= 0x1fffffffffe)
222                         return 2;
223
224                 if (a >= 0xff00000000) {} else
225                         return 3;
226
227                 if (a >= 0xfefffffffe) {} else
228                         return 4;
229
230                 a = 0xff00000000;
231                 if (a >= 0xffffffffff)
232                         return 5;
233
234                 return 0;
235         }
236
237         public static int test_0_bgt () {
238                 long a = 0xffffffffff;
239                 if (a <= 0xfffffffffe)
240                         return 1;
241
242                 if (a <= 0x1ffffffffff) {} else
243                         return 2;
244
245                 if (a <= 0xff00000000)
246                         return 3;
247
248                 if (a <= 0xfeffffffff)
249                         return 4;
250
251                 a = 0xff00000000;
252                 if (a <= 0xffffffffff) {} else
253                         return 5;
254
255                 return 0;
256         }
257
258         public static int test_0_bgt_un () {
259                 ulong a = 0xffffffffff;
260                 if (a <= 0xfffffffffe)
261                         return 1;
262
263                 if (a <= 0x1ffffffffff) {} else
264                         return 2;
265
266                 if (a <= 0xff00000000)
267                         return 3;
268
269                 if (a <= 0xfeffffffff)
270                         return 4;
271
272                 a = 0xff00000000;
273                 if (a <= 0xffffffffff) {} else
274                         return 5;
275
276                 return 0;
277         }
278
279         public static int test_0_conv_to_i4 () {
280                 long a = 0;
281
282                 return (int)a;
283         }
284
285         public static int test_32_conv_to_u4 () {
286                 long a = 32;
287
288                 return (int)(uint)a;
289         }
290
291         public static int test_15_conv_to_u4_2 () {
292                 long a = 0x10000000f;
293
294                 return (int)(uint)a;
295         }
296
297         public static int test_0_conv_from_i4 () {
298                 long a = 2;
299                 if (a != 2)
300                         return 1;
301
302                 int b = 2;
303
304                 if (a != b)
305                     return 2;
306                 return 0;
307         }
308
309         public static int test_0_conv_from_i4_negative () {
310                 long a = -2;
311                 if (a != -2)
312                         return 1;
313
314                 int b = -2;
315
316                 if (a != b)
317                     return 2;
318                 return 0;
319         }
320
321         /*
322         public static int test_0_conv_from_r8 () {
323                 double b = 2.0;
324                 long a = (long)b;
325
326                 if (a != 2)
327                         return 1;
328                 return 0;
329         }
330
331         public static int test_0_conv_from_r4 () {
332                 float b = 2.0F;
333                 long a = (long)b;
334
335                 if (a != 2)
336                         return 1;
337                 return 0;
338         }
339         */
340         
341         public static int test_8_and () {
342                 long a = 0xffffffffff;
343                 long b = 8;             
344                 return (int)(a & b);
345         }
346
347         public static int test_8_and_imm () {
348                 long a = 0xffffffffff;
349                 return (int)(a & 8);
350         }
351
352         public static int test_10_or () {
353                 long a = 8;
354                 long b = 2;             
355                 return (int)(a | b);
356         }
357
358         public static int test_10_or_imm () {
359                 long a = 8;
360                 return (int)(a | 2);
361         }
362
363         public static int test_5_xor () {
364                 long a = 7;
365                 long b = 2;             
366                 return (int)(a ^ b);
367         }
368
369         public static int test_5_xor_imm () {
370                 long a = 7;
371                 return (int)(a ^ 2);
372         }
373
374         public static int test_5_add () {
375                 long a = 2;
376                 long b = 3;             
377                 return (int)(a + b);
378         }
379
380         public static int test_5_add_imm () {
381                 long a = 2;
382                 return (int)(a + 3);
383         }
384
385         public static int test_0_add_imm_carry () {
386                 long a = -1;
387                 return (int)(a + 1);
388         }
389
390         public static int test_0_add_imm_no_inc () {
391                 // we can't blindly convert an add x, 1 to an inc x
392                 long a = 0x1ffffffff;
393                 long c;
394                 c = a + 2;
395                 if (c == ((a + 1) + 1))
396                         return 0;
397                 return 1;
398         }
399
400         public static int test_4_addcc_imm () {
401                 long a = 3;
402                 long b = 0;
403                 return (int)(a - b + 1);
404         }
405
406         public static int test_5_sub () {
407                 long a = 8;
408                 long b = 3;             
409                 return (int)(a - b);
410         }
411
412         public static int test_5_sub_imm () {
413                 long a = 8;
414                 return (int)(a - 3);
415         }
416
417         public static int test_0_sub_imm_carry () {
418                 long a = 0;
419                 return (int)((a - 1) + 1);
420         }
421
422         public static int test_0_add_ovf () {
423                 long i, j, k;
424
425                 checked {
426                         i = System.Int64.MinValue;
427                         j = 0;
428                         k = i + j;
429                 }
430
431                 if (k != System.Int64.MinValue)
432                         return 1;
433
434                 checked {
435                         i = System.Int64.MaxValue;
436                         j = 0;
437                         k = i + j;
438                 }
439
440                 if (k != System.Int64.MaxValue)
441                         return 2;
442
443                 checked {
444                         i = System.Int64.MinValue;
445                         j = System.Int64.MaxValue;
446                         k = i + j;
447                 }
448
449                 if (k != -1)
450                         return 3;
451
452                 checked {
453                         i = System.Int64.MaxValue;
454                         j = System.Int64.MinValue;
455                         k = i + j;
456                 }
457
458                 if (k != -1)
459                         return 4;
460
461                 checked {
462                         i = System.Int64.MinValue + 1234;
463                         j = -1234;
464                         k = i + j;
465                 }
466
467                 if (k != System.Int64.MinValue)
468                         return 5;
469
470                 checked {
471                         i = System.Int64.MaxValue - 1234;
472                         j = 1234;
473                         k = i + j;
474                 }
475
476                 if (k != System.Int64.MaxValue)
477                         return 6;
478
479                 return 0;
480         }
481
482         public static int test_0_add_un_ovf () {
483                 ulong n = (ulong)134217728 * 16;
484                 ulong number = checked (n + (uint)0);
485
486                 return number == n ? 0 : 1;
487         }
488
489         public static int test_0_sub_ovf () {
490                 long i, j, k;
491
492                 checked {
493                         i = System.Int64.MinValue;
494                         j = 0;
495                         k = i - j;
496                 }
497
498                 if (k != System.Int64.MinValue)
499                         return 1;
500
501                 checked {
502                         i = System.Int64.MaxValue;
503                         j = 0;
504                         k = i - j;
505                 }
506
507                 if (k != System.Int64.MaxValue)
508                         return 2;
509
510                 checked {
511                         i = System.Int64.MinValue;
512                         j = System.Int64.MinValue + 1234;
513                         k = i - j;
514                 }
515
516                 if (k != -1234)
517                         return 3;
518
519                 checked {
520                         i = System.Int64.MaxValue;
521                         j = 1234;
522                         k = i - j;
523                 }
524
525                 if (k != System.Int64.MaxValue - 1234)
526                         return 4;
527
528                 checked {
529                         i = System.Int64.MaxValue - 1234;
530                         j = -1234;
531                         k = i - j;
532                 }
533
534                 if (k != System.Int64.MaxValue)
535                         return 5;
536
537                 checked {
538                         i = System.Int64.MinValue + 1234;
539                         j = 1234;
540                         k = i - j;
541                 }
542
543                 if (k != System.Int64.MinValue)
544                         return 6;
545
546                 return 0;
547         }
548
549         public static int test_0_sub_ovf_un () {
550                 ulong i, j, k;
551
552                 checked {
553                         i = System.UInt64.MaxValue;
554                         j = 0;
555                         k = i - j;
556                 }
557
558                 if (k != System.UInt64.MaxValue)
559                         return 1;
560
561                 checked {
562                         i = System.UInt64.MaxValue;
563                         j = System.UInt64.MaxValue;
564                         k = i - j;
565                 }
566
567                 if (k != 0)
568                         return 2;
569
570                 return 0;
571         }
572
573         public static int test_2_neg () {
574                 long a = -2;            
575                 return (int)(-a);
576         }       
577
578         public static int test_0_neg_large () {
579                 long min = -9223372036854775808;
580                 unchecked {
581                         ulong ul = (ulong)min;
582                         return (min == -(long)ul) ? 0 : 1;
583                 }
584         }       
585
586         public static int test_5_shift ()
587         {
588                 long a = 9;
589                 int b = 1;
590                 int count = 0;
591                 
592                 if ((a >> b) != 4)
593                         return count;
594                 count++;
595
596                 if ((a >> 63) != 0)
597                         return count;
598                 count++;
599
600                 if ((a << 1) != 18)
601                         return count;
602                 count++;
603
604                 if ((a << b) != 18)
605                         return count;
606                 count++;
607
608                 a = -9;
609                 if ((a >> b) != -5)
610                         return count;
611                 count++;
612
613                 return count;
614         }
615
616         public static int test_1_shift_u ()
617         {
618                 ulong a;
619                 int count = 0;
620
621                 // The JIT optimizes this
622                 a = 8589934592UL;
623                 if ((a >> 32) != 2)
624                         return 0;
625                 count ++;
626
627                 return count;
628         }
629
630         public static int test_1_shift_u_32 ()
631         {
632                 ulong a;
633                 int count = 0;
634
635                 a = UInt64.MaxValue;
636                 // Avoid constant folding
637                 for (int i = 0; i < 32; ++i)
638                         count ++;
639
640                 if ((a >> count) != 0xFFFFFFFFUL)
641                         return 0;
642                 else
643                         return 1;
644         }
645
646         public static int test_1_simple_neg () {
647                 long a = 9;
648                 
649                 if (-a != -9)
650                         return 0;
651                 return 1;
652         }
653
654         public static int test_2_compare () {
655                 long a = 1;
656                 long b = 1;
657                 
658                 if (a != b)
659                         return 0;
660                 return 2;
661         }
662
663         public static int test_9_alu ()
664         {
665                 long a = 9, b = 6;
666                 int count = 0;
667                 
668                 if ((a + b) != 15)
669                         return count;
670                 count++;
671                 
672                 if ((a - b) != 3)
673                         return count;
674                 count++;
675
676                 if ((a & 8) != 8)
677                         return count;
678                 count++;
679
680                 if ((a | 2) != 11)
681                         return count;
682                 count++;
683
684                 if ((a * b) != 54)
685                         return count;
686                 count++;
687                 
688                 if ((a / 4) != 2)
689                         return count;
690                 count++;
691                 
692                 if ((a % 4) != 1)
693                         return count;
694                 count++;
695
696                 if (-a != -9)
697                         return count;
698                 count++;
699
700                 b = -1;
701                 if (~b != 0)
702                         return count;
703                 count++;
704
705                 return count;
706         }
707         
708         public static int test_24_mul () {
709                 long a = 8;
710                 long b = 3;             
711                 return (int)(a * b);
712         }       
713         
714         public static int test_24_mul_ovf () {
715                 long a = 8;
716                 long b = 3;
717                 long res;
718                 
719                 checked {
720                         res = a * b;
721                 }
722                 return (int)res;
723         }       
724
725         public static int test_24_mul_un () {
726                 ulong a = 8;
727                 ulong b = 3;            
728                 return (int)(a * b);
729         }       
730         
731         public static int test_24_mul_ovf_un () {
732                 ulong a = 8;
733                 ulong b = 3;
734                 ulong res;
735                 
736                 checked {
737                         res = a * b;
738                 }
739                 return (int)res;
740         }       
741
742         public static int test_0_mul_imm () {
743             long i = 4;
744
745                 if ((i * 0) != 0)
746                         return 1;
747                 if ((i * 1) != 4)
748                         return 2;
749                 if ((i * 2) != 8)
750                         return 3;
751                 if ((i * 3) != 12)
752                         return 4;
753                 if ((i * 1234) != 4936)
754                         return 5;
755                 if ((i * -1) != -4)
756                         return 6;
757                 if ((i * -2) != -8)
758                         return 7;
759                 if ((i * -3) != -12)
760                         return 8;
761                 if ((i * -1234) != -4936)
762                         return 9;
763
764                 return 0;
765         }
766
767         public static int test_0_mul_imm_opt ()
768         {
769                 long i;
770
771                 i = 1;
772                 if ((i * 2) != 2)
773                         return 1;
774                 i = -1;
775                 if ((i * 2) != -2)
776                         return 2;
777                 i = 1;
778                 if ((i * 3) != 3)
779                         return 3;
780                 i = -1;
781                 if ((i * 3) != -3)
782                         return 4;
783                 i = 1;
784                 if ((i * 5) != 5)
785                         return 5;
786                 i = -1;
787                 if ((i * 5) != -5)
788                         return 6;
789                 i = 1;
790                 if ((i * 6) != 6)
791                         return 7;
792                 i = -1;
793                 if ((i * 6) != -6)
794                         return 8;
795                 i = 1;
796                 if ((i * 9) != 9)
797                         return 9;
798                 i = -1;
799                 if ((i * 9) != -9)
800                         return 10;
801                 i = 1;
802                 if ((i * 10) != 10)
803                         return 11;
804                 i = -1;
805                 if ((i * 10) != -10)
806                         return 12;
807                 i = 1;
808                 if ((i * 12) != 12)
809                         return 13;
810                 i = -1;
811                 if ((i * 12) != -12)
812                         return 14;
813                 i = 1;
814                 if ((i * 25) != 25)
815                         return 15;
816                 i = -1;
817                 if ((i * 25) != -25)
818                         return 16;
819                 i = 1;
820                 if ((i * 100) != 100)
821                         return 17;
822                 i = -1;
823                 if ((i * 100) != -100)
824                         return 18;
825                 
826                 return 0;
827         }
828         
829         public static int test_4_divun () {
830                 uint b = 12;
831                 int a = 3;
832                 return (int)(b / a);
833         }
834
835         public static int test_1431655764_bigdivun_imm () {
836                 unchecked {
837                         uint b = (uint)-2;
838                         return (int)(b / 3);
839                 }
840         }
841
842         public static int test_1431655764_bigdivun () {
843                 unchecked {
844                         uint b = (uint)-2;
845                         int a = 3;
846                         return (int)(b / a);
847                 }
848         }
849
850         public static int test_1_remun () {
851                 uint b = 13;
852                 int a = 3;
853                 return (int)(b % a);
854         }
855
856         public static int test_2_bigremun () {
857                 unchecked {
858                         uint b = (uint)-2;
859                         int a = 3;
860                         return (int)(b % a);
861                 }
862         }
863
864         public static int test_0_ceq () {
865                 long a = 2;
866                 long b = 2;
867                 long c = 3;
868                 long d = 0xff00000002;
869                 
870                 bool val = (a == b); // this should produce a ceq
871                 if (!val)
872                         return 1;
873                 
874                 val = (a == c); // this should produce a ceq
875                 if (val)
876                         return 2;
877                 
878                 val = (a == d); // this should produce a ceq
879                 if (val)
880                         return 3;
881                 
882                 return 0;
883         }
884
885         public static int test_0_ceq_complex () {
886                 long l = 1, ll = 2;
887
888                 if (l < 0 != ll < 0)
889                         return 1;
890
891                 return 0;
892         }
893         
894         public static int test_0_clt () {
895                 long a = 2;
896                 long b = 2;
897                 long c = 3;
898                 long d = 0xff00000002L;
899                 long e = -1;
900                 
901                 bool val = (a < b); // this should produce a clt
902                 if (val)
903                         return 1;
904                 
905                 val = (a < c); // this should produce a clt
906                 if (!val)
907                         return 2;
908                 
909                 val = (c < a); // this should produce a clt
910                 if (val)
911                         return 3;
912                 
913                 val = (e < d); // this should produce a clt
914                 if (!val)
915                         return 4;
916                 
917                 val = (d < e); // this should produce a clt
918                 if (val)
919                         return 5;
920                 
921                 return 0;
922         }
923         
924         public static int test_0_clt_un () {
925                 ulong a = 2;
926                 ulong b = 2;
927                 ulong c = 3;
928                 ulong d = 0xff00000002;
929                 ulong e = 0xffffffffffffffff;
930                 
931                 bool val = (a < b); // this should produce a clt_un
932                 if (val)
933                         return 1;
934                 
935                 val = (a < c); // this should produce a clt_un
936                 if (!val)
937                         return 1;
938                 
939                 val = (d < e); // this should produce a clt_un
940                 if (!val)
941                         return 1;
942                 
943                 val = (e < d); // this should produce a clt_un
944                 if (val)
945                         return 1;
946                 
947                 return 0;
948         }
949
950         public static int test_0_cgt () {
951                 long a = 2;
952                 long b = 2;
953                 long c = 3;
954                 long d = 0xff00000002L;
955                 long e = -1;
956                 
957                 bool val = (a > b); // this should produce a cgt
958                 if (val)
959                         return 1;
960                 
961                 val = (a > c); // this should produce a cgt
962                 if (val)
963                         return 2;
964                 
965                 val = (c > a); // this should produce a cgt
966                 if (!val)
967                         return 3;
968                 
969                 val = (e > d); // this should produce a cgt
970                 if (val)
971                         return 4;
972                 
973                 val = (d > e); // this should produce a cgt
974                 if (!val)
975                         return 5;
976                 
977                 return 0;
978         }
979
980         public static int test_0_cgt_un () {
981                 ulong a = 2;
982                 ulong b = 2;
983                 ulong c = 3;
984                 ulong d = 0xff00000002;
985                 ulong e = 0xffffffffffffffff;
986                 
987                 bool val = (a > b); // this should produce a cgt_un
988                 if (val)
989                         return 1;
990                 
991                 val = (a > c); // this should produce a cgt_un
992                 if (val)
993                         return 1;
994                 
995                 val = (d > e); // this should produce a cgt_un
996                 if (val)
997                         return 1;
998                 
999                 val = (e > d); // this should produce a cgt_un
1000                 if (!val)
1001                         return 1;
1002                 
1003                 return 0;
1004         }
1005
1006         static long return_5low () {
1007                 return 5;
1008         }
1009         
1010         static long return_5high () {
1011                 return 0x500000000;
1012         }
1013
1014         public static int test_3_long_ret () {
1015                 long val = return_5low ();
1016                 return (int) (val - 2);
1017         }
1018
1019         public static int test_1_long_ret2 () {
1020                 long val = return_5high ();
1021                 if (val > 0xffffffff)
1022                         return 1;
1023                 return 0;
1024         }
1025
1026         public static int test_3_byte_cast () {
1027                 ulong val = 0xff00ff00f0f0f0f0;
1028                 byte b;
1029                 b = (byte) (val & 0xFF);
1030                 if (b != 0xf0)
1031                         return 1;
1032
1033                 return 3;
1034         }
1035
1036         public static int test_4_ushort_cast () {
1037                 ulong val = 0xff00ff00f0f0f0f0;
1038                 ushort b;
1039                 b = (ushort) (val & 0xFFFF);
1040                 if (b != 0xf0f0)
1041                         return 1;
1042                 return 4;
1043         }
1044
1045         public static int test_500_mul_div () {
1046                 long val = 1000;
1047                 long exp = 10;
1048                 long maxexp = 20;
1049                 long res = val * exp / maxexp;
1050
1051                 return (int)res;
1052         }
1053         
1054         public static int test_3_checked_cast_un () {
1055                 ulong i = 2;
1056                 long j;
1057
1058                 checked { j = (long)i; }
1059
1060                 if (j != 2)
1061                         return 0;
1062                 return 3;
1063         }
1064         
1065         public static int test_4_checked_cast () {
1066                 long i = 3;
1067                 ulong j;
1068
1069                 checked { j = (ulong)i; }
1070
1071                 if (j != 3)
1072                         return 0;
1073                 return 4;
1074         }
1075
1076         public static int test_12_checked_i1_cast () {
1077                 long l = 12;
1078
1079                 checked {
1080                         return (sbyte)l;
1081                 }
1082         }
1083
1084         public static int test_127_checked_i1_cast_un () {
1085                 ulong l = 127;
1086
1087                 checked {
1088                         return (sbyte)l;
1089                 }
1090         }
1091
1092         public static int test_1234_checked_i2_cast () {
1093                 long l = 1234;
1094
1095                 checked {
1096                         return (short)l;
1097                 }
1098         }
1099
1100         public static int test_32767_checked_i2_cast_un () {
1101                 ulong l = 32767;
1102
1103                 checked {
1104                         return (ushort)l;
1105                 }
1106         }
1107
1108         public static int test_1234_checked_i4_cast () {
1109                 ulong ul = 1234;
1110
1111                 checked {
1112                         return (int)ul;
1113                 }
1114         }
1115
1116         public static int test_10_int_uint_compare () {
1117                 uint size = 10;
1118                 int j = 0;
1119                 for (int i = 0; i < size; ++i) {
1120                         j++;
1121                 }
1122                 return j;
1123         }
1124
1125         public static int test_0_ulong_regress () {
1126                 ulong u = 4257145737;
1127                 u --;
1128                 return (u == 4257145736) ? 0 : 1;
1129         }
1130
1131         public static int test_0_ulong_regress2 () {
1132                 int p2 = 31;
1133                 ulong sum_p = 2897079476 + (ulong) (1 << p2);
1134                 return (sum_p == 749595828) ? 0 : 1;
1135         }
1136         
1137         public static int test_0_assemble_long ()
1138         {
1139                 uint a = 5;
1140                 ulong x = 0x12345678;
1141                 ulong y = 1;
1142                 
1143                 
1144                 ulong z = ((x - y) << 32) | a;
1145                 
1146                 if (z != 0x1234567700000005)
1147                         return 1;
1148                 
1149                 return 0;
1150         }
1151         
1152         public static int test_0_hash ()
1153         {
1154                 ulong x = 0x1234567887654321;
1155                 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
1156                 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
1157                         return h;
1158                 return 0;
1159                                 
1160         }
1161
1162         public static int test_0_shift_regress () {
1163                 long a = 0; 
1164                 int b = 6; 
1165                 UInt16 c = 3;
1166
1167                 return ((a >> (b - c)) == 0) ? 0 : 1;
1168         }
1169
1170         public static int test_1234_conv_ovf_u8 () {
1171                 int i = 1234;
1172
1173                 checked {
1174                         ulong l = (ulong)i;
1175                         return (int)l;
1176                 }
1177         }
1178
1179         public static int test_0_regress_cprop_80738 () {
1180                 int hours = Int32.MinValue;
1181                 int hrssec = (hours * 3600);
1182                 long t = ((long)(hrssec) * 1000L);
1183
1184                 return t == 0 ? 0 : 1;
1185         }
1186 }
1187