3 ms·
AFAIK, auto-vectorization has the same limitation in Rust as in C and C++ - it cannot be required. Hence, it is very easy to break the vectorization in brittle
by kookamamie 2y ago
AFAIK, auto-vectorization has the same limitation in Rust as in C and C++ - it cannot be required. Hence, it is very easy to break the vectorization in brittle ways, without even noticing the issue.
It would be nice to have a sort of autovec-or-error annotation for preventing this.
- dwattttt 2y agoRust is experimenting with "portable SIMD": https://doc.rust-lang.org/std/simd/index.html https://doc.rust-lang.org/std/simd/index.html It defines a generic `Simd<T, N>` type, expressing "This is a vector of T elements (such as i8), and is present in chunks of N". Methods that are easily vectorisable are defined on it, so if you can express what you want to do with one, you'll get well defined vectorised operations. Maybe not as perfect as you could hand write if you know what you're doing, but it _does_ guarantee to use vector instructions, so you're not at the behest of the compiler recognising a loop idiom.
- kookamamie 2y agoYes, that's a variant of manual vectorization. However, AFAIK Rust doesn't provide dynamic dispatching as part of the portable SIMD? If this is the case, ISPC still looks like a better option, I think, albeit it is unlikely to be seen as the Rusty way of doing things.
- flohofwoe 2y agoIt's most likely built onto the same LLVM features which enable the 'Clang extended vector extension' for C (it even compiles down to scalar code for CPUs without SIMD support): https://www.godbolt.org/z/MW8WeYjGo https://www.godbolt.org/z/MW8WeYjGo Not sure why Rust needs a lot of experimenting tbh, it's been in Clang since forever.
- steveklabnik 2y agoJust because the underlying infrastructure works doesn’t mean experimentation isn’t warranted, it’s about how you present the API to the user. Note that the ALI you’ve shown off here is different than the one shown above, maybe one or the other is better to use, hence experimenting with it.
- charleslmunger 2y agoClang emits a warning if you ask it to vectorize a loop and it can't; you can then promote that to an error. But even if the loop vectorizes, that doesn't mean that it vectorizes in the optimal way - my understanding is that pros write their loops with intrinsics specifying the operations they want for this reason. https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAMzwBtMA7AQwFtMQByARg9KtQYEAysib0QXACx8BBAKoBnTAAUAHpwAMvAFYTStJg1DIApACYAQuYukl9ZATwDKjdAGFUtAK4sGISVykrgAyeAyY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N9HfMQ4nSY2zbDkFdPIAghCShsYj7FQmDohsmAKM8akaXiEC4IQry1lwyy8Jh0XLLh%2BGEaRavERRYEcNRpBQd59GMcxrGK6QHGICA6wEMkqUCRAQl8cQESsNsYmSVJTPKSz8lsxzOkONztC8/zT5CyL6kMDhctBPgUp4OgeiDcIKajdIieTWotFzaQXVcskjmUxwEG67R9HWal1tQqgx6u4z/KexArNNOznP%2B1ygd8wL4bC/sosR%2BLHg8Q7qGy/LbHKwRRHq2rlHa9T%2BucIbLEK1oSsz2Yc8wQvxsr6sFXpM4khAA%3D https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaP...
- kookamamie 2y agoWarn-to-error promotion is a good point. I kind of wish something like this would exist on the language level.