Skip to content

Commit 144f83e

Browse files
authored
[libc++] Optimize std::has_single_bit v2.0
1 parent 549d11d commit 144f83e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libcxx/include/__bit/has_single_bit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2525

2626
template <__libcpp_unsigned_integer _Tp>
2727
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_single_bit(_Tp __t) noexcept {
28-
return (__t ^ (__t - 1)) > __t - 1;
28+
return __builtin_popcountg(__t) == 1;
2929
}
3030

3131
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)