I am trying to vectorize a loop that does a lot of iteration (over 300 000 000) to gain some computation time:
uint16_t* samples = (uint16_t*)pixmap->samples;
Image image(pixmap->w, pixmap->h);
uint8_t *dest = (uint8_t*)image[0];
for (int x = 0; x < len; x++)
{
dest[x] = samples[x] & 0xFF;
}
But qvec-report say it could not be vectorized due to reason 1300.
According to the MSDN, reason 1300 is :
Loop body contains no—or very little—computation.
Indeed, my loop body does very little computation, but since there is a lot of iteration, it still take some time.
Why does the vectorization is not done in that case ? Is it because it would not be worth it ? If yes, why ?
If no, is there any way or any tricks to "force" it ?
Basically the body of the loop is so simple that it's more efficient to compile it as it is rather than vectorize it as the runtime cost of the vectorization would be greater than executing the code as it is.
There's really no point in trying to force it, as the compiler is telling you that the vectorized version would be less efficient that the non-vectorized version. If you add more computations to the loop the compiler may choose to vectorize it.