From a8a4f0db792b077adfbebfe41801c7dc9ebf23e8 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 18 Apr 2017 04:39:48 +0000 Subject: [APInt] Make operator<<= shift in place. Improve the implementation of tcShiftLeft and use it to implement operator<<=. llvm-svn: 300526 --- llvm/unittests/ADT/APIntTest.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'llvm/unittests/ADT/APIntTest.cpp') diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 0bd309dd087..0f1d2d6d8f9 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -2024,4 +2024,37 @@ TEST(APIntTest, LogicalRightShift) { EXPECT_EQ(0, neg_one.lshr(257)); } +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(-1), true); + EXPECT_EQ(0, neg_one.shl(257)); +} + } // end anonymous namespace -- cgit v1.2.3