-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow simd_shuffle to accept vectors of any length #88855
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/test/ui/simd-intrinsic/simd-intrinsic-generic-shuffle.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// build-fail | ||
|
||
// Test that the simd_shuffle intrinsic produces ok-ish error | ||
// messages when misused. | ||
|
||
#![feature(repr_simd, platform_intrinsics)] | ||
|
||
#[repr(simd)] | ||
#[derive(Copy, Clone)] | ||
pub struct Simd<T, const N: usize>([T; N]); | ||
|
||
extern "platform-intrinsic" { | ||
fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U; | ||
} | ||
|
||
fn main() { | ||
const I: [u32; 2] = [0; 2]; | ||
const I2: [f32; 2] = [0.; 2]; | ||
let v = Simd::<u32, 4>([0; 4]); | ||
|
||
unsafe { | ||
let _: Simd<u32, 2> = simd_shuffle(v, v, I); | ||
|
||
let _: Simd<u32, 4> = simd_shuffle(v, v, I); | ||
//~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic | ||
|
||
let _: Simd<f32, 2> = simd_shuffle(v, v, I); | ||
//~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic | ||
|
||
let _: Simd<u32, 2> = simd_shuffle(v, v, I2); | ||
//~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/simd-intrinsic/simd-intrinsic-generic-shuffle.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 2, found `Simd<u32, 4_usize>` with length 4 | ||
--> $DIR/simd-intrinsic-generic-shuffle.rs:24:31 | ||
| | ||
LL | let _: Simd<u32, 4> = simd_shuffle(v, v, I); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `u32` (element of input `Simd<u32, 4_usize>`), found `Simd<f32, 2_usize>` with element type `f32` | ||
--> $DIR/simd-intrinsic-generic-shuffle.rs:27:31 | ||
| | ||
LL | let _: Simd<f32, 2> = simd_shuffle(v, v, I); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: simd_shuffle index must be an array of `u32`, got `[f32; 2]` | ||
--> $DIR/simd-intrinsic-generic-shuffle.rs:30:31 | ||
| | ||
LL | let _: Simd<u32, 2> = simd_shuffle(v, v, I2); | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0511`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//run-pass | ||
#![feature(repr_simd, platform_intrinsics)] | ||
|
||
extern "platform-intrinsic" { | ||
fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U; | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(simd)] | ||
struct Simd<T, const N: usize>([T; N]); | ||
|
||
trait Shuffle<const N: usize> { | ||
const I: [u32; N]; | ||
|
||
unsafe fn shuffle<T, const M: usize>(&self, a: Simd<T, M>, b: Simd<T, M>) -> Simd<T, N> { | ||
simd_shuffle(a, b, Self::I) | ||
} | ||
} | ||
|
||
fn main() { | ||
struct I1; | ||
impl Shuffle<4> for I1 { | ||
const I: [u32; 4] = [0, 2, 4, 6]; | ||
} | ||
|
||
struct I2; | ||
impl Shuffle<2> for I2 { | ||
const I: [u32; 2] = [1, 5]; | ||
} | ||
|
||
let a = Simd::<u8, 4>([0, 1, 2, 3]); | ||
let b = Simd::<u8, 4>([4, 5, 6, 7]); | ||
unsafe { | ||
let x: Simd<u8, 4> = I1.shuffle(a, b); | ||
assert_eq!(x.0, [0, 2, 4, 6]); | ||
|
||
let y: Simd<u8, 2> = I2.shuffle(a, b); | ||
assert_eq!(y.0, [1, 5]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//run-pass | ||
#![feature(repr_simd, platform_intrinsics)] | ||
|
||
extern "platform-intrinsic" { | ||
fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U; | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(simd)] | ||
struct Simd<T, const N: usize>([T; N]); | ||
|
||
fn main() { | ||
const I1: [u32; 4] = [0, 2, 4, 6]; | ||
const I2: [u32; 2] = [1, 5]; | ||
let a = Simd::<u8, 4>([0, 1, 2, 3]); | ||
let b = Simd::<u8, 4>([4, 5, 6, 7]); | ||
unsafe { | ||
let x: Simd<u8, 4> = simd_shuffle(a, b, I1); | ||
assert_eq!(x.0, [0, 2, 4, 6]); | ||
|
||
let y: Simd<u8, 2> = simd_shuffle(a, b, I2); | ||
assert_eq!(y.0, [1, 5]); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.