简体   繁体   中英

Getting auto-vectorization with gcc?

In the context of evaluating negative-log-likelihoods, I have to perform a bunch of operations that could benefit from vectorization

0) for (i = 1...n) { a[i] = 0; } // but this I think

std::fill( a.begin(), a.end(), 0 ) is already optimal

1) for (i = 1...n) { a[i] += b * c[i]; }

2) sum = 0; for (i = 1 .. n) { sum += a[i] * log( b[i] / c ); }

do you know if there's any hope to get gcc 434 to do auto-vectorization, and how should I code the loop to help him (eg using indices vs using iterators, should I break up (2) in simpler loops, ...) up to now I'm using doubles, have to check if I can move to floats at least for (1).

http://gcc.gnu.org/projects/tree-ssa/vectorization.html

Use the required options, -O3 -msse2

For more options, read the documentation above.

for autovectorization of floating point reductions like 2) you need to enable -funsafe-math-optimizations

on i386 like targets you also need to add -mfpmath=sse

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM