4 public class SimdTests {
6 public static int test_0_vector4f_dup_high () {
7 Vector4f a = new Vector4f (1, 2, 3, 4);
8 Vector4f c = Vector4f.DuplicateHigh(a);
21 public static int test_0_vector4f_dup_low () {
22 Vector4f a = new Vector4f (1, 2, 3, 4);
23 Vector4f c = Vector4f.DuplicateLow (a);
37 public static int test_0_vector4f_interleave_high () {
38 Vector4f a = new Vector4f (1, 2, 3, 4);
39 Vector4f b = new Vector4f (5, 6, 7, 8);
40 Vector4f c = Vector4f.InterleaveHigh (a, b);
53 public static int test_0_vector4f_interleave_low () {
54 Vector4f a = new Vector4f (1, 2, 3, 4);
55 Vector4f b = new Vector4f (5, 6, 7, 8);
56 Vector4f c = Vector4f.InterleaveLow (a, b);
69 public static int test_0_vector4f_rcp () {
70 Vector4f a = new Vector4f (1, 2, 4, 8);
71 Vector4f c = Vector4f.Reciprocal (a);
73 //Test with ranges due to the terrible precision.
74 if (c.X < (1 - 0.01f) || c.X > (1 + 0.01f))
76 if (c.Y < (0.5 - 0.01f) || c.Y > (0.5 + 0.01f))
78 if (c.Z < (0.25 - 0.01f) || c.Z > (0.25 + 0.01f))
80 if (c.W < (0.125 - 0.01f) || c.W > (0.125 + 0.01f))
85 public static int test_0_vector4f_xor () {
86 Vector4f a = new Vector4f (1, 2, 3, 4);
87 Vector4f b = new Vector4f (1, 3, 3, 8);
90 if (((Vector4ui)c).X != 0)
92 if (((Vector4ui)c).Y != 0x400000)
94 if (((Vector4ui)c).Z != 0)
96 if (((Vector4ui)c).W != 0x1800000)
101 public static int test_0_vector4f_or () {
102 Vector4f a = new Vector4f (1, 2, 3, 4);
103 Vector4f b = new Vector4f (1, 3, 3, 8);
106 if (((Vector4ui)c).X != 0x3F800000)
108 if (((Vector4ui)c).Y != 0x40400000)
110 if (((Vector4ui)c).Z != 0x40400000)
112 if (((Vector4ui)c).W != 0x41800000)
116 public static int test_0_vector4f_andn () {
117 Vector4f a = new Vector4f (1, 2, 3, 4);
118 Vector4f b = new Vector4f (1, 3, 3, 8);
119 Vector4f c = Vector4f.AndNot (a ,b);
121 if (((Vector4ui)c).X != 0)
123 if (((Vector4ui)c).Y != 0x400000)
125 if (((Vector4ui)c).Z != 0)
127 if (((Vector4ui)c).W != 0x1000000)
132 public static int test_0_vector4f_and () {
133 Vector4f a = new Vector4f (1, 2, 3, 4);
134 Vector4f b = new Vector4f (1, 3, 3, 8);
137 if (((Vector4ui)c).X != 0x3F800000)
139 if (((Vector4ui)c).Y != 0x40000000)
141 if (((Vector4ui)c).Z != 0x40400000)
143 if (((Vector4ui)c).W != 0x40000000)
148 public static int test_0_vector4f_cmpord () {
149 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
150 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
151 Vector4f c = Vector4f.CompareOrdered (a, b);
153 if (((Vector4ui)c).X != 0)
155 if (((Vector4ui)c).Y != 0)
157 if (((Vector4ui)c).Z != 0xFFFFFFFF)
159 if (((Vector4ui)c).W != 0xFFFFFFFF)
164 public static int test_0_vector4f_cmpnle () {
165 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
166 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
167 Vector4f c = Vector4f.CompareNotLessEqual (a, b);
169 if (((Vector4ui)c).X != 0xFFFFFFFF)
171 if (((Vector4ui)c).Y != 0xFFFFFFFF)
173 if (((Vector4ui)c).Z != 0)
175 if (((Vector4ui)c).W != 0)
180 public static int test_0_vector4f_cmpnlt () {
181 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
182 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
183 Vector4f c = Vector4f.CompareNotLessThan (a, b);
185 if (((Vector4ui)c).X != 0xFFFFFFFF)
187 if (((Vector4ui)c).Y != 0xFFFFFFFF)
189 if (((Vector4ui)c).Z != 0xFFFFFFFF)
191 if (((Vector4ui)c).W != 0)
196 public static int test_0_vector4f_cmpneq () {
197 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
198 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
199 Vector4f c = Vector4f.CompareNotEqual (a, b);
201 if (((Vector4ui)c).X != 0xFFFFFFFF)
203 if (((Vector4ui)c).Y != 0xFFFFFFFF)
205 if (((Vector4ui)c).Z != 0)
207 if (((Vector4ui)c).W != 0xFFFFFFFF)
212 public static int test_0_vector4f_cmpunord () {
213 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
214 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
215 Vector4f c = Vector4f.CompareUnordered (a, b);
217 if (((Vector4ui)c).X != 0xFFFFFFFF)
219 if (((Vector4ui)c).Y != 0xFFFFFFFF)
221 if (((Vector4ui)c).Z != 0)
223 if (((Vector4ui)c).W != 0)
228 public static int test_0_vector4f_cmple () {
229 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
230 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
231 Vector4f c = Vector4f.CompareLessEqual (a, b);
233 if (((Vector4ui)c).X != 0)
235 if (((Vector4ui)c).Y != 0)
237 if (((Vector4ui)c).Z != 0xFFFFFFFF)
239 if (((Vector4ui)c).W != 0xFFFFFFFF)
243 public static int test_0_vector4f_cmplt () {
244 Vector4f a = new Vector4f (float.NaN, 2, 3, 4);
245 Vector4f b = new Vector4f (1, float.NaN, 3, 6);
246 Vector4f c = Vector4f.CompareLessThan (a, b);
248 if (((Vector4ui)c).X != 0)
250 if (((Vector4ui)c).Y != 0)
252 if (((Vector4ui)c).Z != 0)
254 if (((Vector4ui)c).W != 0xFFFFFFFF)
259 public static int test_0_vector4f_cmpeq () {
260 Vector4f a = new Vector4f (float.NaN, 2, 3, 6);
261 Vector4f b = new Vector4f (1, float.NaN, 3, 4);
262 Vector4f c = Vector4f.CompareEquals (a, b);
264 if (((Vector4ui)c).X != 0)
266 if (((Vector4ui)c).Y != 0)
268 if (((Vector4ui)c).Z != 0xFFFFFFFF)
270 if (((Vector4ui)c).W != 0)
275 public static int test_0_vector4ui_sar () {
276 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
278 Vector4ui c = Vector4ui.ShiftRightArithmetic (a, 2);
280 if (c.X != 0xFC000000)
291 public static int test_0_vector4ui_unpack_high () {
292 Vector4ui a = new Vector4ui (1,2,3,4);
293 Vector4ui b = new Vector4ui (5,6,7,8);
295 Vector4ui c = Vector4ui.UnpackHigh(a, b);
308 public static int test_0_vector4ui_unpack_low () {
309 Vector4ui a = new Vector4ui (1,2,3,4);
310 Vector4ui b = new Vector4ui (5,6,7,8);
312 Vector4ui c = Vector4ui.UnpackLow (a, b);
325 public static int test_0_vector4ui_xor () {
326 Vector4ui a = new Vector4ui (1,2,3,4);
327 Vector4ui b = new Vector4ui (7,5,3,1);
342 public static int test_0_vector4ui_or () {
343 Vector4ui a = new Vector4ui (1,2,3,4);
344 Vector4ui b = new Vector4ui (7,5,3,1);
358 public static int test_0_vector4ui_and () {
359 Vector4ui a = new Vector4ui (1,2,3,4);
360 Vector4ui b = new Vector4ui (7,5,3,1);
375 public static int test_0_vector4ui_shr () {
376 Vector4ui a = new Vector4ui (0xF0000000u,20,3,40);
378 Vector4ui c = a >> 2;
380 if (c.X != 0x3C000000)
391 public static int test_0_vector4ui_shl () {
392 Vector4ui a = new Vector4ui (10,20,3,40);
394 Vector4ui c = a << 2;
407 public static int test_0_vector4ui_mul () {
408 Vector4ui a = new Vector4ui (0x8888,20,3,40);
409 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
413 if (c.X != 0xffff7800)
423 public static int test_0_vector4ui_sub () {
424 Vector4ui a = new Vector4ui (1,20,3,40);
425 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
440 public static int test_0_vector4ui_add () {
441 Vector4ui a = new Vector4ui (0xFF00FF00u,2,3,4);
442 Vector4ui b = new Vector4ui (0xFF00FF00u,2,3,4);
446 if (c.X != 0xfe01fe00)
458 static int test_0_vector4ui_accessors () {
459 Vector4ui a = new Vector4ui (1,2,3,4);
485 static int test_0_vector8us_sub_sat () {
486 Vector8us a = new Vector8us (0xF000,1,20,3,4,5,6,7);
487 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
488 Vector8us c = Vector8us.SubWithSaturation (a, b);
509 static int test_0_vector8us_add_sat () {
510 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
511 Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10);
512 Vector8us c = Vector8us.AddWithSaturation (a, b);
533 static int test_0_vector8us_unpack_low () {
534 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
535 Vector8us b = new Vector8us (3,4,5,6,7,8,9,10);
536 Vector8us c = Vector8us.UnpackLow (a, b);
558 static int test_0_vector8us_shift_left () {
559 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
561 Vector8us c = a << amt;
572 static int test_0_vector8us_shift_right_arithmetic () {
573 Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7);
575 Vector8us c = Vector8us.ShiftRightArithmetic (a, amt);
586 static int test_0_vector8us_shift_variable_offset () {
588 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
590 Vector8us c = b >> off;
607 static int test_0_vector8us_shift_operand_is_live_after_op () {
608 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
610 Vector8us c = b >> 2;
626 static int test_0_vector8us_shr_constant () {
627 Vector8us a = new Vector8us (0xF000,1,2,3,4,5,6,7);
628 Vector8us c = a >> 2;
639 static int test_0_vector8us_mul () {
640 Vector8us a = new Vector8us (0x0F00,4,5,6,7,8,9,10);
641 Vector8us b = new Vector8us (0x0888,1,2,3,4,5,6,8);
653 static int test_0_vector8us_add () {
654 Vector8us a = new Vector8us (0xFF00,4,5,6,7,8,9,10);
655 Vector8us b = new Vector8us (0x8888,1,2,3,4,5,6,8);
668 static int test_0_vector8us_sub () {
669 Vector8us a = new Vector8us (3,4,5,6,7,8,9,10);
670 Vector8us b = new Vector8us (10,1,2,3,4,5,6,8);
684 static int test_0_vector8us_accessors () {
685 Vector8us a = new Vector8us (0,1,2,3,4,5,6,7);
733 static int test_0_vector16b_unpack_high () {
734 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
735 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
736 Vector16b c = Vector16b.UnpackHigh (a, b);
757 static int test_0_vector16b_unpack_low () {
758 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
759 Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
760 Vector16b c = Vector16b.UnpackLow (a, b);
781 static int test_0_vector16b_sar () {
782 Vector16b a = new Vector16b (0xF0,20,3,40,0,0,0,0,0,0,0,0,0,0,0,0);
784 Vector16b c = Vector16b.ShiftRightArithmetic (a, 2);
796 static int test_0_vector16b_sub_sat () {
797 Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
798 Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
799 Vector16b c = Vector16b.SubWithSaturation (a, b);
810 static int test_0_vector16b_add_sat () {
811 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
812 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
813 Vector16b c = Vector16b.AddWithSaturation (a, b);
824 static int test_0_vector16b_add_ovf () {
825 Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
826 Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8);
838 static int test_0_vector16b_accessors () {
839 Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
926 public static int test_0_accessors () {
927 Vector4f a = new Vector4f (1, 2, 3, 4);
939 public static int test_0_packed_add_with_stack_tmp () {
940 Vector4f a = new Vector4f (1, 2, 3, 4);
941 Vector4f b = new Vector4f (5, 6, 7, 8);
942 Vector4f c = new Vector4f (-1, -3, -4, -5);
943 Vector4f d = a + b + c;
955 public static int test_0_simple_packed_add () {
956 Vector4f a = new Vector4f (1, 2, 3, 4);
957 Vector4f b = new Vector4f (5, 6, 7, 8);
971 public static int test_0_simple_packed_sub () {
972 Vector4f a = new Vector4f (1, 2, 3, 4);
973 Vector4f b = new Vector4f (5, 6, 7, 8);
986 public static int test_0_simple_packed_mul () {
987 Vector4f a = new Vector4f (1, 2, 3, 4);
988 Vector4f b = new Vector4f (5, 6, 7, 8);
1001 public static int test_0_simple_packed_div () {
1002 Vector4f a = new Vector4f (2, 2, 3, 4);
1003 Vector4f b = new Vector4f (20, 10, 33, 12);
1016 public static int test_0_simple_packed_sqrt () {
1017 Vector4f a = new Vector4f (16, 4, 9, 25);
1018 a = Vector4f.Sqrt (a);
1030 public static int test_0_simple_packed_invsqrt () {
1031 Vector4f a = new Vector4f (16, 4, 100, 25);
1032 //this function has VERY low precision
1033 a = Vector4f.InvSqrt (a);
1034 if (a.X < (1/4f - 0.01f) || a.X > (1/4f + 0.01f))
1036 if (a.Y < (1/2f - 0.01f) || a.Y > (1/2f + 0.01f))
1038 if (a.Z < (1/10f - 0.01f) || a.Z > (1/10f + 0.01f))
1040 if (a.W < (1/5f - 0.01f) || a.W > (1/5f + 0.01f))
1045 public static int test_0_simple_packed_min () {
1046 Vector4f a = new Vector4f (16, -4, 9, 25);
1047 Vector4f b = new Vector4f (5, 3, 9, 0);
1048 Vector4f c = Vector4f.Min (a, b);
1060 public static int test_0_simple_packed_max () {
1061 Vector4f a = new Vector4f (16, -4, 9, 25);
1062 Vector4f b = new Vector4f (5, 3, 9, 0);
1063 Vector4f c = Vector4f.Max (a, b);
1075 public static int test_0_simple_packed_hadd () {
1076 Vector4f a = new Vector4f (5, 5, 6, 6);
1077 Vector4f b = new Vector4f (7, 7, 8, 8);
1078 Vector4f c = Vector4f.HorizontalAdd (a, b);
1090 public static int test_0_simple_packed_hsub () {
1091 Vector4f a = new Vector4f (5, 2, 6, 1);
1092 Vector4f b = new Vector4f (7, 0, 8, 3);
1093 Vector4f c = Vector4f.HorizontalSub (a, b);
1105 public static int test_0_simple_packed_addsub () {
1106 Vector4f a = new Vector4f (5, 2, 6, 1);
1107 Vector4f b = new Vector4f (7, 0, 8, 3);
1108 Vector4f c = Vector4f.AddSub (a, b);
1120 public static int test_0_simple_packed_shuffle () {
1121 Vector4f a = new Vector4f (1, 2, 3, 4);
1122 a = Vector4f.Shuffle(a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1134 public static int test_0_packed_shuffle_with_reg_pressure () {
1135 Vector4f v = new Vector4f (1, 2, 3, 4);
1136 Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v;
1137 if (ff) v = v + v -v ;
1139 Vector4f r0 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1140 Vector4f r1 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1141 Vector4f x = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1142 Vector4f r2 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1143 Vector4f r3 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ);
1151 Vector4f result = r0 + r1 + r2 + r3;
1161 if (result.Y != result.Y)
1166 public static int test_24_regs_pressure_a () {
1167 Vector4f a = new Vector4f (1, 2, 3, 4);
1175 public static int test_54_regs_pressure_b () {
1176 Vector4f a = new Vector4f (1, 2, 3, 4);
1180 Vector4f e = a + b + c;
1181 Vector4f f = d - b + a - c;
1182 Vector4f g = a - d * f - c + b;
1183 Vector4f h = a * b - c + e;
1184 Vector4f i = h - g - f - e - d - c - b - a;
1185 Vector4f j = a + b + c + d + e + f + g + h + i;
1190 public static int test_3_single_block_var_is_properly_promoted () {
1191 Vector4f a = new Vector4f (4, 5, 6, 7);
1195 Vector4f b = new Vector4f (1, 2, 3, 4);
1206 static float float_val = 45f;
1208 public static int test_0_sse2_opt_and_simd_intrinsic_proper_regalloc () {
1209 Vector4f v = new Vector4f (1, 2, 3, 4);
1210 float f = float_val;
1219 public static int Main () {
1220 return TestDriver.RunTests (typeof (SimdTests));