-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add const-eval support for SIMD types, insert, and extract #64738
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 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
03ac54a
Add const-eval support for SIMD types, insert, and extract
gnzlbg 75d8199
Add a fail test
gnzlbg f0bbd2b
Move tests to SIMD subdirectory
gnzlbg e6239bb
Add some more tests
gnzlbg 3a6e96e
Allow simd_insert and simd_extract in const_fn
gnzlbg 97ce904
Remove unreachable code
gnzlbg 02b3234
Tidy
gnzlbg 5976674
Refactor
gnzlbg e74a268
Test errors
gnzlbg e1cf0a1
Format
gnzlbg 02bfbf9
Clean tests
gnzlbg 5ecb7eb
Remove fail tests
gnzlbg 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![feature(const_fn)] | ||
#![feature(repr_simd)] | ||
#![feature(platform_intrinsics)] | ||
#![allow(non_camel_case_types)] | ||
|
||
#[repr(simd)] struct i8x1(i8); | ||
|
||
extern "platform-intrinsic" { | ||
fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T; | ||
} | ||
|
||
const fn foo(x: i8x1) -> i8 { | ||
// 42 is a i16 that does not fit in a i8 | ||
unsafe { simd_insert(x, 0_u32, 42_i16) }.0 //~ ERROR | ||
} | ||
|
||
fn main() { | ||
const V: i8x1 = i8x1(13); | ||
const X: i8 = foo(V); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/test/ui/consts/const-eval/simd/insert_extract-fail.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,16 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/insert_extract-fail.rs:14:14 | ||
| | ||
LL | unsafe { simd_insert(x, 0_u32, 42_i16) }.0 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| Inserting `i16` with size `2` to a vector element place of size `1` | ||
| inside call to `foo` at $DIR/insert_extract-fail.rs:19:19 | ||
gnzlbg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
... | ||
LL | const X: i8 = foo(V); | ||
| --------------------- | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: aborting due to previous error | ||
|
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,53 @@ | ||
// run-pass | ||
#![feature(const_fn)] | ||
#![feature(repr_simd)] | ||
#![feature(platform_intrinsics)] | ||
#![allow(non_camel_case_types)] | ||
|
||
#[repr(simd)] struct i8x1(i8); | ||
#[repr(simd)] struct u16x2(u16, u16); | ||
#[repr(simd)] struct f32x3(f32, f32, f32); | ||
|
||
extern "platform-intrinsic" { | ||
fn simd_insert<T, U>(x: T, idx: u32, val: U) -> T; | ||
fn simd_extract<T, U>(x: T, idx: u32) -> U; | ||
} | ||
|
||
fn main() { | ||
{ | ||
const U: i8x1 = i8x1(13); | ||
const V: i8x1 = unsafe { simd_insert(U, 0_u32, 42_i8) }; | ||
const X0: i8 = V.0; | ||
const Y0: i8 = unsafe { simd_extract(V, 0) }; | ||
assert_eq!(X0, 42); | ||
assert_eq!(Y0, 42); | ||
} | ||
{ | ||
const U: u16x2 = u16x2(13, 14); | ||
const V: u16x2 = unsafe { simd_insert(U, 1_u32, 42_u16) }; | ||
const X0: u16 = V.0; | ||
const X1: u16 = V.1; | ||
const Y0: u16 = unsafe { simd_extract(V, 0) }; | ||
const Y1: u16 = unsafe { simd_extract(V, 1) }; | ||
assert_eq!(X0, 13); | ||
assert_eq!(X1, 42); | ||
assert_eq!(Y0, 13); | ||
assert_eq!(Y1, 42); | ||
} | ||
{ | ||
const U: f32x3 = f32x3(13., 14., 15.); | ||
const V: f32x3 = unsafe { simd_insert(U, 1_u32, 42_f32) }; | ||
const X0: f32 = V.0; | ||
const X1: f32 = V.1; | ||
const X2: f32 = V.2; | ||
const Y0: f32 = unsafe { simd_extract(V, 0) }; | ||
const Y1: f32 = unsafe { simd_extract(V, 1) }; | ||
const Y2: f32 = unsafe { simd_extract(V, 2) }; | ||
assert_eq!(X0, 13.); | ||
assert_eq!(X1, 42.); | ||
assert_eq!(X2, 15.); | ||
assert_eq!(Y0, 13.); | ||
assert_eq!(Y1, 42.); | ||
assert_eq!(Y2, 15.); | ||
} | ||
} |
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.