2 using System
.Reflection
;
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
29 return TestDriver
.RunTests (typeof (Tests
));
32 public static int test_0_return () {
36 public static int test_100000_return_large () {
40 public static int test_1_load_bool () {
45 public static int test_0_load_bool_false () {
50 public static int test_200_load_byte () {
55 public static int test_100_load_sbyte () {
60 public static int test_200_load_short () {
65 public static int test_100_load_ushort () {
70 public static int test_3_add_simple () {
76 public static int test_3_add_imm () {
81 public static int test_13407573_add_largeimm () {
86 public static int test_1_sub_simple () {
92 public static int test_1_sub_simple_un () {
98 public static int test_1_sub_imm () {
103 public static int test_2_sub_large_imm () {
108 public static int test_0_sub_inv_imm () {
113 public static int test_2_and () {
119 public static int test_0_and_imm () {
124 public static int test_0_and_large_imm () {
126 return b
& 0x10000000;
129 public static int test_0_and_large_imm2 () {
131 return b
& 0x100000f0;
134 public static int test_2_div () {
140 public static int test_4_div_imm () {
145 public static int test_4_divun_imm () {
150 public static int test_0_div_fold () {
155 public static int test_2_div_fold4 () {
160 public static int test_2_div_fold16 () {
165 public static int test_719177_div_destreg () {
167 return ((365* (year
-1)) + ((year
-1)/4));
170 public static int test_1_remun_imm () {
175 public static int test_2_bigremun_imm () {
182 public static int test_2_rem () {
188 public static int test_4_rem_imm () {
193 public static int test_0_rem_imm_0 () {
198 public static int test_0_rem_imm_0_neg () {
203 public static int test_4_rem_big_imm () {
208 public static int test_9_mul () {
214 public static int test_15_mul_imm () {
219 public static int test_24_mul () {
229 public static int test_24_mul_ovf () {
241 public static int test_24_mul_un () {
251 public static int test_24_mul_ovf_un () {
263 public static int test_0_add_ovf1 () {
267 i
= System
.Int32
.MinValue
;
272 if (k
!= System
.Int32
.MinValue
)
277 public static int test_0_add_ovf2 () {
281 i
= System
.Int32
.MaxValue
;
286 if (k
!= System
.Int32
.MaxValue
)
291 public static int test_0_add_ovf3 () {
295 i
= System
.Int32
.MinValue
;
296 j
= System
.Int32
.MaxValue
;
305 public static int test_0_add_ovf4 () {
309 i
= System
.Int32
.MaxValue
;
310 j
= System
.Int32
.MinValue
;
319 public static int test_0_add_ovf5 () {
323 i
= System
.Int32
.MinValue
+ 1234;
328 if (k
!= System
.Int32
.MinValue
)
333 public static int test_0_add_ovf6 () {
337 i
= System
.Int32
.MaxValue
- 1234;
342 if (k
!= System
.Int32
.MaxValue
)
348 public static int test_0_add_un_ovf () {
349 uint n
= (uint)134217728 * 16;
350 uint number
= checked (n
+ (uint)0);
352 return number
== n
? 0 : 1;
355 public static int test_0_sub_ovf1 () {
359 i
= System
.Int32
.MinValue
;
364 if (k
!= System
.Int32
.MinValue
)
370 public static int test_0_sub_ovf2 () {
374 i
= System
.Int32
.MaxValue
;
379 if (k
!= System
.Int32
.MaxValue
)
385 public static int test_0_sub_ovf3 () {
389 i
= System
.Int32
.MinValue
;
390 j
= System
.Int32
.MinValue
+ 1234;
400 public static int test_0_sub_ovf4 () {
404 i
= System
.Int32
.MaxValue
;
409 if (k
!= System
.Int32
.MaxValue
- 1234)
415 public static int test_0_sub_ovf5 () {
419 i
= System
.Int32
.MaxValue
- 1234;
424 if (k
!= System
.Int32
.MaxValue
)
430 public static int test_0_sub_ovf6 () {
434 i
= System
.Int32
.MinValue
+ 1234;
439 if (k
!= System
.Int32
.MinValue
)
445 public static int test_0_sub_ovf_un () {
449 i
= System
.UInt32
.MaxValue
;
454 if (k
!= System
.UInt32
.MaxValue
)
458 i
= System
.UInt32
.MaxValue
;
459 j
= System
.UInt32
.MaxValue
;
469 public static int test_3_or () {
475 public static int test_3_or_un () {
481 public static int test_3_or_short_un () {
487 public static int test_18_or_imm () {
492 public static int test_268435458_or_large_imm () {
494 return b
| 0x10000000;
497 public static int test_268435459_or_large_imm2 () {
499 return b
| 0x10000001;
502 public static int test_1_xor () {
508 public static int test_1_xor_imm () {
513 public static int test_983041_xor_imm_large () {
518 public static int test_1_neg () {
524 public static int test_2_not () {
530 public static int test_16_shift () {
536 public static int test_16_shift_add () {
543 public static int test_16_shift_add2 () {
550 public static int test_16_shift_imm () {
555 public static int test_524288_shift_imm_large () {
560 public static int test_12_shift_imm_inv () {
565 public static int test_12_shift_imm_inv_sbyte () {
570 public static int test_1_rshift_imm () {
575 public static int test_2_unrshift_imm () {
577 return (int)(b
>> 3);
580 public static int test_0_bigunrshift_imm () {
590 public static int test_0_bigrshift_imm () {
598 public static int test_1_rshift () {
604 public static int test_2_unrshift () {
607 return (int)(b
>> a
);
610 public static int test_0_bigunrshift () {
621 public static int test_0_bigrshift () {
630 public static int test_2_cond () {
637 public static int test_2_cond_short () {
638 short b
= 2, a
= 3, c
;
644 public static int test_2_cond_sbyte () {
645 sbyte b
= 2, a
= 3, c
;
651 public static int test_6_cascade_cond () {
665 public static int test_6_cascade_short () {
666 short b
= 2, a
= 3, c
;
679 public static int test_0_short_sign_extend () {
681 short s1
= (short)t1
;
684 if ((uint)t2
!= 0xffffeedd)
690 public static int test_127_iconv_to_i1 () {
697 public static int test_384_iconv_to_i2 () {
704 public static int test_15_for_loop () {
706 for (i
= 0; i
< 15; ++i
) {
711 public static int test_11_nested_for_loop () {
712 int i
, j
= 0; /* mcs bug here if j not set */
713 for (i
= 0; i
< 15; ++i
) {
714 for (j
= 200; j
>= 5; --j
) ;
719 public static int test_11_several_nested_for_loops () {
720 int i
, j
= 0; /* mcs bug here if j not set */
721 for (i
= 0; i
< 15; ++i
) {
722 for (j
= 200; j
>= 5; --j
) ;
725 for (i
= 0; i
< 15; ++i
) {
726 for (j
= 200; j
>= 5; --j
) ;
731 public static int test_0_conv_ovf_i1 () {
734 //for (int j = 0; j < 10000000; j++)
745 public static int test_0_conv_ovf_i1_un () {
756 public static int test_0_conv_ovf_i2 () {
774 public static int test_0_conv_ovf_i2_un () {
785 public static int test_0_conv_ovf_u2 () {
790 UInt16 b
= (UInt16
)c
;
796 public static int test_0_conv_ovf_u2_un () {
801 UInt16 b
= (UInt16
)c
;
807 public static int test_0_conv_ovf_u4 () {
818 public static int test_0_conv_ovf_i4_un () {
829 public static int test_0_bool () {
836 public static int test_1_bool_inverted () {
843 public static int test_1_bool_assign () {
845 val
= !val
; // this should produce a ceq
851 public static int test_1_bool_multi () {
855 if ((val
&& !val2
) && (!val2
&& val
))
860 public static int test_16_spill () {
867 return (1 + (a
+ (b
+ (c
+ (d
+ e
)))));
870 public static int test_1_switch () {
883 public static int test_0_switch_constprop () {
896 public static int test_0_switch_constprop2 () {
909 public static int test_0_while_loop_1 () {
915 } while (value != 0);
920 public static int test_0_while_loop_2 () {
926 } while (value != 0 && position
> 1);
931 public static int test_0_char_conv () {
934 char tc
= (char) ('0' + i
);
942 public static int test_3_shift_regalloc () {
947 orig
&= ~
(0xff << shift
);
948 orig
|= value << shift
;
957 public static int test_2_optimize_branches () {
967 public static int test_0_checked_byte_cast () {
969 int b
= checked ((byte) (v
));
976 public static int test_0_checked_byte_cast_un () {
978 uint b
= checked ((byte) (v
));
985 public static int test_0_checked_short_cast () {
987 int b
= checked ((ushort) (v
));
994 public static int test_0_checked_short_cast_un () {
996 uint b
= checked ((ushort) (v
));
1003 public static int test_1_a_eq_b_plus_a () {
1009 public static int test_0_comp () {
1038 public static int test_0_comp_unsigned () {
1040 uint b
= 0xffffffff;
1097 public static int test_16_cmov ()
1106 public static int test_0_and_cmp ()
1109 int local
= 0x01020304;
1111 if ((local
& 0x01020304) == 0)
1114 if ((local
& 0x00000304) == 0)
1117 if ((local
& 0x00000004) == 0)
1120 if ((local
& 0x00000300) == 0)
1123 if ((local
& 0x00020000) == 0)
1126 if ((local
& 0x01000000) == 0)
1132 public static int test_0_mul_imm_opt ()
1170 if ((i
* 10) != -10)
1176 if ((i
* 12) != -12)
1182 if ((i
* 25) != -25)
1185 if ((i
* 100) != 100)
1188 if ((i
* 100) != -100)
1194 public static int test_0_cne ()
1210 public static int test_0_cmp_regvar_zero ()
1214 if (!(n
> 0 && n
>= 0 && n
!= 0))
1216 if (n
< 0 || n
<= 0 || n
== 0)
1222 public static int test_5_div_un_cfold ()
1227 return (int)(i
/ j
);
1230 public static int test_1_rem_un_cfold ()
1235 return (int)(i
% j
);
1238 public static int test_0_div_opt () {
1241 // Avoid cfolding this
1243 for (int j
= 0; j
< 567; ++j
)
1246 if ((i
/ 2) != 617283)
1248 if ((i
/ 4) != 308641)
1250 if ((i
/ 8) != 154320)
1252 if ((i
/ 16) != 77160)
1255 // Avoid cfolding this
1257 for (int j
= 0; j
< 567; ++j
)
1260 if ((i
/ 2) != -617283)
1262 if ((i
/ 4) != -308641)
1264 if ((i
/ 8) != -154320)
1266 if ((i
/ 16) != -77160)
1272 public static int test_0_rem_opt () {
1275 // Avoid cfolding this
1277 for (int j
= 0; j
< 29; ++j
)
1288 // Avoid cfolding this
1290 for (int j
= 0; j
< 29; ++j
)
1298 if ((i
% 16) != -13)
1304 public static int cmov (int i
) {
1313 public static int cmov2 (int i
) {
1324 public static int test_0_branch_to_cmov_opt () {
1336 public static unsafe int test_0_ishr_sign_extend () {
1337 // Check that ishr does sign extension from bit 31 on 64 bit platforms
1338 uint val
= 0xF0000000u
;
1341 uint ui
= (uint)((int)(*a
) >> 2);
1343 if (ui
!= 0xfc000000)
1346 // Same with non-immediates
1349 ui
= (uint)((int)(*a
) >> amount
);
1351 if (ui
!= 0xfc000000)
1357 public static unsafe int test_0_ishr_sign_extend_cfold () {
1362 return k
== -32768 ? 0 : 1;