Skip to content

Add NonZeroUn::is_power_of_two #81107

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jan 17, 2021
Merged

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jan 17, 2021

This saves instructions on both new and old machines https://rust.godbolt.org/z/4fjTMz

  • On the default x64 target (with no fancy instructions available) it saves a few instructions by not needing to also check for zero.
  • On newer targets (with BMI1) it uses BLSR for super-short assembly.

This can be used for things like checks against alignments stored in NonZeroUsize.

EDIT: New demonstration now that this is available on nightly: https://rust.godbolt.org/z/7bPWxx

This saves instructions on both new and old machines.
@rust-highfive
Copy link
Contributor

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 17, 2021
@kennytm
Copy link
Member

kennytm commented Jan 17, 2021

it's a simple unstable addition, so @bors r+

cc @rust-lang/libs

@bors
Copy link
Collaborator

bors commented Jan 17, 2021

📌 Commit 3e16e92 has been approved by kennytm

@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 Jan 17, 2021
@kennytm
Copy link
Member

kennytm commented Jan 17, 2021

@bors rollup

m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 17, 2021
…=kennytm

Add NonZeroUn::is_power_of_two

This saves instructions on both new and old machines <https://rust.godbolt.org/z/4fjTMz>
- On the default x64 target (with no fancy instructions available) it saves a few instructions by not needing to also check for zero.
- On newer targets (with BMI1) it uses `BLSR` for super-short assembly.

This can be used for things like checks against alignments stored in `NonZeroUsize`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2021
Rollup of 13 pull requests

Successful merges:

 - rust-lang#79298 (correctly deal with late-bound lifetimes in anon consts)
 - rust-lang#80031 (resolve: Reject ambiguity built-in attr vs different built-in attr)
 - rust-lang#80201 (Add benchmark and fast path for BufReader::read_exact)
 - rust-lang#80635 (Improve diagnostics when closure doesn't meet trait bound)
 - rust-lang#80765 (resolve: Simplify collection of traits in scope)
 - rust-lang#80932 (Allow downloading LLVM on Windows and MacOS)
 - rust-lang#80983 (Remove is_dllimport_foreign_item definition from cg_ssa)
 - rust-lang#81064 (Support non-stage0 check)
 - rust-lang#81080 (Force vec![] to expression position only)
 - rust-lang#81082 (BTreeMap: clean up a few more comments)
 - rust-lang#81084 (Use Option::map instead of open-coding it)
 - rust-lang#81095 (Use Option::unwrap_or instead of open-coding it)
 - rust-lang#81107 (Add NonZeroUn::is_power_of_two)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8016846 into rust-lang:master Jan 17, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 17, 2021
@scottmcm scottmcm deleted the nonzero-is_power_of_two branch January 18, 2021 19:33
@jplatte jplatte mentioned this pull request Jan 26, 2021
65 tasks
# for free to join this conversation on GitHub. Already have an account? # 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.

5 participants