2009-06-10 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / mini / basic-simd.cs
index 6c1c21b2fc148fb326a341e73c26076b245a6ef9..bed394fa7a3a0cf81a0b6cc37d6dba44c56fd9c0 100644 (file)
@@ -2,6 +2,312 @@ 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);
@@ -769,7 +1075,7 @@ 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);
 
@@ -783,7 +1089,7 @@ 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);
 
@@ -808,7 +1114,7 @@ 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);
 
@@ -833,7 +1139,7 @@ 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);