我正试图使用clang根据此clang参考文献对以下函数进行向量化。它获取一个字节数组的向量,并根据此RFC应用掩码。
static void apply_mask(vector<uint8_t> &payload, uint8_t (&masking_key)[4]) {
#pragma clang loop vectorize(enable) interleave(enable)
for (size_t i = 0; i < payload.size(); i++) {
payload[i] = payload[i] ^ masking_key[i % 4];
}
}
以下标志被传递给clang编译器:-O3
-Rpass=loop-vectorize
-Rpass-analysis=loop-vectorize
然而,使用向量化时出现以下错误:
WebSocket.cpp:5:
WebSocket.h:14:
In file included from boost/asio/io_service.hpp:767:
In file included from boost/asio/impl/io_service.hpp:19:
In file included from boost/asio/detail/service_registry.hpp:143:
In file included from boost/asio/detail/impl/service_registry.ipp:19:
c++/v1/vector:1498:18: remark: loop not vectorized: could not determine number
of loop iterations [-Rpass-analysis]
return this->__begin_[__n];
^
c++/v1/vector:1498:18: error: loop not vectorized: failed explicitly specified
loop vectorization [-Werror,-Wpass-failed]
如何将这个for循环向量化?
-03
下隐式地执行它? - Baum mit Augenrestrict
(和/或const
)应用于uint8_t (&masking_key)[4]
? - Paul Rconst
可能不会有帮助,因为一个非const
数据可以有const&
。不过restrict
值得一试。 - Baum mit Augenstd::array
作为键也可以消除所有潜在的别名问题。 - Baum mit Augen