forked from OSchip/llvm-project
Express APInt::{s,u}{l,g}e(uint64_t) in terms of APInt::{s,u}{l,g}t(uint64_t). NFC.
This is preparation for http://reviews.llvm.org/D10655: Change APInt comparison with uint64_t. Some unit tests added also. llvm-svn: 240626
This commit is contained in:
parent
7bc44dcb0c
commit
8bebed98a6
|
@ -1070,7 +1070,7 @@ public:
|
|||
/// the validity of the less-or-equal relationship.
|
||||
///
|
||||
/// \returns true if *this <= RHS when considered unsigned.
|
||||
bool ule(uint64_t RHS) const { return ule(APInt(getBitWidth(), RHS)); }
|
||||
bool ule(uint64_t RHS) const { return !ugt(RHS); }
|
||||
|
||||
/// \brief Signed less or equal comparison
|
||||
///
|
||||
|
@ -1086,7 +1086,7 @@ public:
|
|||
/// validity of the less-or-equal relationship.
|
||||
///
|
||||
/// \returns true if *this <= RHS when considered signed.
|
||||
bool sle(uint64_t RHS) const { return sle(APInt(getBitWidth(), RHS)); }
|
||||
bool sle(uint64_t RHS) const { return !sgt(RHS); }
|
||||
|
||||
/// \brief Unsigned greather than comparison
|
||||
///
|
||||
|
@ -1134,7 +1134,7 @@ public:
|
|||
/// the validity of the greater-or-equal relationship.
|
||||
///
|
||||
/// \returns true if *this >= RHS when considered unsigned.
|
||||
bool uge(uint64_t RHS) const { return uge(APInt(getBitWidth(), RHS)); }
|
||||
bool uge(uint64_t RHS) const { return !ult(RHS); }
|
||||
|
||||
/// \brief Signed greather or equal comparison
|
||||
///
|
||||
|
@ -1150,7 +1150,7 @@ public:
|
|||
/// the validity of the greater-or-equal relationship.
|
||||
///
|
||||
/// \returns true if *this >= RHS when considered signed.
|
||||
bool sge(uint64_t RHS) const { return sge(APInt(getBitWidth(), RHS)); }
|
||||
bool sge(uint64_t RHS) const { return !slt(RHS); }
|
||||
|
||||
/// This operation tests if there are any pairs of corresponding bits
|
||||
/// between this APInt and RHS that are both set.
|
||||
|
|
|
@ -215,6 +215,44 @@ TEST(APIntTest, i1) {
|
|||
}
|
||||
}
|
||||
|
||||
TEST(APIntTest, compare) {
|
||||
std::array<APInt, 5> testVals{{
|
||||
APInt{16, 2},
|
||||
APInt{16, 1},
|
||||
APInt{16, 0},
|
||||
APInt{16, (uint64_t)-1, true},
|
||||
APInt{16, (uint64_t)-2, true},
|
||||
}};
|
||||
|
||||
for (auto &arg1 : testVals)
|
||||
for (auto &arg2 : testVals) {
|
||||
auto uv1 = arg1.getZExtValue();
|
||||
auto uv2 = arg2.getZExtValue();
|
||||
auto sv1 = arg1.getSExtValue();
|
||||
auto sv2 = arg2.getSExtValue();
|
||||
|
||||
EXPECT_EQ(uv1 < uv2, arg1.ult(arg2));
|
||||
EXPECT_EQ(uv1 <= uv2, arg1.ule(arg2));
|
||||
EXPECT_EQ(uv1 > uv2, arg1.ugt(arg2));
|
||||
EXPECT_EQ(uv1 >= uv2, arg1.uge(arg2));
|
||||
|
||||
EXPECT_EQ(sv1 < sv2, arg1.slt(arg2));
|
||||
EXPECT_EQ(sv1 <= sv2, arg1.sle(arg2));
|
||||
EXPECT_EQ(sv1 > sv2, arg1.sgt(arg2));
|
||||
EXPECT_EQ(sv1 >= sv2, arg1.sge(arg2));
|
||||
|
||||
EXPECT_EQ(uv1 < uv2, arg1.ult(uv2));
|
||||
EXPECT_EQ(uv1 <= uv2, arg1.ule(uv2));
|
||||
EXPECT_EQ(uv1 > uv2, arg1.ugt(uv2));
|
||||
EXPECT_EQ(uv1 >= uv2, arg1.uge(uv2));
|
||||
|
||||
EXPECT_EQ(sv1 < sv2, arg1.slt(sv2));
|
||||
EXPECT_EQ(sv1 <= sv2, arg1.sle(sv2));
|
||||
EXPECT_EQ(sv1 > sv2, arg1.sgt(sv2));
|
||||
EXPECT_EQ(sv1 >= sv2, arg1.sge(sv2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Tests different div/rem varaints using scheme (a * b + c) / a
|
||||
void testDiv(APInt a, APInt b, APInt c) {
|
||||
|
|
Loading…
Reference in New Issue