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

Implement checked Shl/Shr on SIMD types #26198

Merged
merged 1 commit into from Jun 20, 2015
Merged

Implement checked Shl/Shr on SIMD types #26198

merged 1 commit into from Jun 20, 2015

Conversation

ghost
Copy link

@ghost ghost commented Jun 11, 2015

When overflow checking on << and >> was added for integers, the << and >> operations broke for SIMD types (u32x4, i16x8, etc.). This PR implements checked shifts on SIMD types.

Fixes #24258.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (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. 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.

@ghost
Copy link
Author

ghost commented Jun 11, 2015

The generated check is somewhat heavy: a checked shift on a u8x16 inspects all 16 elements of the RHS. In general it generates ~2N IR instructions for a checked shift on a uMxN or iMxN.

Is there a better way to check if a vector contains a nonzero element? Or is it not even worth worrying about? The check is only generated when opt-level=0 or debug-assertions is enabled.

@huonw
Copy link
Member

huonw commented Jun 16, 2015

I'm pretty sure there is a better way, but I'm very happy to just merge this as is having opened an issue and adding a FIXME #<the issue number>.

@ghost
Copy link
Author

ghost commented Jun 18, 2015

Figured it out. I didn't know about LLVM's bitcast .. to instruction.

TypeKind::Integer => ICmp(bcx, llvm::IntNE, value, C_null(llty), binop_debug_loc),
TypeKind::Vector => {
let width = llty.vector_length() as u64 * llty.element_type().int_width();
let int_value = BitCast(bcx, value, Type::ix(bcx.ccx(), width));
Copy link
Member

Choose a reason for hiding this comment

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

Neat trick; could you add a comment describing what's happening? ("check non-zeroness by treating the SIMD vector as one large integer and comparing that".)

Copy link
Author

Choose a reason for hiding this comment

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

(Added comment in latest commit)

@huonw
Copy link
Member

huonw commented Jun 19, 2015

Looks great! Could you squash the commits down to one?

@ghost
Copy link
Author

ghost commented Jun 19, 2015

All set.

@huonw
Copy link
Member

huonw commented Jun 19, 2015

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Jun 19, 2015

📌 Commit 837c569 has been approved by huonw

@bors
Copy link
Contributor

bors commented Jun 20, 2015

⌛ Testing commit 837c569 with merge 38d1618...

@bors
Copy link
Contributor

bors commented Jun 20, 2015

💔 Test failed - auto-mac-64-opt

@ghost
Copy link
Author

ghost commented Jun 20, 2015

The core feature was split apart in PR #26192. Rebased against master and replaced #![feature(core)] with #![feature(core_simd)] in the tests.

Running check-stage1 locally right now.

@huonw
Copy link
Member

huonw commented Jun 20, 2015

@bors r+

@bors
Copy link
Contributor

bors commented Jun 20, 2015

📌 Commit 875f50a has been approved by huonw

@bors
Copy link
Contributor

bors commented Jun 20, 2015

⌛ Testing commit 875f50a with merge 84be3ef...

@bors
Copy link
Contributor

bors commented Jun 20, 2015

💔 Test failed - auto-win-gnu-64-nopt-t

@ghost
Copy link
Author

ghost commented Jun 20, 2015

The failure looks similar to the example failure in PR #26382. Now that #26382 has been merged, try again?

@alexcrichton
Copy link
Member

@bors: retry

On Sat, Jun 20, 2015 at 9:34 AM, David Stygstra notifications@github.com
wrote:

The failure looks similar to the example failure in PR #26382
#26382. Now that #26382
#26382 has been merged, try again?


Reply to this email directly or view it on GitHub
#26198 (comment).

@bors
Copy link
Contributor

bors commented Jun 20, 2015

⌛ Testing commit 875f50a with merge cca2817...

bors added a commit that referenced this pull request Jun 20, 2015
When overflow checking on `<<` and `>>` was added for integers, the `<<` and `>>` operations broke for SIMD types (`u32x4`, `i16x8`, etc.). This PR implements checked shifts on SIMD types.

Fixes #24258.
@bors bors merged commit 875f50a into rust-lang:master Jun 20, 2015
@ghost
Copy link
Author

ghost commented Jun 20, 2015

Thanks!

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.

4 participants