19c33016558ce9370177433000f1f37c5ba24f5d
[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 get_high_bit (ulong a) {
353                 if ((a & 0x8000000000000000) != 0)
354                         return 1;
355                 return 0;
356         }
357
358         public static int test_1_and () {
359                 ulong a = 0xabcd1234deadbeef;
360                 return get_high_bit (a);
361         }
362
363         public static int test_10_or () {
364                 long a = 8;
365                 long b = 2;             
366                 return (int)(a | b);
367         }
368
369         public static int test_10_or_imm () {
370                 long a = 8;
371                 return (int)(a | 2);
372         }
373
374         public static int test_5_xor () {
375                 long a = 7;
376                 long b = 2;             
377                 return (int)(a ^ b);
378         }
379
380         public static int test_5_xor_imm () {
381                 long a = 7;
382                 return (int)(a ^ 2);
383         }
384
385         public static int test_5_add () {
386                 long a = 2;
387                 long b = 3;             
388                 return (int)(a + b);
389         }
390
391         public static int test_5_add_imm () {
392                 long a = 2;
393                 return (int)(a + 3);
394         }
395
396         public static int test_0_add_imm_carry () {
397                 long a = -1;
398                 return (int)(a + 1);
399         }
400
401         public static int test_0_add_imm_no_inc () {
402                 // we can't blindly convert an add x, 1 to an inc x
403                 long a = 0x1ffffffff;
404                 long c;
405                 c = a + 2;
406                 if (c == ((a + 1) + 1))
407                         return 0;
408                 return 1;
409         }
410
411         public static int test_4_addcc_imm () {
412                 long a = 3;
413                 long b = 0;
414                 return (int)(a - b + 1);
415         }
416
417         public static int test_5_sub () {
418                 long a = 8;
419                 long b = 3;             
420                 return (int)(a - b);
421         }
422
423         public static int test_5_sub_imm () {
424                 long a = 8;
425                 return (int)(a - 3);
426         }
427
428         public static int test_0_sub_imm_carry () {
429                 long a = 0;
430                 return (int)((a - 1) + 1);
431         }
432
433         public static int test_0_add_ovf () {
434                 long i, j, k;
435
436                 checked {
437                         i = System.Int64.MinValue;
438                         j = 0;
439                         k = i + j;
440                 }
441
442                 if (k != System.Int64.MinValue)
443                         return 1;
444
445                 checked {
446                         i = System.Int64.MaxValue;
447                         j = 0;
448                         k = i + j;
449                 }
450
451                 if (k != System.Int64.MaxValue)
452                         return 2;
453
454                 checked {
455                         i = System.Int64.MinValue;
456                         j = System.Int64.MaxValue;
457                         k = i + j;
458                 }
459
460                 if (k != -1)
461                         return 3;
462
463                 checked {
464                         i = System.Int64.MaxValue;
465                         j = System.Int64.MinValue;
466                         k = i + j;
467                 }
468
469                 if (k != -1)
470                         return 4;
471
472                 checked {
473                         i = System.Int64.MinValue + 1234;
474                         j = -1234;
475                         k = i + j;
476                 }
477
478                 if (k != System.Int64.MinValue)
479                         return 5;
480
481                 checked {
482                         i = System.Int64.MaxValue - 1234;
483                         j = 1234;
484                         k = i + j;
485                 }
486
487                 if (k != System.Int64.MaxValue)
488                         return 6;
489
490                 return 0;
491         }
492
493         public static int test_0_add_un_ovf () {
494                 ulong n = (ulong)134217728 * 16;
495                 ulong number = checked (n + (uint)0);
496
497                 return number == n ? 0 : 1;
498         }
499
500         public static int test_0_sub_ovf () {
501                 long i, j, k;
502
503                 checked {
504                         i = System.Int64.MinValue;
505                         j = 0;
506                         k = i - j;
507                 }
508
509                 if (k != System.Int64.MinValue)
510                         return 1;
511
512                 checked {
513                         i = System.Int64.MaxValue;
514                         j = 0;
515                         k = i - j;
516                 }
517
518                 if (k != System.Int64.MaxValue)
519                         return 2;
520
521                 checked {
522                         i = System.Int64.MinValue;
523                         j = System.Int64.MinValue + 1234;
524                         k = i - j;
525                 }
526
527                 if (k != -1234)
528                         return 3;
529
530                 checked {
531                         i = System.Int64.MaxValue;
532                         j = 1234;
533                         k = i - j;
534                 }
535
536                 if (k != System.Int64.MaxValue - 1234)
537                         return 4;
538
539                 checked {
540                         i = System.Int64.MaxValue - 1234;
541                         j = -1234;
542                         k = i - j;
543                 }
544
545                 if (k != System.Int64.MaxValue)
546                         return 5;
547
548                 checked {
549                         i = System.Int64.MinValue + 1234;
550                         j = 1234;
551                         k = i - j;
552                 }
553
554                 if (k != System.Int64.MinValue)
555                         return 6;
556
557                 return 0;
558         }
559
560         public static int test_0_sub_ovf_un () {
561                 ulong i, j, k;
562
563                 checked {
564                         i = System.UInt64.MaxValue;
565                         j = 0;
566                         k = i - j;
567                 }
568
569                 if (k != System.UInt64.MaxValue)
570                         return 1;
571
572                 checked {
573                         i = System.UInt64.MaxValue;
574                         j = System.UInt64.MaxValue;
575                         k = i - j;
576                 }
577
578                 if (k != 0)
579                         return 2;
580
581                 return 0;
582         }
583
584         public static int test_2_neg () {
585                 long a = -2;            
586                 return (int)(-a);
587         }       
588
589         public static int test_0_neg_large () {
590                 long min = -9223372036854775808;
591                 unchecked {
592                         ulong ul = (ulong)min;
593                         return (min == -(long)ul) ? 0 : 1;
594                 }
595         }       
596
597         public static int test_5_shift ()
598         {
599                 long a = 9;
600                 int b = 1;
601                 int count = 0;
602                 
603                 if ((a >> b) != 4)
604                         return count;
605                 count++;
606
607                 if ((a >> 63) != 0)
608                         return count;
609                 count++;
610
611                 if ((a << 1) != 18)
612                         return count;
613                 count++;
614
615                 if ((a << b) != 18)
616                         return count;
617                 count++;
618
619                 a = -9;
620                 if ((a >> b) != -5)
621                         return count;
622                 count++;
623
624                 return count;
625         }
626
627         public static int test_1_shift_u ()
628         {
629                 ulong a;
630                 int count = 0;
631
632                 // The JIT optimizes this
633                 a = 8589934592UL;
634                 if ((a >> 32) != 2)
635                         return 0;
636                 count ++;
637
638                 return count;
639         }
640
641         public static int test_1_shift_u_32 ()
642         {
643                 ulong a;
644                 int count = 0;
645
646                 a = UInt64.MaxValue;
647                 // Avoid constant folding
648                 for (int i = 0; i < 32; ++i)
649                         count ++;
650
651                 if ((a >> count) != 0xFFFFFFFFUL)
652                         return 0;
653                 else
654                         return 1;
655         }
656
657         public static int test_1_simple_neg () {
658                 long a = 9;
659                 
660                 if (-a != -9)
661                         return 0;
662                 return 1;
663         }
664
665         public static int test_2_compare () {
666                 long a = 1;
667                 long b = 1;
668                 
669                 if (a != b)
670                         return 0;
671                 return 2;
672         }
673
674         public static int test_9_alu ()
675         {
676                 long a = 9, b = 6;
677                 int count = 0;
678                 
679                 if ((a + b) != 15)
680                         return count;
681                 count++;
682                 
683                 if ((a - b) != 3)
684                         return count;
685                 count++;
686
687                 if ((a & 8) != 8)
688                         return count;
689                 count++;
690
691                 if ((a | 2) != 11)
692                         return count;
693                 count++;
694
695                 if ((a * b) != 54)
696                         return count;
697                 count++;
698                 
699                 if ((a / 4) != 2)
700                         return count;
701                 count++;
702                 
703                 if ((a % 4) != 1)
704                         return count;
705                 count++;
706
707                 if (-a != -9)
708                         return count;
709                 count++;
710
711                 b = -1;
712                 if (~b != 0)
713                         return count;
714                 count++;
715
716                 return count;
717         }
718         
719         public static int test_24_mul () {
720                 long a = 8;
721                 long b = 3;             
722                 return (int)(a * b);
723         }       
724         
725         public static int test_24_mul_ovf () {
726                 long a = 8;
727                 long b = 3;
728                 long res;
729                 
730                 checked {
731                         res = a * b;
732                 }
733                 return (int)res;
734         }       
735
736         public static int test_24_mul_un () {
737                 ulong a = 8;
738                 ulong b = 3;            
739                 return (int)(a * b);
740         }       
741         
742         public static int test_24_mul_ovf_un () {
743                 ulong a = 8;
744                 ulong b = 3;
745                 ulong res;
746                 
747                 checked {
748                         res = a * b;
749                 }
750                 return (int)res;
751         }       
752
753         public static int test_0_mul_imm () {
754             long i = 4;
755
756                 if ((i * 0) != 0)
757                         return 1;
758                 if ((i * 1) != 4)
759                         return 2;
760                 if ((i * 2) != 8)
761                         return 3;
762                 if ((i * 3) != 12)
763                         return 4;
764                 if ((i * 1234) != 4936)
765                         return 5;
766                 if ((i * -1) != -4)
767                         return 6;
768                 if ((i * -2) != -8)
769                         return 7;
770                 if ((i * -3) != -12)
771                         return 8;
772                 if ((i * -1234) != -4936)
773                         return 9;
774
775                 return 0;
776         }
777
778         public static int test_0_mul_imm_opt ()
779         {
780                 long i;
781
782                 i = 1;
783                 if ((i * 2) != 2)
784                         return 1;
785                 i = -1;
786                 if ((i * 2) != -2)
787                         return 2;
788                 i = 1;
789                 if ((i * 3) != 3)
790                         return 3;
791                 i = -1;
792                 if ((i * 3) != -3)
793                         return 4;
794                 i = 1;
795                 if ((i * 5) != 5)
796                         return 5;
797                 i = -1;
798                 if ((i * 5) != -5)
799                         return 6;
800                 i = 1;
801                 if ((i * 6) != 6)
802                         return 7;
803                 i = -1;
804                 if ((i * 6) != -6)
805                         return 8;
806                 i = 1;
807                 if ((i * 9) != 9)
808                         return 9;
809                 i = -1;
810                 if ((i * 9) != -9)
811                         return 10;
812                 i = 1;
813                 if ((i * 10) != 10)
814                         return 11;
815                 i = -1;
816                 if ((i * 10) != -10)
817                         return 12;
818                 i = 1;
819                 if ((i * 12) != 12)
820                         return 13;
821                 i = -1;
822                 if ((i * 12) != -12)
823                         return 14;
824                 i = 1;
825                 if ((i * 25) != 25)
826                         return 15;
827                 i = -1;
828                 if ((i * 25) != -25)
829                         return 16;
830                 i = 1;
831                 if ((i * 100) != 100)
832                         return 17;
833                 i = -1;
834                 if ((i * 100) != -100)
835                         return 18;
836                 
837                 return 0;
838         }
839         
840         public static int test_4_divun () {
841                 uint b = 12;
842                 int a = 3;
843                 return (int)(b / a);
844         }
845
846         public static int test_1431655764_bigdivun_imm () {
847                 unchecked {
848                         uint b = (uint)-2;
849                         return (int)(b / 3);
850                 }
851         }
852
853         public static int test_1431655764_bigdivun () {
854                 unchecked {
855                         uint b = (uint)-2;
856                         int a = 3;
857                         return (int)(b / a);
858                 }
859         }
860
861         public static int test_1_remun () {
862                 uint b = 13;
863                 int a = 3;
864                 return (int)(b % a);
865         }
866
867         public static int test_2_bigremun () {
868                 unchecked {
869                         uint b = (uint)-2;
870                         int a = 3;
871                         return (int)(b % a);
872                 }
873         }
874
875         public static int test_0_ceq () {
876                 long a = 2;
877                 long b = 2;
878                 long c = 3;
879                 long d = 0xff00000002;
880                 
881                 bool val = (a == b); // this should produce a ceq
882                 if (!val)
883                         return 1;
884                 
885                 val = (a == c); // this should produce a ceq
886                 if (val)
887                         return 2;
888                 
889                 val = (a == d); // this should produce a ceq
890                 if (val)
891                         return 3;
892                 
893                 return 0;
894         }
895
896         public static int test_0_ceq_complex () {
897                 long l = 1, ll = 2;
898
899                 if (l < 0 != ll < 0)
900                         return 1;
901
902                 return 0;
903         }
904         
905         public static int test_0_clt () {
906                 long a = 2;
907                 long b = 2;
908                 long c = 3;
909                 long d = 0xff00000002L;
910                 long e = -1;
911                 
912                 bool val = (a < b); // this should produce a clt
913                 if (val)
914                         return 1;
915                 
916                 val = (a < c); // this should produce a clt
917                 if (!val)
918                         return 2;
919                 
920                 val = (c < a); // this should produce a clt
921                 if (val)
922                         return 3;
923                 
924                 val = (e < d); // this should produce a clt
925                 if (!val)
926                         return 4;
927                 
928                 val = (d < e); // this should produce a clt
929                 if (val)
930                         return 5;
931                 
932                 return 0;
933         }
934         
935         public static int test_0_clt_un () {
936                 ulong a = 2;
937                 ulong b = 2;
938                 ulong c = 3;
939                 ulong d = 0xff00000002;
940                 ulong e = 0xffffffffffffffff;
941                 
942                 bool val = (a < b); // this should produce a clt_un
943                 if (val)
944                         return 1;
945                 
946                 val = (a < c); // this should produce a clt_un
947                 if (!val)
948                         return 1;
949                 
950                 val = (d < e); // this should produce a clt_un
951                 if (!val)
952                         return 1;
953                 
954                 val = (e < d); // this should produce a clt_un
955                 if (val)
956                         return 1;
957                 
958                 return 0;
959         }
960
961         public static int test_0_cgt () {
962                 long a = 2;
963                 long b = 2;
964                 long c = 3;
965                 long d = 0xff00000002L;
966                 long e = -1;
967                 
968                 bool val = (a > b); // this should produce a cgt
969                 if (val)
970                         return 1;
971                 
972                 val = (a > c); // this should produce a cgt
973                 if (val)
974                         return 2;
975                 
976                 val = (c > a); // this should produce a cgt
977                 if (!val)
978                         return 3;
979                 
980                 val = (e > d); // this should produce a cgt
981                 if (val)
982                         return 4;
983                 
984                 val = (d > e); // this should produce a cgt
985                 if (!val)
986                         return 5;
987                 
988                 return 0;
989         }
990
991         public static int test_0_cgt_un () {
992                 ulong a = 2;
993                 ulong b = 2;
994                 ulong c = 3;
995                 ulong d = 0xff00000002;
996                 ulong e = 0xffffffffffffffff;
997                 
998                 bool val = (a > b); // this should produce a cgt_un
999                 if (val)
1000                         return 1;
1001                 
1002                 val = (a > c); // this should produce a cgt_un
1003                 if (val)
1004                         return 1;
1005                 
1006                 val = (d > e); // this should produce a cgt_un
1007                 if (val)
1008                         return 1;
1009                 
1010                 val = (e > d); // this should produce a cgt_un
1011                 if (!val)
1012                         return 1;
1013                 
1014                 return 0;
1015         }
1016
1017         public static int test_3_byte_cast () {
1018                 ulong val = 0xff00ff00f0f0f0f0;
1019                 byte b;
1020                 b = (byte) (val & 0xFF);
1021                 if (b != 0xf0)
1022                         return 1;
1023
1024                 return 3;
1025         }
1026
1027         public static int test_4_ushort_cast () {
1028                 ulong val = 0xff00ff00f0f0f0f0;
1029                 ushort b;
1030                 b = (ushort) (val & 0xFFFF);
1031                 if (b != 0xf0f0)
1032                         return 1;
1033                 return 4;
1034         }
1035
1036         public static int test_500_mul_div () {
1037                 long val = 1000;
1038                 long exp = 10;
1039                 long maxexp = 20;
1040                 long res = val * exp / maxexp;
1041
1042                 return (int)res;
1043         }
1044         
1045         public static int test_3_checked_cast_un () {
1046                 ulong i = 2;
1047                 long j;
1048
1049                 checked { j = (long)i; }
1050
1051                 if (j != 2)
1052                         return 0;
1053                 return 3;
1054         }
1055         
1056         public static int test_4_checked_cast () {
1057                 long i = 3;
1058                 ulong j;
1059
1060                 checked { j = (ulong)i; }
1061
1062                 if (j != 3)
1063                         return 0;
1064                 return 4;
1065         }
1066
1067         public static int test_12_checked_i1_cast () {
1068                 long l = 12;
1069
1070                 checked {
1071                         return (sbyte)l;
1072                 }
1073         }
1074
1075         public static int test_127_checked_i1_cast_un () {
1076                 ulong l = 127;
1077
1078                 checked {
1079                         return (sbyte)l;
1080                 }
1081         }
1082
1083         public static int test_1234_checked_i2_cast () {
1084                 long l = 1234;
1085
1086                 checked {
1087                         return (short)l;
1088                 }
1089         }
1090
1091         public static int test_32767_checked_i2_cast_un () {
1092                 ulong l = 32767;
1093
1094                 checked {
1095                         return (ushort)l;
1096                 }
1097         }
1098
1099         public static int test_1234_checked_i4_cast () {
1100                 ulong ul = 1234;
1101
1102                 checked {
1103                         return (int)ul;
1104                 }
1105         }
1106
1107         public static int test_10_int_uint_compare () {
1108                 uint size = 10;
1109                 int j = 0;
1110                 for (int i = 0; i < size; ++i) {
1111                         j++;
1112                 }
1113                 return j;
1114         }
1115
1116         public static int test_0_ulong_regress () {
1117                 ulong u = 4257145737;
1118                 u --;
1119                 return (u == 4257145736) ? 0 : 1;
1120         }
1121
1122         public static int test_0_ulong_regress2 () {
1123                 int p2 = 31;
1124                 ulong sum_p = 2897079476 + (ulong) (1 << p2);
1125                 return (sum_p == 749595828) ? 0 : 1;
1126         }
1127         
1128         public static int test_0_assemble_long ()
1129         {
1130                 uint a = 5;
1131                 ulong x = 0x12345678;
1132                 ulong y = 1;
1133                 
1134                 
1135                 ulong z = ((x - y) << 32) | a;
1136                 
1137                 if (z != 0x1234567700000005)
1138                         return 1;
1139                 
1140                 return 0;
1141         }
1142         
1143         public static int test_0_hash ()
1144         {
1145                 ulong x = 0x1234567887654321;
1146                 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
1147                 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
1148                         return h;
1149                 return 0;
1150                                 
1151         }
1152
1153         public static int test_0_shift_regress () {
1154                 long a = 0; 
1155                 int b = 6; 
1156                 UInt16 c = 3;
1157
1158                 return ((a >> (b - c)) == 0) ? 0 : 1;
1159         }
1160
1161         public static int test_1234_conv_ovf_u8 () {
1162                 int i = 1234;
1163
1164                 checked {
1165                         ulong l = (ulong)i;
1166                         return (int)l;
1167                 }
1168         }
1169
1170         public static int test_0_regress_cprop_80738 () {
1171                 int hours = Int32.MinValue;
1172                 int hrssec = (hours * 3600);
1173                 long t = ((long)(hrssec) * 1000L);
1174
1175                 return t == 0 ? 0 : 1;
1176         }
1177
1178         public static int test_0_conv_u () {
1179                 unsafe {
1180                         int** dead = (int**) 0xdeadbeaf;
1181                         long i = (long)dead;
1182                         return (i == 0xdeadbeaf) ? 0 : 1;
1183                 }
1184         }
1185
1186         public static int test_0_lconv_to_u2 () {
1187                 unchecked { 
1188                         ulong value = (ulong)(short)-10;
1189                         value = (ushort)value;
1190                     return (value == 65526) ? 0 : 1;
1191                 }
1192         }
1193
1194         public static int test_0_lneg_regress_10320 () {
1195                 long a = 0x100000000;
1196                 ulong c = ((ulong) (-(-a))) >> 32;
1197                 return c == 1 ? 0 : 1;
1198         }
1199 }
1200