public static int test_0_accessor_and_byref_var() { Vector4f a = new Vector4f (1, 2, 3, 4); if (use_getter_with_byref (ref a) != 4) return 1; return 0; }
public static Vector4f Dp2Add(Vector4f a, Vector4f b, Vector4f c) { Vector4f res = a * b; //XX we could use HorizontalAdd here res = res + res.Shuffle (ShuffleSel.XFromY) + c; return res.Shuffle (ShuffleSel.ExpandX); }
public static float Dot (ref Vector4f vector1, ref Vector4f vector2) { Vector4f t = vector1 * vector2; t = t.HorizontalAdd (t); t = t.HorizontalAdd (t); return t.X; }
public Vector4f Sample(Vector4f coord) { int x = (int) (coord.X * tex.Width); int y = (int) (coord.Y * tex.Height); Vector4f color = tex.ReadColor (x, y); if (Tracing.Enabled) Console.WriteLine ("sampling {0} -> [{1}, {2}] -> {3}", coord, x, y, color); return color; }
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 Quaternion (float x, float y, float z, float w) { #if SIMD v4 = new Vector4f (x, y, z, w); #else this.x = x; this.y = y; this.z = z; this.w = w; #endif }
public Quaternion (Vector3 vectorPart, float scalarPart) { #if SIMD v4 = new Vector4f (vectorPart.X, vectorPart.Y, vectorPart.Z, scalarPart); #else x = vectorPart.X; y = vectorPart.Y; z = vectorPart.Z; w = scalarPart; #endif }
public static unsafe Vector4f AndNot (this Vector4f v1, Vector4f v2) { Vector4f res = new Vector4f (); int *a = (int*)&v1; int *b = (int*)&v2; int *c = (int*)&res; *c++ = ~*a++ & *b++; *c++ = ~*a++ & *b++; *c++ = ~*a++ & *b++; *c = ~*a & *b; return res; }
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); }
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; }
public static int test_0_accessors() { Vector4f a = new Vector4f (1, 2, 3, 4); if (a.X != 1f) return 1; if (a.Y != 2f) return 2; if (a.Z != 3f) return 3; if (a.W != 4f) return 4; return 0; }
private void ComputeFFT(float[] data, Vector2[] displacements, vector4[] forceAndHeight, int[][] indices, float[][] weights, float[] pingPongA, float[] pingPongB) { int resolutionx12 = pingPongA.Length; int index = 0; for (int y = resolution - 1; y >= 0; --y) { System.Array.Copy(data, index, pingPongA, 0, resolutionx12); FFT(indices, weights, ref pingPongA, ref pingPongB); System.Array.Copy(pingPongA, 0, data, index, resolutionx12); index += resolutionx12; } index = resolution * (resolution + 1) * 12; for (int x = resolution - 1; x >= 0; --x) { index -= 12; int index2 = index; for (int y = resolutionx12 - 12; y >= 0; y -= 12) { index2 -= resolutionx12; for (int i = 0; i < 12; ++i) { pingPongA[y + i] = data[index2 + i]; } } FFT(indices, weights, ref pingPongA, ref pingPongB); index2 = index / 12; for (int y = resolutionx12 - 12; y >= 0; y -= 12) { index2 -= resolution; forceAndHeight[index2] = new vector4(pingPongA[y], pingPongA[y + 2], pingPongA[y + 1], pingPongA[y + 7]); displacements[index2] = new Vector2(pingPongA[y + 8], pingPongA[y + 10]); } } }
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_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_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_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_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 int test_3_single_block_var_is_properly_promoted () { Vector4f a = new Vector4f (4, 5, 6, 7); if (ff) a = a - a; else { Vector4f b = new Vector4f (1, 2, 3, 4); Vector4f c = b; a = a - b; if (ff) { c = a; a = c; } } return (int)a.X; }
public static Vector4f InterleaveHigh(Vector4f v1, Vector4f v2) { return(new Vector4f(v1.z, v2.z, v1.w, v2.w)); }
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 void PrefetchNonTemporal(ref Vector4f res) { }
public static Vector4f InterleaveLow(Vector4f v1, Vector4f v2) { return(new Vector4f(v1.x, v2.x, v1.y, v2.y)); }
public static void PrefetchTemporal2ndLevelCache(ref Vector4f res) { }
public static void PrefetchTemporalAllCacheLevels(ref Vector4f res) { }
public static unsafe void StoreAligned(Vector4f *res, Vector4f val) { *res = val; }
public static void StoreAligned(ref Vector4f res, Vector4f val) { res = val; }
public static Vector4f HorizontalSub(Vector4f v1, Vector4f v2) { return(new Vector4f(v1.x - v1.y, v1.z - v1.w, v2.x - v2.y, v2.z - v2.w)); }
public static Vector4f DuplicateHigh(Vector4f v1) { return(new Vector4f(v1.y, v1.y, v1.w, v1.w)); }
public static Vector4f AddSub(Vector4f v1, Vector4f v2) { return(new Vector4f(v1.x - v2.x, v1.y + v2.y, v1.z - v2.z, v1.w + v2.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 Vector4f HorizontalAdd(Vector4f v1, Vector4f v2) { return(new Vector4f(v1.x + v1.y, v1.z + v1.w, v2.x + v2.y, v2.z + v2.w)); }
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; }
public static int test_0_accessor_vecto4f () { Vector4f a = new Vector4f (1,2,3,4); if (a.X != 1) return 1; if (a.Y != 2) return 2; if (a.Z != 3) return 3; if (a.W != 4) return 4; a.X = 128f; a.Y = 256f; a.Z = -0.5f; a.W = 0.125f; if (a.X != 128) return 5; if (a.Y != 256) return 6; if (a.Z != -0.5) return 7; if (a.W != 0.125) return 8; return 0; }
public static int test_0_sse2_opt_and_simd_intrinsic_proper_regalloc () { Vector4f v = new Vector4f (1, 2, 3, 4); float f = float_val; int x = (int)f; if (v.X != 1f) return 1; if (x != 45f) return 2; return 0; }
public static unsafe Vector4i ConvertToIntTruncated(this Vector4f v0) { return(new Vector4i((int)v0.X, (int)v0.Y, (int)v0.Z, (int)v0.W)); }
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 Vector4f Reciprocal(Vector4f v1) { return(new Vector4f(1.0f / v1.x, 1.0f / v1.y, 1.0f / v1.z, 1.0f / v1.w)); }
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; }
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; }
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_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_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 Vector4f LoadAligned(ref Vector4f v) { return(v); }
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; }
private void FFT(int[][] indices, float[][] weights, ref float[] pingPongA, ref float[] pingPongB) { int numButterflies = weights.Length; for (int butterflyIndex = 0; butterflyIndex < numButterflies; ++butterflyIndex) { var localIndices = indices[numButterflies - butterflyIndex - 1]; var localWeights = weights[butterflyIndex]; int i12 = (resolution - 1) * 12; for (int i2 = localIndices.Length - 2; i2 >= 0; i2 -= 2) { int ix = localIndices[i2]; int iy = localIndices[i2 + 1]; #if WATER_SIMD float wyf = localWeights[i2 + 1]; vector4 wx = new vector4(localWeights[i2]); vector4 wy = new vector4(wyf); pingPongB.SetVector(pingPongA.GetVector(ix) + wy * pingPongA.GetVector(iy + 4) + wx * pingPongA.GetVector(iy), i12); pingPongB.SetVector(pingPongA.GetVector(ix + 4) + wx * pingPongA.GetVector(iy + 4) - wy * pingPongA.GetVector(iy), i12 + 4); iy += 8; wy = new vector4(-wyf, wyf, -wyf, wyf); pingPongB.SetVector(pingPongA.GetVector(ix + 8) + wx * pingPongA.GetVector(iy) + wy * pingPongA.GetVector(iy).Shuffle(ShuffleSel.XFromY | ShuffleSel.YFromX | ShuffleSel.ZFromW | ShuffleSel.WFromZ), i12 + 8); i12 -= 12; #else float wx = localWeights[i2]; float wy = localWeights[i2 + 1]; int iy4 = iy + 4; pingPongB[i12++] = pingPongA[ix++] + wy * pingPongA[iy4++] + wx * pingPongA[iy++]; pingPongB[i12++] = pingPongA[ix++] + wy * pingPongA[iy4++] + wx * pingPongA[iy++]; pingPongB[i12++] = pingPongA[ix++] + wy * pingPongA[iy4++] + wx * pingPongA[iy++]; pingPongB[i12++] = pingPongA[ix++] + wy * pingPongA[iy4++] + wx * pingPongA[iy++]; iy4 = iy; iy -= 4; pingPongB[i12++] = pingPongA[ix++] + wx * pingPongA[iy4++] - wy * pingPongA[iy++]; pingPongB[i12++] = pingPongA[ix++] + wx * pingPongA[iy4++] - wy * pingPongA[iy++]; pingPongB[i12++] = pingPongA[ix++] + wx * pingPongA[iy4++] - wy * pingPongA[iy++]; pingPongB[i12++] = pingPongA[ix++] + wx * pingPongA[iy4++] - wy * pingPongA[iy++]; iy = iy4; pingPongB[i12++] = pingPongA[ix++] + wx * pingPongA[iy4++] - wy * pingPongA[iy + 1]; pingPongB[i12++] = pingPongA[ix++] + wx * pingPongA[iy4++] + wy * pingPongA[iy]; pingPongB[i12++] = pingPongA[ix++] + wx * pingPongA[iy4++] - wy * pingPongA[iy + 3]; pingPongB[i12] = pingPongA[ix] + wx * pingPongA[iy4] + wy * pingPongA[iy + 2]; i12 -= 23; //CpuSpectrumValue a1 = pingPongA[ix]; //CpuSpectrumValue b1 = pingPongA[iy]; //pingPongB[i].dx0 = a1.dx0 + wx * b1.dx0 - wy * b1.dx1; //pingPongB[i].dx1 = a1.dx1 + wy * b1.dx0 + wx * b1.dx1; //pingPongB[i].dy0 = a1.dy0 + wx * b1.dy0 - wy * b1.dy1; //pingPongB[i].dy1 = a1.dy1 + wy * b1.dy0 + wx * b1.dy1; //pingPongB[i].dz0 = a1.dz0 + wx * b1.dz0 - wy * b1.dz1; //pingPongB[i].dz1 = a1.dz1 + wy * b1.dz0 + wx * b1.dz1; //pingPongB[i].fx0 = a1.fx0 + wx * b1.fx0 - wy * b1.fx1; //pingPongB[i].fx1 = a1.fx1 + wy * b1.fx0 + wx * b1.fx1; //pingPongB[i].fy0 = a1.fy0 + wx * b1.fy0 - wy * b1.fy1; //pingPongB[i].fy1 = a1.fy1 + wy * b1.fy0 + wx * b1.fy1; //pingPongB[i].fz0 = a1.fz0 + wx * b1.fz0 - wy * b1.fz1; //pingPongB[i].fz1 = a1.fz1 + wy * b1.fz0 + wx * b1.fz1; #endif } var t = pingPongA; pingPongA = pingPongB; pingPongB = t; } }
public static unsafe Vector2d ConvertToDouble(this Vector4f v0) { return(new Vector2d(v0.X, v0.Y)); }
public static Vector4f DuplicateLow(Vector4f v1) { return(new Vector4f(v1.x, v1.x, v1.z, v1.z)); }
static float use_getter_with_byref (ref Vector4f a) { return a.W; }
public static unsafe Vector4i ConvertToInt(this Vector4f v0) { return(new Vector4i((int)System.Math.Round(v0.X), (int)System.Math.Round(v0.Y), (int)System.Math.Round(v0.Z), (int)System.Math.Round(v0.W))); }