summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-03-07 02:19:45 +0000
committerCraig Topper <craig.topper@gmail.com>2017-03-07 02:19:45 +0000
commitdfd9131db385a5c7d3961c5b389daf457bc32a2e (patch)
tree0effd3a462edb74938c3e9f71216193aff69a41b /llvm/unittests/ADT
parentbafdd03b55b1d770dc13f3fb04d398d00480a260 (diff)
downloadbcm5719-llvm-dfd9131db385a5c7d3961c5b389daf457bc32a2e.tar.gz
bcm5719-llvm-dfd9131db385a5c7d3961c5b389daf457bc32a2e.zip
[APInt] Implement getLowBitsSet/getHighBitsSet/getBitsSet using setLowBits/setHighBits/setBits
This patch implements getLowBitsSet/getHighBitsSet/getBitsSet in terms of the new setLowBits/setHighBits/setBits methods by making an all 0s APInt and then calling the appropriate set method. This also adds support to setBits to allow loBits/hiBits to be in the other order to match with getBitsSet behavior. Differential Revision: https://reviews.llvm.org/D30563 llvm-svn: 297112
Diffstat (limited to 'llvm/unittests/ADT')
-rw-r--r--llvm/unittests/ADT/APIntTest.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 8a9c4ebc9c7..ad0cf42fb31 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -1557,6 +1557,24 @@ TEST(APIntTest, getLowBitsSet) {
}
TEST(APIntTest, getHighBitsSet) {
+ APInt i64hi1lo1 = APInt::getBitsSet(64, 63, 1);
+ EXPECT_EQ(1u, i64hi1lo1.countLeadingOnes());
+ EXPECT_EQ(0u, i64hi1lo1.countLeadingZeros());
+ EXPECT_EQ(64u, i64hi1lo1.getActiveBits());
+ EXPECT_EQ(0u, i64hi1lo1.countTrailingZeros());
+ EXPECT_EQ(1u, i64hi1lo1.countTrailingOnes());
+ EXPECT_EQ(2u, i64hi1lo1.countPopulation());
+
+ APInt i127hi1lo1 = APInt::getBitsSet(127, 126, 1);
+ EXPECT_EQ(1u, i127hi1lo1.countLeadingOnes());
+ EXPECT_EQ(0u, i127hi1lo1.countLeadingZeros());
+ EXPECT_EQ(127u, i127hi1lo1.getActiveBits());
+ EXPECT_EQ(0u, i127hi1lo1.countTrailingZeros());
+ EXPECT_EQ(1u, i127hi1lo1.countTrailingOnes());
+ EXPECT_EQ(2u, i127hi1lo1.countPopulation());
+}
+
+TEST(APIntTest, getBitsSet) {
APInt i64hi32 = APInt::getHighBitsSet(64, 32);
EXPECT_EQ(32u, i64hi32.countLeadingOnes());
EXPECT_EQ(0u, i64hi32.countLeadingZeros());
OpenPOWER on IntegriCloud