Skip to content

Commit f977136

Browse files
greg7mdpchfast
authored andcommitted
Optimize comparison operators
1 parent e243bfb commit f977136

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

include/intx/intx.hpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,24 +1211,15 @@ inline constexpr bool operator!=(const T& x, const uint<N>& y) noexcept
12111211
return uint<N>(x) != y;
12121212
}
12131213

1214-
#if !defined(_MSC_VER) || _MSC_VER < 1916 // This kills MSVC 2017 compiler.
1215-
inline constexpr bool operator<(const uint256& x, const uint256& y) noexcept
1216-
{
1217-
auto xp = uint128{x[2], x[3]};
1218-
auto yp = uint128{y[2], y[3]};
1219-
if (xp == yp)
1220-
{
1221-
xp = uint128{x[0], x[1]};
1222-
yp = uint128{y[0], y[1]};
1223-
}
1224-
return xp < yp;
1225-
}
1226-
#endif
1227-
12281214
template <unsigned N>
12291215
inline constexpr bool operator<(const uint<N>& x, const uint<N>& y) noexcept
12301216
{
1231-
return subc(x, y).carry;
1217+
for (auto i = uint<N>::num_words - 1; i > 0; --i)
1218+
{
1219+
if (x[i] != y[i])
1220+
return x[i] < y[i];
1221+
}
1222+
return x[0] < y[0];
12321223
}
12331224

12341225
template <unsigned N, typename T,

0 commit comments

Comments
 (0)