Original Post
Hello all, I'm trying to vectorise a dot product calculation using SSE intrinsics, I am new to this, what I'm trying to get is 4 dot products:- a . e b . e c . e d . e This is what I have at the moment.
__declspec(align(16)) float x1[4] = {a.x, b.x, c.x, d.x};
__declspec(align(16)) float y1[4] = {a.y, b.y, c.y, d.y};
__declspec(align(16)) float z1[4] = {a.z, b.z, c.z, d.z};
__declspec(align(16)) float vectresult[4];
__m128 m1, m2, m3, m4;
__m128* pSrc1 = (__m128*) x1;
__m128* pSrc2 = (__m128*) y1;
__m128* pSrc3 = (__m128*) z1;
__m128* pOut = (__m128*) vectresult;
while(some condition)
{
updateEvector();
__m128 m0_x = _mm_set_ps1(e.x);
__m128 m0_y = _mm_set_ps1(e.y);
__m128 m0_z = _mm_set_ps1(e.z);
m1 = _mm_mul_ps(*pSrc1, m0_x);
m2 = _mm_mul_ps(*pSrc2, m0_y);
m3 = _mm_mul_ps(*pSrc3, m0_z);
m4 = _mm_add_ps(m1, m2);
m4 = _mm_add_ps(m4, m3);
*pOut = m4;
}
It is currently getting beaten with the tradional method using the FPU:-
while(some condition)
{
updateEvector();
ae = (a.x*e.x) + (a.y*e.y) + (a.z*e.z);
be = (b.x*e.x) + (b.y*e.y) + (b.z*e.z);
ce = (c.x*e.x) + (c.y*e.y) + (c.z*e.z);
de = (d.x*e.x) + (d.y*e.y) + (d.z*e.z);
}
I did see an SSE implementation for a dot product with asm on this forum, but that was still slower then using the FPU. Is it possible to do what I want to do and beat the FPU with SSE for dot products or am I wasting my time? Thnaks in advance