假设我有以下代码:
class Vec3
{
// ... deleted, not needed...
public:
Vec3 operator+(const Vec3 &rh) const;
};
void test(Vec3 *a, Vec3 *b, Vec3 *c, size_t len)
{
for(size_t i = 0; i < len; i++)
c[i] = a[i] + b[i];
}
这似乎是向量化的普通示例,但是由于operator +()是用户定义的函数,因此该循环不会自动向量化。我也尝试__declspec(vector)
按照此处的建议进行添加,但这会导致编译错误:
error: return type with class/struct/union is not supported in vector function
也许我误解了这个前缀的作用。如何使函数可矢量化?
提前致谢!
仅当函数的参数属于以下类别之一时,才能转换传统函数(这是当前限制,网址为https://software.intel.com/sites/products/documentation/doclib/iss/2013/在“使用向量声明的限制”下的编译器/cpp-lin/GUID-42986DEF-8710-453A-9DAC-2086EE55F1F5.htm):
您的程序使用的是用户定义的数据类型Vec3,该数据类型不属于上述四个类别。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句