From f97713677aa86f94c24b0fe66c9bad3184b9593d Mon Sep 17 00:00:00 2001 From: greg7mdp Date: Tue, 12 Apr 2022 07:57:28 -0400 Subject: [PATCH] Optimize comparison operators --- include/intx/intx.hpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/include/intx/intx.hpp b/include/intx/intx.hpp index bc1fce7a..7841faf5 100644 --- a/include/intx/intx.hpp +++ b/include/intx/intx.hpp @@ -1211,24 +1211,15 @@ inline constexpr bool operator!=(const T& x, const uint& y) noexcept return uint(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 inline constexpr bool operator<(const uint& x, const uint& y) noexcept { - return subc(x, y).carry; + for (auto i = uint::num_words - 1; i > 0; --i) + { + if (x[i] != y[i]) + return x[i] < y[i]; + } + return x[0] < y[0]; } template