Skip to content

Commit

Permalink
Optimize comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp authored and chfast committed Aug 26, 2022
1 parent e243bfb commit f977136
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions include/intx/intx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,24 +1211,15 @@ inline constexpr bool operator!=(const T& x, const uint<N>& y) noexcept
return uint<N>(x) != y;
}

#if !defined(_MSC_VER) || _MSC_VER < 1916 // This kills MSVC 2017 compiler.
inline constexpr bool operator<(const uint256& x, const uint256& y) noexcept
{
auto xp = uint128{x[2], x[3]};
auto yp = uint128{y[2], y[3]};
if (xp == yp)
{
xp = uint128{x[0], x[1]};
yp = uint128{y[0], y[1]};
}
return xp < yp;
}
#endif

template <unsigned N>
inline constexpr bool operator<(const uint<N>& x, const uint<N>& y) noexcept
{
return subc(x, y).carry;
for (auto i = uint<N>::num_words - 1; i > 0; --i)
{
if (x[i] != y[i])
return x[i] < y[i];
}
return x[0] < y[0];
}

template <unsigned N, typename T,
Expand Down

0 comments on commit f977136

Please sign in to comment.