The Compiler Will Not Reassociate
This double-precision sum runs at 3.01 cycles per element, matching the 3-cycle FP add latency:
double s = 0.0;
for (long i = 0; i < n; i++)
s = s + d[i];
You rewrite it by hand with four accumulators and get 1.01, the best this part can do for scalar FP addition. A reviewer objects:
Delete the hand-rolled version.
-O3unrolls loops; the compiler will do this transformation itself and the original is readable.
You check the assembly at -O3 and the compiler did unroll the loop, but kept one accumulator and the CPE is still 3.01. Why?
Sign in to answer questions and track your progress
Sign In