risinglight icon indicating copy to clipboard operation
risinglight copied to clipboard

expr: explicit SIMD

Open skyzh opened this issue 2 years ago • 7 comments

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?

skyzh avatar Feb 19 '23 05:02 skyzh

Bounds checking does not allow the compiler to auto-vectorize.

Try and test res = vec::from_iter(a.iter().zip(b.iter()).map())

lokax avatar Feb 19 '23 21:02 lokax

yeah it works! https://godbolt.org/z/eG61feTM4 I'll check if binary operations are actually vectorized in RisingLight later...

skyzh avatar Feb 19 '23 21:02 skyzh

You can check them via cargo bench --bench array. It would be obvious which operations are vectorized and which are not.

wangrunji0408 avatar Feb 20 '23 03:02 wangrunji0408

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).

wangrunji0408 avatar Feb 20 '23 03:02 wangrunji0408

Yep, I also think auto vectorization

skyzh avatar Feb 20 '23 03:02 skyzh

… is good

skyzh avatar Feb 20 '23 03:02 skyzh

https://matklad.github.io/2023/04/09/can-you-trust-a-compiler-to-optimize-your-code.html

:p

xxchan avatar Apr 23 '23 13:04 xxchan