Skip to content

Ensure swap_nonoverlapping is really always untyped - #137412

Merged
bors merged 3 commits into
rust-lang:masterfrom
scottmcm:redo-swap
Apr 10, 2025
Merged

Ensure swap_nonoverlapping is really always untyped#137412
bors merged 3 commits into
rust-lang:masterfrom
scottmcm:redo-swap

Conversation

@scottmcm

@scottmcm scottmcm commented Feb 22, 2025

Copy link
Copy Markdown
Member

This replaces #134954, which was arguably overcomplicated.

Fixes #134713

Actually using the type passed to ptr::swap_nonoverlapping for anything other than its size + align turns out to not work, so this goes back to always erasing the types down to just bytes.

(Except in const, which keeps doing the same thing as before to preserve @RalfJung's fix from #134689)

Fixes #134946

I'd previously moved the swapping to use auto-vectorization on bytes, but someone pointed out on Discord that the tail loop handling from that left a whole bunch of byte-by-byte swapping around. This goes back to manual tail handling to avoid that, then still triggers auto-vectorization on pointer-width values. (So you'll see <4 x i64> on x86-64-v3 for example.)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop emitting one-at-a-time byte ops when swapping byte arrays std::ptr::swap_nonoverlapping is not always untyped