[llvm] r298867 - [APInt] Use memset in setAllBits.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 27 10:50:54 PDT 2017
Author: ctopper
Date: Mon Mar 27 12:50:54 2017
New Revision: 298867
URL: http://llvm.org/viewvc/llvm-project?rev=298867&view=rev
Log:
[APInt] Use memset in setAllBits.
Modified:
llvm/trunk/include/llvm/ADT/APInt.h
llvm/trunk/unittests/ADT/APIntTest.cpp
Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=298867&r1=298866&r2=298867&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Mon Mar 27 12:50:54 2017
@@ -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();
}
Modified: llvm/trunk/unittests/ADT/APIntTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/APIntTest.cpp?rev=298867&r1=298866&r2=298867&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp (original)
+++ llvm/trunk/unittests/ADT/APIntTest.cpp Mon Mar 27 12:50:54 2017
@@ -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());
+}
More information about the llvm-commits
mailing list