3 ms·
What are the odds this turns out to be practical advice for this example? High. E.g. gcc 4.8.2 vectorizes this on my machine (-march=native -mtune=native -O3 -
by danieldk 12y ago
What are the odds this turns out to be practical advice for this example?
High. E.g. gcc 4.8.2 vectorizes this on my machine (-march=native -mtune=native -O3 -ffast-math -ftree-vectorizer-verbose=1):
for (size_t i = 0; i < n; ++i) {
sum += a[i];
sum += b[i];
}
(a and b have the same length)
But doesn't vectorize:
for (double *p = a; p < a + n; ++p) {
sum += *p;
sum += *(b + (p-a));
}
(Yes, you can make an extra pointer for b, but just for the sake of the example.)
tl;dr: your compiler writer probably knows better than you.
- asveikau 12y agoThe poster did not sum values. They used the loop to call into printf. I'm guessing they didn't also use those particular compiler options... What you have here sounds like a lot of tuning that does not apply equally for all scenarios.