-
Notifications
You must be signed in to change notification settings - Fork 289
Flavorful return types like "uint8x16x2_t" #316
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
I think the last option is the ideal one. A quick look at clang's arm_neon.h suggests that
|
Ok yeah that makes sense to me! In that case I think it's ok for us to take a bit of liberty here and return tuples instead of strictly the structs specified. Although I'd also be ok with fixed size arrays as well! |
I would do what the spec does, that is, option 1. |
Unless there is a good reason not to. Is it? Like if we can make a tuple, we can make a struct right? Or does this tuple need to be magical? |
We'd sort of be defining a new type either way and adding logic to ensure that it matches with the spec no matter what we choose. In that sense I think it's an equal amount of work/verification logic for any choice here, so I figured we'd go with the most ergonomic to consume one. |
A tuple is nicer for Rust destructuring. (Also, since the ARM stuff is already strongly-typed, |
With #![feature(slice_patterns)]
fn main() {
let a = [2, 3, 4];
let [c, d, e]: [i32; 3] = a;
assert_eq!(c, 2);
assert_eq!(d, 3);
assert_eq!(e, 4);
} For what we know, C uses a struct because it cannot return arrays by value ... |
I think sticking to the vendor-defined pattern is the right way forward for this. This gives us the "this is how it's defined upstream" argument when attempting to stabilize. We've also done a similar thing with the Intel intrinsics. We can leave rustification to downstream crates. |
Some intrinsics on NEON like
vtrnq_u8
have a nonstandard return type likeuint8x16x2_t
defined as:How should we best represent this in Rust? A few possible options are:
unsafe fn vtrnq_u8(a: uint8x16_t, b: uint8x16_t) -> uint8x16x2_t;
- aka we define the struct w/ pub fields in Rust like with thelibc
crateunsafe fn vtrnq_u8(a: uint8x16_t, b: uint8x16_t) -> [uint8x16_t; 2]
unsafe fn vtrnq_u8(a: uint8x16_t, b: uint8x16_t) -> (uint8x16_t; uint8x16_6)
I'd sort of lean towards the last one, but it also depends on how "flavorful" the return types get!
The text was updated successfully, but these errors were encountered: