struct Vector4
{
float x, y, z, w;
};
struct Matrix
{
float _M[][];
}; void SSE_VectorMultiplyMatrix(const Vector4& v,const Matrix& m1,Vector4& ret)
{
Vector4 va,vb,vc,vd;
Vector4 *pva,*pvb,*pvc,*pvd;
const Vector4 *pv;
//取出矩阵每一列
va.x = m1._M[][];
va.y = m1._M[][];
va.z = m1._M[][];
va.w = m1._M[][]; vb.x = m1._M[][];
vb.y = m1._M[][];
vb.z = m1._M[][];
vb.w = m1._M[][]; vc.x = m1._M[][];
vc.y = m1._M[][];
vc.z = m1._M[][];
vc.w = m1._M[][]; vd.x = m1._M[][];
vd.y = m1._M[][];
vd.z = m1._M[][];
vd.w = m1._M[][]; pva = &va;
pvb = &vb;
pvc = &vc;
pvd = &vd;
pv = &v;
__asm
{
//矩阵四列放入mmx0-mmx3
MOV EAX, pva // Load pointer into CPU reg
MOVUPS XMM0, [EAX]
MOV EAX, pvb // Load pointer into CPU reg
MOVUPS XMM1, [EAX]
MOV EAX, pvc // Load pointer into CPU reg
MOVUPS XMM2, [EAX]
MOV EAX, pvd // Load pointer into CPU reg
MOVUPS XMM3, [EAX] //向量放入 mmx4
MOV EAX, pv
MOVUPS XMM4, [EAX] //向量点乘矩阵每列
MULPS XMM0,XMM4
MULPS XMM1,XMM4
MULPS XMM2,XMM4
MULPS XMM3,XMM4 //输出四个分量
MOVUPS [va], XMM0
MOVUPS [vb], XMM1
MOVUPS [vc], XMM2
MOVUPS [vd], XMM3
} //四个分量求和得变换后向量
ret.x = va.w + va.x + va.y + va.z;
ret.y = vb.w + vb.x + vb.y + vb.z;
ret.z = vc.w + vc.x + vc.y + vc.z;
ret.w = vd.w + vd.x + vd.y + vd.z; }