Split
On this Haswell part, double-precision FP multiply has a latency of 5 cycles and can issue 1 per cycle on each of 2 multiply units. A serial product loop measures 5.01 cycles per element:
double x = 1.0;
for (long i = 0; i < n; i++)
x = x * d[i];
You unroll by 4 and keep 4 independent accumulators, combining them once at the end:
double x0 = 1.0, x1 = 1.0, x2 = 1.0, x3 = 1.0;
for (i = 0; i + 3 < n; i += 4) {
x0 = x0 * d[i]; x1 = x1 * d[i+1];
x2 = x2 * d[i+2]; x3 = x3 * d[i+3];
}
for (; i < n; i++) x0 = x0 * d[i];
double x = x0 * x1 * x2 * x3;
What cycles-per-element should you predict?
Sign in to answer questions and track your progress
Sign In