c++ - Vectorize function calls on each element of a vector -
when call function each element in vector using for_each calls vectorized or not?
in general, no.
std::for_each
wrapper around loop.
however, optimizations on, it's quite call std::for_each
inlined, , simple functions, function call each element inlined too.
once inlined, it's if loop had been written hand; in such case, question becomes "will compiler vectorize loop doing simple arithmetic"; , that's entirely compiler.
in order happen, compiler needs know target architecture supports simd instructions, , may or may not vectorize depending on optimization level, whether number of iterations constant or not, whether number of iterations known multiple of 4, etc.
Comments
Post a Comment