diff options
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index d24d5800a40..0bd309dd087 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/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()); @@ -1996,4 +1991,37 @@ TEST(APIntTest, GCD) { 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(257)); +} + } // end anonymous namespace |