-
Notifications
You must be signed in to change notification settings - Fork 3.4k
SIMD extract functions return unexpected types #11419
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
Comments
This is intentional, but is also open for discussion. The idea when first implementing the intrinsics was to match the types of the underlying WebAssembly instructions as closely as possible. WebAssembly doesn't have |
That makes sense to me in theory, but is there any practical benefit? I'm having trouble thinking of examples where it solves a problem. It may be consistent with the WASM types, but it's not consistent with C-level APIs. For example, And, of course, you're much less likely to get a warning from the compiler about implicitly converting to a wider type than to a narrower type. I know clang (at least) has a double-promotion warning which is triggered by assigning a float to a double, but I don't think there is anything similar for assigning, for example, an I guess it just feels like with the current API I'm fighting against the type system, when it should be helping me find bugs. // Possible warning (depending on flags)
int8_t e = wasm_i8x16_extract_lane(v, 0);
// Fix that with a cast.
int8_t e = (int8_t) wasm_i8x16_extract_lane(v, 0);
// That's ugly, but at least it works. Unfortunately, it is too broad
// and creates a dangerous pattern:
int8_t e = (int8_t) wasm_i16x8_extract_lane(v, 0);
// Even without the cast, this generates (or doesn't) the same
// diagnostic as the first one
int8_t e1 = wasm_i16x8_extract_lane(v, 0); These are exactly the sort of issues the type system can help with. I don't see a reason not to let it. |
Yeah, definitely makes sense to me. I'll file an issue on the SIMD repo to see if anyone else has thoughts about this, but I'd be in favor of making this change. |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant. |
This might be intentional, if so sorry for the noise. I really hope not, though.
Most of the integer
wasm_*_extract_lane
function-like macros returnint
or, in the case of i64,long long
. This causes a bit of awkwardness when attempting to use them with-Wimplicit-int-conversion
active. For example,Triggers a diagnostic.
It's straightforward enough to work around with a cast, but I feel like the cast should go in the extract_lane macros in wasm_simd128.h (or maybe even the return type of the builtins it uses), not on the caller side.
CC @tlively since it's a SIMD thing.
The text was updated successfully, but these errors were encountered: