risinglight
risinglight copied to clipboard
expr: explicit SIMD
I've been working with some other database things recently and it seems that Rust compiler cannot automatically vectorize array-array operation.
https://godbolt.org/z/G8WMr4acY
Probably we should bring back the portable SIMD expressions framework?
Bounds checking does not allow the compiler to auto-vectorize.
Try and test res = vec::from_iter(a.iter().zip(b.iter()).map())
yeah it works! https://godbolt.org/z/eG61feTM4 I'll check if binary operations are actually vectorized in RisingLight later...
You can check them via cargo bench --bench array
. It would be obvious which operations are vectorized and which are not.
I still prefer auto-vectorization over explicit SIMD, because usually compilers do it better than humans and it makes code cleaner. However, as mentioned above, auto-vectorization requires special craft of codes. There are plenty of things that prevent SIMD, e.g. bound check, branching. AFAIK, there's also no way to hint or ensure auto-vectorization for a piece of code in Rust, i.e. no equivalent for #pragma clang loop vectorize(enable)
.
Yep, I also think auto vectorization
… is good
https://matklad.github.io/2023/04/09/can-you-trust-a-compiler-to-optimize-your-code.html
:p