我尝试编译此代码,
#include <stdlib.h>
struct rgb {
int r, g, b;
};
void adjust_brightness(struct rgb *picdata, size_t len, int adjustment) {
// assume adjustment is between 0 and 255.
for (int i = 0; i < len; i++) {
picdata[i].r += adjustment;
picdata[i].g += adjustment;
picdata[i].b += adjustment;
}
}
使用此命令在OSX上,
$ cc -Rpass-analysis=loop-vectorize -c -std=c99 -O3 brightness.c
brightness.c:13:3: remark: loop not vectorized: unsafe dependent memory operations in loop [-Rpass-analysis=loop-vectorize]
for (int i = 0; i < len; i++) {
^
有人能解释一下这里不安全和依赖吗?我正在学习SIMD,这在SIMD最明显的用途中得到了解释。我希望了解编译器如何为一个简单的例子生成SIMD指令。在我看来,我希望编译器可能不会递增1,它会增加足够的数量以将循环体放入向量寄存器中吗?
我误解了吗?