forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#88855 - calebzulawski:feature/simd_shuffle,…
… r=nagisa Allow simd_shuffle to accept vectors of any length cc `@rust-lang/project-portable-simd` `@workingjubilee`
- Loading branch information
Showing
14 changed files
with
171 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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]); | ||
} | ||
} |