WebKit Bugzilla
Attachment 350081 Details for
Bug 189633
: Add count() function to OptionSet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189633-20180918173321.patch (text/plain), 5.14 KB, created by
Woodrow Wang
on 2018-09-18 17:33:21 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Woodrow Wang
Created:
2018-09-18 17:33:21 PDT
Size:
5.14 KB
patch
obsolete
>Subversion Revision: 236158 >diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index d308be19282a9a310e8404b1044d05cde49dadce..07a64ba2527f9d25b13ec0adb17e328e617fbb7c 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,21 @@ >+2018-09-18 Woodrow Wang <woodrow_wang@apple.com> >+ >+ Add size() function to OptionSet >+ https://bugs.webkit.org/show_bug.cgi?id=189633 >+ <rdar://problem/44469944> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add countSetBits() function to MathExtras with specialized templates >+ for 32 bit and 64 bit unsigned integers that use optimized >+ machine instructions. >+ >+ * wtf/MathExtras.h: >+ >+ (WTF::countSetBits): >+ * wtf/OptionSet.h: >+ (WTF::OptionSet::size const): >+ > 2018-09-17 Yusuke Suzuki <utatane.tea@gmail.com> > > [WTF] Use Semaphore and BinarySemaphore instead of dispatch_semaphore_t >diff --git a/Source/WTF/wtf/MathExtras.h b/Source/WTF/wtf/MathExtras.h >index 512c160c721a576da63ea968793d9b7a2e8f52fa..d363bca25255ca3891b2fd139da1e9e52bb9a2d7 100644 >--- a/Source/WTF/wtf/MathExtras.h >+++ b/Source/WTF/wtf/MathExtras.h >@@ -575,6 +575,70 @@ inline unsigned clz64(uint64_t number) > #endif > } > >+template<size_t sizeInBytes> struct CountSetBitsFunctor { >+ template<typename T> constexpr unsigned operator()(T number) >+ { >+ unsigned numberOfSetBits = 0; >+ while (number) { >+ number &= number - 1; >+ ++numberOfSetBits; >+ } >+ return numberOfSetBits; >+ } >+}; >+ >+template<> struct CountSetBitsFunctor<4> { >+ template<typename T> constexpr unsigned operator()(T number) >+ { >+#if COMPILER(GCC_OR_CLANG) >+ return __builtin_popcount(number); >+#elif COMPILER(MSVC) >+ return __popcnt(number); >+#else >+ unsigned numberOfSetBits = 0; >+ while (number) { >+ number &= number - 1; >+ ++numberOfSetBits; >+ } >+ return numberOfSetBits; >+#endif >+ } >+}; >+ >+template<> struct CountSetBitsFunctor<8> { >+ template<typename T> constexpr unsigned operator()(T number) >+ { >+#if COMPILER(GCC_OR_CLANG) >+ return __builtin_popcountll(number); >+#elif COMPILER(MSVC) >+ >+#if CPU(X86_64) >+ return __popcnt64(number); >+#elif CPU(X86) >+ constexpr uint32_t upper = number >> 32; >+ constexpr uint32_t lower = number & 0xFFFFFFFF; >+ return __popcnt(upper) + __popcnt(lower); >+#endif >+ >+#else >+ unsigned numberOfSetBits = 0; >+ while (number) { >+ number &= number - 1; >+ ++numberOfSetBits; >+ } >+ return numberOfSetBits; >+#endif >+ } >+}; >+ >+template<typename T> constexpr unsigned countSetBits(T number) >+{ >+ using UnsignedType = typename std::make_unsigned<T>::type; >+ static_assert(sizeof(T) == sizeof(UnsignedType), "Size of unsigned and signed types are the same."); >+ CountSetBitsFunctor<sizeof(UnsignedType)> countSetBitsFunctor; >+ return countSetBitsFunctor(static_cast<UnsignedType>(number)); >+} >+ > } // namespace WTF > > using WTF::opaque; >diff --git a/Source/WTF/wtf/OptionSet.h b/Source/WTF/wtf/OptionSet.h >index f18ff2c9ff6f1fd09bef2443f082223f5ab24c7d..65b8bb55fcc0253ab9c03b29a882788edf39487d 100644 >--- a/Source/WTF/wtf/OptionSet.h >+++ b/Source/WTF/wtf/OptionSet.h >@@ -121,6 +121,11 @@ public: > m_storage &= ~optionSet.m_storage; > } > >+ constexpr unsigned size() const >+ { >+ return WTF::countSetBits(m_storage); >+ } >+ > constexpr friend bool operator==(OptionSet lhs, OptionSet rhs) > { > return lhs.m_storage == rhs.m_storage; >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index c47bbc16318fdab7f8cf9c54ed625f7942e73530..9669c92fa7459cef26e3d3292ce5d6e62f8d83ed 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,16 @@ >+2018-09-18 Woodrow Wang <woodrow_wang@apple.com> >+ >+ Add size() function to OptionSet >+ https://bugs.webkit.org/show_bug.cgi?id=189633 >+ <rdar://problem/44469944> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add a test for new size() function. >+ >+ * TestWebKitAPI/Tests/WTF/OptionSet.cpp: >+ (TestWebKitAPI::TEST): >+ > 2018-08-31 Woodrow Wang <woodrow_wang@apple.com> > > Add infrastructure to dump resource load statistics >diff --git a/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp b/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp >index 493ec25c06f569cd5439c401f82654cf7b7c2b9b..acbde2d4deae4681a20208831a2885ea49db97ed 100644 >--- a/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp >+++ b/Tools/TestWebKitAPI/Tests/WTF/OptionSet.cpp >@@ -436,4 +436,23 @@ TEST(WTF_OptionSet, ContainsAll) > EXPECT_FALSE(set.containsAll({ ExampleFlags::A, ExampleFlags::B, ExampleFlags::C })); > } > >+TEST(WTF_OptionSet, Size) >+{ >+ OptionSet<ExampleFlags> set; >+ >+ EXPECT_EQ(set.size(), 0U); >+ set.add(ExampleFlags::A); >+ EXPECT_EQ(set.size(), 1U); >+ set.remove(ExampleFlags::A); >+ set.add(ExampleFlags::B); >+ EXPECT_EQ(set.size(), 1U); >+ set.remove(ExampleFlags::B); >+ set.add(ExampleFlags::E); >+ EXPECT_EQ(set.size(), 1U); >+ set.add(ExampleFlags::A); >+ EXPECT_EQ(set.size(), 2U); >+ set.add(ExampleFlags::C); >+ EXPECT_EQ(set.size(), 3U); >+} >+ > } // namespace TestWebKitAPI
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
ews-watchlist
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189633
:
349941
|
349946
|
349975
|
349978
|
350056
|
350081
|
350086
|
350134
|
350150
|
350281