WebKit Bugzilla
Attachment 369791 Details for
Bug 197816
: bitCount() should use popcount where available
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
patch197816 (text/plain), 8.55 KB, created by
Robin Morisset
on 2019-05-13 15:39:48 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Robin Morisset
Created:
2019-05-13 15:39:48 PDT
Size:
8.55 KB
patch
obsolete
>Index: Source/WTF/ChangeLog >=================================================================== >--- Source/WTF/ChangeLog (revision 245195) >+++ Source/WTF/ChangeLog (working copy) >@@ -1,3 +1,15 @@ >+2019-05-13 Robin Morisset <rmorisset@apple.com> >+ >+ bitCount() should use popcount where available >+ https://bugs.webkit.org/show_bug.cgi?id=197816 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Only for GCC and Clang so far, because the MSVC builtins produce undefined behaviour on machines without the right instruction, and testing for it at compile-time is non-trivial. >+ >+ * wtf/StdLibExtras.h: >+ (WTF::bitCount): >+ > 2019-05-10 Fujii Hironori <Hironori.Fujii@sony.com> > > [WinCairo] storage/indexeddb tests are timing out >Index: Source/WTF/wtf/StdLibExtras.h >=================================================================== >--- Source/WTF/wtf/StdLibExtras.h (revision 245195) >+++ Source/WTF/wtf/StdLibExtras.h (working copy) >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2008-2017 Apple Inc. All Rights Reserved. >+ * Copyright (C) 2008-2019 Apple Inc. All Rights Reserved. > * Copyright (C) 2013 Patrick Gansterer <paroga@paroga.com> > * > * Redistribution and use in source and binary forms, with or without >@@ -152,16 +152,25 @@ > } > > // Returns a count of the number of bits set in 'bits'. >-inline size_t bitCount(unsigned bits) >+ALWAYS_INLINE size_t bitCount(unsigned bits) > { >+#if COMPILER(GCC_OR_CLANG) >+ return __builtin_popcount(bits); >+#else > bits = bits - ((bits >> 1) & 0x55555555); > bits = (bits & 0x33333333) + ((bits >> 2) & 0x33333333); > return (((bits + (bits >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; >+#endif > } > >-inline size_t bitCount(uint64_t bits) >+ALWAYS_INLINE size_t bitCount(uint64_t bits) > { >+#if COMPILER(GCC_OR_CLANG) >+ return __builtin_popcountll(bits); >+#else >+ // FIXME: this does not generate optimal code, as it does the entire bitCount() twice, instead of doing it once just with larger constants. > return bitCount(static_cast<unsigned>(bits)) + bitCount(static_cast<unsigned>(bits >> 32)); >+#endif > } > > // Macro that returns a compile time constant with the length of an array, but gives an error if passed a non-array. >Index: Tools/ChangeLog >=================================================================== >--- Tools/ChangeLog (revision 245258) >+++ Tools/ChangeLog (working copy) >@@ -1,3 +1,16 @@ >+2019-05-13 Robin Morisset <rmorisset@apple.com> >+ >+ bitCount() should use popcount where available >+ https://bugs.webkit.org/show_bug.cgi?id=197816 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add tests for bitCount(). >+ >+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: >+ * TestWebKitAPI/Tests/WTF/StdLibExtras.cpp: Added. >+ (TestWebKitAPI::TEST): >+ > 2019-05-12 Yusuke Suzuki <ysuzuki@apple.com> > > [JSC] Compress Watchpoint size by using enum type and Packed<> data structure >Index: Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj >=================================================================== >--- Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (revision 245195) >+++ Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (working copy) >@@ -146,6 +146,7 @@ > 2EFF06D71D8AF34A0004BB30 /* WKWebViewCandidateTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2EFF06D61D8AF34A0004BB30 /* WKWebViewCandidateTests.mm */; }; > 313C3A0221E567C300DBA86E /* SystemPreviewBlobNaming.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */; }; > 315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; }; >+ 33579914228A25EF004972F6 /* StdLibExtras.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33579913228A25D8004972F6 /* StdLibExtras.cpp */; }; > 33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; }; > 33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; }; > 33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */; }; >@@ -1522,6 +1523,7 @@ > 313C3A0121E5677A00DBA86E /* SystemPreviewBlobNaming.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = SystemPreviewBlobNaming.html; sourceTree = "<group>"; }; > 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; }; > 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; }; >+ 33579913228A25D8004972F6 /* StdLibExtras.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StdLibExtras.cpp; sourceTree = "<group>"; }; > 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; }; > 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash_Bundle.cpp; sourceTree = "<group>"; }; > 33DC890E1419539300747EF7 /* simple-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "simple-iframe.html"; sourceTree = "<group>"; }; >@@ -3303,6 +3305,7 @@ > BC9096461255618900083756 /* WTF */ = { > isa = PBXGroup; > children = ( >+ 33579913228A25D8004972F6 /* StdLibExtras.cpp */, > C0991C4F143C7D68007998F2 /* cf */, > E3C21A7821B25C82003B31A3 /* cocoa */, > 7CBBA07519BB8A0900BBF025 /* darwin */, >@@ -3942,6 +3945,7 @@ > 933D631D1FCB76200032ECD6 /* Hasher.cpp in Sources */, > 7C83DED21D0A590C00FEBCF3 /* HashMap.cpp in Sources */, > 7C83DED41D0A590C00FEBCF3 /* HashSet.cpp in Sources */, >+ 33579914228A25EF004972F6 /* StdLibExtras.cpp in Sources */, > 7C83DEE01D0A590C00FEBCF3 /* IntegerToStringConversion.cpp in Sources */, > 7CEB62AB223609DE0069CBB0 /* IteratorRange.cpp in Sources */, > 7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */, >Index: Tools/TestWebKitAPI/Tests/WTF/StdLibExtras.cpp >=================================================================== >--- Tools/TestWebKitAPI/Tests/WTF/StdLibExtras.cpp (nonexistent) >+++ Tools/TestWebKitAPI/Tests/WTF/StdLibExtras.cpp (working copy) >@@ -0,0 +1,46 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+ >+#include <wtf/StdLibExtras.h> >+ >+namespace TestWebKitAPI { >+ >+TEST(WTF_StdLibExtras, bitCount) >+{ >+ EXPECT_EQ(bitCount(0u), 0); >+ EXPECT_EQ(bitCount(1u), 0); >+ EXPECT_EQ(bitCount(42u), 3); >+ EXPECT_EQ(bitCount(static_cast<unsigned>(-1)), 32); >+ >+ EXPECT_EQ(bitCount(0ull), 0); >+ EXPECT_EQ(bitCount(1ull), 0); >+ EXPECT_EQ(bitCount(42ull), 3); >+ EXPECT_EQ(bitCount(1ull << 42), 1); >+ EXPECT_EQ(bitCount(static_cast<unsigned>(-1)), 64); >+} >+ >+}
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:
ysuzuki
:
review-
ysuzuki
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 197816
:
369653
|
369663
| 369791