I have read many SO questions about SSE/SIMD (e.g., Getting started with SSE), but I'm still confused by all of it. All I want is a dot product between two double precision floating-point vectors, in C (C99 FWIW). I'm using GCC.
Can someone post a simple and complete example, including how to convert double vectors to the SSE types and back again?
[Edit 2012-10-08]
Here's some SSE2 code I managed to cobble together, critiques?
#include <emmintrin.h>
double dotprod(double *restrict a, double *restrict b, int n)
{
__m128d aa, bb, cc, ss;
int i, n1 = n - 1;
double *s = calloc(2, sizeof(double));
double s2 = 0;
ss = _mm_set1_pd(0);
for(i = 0 ; i < n1 ; i += 2)
{
aa = _mm_load_pd(a + i);
bb = _mm_load_pd(b + i);
cc = _mm_mul_pd(aa, bb);
ss = _mm_add_pd(ss, cc);
}
_mm_store_pd(s, ss);
s2 = s[0] + s[1];
if(i < n)
s2 += a[i] * b[i];
free(s);
return s2;
}