Skip to content

Conversation

Kmeakin
Copy link
Contributor

@Kmeakin Kmeakin commented Aug 16, 2025

Save a few instructions in encode_utf8_raw_unchecked by performing manual CSE.

@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 16, 2025
Save a few instructions in `encode_utf8_raw_unchecked` by performing
manual CSE.
@Kmeakin Kmeakin force-pushed the km/optimize-char-encode-utf8 branch from 348abc3 to c9ce45c Compare August 17, 2025 00:40
@the8472
Copy link
Member

the8472 commented Aug 17, 2025

Do you have benchmarks or assembly examples showing that this is better?

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Aug 17, 2025

Do you have benchmarks or assembly examples showing that this is better?

Yes: https://godbolt.org/z/Ysfqn53oK

@Mark-Simulacrum
Copy link
Member

It looks like the old impl would use some vector instructions to assemble the 4-byte wide case on newer CPUs (e.g., see https://godbolt.org/z/G457TP9nW) but I'm not convinced that's a good thing and this seems reasonable enough.

@bors r+ rollup=iffy

@bors
Copy link
Collaborator

bors commented Aug 21, 2025

📌 Commit c9ce45c has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 21, 2025
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 23, 2025
…f8, r=Mark-Simulacrum

Optimize `char::encode_utf8`

Save a few instructions in `encode_utf8_raw_unchecked` by performing manual CSE.
bors added a commit that referenced this pull request Aug 23, 2025
Rollup of 7 pull requests

Successful merges:

 - #144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin)
 - #145307 (Fix `LazyLock` poison panic message)
 - #145515 (Optimize `char::encode_utf8`)
 - #145540 (interpret/allocation: get_range on ProvenanceMap)
 - #145774 (Remove default opts from config)
 - #145780 (Do not warn about missing change ID in tarball builds)
 - #145781 (Remove profile section from Clippy)

r? `@ghost`
`@rustbot` modify labels: rollup
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 23, 2025
…f8, r=Mark-Simulacrum

Optimize `char::encode_utf8`

Save a few instructions in `encode_utf8_raw_unchecked` by performing manual CSE.
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 23, 2025
…f8, r=Mark-Simulacrum

Optimize `char::encode_utf8`

Save a few instructions in `encode_utf8_raw_unchecked` by performing manual CSE.
bors added a commit that referenced this pull request Aug 23, 2025
Rollup of 14 pull requests

Successful merges:

 - #143898 (opt-dist: rebuild rustc when doing static LLVM builds)
 - #144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin)
 - #145234 (match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little))
 - #145515 (Optimize `char::encode_utf8`)
 - #145540 (interpret/allocation: get_range on ProvenanceMap)
 - #145670 (port `sanitize` attribute to the new parsing infrastructure)
 - #145713 (next-solver: fix `feature(const_trait_impl)` bootstrap)
 - #145729 (Remove two duplicated crates)
 - #145744 (miri: also detect aliasing of in-place argument and return place)
 - #145774 (Remove default opts from config)
 - #145781 (Remove profile section from Clippy)
 - #145782 (rustdoc: make attributes render consistently)
 - #145787 (citool: cleanup `mismatched_lifetime_syntaxes` warnings)
 - #145791 (Fix ICE when validating transmuting ZST to inhabited enum)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1b9ae8f into rust-lang:master Aug 24, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 24, 2025
@bors
Copy link
Collaborator

bors commented Aug 24, 2025

⌛ Testing commit c9ce45c with merge f6d2341...

rust-timer added a commit that referenced this pull request Aug 24, 2025
Rollup merge of #145515 - Kmeakin:km/optimize-char-encode-utf8, r=Mark-Simulacrum

Optimize `char::encode_utf8`

Save a few instructions in `encode_utf8_raw_unchecked` by performing manual CSE.
@jhpratt
Copy link
Member

jhpratt commented Aug 24, 2025

@bors r-

github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 24, 2025
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#143898 (opt-dist: rebuild rustc when doing static LLVM builds)
 - rust-lang/rust#144452 (std/sys/fd: Relax `READ_LIMIT` on Darwin)
 - rust-lang/rust#145234 (match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little))
 - rust-lang/rust#145515 (Optimize `char::encode_utf8`)
 - rust-lang/rust#145540 (interpret/allocation: get_range on ProvenanceMap)
 - rust-lang/rust#145670 (port `sanitize` attribute to the new parsing infrastructure)
 - rust-lang/rust#145713 (next-solver: fix `feature(const_trait_impl)` bootstrap)
 - rust-lang/rust#145729 (Remove two duplicated crates)
 - rust-lang/rust#145744 (miri: also detect aliasing of in-place argument and return place)
 - rust-lang/rust#145774 (Remove default opts from config)
 - rust-lang/rust#145781 (Remove profile section from Clippy)
 - rust-lang/rust#145782 (rustdoc: make attributes render consistently)
 - rust-lang/rust#145787 (citool: cleanup `mismatched_lifetime_syntaxes` warnings)
 - rust-lang/rust#145791 (Fix ICE when validating transmuting ZST to inhabited enum)

r? `@ghost`
`@rustbot` modify labels: rollup
@Kmeakin Kmeakin deleted the km/optimize-char-encode-utf8 branch August 24, 2025 11:55
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Aug 26, 2025
…f8, r=Mark-Simulacrum

Optimize `char::encode_utf8`

Save a few instructions in `encode_utf8_raw_unchecked` by performing manual CSE.
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. 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.

6 participants