Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions stl/inc/__msvc_bit_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ _NODISCARD int _Checked_x86_x64_countr_zero(const _Ty _Val) noexcept {
#define _POPCNT_INTRINSICS_ALWAYS_AVAILABLE 0
#endif // ^^^ intrinsics not always available ^^^
#else // ^^^ intrinsics available / intrinsics unavailable vvv
#define _HAS_POPCNT_INTRINSICS 0
#define _HAS_POPCNT_INTRINSICS 0
#define _POPCNT_INTRINSICS_ALWAYS_AVAILABLE 0
#endif // ^^^ intrinsics unavailable ^^^

#if _HAS_POPCNT_INTRINSICS
Expand Down Expand Up @@ -384,9 +385,7 @@ _CONSTEXPR20 decltype(auto) _Select_popcount_impl(_Fn _Callback) {
return _Callback([](_Ty _Val) _STATIC_LAMBDA { return _Popcount_fallback(_Val); });
}

#undef _HAS_POPCNT_INTRINSICS
#undef _HAS_TZCNT_BSF_INTRINSICS
#undef _POPCNT_INTRINSICS_ALWAYS_AVAILABLE

_STD_END

Expand Down
6 changes: 6 additions & 0 deletions stl/inc/bit
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ _NODISCARD constexpr int countl_zero(_Ty _Val) noexcept;

_EXPORT_STD template <_Standard_unsigned_integral _Ty>
_NODISCARD constexpr bool has_single_bit(const _Ty _Val) noexcept {
#if _POPCNT_INTRINSICS_ALWAYS_AVAILABLE
if (!_STD is_constant_evaluated()) {
return _Unchecked_popcount(_Val) == 1;
}
#endif // ^^^ _POPCNT_INTRINSICS_ALWAYS_AVAILABLE ^^^

return (_Val ^ (_Val - 1)) > _Val - 1;
}

Expand Down