I understand the basic ideas of vectorization. I am thinking transform one of my programs into to the vectorized version. But it seems complicated.
There is a table (2d-array) table[M][N]
, and two vectors X[1..4]
and Y[1..4]
. Can I do operations as below? Any thoughts?
X[1..4] = table[X[1..4]][Y[1..4]]
(sequential version: X[i] = table[X[i]][Y[i]]
)
In another word, can the following loop be vectorized?
for(k=0; k<4; k++) {
tmp1 = X[k];
tmp2 = Y[k];
X[k] = table[tmp1][tmp2];
}
Note: X[]
always contains distinct values.
Currently, it is implemented in C Language.
If you are copying adjacent memory cells, you can use memcpy() to copy a whole chunk of data. But since that's the the case here, no can do, you have to use the loop.