-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Support repr(simd) on ADTs containing a single array field #78863
Conversation
r? @oli-obk (rust_highfive has picked a reviewer for you, use r? to override) |
This PR allows using `#[repr(simd)]` on ADTs containing a single array field: ```rust #[repr(simd)] struct S0([f32; 4]); #[repr(simd)] struct S1<const N: usize>([f32; N]); #[repr(simd)] struct S2<T, const N: usize>([T; N]); ``` This should allow experimenting with portable packed SIMD abstractions on nightly that make use of const generics.
src/test/codegen/simd-intrinsic/simd-intrinsic-generic-extract-insert.rs
Outdated
Show resolved
Hide resolved
src/test/codegen/simd-intrinsic/simd-intrinsic-transmute-array.rs
Outdated
Show resolved
Hide resolved
src/test/ui/simd/simd-intrinsic-generic-arithmetic-saturating.rs
Outdated
Show resolved
Hide resolved
src/test/codegen/simd-intrinsic/simd-intrinsic-generic-extract-insert.rs
Outdated
Show resolved
Hide resolved
src/test/codegen/simd-intrinsic/simd-intrinsic-transmute-array.rs
Outdated
Show resolved
Hide resolved
src/test/ui/simd/simd-intrinsic-generic-arithmetic-saturating.rs
Outdated
Show resolved
Hide resolved
I think |
src/test/codegen/simd-intrinsic/simd-intrinsic-generic-extract-insert.rs
Show resolved
Hide resolved
I've added a compile-fail test for a |
@bors r+ |
📌 Commit e217fc4 has been approved by |
Support repr(simd) on ADTs containing a single array field This is a squash and rebase of `@gnzlbg's` rust-lang#63531 I've never actually written code in the compiler before so just fumbled my way around until it would build 😅 I imagine there'll be some work we need to do in `rustc_codegen_cranelift` too for this now, but might need some input from `@bjorn3` to know what that is. cc `@rust-lang/project-portable-simd` ----- This PR allows using `#[repr(simd)]` on ADTs containing a single array field: ```rust #[repr(simd)] struct S0([f32; 4]); #[repr(simd)] struct S1<const N: usize>([f32; N]); #[repr(simd)] struct S2<T, const N: usize>([T; N]); ``` This should allow experimenting with portable packed SIMD abstractions on nightly that make use of const generics.
This failed in #79122: https://github.com/rust-lang-ci/rust/runs/1410088728 @bors r- |
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}} %{{[0-9]+}}, i8* {{.*}} %3, i64 16, i1 false) | ||
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}} %{{[0-9]+}}, i8* {{.*}} %6, i64 16, i1 false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
14: call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %2, i8* align 4 %3, i32 16, i1 false)
check:25'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:25'1 ? possible intended match
On the i586 platform, it uses i32 here instead, but this test passes on the 64-bit platforms. If this is a pointer size then it needs to be allowed to vary based on platform, I suppose? Or to exclude platforms where it won't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, since these are regex matches we should be able to do something like:
call void @llvm.memcpy.p0i8.p0i8.{{i32|i64}}(i8* {{.*}} %{{[0-9]+}}, i8* {{.*}} %3, {{i32|i64}} 16, i1 false)
I’ll give it a try!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd guess you also want the i16 version for 16-bit targets such as msp430 or avr
@bors try |
💔 Test failed - checks-actions |
@bors r=oli-obk rollup=never |
📌 Commit 90255c8 has been approved by |
⌛ Testing commit 90255c8 with merge 592a105933bbca87806f71c11640a71131c7e949... |
💔 Test failed - checks-actions |
@bors r=oli-obk rollup=never |
📌 Commit 354c7d0 has been approved by |
☀️ Test successful - checks-actions |
This is a squash and rebase of @gnzlbg's #63531
I've never actually written code in the compiler before so just fumbled my way around until it would build 😅
I imagine there'll be some work we need to do in
rustc_codegen_cranelift
too for this now, but might need some input from @bjorn3 to know what that is.cc @rust-lang/project-portable-simd
This PR allows using
#[repr(simd)]
on ADTs containing a single array field:This should allow experimenting with portable packed SIMD abstractions on nightly that make use of const generics.