1

Use bitwise XOR in to_ascii_uppercase by redzic · Pull Request #95831 · rust-lan...

 2 years ago
source link: https://github.com/rust-lang/rust/pull/95831
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

@redzic redzic commented 9 days ago

This saves an instruction compared to the previous approach, which
was to unset the fifth bit with bitwise OR.

Comparison of generated assembly on x86: https://godbolt.org/z/GdfvdGs39

This can also affect autovectorization, saving SIMD instructions as well: https://godbolt.org/z/cnPcz75T9

Not sure if u8::to_ascii_lowercase should also be changed, since using bitwise OR for that function does not require an extra bitwise negate since the code is setting a bit rather than unsetting a bit. char::to_ascii_uppercase already uses XOR, so no change seems to be required there.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK