2 using System.Runtime.CompilerServices;
6 * Regression tests for the mono JIT.
8 * Each test needs to be of the form:
10 * static int test_<result>_<name> ();
12 * where <result> is an integer (the value that needs to be returned by
13 * the method to make it pass.
14 * <name> is a user-displayed name used to identify the test.
16 * The tests can be driven in two ways:
17 * *) running the program directly: Main() uses reflection to find and invoke
18 * the test methods (this is useful mostly to check that the tests are correct)
19 * *) with the --regression switch of the jit (this is the preferred way since
20 * all the tests will be run with optimizations on and off)
22 * The reflection logic could be moved to a .dll since we need at least another
23 * regression test file written in IL code to have better control on how
28 namespace UnalignedTests
36 public static int Main (string[] args) {
37 return TestDriver.RunTests (typeof (Tests), args);
42 public static unsafe int test_0_ldobj_r4 ()
44 byte *ptr = stackalloc byte [32];
45 float f = (float)123.44f;
46 *(float*)ptr = (float)f;
48 int expected = *(int*)ptr;
50 Intrinsics.UnalignedStobj<int> (ptr + 1, expected);
51 if (Intrinsics.UnalignedLdobj<float> (ptr + 1) != f)
57 public static unsafe int test_0_ldobj_r8 ()
59 byte *ptr = stackalloc byte [32];
61 *(double*)ptr = (double)f;
63 long expected = *(long*)ptr;
65 Intrinsics.UnalignedStobj<long> (ptr + 3, expected);
66 if (Intrinsics.UnalignedLdobj<double> (ptr + 3) != f)
72 public static unsafe int test_0_ldobj ()
74 byte *ptr = stackalloc byte [20];
75 for (int i = 0; i < 20; ++i)
79 if (Intrinsics.UnalignedLdobj<short> (ptr + 0) != 0x0100)
82 if (Intrinsics.UnalignedLdobj<short> (ptr + 1) != 0x0201)
85 if (Intrinsics.UnalignedLdobj<short> (ptr + 2) != 0x0302)
88 if (Intrinsics.UnalignedLdobj<int> (ptr + 1) != 0x04030201)
91 if (Intrinsics.UnalignedLdobj<int> (ptr + 2) != 0x05040302)
94 if (Intrinsics.UnalignedLdobj<long> (ptr + 1) != 0x0807060504030201)
97 if (Intrinsics.UnalignedLdobj<long> (ptr + 6) != 0xD0C0B0A09080706)
103 public static unsafe int test_0_ldind ()
105 byte *ptr = stackalloc byte [20];
106 for (int i = 0; i < 20; ++i)
110 if (Intrinsics.UnalignedLdInd2 (ptr + 0) != 0x0100)
113 if (Intrinsics.UnalignedLdInd2 (ptr + 1) != 0x0201)
116 if (Intrinsics.UnalignedLdInd2 (ptr + 2) != 0x0302)
119 if (Intrinsics.UnalignedLdInd4 (ptr + 1) != 0x04030201)
122 if (Intrinsics.UnalignedLdInd4 (ptr + 2) != 0x05040302)
125 if (Intrinsics.UnalignedLdInd8 (ptr + 1) != 0x0807060504030201)
128 if (Intrinsics.UnalignedLdInd8 (ptr + 6) != 0xD0C0B0A09080706)
133 public static unsafe int test_0_cpobj ()
135 byte *dest = stackalloc byte [20];
136 byte *src = stackalloc byte [20];
137 for (int i = 0; i < 20; ++i)
140 Intrinsics.UnalignedCpobj<short> (dest + 0, src + 0);
141 if (dest [0] != src [0] || dest [1] != src [1])
144 Intrinsics.UnalignedCpobj<short> (dest + 1, src + 0);
145 if (dest [1] != src [0] || dest [2] != src [1])
148 Intrinsics.UnalignedCpobj<short> (dest + 0, src + 1);
149 if (dest [0] != src [1] || dest [1] != src [2])
152 Intrinsics.UnalignedCpobj<short> (dest + 1, src + 1);
153 if (dest [1] != src [1] || dest [2] != src [2])
156 Intrinsics.UnalignedCpobj<int> (dest + 3, src);
157 for (int i = 0; i < 4; ++i) {
158 if (dest [i + 3] != src [i])
162 Intrinsics.UnalignedCpobj<int> (dest + 1, src + 2);
163 for (int i = 0; i < 4; ++i) {
164 if (dest [i + 1] != src [i + 2])
168 Intrinsics.UnalignedCpobj<long> (dest + 1, src + 2);
169 for (int i = 0; i < 8; ++i) {
170 if (dest [i + 1] != src [i + 2])
174 Intrinsics.UnalignedCpobj<long> (dest + 7, src + 2);
175 for (int i = 0; i < 8; ++i) {
176 if (dest [i + 7] != src [i + 2])
183 public static unsafe int test_0_stobj ()
185 byte *ptr = stackalloc byte [20];
187 Intrinsics.UnalignedStobj <short> (ptr + 0, 0x6688);
188 if (ptr [0] != 0x88 || ptr [1] != 0x66)
191 Intrinsics.UnalignedStobj <short> (ptr + 1, 0x6589);
192 if (ptr [1] != 0x89 || ptr [2] != 0x65)
195 Intrinsics.UnalignedStobj <int> (ptr + 1, 0x60708090);
196 if (ptr [1] != 0x90 || ptr [2] != 0x80 || ptr [3] != 0x70 || ptr [4] != 0x60)
199 Intrinsics.UnalignedStobj <long> (ptr + 1, 0x405060708090);
200 if (ptr [1] != 0x90 || ptr [2] != 0x80 || ptr [3] != 0x70 || ptr [4] != 0x60 || ptr [5] != 0x50 || ptr [6] != 0x40)
206 public static unsafe int test_0_ldobj_stobj ()
208 byte *dest = stackalloc byte [20];
209 byte *src = stackalloc byte [20];
211 for (int i = 0; i < 20; ++i)
214 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 0, src + 0);
215 if (dest [0] != src [0] || dest [1] != src [1])
218 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 1, src + 0);
219 if (dest [1] != src [0] || dest [2] != src [1])
222 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 0, src + 1);
223 if (dest [0] != src [1] || dest [1] != src [2])
226 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 1, src + 1);
227 if (dest [1] != src [1] || dest [2] != src [2])
230 Intrinsics.UnalignedLdobjStObjPair<int> (dest + 1, src + 1);
231 if (dest [1] != src [1] || dest [2] != src [2])
234 Intrinsics.UnalignedLdobjStObjPair<long> (dest + 1, src + 1);
235 if (dest [1] != src [1] || dest [2] != src [2])
243 public static unsafe int test_0_cpblk ()
245 byte *dest = stackalloc byte [20];
246 byte *src = stackalloc byte [20];
247 for (int i = 0; i < 20; ++i)
251 Intrinsics.UnalignedCpblk (dest + 0, src + 0, 2);
252 if (dest [0] != src [0] || dest [1] != src [1])
255 Intrinsics.UnalignedCpblk (dest + 1, src + 0, 2);
256 if (dest [1] != src [0] || dest [2] != src [1])
259 Intrinsics.UnalignedCpblk (dest + 0, src + 1, 2);
260 if (dest [0] != src [1] || dest [1] != src [2])
263 Intrinsics.UnalignedCpblk (dest + 1, src + 1, 2);
264 if (dest [1] != src [1] || dest [2] != src [2])
267 Intrinsics.UnalignedCpblk (dest + 1, src + 1, 4);
268 for (int i = 0; i < 4; ++i) {
269 if (dest [i + 1] != src [i + 1])
273 Intrinsics.UnalignedCpblk (dest + 1, src + 1, 8);
274 for (int i = 0; i < 8; ++i) {
275 if (dest [i + 1] != src [i + 1])
283 public static unsafe int test_0_initblk ()
285 byte *ptr = stackalloc byte [20];
287 for (int i = 0; i < 20; ++i)
290 Intrinsics.UnalignedInit (ptr, 30, 2);
291 if (ptr [0] != 30 || ptr [1] != 30)
294 Intrinsics.UnalignedInit (ptr + 1, 31, 2);
295 if (ptr[0] != 30 || ptr [1] != 31 || ptr [2] != 31)