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

Removed redundant shift in std::gcd #3127

Merged
merged 2 commits into from
Oct 12, 2022
Merged

Removed redundant shift in std::gcd #3127

merged 2 commits into from
Oct 12, 2022

Conversation

matt77hias
Copy link
Contributor

No description provided.

@matt77hias matt77hias requested a review from a team as a code owner September 24, 2022 13:40
@StephanTLavavej StephanTLavavej added the performance Must go faster label Sep 25, 2022
Copy link
Contributor

@strega-nil-ms strega-nil-ms left a comment

Choose a reason for hiding this comment

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

Please cache _Countr_zero_impl(_Nx_magnitude). Otherwise, this looks great!

stl/inc/numeric Show resolved Hide resolved
stl/inc/numeric Show resolved Hide resolved
@CaseyCarter
Copy link
Member

I've pushed a change to avoid the redundant _Countr_zero_impl call by breaking in the middle of the loop. This is a large enough change that I've reset the review @strega-nil-ms.

@matt77hias
Copy link
Contributor Author

matt77hias commented Sep 26, 2022

Note that you can also write something like:

const auto _Mx_trailing_zeroes = static_cast<unsigned long>(_Countr_zero_impl(_Mx_magnitude));
const auto _Common_factors_of_2 = static_cast<unsigned long>(_Countr_zero_impl(_Mx_magnitude | _Nx_magnitude));

which I assume to be faster in debug builds as it does not involve a function (<> std::min).

Cfr. https://hbfs.wordpress.com/2013/12/10/the-speed-of-gcd/

@CaseyCarter
Copy link
Member

Note that you can also write something like:

const auto _Mx_trailing_zeroes = static_cast<unsigned long>(_Countr_zero_impl(_Mx_magnitude));
const auto _Common_factors_of_2 = static_cast<unsigned long>(_Countr_zero_impl(_Mx_magnitude | _Nx_magnitude));

which I assume to be faster in debug builds as it does not involve a function (<> std::min).

Doesn't this just replace the call to min with a call to _Countr_zero_impl?

@StephanTLavavej
Copy link
Member

It appears that the MS/GitHub infrastructure is running two different Contributor License Agreement bots (not specific to this PR, the second one appeared fairly recently) and one of them is saying "Contributor License Agreement is not agreed yet", possibly because @CaseyCarter expanded the original 1-line PR beyond the "too tiny to need a CLA" limit.

@matt77hias, have you gotten a link to click-sign the CLA?

@matt77hias
Copy link
Contributor Author

matt77hias commented Sep 27, 2022

Doesn't this just replace the call to min with a call to _Countr_zero_impl?

I would have expected this to map to assembly instructions. My bad.

have you gotten a link to click-sign the CLA?

No, I haven't received a link (not in the thread, not by email).

@StephanTLavavej
Copy link
Member

No, I haven't received a link (not in the thread, not by email).

Ok, thanks. I'm going to try closing and reopening this PR, which in the past has gotten the CLA Bot to rerun its check, at which point it should hopefully send you the link. (Unlike the actual test runs, we don't have any other way to control the CLA Bot.) Let's see if this works...

@matt77hias
Copy link
Contributor Author

@microsoft-github-policy-service agree

@matt77hias
Copy link
Contributor Author

@microsoft-github-policy-service agree

@StephanTLavavej
Copy link
Member

Thanks - the new (blue symbol) license/cla check appears to be green, saying "All CLA requirements met.", so I'm not sure why those "incorrect command" messages were emitted. (This is the first time I've seen the new bot in action.)

I think you're good to go, as the green check should allow us to merge this, after the build+tests pass (they unavoidably run again when a PR is reopened, should take ~25-30 minutes). 😸

@matt77hias
Copy link
Contributor Author

I'm not sure why those "incorrect command" messages were emitted.

I tried (and deleted) @microsoft-github-policy-service agree [company=""] before those messages as well, because I did not receive any kind of acknowledgment for @microsoft-github-policy-service agree from the bot.

@StephanTLavavej
Copy link
Member

Ah, thanks for explaining! I'm guessing that it doesn't reply with a comment for success, instead just turning the check green, but "silence is success" is quite surprising for a comment-driven interface.

Thanks for being a test subject here 😻 - now we'll know what to do the next time a new contributor runs into this bot behavior. 🤖

@AreaZR
Copy link
Contributor

AreaZR commented Oct 11, 2022

Any update on this?

@fsb4000
Copy link
Contributor

fsb4000 commented Oct 11, 2022

Any update on this?

The PR is in "Ready To Merge" stage: https://github.com/microsoft/STL/projects/1

@StephanTLavavej StephanTLavavej self-assigned this Oct 11, 2022
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit a14eac5 into microsoft:main Oct 12, 2022
@StephanTLavavej
Copy link
Member

Thanks for noticing that the performance could be improved here - and congratulations on your first microsoft/STL commit! 🎉 😻 🚀

This will ship in VS 2022 17.5 Preview 2.

@matt77hias matt77hias deleted the patch-1 branch October 12, 2022 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants