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

<numeric>: _Countr_zero used by std::gcd has unnecessary zero checks #2292

Closed
AlexGuteniev opened this issue Oct 22, 2021 · 0 comments · Fixed by #2343
Closed

<numeric>: _Countr_zero used by std::gcd has unnecessary zero checks #2292

AlexGuteniev opened this issue Oct 22, 2021 · 0 comments · Fixed by #2343
Labels
fixed Something works now, yay! performance Must go faster

Comments

@AlexGuteniev
Copy link
Contributor

Originally reported as DevCom-1560717

_Countr_zero in this loop has unnecessary checks for zero input in the compiled code:

STL/stl/inc/numeric

Lines 567 to 577 in d8f03cf

_Mx_magnitude >>= _Mx_trailing_zeroes;
do {
_Nx_magnitude >>= static_cast<unsigned long>(_Countr_zero(_Nx_magnitude));
if (_Mx_magnitude > _Nx_magnitude) {
_Common_unsigned _Temp = _Mx_magnitude;
_Mx_magnitude = _Nx_magnitude;
_Nx_magnitude = _Temp;
}
_Nx_magnitude -= _Mx_magnitude;
} while (_Nx_magnitude != 0U);

See the demo with __assume workaround: https://godbolt.org/z/Ts7ExjbYb

As the reported noted, compiler codegen could be improved.

But from the library, it can also be fixed by making specialized _Countr_zero that does not check for zero input, and calling the specialized version from std::gcd.

@AlexGuteniev AlexGuteniev changed the title <numeric>: _Countr_zero used by std:;gcd has unnecessary zero checks <numeric>: _Countr_zero used by std::gcd has unnecessary zero checks Oct 22, 2021
@CaseyCarter CaseyCarter added the performance Must go faster label Oct 22, 2021
AlexGuteniev added a commit to AlexGuteniev/STL that referenced this issue Oct 23, 2021
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Something works now, yay! performance Must go faster
Projects
None yet
3 participants