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
34 public static int Main (string[] args
) {
35 return TestDriver
.RunTests (typeof (Tests
), args
);
39 public static int test_0_return () {
43 public static int test_100000_return_large () {
47 public static int test_1_load_bool () {
52 public static int test_0_load_bool_false () {
57 public static int test_200_load_byte () {
62 public static int test_100_load_sbyte () {
67 public static int test_200_load_short () {
72 public static int test_100_load_ushort () {
77 public static int test_3_add_simple () {
83 public static int test_3_add_imm () {
88 public static int test_13407573_add_largeimm () {
93 public static int test_1_sub_simple () {
99 public static int test_1_sub_simple_un () {
105 public static int test_1_sub_imm () {
110 public static int test_2_sub_large_imm () {
115 public static int test_0_sub_inv_imm () {
120 public static int test_2_and () {
126 public static int test_0_and_imm () {
131 public static int test_0_and_large_imm () {
133 return b
& 0x10000000;
136 public static int test_0_and_large_imm2 () {
138 return b
& 0x100000f0;
141 public static int test_2_div () {
147 public static int test_4_div_imm () {
152 public static int test_4_divun_imm () {
157 public static int test_0_div_fold () {
162 public static int test_2_div_fold4 () {
167 public static int test_2_div_fold16 () {
172 public static int test_719177_div_destreg () {
174 return ((365* (year
-1)) + ((year
-1)/4));
177 public static int test_1_remun_imm () {
182 public static int test_2_bigremun_imm () {
189 public static int test_2_rem () {
195 public static int test_4_rem_imm () {
200 public static int test_0_rem_imm_0 () {
205 public static int test_0_rem_imm_0_neg () {
210 public static int test_4_rem_big_imm () {
215 public static int test_9_mul () {
221 public static int test_15_mul_imm () {
226 public static int test_24_mul () {
236 public static int test_24_mul_ovf () {
248 public static int test_24_mul_un () {
258 public static int test_24_mul_ovf_un () {
270 public static int test_0_add_ovf1 () {
274 i
= System
.Int32
.MinValue
;
279 if (k
!= System
.Int32
.MinValue
)
284 public static int test_0_add_ovf2 () {
288 i
= System
.Int32
.MaxValue
;
293 if (k
!= System
.Int32
.MaxValue
)
298 public static int test_0_add_ovf3 () {
302 i
= System
.Int32
.MinValue
;
303 j
= System
.Int32
.MaxValue
;
312 public static int test_0_add_ovf4 () {
316 i
= System
.Int32
.MaxValue
;
317 j
= System
.Int32
.MinValue
;
326 public static int test_0_add_ovf5 () {
330 i
= System
.Int32
.MinValue
+ 1234;
335 if (k
!= System
.Int32
.MinValue
)
340 public static int test_0_add_ovf6 () {
344 i
= System
.Int32
.MaxValue
- 1234;
349 if (k
!= System
.Int32
.MaxValue
)
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 () {
366 i
= System
.Int32
.MinValue
;
371 if (k
!= System
.Int32
.MinValue
)
377 public static int test_0_sub_ovf2 () {
381 i
= System
.Int32
.MaxValue
;
386 if (k
!= System
.Int32
.MaxValue
)
392 public static int test_0_sub_ovf3 () {
396 i
= System
.Int32
.MinValue
;
397 j
= System
.Int32
.MinValue
+ 1234;
407 public static int test_0_sub_ovf4 () {
411 i
= System
.Int32
.MaxValue
;
416 if (k
!= System
.Int32
.MaxValue
- 1234)
422 public static int test_0_sub_ovf5 () {
426 i
= System
.Int32
.MaxValue
- 1234;
431 if (k
!= System
.Int32
.MaxValue
)
437 public static int test_0_sub_ovf6 () {
441 i
= System
.Int32
.MinValue
+ 1234;
446 if (k
!= System
.Int32
.MinValue
)
452 public static int test_0_sub_ovf_un () {
456 i
= System
.UInt32
.MaxValue
;
461 if (k
!= System
.UInt32
.MaxValue
)
465 i
= System
.UInt32
.MaxValue
;
466 j
= System
.UInt32
.MaxValue
;
476 public static int test_3_or () {
482 public static int test_3_or_un () {
488 public static int test_3_or_short_un () {
494 public static int test_18_or_imm () {
499 public static int test_268435458_or_large_imm () {
501 return b
| 0x10000000;
504 public static int test_268435459_or_large_imm2 () {
506 return b
| 0x10000001;
509 public static int test_1_xor () {
515 public static int test_1_xor_imm () {
520 public static int test_983041_xor_imm_large () {
525 public static int test_1_neg () {
531 public static int test_2_not () {
537 public static int test_16_shift () {
543 public static int test_16_shift_add () {
550 public static int test_16_shift_add2 () {
557 public static int test_16_shift_imm () {
562 public static int test_524288_shift_imm_large () {
567 public static int test_12_shift_imm_inv () {
572 public static int test_12_shift_imm_inv_sbyte () {
577 public static int test_1_rshift_imm () {
582 public static int test_2_unrshift_imm () {
584 return (int)(b
>> 3);
587 public static int test_0_bigunrshift_imm () {
597 public static int test_0_bigrshift_imm () {
605 public static int test_1_rshift () {
611 public static int test_2_unrshift () {
614 return (int)(b
>> a
);
617 public static int test_0_bigunrshift () {
628 public static int test_0_bigrshift () {
637 public static int test_2_cond () {
644 public static int test_2_cond_short () {
645 short b
= 2, a
= 3, c
;
651 public static int test_2_cond_sbyte () {
652 sbyte b
= 2, a
= 3, c
;
658 public static int test_6_cascade_cond () {
672 public static int test_6_cascade_short () {
673 short b
= 2, a
= 3, c
;
686 public static int test_0_short_sign_extend () {
688 short s1
= (short)t1
;
691 if ((uint)t2
!= 0xffffeedd)
697 public static int test_127_iconv_to_i1 () {
704 public static int test_384_iconv_to_i2 () {
711 public static int test_15_for_loop () {
713 for (i
= 0; i
< 15; ++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
) ;
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
) ;
732 for (i
= 0; i
< 15; ++i
) {
733 for (j
= 200; j
>= 5; --j
) ;
738 public static int test_0_conv_ovf_i1 () {
741 //for (int j = 0; j < 10000000; j++)
752 public static int test_0_conv_ovf_i1_un () {
763 public static int test_0_conv_ovf_i2 () {
781 public static int test_0_conv_ovf_i2_un () {
792 public static int test_0_conv_ovf_u2 () {
797 UInt16 b
= (UInt16
)c
;
803 public static int test_0_conv_ovf_u2_un () {
808 UInt16 b
= (UInt16
)c
;
814 public static int test_0_conv_ovf_u4 () {
825 public static int test_0_conv_ovf_i4_un () {
836 public static int test_0_bool () {
843 public static int test_1_bool_inverted () {
850 public static int test_1_bool_assign () {
852 val
= !val
; // this should produce a ceq
858 public static int test_1_bool_multi () {
862 if ((val
&& !val2
) && (!val2
&& val
))
867 public static int test_16_spill () {
874 return (1 + (a
+ (b
+ (c
+ (d
+ e
)))));
877 public static int test_1_switch () {
890 public static int test_0_switch_constprop () {
903 public static int test_0_switch_constprop2 () {
916 public static int test_0_while_loop_1 () {
922 } while (value != 0);
927 public static int test_0_while_loop_2 () {
933 } while (value != 0 && position
> 1);
938 public static int test_0_char_conv () {
941 char tc
= (char) ('0' + i
);
949 public static int test_3_shift_regalloc () {
954 orig
&= ~
(0xff << shift
);
955 orig
|= value << shift
;
964 public static int test_2_optimize_branches () {
974 public static int test_0_checked_byte_cast () {
976 int b
= checked ((byte) (v
));
983 public static int test_0_checked_byte_cast_un () {
985 uint b
= checked ((byte) (v
));
992 public static int test_0_checked_short_cast () {
994 int b
= checked ((ushort) (v
));
1001 public static int test_0_checked_short_cast_un () {
1003 uint b
= checked ((ushort) (v
));
1010 public static int test_1_a_eq_b_plus_a () {
1016 public static int test_0_comp () {
1045 public static int test_0_comp_unsigned () {
1047 uint b
= 0xffffffff;
1104 public static int test_16_cmov ()
1113 public static int test_0_and_cmp ()
1116 int local
= 0x01020304;
1118 if ((local
& 0x01020304) == 0)
1121 if ((local
& 0x00000304) == 0)
1124 if ((local
& 0x00000004) == 0)
1127 if ((local
& 0x00000300) == 0)
1130 if ((local
& 0x00020000) == 0)
1133 if ((local
& 0x01000000) == 0)
1139 public static int test_0_mul_imm_opt ()
1177 if ((i
* 10) != -10)
1183 if ((i
* 12) != -12)
1189 if ((i
* 25) != -25)
1192 if ((i
* 100) != 100)
1195 if ((i
* 100) != -100)
1201 public static int test_0_cne ()
1217 public static int test_0_cmp_regvar_zero ()
1221 if (!(n
> 0 && n
>= 0 && n
!= 0))
1223 if (n
< 0 || n
<= 0 || n
== 0)
1229 public static int test_5_div_un_cfold ()
1234 return (int)(i
/ j
);
1237 public static int test_1_rem_un_cfold ()
1242 return (int)(i
% j
);
1245 public static int test_0_div_opt () {
1248 // Avoid cfolding this
1250 for (int j
= 0; j
< 567; ++j
)
1253 if ((i
/ 2) != 617283)
1255 if ((i
/ 4) != 308641)
1257 if ((i
/ 8) != 154320)
1259 if ((i
/ 16) != 77160)
1262 // Avoid cfolding this
1264 for (int j
= 0; j
< 567; ++j
)
1267 if ((i
/ 2) != -617283)
1269 if ((i
/ 4) != -308641)
1271 if ((i
/ 8) != -154320)
1273 if ((i
/ 16) != -77160)
1279 public static int test_0_udiv_opt () {
1282 // Avoid cfolding this
1284 for (int j
= 0; j
< 567; ++j
)
1287 if ((i
/ 2) != 617283)
1289 if ((i
/ 4) != 308641)
1291 if ((i
/ 8) != 154320)
1293 if ((i
/ 16) != 77160)
1299 public static int test_0_signed_ct_div () {
1301 bool divide_by_zero
= false;
1302 bool overflow
= false;
1304 if ((n
/ 2147483647) != 1)
1306 if ((n
/ -2147483647) != -1)
1309 if ((n
/ 2147483647) != -1)
1312 if ((n
/ -2147483648) != 1)
1314 if ((n
/ 2147483647) != -1)
1321 public static int test_0_unsigned_ct_div () {
1322 uint n
= 4294967295;
1323 bool divide_by_zero
= false;
1325 if ((n
/ 4294967295) != 1)
1328 if ((n
/ 4294967295) != 0)
1331 if ((n
/ 4294967294) != 1)
1339 public static int test_0_rem_opt () {
1342 // Avoid cfolding this
1344 for (int j
= 0; j
< 29; ++j
)
1355 // Avoid cfolding this
1357 for (int j
= 0; j
< 29; ++j
)
1365 if ((i
% 16) != -13)
1371 public static int cmov (int i
) {
1380 public static int cmov2 (int i
) {
1391 public static int test_0_branch_to_cmov_opt () {
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
;
1408 uint ui
= (uint)((int)(*a
) >> 2);
1410 if (ui
!= 0xfc000000)
1413 // Same with non-immediates
1416 ui
= (uint)((int)(*a
) >> amount
);
1418 if (ui
!= 0xfc000000)
1424 public static unsafe int test_0_ishr_sign_extend_cfold () {
1429 return k
== -32768 ? 0 : 1;