Beispiel #1
0
        public void SimdTest()
        {
            Bounds bounds = new Bounds(new Vector3(1, 1, 1), new Vector3(3, 3, 3));
            const int positionX = 4;
            const int positionZ = 3;

            // Non-SIMD version
            Vector3Int bMin;
            Vector3Int bMax;
            Vector3Int myVec52 = new Vector3Int(Chunk.Vec5.X, Chunk.Vec5.X, Chunk.Vec5.X);
            {
                Vector3Int pom = new Vector3Int(positionX * EngineSettings.ChunkConfig.SizeX, 0, positionZ * EngineSettings.ChunkConfig.SizeZ);

                int minX = Mathf.Clamp(Mathf.FloorToInt(bounds.min.x) - pom.X - myVec52.X, 0, EngineSettings.ChunkConfig.MaskX);
                int minY = Mathf.Clamp(Mathf.FloorToInt(bounds.min.y) - myVec52.Y, 0, EngineSettings.ChunkConfig.SizeYTotal - 1);
                int minZ = Mathf.Clamp(Mathf.FloorToInt(bounds.min.z) - pom.Z - myVec52.Z, 0, EngineSettings.ChunkConfig.MaskZ);
                bMin = new Vector3Int(minX, minY, minZ);

                int maxX = Mathf.Clamp(Mathf.Clamp(bMin.X, 0, EngineSettings.ChunkConfig.MaskX), 0, EngineSettings.ChunkConfig.MaskX);
                int maxY = Mathf.Clamp(Mathf.Clamp(bMin.Y, 0, EngineSettings.ChunkConfig.SizeYTotal - 1), 0, EngineSettings.ChunkConfig.SizeYTotal-1);
                int maxZ = Mathf.Clamp(Mathf.Clamp(bMin.Z, 0, EngineSettings.ChunkConfig.MaskZ), 0, EngineSettings.ChunkConfig.MaskZ);
                bMax = new Vector3Int(maxX, maxY, maxZ);
            }

            // SIMD version
            Vector4i bMinv;
            Vector4i bMaxv;
            {
                Vector4f bMinf = new Vector4f(bounds.min.x, bounds.min.y, bounds.min.z, 0f);
                bMinv = bMinf.ConvertToIntTruncated();
                Vector4f bMaxf = new Vector4f(bounds.max.x, bounds.max.y, bounds.max.z, 0f);
                bMaxv = bMaxf.ConvertToInt();

                Vector4i pom = new Vector4i(positionX, 0, positionZ, 0)*Chunk.VecSize;
                bMinv -= pom;
                bMinv -= Chunk.Vec5;
                bMinv = bMinv.Max(Vector4i.Zero).Min(Chunk.VecSize1);
                    // Clamp to 0..size (x,z) or 0..height (y) respectively

                bMaxv -= pom;
                bMaxv += Chunk.Vec5;
                bMaxv = bMaxv.Max(Vector4i.Zero).Min(Chunk.VecSize1);
                    // Clamp to 0..size (x,z) or 0..height (y) respectively
            }

            Assert.AreEqual(bMin.X, bMinv.X);
            Assert.AreEqual(bMin.Y, bMinv.Y);
            Assert.AreEqual(bMin.Z, bMinv.Z);

            Assert.AreEqual(bMax.X, bMaxv.X);
            Assert.AreEqual(bMax.Y, bMaxv.Y);
            Assert.AreEqual(bMax.Z, bMaxv.Z);
        }
Beispiel #2
0
		public static Vector4i CompareEqual (this Vector4i v1, Vector4i v2)
		{
			return new Vector4i ((int)(v1.x ==  v2.x ? -1 : 0), (int)(v1.y ==  v2.y ? -1 : 0), (int)(v1.z ==  v2.z ? -1 : 0), (int)(v1.w ==  v2.w ? -1 : 0));
		}
Beispiel #3
0
		public static unsafe Vector8s PackWithSignedSaturation (this Vector4i va, Vector4i vb) {
			Vector8s res = new Vector8s ();
			int *a = (int*)&va;
			int *b = (int*)&vb;
			short *c = (short*)&res;
			for (int i = 0; i < 4; ++i)
				*c++ = (short)System.Math.Max (System.Math.Min ((int)*a++, short.MaxValue), short.MinValue);
			for (int i = 0; i < 4; ++i)
				*c++ = (short)System.Math.Max (System.Math.Min ((int)*b++, short.MaxValue), short.MinValue);
			return res;
		}
Beispiel #4
0
		public static unsafe void PrefetchNonTemporal (Vector4i *res)
		{
		}
Beispiel #5
0
		public static unsafe void PrefetchTemporalAllCacheLevels (Vector4i *res)
		{
		}
Beispiel #6
0
		public static void PrefetchTemporal2ndLevelCache (ref Vector4i res)
		{
		}
Beispiel #7
0
		public static unsafe void StoreAligned (Vector4i *res, Vector4i val)
		{
			*res = val;
		}
Beispiel #8
0
 public static unsafe Vector2d ConvertToDouble(this Vector4i v0)
 {
     return(new Vector2d(v0.X, v0.Y));
 }
Beispiel #9
0
 public static Vector4i LoadAligned(ref Vector4i v)
 {
     return(v);
 }
Beispiel #10
0
 public static Vector4i CompareGreaterThan(Vector4i v1, Vector4i v2)
 {
     return(new Vector4i((int)(v1.x > v2.x ? -1 : 0), (int)(v1.y > v2.y ? -1 : 0), (int)(v1.z > v2.z ? -1 : 0), (int)(v1.w > v2.w ? -1 : 0)));
 }
