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

Reuse the mem::swap optimizations to speed up slice::rotate #42819

Merged
merged 1 commit into from
Jun 28, 2017

Conversation

scottmcm
Copy link
Member

This is most helpful for compound types where LLVM didn't vectorize the loop. Highlight: bench slice::rotate_medium_by727_strings gets 38% faster.

Exposes the swapping logic from PR #40454 as pub unsafe fn ptr::swap_nonoverlapping under library feature swap_nonoverlapping #42818.

(The new method seemed plausible, and was the simplest way to share the logic. I'm not attached to it, though, so let me know if a different way would be better.)

Exposes the swapping logic from PR 40454 as `pub unsafe fn ptr::swap_nonoverlapping` under feature swap_nonoverlapping

This is most helpful for compound types where LLVM didn't vectorize the loop.  Highlight: bench slice::rotate_medium_by727_strings gets 38% faster.
@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton alexcrichton added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 22, 2017
@carols10cents
Copy link
Member

friendly ping @sfackler, pinging you on IRC too!

@carols10cents carols10cents removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2017
@sfackler
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 26, 2017

📌 Commit 47fa016 has been approved by sfackler

@bors
Copy link
Contributor

bors commented Jun 26, 2017

⌛ Testing commit 47fa016 with merge 240dcc4d98ed5e20f3d3177ac77debc65aa131e9...

@bors
Copy link
Contributor

bors commented Jun 26, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

@bors: retry

  • osx timed out

@arielb1 arielb1 added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 27, 2017
@bors
Copy link
Contributor

bors commented Jun 28, 2017

⌛ Testing commit 47fa016 with merge 47faf1d...

bors added a commit that referenced this pull request Jun 28, 2017
Reuse the mem::swap optimizations to speed up slice::rotate

This is most helpful for compound types where LLVM didn't vectorize the loop.  Highlight: bench slice::rotate_medium_by727_strings gets 38% faster.

Exposes the swapping logic from PR #40454 as `pub unsafe fn ptr::swap_nonoverlapping` under library feature `swap_nonoverlapping` #42818.

(The new method seemed plausible, and was the simplest way to share the logic.  I'm not attached to it, though, so let me know if a different way would be better.)
@bors
Copy link
Contributor

bors commented Jun 28, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: sfackler
Pushing 47faf1d to master...

@bors bors merged commit 47fa016 into rust-lang:master Jun 28, 2017
@scottmcm scottmcm deleted the swap-nonoverlapping branch July 1, 2017 21:56
pub unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
let x = x as *mut u8;
let y = y as *mut u8;
let len = mem::size_of::<T>() * count;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this use .checked_mul(count).unwrap()?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that's necessary, because of the safety requirement that the arguments refer to valid ranges of memory -- if it's valid, its length must fit in a usize.

cuviper added a commit to cuviper/rust that referenced this pull request Jul 11, 2017
This is a workaround for rust-lang#42778, which was git-bisected to rust-lang#40454's
optimizations to `mem::swap`, later moved to `ptr` in rust-lang#42819.  Natively
compiled rustc couldn't even compile stage1 libcore on powerpc64 and
s390x, but they work fine without this `repr(simd)`.  Since powerpc64le
works OK, it seems probably related to being big-endian.

The underlying problem is not yet known, but this at least makes those
architectures functional again in the meantime.

cc @arielb1
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Jul 15, 2017
Disable big-endian simd in swap_nonoverlapping_bytes

This is a workaround for rust-lang#42778, which was git-bisected to rust-lang#40454's
optimizations to `mem::swap`, later moved to `ptr` in rust-lang#42819.  Natively
compiled rustc couldn't even compile stage1 libcore on powerpc64 and
s390x, but they work fine without this `repr(simd)`.  Since powerpc64le
works OK, it seems probably related to being big-endian.

The underlying problem is not yet known, but this at least makes those
architectures functional again in the meantime.

cc @arielb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants