Add saturation arithmetic support to FractionalLayoutUnit
authoreae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2012 00:14:00 +0000 (00:14 +0000)
committereae@chromium.org <eae@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2012 00:14:00 +0000 (00:14 +0000)
commit0d46b3f12b414a7ad7676978af3d43bc9100e9ab
tree5aed54dbaa58d32261291b94e09d3022dafbe4ba
parent5ebd4e803a6a84e0fda814cdbf8b5167f09a719f
Add saturation arithmetic support to FractionalLayoutUnit
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: https://svn.webkit.org/repository/webkit/trunk@126509 268f45cc-cd09-0410-ab3c-d52691b4dbfc
18 files changed:
Source/WTF/ChangeLog
Source/WTF/GNUmakefile.list.am
Source/WTF/WTF.gypi
Source/WTF/WTF.pro
Source/WTF/WTF.vcproj/WTF.vcproj
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/CMakeLists.txt
Source/WTF/wtf/Platform.h
Source/WTF/wtf/SaturatedArithmetic.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/FractionalLayoutUnit.h
Tools/ChangeLog
Tools/TestWebKitAPI/CMakeLists.txt
Tools/TestWebKitAPI/GNUmakefile.am
Tools/TestWebKitAPI/TestWebKitAPI.gypi
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WTF/SaturatedArithmeticOperations.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj