Skip to content

Commit 00b0d72

Browse files
committed
[libc++] std::cmp_less and other integer comparison functions could be improved with _LIBCPP_ASSUME
1 parent a6083a1 commit 00b0d72

File tree

1 file changed

+7
-10
lines changed
  • libcxx/include/__utility

1 file changed

+7
-10
lines changed

libcxx/include/__utility/cmp.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef _LIBCPP___UTILITY_CMP_H
1010
#define _LIBCPP___UTILITY_CMP_H
1111

12+
#include "__assert"
1213
#include <__config>
1314
#include <__type_traits/integer_traits.h>
1415
#include <__type_traits/is_signed.h>
@@ -28,13 +29,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2829

2930
template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
3031
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_equal(_Tp __t, _Up __u) noexcept {
31-
if constexpr (sizeof(_Tp) < sizeof(int) && sizeof(_Up) < sizeof(int)) {
32-
__builtin_assume(__t < numeric_limits<int>::max() && __u < numeric_limits<int>::max());
32+
if constexpr (sizeof(_Tp) < sizeof(int) && sizeof(_Up) < sizeof(int))
3333
return static_cast<int>(__t) == static_cast<int>(__u);
34-
} else if constexpr (sizeof(_Tp) < sizeof(long long) && sizeof(_Up) < sizeof(long long)) {
35-
__builtin_assume(__t < numeric_limits<long long>::max() && __u < numeric_limits<long long>::max());
34+
else if constexpr (sizeof(_Tp) < sizeof(long long) && sizeof(_Up) < sizeof(long long))
3635
return static_cast<long long>(__t) == static_cast<long long>(__u);
37-
} else if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
36+
else if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
3837
return __t == __u;
3938
else if constexpr (is_signed_v<_Tp>)
4039
return __t < 0 ? false : make_unsigned_t<_Tp>(__t) == __u;
@@ -49,13 +48,11 @@ _LIBCPP_HIDE_FROM_ABI constexpr bool cmp_not_equal(_Tp __t, _Up __u) noexcept {
4948

5049
template <__signed_or_unsigned_integer _Tp, __signed_or_unsigned_integer _Up>
5150
_LIBCPP_HIDE_FROM_ABI constexpr bool cmp_less(_Tp __t, _Up __u) noexcept {
52-
if constexpr (sizeof(_Tp) < sizeof(int) && sizeof(_Up) < sizeof(int)) {
53-
__builtin_assume(__t < numeric_limits<int>::max() && __u < numeric_limits<int>::max());
51+
if constexpr (sizeof(_Tp) < sizeof(int) && sizeof(_Up) < sizeof(int))
5452
return static_cast<int>(__t) < static_cast<int>(__u);
55-
} else if constexpr (sizeof(_Tp) < sizeof(long long) && sizeof(_Up) < sizeof(long long)) {
56-
__builtin_assume(__t < numeric_limits<long long>::max() && __u < numeric_limits<long long>::max());
53+
else if constexpr (sizeof(_Tp) < sizeof(long long) && sizeof(_Up) < sizeof(long long))
5754
return static_cast<long long>(__t) < static_cast<long long>(__u);
58-
} else if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
55+
else if constexpr (is_signed_v<_Tp> == is_signed_v<_Up>)
5956
return __t < __u;
6057
else if constexpr (is_signed_v<_Tp>)
6158
return __t < 0 ? true : make_unsigned_t<_Tp>(__t) < __u;

0 commit comments

Comments
 (0)