Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove length 3 repr_simd vectors #66

Closed
calebzulawski opened this issue Feb 7, 2021 · 2 comments
Closed

Remove length 3 repr_simd vectors #66

calebzulawski opened this issue Feb 7, 2021 · 2 comments

Comments

@calebzulawski
Copy link

calebzulawski commented Feb 7, 2021

In rust-lang/rust#80652 we are removing support for non-power-of-two vector lengths with #[repr(simd)] from nightly Rust, and vek is one of the crates that will be effected. Just wanted to give a heads up before we make the change. If you have any questions feel free to ask!

@yoanlcq
Copy link
Owner

yoanlcq commented Feb 7, 2021

Hi, thanks for letting me know!

Fortunately this will be easy to fix on my side, I'll just make the non-power-of-two vectors in my repr_simd modules be actually #[repr(C)] instead, so this wouldn't break the API, although this has minor consequences related to alignment and stuff, but I doubt anybody would complain. If they do care, they should be using length 4 vectors instead anyway.

That said, I liked the fact that it "worked" and that the compiler would silently round up the length to the next power of two. Very often I like to use a Vec3 because it describes my intent exactly, but still have it backed by an SIMD register for efficiency.
Compared to biting the bullet and using a Vec4, this has positive consequences such as :

  • Completely preventing (erroneous) use of the 4th element, since there is no such member in the struct;
  • Some operations such as the cross product only make sense for Vec3. Of course I could implement these for Vec4 as well (and I probably will have to), but it was nice to have the type system help me enforce this while backing that with SIMD for me.

I wish it could keep "working" as it did, but I understand that this regression may make life significantly easier for the backend, so let's roll with it!

@yoanlcq yoanlcq closed this as completed in 3274010 Feb 7, 2021
@calebzulawski
Copy link
Author

I agree with all of your reasoning and I'll open an issue with stdsimd to make sure we get to it eventually. Unfortunately the cranelift backend does not support unusual vector lengths yet, and we are trying to bring std::simd and cranelift simultaneously. Once cranelift supports it, we can reenable it. Thanks for the quick fix!

jfroy added a commit to jfroy/rrt that referenced this issue Feb 22, 2021
See yoanlcq/vek#66

This ends up a bit slower than the previous baseline, but remains way
faster than falling back to the C representation.

Bench for the C repr:
AMD Ryzen 9 3900X 12-Core Processor (AMD64 Family 23 Model 113 Stepping 0)
$ cargo bench --bench benchmark -- --baseline master
tracescene/10x10x4      time:   [525.46 us 527.30 us 529.31 us]
                        change: [+74.250% +75.107% +75.981%] (p = 0.00 < 0.05)
                        Performance has regressed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants