X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmini%2Fbasic-simd.cs;h=f8fdcebaf9b220170a913328bda60bf8e77ead3b;hb=HEAD;hp=a38048ab2d9bc24d5b4f29aff703041bde19bcd5;hpb=c6c29ff831af59af70890bc776a77bce09646bb0;p=mono.git diff --git a/mono/mini/basic-simd.cs b/mono/mini/basic-simd.cs index a38048ab2d9..f8fdcebaf9b 100644 --- a/mono/mini/basic-simd.cs +++ b/mono/mini/basic-simd.cs @@ -2,6 +2,420 @@ using System; using Mono.Simd; public class SimdTests { + static int ddd; + static void InitByRef (out Vector4i v) { + v = new Vector4i (99); + if (ddd > 10) + throw new Exception ("ddd"); + } + + static int test_0_vector4i_one_element_ctor_with_byref () + { + Vector4i a; + InitByRef (out a); + if (a.X != 99) + return 1; + if (a.Y != 99) + return 2; + if (a.Z != 99) + return 3; + if (a.W != 99) + return 4; + return 0; + } + + static int test_0_vector2d_one_element_ctor () { + Vector2d a = new Vector2d (99); + if (a.X != 99) + return 1; + if (a.Y != 99) + return 2; + return 0; + } + + static int test_0_vector2ul_one_element_ctor () { + Vector2ul a = new Vector2ul (99); + + if (a.X != 99) + return 1; + if (a.Y != 99) + return 2; + return 0; + } + + static int test_0_vector2l_one_element_ctor () { + Vector2l a = new Vector2l (99); + + if (a.X != 99) + return 1; + if (a.Y != 99) + return 2; + return 0; + } + + static int test_0_vector4f_one_element_ctor () { + Vector4f a = new Vector4f (99); + + if (a.X != 99) + return 1; + if (a.Y != 99) + return 2; + if (a.Z != 99) + return 3; + if (a.W != 99) + return 4; + return 0; + } + + static int test_0_vector4ui_one_element_ctor () { + Vector4ui a = new Vector4ui (99); + + if (a.X != 99) + return 1; + if (a.Y != 99) + return 2; + if (a.Z != 99) + return 3; + if (a.W != 99) + return 4; + return 0; + } + + static int test_0_vector4i_one_element_ctor () { + Vector4i a = new Vector4i (99); + + if (a.X != 99) + return 1; + if (a.Y != 99) + return 2; + if (a.Z != 99) + return 3; + if (a.W != 99) + return 4; + return 0; + } + + static int test_0_vector8us_one_element_ctor () { + Vector8us a = new Vector8us (99); + + if (a.V0 != 99) + return 1; + if (a.V1 != 99) + return 2; + if (a.V2 != 99) + return 3; + if (a.V3 != 99) + return 4; + if (a.V4 != 99) + return 5; + if (a.V5 != 99) + return 6; + if (a.V6 != 99) + return 7; + if (a.V7 != 99) + return 8; + return 0; + } + + static int test_0_vector8s_one_element_ctor () { + Vector8s a = new Vector8s (99); + + if (a.V0 != 99) + return 1; + if (a.V1 != 99) + return 2; + if (a.V2 != 99) + return 3; + if (a.V3 != 99) + return 4; + if (a.V4 != 99) + return 5; + if (a.V5 != 99) + return 6; + if (a.V6 != 99) + return 7; + if (a.V7 != 99) + return 8; + return 0; + } + + static int test_0_vector16sb_one_element_ctor () { + Vector16sb a = new Vector16sb (99); + + if (a.V0 != 99) + return 1; + if (a.V1 != 99) + return 2; + if (a.V2 != 99) + return 3; + if (a.V3 != 99) + return 4; + if (a.V4 != 99) + return 5; + if (a.V5 != 99) + return 6; + if (a.V6 != 99) + return 7; + if (a.V7 != 99) + return 8; + if (a.V8 != 99) + return 9; + if (a.V9 != 99) + return 10; + if (a.V10 != 99) + return 11; + if (a.V11 != 99) + return 12; + if (a.V12 != 99) + return 13; + if (a.V13 != 99) + return 14; + if (a.V14 != 99) + return 15; + if (a.V15 != 99) + return 16; + return 0; + } + + static int test_0_vector16b_one_element_ctor () { + Vector16b a = new Vector16b (99); + + if (a.V0 != 99) + return 1; + if (a.V1 != 99) + return 2; + if (a.V2 != 99) + return 3; + if (a.V3 != 99) + return 4; + if (a.V4 != 99) + return 5; + if (a.V5 != 99) + return 6; + if (a.V6 != 99) + return 7; + if (a.V7 != 99) + return 8; + if (a.V8 != 99) + return 9; + if (a.V9 != 99) + return 10; + if (a.V10 != 99) + return 11; + if (a.V11 != 99) + return 12; + if (a.V12 != 99) + return 13; + if (a.V13 != 99) + return 14; + if (a.V14 != 99) + return 15; + if (a.V15 != 99) + return 16; + return 0; + } + + public static unsafe int test_0_sizeof_returns_16_2d () + { + double[] array = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + fixed (double *ptr = &array [0]) { + Vector2d *f = (Vector2d*)ptr; + Vector2d a = *f++; + Vector2d b = *f++; + Vector2d c = *f++; + Vector2d d = *f++; + + if (a.X != 1 || a.Y != 2) + return 1; + if (b.X != 3 || b.Y != 4) + return 2; + if (c.X != 5 || c.Y != 6) + return 3; + if (d.X != 7 || d.Y != 8) + return 4; + } + return 0; + } + + public static unsafe int test_0_sizeof_returns_16_4f () + { + float[] array = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; + fixed (float *ptr = &array [0]) { + Vector4f *f = (Vector4f*)ptr; + Vector4f a = *f++; + Vector4f b = *f++; + Vector4f c = *f++; + Vector4f d = *f++; + + if (a.X != 1 || a.W != 4) + return 1; + if (b.X != 5 || b.W != 8) + return 2; + if (c.X != 9 || c.W != 12) + return 3; + if (d.X != 13 || d.W != 16) + return 4; + } + return 0; + } + + public static unsafe int test_0_sizeof_returns_16_8d () + { + short[] array = new short[40]; + for (int i = 0; i < 40; ++i) + array [i] = (short) (i + 1); + + fixed (short *ptr = &array [0]) { + Vector8s *f = (Vector8s*)ptr; + Vector8s a = *f++; + Vector8s b = *f++; + Vector8s c = *f++; + Vector8s d = *f++; + + if (a.V0 != 1 || a.V7 != 8) + return 1; + if (b.V0 != 9 || b.V7 != 16) + return 2; + if (c.V0 != 17 || c.V7 != 24) + return 3; + if (d.V0 != 25 || d.V7 != 32) + return 4; + } + return 0; + } + + public static unsafe int test_0_sizeof_returns_16_16b () + { + byte[] array = new byte[80]; + for (int i = 0; i < 80; ++i) + array [i] = (byte) (i + 1); + + fixed (byte *ptr = &array [0]) { + Vector16b *f = (Vector16b*)ptr; + Vector16b a = *f++; + Vector16b b = *f++; + Vector16b c = *f++; + Vector16b d = *f++; + + if (a.V0 != 1 || a.V15 != 16) + return 1; + if (b.V0 != 17 || b.V15 != 32) + return 2; + if (c.V0 != 33 || c.V15 != 48) + return 3; + if (d.V0 != 49 || d.V15 != 64) + return 4; + } + return 0; + } + public static int test_0_bug_462457 () + { + Vector4f sum = new Vector4f(0,0,0,0); + Vector4f add = new Vector4f(1.0F,1.0F,1.0F,1.0F); + + for (int i = 0; i < 10; ++i) + sum = sum + add; + + if (sum.X != 10f) + return 1; + return 0; + } + + public static int test_0_vector16b_operator_neq () { + Vector16b a = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8); + Vector16b b = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8); + if (a != b) + return 1; + b.V0 = 99; + if (!(a != b)) + return 2; + return 0; + } + + public static int test_0_vector16b_operator_eq () { + Vector16b a = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8); + Vector16b b = new Vector16b(1,2,3,5,5,6,7,8,1,2,3,5,5,6,7,8); + if (!(a == b)) + return 1; + b.V0 = 99; + if (a == b) + return 2; + return 0; + } + + public static int test_0_vector8us_operator_neq () { + Vector8us a = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8); + Vector8us b = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8); + if (a != b) + return 1; + b.V0 = 99; + if (!(a != b)) + return 2; + return 0; + } + + public static int test_0_vector8us_operator_eq () { + Vector8us a = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8); + Vector8us b = new Vector8us(1, 2, 3, 4, 5, 6, 7, 8); + if (!(a == b)) + return 1; + b.V0 = 99; + if (a == b) + return 2; + return 0; + } + + public static int test_0_set_vector4f_operator_neq () { + Vector4f a = new Vector4f(1, 2, 3, 4); + Vector4f b = new Vector4f(1, 2, 3, 4); + if (a != b) + return 1; + + a = new Vector4f(1, 2, float.NaN, 4); + b = new Vector4f(1, 2, float.NaN, 4); + if (!(a != b)) //NaN is always != + return 2; + + a = new Vector4f(1, 2, float.NaN, 4); + b = new Vector4f(1, 2, 10, 4); + if (!(a != b)) + return 3; + + a = new Vector4f(1, 2, float.PositiveInfinity, 4); + b = new Vector4f(1, 2, float.PositiveInfinity, 4); + if (a != b) + return 4; + + a = new Vector4f(1, 2, 20, 4); + b = new Vector4f(1, 2, 30, 4); + if (!(a != b)) + return 5; + + return 0; + } + + public static int test_0_set_vector4f_operator_eq () { + Vector4f a = new Vector4f(1, 2, 3, 4); + Vector4f b = new Vector4f(1, 2, 3, 4); + if (!(a == b)) + return 1; + + a = new Vector4f(1, 2, float.NaN, 4); + b = new Vector4f(1, 2, float.NaN, 4); + if (a == b) + return 2; + + a = new Vector4f(1, 2, 10, 4); + b = new Vector4f(1, 2, float.NaN, 4); + if (a == b) + return 3; + + a = new Vector4f(1, 2, float.PositiveInfinity, 4); + b = new Vector4f(1, 2, float.PositiveInfinity, 4); + if (!(a == b)) + return 4; + return 0; + } public static int test_1_set_vector4ui_operator_neq () { Vector4ui a = new Vector4ui(1, 2, 3, 4); @@ -143,12 +557,12 @@ public class SimdTests { if (a.Y != 2) return 2; - a.X = 500000000000055l; - a.Y = -12345678900l; + a.X = 500000000000055L; + a.Y = -12345678900L; - if (a.X != 500000000000055l) + if (a.X != 500000000000055L) return 3; - if (a.Y != -12345678900l) + if (a.Y != -12345678900L) return 4; return 0; } @@ -281,7 +695,7 @@ public class SimdTests { Vector2l a = new Vector2l (10, 5); Vector2l b = new Vector2l (-1, 5); - Vector2l c = Vector2l.CompareGreaterThan (a, b); + Vector2l c = a.CompareGreaterThan (b); if (c.X != -1) return 1; @@ -294,7 +708,7 @@ public class SimdTests { Vector2l a = new Vector2l (0xFF, 5); Vector2l b = new Vector2l (0xFF000000FFL, 5); - Vector2l c = Vector2l.CompareEqual (a, b); + Vector2l c = a.CompareEqual (b); if (c.X != 0) return 1; @@ -306,7 +720,7 @@ public class SimdTests { public static unsafe int test_0_vector2l_srl () { Vector2l a = new Vector2l (1, 6); - Vector2l c = Vector2l.LogicalRightShift (a, 1); + Vector2l c = a.LogicalRightShift (1); if (c.X != 0) return 1; @@ -319,7 +733,7 @@ public class SimdTests { Vector2l a = new Vector2l (1, 6); Vector2l b = new Vector2l (3, 4); - Vector2l c = Vector2l.UnpackHigh (a, b); + Vector2l c = a.UnpackHigh (b); if (c.X != 6) return 1; @@ -332,7 +746,7 @@ public class SimdTests { Vector2l a = new Vector2l (1, 6); Vector2l b = new Vector2l (3, 4); - Vector2l c = Vector2l.UnpackLow (a, b); + Vector2l c = a.UnpackLow (b); if (c.X != 1) return 1; @@ -420,7 +834,7 @@ public class SimdTests { public static unsafe int test_0_vector2d_dup () { Vector2d a = new Vector2d (3, 2); - Vector2d c = Vector2d.Duplicate (a); + Vector2d c = a.Duplicate (); if (c.X != 3) return 1; @@ -433,7 +847,7 @@ public class SimdTests { Vector2d a = new Vector2d (3, 2); Vector2d b = new Vector2d (3, 4); - Vector4ui c = (Vector4ui)Vector2d.CompareEqual (a, b); + Vector4ui c = (Vector4ui)a.CompareEqual (b); if (c.X != 0xFFFFFFFF) return 1; @@ -450,7 +864,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (4, 5); - Vector2d c = Vector2d.InterleaveLow (a, b); + Vector2d c = a.InterleaveLow (b); if (c.X != 1) return 1; @@ -463,7 +877,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (4, 5); - Vector2d c = Vector2d.InterleaveHigh (a, b); + Vector2d c = a.InterleaveHigh (b); if (c.X != 2) return 1; @@ -475,7 +889,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (4, 1); - Vector2d c = Vector2d.AddSub (a, b); + Vector2d c = a.AddSub (b); if (c.X != -3) return 1; @@ -487,7 +901,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (4, 1); - Vector2d c = Vector2d.HorizontalSub (a, b); + Vector2d c = a.HorizontalSub (b); if (c.X != -1) return 1; @@ -500,7 +914,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (4, 0); - Vector2d c = Vector2d.HorizontalAdd (a, b); + Vector2d c = a.HorizontalAdd (b); if (c.X != 3) return 1; @@ -513,7 +927,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (4, 0); - Vector2d c = Vector2d.Min (a, b); + Vector2d c = a.Min (b); if (c.X != 1) return 1; @@ -526,7 +940,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (4, 0); - Vector2d c = Vector2d.Max (a, b); + Vector2d c = a.Max (b); if (c.X != 4) return 1; @@ -540,7 +954,7 @@ public class SimdTests { Vector2d a = new Vector2d (1, 2); Vector2d b = new Vector2d (3, 4); - Vector4ui c = (Vector4ui)Vector2d.AndNot (a, b); + Vector4ui c = (Vector4ui)a.AndNot (b); Vector4ui ta = (Vector4ui)a; Vector4ui tb = (Vector4ui)b; @@ -661,11 +1075,11 @@ public class SimdTests { return 0; } - public static unsafe int test_vector8s_pack_signed_sat () { + public static unsafe int test_0_vector8s_pack_signed_sat () { Vector8s a = new Vector8s (-200, 200, 3, 0, 5, 6, 5, 4); Vector8s b = new Vector8s (9, 2, 1, 2, 3, 6, 5, 6); - Vector16sb c = Vector8s.PackWithSignedSaturation (a, b); + Vector16sb c = a.PackWithSignedSaturation (b); if (c.V0 != -128) return 1; @@ -675,11 +1089,11 @@ public class SimdTests { return 0; } - public static unsafe int test_vector16sb_sub_sat () { + public static unsafe int test_0_vector16sb_sub_sat () { Vector16sb a = new Vector16sb (100,-100,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16sb b = new Vector16sb (-100, 100,11,12,4,5,6,7,8,9,10,11,12,13,14,15); - Vector16sb c = Vector16sb.SubtractWithSaturation (a, b); + Vector16sb c = a.SubtractWithSaturation (b); if (c.V0 != 127) return 1; @@ -700,11 +1114,11 @@ public class SimdTests { return 0; } - public static unsafe int test_vector16sb_add_sat () { + public static unsafe int test_0_vector16sb_add_sat () { Vector16sb a = new Vector16sb (100,-100,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16sb b = new Vector16sb (100, -100,11,12,4,5,6,7,8,9,10,11,12,13,14,15); - Vector16sb c = Vector16sb.AddWithSaturation (a, b); + Vector16sb c = a.AddWithSaturation (b); if (c.V0 != 127) return 1; @@ -725,11 +1139,11 @@ public class SimdTests { return 0; } - public static unsafe int test_vector16sb_cmp_gt () { + public static unsafe int test_0_vector16sb_cmp_gt () { Vector16sb a = new Vector16sb (100,-100,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16sb b = new Vector16sb (-100, 100,11,12,4,5,6,7,8,9,10,11,12,13,14,15); - Vector16sb c = Vector16sb.CompareGreaterThan (a, b); + Vector16sb c = a.CompareGreaterThan (b); if (c.V0 != -1) return 1; @@ -753,7 +1167,7 @@ public class SimdTests { Vector4ui a = new Vector4ui (0xF0000000,0xF0000,3,4); Vector4ui b = new Vector4ui (5,6,7,8); - Vector8us c = Vector4ui.SignedPackWithUnsignedSaturation (a, b); + Vector8us c = a.SignedPackWithUnsignedSaturation (b); if (c.V0 != 0) return 1; @@ -777,7 +1191,7 @@ public class SimdTests { public static int test_0_vector8us_pack_with_sat () { Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7); Vector8us b = new Vector8us (3,4,5,6,7,8,9,10); - Vector16b c = Vector8us.SignedPackWithUnsignedSaturation (a, b); + Vector16b c = a.SignedPackWithUnsignedSaturation (b); if (c.V0 != 0) return 1; @@ -795,7 +1209,7 @@ public class SimdTests { public static int test_0_vector8us_mul_high () { Vector8us a = new Vector8us (0xFF00, 2, 3, 0, 5, 6, 5, 4); Vector8us b = new Vector8us (0xFF00, 2, 1, 2, 3, 6, 5, 6); - Vector8us c = Vector8us.MultiplyStoreHigh (a, b); + Vector8us c = a.MultiplyStoreHigh (b); if (c.V0 != 0xFE01) return 1; @@ -819,7 +1233,7 @@ public class SimdTests { public static int test_0_vector8us_cmpeq () { Vector8us a = new Vector8us (1, 2, 3, 0, 5, 6, 5, 4); Vector8us b = new Vector8us (9, 2, 1, 2, 3, 6, 5, 6); - Vector8us c = Vector8us.CompareEqual (a, b); + Vector8us c = a.CompareEqual (b); if (c.V0 != 0) return 1; @@ -844,7 +1258,7 @@ public class SimdTests { public static int test_0_vector4ui_cmpeq () { Vector4ui a = new Vector4ui (6,1,6,3); Vector4ui b = new Vector4ui (3,4,6,7); - Vector4ui c = Vector4ui.CompareEqual (a, b); + Vector4ui c = a.CompareEqual (b); if (c.X != 0) return 1; @@ -859,7 +1273,7 @@ public class SimdTests { public static int test_0_vector4ui_shuffle () { Vector4ui a = new Vector4ui (1,2,3,4); - Vector4ui c = Vector4ui.Shuffle (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector4ui c = a.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); if (c.X != 2) return 1; @@ -875,7 +1289,7 @@ public class SimdTests { public static int test_0_vector4ui_min () { Vector4ui a = new Vector4ui (6,1,6,3); Vector4ui b = new Vector4ui (3,4,6,7); - Vector4ui c = Vector4ui.Min (a, b); + Vector4ui c = a.Min (b); if (c.X != 3) return 1; @@ -891,7 +1305,7 @@ public class SimdTests { public static int test_0_vector4ui_max () { Vector4ui a = new Vector4ui (6,1,6,3); Vector4ui b = new Vector4ui (3,4,6,7); - Vector4ui c = Vector4ui.Max (a, b); + Vector4ui c = a.Max (b); if (c.X != 6) return 1; @@ -907,7 +1321,7 @@ public class SimdTests { public static int vector16b_cmpeq () { Vector16b a = new Vector16b (1,0,9,0,0,0,0,0,0,0,0,0,0,0,0,1); Vector16b b = new Vector16b (0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0); - Vector16b c = Vector16b.CompareEqual (a, b); + Vector16b c = a.CompareEqual (b); if (c.V0 != 0) return 1; @@ -948,7 +1362,7 @@ public class SimdTests { public static int vector16b_sum_abs_diff () { Vector16b a = new Vector16b (100,20,20,20,0,0,0,0,0,0,0,0,0,0, 0, 0); Vector16sb b = new Vector16sb (0, 10,10,10,0,0,0,0,0,0,0,0,0,0,10,10); - Vector8us c = Vector16b.SumOfAbsoluteDifferences (a, b); + Vector8us c = a.SumOfAbsoluteDifferences (b); if (c.V0 != 130) return 1; @@ -972,7 +1386,7 @@ public class SimdTests { public static int test_0_vector16b_extract_mask () { Vector16b a = new Vector16b (0xF0,0,0xF0,0,0,0,0xF0,0xAA,0x0F,0,0xFF,0,0,0,0,0); - int c = Vector16b.ExtractByteMask (a); + int c = a.ExtractByteMask (); if (c != 0x4C5) return 1; @@ -982,7 +1396,7 @@ public class SimdTests { public static int test_0_vector16b_min () { Vector16b a = new Vector16b (0,12,20,12,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); - Vector16b c = Vector16b.Min (a, b); + Vector16b c = a.Min (b); if (c.V0 != 0) return 1; @@ -1022,7 +1436,7 @@ public class SimdTests { public static int test_0_vector16b_max () { Vector16b a = new Vector16b (0,12,20,12,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); - Vector16b c = Vector16b.Max (a, b); + Vector16b c = a.Max (b); if (c.V0 != 9) return 1; @@ -1061,7 +1475,7 @@ public class SimdTests { public static int test_0_vector16b_avg () { Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); - Vector16b c = Vector16b.Average (a, b); + Vector16b c = a.Average (b); if (c.V0 != 5) return 1; @@ -1149,7 +1563,7 @@ public class SimdTests { public static int test_0_vecto8us_shuffle_low () { Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8); - Vector8us c = Vector8us.ShuffleLow (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector8us c = a.ShuffleLow (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); if (c.V0 != 2) return 1; @@ -1172,7 +1586,7 @@ public class SimdTests { public static int test_0_vecto8us_shuffle_high () { Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8); - Vector8us c = Vector8us.ShuffleHigh (a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector8us c = a.ShuffleHigh (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); if (c.V0 != 1) return 1; @@ -1197,7 +1611,7 @@ public class SimdTests { public static int test_0_vecto8us_max () { Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8); Vector8us b = new Vector8us (9, 1, 1, 2, 9, 6, 5, 1000); - Vector8us c = Vector8us.Max (a, b); + Vector8us c = a.Max (b); if (c.V0 != 9) return 1; @@ -1222,7 +1636,7 @@ public class SimdTests { public static int test_0_vecto8us_min () { Vector8us a = new Vector8us (1, 2, 3, 0, 5, 6, 5, 4); Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6); - Vector8us c = Vector8us.Min (a, b); + Vector8us c = a.Min (b); if (c.V0 != 1) return 1; @@ -1246,7 +1660,7 @@ public class SimdTests { public static int test_0_vecto8us_avg () { Vector8us a = new Vector8us (1, 2, 3, 4, 5, 6, 7, 8); Vector8us b = new Vector8us (9, 1, 1, 2, 3, 4, 5, 6); - Vector8us c = Vector8us.Average (a, b); + Vector8us c = a.Average (b); if (c.V0 != 5) return 1; @@ -1294,7 +1708,7 @@ public class SimdTests { public static int test_0_vector4f_dup_high () { Vector4f a = new Vector4f (1, 2, 3, 4); - Vector4f c = Vector4f.DuplicateHigh(a); + Vector4f c = a.DuplicateHigh(); if (c.X != 2) return 1; @@ -1309,7 +1723,7 @@ public class SimdTests { public static int test_0_vector4f_dup_low () { Vector4f a = new Vector4f (1, 2, 3, 4); - Vector4f c = Vector4f.DuplicateLow (a); + Vector4f c = a.DuplicateLow (); if (c.X != 1) return 1; @@ -1326,7 +1740,7 @@ public class SimdTests { public static int test_0_vector4f_interleave_high () { Vector4f a = new Vector4f (1, 2, 3, 4); Vector4f b = new Vector4f (5, 6, 7, 8); - Vector4f c = Vector4f.InterleaveHigh (a, b); + Vector4f c = a.InterleaveHigh (b); if (c.X != 3) return 1; @@ -1342,7 +1756,7 @@ public class SimdTests { public static int test_0_vector4f_interleave_low () { Vector4f a = new Vector4f (1, 2, 3, 4); Vector4f b = new Vector4f (5, 6, 7, 8); - Vector4f c = Vector4f.InterleaveLow (a, b); + Vector4f c = a.InterleaveLow (b); if (c.X != 1) return 1; @@ -1357,7 +1771,7 @@ public class SimdTests { public static int test_0_vector4f_rcp () { Vector4f a = new Vector4f (1, 2, 4, 8); - Vector4f c = Vector4f.Reciprocal (a); + Vector4f c = a.Reciprocal (); //Test with ranges due to the terrible precision. if (c.X < (1 - 0.01f) || c.X > (1 + 0.01f)) @@ -1405,7 +1819,7 @@ public class SimdTests { public static int test_0_vector4f_andn () { Vector4f a = new Vector4f (1, 2, 3, 4); Vector4f b = new Vector4f (1, 3, 3, 8); - Vector4f c = Vector4f.AndNot (a ,b); + Vector4f c = a.AndNot (b); if (((Vector4ui)c).X != 0) return 1; @@ -1437,7 +1851,7 @@ public class SimdTests { public static int test_0_vector4f_cmpord () { Vector4f a = new Vector4f (float.NaN, 2, 3, 4); Vector4f b = new Vector4f (1, float.NaN, 3, 6); - Vector4f c = Vector4f.CompareOrdered (a, b); + Vector4f c = a.CompareOrdered (b); if (((Vector4ui)c).X != 0) return 1; @@ -1453,7 +1867,7 @@ public class SimdTests { public static int test_0_vector4f_cmpnle () { Vector4f a = new Vector4f (float.NaN, 2, 3, 4); Vector4f b = new Vector4f (1, float.NaN, 3, 6); - Vector4f c = Vector4f.CompareNotLessEqual (a, b); + Vector4f c = a.CompareNotLessEqual (b); if (((Vector4ui)c).X != 0xFFFFFFFF) return 1; @@ -1469,7 +1883,7 @@ public class SimdTests { public static int test_0_vector4f_cmpnlt () { Vector4f a = new Vector4f (float.NaN, 2, 3, 4); Vector4f b = new Vector4f (1, float.NaN, 3, 6); - Vector4f c = Vector4f.CompareNotLessThan (a, b); + Vector4f c = a.CompareNotLessThan (b); if (((Vector4ui)c).X != 0xFFFFFFFF) return 1; @@ -1485,7 +1899,7 @@ public class SimdTests { public static int test_0_vector4f_cmpneq () { Vector4f a = new Vector4f (float.NaN, 2, 3, 4); Vector4f b = new Vector4f (1, float.NaN, 3, 6); - Vector4f c = Vector4f.CompareNotEqual (a, b); + Vector4f c = a.CompareNotEqual (b); if (((Vector4ui)c).X != 0xFFFFFFFF) return 1; @@ -1501,7 +1915,7 @@ public class SimdTests { public static int test_0_vector4f_cmpunord () { Vector4f a = new Vector4f (float.NaN, 2, 3, 4); Vector4f b = new Vector4f (1, float.NaN, 3, 6); - Vector4f c = Vector4f.CompareUnordered (a, b); + Vector4f c = a.CompareUnordered (b); if (((Vector4ui)c).X != 0xFFFFFFFF) return 1; @@ -1517,7 +1931,7 @@ public class SimdTests { public static int test_0_vector4f_cmple () { Vector4f a = new Vector4f (float.NaN, 2, 3, 4); Vector4f b = new Vector4f (1, float.NaN, 3, 6); - Vector4f c = Vector4f.CompareLessEqual (a, b); + Vector4f c = a.CompareLessEqual (b); if (((Vector4ui)c).X != 0) return 1; @@ -1533,7 +1947,7 @@ public class SimdTests { public static int test_0_vector4f_cmplt () { Vector4f a = new Vector4f (float.NaN, 2, 3, 4); Vector4f b = new Vector4f (1, float.NaN, 3, 6); - Vector4f c = Vector4f.CompareLessThan (a, b); + Vector4f c = a.CompareLessThan (b); if (((Vector4ui)c).X != 0) return 1; @@ -1549,7 +1963,7 @@ public class SimdTests { public static int test_0_vector4f_cmpeq () { Vector4f a = new Vector4f (float.NaN, 2, 3, 6); Vector4f b = new Vector4f (1, float.NaN, 3, 4); - Vector4f c = Vector4f.CompareEqual (a, b); + Vector4f c = a.CompareEqual (b); if (((Vector4ui)c).X != 0) return 1; @@ -1565,7 +1979,7 @@ public class SimdTests { public static int test_0_vector4ui_sar () { Vector4ui a = new Vector4ui (0xF0000000u,20,3,40); - Vector4ui c = Vector4ui.ArithmeticRightShift (a, 2); + Vector4ui c = a.ArithmeticRightShift (2); if (c.X != 0xFC000000) return 1; @@ -1582,7 +1996,7 @@ public class SimdTests { Vector4ui a = new Vector4ui (1,2,3,4); Vector4ui b = new Vector4ui (5,6,7,8); - Vector4ui c = Vector4ui.UnpackHigh(a, b); + Vector4ui c = a.UnpackHigh(b); if (c.X != 3) return 1; @@ -1599,7 +2013,7 @@ public class SimdTests { Vector4ui a = new Vector4ui (1,2,3,4); Vector4ui b = new Vector4ui (5,6,7,8); - Vector4ui c = Vector4ui.UnpackLow (a, b); + Vector4ui c = a.UnpackLow (b); if (c.X != 1) return 1; @@ -1775,7 +2189,7 @@ public class SimdTests { static int test_0_vector8us_sub_sat () { Vector8us a = new Vector8us (0xF000,1,20,3,4,5,6,7); Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10); - Vector8us c = Vector8us.SubtractWithSaturation (a, b); + Vector8us c = a.SubtractWithSaturation (b); if (c.V0 != 0) return 1; @@ -1799,7 +2213,7 @@ public class SimdTests { static int test_0_vector8us_add_sat () { Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7); Vector8us b = new Vector8us (0xFF00,4,5,6,7,8,9,10); - Vector8us c = Vector8us.AddWithSaturation (a, b); + Vector8us c = a.AddWithSaturation (b); if (c.V0 != 0xFFFF) return 1; @@ -1823,7 +2237,7 @@ public class SimdTests { static int test_0_vector8us_unpack_low () { Vector8us a = new Vector8us (0,1,2,3,4,5,6,7); Vector8us b = new Vector8us (3,4,5,6,7,8,9,10); - Vector8us c = Vector8us.UnpackLow (a, b); + Vector8us c = a.UnpackLow (b); if (c.V0 != 0) return 1; @@ -1862,7 +2276,7 @@ public class SimdTests { static int test_0_vector8us_shift_right_arithmetic () { Vector8us a = new Vector8us (0xFF00,1,2,3,4,5,6,7); int amt = 2; - Vector8us c = Vector8us.ArithmeticRightShift (a, amt); + Vector8us c = a.ArithmeticRightShift (amt); if (c.V0 != 0xFFC0) return 1; @@ -2023,7 +2437,7 @@ public class SimdTests { static int test_0_vector16b_unpack_high () { Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); - Vector16b c = Vector16b.UnpackHigh (a, b); + Vector16b c = a.UnpackHigh (b); if (c.V0 != 8) return 1; @@ -2047,7 +2461,7 @@ public class SimdTests { static int test_0_vector16b_unpack_low () { Vector16b a = new Vector16b (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); - Vector16b c = Vector16b.UnpackLow (a, b); + Vector16b c = a.UnpackLow (b); if (c.V0 != 0) return 1; @@ -2071,7 +2485,7 @@ public class SimdTests { static int test_0_vector16b_sub_sat () { Vector16b a = new Vector16b (100,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); Vector16b b = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); - Vector16b c = Vector16b.SubtractWithSaturation (a, b); + Vector16b c = a.SubtractWithSaturation (b); if (c.V0 != 0) return 1; @@ -2085,7 +2499,7 @@ public class SimdTests { static int test_0_vector16b_add_sat () { Vector16b a = new Vector16b (200,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); Vector16b b = new Vector16b (200,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8); - Vector16b c = Vector16b.AddWithSaturation (a, b); + Vector16b c = a.AddWithSaturation (b); if (c.V0 != 255) return 1; @@ -2290,7 +2704,7 @@ public class SimdTests { public static int test_0_simple_packed_sqrt () { Vector4f a = new Vector4f (16, 4, 9, 25); - a = Vector4f.Sqrt (a); + a = a.Sqrt (); if (a.X != 4f) return 1; if (a.Y != 2f) @@ -2305,7 +2719,7 @@ public class SimdTests { public static int test_0_simple_packed_invsqrt () { Vector4f a = new Vector4f (16, 4, 100, 25); //this function has VERY low precision - a = Vector4f.InvSqrt (a); + a = a.InvSqrt (); if (a.X < (1/4f - 0.01f) || a.X > (1/4f + 0.01f)) return 1; if (a.Y < (1/2f - 0.01f) || a.Y > (1/2f + 0.01f)) @@ -2320,7 +2734,7 @@ public class SimdTests { public static int test_0_simple_packed_min () { Vector4f a = new Vector4f (16, -4, 9, 25); Vector4f b = new Vector4f (5, 3, 9, 0); - Vector4f c = Vector4f.Min (a, b); + Vector4f c = a.Min (b); if (c.X != 5f) return 1; if (c.Y != -4f) @@ -2335,7 +2749,7 @@ public class SimdTests { public static int test_0_simple_packed_max () { Vector4f a = new Vector4f (16, -4, 9, 25); Vector4f b = new Vector4f (5, 3, 9, 0); - Vector4f c = Vector4f.Max (a, b); + Vector4f c = a.Max (b); if (c.X != 16f) return 1; if (c.Y != 3f) @@ -2350,7 +2764,7 @@ public class SimdTests { public static int test_0_simple_packed_hadd () { Vector4f a = new Vector4f (5, 5, 6, 6); Vector4f b = new Vector4f (7, 7, 8, 8); - Vector4f c = Vector4f.HorizontalAdd (a, b); + Vector4f c = a.HorizontalAdd (b); if (c.X != 10f) return 1; if (c.Y != 12f) @@ -2365,7 +2779,7 @@ public class SimdTests { public static int test_0_simple_packed_hsub () { Vector4f a = new Vector4f (5, 2, 6, 1); Vector4f b = new Vector4f (7, 0, 8, 3); - Vector4f c = Vector4f.HorizontalSub (a, b); + Vector4f c = a.HorizontalSub (b); if (c.X != 3f) return 1; if (c.Y != 5f) @@ -2380,7 +2794,7 @@ public class SimdTests { public static int test_0_simple_packed_addsub () { Vector4f a = new Vector4f (5, 2, 6, 1); Vector4f b = new Vector4f (7, 0, 8, 3); - Vector4f c = Vector4f.AddSub (a, b); + Vector4f c = a.AddSub (b); if (c.X != -2f) return 1; if (c.Y != 2f) @@ -2394,7 +2808,7 @@ public class SimdTests { public static int test_0_simple_packed_shuffle () { Vector4f a = new Vector4f (1, 2, 3, 4); - a = Vector4f.Shuffle(a, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + a = a.Shuffle(ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); if (a.X != 2f) return 1; if (a.Y != 4f) @@ -2411,11 +2825,11 @@ public class SimdTests { Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v; if (ff) v = v + v -v ; - Vector4f r0 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); - Vector4f r1 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); - Vector4f x = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); - Vector4f r2 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); - Vector4f r3 = Vector4f.Shuffle (v, ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector4f r0 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector4f r1 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector4f x = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector4f r2 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); + Vector4f r3 = v.Shuffle (ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); Vector4f a = x; r0 = r0 * m0 + x; @@ -2438,6 +2852,16 @@ public class SimdTests { return 0; } + public static int test_0_double_packed_sqrt () { + Vector2d a = new Vector2d (16, 4); + a = a.Sqrt (); + if (a.X != 4f) + return 1; + if (a.Y != 2f) + return 2; + return 0; + } + public static int test_24_regs_pressure_a () { Vector4f a = new Vector4f (1, 2, 3, 4); Vector4f b = a + a; @@ -2461,6 +2885,152 @@ public class SimdTests { return (int)j.Z; } + public static int test_8_regs_pressure_c () { + Vector4f a = new Vector4f (1, 2, 3, 4); + Vector4f b = a + a; + Vector4f c = b - a; + Vector4f d = c - a; + Vector4f e = a + b + c; + Vector4f f = d - b + a - c; + Vector4f g = a - d * f - c + b; + Vector4f h = a * b - c + e; + Vector4f i = h - g - f - e - d - c - b - a; + Vector4f j = a + b + c + d + e + f + g + h + i; + Vector4f k = j - i - h + e + d - a + b - f + g; + Vector4f l = k * c - j * b - i * e + f - g; + Vector4f m = l - k + j - i + e + f; + Vector4f n = m - j + g - i + e * b + a * d; + Vector4f o = k + j + i * b; + Vector4f p = m + j + i + e + l; + Vector4f q = l * m + j + k; + Vector4f r = p * a + o * b + j * c + m * d + l * e; + Vector4f s = a - b - c - d - e - f - g - h - i - j - k - l - m - p - o - q - r; + Vector4f t = a + b + c + d + e + f + g + h + i + j + k + l + m + p + o + q + r + s; + return (int)t.W; + } + + public static int test_0_regs_pressure_fp_and_simd_share_bank_1 () { + Vector4f a = new Vector4f (4, 3, 2, 1); + float aF = 10f; + Vector4f b = a + a; + float bF = aF + aF; + Vector4f c = b - a; + float cF = bF - aF; + Vector4f d = c - a; + float dF = cF - aF; + Vector4f e = a + b + c; + float eF = aF + bF + cF; + Vector4f f = d - b + a - c; + float fF = dF - bF + aF - cF; + Vector4f g = a - d * f - c + b; + float gF = aF - dF * fF - cF + bF; + Vector4f h = a * b - c + e; + float hF = aF * bF - cF + eF; + Vector4f i = h - g - f - e - d - c - b - a; + float iF = hF - gF - fF - eF - dF - cF - bF - aF; + Vector4f j = a + b + c + d + e + f + g + h + i; + float jF = aF + bF + cF + dF + eF + fF + gF + hF + iF; + + if (j.X != 88f) + return 1; + + if(jF != 460f) + return 2; + + return 0; + } + + public static int test_0_regs_pressure_fp_and_simd_share_bank_2 () { + Vector4f a = new Vector4f (4, 3, 2, 1); + float aF = 10f; + Vector4f b = a + a; + float bF = aF + aF; + Vector4f c = b - a; + float cF = bF - aF; + Vector4f d = c - a; + float dF = cF - aF; + Vector4f e = a + b + c; + float eF = aF + bF + cF; + Vector4f f = d - b + a - c; + float fF = dF - bF + aF - cF; + Vector4f g = a - d * f - c + b; + float gF = aF - dF * fF - cF + bF; + Vector4f h = a * b - c + e; + float hF = aF * bF - cF + eF; + Vector4f i = h - g - f - e - d - c - b - a; + float iF = hF - gF - fF - eF - dF - cF - bF - aF; + Vector4f j = a + b + c + d + e + f + g + h + i; + float jF = aF + bF + cF + dF + eF + fF + gF + hF + iF; + Vector4f k = j - i - h + e + d - a + b - f + g; + float kF = jF - iF - hF + eF + dF - aF + bF - fF + gF; + Vector4f l = k * c - j * b - i * e + f - g; + float lF = kF * cF - jF * bF - iF * eF + fF - gF; + Vector4f m = l - k + j - i + e + f; + float mF = lF - kF + jF - iF + eF + fF; + Vector4f n = m - j + g - i + e * b + a * d; + float nF = mF - jF + gF - iF + eF * bF + aF * dF; + Vector4f o = k + j + i * b; + float oF = kF + jF + iF * bF; + Vector4f p = m + j + i + e + l; + float pF = mF + jF + iF + eF + lF; + Vector4f q = l * m + j + k; + float qF = lF * mF + jF + kF; + Vector4f r = p * a + o * b + j * c + m * d + l * e; + float rF = pF * aF + oF * bF + jF * cF + mF * dF + lF * eF; + Vector4f s = a - b - c - d - e - f - g - h - i - j - k - l - m - p - o - q - r; + float sF = aF - bF - cF - dF - eF - fF - gF - hF - iF - jF - kF - lF - mF - pF - oF - qF - rF; + Vector4f t = a + b + c + d + e + f + g + h + i + j + k + l + m + p + o + q + r + s; + float tF = aF + bF + cF + dF + eF + fF + gF + hF + iF + jF + kF + lF + mF + pF + oF + qF + rF + sF; + + if (t.X != 8f) + return 1; + + if(tF != 14f) + return 2; + + return 0; + } + + + public static void call_simd_fp () { + Vector4f a = new Vector4f (20f, 22f, 23f, 24f); + float b = 25f; + Vector4f c = new Vector4f (26f, 27f, 28f, 29f); + float d = 30f; + + b += d; + a += c; + } + public static int test_0_call_fp_and_simd_share_bank () { + + float a = 1f; + Vector4f b = new Vector4f (2f, 3f, 4f, 5f); + float c = 6f; + Vector4f d = new Vector4f (7f, 8f, 9f, 10f); + + a += c; + + b += d; + + call_simd_fp (); + if (a != 7f) + return 1; + if (b.X != 9f) + return 2; + if (c != 6f) + return 3; + if (d.X != 7f) + return 4; + if (b.W != 15f) + return 5; + if (d.W != 10f) + return 6; + + + return 0; + } + + static bool ff; public static int test_3_single_block_var_is_properly_promoted () { Vector4f a = new Vector4f (4, 5, 6, 7); @@ -2491,8 +3061,251 @@ public class SimdTests { return 0; } - public static int Main () { - return TestDriver.RunTests (typeof (SimdTests)); + public static int test_0_sse41_vector8s_min () { + Vector8s v = new Vector8s(2); + Vector8s v2 = new Vector8s(1); + v = v.Min(v2); + if (v.V0 != 1 || v.V1 != 1 || v.V2 != 1 || v.V3 != 1 || v.V4 != 1 || v.V5 != 1 || v.V6 != 1 || v.V7 != 1) + return 1; + return 0; + } + + public static int test_0_simd_const_indexer_simple () { + Vector4f v = new Vector4f (1, 2, 3, 4); + + if (v[0] != 1) + return 1; + if (v[1] != 2) + return 2; + if (v[2] != 3) + return 3; + if (v[3] != 4) + return 4; + return 0; + } + + public static int test_0_simd_var_indexer_simple () { + Vector4f v = new Vector4f (1, 2, 3, 4); + + int index = 0; + + if (v[index++] != 1) + return 1; + if (v[index++] != 2) + return 2; + if (v[index++] != 3) + return 3; + if (v[index] != 4) + return 4; + return 0; + } + + public static int test_0_simd_const_indexer_double () { + Vector2d v = new Vector2d (1, 2); + + if (v[0] != 1) + return 1; + if (v[1] != 2) + return 2; + return 0; + } + + public static int test_0_simd_var_indexer_double () { + Vector2d v = new Vector2d (1, 2); + + int index = 0; + + if (v[index++] != 1) + return 1; + if (v[index] != 2) + return 2; + return 0; + } + + + public static int test_0_scala_vector4f_mul () { + Vector4f a = new Vector4f (1, 2, 3, 4); + Vector4f b = 2 * a; + Vector4f c = a * 3; + + if (b.X != 2f || b.Y != 4f || b.Z != 6f || b.W != 8f ) + return 1; + if (c.X != 3f || c.Y != 6f || c.Z != 9f || c.W != 12f ) + return 1; + + return 0; + } + + static void CallMethodThatClobbersRegs () { + Vector4f a = new Vector4f (9,9,9,9); + Vector4f b = new Vector4f (9,9,9,9); + a = a + b; + } + + public static int test_0_call_spills_regs_correctly () { + Vector4f a = new Vector4f (1,2,3,4); + Vector4f b = new Vector4f (5,6,7,8); + + CallMethodThatClobbersRegs (); + + bool b0 = a.X == 1f; + bool b1 = b.X == 5f; + if (!b0 || !b1) + return 1; + return 0; + } + + public static int test_0_shuffle_with_two_args_pd () { + Vector2d a = new Vector2d (1,2); + Vector2d b = new Vector2d (5,6); + + Vector2d c = a.Shuffle (b, 0x2); + if (c.X != 1) + return 1; + if (c.Y != 6) + return 2; + return 0; + } + + public static int test_0_shuffle_with_two_args_ps () { + Vector4f a = new Vector4f (1, 2, 3, 4); + Vector4f b = new Vector4f (5, 6, 7, 8); + + Vector4f c = a.Shuffle (b, ShuffleSel.ExpandY); + if (c.X != 2) + return 1; + if (c.Y != 2) + return 2; + if (c.Z != 6) + return 3; + if (c.W != 6) + return 4; + return 0; + } + + public static int test_0_i_to_d () { + var a = new Vector4i (1, 2, 3, 4); + var b = a.ConvertToDouble (); + if (b.X != 1) + return 1; + if (b.Y != 2) + return 2; + return 0; + } + + public static int test_0_i_to_f () { + var a = new Vector4i (1, 2, 3, 4); + var b = a.ConvertToFloat (); + if (b.X != 1) + return 1; + if (b.Y != 2) + return 2; + if (b.Z != 3) + return 3; + if (b.W != 4) + return 4; + return 0; + } + + public static int test_0_d_to_i () { + var a = new Vector2d (1.4, 2.6); + var b = a.ConvertToInt (); + if (b.X != 1) + return 1; + if (b.Y != 3) + return 2; + if (b.Z != 0) + return 3; + if (b.W != 0) + return 4; + return 0; + } + + public static int test_0_d_to_f () { + var a = new Vector2d (1, 2); + var b = a.ConvertToFloat (); + if (b.X != 1) + return 1; + if (b.Y != 2) + return 2; + if (b.Z != 0) + return 3; + if (b.W != 0) + return 4; + return 0; + } + + public static int test_0_f_to_i () { + var a = new Vector4f (1.1f, 2.2f, 3.5f, 4.6f); + var b = a.ConvertToInt (); + if (b.X != 1) + return 1; + if (b.Y != 2) + return 2; + if (b.Z != 4) + return 3; + if (b.W != 5) + return 4; + return 0; + } + + public static int test_0_f_to_d () { + var a = new Vector4f (1,2,3,4); + var b = a.ConvertToDouble (); + if (b.X != 1) + return 1; + if (b.Y != 2) + return 2; + return 0; + } + + public static int test_0_d_to_i_trunc () { + var a = new Vector2d (1.4, 2.6); + var b = a.ConvertToIntTruncated (); + if (b.X != 1) + return 1; + if (b.Y != 2) + return 2; + if (b.Z != 0) + return 3; + if (b.W != 0) + return 4; + return 0; + } + + public static int test_0_f_to_i_trunc () { + var a = new Vector4f (1.1f, 2.2f, 3.5f, 4.6f); + var b = a.ConvertToIntTruncated (); + if (b.X != 1) + return 1; + if (b.Y != 2) + return 2; + if (b.Z != 3) + return 3; + if (b.W != 4) + return 4; + return 0; + } + + class BoxedVector2d + { + public Vector2d v; + } + + public static int test_0_vector2d_set_x () { + var bv = new BoxedVector2d (); + var xy = new Vector2d (); + xy.X = bv.v.X; + + if (xy.X != 0) + return 1; + if (xy.Y != 0) + return 2; + return 0; + } + + public static int Main (String[] args) { + return TestDriver.RunTests (typeof (SimdTests), args); } }