Skip to content
  • eae@chromium.org's avatar
    Add saturation arithmetic support to FractionalLayoutUnit · 5fcc0d68
    eae@chromium.org authored
    https://bugs.webkit.org/show_bug.cgi?id=94364
    
    Reviewed by Benjamin Poulain.
    
    Source/WebCore:
    
    Add experimental saturation arithmetic support to FractionalLayoutUnit,
    guarded by a flag.
    The idea here is to saturate (or clamp) rather than overflow when
    computing positions and sizes.
    
    No new tests for WebCore, not enabled by default.
    
    * platform/FractionalLayoutUnit.h:
    (WebCore::FractionalLayoutUnit::intMinForLayoutUnit):
    Use INT_MIN instead of -INT_MAX to compute minimum value as the two are
    not the same.
    
    (WebCore::FractionalLayoutUnit::FractionalLayoutUnit):
    (WebCore::FractionalLayoutUnit::fromFloatCeil):
    (WebCore::FractionalLayoutUnit::fromFloatFloor):
    (WebCore::FractionalLayoutUnit::fromFloatRound):
    (WebCore::FractionalLayoutUnit::setValue):
    Add range checks.
    
    (WebCore::operator*):
    (WebCore::operator+):
    (WebCore::operator-):
    (WebCore::operator+=):
    (WebCore::operator-=):
    Use the saturatedAddition and saturatedSubtraction functions, which have
    been optimized to reduce branching, instead of range checks for the most
    common operators.
    
    Source/WTF:
    
    Add support functions for saturated addition and subtraction.
    
    Test: TestWebKitAPI/Tests/WTF/SaturatedArithmeticOperations.cpp
    
    * GNUmakefile.list.am:
    * WTF.gypi:
    * WTF.pro:
    * WTF.vcproj/WTF.vcproj:
    * WTF.xcodeproj/project.pbxproj:
    * WTF/wtf/CMakeLists.txt:
    Add SaturatedArithmetic.h to build files.
    
    * wtf/SaturatedArithmetic.h: Added.
    (saturatedAddition):
    (saturatedSubtraction):
    Support functions for saturated addition/subtraction. Compares the signed
    bit of the values instead of using range checks to reduce branching.
    
    * wtf/Platform.h:
    Add ENABLE_SATURATED_LAYOUT_ARITHMETIC flag.
    
    Tools:
    
    Add test for new saturatedArithmetic functions.
    
    * TestWebKitAPI/CMakeLists.txt:
    * TestWebKitAPI/GNUmakefile.am:
    * TestWebKitAPI/TestWebKitAPI.gypi:
    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/WTF/SaturatedArithmeticOperations.cpp: Added.
    (TestWebKitAPI):
    (TestWebKitAPI::TEST):
    * TestWebKitAPI/win/TestWebKitAPI.vcproj:
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@126509 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    5fcc0d68