English 中文(简体)
为什么没有这种循环?
原标题:Why isn t this loop vectorized?

在我介绍我正在使用的守则时,一个特别热点是:

for(int loc = start; loc<end; ++loc)
    y[loc]+=a[offset+loc]*x[loc+d];

阵列、a、x没有重叠。 在我看来,像这种循环很容易成为病媒,然而,当我用“O3-ftree-vectorize-ftree-vectorizer-verbose=1”的“g++”汇编时,我没有发现这一特殊循环是病媒的。 然而,在上述法典之前就发生了一起诉讼:

for(int i=0; i<m; ++i)
    y[i]=0;

does get vectorized according to the output. Any thoughts on why the first loop is not vectorized, or how I might be able to fix this? (I am not all that educated on the concept of vectorization, so I am likely missing something quite obvious)

As per Oli s suggestion, turning up the verbosity yields the following notes (while I am usually good at reading compiler warnings/errors/output, I have no idea what this means):

./include/mv_ops.h:89: note: dependence distance  = 0.
./include/mv_ops.h:89: note: accesses have the same alignment.
./include/mv_ops.h:89: note: dependence distance modulo vf == 0 between *D.50620_89 and *D.50620_89
./include/mv_ops.h:89: note: not vectorized: can t determine dependence between *D.50623_98 and *D.50620_89
最佳回答

You need to tell the compiler that x, y, and a do not overlap. In C/C++ terms that means telling the compiler that those pointers do not alias by declaring them with restrict (or __restrict). gcc is very aggressive about optimizations when it assumes no aliasing, so be careful.

问题回答

一种可能性是,汇编者不能保证没有别的东西。 换言之,汇编者如何确保<代码>y,ax t不以某种方式重叠?

如果你把博爱提升到更高水平,你会得到一些额外的信息。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签