llvm.org GIT mirror llvm / 31355ac
[APInt] Use memset in setAllBits. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298867 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
2 changed file(s) with 40 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
11631163 void setAllBits() {
11641164 if (isSingleWord())
11651165 VAL = UINT64_MAX;
1166 else {
1166 else
11671167 // Set all the bits in all the words.
1168 for (unsigned i = 0; i < getNumWords(); ++i)
1169 pVal[i] = UINT64_MAX;
1170 }
1168 memset(pVal, -1, getNumWords() * APINT_WORD_SIZE);
11711169 // Clear the unused ones
11721170 clearUnusedBits();
11731171 }
18941894 EXPECT_EQ(0u, i64from63.countTrailingOnes());
18951895 EXPECT_EQ(1u, i64from63.countPopulation());
18961896 }
1897
1898 TEST(APIntTest, setAllBits) {
1899 APInt i32(32, 0);
1900 i32.setAllBits();
1901 EXPECT_EQ(32u, i32.countLeadingOnes());
1902 EXPECT_EQ(0u, i32.countLeadingZeros());
1903 EXPECT_EQ(32u, i32.getActiveBits());
1904 EXPECT_EQ(0u, i32.countTrailingZeros());
1905 EXPECT_EQ(32u, i32.countTrailingOnes());
1906 EXPECT_EQ(32u, i32.countPopulation());
1907
1908 APInt i64(64, 0);
1909 i64.setAllBits();
1910 EXPECT_EQ(64u, i64.countLeadingOnes());
1911 EXPECT_EQ(0u, i64.countLeadingZeros());
1912 EXPECT_EQ(64u, i64.getActiveBits());
1913 EXPECT_EQ(0u, i64.countTrailingZeros());
1914 EXPECT_EQ(64u, i64.countTrailingOnes());
1915 EXPECT_EQ(64u, i64.countPopulation());
1916
1917 APInt i96(96, 0);
1918 i96.setAllBits();
1919 EXPECT_EQ(96u, i96.countLeadingOnes());
1920 EXPECT_EQ(0u, i96.countLeadingZeros());
1921 EXPECT_EQ(96u, i96.getActiveBits());
1922 EXPECT_EQ(0u, i96.countTrailingZeros());
1923 EXPECT_EQ(96u, i96.countTrailingOnes());
1924 EXPECT_EQ(96u, i96.countPopulation());
1925
1926 APInt i128(128, 0);
1927 i128.setAllBits();
1928 EXPECT_EQ(128u, i128.countLeadingOnes());
1929 EXPECT_EQ(0u, i128.countLeadingZeros());
1930 EXPECT_EQ(128u, i128.getActiveBits());
1931 EXPECT_EQ(0u, i128.countTrailingZeros());
1932 EXPECT_EQ(128u, i128.countTrailingOnes());
1933 EXPECT_EQ(128u, i128.countPopulation());
1934 }