public static Vector4D Normalize4D_Software(Vector4DParam1_3 vector) { // No software fallback needed, these methods cover it Vector4D magnitude = Length4D_Software(vector); return(Divide_Software(vector, magnitude)); }
public static Vector4D CrossProduct4D_Software(Vector4DParam1_3 one, Vector4DParam1_3 two, Vector4DParam1_3 three) { return(Vector256.Create( (two.GetElement(2) * three.GetElement(3) - two.GetElement(3) * three.GetElement(2)) * one.GetElement(1) - (two.GetElement(1) * three.GetElement(3) - two.GetElement(3) * three.GetElement(1)) * one.GetElement(2) + (two.GetElement(1) * three.GetElement(2) - two.GetElement(2) * three.GetElement(1)) * one.GetElement(3), (two.GetElement(3) * three.GetElement(2) - two.GetElement(2) * three.GetElement(3)) * one.GetElement(0) - (two.GetElement(3) * three.GetElement(0) - two.GetElement(0) * three.GetElement(3)) * one.GetElement(2) + (two.GetElement(2) * three.GetElement(0) - two.GetElement(0) * three.GetElement(2)) * one.GetElement(3), (two.GetElement(1) * three.GetElement(3) - two.GetElement(3) * three.GetElement(1)) * one.GetElement(0) - (two.GetElement(0) * three.GetElement(3) - two.GetElement(3) * three.GetElement(0)) * one.GetElement(1) + (two.GetElement(0) * three.GetElement(1) - two.GetElement(1) * three.GetElement(0)) * one.GetElement(3), (two.GetElement(2) * three.GetElement(1) - two.GetElement(1) * three.GetElement(2)) * one.GetElement(0) - (two.GetElement(2) * three.GetElement(0) - two.GetElement(0) * three.GetElement(2)) * one.GetElement(1) + (two.GetElement(1) * three.GetElement(0) - two.GetElement(0) * three.GetElement(1)) * one.GetElement(2) )); }
public static Vector4D DotProduct2D_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { return(Vector256.Create( Helpers.X(left) * Helpers.X(right) + +Helpers.Y(left) * Helpers.Y(right) )); }
public static Vector256 <double> FusedMultiplyAdd(Vector4DParam1_3 x, Vector4DParam1_3 y, Vector4DParam1_3 z) { if (Fma.IsSupported) { return(Fma.MultiplyAdd(x, y, z)); } return(SoftwareFallback(x, y, z));
public static Vector4D GreaterThan_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { return(Vector256.Create( BoolToSimdBoolDouble(X(left) > X(right)), BoolToSimdBoolDouble(Y(left) > Y(right)), BoolToSimdBoolDouble(Z(left) > Z(right)), BoolToSimdBoolDouble(W(left) > W(right)) )); }
public static Vector4D Inequality_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { return(Vector256.Create( BoolToSimdBoolDouble(X(left) != X(right)), BoolToSimdBoolDouble(Y(left) != Y(right)), BoolToSimdBoolDouble(Z(left) != Z(right)), BoolToSimdBoolDouble(W(left) != W(right)) )); }
public static Vector256 <double> Shuffle(Vector4DParam1_3 left, Vector4DParam1_3 right, byte control) { if (Avx.IsSupported) { return(Avx.Shuffle(left, right, control)); } return(Shuffle_Software(left, right, control)); }
public static Vector4D LessThanOrEqual_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { return(Vector256.Create( BoolToSimdBoolDouble(X(left) <= X(right)), BoolToSimdBoolDouble(Y(left) <= Y(right)), BoolToSimdBoolDouble(Z(left) <= Z(right)), BoolToSimdBoolDouble(W(left) <= W(right)) )); }
static Vector256 <double> SoftwareFallback(Vector4DParam1_3 vector) { return(Vector256.Create( Math.Sin(X(vector)), Math.Sin(Y(vector)), Math.Sin(Z(vector)), Math.Sin(W(vector)) )); }
static Vector256 <double> SoftwareFallback(Vector4DParam1_3 x, Vector4DParam1_3 y, Vector4DParam1_3 z) { return(Vector256.Create( Math.FusedMultiplyAdd(X(x), X(y), X(z)), Math.FusedMultiplyAdd(Y(x), Y(y), Y(z)), Math.FusedMultiplyAdd(Z(x), Z(y), Z(z)), Math.FusedMultiplyAdd(W(x), W(y), W(z)) )); }
public static Vector256 <double> Permute(Vector4DParam1_3 vector, byte control) { if (Avx.IsSupported) { return(Avx.Permute(vector, control)); } return(Shuffle(vector, vector, control)); }
public static Vector256 <double> Shuffle(Vector4DParam1_3 left, Vector4DParam1_3 right, byte control) { //There is a way to do Permute4x64 with a few AVX instructions but haven't figured it out yet //if (Avx.IsSupported) //{ // return Avx.Shuffle(left, right, control); //} return(Shuffle_Software(left, right, control)); }
public static Vector256 <double> CompareEqual_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { double lX = X(left), rX = X(right); double lY = Y(left), rY = Y(right); double lZ = Z(left), rZ = Z(right); double lW = W(left), rW = W(right); return(Vector256.Create( BoolToSimdBoolDouble(lX == rX), BoolToSimdBoolDouble(lY == rY), BoolToSimdBoolDouble(lZ == rZ), BoolToSimdBoolDouble(lW == rW) )); }
public static Vector256 <double> CompareGreaterThanOrEqual_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { double lX = X(left), rX = X(right); double lY = Y(left), rY = Y(right); double lZ = Z(left), rZ = Z(right); double lW = W(left), rW = W(right); return(Vector256.Create( BoolToSimdBoolDouble(lX >= rX || IsNan(lX, rX)), BoolToSimdBoolDouble(lY >= rY || IsNan(lY, rY)), BoolToSimdBoolDouble(lZ >= rZ || IsNan(lZ, rZ)), BoolToSimdBoolDouble(lW >= rW || IsNan(lW, rW)) )); }
public static Vector256 <double> CompareLessThanOrEqual_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { double lX = X(left), rX = X(right); double lY = Y(left), rY = Y(right); double lZ = Z(left), rZ = Z(right); double lW = W(left), rW = W(right); return(Vector256.Create( BoolToSimdBoolDouble(lX <= rX /* || IsNan(lX, rX)*/), BoolToSimdBoolDouble(lY <= rY /* || IsNan(lY, rY)*/), BoolToSimdBoolDouble(lZ <= rZ /* || IsNan(lZ, rZ)*/), BoolToSimdBoolDouble(lW <= rW /* || IsNan(lW, rW)*/) )); }
public static Vector4D CrossProduct3D_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { /* Cross product of A(x, y, z, _) and B(x, y, z, _) is * * '(X = (Ay * Bz) - (Az * By), Y = (Az * Bx) - (Ax * Bz), Z = (Ax * By) - (Ay * Bx)' */ return(Vector256.Create( Helpers.Y(left) * Helpers.Z(right) - Helpers.Z(left) * Helpers.Y(right), Helpers.Z(left) * Helpers.X(right) - Helpers.X(left) * Helpers.Z(right), Helpers.X(left) * Helpers.Y(right) - Helpers.Y(left) * Helpers.X(right), 0 )); }
public static Vector256 <double> Sin(Vector4DParam1_3 vector) { if (Avx.IsSupported) { Vector256 <double> vec = Mod2Pi(vector); Vector256 <double> sign = ExtractSign(vec); Vector256 <double> tmp = Or(DoubleConstants.Pi, sign); // Pi with the sign from vector Vector256 <double> abs = AndNot(sign, vec); // Gets the absolute of vector Vector256 <double> neg = Subtract(tmp, vec); Vector256 <double> comp = CompareLessThanOrEqual(abs, DoubleConstants.PiDiv2); vec = Select(neg, vec, comp); Vector256 <double> vectorSquared = Square(vec); // Polynomial approx Vector256 <double> sc0 = SinCoefficient0D; Vector256 <double> constants = Vector256.Create(SinCoefficient1DScalar); Vector256 <double> result = FastMultiplyAdd(constants, vectorSquared, PermuteWithW(sc0)); constants = PermuteWithZ(sc0); result = FastMultiplyAdd(result, vectorSquared, constants); constants = PermuteWithY(sc0); result = FastMultiplyAdd(result, vectorSquared, constants); constants = PermuteWithX(sc0); result = FastMultiplyAdd(result, vectorSquared, constants); result = FastMultiplyAdd(result, vectorSquared, DoubleConstants.One); result = Multiply(result, vec); return(result); } return(SoftwareFallback(vector));
public static Vector256 <double> PermuteWithW(Vector4DParam1_3 vector) => Permute(vector, ShuffleValues._3_3_3_3);
public static Vector4D Length4D_Software(Vector4DParam1_3 vector) { // No software fallback needed, these methods cover it return(Sqrt_Software(DotProduct4D_Software(vector, vector))); }
public static Vector4D Length2D_Software(Vector4DParam1_3 vector) { return(Sqrt_Software(DotProduct2D_Software(vector, vector))); }
public static Vector4D Normalize3D_Software(Vector4DParam1_3 vector) { Vector4D magnitude = Length3D_Software(vector); return(Divide_Software(vector, magnitude)); }
public static Vector4D DistanceSquared4D_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { Vector4DParam1_3 diff = Subtract_Software(left, right); return(DotProduct4D_Software(diff, diff)); }
public static Vector4D Distance4D_Software(Vector4DParam1_3 left, Vector4DParam1_3 right) { Vector4DParam1_3 diff = Subtract_Software(left, right); return(Length4D_Software(diff)); }