[APInt] Use memset in setAllBits.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298867 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper 2017-03-27 17:50:54 +00:00
parent 91a21c4db6
commit 31355ac435
2 changed files with 40 additions and 4 deletions

View File

@ -1164,11 +1164,9 @@ public:
void setAllBits() {
if (isSingleWord())
VAL = UINT64_MAX;
else {
else
// Set all the bits in all the words.
for (unsigned i = 0; i < getNumWords(); ++i)
pVal[i] = UINT64_MAX;
}
memset(pVal, -1, getNumWords() * APINT_WORD_SIZE);
// Clear the unused ones
clearUnusedBits();
}

View File

@ -1895,3 +1895,41 @@ TEST(APIntTest, setBitsFrom) {
EXPECT_EQ(0u, i64from63.countTrailingOnes());
EXPECT_EQ(1u, i64from63.countPopulation());
}
TEST(APIntTest, setAllBits) {
APInt i32(32, 0);
i32.setAllBits();
EXPECT_EQ(32u, i32.countLeadingOnes());
EXPECT_EQ(0u, i32.countLeadingZeros());
EXPECT_EQ(32u, i32.getActiveBits());
EXPECT_EQ(0u, i32.countTrailingZeros());
EXPECT_EQ(32u, i32.countTrailingOnes());
EXPECT_EQ(32u, i32.countPopulation());
APInt i64(64, 0);
i64.setAllBits();
EXPECT_EQ(64u, i64.countLeadingOnes());
EXPECT_EQ(0u, i64.countLeadingZeros());
EXPECT_EQ(64u, i64.getActiveBits());
EXPECT_EQ(0u, i64.countTrailingZeros());
EXPECT_EQ(64u, i64.countTrailingOnes());
EXPECT_EQ(64u, i64.countPopulation());
APInt i96(96, 0);
i96.setAllBits();
EXPECT_EQ(96u, i96.countLeadingOnes());
EXPECT_EQ(0u, i96.countLeadingZeros());
EXPECT_EQ(96u, i96.getActiveBits());
EXPECT_EQ(0u, i96.countTrailingZeros());
EXPECT_EQ(96u, i96.countTrailingOnes());
EXPECT_EQ(96u, i96.countPopulation());
APInt i128(128, 0);
i128.setAllBits();
EXPECT_EQ(128u, i128.countLeadingOnes());
EXPECT_EQ(0u, i128.countLeadingZeros());
EXPECT_EQ(128u, i128.getActiveBits());
EXPECT_EQ(0u, i128.countTrailingZeros());
EXPECT_EQ(128u, i128.countTrailingOnes());
EXPECT_EQ(128u, i128.countPopulation());
}