gpt4 book ai didi

c++ - opencv CV_ENABLE_UNROLLED 这个特性有什么作用?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:23:40 26 4
gpt4 key购买 nike

我在 OpenCV 中看到它在许多地方使用了 #if CV_ENABLE_UNROLLED。例如

#if CV_ENABLE_UNROLLED
for( ; i <= width - 4; i += 4 )
{
ST f = ky[0];
const ST* S = (const ST*)src[0] + i, *S2;
ST s0 = f*S[0] + _delta, s1 = f*S[1] + _delta,
s2 = f*S[2] + _delta, s3 = f*S[3] + _delta;

for( k = 1; k <= ksize2; k++ )
{
S = (const ST*)src[k] + i;
S2 = (const ST*)src[-k] + i;
f = ky[k];
s0 += f*(S[0] + S2[0]);
s1 += f*(S[1] + S2[1]);
s2 += f*(S[2] + S2[2]);
s3 += f*(S[3] + S2[3]);
}

D[i] = castOp(s0); D[i+1] = castOp(s1);
D[i+2] = castOp(s2); D[i+3] = castOp(s3);
}
#endif

filter.cpp

除了在循环中进行 4 次浮点运算意味着更少的条件检查次数之外,此功能还有其他优势吗?如果是,那是什么。如果不是,那么当把它放在宏中时,为什么我们不能一直使用它呢?

最佳答案

来自 OpenCV's revisions :

CV_ENABLE_UNROLLED (?? default)default) - Experimental feature, that activates some 4- or 8- unroll loops. It theoretically helps compiler optimize the code, and improves memory access. However, the coverage of this feature in code is still very limited.

关于c++ - opencv CV_ENABLE_UNROLLED 这个特性有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22339707/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com