[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mono / mini / basic.cs
blob1eaf7ccc63779f51610019899bb810417d60a7f9
1 using System;
2 using System.Reflection;
4 /*
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * static int test_<result>_<name> ();
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.
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)
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.
26 #if __MOBILE__
27 class BasicTests
28 #else
29 class Tests
30 #endif
33 #if !__MOBILE__
34 public static int Main (string[] args) {
35 return TestDriver.RunTests (typeof (Tests), args);
37 #endif
39 public static int test_0_return () {
40 return 0;
43 public static int test_100000_return_large () {
44 return 100000;
47 public static int test_1_load_bool () {
48 bool a = true;
49 return a? 1: 0;
52 public static int test_0_load_bool_false () {
53 bool a = false;
54 return a? 1: 0;
57 public static int test_200_load_byte () {
58 byte a = 200;
59 return a;
62 public static int test_100_load_sbyte () {
63 sbyte a = 100;
64 return a;
67 public static int test_200_load_short () {
68 short a = 200;
69 return a;
72 public static int test_100_load_ushort () {
73 ushort a = 100;
74 return a;
77 public static int test_3_add_simple () {
78 int a = 1;
79 int b = 2;
80 return a + b;
83 public static int test_3_add_imm () {
84 int a = 1;
85 return a + 2;
88 public static int test_13407573_add_largeimm () {
89 int a = 1;
90 return a + 13407572;
93 public static int test_1_sub_simple () {
94 int a = 1;
95 int b = 2;
96 return b - a;
99 public static int test_1_sub_simple_un () {
100 uint a = 1;
101 uint b = 2;
102 return (int)(b - a);
105 public static int test_1_sub_imm () {
106 int b = 2;
107 return b - 1;
110 public static int test_2_sub_large_imm () {
111 int b = 0xff0f0f;
112 return b - 0xff0f0d;
115 public static int test_0_sub_inv_imm () {
116 int b = 2;
117 return 2 - b;
120 public static int test_2_and () {
121 int b = 2;
122 int a = 3;
123 return b & a;
126 public static int test_0_and_imm () {
127 int b = 2;
128 return b & 0x10;
131 public static int test_0_and_large_imm () {
132 int b = 2;
133 return b & 0x10000000;
136 public static int test_0_and_large_imm2 () {
137 int b = 2;
138 return b & 0x100000f0;
141 public static int test_2_div () {
142 int b = 6;
143 int a = 3;
144 return b / a;
147 public static int test_4_div_imm () {
148 int b = 12;
149 return b / 3;
152 public static int test_4_divun_imm () {
153 uint b = 12;
154 return (int)(b / 3);
157 public static int test_0_div_fold () {
158 int b = -1;
159 return b / 2;
162 public static int test_2_div_fold4 () {
163 int b = -8;
164 return -(b / 4);
167 public static int test_2_div_fold16 () {
168 int b = 32;
169 return b / 16;
172 public static int test_719177_div_destreg () {
173 int year = 1970;
174 return ((365* (year-1)) + ((year-1)/4));
177 public static int test_1_remun_imm () {
178 uint b = 13;
179 return (int)(b % 3);
182 public static int test_2_bigremun_imm () {
183 unchecked {
184 uint b = (uint)-2;
185 return (int)(b % 3);
189 public static int test_2_rem () {
190 int b = 5;
191 int a = 3;
192 return b % a;
195 public static int test_4_rem_imm () {
196 int b = 12;
197 return b % 8;
200 public static int test_0_rem_imm_0 () {
201 int b = 12;
202 return b % 1;
205 public static int test_0_rem_imm_0_neg () {
206 int b = -2;
207 return b % 1;
210 public static int test_4_rem_big_imm () {
211 int b = 10004;
212 return b % 10000;
215 public static int test_9_mul () {
216 int b = 3;
217 int a = 3;
218 return b * a;
221 public static int test_15_mul_imm () {
222 int b = 3;
223 return b * 5;
226 public static int test_24_mul () {
227 int a = 3;
228 int b = 8;
229 int res;
231 res = a * b;
233 return res;
236 public static int test_24_mul_ovf () {
237 int a = 3;
238 int b = 8;
239 int res;
241 checked {
242 res = a * b;
245 return res;
248 public static int test_24_mul_un () {
249 uint a = 3;
250 uint b = 8;
251 uint res;
253 res = a * b;
255 return (int)res;
258 public static int test_24_mul_ovf_un () {
259 uint a = 3;
260 uint b = 8;
261 uint res;
263 checked {
264 res = a * b;
267 return (int)res;
270 public static int test_0_add_ovf1 () {
271 int i, j, k;
273 checked {
274 i = System.Int32.MinValue;
275 j = 0;
276 k = i + j;
279 if (k != System.Int32.MinValue)
280 return 1;
281 return 0;
284 public static int test_0_add_ovf2 () {
285 int i, j, k;
287 checked {
288 i = System.Int32.MaxValue;
289 j = 0;
290 k = i + j;
293 if (k != System.Int32.MaxValue)
294 return 2;
295 return 0;
298 public static int test_0_add_ovf3 () {
299 int i, j, k;
301 checked {
302 i = System.Int32.MinValue;
303 j = System.Int32.MaxValue;
304 k = i + j;
307 if (k != -1)
308 return 3;
309 return 0;
312 public static int test_0_add_ovf4 () {
313 int i, j, k;
315 checked {
316 i = System.Int32.MaxValue;
317 j = System.Int32.MinValue;
318 k = i + j;
321 if (k != -1)
322 return 4;
323 return 0;
326 public static int test_0_add_ovf5 () {
327 int i, j, k;
329 checked {
330 i = System.Int32.MinValue + 1234;
331 j = -1234;
332 k = i + j;
335 if (k != System.Int32.MinValue)
336 return 5;
337 return 0;
340 public static int test_0_add_ovf6 () {
341 int i, j, k;
343 checked {
344 i = System.Int32.MaxValue - 1234;
345 j = 1234;
346 k = i + j;
349 if (k != System.Int32.MaxValue)
350 return 6;
352 return 0;
355 public static int test_0_add_un_ovf () {
356 uint n = (uint)134217728 * 16;
357 uint number = checked (n + (uint)0);
359 return number == n ? 0 : 1;
362 public static int test_0_sub_ovf1 () {
363 int i, j, k;
365 checked {
366 i = System.Int32.MinValue;
367 j = 0;
368 k = i - j;
371 if (k != System.Int32.MinValue)
372 return 1;
374 return 0;
377 public static int test_0_sub_ovf2 () {
378 int i, j, k;
380 checked {
381 i = System.Int32.MaxValue;
382 j = 0;
383 k = i - j;
386 if (k != System.Int32.MaxValue)
387 return 2;
389 return 0;
392 public static int test_0_sub_ovf3 () {
393 int i, j, k;
395 checked {
396 i = System.Int32.MinValue;
397 j = System.Int32.MinValue + 1234;
398 k = i - j;
401 if (k != -1234)
402 return 3;
404 return 0;
407 public static int test_0_sub_ovf4 () {
408 int i, j, k;
410 checked {
411 i = System.Int32.MaxValue;
412 j = 1234;
413 k = i - j;
416 if (k != System.Int32.MaxValue - 1234)
417 return 4;
419 return 0;
422 public static int test_0_sub_ovf5 () {
423 int i, j, k;
425 checked {
426 i = System.Int32.MaxValue - 1234;
427 j = -1234;
428 k = i - j;
431 if (k != System.Int32.MaxValue)
432 return 5;
434 return 0;
437 public static int test_0_sub_ovf6 () {
438 int i, j, k;
440 checked {
441 i = System.Int32.MinValue + 1234;
442 j = 1234;
443 k = i - j;
446 if (k != System.Int32.MinValue)
447 return 6;
449 return 0;
452 public static int test_0_sub_ovf_un () {
453 uint i, j, k;
455 checked {
456 i = System.UInt32.MaxValue;
457 j = 0;
458 k = i - j;
461 if (k != System.UInt32.MaxValue)
462 return 1;
464 checked {
465 i = System.UInt32.MaxValue;
466 j = System.UInt32.MaxValue;
467 k = i - j;
470 if (k != 0)
471 return 2;
473 return 0;
476 public static int test_3_or () {
477 int b = 2;
478 int a = 3;
479 return b | a;
482 public static int test_3_or_un () {
483 uint b = 2;
484 uint a = 3;
485 return (int)(b | a);
488 public static int test_3_or_short_un () {
489 ushort b = 2;
490 ushort a = 3;
491 return (int)(b | a);
494 public static int test_18_or_imm () {
495 int b = 2;
496 return b | 0x10;
499 public static int test_268435458_or_large_imm () {
500 int b = 2;
501 return b | 0x10000000;
504 public static int test_268435459_or_large_imm2 () {
505 int b = 2;
506 return b | 0x10000001;
509 public static int test_1_xor () {
510 int b = 2;
511 int a = 3;
512 return b ^ a;
515 public static int test_1_xor_imm () {
516 int b = 2;
517 return b ^ 3;
520 public static int test_983041_xor_imm_large () {
521 int b = 2;
522 return b ^ 0xf0003;
525 public static int test_1_neg () {
526 int b = -2;
527 b++;
528 return -b;
531 public static int test_2_not () {
532 int b = ~2;
533 b = ~b;
534 return b;
537 public static int test_16_shift () {
538 int b = 2;
539 int a = 3;
540 return b << a;
543 public static int test_16_shift_add () {
544 int b = 2;
545 int a = 3;
546 int c = 0;
547 return b << (a + c);
550 public static int test_16_shift_add2 () {
551 int b = 2;
552 int a = 3;
553 int c = 0;
554 return (b + c) << a;
557 public static int test_16_shift_imm () {
558 int b = 2;
559 return b << 3;
562 public static int test_524288_shift_imm_large () {
563 int b = 2;
564 return b << 18;
567 public static int test_12_shift_imm_inv () {
568 int b = 2;
569 return 3 << 2;
572 public static int test_12_shift_imm_inv_sbyte () {
573 sbyte b = 2;
574 return 3 << 2;
577 public static int test_1_rshift_imm () {
578 int b = 8;
579 return b >> 3;
582 public static int test_2_unrshift_imm () {
583 uint b = 16;
584 return (int)(b >> 3);
587 public static int test_0_bigunrshift_imm () {
588 unchecked {
589 uint b = (uint)-1;
590 b = b >> 1;
591 if (b != 0x7fffffff)
592 return 1;
593 return 0;
597 public static int test_0_bigrshift_imm () {
598 int b = -1;
599 b = b >> 1;
600 if (b != -1)
601 return 1;
602 return 0;
605 public static int test_1_rshift () {
606 int b = 8;
607 int a = 3;
608 return b >> a;
611 public static int test_2_unrshift () {
612 uint b = 16;
613 int a = 3;
614 return (int)(b >> a);
617 public static int test_0_bigunrshift () {
618 unchecked {
619 uint b = (uint)-1;
620 int a = 1;
621 b = b >> a;
622 if (b != 0x7fffffff)
623 return 1;
624 return 0;
628 public static int test_0_bigrshift () {
629 int b = -1;
630 int a = 1;
631 b = b >> a;
632 if (b != -1)
633 return 1;
634 return 0;
637 public static int test_2_cond () {
638 int b = 2, a = 3, c;
639 if (a == b)
640 return 0;
641 return 2;
644 public static int test_2_cond_short () {
645 short b = 2, a = 3, c;
646 if (a == b)
647 return 0;
648 return 2;
651 public static int test_2_cond_sbyte () {
652 sbyte b = 2, a = 3, c;
653 if (a == b)
654 return 0;
655 return 2;
658 public static int test_6_cascade_cond () {
659 int b = 2, a = 3, c;
660 if (a == b)
661 return 0;
662 else if (b > a)
663 return 1;
664 else if (b != b)
665 return 2;
666 else {
667 c = 1;
669 return a + b + c;
672 public static int test_6_cascade_short () {
673 short b = 2, a = 3, c;
674 if (a == b)
675 return 0;
676 else if (b > a)
677 return 1;
678 else if (b != b)
679 return 2;
680 else {
681 c = 1;
683 return a + b + c;
686 public static int test_0_short_sign_extend () {
687 int t1 = 0xffeedd;
688 short s1 = (short)t1;
689 int t2 = s1;
691 if ((uint)t2 != 0xffffeedd)
692 return 1;
693 else
694 return 0;
697 public static int test_127_iconv_to_i1 () {
698 int i = 0x100017f;
699 sbyte s = (sbyte)i;
701 return s;
704 public static int test_384_iconv_to_i2 () {
705 int i = 0x1000180;
706 short s = (short)i;
708 return s;
711 public static int test_15_for_loop () {
712 int i;
713 for (i = 0; i < 15; ++i) {
715 return i;
718 public static int test_11_nested_for_loop () {
719 int i, j = 0; /* mcs bug here if j not set */
720 for (i = 0; i < 15; ++i) {
721 for (j = 200; j >= 5; --j) ;
723 return i - j;
726 public static int test_11_several_nested_for_loops () {
727 int i, j = 0; /* mcs bug here if j not set */
728 for (i = 0; i < 15; ++i) {
729 for (j = 200; j >= 5; --j) ;
731 i = j = 0;
732 for (i = 0; i < 15; ++i) {
733 for (j = 200; j >= 5; --j) ;
735 return i - j;
738 public static int test_0_conv_ovf_i1 () {
739 int c;
741 //for (int j = 0; j < 10000000; j++)
742 checked {
743 c = 127;
744 sbyte b = (sbyte)c;
745 c = -128;
746 b = (sbyte)c;
749 return 0;
752 public static int test_0_conv_ovf_i1_un () {
753 uint c;
755 checked {
756 c = 127;
757 sbyte b = (sbyte)c;
760 return 0;
763 public static int test_0_conv_ovf_i2 () {
764 int c;
766 checked {
767 c = 32767;
768 Int16 b = (Int16)c;
769 c = -32768;
770 b = (Int16)c;
771 unchecked {
772 uint u = 0xfffffffd;
773 c = (int)u;
775 b = (Int16)c;
778 return 0;
781 public static int test_0_conv_ovf_i2_un () {
782 uint c;
784 checked {
785 c = 32767;
786 Int16 b = (Int16)c;
789 return 0;
792 public static int test_0_conv_ovf_u2 () {
793 int c;
795 checked {
796 c = 65535;
797 UInt16 b = (UInt16)c;
800 return 0;
803 public static int test_0_conv_ovf_u2_un () {
804 uint c;
806 checked {
807 c = 65535;
808 UInt16 b = (UInt16)c;
811 return 0;
814 public static int test_0_conv_ovf_u4 () {
815 int c;
817 checked {
818 c = 0x7fffffff;
819 uint b = (uint)c;
822 return 0;
825 public static int test_0_conv_ovf_i4_un () {
826 uint c;
828 checked {
829 c = 0x7fffffff;
830 int b = (int)c;
833 return 0;
836 public static int test_0_bool () {
837 bool val = true;
838 if (val)
839 return 0;
840 return 1;
843 public static int test_1_bool_inverted () {
844 bool val = true;
845 if (!val)
846 return 0;
847 return 1;
850 public static int test_1_bool_assign () {
851 bool val = true;
852 val = !val; // this should produce a ceq
853 if (val)
854 return 0;
855 return 1;
858 public static int test_1_bool_multi () {
859 bool val = true;
860 bool val2 = true;
861 val = !val;
862 if ((val && !val2) && (!val2 && val))
863 return 0;
864 return 1;
867 public static int test_16_spill () {
868 int a = 1;
869 int b = 2;
870 int c = 3;
871 int d = 4;
872 int e = 5;
874 return (1 + (a + (b + (c + (d + e)))));
877 public static int test_1_switch () {
878 int n = 0;
880 switch (n) {
881 case 0: return 1;
882 case 1: return 2;
883 case -1: return 3;
884 default:
885 return 4;
887 return 1;
890 public static int test_0_switch_constprop () {
891 int n = -1;
893 switch (n) {
894 case 0: return 2;
895 case 1: return 3;
896 case 2: return 3;
897 default:
898 return 0;
900 return 3;
903 public static int test_0_switch_constprop2 () {
904 int n = 3;
906 switch (n) {
907 case 0: return 2;
908 case 1: return 3;
909 case 2: return 3;
910 default:
911 return 0;
913 return 3;
916 public static int test_0_while_loop_1 () {
918 int value = 255;
920 do {
921 value = value >> 4;
922 } while (value != 0);
924 return 0;
927 public static int test_0_while_loop_2 () {
928 int value = 255;
929 int position = 5;
931 do {
932 value = value >> 4;
933 } while (value != 0 && position > 1);
935 return 0;
938 public static int test_0_char_conv () {
939 int i = 1;
941 char tc = (char) ('0' + i);
943 if (tc != '1')
944 return 1;
946 return 0;
949 public static int test_3_shift_regalloc () {
950 int shift = 8;
951 int orig = 1;
952 byte value = 0xfe;
954 orig &= ~(0xff << shift);
955 orig |= value << shift;
957 if (orig == 0xfe01)
958 return 3;
959 return 0;
962 enum E {A, B};
964 public static int test_2_optimize_branches () {
965 switch (E.A) {
966 case E.A:
967 if (E.A == E.B) {
969 break;
971 return 2;
974 public static int test_0_checked_byte_cast () {
975 int v = 250;
976 int b = checked ((byte) (v));
978 if (b != 250)
979 return 1;
980 return 0;
983 public static int test_0_checked_byte_cast_un () {
984 uint v = 250;
985 uint b = checked ((byte) (v));
987 if (b != 250)
988 return 1;
989 return 0;
992 public static int test_0_checked_short_cast () {
993 int v = 250;
994 int b = checked ((ushort) (v));
996 if (b != 250)
997 return 1;
998 return 0;
1001 public static int test_0_checked_short_cast_un () {
1002 uint v = 250;
1003 uint b = checked ((ushort) (v));
1005 if (b != 250)
1006 return 1;
1007 return 0;
1010 public static int test_1_a_eq_b_plus_a () {
1011 int a = 0, b = 1;
1012 a = b + a;
1013 return a;
1016 public static int test_0_comp () {
1017 int a = 0;
1018 int b = -1;
1019 int error = 1;
1020 bool val;
1022 val = a < b;
1023 if (val)
1024 return error;
1025 error++;
1027 val = a > b;
1028 if (!val)
1029 return error;
1030 error ++;
1032 val = a == b;
1033 if (val)
1034 return error;
1035 error ++;
1037 val = a == a;
1038 if (!val)
1039 return error;
1040 error ++;
1042 return 0;
1045 public static int test_0_comp_unsigned () {
1046 uint a = 1;
1047 uint b = 0xffffffff;
1048 int error = 1;
1049 bool val;
1051 val = a < b;
1052 if (!val)
1053 return error;
1054 error++;
1056 val = a <= b;
1057 if (!val)
1058 return error;
1059 error++;
1061 val = a == b;
1062 if (val)
1063 return error;
1064 error++;
1066 val = a >= b;
1067 if (val)
1068 return error;
1069 error++;
1071 val = a > b;
1072 if (val)
1073 return error;
1074 error++;
1076 val = b < a;
1077 if (val)
1078 return error;
1079 error++;
1081 val = b <= a;
1082 if (val)
1083 return error;
1084 error++;
1086 val = b == a;
1087 if (val)
1088 return error;
1089 error++;
1091 val = b > a;
1092 if (!val)
1093 return error;
1094 error++;
1096 val = b >= a;
1097 if (!val)
1098 return error;
1099 error++;
1101 return 0;
1104 public static int test_16_cmov ()
1106 int n = 0;
1107 if (n == 0)
1108 n = 16;
1110 return n;
1113 public static int test_0_and_cmp ()
1115 /* test esi, imm */
1116 int local = 0x01020304;
1118 if ((local & 0x01020304) == 0)
1119 return 7;
1121 if ((local & 0x00000304) == 0)
1122 return 8;
1124 if ((local & 0x00000004) == 0)
1125 return 9;
1127 if ((local & 0x00000300) == 0)
1128 return 10;
1130 if ((local & 0x00020000) == 0)
1131 return 11;
1133 if ((local & 0x01000000) == 0)
1134 return 12;
1136 return 0;
1139 public static int test_0_mul_imm_opt ()
1141 int i;
1143 i = 1;
1144 if ((i * 2) != 2)
1145 return 1;
1146 i = -1;
1147 if ((i * 2) != -2)
1148 return 2;
1149 i = 1;
1150 if ((i * 3) != 3)
1151 return 3;
1152 i = -1;
1153 if ((i * 3) != -3)
1154 return 4;
1155 i = 1;
1156 if ((i * 5) != 5)
1157 return 5;
1158 i = -1;
1159 if ((i * 5) != -5)
1160 return 6;
1161 i = 1;
1162 if ((i * 6) != 6)
1163 return 7;
1164 i = -1;
1165 if ((i * 6) != -6)
1166 return 8;
1167 i = 1;
1168 if ((i * 9) != 9)
1169 return 9;
1170 i = -1;
1171 if ((i * 9) != -9)
1172 return 10;
1173 i = 1;
1174 if ((i * 10) != 10)
1175 return 11;
1176 i = -1;
1177 if ((i * 10) != -10)
1178 return 12;
1179 i = 1;
1180 if ((i * 12) != 12)
1181 return 13;
1182 i = -1;
1183 if ((i * 12) != -12)
1184 return 14;
1185 i = 1;
1186 if ((i * 25) != 25)
1187 return 15;
1188 i = -1;
1189 if ((i * 25) != -25)
1190 return 16;
1191 i = 1;
1192 if ((i * 100) != 100)
1193 return 17;
1194 i = -1;
1195 if ((i * 100) != -100)
1196 return 18;
1198 return 0;
1201 public static int test_0_cne ()
1203 int x = 0;
1204 int y = 1;
1206 bool b = x != y;
1207 bool bb = x != x;
1209 if (!b)
1210 return 1;
1211 if (bb)
1212 return 2;
1214 return 0;
1217 public static int test_0_cmp_regvar_zero ()
1219 int n = 10;
1221 if (!(n > 0 && n >= 0 && n != 0))
1222 return 1;
1223 if (n < 0 || n <= 0 || n == 0)
1224 return 1;
1226 return 0;
1229 public static int test_5_div_un_cfold ()
1231 uint i = 10;
1232 uint j = 2;
1234 return (int)(i / j);
1237 public static int test_1_rem_un_cfold ()
1239 uint i = 11;
1240 uint j = 2;
1242 return (int)(i % j);
1245 public static int test_0_div_opt () {
1246 int i;
1248 // Avoid cfolding this
1249 i = 0;
1250 for (int j = 0; j < 567; ++j)
1251 i ++;
1252 i += 1234000;
1253 if ((i / 2) != 617283)
1254 return 1;
1255 if ((i / 4) != 308641)
1256 return 2;
1257 if ((i / 8) != 154320)
1258 return 3;
1259 if ((i / 16) != 77160)
1260 return 4;
1262 // Avoid cfolding this
1263 i = 0;
1264 for (int j = 0; j < 567; ++j)
1265 i --;
1266 i -= 1234000;
1267 if ((i / 2) != -617283)
1268 return 5;
1269 if ((i / 4) != -308641)
1270 return 6;
1271 if ((i / 8) != -154320)
1272 return 7;
1273 if ((i / 16) != -77160)
1274 return 8;
1276 return 0;
1279 public static int test_0_udiv_opt () {
1280 uint i;
1282 // Avoid cfolding this
1283 i = 0;
1284 for (int j = 0; j < 567; ++j)
1285 i ++;
1286 i += 1234000;
1287 if ((i / 2) != 617283)
1288 return 1;
1289 if ((i / 4) != 308641)
1290 return 2;
1291 if ((i / 8) != 154320)
1292 return 3;
1293 if ((i / 16) != 77160)
1294 return 4;
1296 return 0;
1299 public static int test_0_signed_ct_div () {
1300 int n = 2147483647;
1301 bool divide_by_zero = false;
1302 bool overflow = false;
1304 if ((n / 2147483647) != 1)
1305 return 1;
1306 if ((n / -2147483647) != -1)
1307 return 2;
1308 n = -n;
1309 if ((n / 2147483647) != -1)
1310 return 3;
1311 n--; /* MinValue */
1312 if ((n / -2147483648) != 1)
1313 return 4;
1314 if ((n / 2147483647) != -1)
1315 return 5;
1316 if ((n / 1) != n)
1317 return 6;
1318 return 0;
1321 public static int test_0_unsigned_ct_div () {
1322 uint n = 4294967295;
1323 bool divide_by_zero = false;
1325 if ((n / 4294967295) != 1)
1326 return 1;
1327 n--;
1328 if ((n / 4294967295) != 0)
1329 return 2;
1330 n++;
1331 if ((n / 4294967294) != 1)
1332 return 3;
1333 if ((n / 1) != n)
1334 return 4;
1336 return 0;
1339 public static int test_0_rem_opt () {
1340 int i;
1342 // Avoid cfolding this
1343 i = 0;
1344 for (int j = 0; j < 29; ++j)
1345 i ++;
1346 if ((i % 2) != 1)
1347 return 1;
1348 if ((i % 4) != 1)
1349 return 2;
1350 if ((i % 8) != 5)
1351 return 3;
1352 if ((i % 16) != 13)
1353 return 4;
1355 // Avoid cfolding this
1356 i = 0;
1357 for (int j = 0; j < 29; ++j)
1358 i --;
1359 if ((i % 2) != -1)
1360 return 5;
1361 if ((i % 4) != -1)
1362 return 6;
1363 if ((i % 8) != -5)
1364 return 7;
1365 if ((i % 16) != -13)
1366 return 8;
1368 return 0;
1371 public static int cmov (int i) {
1372 int j = 0;
1374 if (i > 0)
1375 j = 1;
1377 return j;
1380 public static int cmov2 (int i) {
1381 int j = 0;
1383 if (i <= 0)
1385 else
1386 j = 1;
1388 return j;
1391 public static int test_0_branch_to_cmov_opt () {
1392 if (cmov (0) != 0)
1393 return 1;
1394 if (cmov (1) != 1)
1395 return 2;
1396 if (cmov2 (0) != 0)
1397 return 1;
1398 if (cmov2 (1) != 1)
1399 return 2;
1400 return 0;
1403 public static unsafe int test_0_ishr_sign_extend () {
1404 // Check that ishr does sign extension from bit 31 on 64 bit platforms
1405 uint val = 0xF0000000u;
1407 uint *a = &val;
1408 uint ui = (uint)((int)(*a) >> 2);
1410 if (ui != 0xfc000000)
1411 return 1;
1413 // Same with non-immediates
1414 int amount = 2;
1416 ui = (uint)((int)(*a) >> amount);
1418 if (ui != 0xfc000000)
1419 return 2;
1421 return 0;
1424 public static unsafe int test_0_ishr_sign_extend_cfold () {
1425 int i = 32768;
1426 int j = i << 16;
1427 int k = j >> 16;
1429 return k == -32768 ? 0 : 1;