4 public class SimdTests {
5 public static int test_0_vecto8us_extract_mask () {
6 Vector8us a = new Vector8us (0xF0F0, 0x700F, 0xAABB, 0x0000, 0x00F0, 0xF0F0, 0, 0);
7 int c = Vector8us.ExtractByteMask (a);
14 public static int test_0_vecto8us_shuffle_low () {
15 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
16 Vector8us c = Vector8us.ShuffleLow (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
37 public static int test_0_vecto8us_shuffle_high () {
38 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
39 Vector8us c = Vector8us.ShuffleHigh (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
61 public static int test_0_vecto8us_max () {
62 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
63 Vector8us b = new Vector8us (9, 1, 1, 2, 9, 6, 5, 1000);
64 Vector8us c = Vector8us.Max (a, b);
86 public static int test_0_vecto8us_min () {
87 Vector8us a = new Vector8us (1, 2, 3, 0, 5, 6, 5, 4);
88 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
89 Vector8us c = Vector8us.Min (a, b);
110 public static int test_0_vecto8us_avg () {
111 Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8);
112 Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6);
113 Vector8us c = Vector8us.Average (a, b);
134 static void store_helper (ref Vector4f x) {
136 k = new Vector4f(9,9,9,9);
140 public static int test_0_vector4f_byref_store ()
143 k = new Vector4f(1,2,3,4);
144 store_helper (ref k);
150 public static int test_0_vector4f_init_array_element ()
152 Vector4f[] v = new Vector4f[1];
153 v[0] = new Vector4f(9,9,9,9);
159 public static int test_0_vector4f_dup_high () {
160 Vector4f a = new Vector4f (1, 2, 3, 4);
161 Vector4f c = Vector4f.DuplicateHigh(a);
174 public static int test_0_vector4f_dup_low () {
175 Vector4f a = new Vector4f (1, 2, 3, 4);
176 Vector4f c = Vector4f.DuplicateLow (a);
190 public static int test_0_vector4f_interleave_high () {
191 Vector4f a = new Vector4f (1, 2, 3, 4);
192 Vector4f b = new Vector4f (5, 6, 7, 8);
193 Vector4f c = Vector4f.InterleaveHigh (a, b);
206 public static int test_0_vector4f_interleave_low () {
207 Vector4f a = new Vector4f (1, 2, 3, 4);
208 Vector4f b = new Vector4f (5, 6, 7, 8);
209 Vector4f c = Vector4f.InterleaveLow (a, b);
222 public static int test_0_vector4f_rcp () {
223 Vector4f a = new Vector4f (1, 2, 4, 8);
224 Vector4f c = Vector4f.Reciprocal (a);
226 //Test with ranges due to the terrible precision.
227 if (c.X < (1 - 0.01f) || c.X > (1 + 0.01f))
229 if (c.Y < (0.5 - 0.01f) || c.Y > (0.5 + 0.01f))
231 if (c.Z < (0.25 - 0.01f) || c.Z > (0.25 + 0.01f))
233 if (c.W < (0.125 - 0.01f) || c.W > (0.125 + 0.01f))
238 public static int test_0_vector4f_xor () {
239 Vector4f a = new Vector4f (1, 2, 3, 4);
240 Vector4f b = new Vector4f (1, 3, 3, 8);
243 if (((Vector4ui)c).X != 0)
245 if (((Vector4ui)c).Y != 0x400000)
247 if (((Vector4ui)c).Z != 0)
249 if (((Vector4ui)c).W != 0x1800000)
254 public static int test_0_vector4f_or () {
255 Vector4f a = new Vector4f (1, 2, 3, 4);
256 Vector4f b = new Vector4f (1, 3, 3, 8);
259 if (((Vector4ui)c).X != 0x3F800000)
261 if (((Vector4ui)c).Y != 0x40400000)
263 if (((Vector4ui)c).Z != 0x40400000)
265 if (((Vector4ui)c).W != 0x41800000)
269 public static int test_0_vector4f_andn () {
270 Vector4f a = new Vector4f (1, 2, 3, 4);
271 Vector4f b = new Vector4f (1, 3, 3, 8);
272 Vector4f c = Vector4f.AndNot (a ,b);
274 if (((Vector4ui)c).X != 0)
276 if (((Vector4ui)c).Y != 0x400000)
278 if (((Vector4ui)c).Z != 0)
280 if (((Vector4ui)c).W != 0x1000000)
285 public static int test_0_vector4f_and () {
286 Vector4f a = new Vector4f (1, 2, 3, 4);
287 Vector4f b = new Vector4f (1, 3, 3, 8);
290 if (((Vector4ui)c).X != 0x3F800000)
292 if (((Vector4ui)c).Y != 0x40000000)
294 if (((Vector4ui)c).Z != 0x40400000)
296 if (((Vector4ui)c).W != 0x40000000)
301 public static int test_0_vector4f_cmpord () {
302 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
303 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
304 Vector4f c = Vector4f.CompareOrdered (a, b);
306 if (((Vector4ui)c).X != 0)
308 if (((Vector4ui)c).Y != 0)
310 if (((Vector4ui)c).Z != 0xFFFFFFFF)
312 if (((Vector4ui)c).W != 0xFFFFFFFF)
317 public static int test_0_vector4f_cmpnle () {
318 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
319 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
320 Vector4f c = Vector4f.CompareNotLessEqual (a, b);
322 if (((Vector4ui)c).X != 0xFFFFFFFF)
324 if (((Vector4ui)c).Y != 0xFFFFFFFF)
326 if (((Vector4ui)c).Z != 0)
328 if (((Vector4ui)c).W != 0)
333 public static int test_0_vector4f_cmpnlt () {
334 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
335 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
336 Vector4f c = Vector4f.CompareNotLessThan (a, b);
338 if (((Vector4ui)c).X != 0xFFFFFFFF)
340 if (((Vector4ui)c).Y != 0xFFFFFFFF)
342 if (((Vector4ui)c).Z != 0xFFFFFFFF)
344 if (((Vector4ui)c).W != 0)
349 public static int test_0_vector4f_cmpneq () {
350 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
351 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
352 Vector4f c = Vector4f.CompareNotEqual (a, b);
354 if (((Vector4ui)c).X != 0xFFFFFFFF)
356 if (((Vector4ui)c).Y != 0xFFFFFFFF)
358 if (((Vector4ui)c).Z != 0)
360 if (((Vector4ui)c).W != 0xFFFFFFFF)
365 public static int test_0_vector4f_cmpunord () {
366 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
367 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
368 Vector4f c = Vector4f.CompareUnordered (a, b);
370 if (((Vector4ui)c).X != 0xFFFFFFFF)
372 if (((Vector4ui)c).Y != 0xFFFFFFFF)
374 if (((Vector4ui)c).Z != 0)
376 if (((Vector4ui)c).W != 0)
381 public static int test_0_vector4f_cmple () {
382 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
383 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
384 Vector4f c = Vector4f.CompareLessEqual (a, b);
386 if (((Vector4ui)c).X != 0)
388 if (((Vector4ui)c).Y != 0)
390 if (((Vector4ui)c).Z != 0xFFFFFFFF)
392 if (((Vector4ui)c).W != 0xFFFFFFFF)
397 public static int test_0_vector4f_cmplt () {
398 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
399 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
400 Vector4f c = Vector4f.CompareLessThan (a, b);
402 if (((Vector4ui)c).X != 0)
404 if (((Vector4ui)c).Y != 0)
406 if (((Vector4ui)c).Z != 0)
408 if (((Vector4ui)c).W != 0xFFFFFFFF)
413 public static int test_0_vector4f_cmpeq () {
414 Vector4f a = new Vector4f (float.NaN, 2, 3, 6);
415 Vector4f b = new Vector4f (1, float.NaN, 3, 4);
416 Vector4f c = Vector4f.CompareEquals (a, b);
418 if (((Vector4ui)c).X != 0)
420 if (((Vector4ui)c).Y != 0)
422 if (((Vector4ui)c).Z != 0xFFFFFFFF)
424 if (((Vector4ui)c).W != 0)
429 public static int test_0_vector4ui_sar () {
430 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
432 Vector4ui c = Vector4ui.ShiftRightArithmetic (a, 2);
434 if (c.X != 0xFC000000)
445 public static int test_0_vector4ui_unpack_high () {
446 Vector4ui a = new Vector4ui (1,2,3,4);
447 Vector4ui b = new Vector4ui (5,6,7,8);
449 Vector4ui c = Vector4ui.UnpackHigh(a, b);
462 public static int test_0_vector4ui_unpack_low () {
463 Vector4ui a = new Vector4ui (1,2,3,4);
464 Vector4ui b = new Vector4ui (5,6,7,8);
466 Vector4ui c = Vector4ui.UnpackLow (a, b);
479 public static int test_0_vector4ui_xor () {
480 Vector4ui a = new Vector4ui (1,2,3,4);
481 Vector4ui b = new Vector4ui (7,5,3,1);
496 public static int test_0_vector4ui_or () {
497 Vector4ui a = new Vector4ui (1,2,3,4);
498 Vector4ui b = new Vector4ui (7,5,3,1);
512 public static int test_0_vector4ui_and () {
513 Vector4ui a = new Vector4ui (1,2,3,4);
514 Vector4ui b = new Vector4ui (7,5,3,1);
529 public static int test_0_vector4ui_shr () {
530 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
532 Vector4ui c = a >> 2;
534 if (c.X != 0x3C000000)
545 public static int test_0_vector4ui_shl () {
546 Vector4ui a = new Vector4ui (10,20,3,40);
548 Vector4ui c = a << 2;
561 public static int test_0_vector4ui_mul () {
562 Vector4ui a = new Vector4ui (0x8888,20,3,40);
563 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
567 if (c.X != 0xffff7800)
577 public static int test_0_vector4ui_sub () {
578 Vector4ui a = new Vector4ui (1,20,3,40);
579 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
594 public static int test_0_vector4ui_add () {
595 Vector4ui a = new Vector4ui (0xFF00FF00u,2,3,4);
596 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
600 if (c.X != 0xfe01fe00)
612 static int test_0_vector4ui_accessors () {
613 Vector4ui a = new Vector4ui (1,2,3,4);
639 static int test_0_vector8us_sub_sat () {
640 Vector8us a = new Vector8us (0xF000,1,20,3,4,5,6,7);
641 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
642 Vector8us c = Vector8us.SubWithSaturation (a, b);
663 static int test_0_vector8us_add_sat () {
664 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
665 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
666 Vector8us c = Vector8us.AddWithSaturation (a, b);
687 static int test_0_vector8us_unpack_low () {
688 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
689 Vector8us b = new Vector8us (3,4,5,6,7,8,9,10);
690 Vector8us c = Vector8us.UnpackLow (a, b);
712 static int test_0_vector8us_shift_left () {
713 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
715 Vector8us c = a << amt;
726 static int test_0_vector8us_shift_right_arithmetic () {
727 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
729 Vector8us c = Vector8us.ShiftRightArithmetic (a, amt);
740 static int test_0_vector8us_shift_variable_offset () {
742 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
744 Vector8us c = b >> off;
761 static int test_0_vector8us_shift_operand_is_live_after_op () {
762 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
764 Vector8us c = b >> 2;
780 static int test_0_vector8us_shr_constant () {
781 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
782 Vector8us c = a >> 2;
793 static int test_0_vector8us_mul () {
794 Vector8us a = new Vector8us (0x0F00,4,5,6,7,8,9,10);
795 Vector8us b = new Vector8us (0x0888,1,2,3,4,5,6,8);
807 static int test_0_vector8us_add () {
808 Vector8us a = new Vector8us (0xFF00,4,5,6,7,8,9,10);
809 Vector8us b = new Vector8us (0x8888,1,2,3,4,5,6,8);
822 static int test_0_vector8us_sub () {
823 Vector8us a = new Vector8us (3,4,5,6,7,8,9,10);
824 Vector8us b = new Vector8us (10,1,2,3,4,5,6,8);
838 static int test_0_vector8us_accessors () {
839 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
887 static int test_0_vector16b_unpack_high () {
888 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
889 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
890 Vector16b c = Vector16b.UnpackHigh (a, b);
911 static int test_0_vector16b_unpack_low () {
912 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
913 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
914 Vector16b c = Vector16b.UnpackLow (a, b);
935 static int test_0_vector16b_sar () {
936 Vector16b a = new Vector16b (0xF0,20,3,40,0,0,0,0,0,0,0,0,0,0,0,0);
938 Vector16b c = Vector16b.ShiftRightArithmetic (a, 2);
950 static int test_0_vector16b_sub_sat () {
951 Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
952 Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
953 Vector16b c = Vector16b.SubWithSaturation (a, b);
964 static int test_0_vector16b_add_sat () {
965 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
966 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
967 Vector16b c = Vector16b.AddWithSaturation (a, b);
978 static int test_0_vector16b_add_ovf () {
979 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
980 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
992 static int test_0_vector16b_accessors () {
993 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
1080 public static int test_0_accessors () {
1081 Vector4f a = new Vector4f (1, 2, 3, 4);
1093 public static int test_0_packed_add_with_stack_tmp () {
1094 Vector4f a = new Vector4f (1, 2, 3, 4);
1095 Vector4f b = new Vector4f (5, 6, 7, 8);
1096 Vector4f c = new Vector4f (-1, -3, -4, -5);
1097 Vector4f d = a + b + c;
1109 public static int test_0_simple_packed_add () {
1110 Vector4f a = new Vector4f (1, 2, 3, 4);
1111 Vector4f b = new Vector4f (5, 6, 7, 8);
1125 public static int test_0_simple_packed_sub () {
1126 Vector4f a = new Vector4f (1, 2, 3, 4);
1127 Vector4f b = new Vector4f (5, 6, 7, 8);
1140 public static int test_0_simple_packed_mul () {
1141 Vector4f a = new Vector4f (1, 2, 3, 4);
1142 Vector4f b = new Vector4f (5, 6, 7, 8);
1155 public static int test_0_simple_packed_div () {
1156 Vector4f a = new Vector4f (2, 2, 3, 4);
1157 Vector4f b = new Vector4f (20, 10, 33, 12);
1170 public static int test_0_simple_packed_sqrt () {
1171 Vector4f a = new Vector4f (16, 4, 9, 25);
1172 a = Vector4f.Sqrt (a);
1184 public static int test_0_simple_packed_invsqrt () {
1185 Vector4f a = new Vector4f (16, 4, 100, 25);
1186 //this function has VERY low precision
1187 a = Vector4f.InvSqrt (a);
1188 if (a.X < (1/4f - 0.01f) || a.X > (1/4f + 0.01f))
1190 if (a.Y < (1/2f - 0.01f) || a.Y > (1/2f + 0.01f))
1192 if (a.Z < (1/10f - 0.01f) || a.Z > (1/10f + 0.01f))
1194 if (a.W < (1/5f - 0.01f) || a.W > (1/5f + 0.01f))
1199 public static int test_0_simple_packed_min () {
1200 Vector4f a = new Vector4f (16, -4, 9, 25);
1201 Vector4f b = new Vector4f (5, 3, 9, 0);
1202 Vector4f c = Vector4f.Min (a, b);
1214 public static int test_0_simple_packed_max () {
1215 Vector4f a = new Vector4f (16, -4, 9, 25);
1216 Vector4f b = new Vector4f (5, 3, 9, 0);
1217 Vector4f c = Vector4f.Max (a, b);
1229 public static int test_0_simple_packed_hadd () {
1230 Vector4f a = new Vector4f (5, 5, 6, 6);
1231 Vector4f b = new Vector4f (7, 7, 8, 8);
1232 Vector4f c = Vector4f.HorizontalAdd (a, b);
1244 public static int test_0_simple_packed_hsub () {
1245 Vector4f a = new Vector4f (5, 2, 6, 1);
1246 Vector4f b = new Vector4f (7, 0, 8, 3);
1247 Vector4f c = Vector4f.HorizontalSub (a, b);
1259 public static int test_0_simple_packed_addsub () {
1260 Vector4f a = new Vector4f (5, 2, 6, 1);
1261 Vector4f b = new Vector4f (7, 0, 8, 3);
1262 Vector4f c = Vector4f.AddSub (a, b);
1274 public static int test_0_simple_packed_shuffle () {
1275 Vector4f a = new Vector4f (1, 2, 3, 4);
1276 a = Vector4f.Shuffle(a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1288 public static int test_0_packed_shuffle_with_reg_pressure () {
1289 Vector4f v = new Vector4f (1, 2, 3, 4);
1290 Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v;
1291 if (ff) v = v + v -v ;
1293 Vector4f r0 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1294 Vector4f r1 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1295 Vector4f x = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1296 Vector4f r2 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1297 Vector4f r3 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1305 Vector4f result = r0 + r1 + r2 + r3;
1315 if (result.Y != result.Y)
1320 public static int test_24_regs_pressure_a () {
1321 Vector4f a = new Vector4f (1, 2, 3, 4);
1329 public static int test_54_regs_pressure_b () {
1330 Vector4f a = new Vector4f (1, 2, 3, 4);
1334 Vector4f e = a + b + c;
1335 Vector4f f = d - b + a - c;
1336 Vector4f g = a - d * f - c + b;
1337 Vector4f h = a * b - c + e;
1338 Vector4f i = h - g - f - e - d - c - b - a;
1339 Vector4f j = a + b + c + d + e + f + g + h + i;
1344 public static int test_3_single_block_var_is_properly_promoted () {
1345 Vector4f a = new Vector4f (4, 5, 6, 7);
1349 Vector4f b = new Vector4f (1, 2, 3, 4);
1360 static float float_val = 45f;
1362 public static int test_0_sse2_opt_and_simd_intrinsic_proper_regalloc () {
1363 Vector4f v = new Vector4f (1, 2, 3, 4);
1364 float f = float_val;
1373 public static int Main () {
1374 return TestDriver.RunTests (typeof (SimdTests));