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 /* we can loose some precision due to r4<->r8 conversions */
52 if (Math.Abs (Intrinsics.UnalignedLdobj<float> (ptr + 1) - f) > 0.01f)
58 public static unsafe int test_0_ldobj_r8 ()
60 byte *ptr = stackalloc byte [32];
62 *(double*)ptr = (double)f;
64 long expected = *(long*)ptr;
66 Intrinsics.UnalignedStobj<long> (ptr + 3, expected);
67 if (Intrinsics.UnalignedLdobj<double> (ptr + 3) != f)
73 public static unsafe int test_0_ldobj ()
75 byte *ptr = stackalloc byte [20];
76 for (int i = 0; i < 20; ++i)
80 if (Intrinsics.UnalignedLdobj<short> (ptr + 0) != 0x0100)
83 if (Intrinsics.UnalignedLdobj<short> (ptr + 1) != 0x0201)
86 if (Intrinsics.UnalignedLdobj<short> (ptr + 2) != 0x0302)
89 if (Intrinsics.UnalignedLdobj<int> (ptr + 1) != 0x04030201)
92 if (Intrinsics.UnalignedLdobj<int> (ptr + 2) != 0x05040302)
95 if (Intrinsics.UnalignedLdobj<long> (ptr + 1) != 0x0807060504030201)
98 if (Intrinsics.UnalignedLdobj<long> (ptr + 6) != 0xD0C0B0A09080706)
104 public static unsafe int test_0_ldind ()
106 byte *ptr = stackalloc byte [20];
107 for (int i = 0; i < 20; ++i)
111 if (Intrinsics.UnalignedLdInd2 (ptr + 0) != 0x0100)
114 if (Intrinsics.UnalignedLdInd2 (ptr + 1) != 0x0201)
117 if (Intrinsics.UnalignedLdInd2 (ptr + 2) != 0x0302)
120 if (Intrinsics.UnalignedLdInd4 (ptr + 1) != 0x04030201)
123 if (Intrinsics.UnalignedLdInd4 (ptr + 2) != 0x05040302)
126 if (Intrinsics.UnalignedLdInd8 (ptr + 1) != 0x0807060504030201)
129 if (Intrinsics.UnalignedLdInd8 (ptr + 6) != 0xD0C0B0A09080706)
134 public static unsafe int test_0_cpobj ()
136 byte *dest = stackalloc byte [20];
137 byte *src = stackalloc byte [20];
138 for (int i = 0; i < 20; ++i)
141 Intrinsics.UnalignedCpobj<short> (dest + 0, src + 0);
142 if (dest [0] != src [0] || dest [1] != src [1])
145 Intrinsics.UnalignedCpobj<short> (dest + 1, src + 0);
146 if (dest [1] != src [0] || dest [2] != src [1])
149 Intrinsics.UnalignedCpobj<short> (dest + 0, src + 1);
150 if (dest [0] != src [1] || dest [1] != src [2])
153 Intrinsics.UnalignedCpobj<short> (dest + 1, src + 1);
154 if (dest [1] != src [1] || dest [2] != src [2])
157 Intrinsics.UnalignedCpobj<int> (dest + 3, src);
158 for (int i = 0; i < 4; ++i) {
159 if (dest [i + 3] != src [i])
163 Intrinsics.UnalignedCpobj<int> (dest + 1, src + 2);
164 for (int i = 0; i < 4; ++i) {
165 if (dest [i + 1] != src [i + 2])
169 Intrinsics.UnalignedCpobj<long> (dest + 1, src + 2);
170 for (int i = 0; i < 8; ++i) {
171 if (dest [i + 1] != src [i + 2])
175 Intrinsics.UnalignedCpobj<long> (dest + 7, src + 2);
176 for (int i = 0; i < 8; ++i) {
177 if (dest [i + 7] != src [i + 2])
184 public static unsafe int test_0_stobj ()
186 byte *ptr = stackalloc byte [20];
188 Intrinsics.UnalignedStobj <short> (ptr + 0, 0x6688);
189 if (ptr [0] != 0x88 || ptr [1] != 0x66)
192 Intrinsics.UnalignedStobj <short> (ptr + 1, 0x6589);
193 if (ptr [1] != 0x89 || ptr [2] != 0x65)
196 Intrinsics.UnalignedStobj <int> (ptr + 1, 0x60708090);
197 if (ptr [1] != 0x90 || ptr [2] != 0x80 || ptr [3] != 0x70 || ptr [4] != 0x60)
200 Intrinsics.UnalignedStobj <long> (ptr + 1, 0x405060708090);
201 if (ptr [1] != 0x90 || ptr [2] != 0x80 || ptr [3] != 0x70 || ptr [4] != 0x60 || ptr [5] != 0x50 || ptr [6] != 0x40)
207 public static unsafe int test_0_ldobj_stobj ()
209 byte *dest = stackalloc byte [20];
210 byte *src = stackalloc byte [20];
212 for (int i = 0; i < 20; ++i)
215 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 0, src + 0);
216 if (dest [0] != src [0] || dest [1] != src [1])
219 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 1, src + 0);
220 if (dest [1] != src [0] || dest [2] != src [1])
223 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 0, src + 1);
224 if (dest [0] != src [1] || dest [1] != src [2])
227 Intrinsics.UnalignedLdobjStObjPair<short> (dest + 1, src + 1);
228 if (dest [1] != src [1] || dest [2] != src [2])
231 Intrinsics.UnalignedLdobjStObjPair<int> (dest + 1, src + 1);
232 if (dest [1] != src [1] || dest [2] != src [2])
235 Intrinsics.UnalignedLdobjStObjPair<long> (dest + 1, src + 1);
236 if (dest [1] != src [1] || dest [2] != src [2])
244 public static unsafe int test_0_cpblk ()
246 byte *dest = stackalloc byte [20];
247 byte *src = stackalloc byte [20];
248 for (int i = 0; i < 20; ++i)
252 Intrinsics.UnalignedCpblk (dest + 0, src + 0, 2);
253 if (dest [0] != src [0] || dest [1] != src [1])
256 Intrinsics.UnalignedCpblk (dest + 1, src + 0, 2);
257 if (dest [1] != src [0] || dest [2] != src [1])
260 Intrinsics.UnalignedCpblk (dest + 0, src + 1, 2);
261 if (dest [0] != src [1] || dest [1] != src [2])
264 Intrinsics.UnalignedCpblk (dest + 1, src + 1, 2);
265 if (dest [1] != src [1] || dest [2] != src [2])
268 Intrinsics.UnalignedCpblk (dest + 1, src + 1, 4);
269 for (int i = 0; i < 4; ++i) {
270 if (dest [i + 1] != src [i + 1])
274 Intrinsics.UnalignedCpblk (dest + 1, src + 1, 8);
275 for (int i = 0; i < 8; ++i) {
276 if (dest [i + 1] != src [i + 1])
284 public static unsafe int test_0_initblk ()
286 byte *ptr = stackalloc byte [20];
288 for (int i = 0; i < 20; ++i)
291 Intrinsics.UnalignedInit (ptr, 30, 2);
292 if (ptr [0] != 30 || ptr [1] != 30)
295 Intrinsics.UnalignedInit (ptr + 1, 31, 2);
296 if (ptr[0] != 30 || ptr [1] != 31 || ptr [2] != 31)