4 public class SimdTests {
5 static unsafe Vector8us bad_method_regression_2 (Vector16b va, Vector16b vb) {
6 Vector8us res = new Vector8us ();
11 for (int i = 0; i < 8; ++i)
12 tmp += System.Math.Abs ((int)*a++ - (int)*b++);
16 for (int i = 0; i < 8; ++i)
17 tmp += System.Math.Abs ((int)*a++ - (int)*b++);
22 /*This bug was caused the simplifier not taking notice of LDADDR on the remaining blocks.*/
23 public static int test_2_local_simplifier_regression_other_blocks () {
24 Vector16b a = new Vector16b (1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1);
25 Vector16b b = new Vector16b (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
26 Vector8us res = bad_method_regression_2 (a,b);
27 return (int)res.V0 + res.V4;
30 static unsafe Vector8us bad_method_regression (Vector16b va, Vector16b vb) {
31 Vector8us res = new Vector8us ();
34 *((ushort*)&res) = 10;
45 /*This bug was caused the simplifier not taking notice of LDADDR on the first block.*/
46 public static int test_10_local_simplifier_regression_first_block () {
47 Vector16b a = new Vector16b ();
48 Vector16b b = new Vector16b ();
49 Vector8us res = bad_method_regression (a,b);
54 public static int test_0_vecto8us_extract_mask () {
55 Vector8us a = new Vector8us (0xF0F0, 0x700F, 0xAABB, 0x0000, 0x00F0, 0xF0F0, 0, 0);
56 int c = Vector8us.ExtractByteMask (a);
63 public static int test_0_vecto8us_shuffle_low () {
64 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
65 Vector8us c = Vector8us.ShuffleLow (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
86 public static int test_0_vecto8us_shuffle_high () {
87 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
88 Vector8us c = Vector8us.ShuffleHigh (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
110 public static int test_0_vecto8us_max () {
111 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
112 Vector8us b = new Vector8us (9, 1, 1, 2, 9, 6, 5, 1000);
113 Vector8us c = Vector8us.Max (a, b);
135 public static int test_0_vecto8us_min () {
136 Vector8us a = new Vector8us (1, 2, 3, 0, 5, 6, 5, 4);
137 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
138 Vector8us c = Vector8us.Min (a, b);
159 public static int test_0_vecto8us_avg () {
160 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
161 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
162 Vector8us c = Vector8us.Average (a, b);
183 static void store_helper (ref Vector4f x) {
185 k = new Vector4f(9,9,9,9);
189 public static int test_0_vector4f_byref_store ()
192 k = new Vector4f(1,2,3,4);
193 store_helper (ref k);
199 public static int test_0_vector4f_init_array_element ()
201 Vector4f[] v = new Vector4f[1];
202 v[0] = new Vector4f(9,9,9,9);
208 public static int test_0_vector4f_dup_high () {
209 Vector4f a = new Vector4f (1, 2, 3, 4);
210 Vector4f c = Vector4f.DuplicateHigh(a);
223 public static int test_0_vector4f_dup_low () {
224 Vector4f a = new Vector4f (1, 2, 3, 4);
225 Vector4f c = Vector4f.DuplicateLow (a);
239 public static int test_0_vector4f_interleave_high () {
240 Vector4f a = new Vector4f (1, 2, 3, 4);
241 Vector4f b = new Vector4f (5, 6, 7, 8);
242 Vector4f c = Vector4f.InterleaveHigh (a, b);
255 public static int test_0_vector4f_interleave_low () {
256 Vector4f a = new Vector4f (1, 2, 3, 4);
257 Vector4f b = new Vector4f (5, 6, 7, 8);
258 Vector4f c = Vector4f.InterleaveLow (a, b);
271 public static int test_0_vector4f_rcp () {
272 Vector4f a = new Vector4f (1, 2, 4, 8);
273 Vector4f c = Vector4f.Reciprocal (a);
275 //Test with ranges due to the terrible precision.
276 if (c.X < (1 - 0.01f) || c.X > (1 + 0.01f))
278 if (c.Y < (0.5 - 0.01f) || c.Y > (0.5 + 0.01f))
280 if (c.Z < (0.25 - 0.01f) || c.Z > (0.25 + 0.01f))
282 if (c.W < (0.125 - 0.01f) || c.W > (0.125 + 0.01f))
287 public static int test_0_vector4f_xor () {
288 Vector4f a = new Vector4f (1, 2, 3, 4);
289 Vector4f b = new Vector4f (1, 3, 3, 8);
292 if (((Vector4ui)c).X != 0)
294 if (((Vector4ui)c).Y != 0x400000)
296 if (((Vector4ui)c).Z != 0)
298 if (((Vector4ui)c).W != 0x1800000)
303 public static int test_0_vector4f_or () {
304 Vector4f a = new Vector4f (1, 2, 3, 4);
305 Vector4f b = new Vector4f (1, 3, 3, 8);
308 if (((Vector4ui)c).X != 0x3F800000)
310 if (((Vector4ui)c).Y != 0x40400000)
312 if (((Vector4ui)c).Z != 0x40400000)
314 if (((Vector4ui)c).W != 0x41800000)
318 public static int test_0_vector4f_andn () {
319 Vector4f a = new Vector4f (1, 2, 3, 4);
320 Vector4f b = new Vector4f (1, 3, 3, 8);
321 Vector4f c = Vector4f.AndNot (a ,b);
323 if (((Vector4ui)c).X != 0)
325 if (((Vector4ui)c).Y != 0x400000)
327 if (((Vector4ui)c).Z != 0)
329 if (((Vector4ui)c).W != 0x1000000)
334 public static int test_0_vector4f_and () {
335 Vector4f a = new Vector4f (1, 2, 3, 4);
336 Vector4f b = new Vector4f (1, 3, 3, 8);
339 if (((Vector4ui)c).X != 0x3F800000)
341 if (((Vector4ui)c).Y != 0x40000000)
343 if (((Vector4ui)c).Z != 0x40400000)
345 if (((Vector4ui)c).W != 0x40000000)
350 public static int test_0_vector4f_cmpord () {
351 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
352 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
353 Vector4f c = Vector4f.CompareOrdered (a, b);
355 if (((Vector4ui)c).X != 0)
357 if (((Vector4ui)c).Y != 0)
359 if (((Vector4ui)c).Z != 0xFFFFFFFF)
361 if (((Vector4ui)c).W != 0xFFFFFFFF)
366 public static int test_0_vector4f_cmpnle () {
367 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
368 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
369 Vector4f c = Vector4f.CompareNotLessEqual (a, b);
371 if (((Vector4ui)c).X != 0xFFFFFFFF)
373 if (((Vector4ui)c).Y != 0xFFFFFFFF)
375 if (((Vector4ui)c).Z != 0)
377 if (((Vector4ui)c).W != 0)
382 public static int test_0_vector4f_cmpnlt () {
383 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
384 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
385 Vector4f c = Vector4f.CompareNotLessThan (a, b);
387 if (((Vector4ui)c).X != 0xFFFFFFFF)
389 if (((Vector4ui)c).Y != 0xFFFFFFFF)
391 if (((Vector4ui)c).Z != 0xFFFFFFFF)
393 if (((Vector4ui)c).W != 0)
398 public static int test_0_vector4f_cmpneq () {
399 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
400 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
401 Vector4f c = Vector4f.CompareNotEqual (a, b);
403 if (((Vector4ui)c).X != 0xFFFFFFFF)
405 if (((Vector4ui)c).Y != 0xFFFFFFFF)
407 if (((Vector4ui)c).Z != 0)
409 if (((Vector4ui)c).W != 0xFFFFFFFF)
414 public static int test_0_vector4f_cmpunord () {
415 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
416 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
417 Vector4f c = Vector4f.CompareUnordered (a, b);
419 if (((Vector4ui)c).X != 0xFFFFFFFF)
421 if (((Vector4ui)c).Y != 0xFFFFFFFF)
423 if (((Vector4ui)c).Z != 0)
425 if (((Vector4ui)c).W != 0)
430 public static int test_0_vector4f_cmple () {
431 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
432 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
433 Vector4f c = Vector4f.CompareLessEqual (a, b);
435 if (((Vector4ui)c).X != 0)
437 if (((Vector4ui)c).Y != 0)
439 if (((Vector4ui)c).Z != 0xFFFFFFFF)
441 if (((Vector4ui)c).W != 0xFFFFFFFF)
446 public static int test_0_vector4f_cmplt () {
447 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
448 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
449 Vector4f c = Vector4f.CompareLessThan (a, b);
451 if (((Vector4ui)c).X != 0)
453 if (((Vector4ui)c).Y != 0)
455 if (((Vector4ui)c).Z != 0)
457 if (((Vector4ui)c).W != 0xFFFFFFFF)
462 public static int test_0_vector4f_cmpeq () {
463 Vector4f a = new Vector4f (float.NaN, 2, 3, 6);
464 Vector4f b = new Vector4f (1, float.NaN, 3, 4);
465 Vector4f c = Vector4f.CompareEquals (a, b);
467 if (((Vector4ui)c).X != 0)
469 if (((Vector4ui)c).Y != 0)
471 if (((Vector4ui)c).Z != 0xFFFFFFFF)
473 if (((Vector4ui)c).W != 0)
478 public static int test_0_vector4ui_sar () {
479 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
481 Vector4ui c = Vector4ui.ShiftRightArithmetic (a, 2);
483 if (c.X != 0xFC000000)
494 public static int test_0_vector4ui_unpack_high () {
495 Vector4ui a = new Vector4ui (1,2,3,4);
496 Vector4ui b = new Vector4ui (5,6,7,8);
498 Vector4ui c = Vector4ui.UnpackHigh(a, b);
511 public static int test_0_vector4ui_unpack_low () {
512 Vector4ui a = new Vector4ui (1,2,3,4);
513 Vector4ui b = new Vector4ui (5,6,7,8);
515 Vector4ui c = Vector4ui.UnpackLow (a, b);
528 public static int test_0_vector4ui_xor () {
529 Vector4ui a = new Vector4ui (1,2,3,4);
530 Vector4ui b = new Vector4ui (7,5,3,1);
545 public static int test_0_vector4ui_or () {
546 Vector4ui a = new Vector4ui (1,2,3,4);
547 Vector4ui b = new Vector4ui (7,5,3,1);
561 public static int test_0_vector4ui_and () {
562 Vector4ui a = new Vector4ui (1,2,3,4);
563 Vector4ui b = new Vector4ui (7,5,3,1);
578 public static int test_0_vector4ui_shr () {
579 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
581 Vector4ui c = a >> 2;
583 if (c.X != 0x3C000000)
594 public static int test_0_vector4ui_shl () {
595 Vector4ui a = new Vector4ui (10,20,3,40);
597 Vector4ui c = a << 2;
610 public static int test_0_vector4ui_mul () {
611 Vector4ui a = new Vector4ui (0x8888,20,3,40);
612 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
616 if (c.X != 0xffff7800)
626 public static int test_0_vector4ui_sub () {
627 Vector4ui a = new Vector4ui (1,20,3,40);
628 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
643 public static int test_0_vector4ui_add () {
644 Vector4ui a = new Vector4ui (0xFF00FF00u,2,3,4);
645 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
649 if (c.X != 0xfe01fe00)
661 static int test_0_vector4ui_accessors () {
662 Vector4ui a = new Vector4ui (1,2,3,4);
688 static int test_0_vector8us_sub_sat () {
689 Vector8us a = new Vector8us (0xF000,1,20,3,4,5,6,7);
690 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
691 Vector8us c = Vector8us.SubWithSaturation (a, b);
712 static int test_0_vector8us_add_sat () {
713 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
714 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
715 Vector8us c = Vector8us.AddWithSaturation (a, b);
736 static int test_0_vector8us_unpack_low () {
737 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
738 Vector8us b = new Vector8us (3,4,5,6,7,8,9,10);
739 Vector8us c = Vector8us.UnpackLow (a, b);
761 static int test_0_vector8us_shift_left () {
762 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
764 Vector8us c = a << amt;
775 static int test_0_vector8us_shift_right_arithmetic () {
776 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
778 Vector8us c = Vector8us.ShiftRightArithmetic (a, amt);
789 static int test_0_vector8us_shift_variable_offset () {
791 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
793 Vector8us c = b >> off;
810 static int test_0_vector8us_shift_operand_is_live_after_op () {
811 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
813 Vector8us c = b >> 2;
829 static int test_0_vector8us_shr_constant () {
830 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
831 Vector8us c = a >> 2;
842 static int test_0_vector8us_mul () {
843 Vector8us a = new Vector8us (0x0F00,4,5,6,7,8,9,10);
844 Vector8us b = new Vector8us (0x0888,1,2,3,4,5,6,8);
856 static int test_0_vector8us_add () {
857 Vector8us a = new Vector8us (0xFF00,4,5,6,7,8,9,10);
858 Vector8us b = new Vector8us (0x8888,1,2,3,4,5,6,8);
871 static int test_0_vector8us_sub () {
872 Vector8us a = new Vector8us (3,4,5,6,7,8,9,10);
873 Vector8us b = new Vector8us (10,1,2,3,4,5,6,8);
887 static int test_0_vector8us_accessors () {
888 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
936 static int test_0_vector16b_unpack_high () {
937 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
938 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
939 Vector16b c = Vector16b.UnpackHigh (a, b);
960 static int test_0_vector16b_unpack_low () {
961 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
962 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
963 Vector16b c = Vector16b.UnpackLow (a, b);
984 static int test_0_vector16b_sar () {
985 Vector16b a = new Vector16b (0xF0,20,3,40,0,0,0,0,0,0,0,0,0,0,0,0);
987 Vector16b c = Vector16b.ShiftRightArithmetic (a, 2);
999 static int test_0_vector16b_sub_sat () {
1000 Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1001 Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1002 Vector16b c = Vector16b.SubWithSaturation (a, b);
1013 static int test_0_vector16b_add_sat () {
1014 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1015 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1016 Vector16b c = Vector16b.AddWithSaturation (a, b);
1027 static int test_0_vector16b_add_ovf () {
1028 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1029 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
1030 Vector16b c = a + b;
1041 static int test_0_vector16b_accessors () {
1042 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1129 public static int test_0_accessors () {
1130 Vector4f a = new Vector4f (1, 2, 3, 4);
1142 public static int test_0_packed_add_with_stack_tmp () {
1143 Vector4f a = new Vector4f (1, 2, 3, 4);
1144 Vector4f b = new Vector4f (5, 6, 7, 8);
1145 Vector4f c = new Vector4f (-1, -3, -4, -5);
1146 Vector4f d = a + b + c;
1158 public static int test_0_simple_packed_add () {
1159 Vector4f a = new Vector4f (1, 2, 3, 4);
1160 Vector4f b = new Vector4f (5, 6, 7, 8);
1174 public static int test_0_simple_packed_sub () {
1175 Vector4f a = new Vector4f (1, 2, 3, 4);
1176 Vector4f b = new Vector4f (5, 6, 7, 8);
1189 public static int test_0_simple_packed_mul () {
1190 Vector4f a = new Vector4f (1, 2, 3, 4);
1191 Vector4f b = new Vector4f (5, 6, 7, 8);
1204 public static int test_0_simple_packed_div () {
1205 Vector4f a = new Vector4f (2, 2, 3, 4);
1206 Vector4f b = new Vector4f (20, 10, 33, 12);
1219 public static int test_0_simple_packed_sqrt () {
1220 Vector4f a = new Vector4f (16, 4, 9, 25);
1221 a = Vector4f.Sqrt (a);
1233 public static int test_0_simple_packed_invsqrt () {
1234 Vector4f a = new Vector4f (16, 4, 100, 25);
1235 //this function has VERY low precision
1236 a = Vector4f.InvSqrt (a);
1237 if (a.X < (1/4f - 0.01f) || a.X > (1/4f + 0.01f))
1239 if (a.Y < (1/2f - 0.01f) || a.Y > (1/2f + 0.01f))
1241 if (a.Z < (1/10f - 0.01f) || a.Z > (1/10f + 0.01f))
1243 if (a.W < (1/5f - 0.01f) || a.W > (1/5f + 0.01f))
1248 public static int test_0_simple_packed_min () {
1249 Vector4f a = new Vector4f (16, -4, 9, 25);
1250 Vector4f b = new Vector4f (5, 3, 9, 0);
1251 Vector4f c = Vector4f.Min (a, b);
1263 public static int test_0_simple_packed_max () {
1264 Vector4f a = new Vector4f (16, -4, 9, 25);
1265 Vector4f b = new Vector4f (5, 3, 9, 0);
1266 Vector4f c = Vector4f.Max (a, b);
1278 public static int test_0_simple_packed_hadd () {
1279 Vector4f a = new Vector4f (5, 5, 6, 6);
1280 Vector4f b = new Vector4f (7, 7, 8, 8);
1281 Vector4f c = Vector4f.HorizontalAdd (a, b);
1293 public static int test_0_simple_packed_hsub () {
1294 Vector4f a = new Vector4f (5, 2, 6, 1);
1295 Vector4f b = new Vector4f (7, 0, 8, 3);
1296 Vector4f c = Vector4f.HorizontalSub (a, b);
1308 public static int test_0_simple_packed_addsub () {
1309 Vector4f a = new Vector4f (5, 2, 6, 1);
1310 Vector4f b = new Vector4f (7, 0, 8, 3);
1311 Vector4f c = Vector4f.AddSub (a, b);
1323 public static int test_0_simple_packed_shuffle () {
1324 Vector4f a = new Vector4f (1, 2, 3, 4);
1325 a = Vector4f.Shuffle(a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1337 public static int test_0_packed_shuffle_with_reg_pressure () {
1338 Vector4f v = new Vector4f (1, 2, 3, 4);
1339 Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v;
1340 if (ff) v = v + v -v ;
1342 Vector4f r0 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1343 Vector4f r1 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1344 Vector4f x = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1345 Vector4f r2 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1346 Vector4f r3 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1354 Vector4f result = r0 + r1 + r2 + r3;
1364 if (result.Y != result.Y)
1369 public static int test_24_regs_pressure_a () {
1370 Vector4f a = new Vector4f (1, 2, 3, 4);
1378 public static int test_54_regs_pressure_b () {
1379 Vector4f a = new Vector4f (1, 2, 3, 4);
1383 Vector4f e = a + b + c;
1384 Vector4f f = d - b + a - c;
1385 Vector4f g = a - d * f - c + b;
1386 Vector4f h = a * b - c + e;
1387 Vector4f i = h - g - f - e - d - c - b - a;
1388 Vector4f j = a + b + c + d + e + f + g + h + i;
1393 public static int test_3_single_block_var_is_properly_promoted () {
1394 Vector4f a = new Vector4f (4, 5, 6, 7);
1398 Vector4f b = new Vector4f (1, 2, 3, 4);
1409 static float float_val = 45f;
1411 public static int test_0_sse2_opt_and_simd_intrinsic_proper_regalloc () {
1412 Vector4f v = new Vector4f (1, 2, 3, 4);
1413 float f = float_val;
1422 public static int Main () {
1423 return TestDriver.RunTests (typeof (SimdTests));