Skip to content

Instantly share code, notes, and snippets.

@tanakamura
Last active December 19, 2015 02:38
Show Gist options
  • Save tanakamura/5884342 to your computer and use it in GitHub Desktop.
Save tanakamura/5884342 to your computer and use it in GitHub Desktop.
#include <pmmintrin.h>
double ddotp2(double *u,
double *v,
int n)
{
int i;
__m128d x = _mm_setzero_pd();
for (i=0; i<n-1; i+=2) {
x = _mm_add_pd(x, _mm_mul_pd(_mm_loadu_pd(&u[i]),
_mm_loadu_pd(&v[i])));
}
double ret = _mm_cvtsd_f64(_mm_hadd_pd(x,x));
if (n & 1) {
return ret + (u[n-1] * v[n-1]);
} else {
return ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment