I am trying to vectorize some simple calculations to speed up work with the SIMD architecture. However, I also want to use them as an inline function, since function calls and non-vectorized codes also take up computational time. However, I cannot always achieve them at the same time. In fact, most of my built-in functions do not receive auto-vectorization. Here is a simple test code that works:
inline void add1(double *v, int Length) {
for(int i=0; i < Length; i++) v[i] += 1;
}
void call_add1(double v[], int L) {
add1(v, L);
}
int main(){return 0;}
On Mac OS X 10.12.3 compile it:
clang++ -O3 -Rpass=loop-vectorize -Rpass-analysis=loop-vectorize -std=c++11 -ffast-math test.cpp
test.cpp:2:5: remark: vectorized loop (vectorization width: 2, interleaved count: 2) [-Rpass=loop-vectorize]
for(int i=0; i < Length; i++) v[i] += 1;
^
However, something very similar (only moving arguments in call_add1) does not work:
inline void add1(double *v, int Length) {
for(int i=0; i < Length; i++) v[i] += 1;
}
void call_add1() {
double v[20]={0,1,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9};
int L=20;
add1(v, L);
}
int main(){ return 0;}
. ? , -? , , , .