summaryrefslogtreecommitdiff
path: root/unittests/ADT/APIntTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/ADT/APIntTest.cpp')
-rw-r--r--unittests/ADT/APIntTest.cpp132
1 files changed, 97 insertions, 35 deletions
diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp
index 65481f5b2f220..5d3afe9a159f3 100644
--- a/unittests/ADT/APIntTest.cpp
+++ b/unittests/ADT/APIntTest.cpp
@@ -37,11 +37,6 @@ TEST(APIntTest, i64_ArithmeticRightShiftNegative) {
EXPECT_EQ(neg_one, neg_one.ashr(7));
}
-TEST(APIntTest, i64_LogicalRightShiftNegative) {
- const APInt neg_one(128, static_cast<uint64_t>(-1), true);
- EXPECT_EQ(0, neg_one.lshr(257));
-}
-
TEST(APIntTest, i128_NegativeCount) {
APInt Minus3(128, static_cast<uint64_t>(-3), true);
EXPECT_EQ(126u, Minus3.countLeadingOnes());
@@ -1606,36 +1601,6 @@ TEST(APIntTest, isShiftedMask) {
}
}
-#if defined(__clang__)
-// Disable the pragma warning from versions of Clang without -Wself-move
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunknown-pragmas"
-// Disable the warning that triggers on exactly what is being tested.
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wself-move"
-#endif
-TEST(APIntTest, SelfMoveAssignment) {
- APInt X(32, 0xdeadbeef);
- X = std::move(X);
- EXPECT_EQ(32u, X.getBitWidth());
- EXPECT_EQ(0xdeadbeefULL, X.getLimitedValue());
-
- uint64_t Bits[] = {0xdeadbeefdeadbeefULL, 0xdeadbeefdeadbeefULL};
- APInt Y(128, Bits);
- Y = std::move(Y);
- EXPECT_EQ(128u, Y.getBitWidth());
- EXPECT_EQ(~0ULL, Y.getLimitedValue());
- const uint64_t *Raw = Y.getRawData();
- EXPECT_EQ(2u, Y.getNumWords());
- EXPECT_EQ(0xdeadbeefdeadbeefULL, Raw[0]);
- EXPECT_EQ(0xdeadbeefdeadbeefULL, Raw[1]);
-}
-#if defined(__clang__)
-#pragma clang diagnostic pop
-#pragma clang diagnostic pop
-#endif
-}
-
TEST(APIntTest, reverseBits) {
EXPECT_EQ(1, APInt(1, 1).reverseBits());
EXPECT_EQ(0, APInt(1, 0).reverseBits());
@@ -2025,3 +1990,100 @@ TEST(APIntTest, GCD) {
APInt C = GreatestCommonDivisor(A, B);
EXPECT_EQ(C, HugePrime);
}
+
+TEST(APIntTest, LogicalRightShift) {
+ APInt i256(APInt::getHighBitsSet(256, 2));
+
+ i256.lshrInPlace(1);
+ EXPECT_EQ(1U, i256.countLeadingZeros());
+ EXPECT_EQ(253U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256.lshrInPlace(62);
+ EXPECT_EQ(63U, i256.countLeadingZeros());
+ EXPECT_EQ(191U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256.lshrInPlace(65);
+ EXPECT_EQ(128U, i256.countLeadingZeros());
+ EXPECT_EQ(126U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256.lshrInPlace(64);
+ EXPECT_EQ(192U, i256.countLeadingZeros());
+ EXPECT_EQ(62U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256.lshrInPlace(63);
+ EXPECT_EQ(255U, i256.countLeadingZeros());
+ EXPECT_EQ(0U, i256.countTrailingZeros());
+ EXPECT_EQ(1U, i256.countPopulation());
+
+ // Ensure we handle large shifts of multi-word.
+ const APInt neg_one(128, static_cast<uint64_t>(-1), true);
+ EXPECT_EQ(0, neg_one.lshr(128));
+}
+
+TEST(APIntTest, LeftShift) {
+ APInt i256(APInt::getLowBitsSet(256, 2));
+
+ i256 <<= 1;
+ EXPECT_EQ(253U, i256.countLeadingZeros());
+ EXPECT_EQ(1U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256 <<= 62;
+ EXPECT_EQ(191U, i256.countLeadingZeros());
+ EXPECT_EQ(63U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256 <<= 65;
+ EXPECT_EQ(126U, i256.countLeadingZeros());
+ EXPECT_EQ(128U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256 <<= 64;
+ EXPECT_EQ(62U, i256.countLeadingZeros());
+ EXPECT_EQ(192U, i256.countTrailingZeros());
+ EXPECT_EQ(2U, i256.countPopulation());
+
+ i256 <<= 63;
+ EXPECT_EQ(0U, i256.countLeadingZeros());
+ EXPECT_EQ(255U, i256.countTrailingZeros());
+ EXPECT_EQ(1U, i256.countPopulation());
+
+ // Ensure we handle large shifts of multi-word.
+ const APInt neg_one(128, static_cast<uint64_t>(-1), true);
+ EXPECT_EQ(0, neg_one.shl(128));
+}
+
+TEST(APIntTest, isSubsetOf) {
+ APInt i32_1(32, 1);
+ APInt i32_2(32, 2);
+ APInt i32_3(32, 3);
+ EXPECT_FALSE(i32_3.isSubsetOf(i32_1));
+ EXPECT_TRUE(i32_1.isSubsetOf(i32_3));
+ EXPECT_FALSE(i32_2.isSubsetOf(i32_1));
+ EXPECT_FALSE(i32_1.isSubsetOf(i32_2));
+ EXPECT_TRUE(i32_3.isSubsetOf(i32_3));
+
+ APInt i128_1(128, 1);
+ APInt i128_2(128, 2);
+ APInt i128_3(128, 3);
+ EXPECT_FALSE(i128_3.isSubsetOf(i128_1));
+ EXPECT_TRUE(i128_1.isSubsetOf(i128_3));
+ EXPECT_FALSE(i128_2.isSubsetOf(i128_1));
+ EXPECT_FALSE(i128_1.isSubsetOf(i128_2));
+ EXPECT_TRUE(i128_3.isSubsetOf(i128_3));
+
+ i128_1 <<= 64;
+ i128_2 <<= 64;
+ i128_3 <<= 64;
+ EXPECT_FALSE(i128_3.isSubsetOf(i128_1));
+ EXPECT_TRUE(i128_1.isSubsetOf(i128_3));
+ EXPECT_FALSE(i128_2.isSubsetOf(i128_1));
+ EXPECT_FALSE(i128_1.isSubsetOf(i128_2));
+ EXPECT_TRUE(i128_3.isSubsetOf(i128_3));
+}
+
+} // end anonymous namespace