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