diff options
| author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2023-01-03 16:10:06 +0000 | 
|---|---|---|
| committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2023-01-03 16:10:29 +0000 | 
| commit | ad3e0e4b419461bbc56a79a33167e93141ba5859 (patch) | |
| tree | 154a66dfdcb761d2a183009f89270bfedaa9fb66 /llvm/unittests/ADT/APIntTest.cpp | |
| parent | e60b0d2a2227a3fa299884bc3388baecdd4c88e6 (diff) | |
| download | llvm-ad3e0e4b419461bbc56a79a33167e93141ba5859.zip llvm-ad3e0e4b419461bbc56a79a33167e93141ba5859.tar.gz llvm-ad3e0e4b419461bbc56a79a33167e93141ba5859.tar.bz2 | |
[APInt] Add APInt::isOneBitSet helper.
Equivalent tester for the APInt::getOneBitSet builder.
This should allow us to remove a number of cases where we're doing "Val == (1 << BitNo)" style code patterns.
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
| -rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 10 | 
1 files changed, 10 insertions, 0 deletions
| diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index e7632c0..0377e05 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -1793,6 +1793,16 @@ TEST(APIntTest, isShiftedMask) {    }  } +TEST(APIntTest, isOneBitSet) { +  EXPECT_FALSE(APInt(5, 0x00).isOneBitSet(0)); +  EXPECT_FALSE(APInt(5, 0x02).isOneBitSet(0)); +  EXPECT_FALSE(APInt(5, 0x03).isOneBitSet(0)); +  EXPECT_TRUE(APInt(5, 0x02).isOneBitSet(1)); +  EXPECT_TRUE(APInt(32, (unsigned)(0xffu << 31)).isOneBitSet(31)); + +  EXPECT_TRUE(APInt::getOneBitSet(255, 13).isOneBitSet(13)); +} +  TEST(APIntTest, isPowerOf2) {    EXPECT_FALSE(APInt(5, 0x00).isPowerOf2());    EXPECT_FALSE(APInt(32, 0x11).isPowerOf2()); | 
