microsoft / DirectXMath

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps

Home Page:https://walbourn.github.io/introducing-directxmath/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiply two vectors to get a matrix

walbourn opened this issue · comments

Request for an optimized version of this function:

inline XMMATRIX XM_CALLCONV XMMatrixVectorTensorProduct
(
    FXMVECTOR V1,
    FXMVECTOR V2
)
{
#if defined(_XM_NO_INTRINSICS_)
    XMMATRIX mResult;
    mResult.m[0][0] = V1.vector4_f32[0] * V2.vector4_f32[0];
    mResult.m[0][1] = V1.vector4_f32[0] * V2.vector4_f32[1];
    mResult.m[0][2] = V1.vector4_f32[0] * V2.vector4_f32[2];
    mResult.m[0][3] = V1.vector4_f32[0] * V2.vector4_f32[3];

    mResult.m[1][0] = V1.vector4_f32[1] * V2.vector4_f32[0];
    mResult.m[1][1] = V1.vector4_f32[1] * V2.vector4_f32[1];
    mResult.m[1][2] = V1.vector4_f32[1] * V2.vector4_f32[2];
    mResult.m[1][3] = V1.vector4_f32[1] * V2.vector4_f32[3];

    mResult.m[2][0] = V1.vector4_f32[2] * V2.vector4_f32[0];
    mResult.m[2][1] = V1.vector4_f32[2] * V2.vector4_f32[1];
    mResult.m[2][2] = V1.vector4_f32[2] * V2.vector4_f32[2];
    mResult.m[2][3] = V1.vector4_f32[2] * V2.vector4_f32[3];
 
    mResult.m[3][0] = V1.vector4_f32[3] * V2.vector4_f32[0];
    mResult.m[3][1] = V1.vector4_f32[3] * V2.vector4_f32[1];
    mResult.m[3][2] = V1.vector4_f32[3] * V2.vector4_f32[2];
    mResult.m[3][3] = V1.vector4_f32[3] * V2.vector4_f32[3];
    return mResult;
#endif
}
#else
		XMMATRIX mResult;
		mResult.r[ 0 ] = XMVectorMultiply( XMVectorSwizzle<0, 0, 0, 0>( V1 ), V2 );
		mResult.r[ 1 ] = XMVectorMultiply( XMVectorSwizzle<1, 1, 1, 1>( V1 ), V2 );
		mResult.r[ 2 ] = XMVectorMultiply( XMVectorSwizzle<2, 2, 2, 2>( V1 ), V2 );
		mResult.r[ 3 ] = XMVectorMultiply( XMVectorSwizzle<3, 3, 3, 3>( V1 ), V2 );
		return mResult;
#endif