public static Matrix Transpose(Matrix matrix) { #if SIMD Vector4f xmm0 = matrix.r1, xmm1 = matrix.r2, xmm2 = matrix.r3, xmm3 = matrix.r4; Vector4f xmm4 = xmm0; xmm0 = VectorOperations.InterleaveLow(xmm0, xmm2); xmm4 = VectorOperations.InterleaveHigh(xmm4, xmm2); xmm2 = xmm1; xmm1 = VectorOperations.InterleaveLow(xmm1, xmm3); xmm2 = VectorOperations.InterleaveHigh(xmm2, xmm3); xmm3 = xmm0; xmm0 = VectorOperations.InterleaveLow(xmm0, xmm1); xmm3 = VectorOperations.InterleaveHigh(xmm3, xmm1); xmm1 = xmm4; xmm1 = VectorOperations.InterleaveLow(xmm1, xmm2); xmm4 = VectorOperations.InterleaveHigh(xmm4, xmm2); return(new Matrix(xmm0, xmm3, xmm1, xmm4)); #else return(new Matrix( matrix.m11, matrix.m21, matrix.m31, matrix.m41, matrix.m12, matrix.m22, matrix.m32, matrix.m42, matrix.m13, matrix.m23, matrix.m33, matrix.m43, matrix.m14, matrix.m24, matrix.m34, matrix.m44)); #endif }
public static void Transpose(ref Matrix matrix, out Matrix result) { #if SIMD //algorithm from public domain - http://0x80.pl/snippets/asm/sse-transpose.c Vector4f xmm0 = matrix.r1; // xmm0 = a0 a1 a2 a3 Vector4f xmm1 = matrix.r2; // xmm1 = b0 b1 b2 b3 Vector4f xmm2 = matrix.r3; // xmm2 = c0 c1 c2 c3 Vector4f xmm3 = matrix.r4; // xmm3 = d0 d1 d2 d3 Vector4f xmm4 = xmm0; xmm0 = VectorOperations.InterleaveLow(xmm0, xmm2); // xmm0 = a0 c0 a1 c1 xmm4 = VectorOperations.InterleaveHigh(xmm4, xmm2); // xmm4 = a2 c2 a3 c3 xmm2 = xmm1; xmm1 = VectorOperations.InterleaveLow(xmm1, xmm3); // xmm1 = b0 d0 b1 d1 xmm2 = VectorOperations.InterleaveHigh(xmm2, xmm3); // xmm2 = b2 d2 b3 d3 xmm3 = xmm0; xmm0 = VectorOperations.InterleaveLow(xmm0, xmm1); // xmm0 = a0 b0 c0 d0 xmm3 = VectorOperations.InterleaveHigh(xmm3, xmm1); // xmm3 = a1 b1 c1 d1 xmm1 = xmm4; xmm1 = VectorOperations.InterleaveLow(xmm1, xmm2); // xmm1 = a2 b2 c2 d2 xmm4 = VectorOperations.InterleaveHigh(xmm4, xmm2); // xmm4 = a3 b3 c3 d3 result.r1 = xmm0; result.r2 = xmm3; result.r3 = xmm1; result.r4 = xmm4; #else result.m11 = matrix.m11; result.m12 = matrix.m21; result.m13 = matrix.m31; result.m14 = matrix.m41; result.m21 = matrix.m12; result.m22 = matrix.m22; result.m23 = matrix.m32; result.m24 = matrix.m42; result.m31 = matrix.m13; result.m32 = matrix.m23; result.m33 = matrix.m33; result.m34 = matrix.m43; result.m41 = matrix.m14; result.m42 = matrix.m24; result.m43 = matrix.m34; result.m44 = matrix.m44; #endif }
public static Matrix Transpose(Matrix matrix) { Vector4f xmm0 = matrix.r1, xmm1 = matrix.r2, xmm2 = matrix.r3, xmm3 = matrix.r4; Vector4f xmm4 = xmm0; xmm0 = VectorOperations.InterleaveLow(xmm0, xmm2); xmm4 = VectorOperations.InterleaveHigh(xmm4, xmm2); xmm2 = xmm1; xmm1 = VectorOperations.InterleaveLow(xmm1, xmm3); xmm2 = VectorOperations.InterleaveHigh(xmm2, xmm3); xmm3 = xmm0; xmm0 = VectorOperations.InterleaveLow(xmm0, xmm1); xmm3 = VectorOperations.InterleaveHigh(xmm3, xmm1); xmm1 = xmm4; xmm1 = VectorOperations.InterleaveLow(xmm1, xmm2); xmm4 = VectorOperations.InterleaveHigh(xmm4, xmm2); return(new Matrix(xmm0, xmm3, xmm1, xmm4)); }