我使用下面的命令編譯我的代碼:如何在使用GCC時禁用矢量化?
gcc -O3 -ftree-vectorizer-verbose=6 -msse4.1 -ffast-math
有了這一切的優化被啓用。
但我想禁用矢量化,同時保持其他優化。
我使用下面的命令編譯我的代碼:如何在使用GCC時禁用矢量化?
gcc -O3 -ftree-vectorizer-verbose=6 -msse4.1 -ffast-math
有了這一切的優化被啓用。
但我想禁用矢量化,同時保持其他優化。
大多數GCC交換機都可以使用前綴no
來禁用它們的行爲。試用-fno-tree-vectorize
(在命令行上輸入-O3
後)。
還可以選擇性地啓用和與優化功能禁止向量化屬性或編譯指示
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html
例如
__attribute__((optimize("no-tree-vectorize")))
void f(double * restrict a, double * restrict b)
{
for (int i = 0; i < 256; i++)
a[i] += b[i];
}
非常好,現在gcc已經變得更具侵略性,
extern "C" __attribute__((optimize("no-tree-vectorize")))
/* Subroutine */
int s111_ (integer * ntimes, integer * ld, integer * n,
real * ctime, real * dtime,
real * __restrict a, real * b, real * c__, real * d__,
real * e, real * aa, real * bb, real * cc)
{
....
for (i__ = 2; i__ <= i__2; i__ += 2)
a[i__] = a[i__ - 1] + b[i__];
....
在上述情況下發布,刪除restrict
用來做的工作,但現在G ++ 6.0不能從矢量化通過去除__restrict
停止。