Beispiel #11
0
 public static Vector4i CompareEqual(Vector4i v1, Vector4i v2)
 {
     return(new Vector4i((int)(v1.x == v2.x ? -1 : 0), (int)(v1.y == v2.y ? -1 : 0), (int)(v1.z == v2.z ? -1 : 0), (int)(v1.w == v2.w ? -1 : 0)));
 }
Beispiel #12
0
 public static Vector4i Min(Vector4i v1, Vector4i v2)
 {
     return(new Vector4i(System.Math.Min(v1.x, v2.x), System.Math.Min(v1.y, v2.y), System.Math.Min(v1.z, v2.z), System.Math.Min(v1.w, v2.w)));
 }
Beispiel #13
0
 public static Vector4i UnpackHigh(Vector4i v1, Vector4i v2)
 {
     return(new Vector4i(v1.z, v2.z, v1.w, v2.w));
 }
Beispiel #14
0
 public static Vector4i UnpackLow(Vector4i v1, Vector4i v2)
 {
     return(new Vector4i(v1.x, v2.x, v1.y, v2.y));
 }
Beispiel #15
0
		public static Vector4i UnpackLow (this Vector4i v1, Vector4i v2)
		{
			return new Vector4i (v1.x, v2.x, v1.y, v2.y);
		}
Beispiel #16
0
		public static unsafe Vector4i LogicalRightShift (this Vector4i v1, int amount)
		{
			Vector4i res = new Vector4i ();
			int *a = &v1.x;
			int *b = &res.x;
			for (int i = 0; i < 4; ++i)
				*b++ = (int)((uint)(*a++) >> amount);
			return res;
		}
Beispiel #17
0
 public static void StoreAligned(ref Vector4i res, Vector4i val)
 {
     res = val;
 }
Beispiel #18
0
		public static unsafe Vector4i LoadAligned (Vector4i *v)
		{
			return *v;
		}
Beispiel #19
0
 public static unsafe void StoreAligned(Vector4i *res, Vector4i val)
 {
     *res = val;
 }
Beispiel #20
0
		public static void PrefetchTemporalAllCacheLevels (ref Vector4i res)
		{
		}
Beispiel #21
0
 public static void PrefetchTemporalAllCacheLevels(ref Vector4i res)
 {
 }
Beispiel #22
0
		public static void PrefetchNonTemporal (ref Vector4i res)
		{
		}
Beispiel #23
0
 public static void PrefetchTemporal2ndLevelCache(ref Vector4i res)
 {
 }
Beispiel #24
0
		public static unsafe void PrefetchTemporal2ndLevelCache (Vector4i *res)
		{
		}
Beispiel #25
0
 public static void PrefetchNonTemporal(ref Vector4i res)
 {
 }
Beispiel #26
0
		public static unsafe Vector8us PackWithUnsignedSaturation (this Vector4i va, Vector4i vb) {
			Vector8us res = new Vector8us ();
			int *a = (int*)&va;
			int *b = (int*)&vb;
			ushort *c = (ushort*)&res;
			for (int i = 0; i < 4; ++i)
				*c++ = (ushort)System.Math.Max (0, System.Math.Min (*a++, ushort.MaxValue));
			for (int i = 0; i < 4; ++i)
				*c++ = (ushort)System.Math.Max (0, System.Math.Min (*b++, ushort.MaxValue));
			return res;
		}
Beispiel #27
0
		public static unsafe int ExtractByteMask (Vector4i va) {
			int res = 0;
			byte *a = (byte*)&va;
			for (int i = 0; i < 16; ++i)
				res |= (*a++ & 0x80) >> 7 << i;
			return res;
		}
Beispiel #28
0
		public static Vector4i Min (this Vector4i v1, Vector4i v2)
		{
			return new Vector4i (System.Math.Min (v1.x, v2.x), System.Math.Min (v1.y, v2.y), System.Math.Min (v1.z, v2.z), System.Math.Min (v1.w, v2.w));
		}
Beispiel #29
0
		public static unsafe Vector4i Shuffle (Vector4i v1, ShuffleSel sel)
		{
			int *ptr = (int*)&v1;
			int idx = (int)sel;
			return new Vector4i (*(ptr + ((idx >> 0) & 0x3)),*(ptr + ((idx >> 2) & 0x3)),*(ptr + ((idx >> 4) & 0x3)),*(ptr + ((idx >> 6) & 0x3)));
		}
Beispiel #30
0
		public static Vector4i CompareGreaterThan (this Vector4i v1, Vector4i v2)
		{
			return new Vector4i ((int)(v1.x > v2.x ? -1 : 0), (int)(v1.y >  v2.y ? -1 : 0), (int)(v1.z >  v2.z ? -1 : 0), (int)(v1.w >  v2.w ? -1 : 0));
		}
Beispiel #31
0
		public static Vector4i LoadAligned (ref Vector4i v)
		{
			return v;
		}
Beispiel #32
0
		public static Vector4i UnpackHigh (this Vector4i v1, Vector4i v2)
		{
			return new Vector4i (v1.z, v2.z, v1.w, v2.w);
		}
Beispiel #33
0
		public static void StoreAligned (ref Vector4i res, Vector4i val)
		{
			res = val;
		}
Beispiel #34
0
		public static unsafe Vector4i Shuffle (this Vector4i v1, Vector4i v2, ShuffleSel sel)
		{
			int *p1 = (int*)&v1;
			int *p2 = (int*)&v2;
			int idx = (int)sel;
			return new Vector4i (*(p1 + ((idx >> 0) & 0x3)), *(p1 + ((idx >> 2) & 0x3)), *(p2 + ((idx >> 4) & 0x3)), *(p2 + ((idx >> 6) & 0x3))); 
		}
Beispiel #35
0
 public static unsafe Vector4f ConvertToFloat(this Vector4i v0)
 {
     return(new Vector4f(v0.X, v0.Y, v0.Z, v0.W));
 }