2 using System
.Reflection
;
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * public 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_10_simple_cast () {
44 public static int test_1_bigmul1 () {
50 c
= (long)a
* (long)b
;
56 public static int test_1_bigmul2 () {
57 int a
= System
.Int32
.MaxValue
, b
= System
.Int32
.MaxValue
;
58 long s
= System
.Int64
.MinValue
;
60 c
= s
+ (long) a
* (long) b
;
61 if (c
== -4611686022722355199)
66 public static int test_1_bigmul3 () {
69 c
= (ulong) a
* (ulong) b
;
75 public static int test_1_bigmul4 () {
76 int a
= System
.Int32
.MaxValue
, b
= System
.Int32
.MaxValue
;
78 c
= (ulong) a
* (ulong) b
;
79 if (c
== 4611686014132420609)
84 public static int test_1_bigmul5 () {
85 int a
= System
.Int32
.MaxValue
, b
= System
.Int32
.MinValue
;
87 c
= (long) a
* (long) b
;
88 if (c
== -4611686016279904256)
93 public static int test_1_bigmul6 () {
94 uint a
= System
.UInt32
.MaxValue
, b
= System
.UInt32
.MaxValue
/(uint)2;
96 c
= (ulong) a
* (ulong) b
;
97 if (c
== 9223372030412324865)
102 public static int test_0_beq () {
103 long a
= 0xffffffffff;
104 if (a
!= 0xffffffffff)
109 public static int test_0_bne_un () {
110 long a
= 0xffffffffff;
111 if (a
== 0xfffffffffe)
113 if (a
== 0xfeffffffff)
118 public static int test_0_ble () {
119 long a
= 0xffffffffff;
120 if (a
> 0xffffffffff)
123 if (a
> 0x1ffffffffff)
126 if (a
> 0xff00000000) {} else
129 if (a
> 0xfeffffffff) {} else
133 if (a
> 0xffffffffff)
139 public static int test_0_ble_un () {
140 ulong a
= 0xffffffffff;
141 if (a
> 0xffffffffff)
144 if (a
> 0x1ffffffffff)
147 if (a
> 0xff00000000) {} else
150 if (a
> 0xfeffffffff) {} else
154 if (a
> 0xffffffffff)
160 public static int test_0_bge () {
161 long a
= 0xffffffffff;
162 if (a
< 0xffffffffff)
165 if (a
< 0x1ffffffffff) {} else
168 if (a
< 0xff00000000)
171 if (a
< 0xfeffffffff)
175 if (a
< 0xffffffffff) {} else
181 public static int test_0_bge_un () {
182 ulong a
= 0xffffffffff;
183 if (a
< 0xffffffffff)
186 if (a
< 0x1ffffffffff) {} else
189 if (a
< 0xff00000000)
192 if (a
< 0xfeffffffff)
196 if (a
< 0xffffffffff) {} else
202 public static int test_0_blt () {
203 long a
= 0xfffffffffe;
204 if (a
>= 0xffffffffff)
207 if (a
>= 0x1fffffffffe)
210 if (a
>= 0xff00000000) {} else
213 if (a
>= 0xfefffffffe) {} else
217 if (a
>= 0xffffffffff)
223 public static int test_0_blt_un () {
224 ulong a
= 0xfffffffffe;
225 if (a
>= 0xffffffffff)
228 if (a
>= 0x1fffffffffe)
231 if (a
>= 0xff00000000) {} else
234 if (a
>= 0xfefffffffe) {} else
238 if (a
>= 0xffffffffff)
244 public static int test_0_bgt () {
245 long a
= 0xffffffffff;
246 if (a
<= 0xfffffffffe)
249 if (a
<= 0x1ffffffffff) {} else
252 if (a
<= 0xff00000000)
255 if (a
<= 0xfeffffffff)
259 if (a
<= 0xffffffffff) {} else
265 public static int test_0_bgt_un () {
266 ulong a
= 0xffffffffff;
267 if (a
<= 0xfffffffffe)
270 if (a
<= 0x1ffffffffff) {} else
273 if (a
<= 0xff00000000)
276 if (a
<= 0xfeffffffff)
280 if (a
<= 0xffffffffff) {} else
286 public static int test_0_conv_to_i4 () {
292 public static int test_32_conv_to_u4 () {
298 public static int test_15_conv_to_u4_2 () {
299 long a
= 0x10000000f;
304 public static int test_0_conv_from_i4 () {
316 public static int test_0_conv_from_i4_negative () {
329 public static int test_0_conv_from_r8 () {
338 public static int test_0_conv_from_r4 () {
348 public static int test_8_and () {
349 long a
= 0xffffffffff;
354 public static int test_8_and_imm () {
355 long a
= 0xffffffffff;
359 public static int get_high_bit (ulong a
) {
360 if ((a
& 0x8000000000000000) != 0)
365 public static int test_1_and () {
366 ulong a
= 0xabcd1234deadbeef;
367 return get_high_bit (a
);
370 public static int test_10_or () {
376 public static int test_10_or_imm () {
381 public static int test_5_xor () {
387 public static int test_5_xor_imm () {
392 public static int test_5_add () {
398 public static int test_5_add_imm () {
403 public static int test_0_add_imm_carry () {
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;
413 if (c
== ((a
+ 1) + 1))
418 public static int test_4_addcc_imm () {
421 return (int)(a
- b
+ 1);
424 public static int test_5_sub () {
430 public static int test_5_sub_imm () {
435 public static int test_0_sub_imm_carry () {
437 return (int)((a
- 1) + 1);
440 public static int test_0_add_ovf () {
444 i
= System
.Int64
.MinValue
;
449 if (k
!= System
.Int64
.MinValue
)
453 i
= System
.Int64
.MaxValue
;
458 if (k
!= System
.Int64
.MaxValue
)
462 i
= System
.Int64
.MinValue
;
463 j
= System
.Int64
.MaxValue
;
471 i
= System
.Int64
.MaxValue
;
472 j
= System
.Int64
.MinValue
;
480 i
= System
.Int64
.MinValue
+ 1234;
485 if (k
!= System
.Int64
.MinValue
)
489 i
= System
.Int64
.MaxValue
- 1234;
494 if (k
!= System
.Int64
.MaxValue
)
500 public static int test_0_add_un_ovf () {
501 ulong n
= (ulong)134217728 * 16;
502 ulong number
= checked (n
+ (uint)0);
504 return number
== n
? 0 : 1;
507 public static int test_0_sub_ovf () {
511 i
= System
.Int64
.MinValue
;
516 if (k
!= System
.Int64
.MinValue
)
520 i
= System
.Int64
.MaxValue
;
525 if (k
!= System
.Int64
.MaxValue
)
529 i
= System
.Int64
.MinValue
;
530 j
= System
.Int64
.MinValue
+ 1234;
538 i
= System
.Int64
.MaxValue
;
543 if (k
!= System
.Int64
.MaxValue
- 1234)
547 i
= System
.Int64
.MaxValue
- 1234;
552 if (k
!= System
.Int64
.MaxValue
)
556 i
= System
.Int64
.MinValue
+ 1234;
561 if (k
!= System
.Int64
.MinValue
)
567 public static int test_0_sub_ovf_un () {
571 i
= System
.UInt64
.MaxValue
;
576 if (k
!= System
.UInt64
.MaxValue
)
580 i
= System
.UInt64
.MaxValue
;
581 j
= System
.UInt64
.MaxValue
;
591 public static int test_2_neg () {
596 public static int test_0_neg_large () {
597 long min
= -9223372036854775808;
599 ulong ul
= (ulong)min
;
600 return (min
== -(long)ul
) ? 0 : 1;
604 public static int test_5_shift ()
634 public static int test_1_shift_u ()
639 // The JIT optimizes this
648 public static int test_1_shift_u_32 ()
654 // Avoid constant folding
655 for (int i
= 0; i
< 32; ++i
)
658 if ((a
>> count
) != 0xFFFFFFFFUL
)
664 public static int test_1_simple_neg () {
672 public static int test_2_compare () {
681 public static int test_9_alu ()
726 public static int test_24_mul () {
732 public static int test_24_mul_ovf () {
743 public static int test_24_mul_un () {
749 public static int test_24_mul_ovf_un () {
760 public static int test_0_mul_imm () {
771 if ((i
* 1234) != 4936)
779 if ((i
* -1234) != -4936)
785 public static int test_0_mul_imm_opt ()
838 if ((i
* 100) != 100)
841 if ((i
* 100) != -100)
847 public static int test_4_divun () {
853 public static int test_1431655764_bigdivun_imm () {
860 public static int test_1431655764_bigdivun () {
868 public static int test_1_remun () {
874 public static int test_2_bigremun () {
882 public static int test_0_ceq () {
886 long d
= 0xff00000002;
888 bool val
= (a
== b
); // this should produce a ceq
892 val
= (a
== c
); // this should produce a ceq
896 val
= (a
== d
); // this should produce a ceq
903 public static int test_0_ceq_complex () {
912 public static int test_0_clt () {
916 long d
= 0xff00000002L
;
919 bool val
= (a
< b
); // this should produce a clt
923 val
= (a
< c
); // this should produce a clt
927 val
= (c
< a
); // this should produce a clt
931 val
= (e
< d
); // this should produce a clt
935 val
= (d
< e
); // this should produce a clt
942 public static int test_0_clt_un () {
946 ulong d
= 0xff00000002;
947 ulong e
= 0xffffffffffffffff;
949 bool val
= (a
< b
); // this should produce a clt_un
953 val
= (a
< c
); // this should produce a clt_un
957 val
= (d
< e
); // this should produce a clt_un
961 val
= (e
< d
); // this should produce a clt_un
968 public static int test_0_cgt () {
972 long d
= 0xff00000002L
;
975 bool val
= (a
> b
); // this should produce a cgt
979 val
= (a
> c
); // this should produce a cgt
983 val
= (c
> a
); // this should produce a cgt
987 val
= (e
> d
); // this should produce a cgt
991 val
= (d
> e
); // this should produce a cgt
998 public static int test_0_cgt_un () {
1002 ulong d
= 0xff00000002;
1003 ulong e
= 0xffffffffffffffff;
1005 bool val
= (a
> b
); // this should produce a cgt_un
1009 val
= (a
> c
); // this should produce a cgt_un
1013 val
= (d
> e
); // this should produce a cgt_un
1017 val
= (e
> d
); // this should produce a cgt_un
1024 public static int test_3_byte_cast () {
1025 ulong val
= 0xff00ff00f0f0f0f0;
1027 b
= (byte) (val
& 0xFF);
1034 public static int test_4_ushort_cast () {
1035 ulong val
= 0xff00ff00f0f0f0f0;
1037 b
= (ushort) (val
& 0xFFFF);
1043 public static int test_500_mul_div () {
1047 long res
= val
* exp
/ maxexp
;
1052 public static int test_3_checked_cast_un () {
1056 checked { j = (long)i; }
1063 public static int test_4_checked_cast () {
1067 checked { j = (ulong)i; }
1074 public static int test_12_checked_i1_cast () {
1082 public static int test_127_checked_i1_cast_un () {
1090 public static int test_1234_checked_i2_cast () {
1098 public static int test_32767_checked_i2_cast_un () {
1106 public static int test_1234_checked_i4_cast () {
1114 public static int test_10_int_uint_compare () {
1117 for (int i
= 0; i
< size
; ++i
) {
1123 public static int test_0_ulong_regress () {
1124 ulong u
= 4257145737;
1126 return (u
== 4257145736) ? 0 : 1;
1129 public static int test_0_ulong_regress2 () {
1131 ulong sum_p
= 2897079476 + (ulong) (1 << p2
);
1132 return (sum_p
== 749595828) ? 0 : 1;
1135 public static int test_0_assemble_long ()
1138 ulong x
= 0x12345678;
1142 ulong z
= ((x
- y
) << 32) | a
;
1144 if (z
!= 0x1234567700000005)
1150 public static int test_0_hash ()
1152 ulong x
= 0x1234567887654321;
1153 int h
= (int)(x
& 0xffffffff) ^
(int)(x
>> 32);
1154 if (h
!= unchecked ((int)(0x87654321 ^
0x12345678)))
1160 public static int test_0_shift_regress () {
1165 return ((a
>> (b
- c
)) == 0) ? 0 : 1;
1168 public static int test_1234_conv_ovf_u8 () {
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);
1182 return t
== 0 ? 0 : 1;
1185 public static int test_0_conv_u () {
1187 int** dead
= (int**) 0xdeadbeaf;
1188 long i
= (long)dead
;
1189 return (i
== 0xdeadbeaf) ? 0 : 1;
1193 public static int test_0_lconv_to_u2 () {
1195 ulong value = (ulong)(short)-10;
1196 value = (ushort)value;
1197 return (value == 65526) ? 0 : 1;
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;
1207 public static int test_6_lrem_un () {
1208 ulong r2
= 4294967296;
1215 public static int test_0_lrem_imm_1 () {
1217 return (int)(b
% 1L);
1220 public static int test_0_lrem_imm_1_neg () {
1222 return (int)(b
% 1L);
1225 public static int test_0_lrem_imm_2 ()
1227 long x
= 245345634L;
1228 return (int)(x
% 2L);
1231 public static int test_1_lrem_imm_2 ()
1233 long x
= 24534553245L;
1234 return (int)(x
% 2L);
1237 public static int test_1_lrem_imm_2_neg ()
1239 long x
= -24534553245L;
1240 return -(int)(x
% 2L);
1243 public static int test_13_lrem_imm_32 ()
1246 return (int)(x
% 32L);
1249 public static int test_27_lrem_imm_32_neg ()
1252 return -(int)(x
% 32L);
1255 public static int test_5_lrem_imm_large ()
1257 long x
= 0x1000000005L
;
1258 return (int)(x
% 0x40000000L
);
1261 public static int test_5_lrem_imm_too_large ()
1263 long x
= 0x1000000005L
;
1264 return (int)(x
% 0x80000000L
);