我从来没有写过SSE优化的汇编代码,所以很抱歉,如果这是一个菜鸟问题。在this aritcle解释了如何使用条件语句矢量化for
。然而,我的代码(从here采取)的形式为:是否可以使用SSE为此嵌套进行矢量化?
for (int j=-halfHeight; j<=halfHeight; ++j)
{
for(int i=-halfWidth; i<=halfWidth; ++i)
{
const float rx = ofsx + j * a12;
const float ry = ofsy + j * a22;
float wx = rx + i * a11;
float wy = ry + i * a21;
const int x = (int) floor(wx);
const int y = (int) floor(wy);
if (x >= 0 && y >= 0 && x < width && y < height)
{
// compute weights
wx -= x; wy -= y;
// bilinear interpolation
*out++ =
(1.0f - wy) * ((1.0f - wx) * im.at<float>(y,x) + wx * im.at<float>(y,x+1)) +
( wy) * ((1.0f - wx) * im.at<float>(y+1,x) + wx * im.at<float>(y+1,x+1));
} else {
*out++ = 0;
}
}
}
所以,从我的理解,有与链接的文章的几个不同之处:
- 在这里,我们有一个嵌套
for
:我在vectroization中总是看到一个级别for
,从未见过嵌套循环 - if条件基于标量值(x和y)而不是数组:我怎样才能使链接的示例适应此?
- 的
out
指数不是基于i
或j
(所以它不是out[i]
或out[j]
):我怎么能以这种方式填补out
?
特别我很困惑,因为for
索引始终用作数组索引,而在这里被用于计算变量而矢量由周期递增周期
我使用icpc
与-O3 -xCORE-AVX2 -qopt-report=5
和一堆其他优化标志。根据英特尔顾问,这是不是矢量化,并使用#pragma omp simd
生成warning #15552: loop was not vectorized with "simd"
你使用哪种编译器?你有没有确认你的编译器还没有为你自动矢量化? – Jonas
@Jonas感谢您的评论。请看看我更新的问题 – justHelloWorld
与您以前的问题非常相似http://stackoverflow.com/questions/43136182/compiler-doesnt-vectorize-even-with-simd-directive有什么变化? –