-
Notifications
You must be signed in to change notification settings - Fork 269
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
Tweak names of wasm SIMD intrinsics #1096
Conversation
r? @Amanieu (rust-highfive has picked a reviewer for you, use r? to override) |
468a01a
to
817329f
Compare
Are these only being renamed in Rust or C / C++ as well? Cause I find it a bit odd for Rust to diverge from C's intrinsics when this was something that was explicitly decided against for x86. |
The original intention of wasm SIMD support was to very closely match the spec 1:1 to provide low-level primitives. Over time though this has become less appealing and "niceties" such as `i64x2_shuffle` have been added instead of only giving users `i8x16_shuffle` (same thing for `*_const` functions). This commit goes through and gives special treatment to all SIMD intrinsics and instructions for wasm. This performs changes such as: * All `*_u` and `*_s` suffixes are now baked into the intrinsic type, e.g. changing `i16x8` to `u16x8` where appropriate. * `*_const` functions have been added for unsigned types * `*_replace_lane` functions have been added for unsigned types * `*_extract_lane` functions have been added for unsigned types While I think it makes sense at the wasm simd spec layer that all these instructions have the names they do, I've concluded that at the Rust layer we'll want more understandable names since they're so easy to bind and are easier to understand when reading/writing code.
817329f
to
90ea922
Compare
Personally I would hope that each architecture inside of the For wasm we don't have the convenience of a preexisting standard to copy from, and additionally we're working with the scale of hundreds of intrinsics instead of thousands. These two combined lead me to believe that wasm should reserve the right to blaze it's own trail here and set the precedent. Functions like All that to say that while I think we can take inspiration from what clang is doing for C I do not think we should be bound to follow it exactly. For example if you look at clang's header file for To reiterate, though, there's no point in intentionally being different from clang. It's not like clang made bad decisions or anything like that, my point is just that the decisions for C-the-language are not always the right decisions for Rust-the-language as well. As such I'm of the opinion that we should do what's right for Rust in this module, not just copy C. Language differences largely come up when handling types/conversions in this instance, but if you look at the header file for C you'll find that this PR actually brings most intrinsics to match names with the C header file. |
Looking at the Clang header, it uses |
I was just wondering that myself this morning about the I think that this naming only really applies to |
The |
For comparisons we it would also apply only to integers because I do find this an oddity though where if you use |
In general I'm definitely in favor of cleaning up the API, in fact I was about to write a clean wrapper API myself (probably as part of safe_arch which does this already for x86). So if this is happening in std, that would be even better. Though it's sad that this did not happen for x86. Though I would then also be in favor of adding proper f32x4, f64x2, ... types. Most of the transmuting will come from iterating e.g. [f32] slices as f32x4 chunks. For this you will need to have some transmute solution anyway. I'd argue that e.g. using f64x2 intrinsics on f32x4 vectors is so rare that you also probably should be transmuting, just so the compiler can catch the likely mistake that this is otherwise. Also it just straight up seems weird to willingly introduce a weakly typed API into Rust which otherwise is very strongly typed (neither x86 nor ARM SIMD is this weakly typed either). It probably makes more sense to just introduce functions / methods on those types for safely converting between them as part of the std::arch::wasm32 API if the transmutation is considered too much of a problem. In fact someone recently wrote a more strongly typed WASM SIMD header for C for exactly this reason: https://github.com/nemequ/wav |
This is also one of the major reasons x86 didn't do anything more than the header file, it allows libstd to entirely side-step the question of "what if it were actually nice to use simd?" and instead just provides the tools to build something nice externally (hoping that someone would do so). Now that being said I think that building something nice externally for x86 is a lot more difficult than it is for wasm (at least as wasm simd stands today). I'm personally not entirely sure what the best direction to go in wasm is. The wav project you pointed out I think is the exact API we'd want (more-or-less) in Rust if the goal of The cost of doing something wav-like in this crate (and libstd) is basically just effort for stabilization. It would require much more scrutiny. Additionally I don't think it's obvious/clear that such an abstraction would be able to live on into the future. For example I couldn't say with certainty that all future wasm simd functionality could live in a well-typed API like that. I think that the current state of the I don't really know what to do about any of this myself. I want wasm simd on a track to stable in a reasonable time frame, especially given that engines are picking up steam implementing the proposal. Beyond that though I don't know what the best long-term option is for this module. |
55df6ed
to
f86f39d
Compare
Ok, should be green now! I initially tried to get the |
The original intention of wasm SIMD support was to very closely match
the spec 1:1 to provide low-level primitives. Over time though this has
become less appealing and "niceties" such as
i64x2_shuffle
have beenadded instead of only giving users
i8x16_shuffle
(same thing for*_const
functions).This commit goes through and gives special treatment to all SIMD
intrinsics and instructions for wasm. This performs changes such as:
*_u
and*_s
suffixes are now baked into the intrinsic type,e.g. changing
i16x8
tou16x8
where appropriate.*_const
functions have been added for unsigned types*_replace_lane
functions have been added for unsigned types*_extract_lane
functions have been added for unsigned typesWhile I think it makes sense at the wasm simd spec layer that all these
instructions have the names they do, I've concluded that at the Rust
layer we'll want more understandable names since they're so easy to bind
and are easier to understand when reading/writing code.