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_packed_shuffle_with_reg_pressure () { Vector4f v = new Vector4f (1, 2, 3, 4); Vector4f m0 = v + v, m1 = v - v, m2 = v * v, m3 = v + v + v; if (ff) v = v + v -v ; 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; r1 = r1 * m1 + x; x = x - v + v; r2 = r2 * m2 + x; r3 = r3 * m3 + x; Vector4f result = r0 + r1 + r2 + r3; if (a.X != 2f) return 1; if (a.Y != 4f) return 2; if (a.Z != 1f) return 3; if (a.W != 3f) return 4; if (result.Y != result.Y) return 0; return 0; }
public static int test_0_simple_packed_shuffle () { Vector4f a = new Vector4f (1, 2, 3, 4); a = a.Shuffle(ShuffleSel.XFromY | ShuffleSel.YFromW | ShuffleSel.ZFromX | ShuffleSel.WFromZ); if (a.X != 2f) return 1; if (a.Y != 4f) return 2; if (a.Z != 1f) return 3; if (a.W != 3f) return 4; return 0; }
public static void Cross (ref Vector4f a, ref Vector4f b, out Vector4f result) { result = (a * b.Shuffle ((ShuffleSel)0xc9) - b * a.Shuffle ((ShuffleSel)0xc9)).Shuffle ((ShuffleSel)0xc9); }
public void Visit(TernaryOp ins) { Vector4f a = ctx.ReadValue (ins.Source1); Vector4f b = ctx.ReadValue (ins.Source2); Vector4f c = ctx.ReadValue (ins.Source3); Vector4f res = new Vector4f (); switch (ins.Operation) { case TernaryOpKind.Cmp: {// a >= 0 ? b : c //m = a < [0,0,0,0] Vector4f mask = a.CompareLessThan (new Vector4f ()); //we change to a <b //res = (m & C) | (~m & B) -- this could be replaced by a blendps res = (mask & c) | mask.AndNot (b); break; } case TernaryOpKind.Mad: {// a * b + c res = (a * b) + c; break; } case TernaryOpKind.SinCos: { // sin(a) , cos(a) //XXX maybe we should use the macro expansion provided in the driver docs for HLSL res.X = (float)Math.Cos (a.X); res.Y = (float)Math.Sin (a.X); break; } case TernaryOpKind.Lrp: //c + a * (b - c) //res = c + (a * (b - c)); res = a * b + (Vector4f.One - a) * c; break; case TernaryOpKind.Dp2Add: //res = a.r * b.r + a.g * b.g + c.swizzle res = a * b; //XX we could use Hadd here res = res + res.Shuffle (ShuffleSel.XFromY) + c; res = res.Shuffle (ShuffleSel.ExpandX); break; default: throw new Exception ("Cant handle " + ins.Operation); } if (Tracing.Enabled) Console.WriteLine ("{0} {1} {2} {3} => {4}/{5}/{6} == {7}", ins.Source1, ins.Operation, ins.Source2, ins.Source3, a, b, c, res); ctx.StoreValue (ins.Dest, res); }
public void Visit(BinaryOp ins) { Vector4f a = ctx.ReadValue (ins.Source1); Vector4f b = ctx.ReadValue (ins.Source2); Vector4f res = new Vector4f (); switch (ins.Operation) { case BinOpKind.Add: res = a + b; break; case BinOpKind.Sub: res = a - b; break; case BinOpKind.Mul: res = a * b; break; case BinOpKind.Max: res = a.Max (b); break; case BinOpKind.Dp3: //res = dp3 res = a * b; res = res + res.Shuffle (ShuffleSel.XFromY) + res.Shuffle (ShuffleSel.XFromZ); res = res.Shuffle (ShuffleSel.ExpandX); break; case BinOpKind.Dp4: //res = dp4 res = a * b; res = res + res.Shuffle (ShuffleSel.XFromY | ShuffleSel.ZFromW); //[x + y, _, w + z, _ res = res + res.Shuffle (ShuffleSel.XFromZ); //[x + y + w + z, ??] res = res.Shuffle (ShuffleSel.ExpandX); break; case BinOpKind.Min: res = a.Min (b); break; case BinOpKind.Slt: res = a.CompareLessThan (b) & new Vector4f (1); break; case BinOpKind.Sge: /*SSE doesn't have >=, so we use < and invert the operands*/ res = b.CompareLessThan (a) & new Vector4f (1); break; default: throw new Exception ("Cant handle " + ins.Operation); } if (Tracing.Enabled) Console.WriteLine ("{0} {1} {2} => {3}/{4} == {5}", ins.Source1, ins.Operation, ins.Source2, a, b, res); ctx.StoreValue (ins.Dest, res); }