3 ms·
I've recently wondered, with C++, if there's a way to declare vectors so that compilers can autovectorise easily and not include the necessary codegen for cases
by secondcoming 4y ago
I've recently wondered, with C++, if there's a way to declare vectors so that compilers can autovectorise easily and not include the necessary codegen for cases where the data length is less than an AVX register width in bytes.
Maybe it's possible with a custom allocator trait?
e.g. the following code could potentially use AVX instructions only
using V = std::vector<std::uint32_t>;
V& andVectors(V& a, const V& b, std::size_t sz) {
for (std::size_t i = 0; i < sz; ++i) {
a[i] &= b[i];
}
return a;
}
https://godbolt.org/z/vzcaor1a9 https://godbolt.org/z/vzcaor1a9