haikuwebkit/Source/WTF/wtf/StdIntExtras.h

44 lines
1.6 KiB
C
Raw Permalink Normal View History

Allow Bitmap to use up to a UCPURegister word size for internal bit storage. https://bugs.webkit.org/show_bug.cgi?id=211328 <rdar://problem/62755865> Reviewed by Yusuke Suzuki. Source/JavaScriptCore: * assembler/CPU.h: Source/WTF: 1. Moved the definition of CPURegister and UCPURegister down into WTF. Added CPU(REGISTER64) and CPU(REGISTER32) for determining what size a CPU general purpose register is. 2. Updated Bitmap so that it will automatically choose the minimal required word size for the number of bits it needs to store. This means the Bitmap can automatically choose a WordType from uint8_t up to UCPURegister. Previously, the WordType is always uint32_t by default. This should improve perf with use of Bitmap on 64-bit platforms. The size optimization is necessary to prevent bloat on 64-bit platforms which would have resulted if we simply set the default to always be UCPURegister. 3. Added a check in findRunOfZeros() for handling the edge case where the requested runLength exceeds the bitmapSize. 4. Fixed a bug in count() that was unnecessarily casting the bits to unsigned instead of just using the Bitmap WordType. As a result, when using a WordType of uint64_t, it was discarding bits from the count. 5. Fixed invert() to leave the bits beyond bitmapSize untouched. Fixed isFull() to ignore the bits beyond bitmapSize. By fixing invert() to leave those bits as 0, isEmpty() and hash() will continue to work. Otherwise, inverting those bits will cause isEmpty() to always fail, and hash()'s result may be different for the same set of bit values within bitmapSize. isFull(), on the other hand, checks for set bits in the words. Since there may be 0 valued bits beyond bitmapSize, isFull() needs to be fixed to ignore those. * WTF.xcodeproj/project.pbxproj: * wtf/Bitmap.h: (WTF::WordType>::invert): (WTF::WordType>::findRunOfZeros const): (WTF::WordType>::count const): (WTF::WordType>::isFull const): * wtf/CMakeLists.txt: * wtf/PlatformCPU.h: * wtf/PlatformUse.h: * wtf/StdIntExtras.h: Copied from Source/WTF/wtf/StdIntExtras.h. Tools: Added API tests for WTF::Bitmap to make sure that Bitmap is behaving correctly. Since Bitmap is used in critical infrastructure like the GC, it is important to ensure that there are no latent bugs. * TestWebKitAPI/CMakeLists.txt: * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/Bitmap.cpp: Added. (TestWebKitAPI::countBits): (TestWebKitAPI::testBitmapSize): (TestWebKitAPI::testBitmapConstructedEmpty): (TestWebKitAPI::testBitmapSetGet): (TestWebKitAPI::testBitmapTestAndSet): (TestWebKitAPI::testBitmapTestAndClear): (TestWebKitAPI::testBitmapConcurrentTestAndSet): (TestWebKitAPI::testBitmapConcurrentTestAndClear): (TestWebKitAPI::testBitmapClear): (TestWebKitAPI::testBitmapClearAll): (TestWebKitAPI::testBitmapInvert): (TestWebKitAPI::testBitmapFindRunOfZeros): (TestWebKitAPI::testBitmapCount): (TestWebKitAPI::testBitmapIsEmpty): (TestWebKitAPI::testBitmapIsFull): (TestWebKitAPI::testBitmapMerge): (TestWebKitAPI::testBitmapFilter): (TestWebKitAPI::testBitmapExclude): (TestWebKitAPI::testBitmapConcurrentFilter): (TestWebKitAPI::testBitmapSubsumes): (TestWebKitAPI::testBitmapForEachSetBit): (TestWebKitAPI::testBitmapFindBit): (TestWebKitAPI::testBitmapIteration): (TestWebKitAPI::testBitmapMergeAndClear): (TestWebKitAPI::testBitmapSetAndClear): (TestWebKitAPI::testBitmapOperatorEqual): (TestWebKitAPI::testBitmapOperatorNotEqual): (TestWebKitAPI::testBitmapHash): (TestWebKitAPI::TEST): LayoutTests: editing/undo-manager/undo-manager-delete-stale-undo-items.html exposed a bug in this patch. However, when a failure occurs, this test runs perpetually until it times out. There's no need to do this. After a finite number of GC cycles, unreachable objects should be collected. This is especially so because GCController.collect() does a synchronous full GC. Added a cap of 10 GC tries, and fail out if the test does not see the expected result. This allows the test to fail fast and avoid the costly time out. * editing/undo-manager/undo-manager-delete-stale-undo-items.html: Canonical link: https://commits.webkit.org/224352@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261179 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-05 17:08:29 +00:00
/*
* Copyright (C) 2020 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. ``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
* 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.
*/
#pragma once
#include <cstdint>
namespace WTF {
#if CPU(REGISTER64)
using CPURegister = int64_t;
using UCPURegister = uint64_t;
#else
using CPURegister = int32_t;
using UCPURegister = uint32_t;
#endif
} // namespace WTF
using WTF::CPURegister;
using WTF::UCPURegister;