Original Post
Hi I have two versions of the same function, one of them is written with SSE instructions and should be faster than the other but it isn't. Could someone take a look and give me some advice why that is, please? Also I would appreciate if someone would direct me to some good books and sites about SSE. Here are the funcs.(SSE assembly code is pasted from some book and looks fine): inline void CrossVec ( Vektor& result, Vektor& op1, Vektor& op2){ result.i = op1.j*op2.k - op2.j*op1.k; result.j = op2.i*op1.k - op1.i*op2.k; result.k = op1.i*op2.j - op2.i*op1.j; } inline void CrossVec ( Vektor& result, Vektor& op1, Vektor& op2){ __asm { MOV EAX, op1 // Load pointers into CPU regs MOV EBX, op2 MOV ECX, result MOVUPS XMM0, [EAX] // Move unaligned vectors to SSE regs MOVUPS XMM1, [EBX] MOVAPS XMM2, XMM0 // Make a copy of vector A MOVAPS XMM3, XMM1 // Make a copy of vector B SHUFPS XMM0, XMM0, 0xD8 // 11 01 10 00 Flip the middle elements of A SHUFPS XMM1, XMM1, 0xE1 // 11 10 00 01 Flip first two elements of B MULPS XMM0, XMM1 // Multiply the modified register vectors SHUFPS XMM2, XMM2, 0xE1 // 11 10 00 01 Flip first two elements of the A copy SHUFPS XMM3, XMM3, 0xD8 // 11 01 10 00 Flip the middle elements of the B copy MULPS XMM2, XMM3 // Multiply the modified register vectors SUBPS XMM0, XMM2 // Subtract the two resulting register vectors MOVUPS [ECX], XMM0 // Save the return vector } }