【发布时间】:2018-09-21 14:26:14
【问题描述】:
我有以下 4x4 矩阵向量乘法代码:
double const __restrict__ a[16];
double const __restrict__ x[4];
double __restrict__ y[4];
//#pragma GCC unroll 1 - does not work either
#pragma GCC nounroll
for ( int j = 0; j < 4; ++j )
{
double const* __restrict__ aj = a + j * 4;
double const xj = x[j];
#pragma GCC ivdep
for ( int i = 0; i < 4; ++i )
{
y[i] += aj[i] * xj;
}
}
我使用-O3 -mavx 标志编译。内部循环是矢量化的(单个 FMAD)。但是,gcc (7.2) 不断展开外循环 4 次,除非我使用 -O2 或更低的优化。
有没有办法覆盖 -O3 展开特定循环?
注意。如果我使用 Intel icc,类似的 #pragma nounroll 也可以工作。
【问题讨论】:
-
#pragma GCC unroll n在 GCC 8.x 中有效——但仅在某种程度上——据我所知,这更像是一个提示而不是严格的要求(应该展开多少次)。跨度>
标签: gcc optimization pragma loop-unrolling