Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions stl/inc/limits
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,14 @@ _NODISCARD int _Checked_x86_x64_countr_zero(const _Ty _Val) noexcept {
constexpr _Ty _Max = (numeric_limits<_Ty>::max)();

#ifndef __AVX2__
const bool _Definitely_have_tzcnt = __isa_available >= __ISA_AVAILABLE_AVX2;
if (!_Definitely_have_tzcnt && _Val == 0) {
return _Digits;
// Because the widening done below will always give a non-0 value, checking for tzcnt
// is not required for 8-bit and 16-bit since the only difference in behavior between
// bsf and tzcnt is when the value is 0.
if constexpr (_Digits > 16) {
const bool _Definitely_have_tzcnt = __isa_available >= __ISA_AVAILABLE_AVX2;
if (!_Definitely_have_tzcnt && _Val == 0) {
return _Digits;
}
}
#endif // __AVX2__

Expand Down