Skip to content
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

Fix x86 extract_epi{8,16} functions #868

Merged
merged 1 commit into from
Jun 9, 2020

Conversation

jethrogb
Copy link
Contributor

@jethrogb jethrogb commented Jun 9, 2020

  • Update Intel intrinsics definitions with the latest version
  • Update _mm256_extract_epi{8,16} to match latest definition
  • Fix _mm_extract_epi16 sign extension

Fixes #867

* Update Intel intrinsics definitions with the latest version
* Update _mm256_extract_epi{8,16} to match latest definition
* Fix _mm_extract_epi16 sign extension

Fixes rust-lang#867
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @gnzlbg (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@@ -3743,9 +3743,9 @@ pub unsafe fn _mm256_xor_si256(a: __m256i, b: __m256i) -> __m256i {
// This intrinsic has no corresponding instruction.
#[rustc_args_required_const(1)]
#[stable(feature = "simd_x86", since = "1.27.0")]
pub unsafe fn _mm256_extract_epi8(a: __m256i, imm8: i32) -> i8 {
pub unsafe fn _mm256_extract_epi8(a: __m256i, imm8: i32) -> i32 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the change below is technically a breaking change in the public API. However we are fixing the function here to match the definition. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need a crater run at the very least for this. cc @rust-lang/libs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably going to break anyone that uses _mm256_extract_epi8, no?

It seems like this is probably an okay "wontfix" bug, since I think i8 is big enough to hold all possible bit patterns returned here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect most users of these intrinsics to cast the returned value immediately, which would hide the issue.

@Amanieu
Copy link
Member

Amanieu commented Jun 9, 2020

I'm going to merge this for now, let's do a crater run on the PR to update the submodule in rust-lang/rust.

@Amanieu Amanieu merged commit 6a20add into rust-lang:master Jun 9, 2020
@alexcrichton
Copy link
Member

FWIW this blocks further updates to the submodule in rust-lang/rust#74482, so for future crater runs could the rust-lang/rust PR point to a fork with the change? That way the master branch of this repository could be updated by rust-lang/rust PRs as necessary for other features.

alexcrichton added a commit to alexcrichton/stdarch that referenced this pull request Jul 28, 2020
This commit partially reverts rust-lang#868 to restore the intrinsics to their
original implementation to avoid breaking changes. This is done while
rust-lang/rust#73166 is running through crater, and should unblock
rust-lang/rust#74482.
Amanieu pushed a commit that referenced this pull request Jul 28, 2020
This commit partially reverts #868 to restore the intrinsics to their
original implementation to avoid breaking changes. This is done while
rust-lang/rust#73166 is running through crater, and should unblock
rust-lang/rust#74482.
jethrogb pushed a commit to jethrogb/stdsimd that referenced this pull request Sep 8, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 15, 2020
Update stdarch

This PR **changes the public signature** of the following functions in `core::arch::{x86, x86_64}`:
```patch
-pub unsafe fn _mm256_extract_epi8(a: __m256i, imm8: i32) -> i8
+pub unsafe fn _mm256_extract_epi8(a: __m256i, imm8: i32) -> i32
-pub unsafe fn _mm256_extract_epi16(a: __m256i, imm8: i32) -> i16
+pub unsafe fn _mm256_extract_epi16(a: __m256i, imm8: i32) -> i32
```

This change is desired so that these signatures
* are similar to those of the 128-bit versions `_mm_extract_epi8` and `_mm_extract_epi16`
* match the Intel definitions for the intrinsics
  * [RFC 2325](https://github.com/rust-lang/rfcs/blob/master/text/2325-stable-simd.md) specifies that the exact vendor function signatures should be used

A [crater run](rust-lang#73166 (comment)) revealed only a single breakage. The [vektor crate](https://github.com/AdamNiederer/vektor/blob/master/src/x86/avx2.rs#L2436-L2472) copied the incorrect signatures in `core` exactly to their own crate. The functions don't seem to be used by anyone anywhere.

Actual breakage is not expected, since due to the nature of the functions, users would generally write `_mm256_extract_epi8(...) as u8` or `_mm256_extract_epi16(...) as u16`.

See rust-lang/stdarch#868. Note that the changes from that stdarch PR have already partially landed in core after rust-lang/stdarch#878. This PR is now only about the remaining changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

x86 Various issues with extract_epiNN functions
6 participants