Microsoft DirectX 8.0 (Visual Basic)

m4x4

Computes the product of the input vector and a 4x4 matrix.

m4x4   rDest, vSrc0, mSrc1

Registers

rDest
Destination register, holding the result of the operation.
vSrc0
Source register, specifying the input argument.
mSrc1
Source register, specifying the input argument.

Operation

   SetDestReg();
    SetSrcReg(0);
    SetSrcReg(1, 4);
    m_TmpReg.x = m_Source[0].x * m_Source[1].x +
                 m_Source[0].y * m_Source[1].y +
                 m_Source[0].z * m_Source[1].z +
                 m_Source[0].w * m_Source[1].w;
    m_TmpReg.y = m_Source[0].x * m_Source[2].x +
                 m_Source[0].y * m_Source[2].y +
                 m_Source[0].z * m_Source[2].z +
                 m_Source[0].w * m_Source[2].w;
    m_TmpReg.z = m_Source[0].x * m_Source[3].x +
                 m_Source[0].y * m_Source[3].y +
                 m_Source[0].z * m_Source[3].z +
                 m_Source[0].w * m_Source[3].w;
    m_TmpReg.w = m_Source[0].x * m_Source[4].x +
                 m_Source[0].y * m_Source[4].y +
                 m_Source[0].z * m_Source[4].z +
                 m_Source[0].w * m_Source[4].w;

    WriteResult();

Expansion

The following m4x4 instruction

m4x4   r5, v[0], c[3]

expands to

dp4   r5.x, v[0], c[3]
dp4   r5.y, v[0], c[4]
dp4   r5.z, v[0], c[5]
dp4   r5.w, v[0], c[6]

Therefore, this macro consumes four instruction slots from the instruction count.

Remarks

The input vector is at vSrc0 and the input 4x4 matrix is at mSrc1 and the three subsequent registers in the same file.

This operation is commonly used to transform an position by a projection matrix. This macro instruction is implemented as a series of dot products.