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)
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

index deaa7f56803c4871dfb2274e9b02cdd51891d9d9..af6f585645998a93eda42835fd85fc018fdb7ede 100644 (file)
@@ -1,3 +1,31 @@
+2012-08-23  Emil A Eklund  <eae@chromium.org>
+
+        Add saturation arithmetic support to FractionalLayoutUnit
+        https://bugs.webkit.org/show_bug.cgi?id=94364
+
+        Reviewed by Benjamin Poulain.
+
+        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.
+
 2012-08-23  Mark Rowe  <mrowe@apple.com>
 
         Roll out part of r126475 that breaks the build with older versions of Clang.
index 7d34ee1b16566f3e5288ecec633f5bbaf541885d..7c123e537554b1857fc9a9266b6c225305953777 100644 (file)
@@ -128,6 +128,7 @@ wtf_sources += \
     Source/WTF/wtf/RetainPtr.h \
     Source/WTF/wtf/SHA1.cpp \
     Source/WTF/wtf/SHA1.h \
+    Source/WTF/wtf/SaturatedArithmetic.h \
     Source/WTF/wtf/SegmentedVector.h \
     Source/WTF/wtf/SentinelLinkedList.h \
     Source/WTF/wtf/SimpleStats.h \
index 5d27970cc1c2c5f2009302c3868a250de3b8d087..531b4381d11f4ef93a4b09f4c6ffce17e505ccce 100644 (file)
@@ -75,6 +75,7 @@
             'wtf/RefPtr.h',
             'wtf/RefPtrHashMap.h',
             'wtf/RetainPtr.h',
+            'wtf/SaturatedArithmetic.h',
             'wtf/SentinelLinkedList.h',
             'wtf/SinglyLinkedList.h',
             'wtf/StackBounds.h',
index d66e29560eb2b950029a6fc85d7d065e653d2fe3..f8223112db75099d252ed9c6b153f4b932b64299 100644 (file)
@@ -119,6 +119,7 @@ HEADERS += \
     RefPtrHashMap.h \
     RetainPtr.h \
     SHA1.h \
+    SaturatedArithmetic.h \
     Spectrum.h \
     StackBounds.h \
     StaticConstructors.h \
index 332a184196b9285109f430a3920a1dd249060c85..959edae34ea48088dabaefd751ef614d2b679707 100644 (file)
                        RelativePath="..\wtf\RetainPtr.h"
                        >
                </File>
+               <File
+                       RelativePath="..\wtf\SaturatedArithmetic.h"
+                       >
+               </File>
                <File
                        RelativePath="..\wtf\SegmentedVector.h"
                        >
index 97e2250b341b2a9a0852e7a4f62837eec850d180..b26784f325995ccb92532559ae7f044d15edaf1b 100644 (file)
@@ -10,6 +10,7 @@
                0FD81AC5154FB22E00983E72 /* FastBitVector.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FD81AC4154FB22E00983E72 /* FastBitVector.h */; settings = {ATTRIBUTES = (); }; };
                143F611F1565F0F900DB514A /* RAMSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143F611D1565F0F900DB514A /* RAMSize.cpp */; };
                143F61201565F0F900DB514A /* RAMSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 143F611E1565F0F900DB514A /* RAMSize.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               14F3B0F715E45E4600210069 /* SaturatedArithmetic.h in Headers */ = {isa = PBXBuildFile; fileRef = 14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2C05385415BC819000F21B96 /* GregorianDateTime.h in Headers */ = {isa = PBXBuildFile; fileRef = 2C05385315BC819000F21B96 /* GregorianDateTime.h */; };
                2CCD892A15C0390200285083 /* GregorianDateTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2CCD892915C0390200285083 /* GregorianDateTime.cpp */; };
                4330F38F15745B0500AAFA8F /* URLString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4330F38E15745B0500AAFA8F /* URLString.cpp */; };
                0FD81AC4154FB22E00983E72 /* FastBitVector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastBitVector.h; sourceTree = "<group>"; };
                143F611D1565F0F900DB514A /* RAMSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RAMSize.cpp; sourceTree = "<group>"; };
                143F611E1565F0F900DB514A /* RAMSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAMSize.h; sourceTree = "<group>"; };
+               14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaturatedArithmetic.h; sourceTree = "<group>"; };
                2C05385315BC819000F21B96 /* GregorianDateTime.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GregorianDateTime.h; sourceTree = "<group>"; };
                2CCD892915C0390200285083 /* GregorianDateTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GregorianDateTime.cpp; sourceTree = "<group>"; };
                4330F38E15745B0500AAFA8F /* URLString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLString.cpp; sourceTree = "<group>"; };
                                A8A47303151A825B004123FF /* RefPtr.h */,
                                A8A47304151A825B004123FF /* RefPtrHashMap.h */,
                                A8A47305151A825B004123FF /* RetainPtr.h */,
+                               14F3B0F615E45E4600210069 /* SaturatedArithmetic.h */,
                                A8A47306151A825B004123FF /* SegmentedVector.h */,
                                A8A47307151A825B004123FF /* SentinelLinkedList.h */,
                                A8A47308151A825B004123FF /* SHA1.cpp */,
                                A8A4741C151A825B004123FF /* RefPtr.h in Headers */,
                                A8A4741D151A825B004123FF /* RefPtrHashMap.h in Headers */,
                                A8A4741E151A825B004123FF /* RetainPtr.h in Headers */,
+                               14F3B0F715E45E4600210069 /* SaturatedArithmetic.h in Headers */,
                                A8A47466151A825B004123FF /* ScriptCodesFromICU.h in Headers */,
                                A8A4741F151A825B004123FF /* SegmentedVector.h in Headers */,
                                A8A47420151A825B004123FF /* SentinelLinkedList.h in Headers */,
index 1f12fb851fcc57b992496e00a6c7e2d30c7aca16..543755904f9d856d39eeb8ad4cc53cad4ff3cae5 100644 (file)
@@ -82,6 +82,7 @@ SET(WTF_HEADERS
     RefPtr.h
     RefPtrHashMap.h
     RetainPtr.h
+    SaturatedArithmetic.h
     SegmentedVector.h
     SHA1.h
     StackBounds.h
index d1383df2932afd994af8114804b8e59cbe484d31..4a4efe846eb55801a8e58beadc7ff7a8ddf21649 100644 (file)
 #endif
 #endif
 
+#if !defined(ENABLE_SATURATED_LAYOUT_ARITHMETIC)
+#define ENABLE_SATURATED_LAYOUT_ARITHMETIC 0
+#endif
+
+#if ENABLE(ENABLE_SATURATED_LAYOUT_ARITHMETIC) && !ENABLE(ENABLE_SUBPIXEL_LAYOUT)
+#error "ENABLE_SATURATED_LAYOUT_ARITHMETIC requires ENABLE_SUBPIXEL_LAYOUT"
+#endif
+
 #define ENABLE_DEBUG_WITH_BREAKPOINT 0
 #define ENABLE_SAMPLING_COUNTERS 0
 #define ENABLE_SAMPLING_FLAGS 0
diff --git a/Source/WTF/wtf/SaturatedArithmetic.h b/Source/WTF/wtf/SaturatedArithmetic.h
new file mode 100644 (file)
index 0000000..cf9e8e1
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2012, Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+#ifndef SaturatedArithmetic_h
+#define SaturatedArithmetic_h
+
+#include <limits>
+#include <stdint.h>
+#include <stdlib.h>
+
+inline int32_t saturatedAddition(int32_t a, int32_t b)
+{
+    uint32_t ua = a;
+    uint32_t ub = b;
+    uint32_t result = ua + ub;
+
+    // Can only overflow if the signed bit of the two values match. If the signed
+    // bit of the result and one of the values differ it did overflow.
+    if (!((ua ^ ub) >> 31) & (result ^ ua) >> 31)
+        result = std::numeric_limits<int>::max() + (ua >> 31);
+
+    return result;
+}
+
+inline int32_t saturatedSubtraction(int32_t a, int32_t b)
+{
+    uint32_t ua = a;
+    uint32_t ub = b;
+    uint32_t result = ua - ub;
+
+    // Can only overflow if the signed bit of the two values do not match. If the
+    // signed bit of the result and the first value differ it did overflow.
+    if ((ua ^ ub) >> 31 & (result ^ ua) >> 31)
+        result = std::numeric_limits<int>::max() + (ua >> 31);
+
+    return result;
+}
+
+#endif // SaturatedArithmetic_h
index bcc90f47be9c8a911809eb296d8e304e667c5fc8..bfe77fe416e5a0e87c7f437f59329fc340ece7d9 100644 (file)
@@ -1,3 +1,55 @@
+2012-08-23  Emil A Eklund  <eae@chromium.org>
+
+        Add saturation arithmetic support to FractionalLayoutUnit
+        https://bugs.webkit.org/show_bug.cgi?id=94364
+
+        Reviewed by Benjamin Poulain.
+
+        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.
+
+2012-08-23  Kenneth Russell  <kbr@google.com>
+
+        Unreviewed, rolling out r126483.
+        http://trac.webkit.org/changeset/126483
+        https://bugs.webkit.org/show_bug.cgi?id=92272
+
+        Caused two Chromium browser_tests to time out 100% reliably.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::init):
+        (WebCore::FrameLoader::prepareForLoadStart):
+        (WebCore::FrameLoader::clearProvisionalLoad):
+        (WebCore::FrameLoader::checkLoadCompleteForThisFrame):
+        (WebCore::FrameLoader::detachFromParent):
+        * loader/FrameLoader.h:
+        (FrameLoader):
+
 2012-08-23  Kentaro Hara  <haraken@chromium.org>
 
         Unreviewed. Just added comments I forgot to add in r126506.
index f6daceac7672be48f71887eaceb3131311efa703..c3bd697d0cc7d2ccf8e75ff42b680bbcfd1405d8 100644 (file)
@@ -36,6 +36,7 @@
 #include <math.h>
 #include <stdlib.h>
 #include <wtf/MathExtras.h>
+#include <wtf/SaturatedArithmetic.h>
 
 #if PLATFORM(QT)
 #include <QDataStream>
@@ -63,7 +64,7 @@ static const int kFixedPointDenominator = 60;
 static const int kFixedPointDenominator = 1;
 #endif
 const int intMaxForLayoutUnit = INT_MAX / kFixedPointDenominator;
-const int intMinForLayoutUnit = -intMaxForLayoutUnit;
+const int intMinForLayoutUnit = INT_MIN / kFixedPointDenominator;
 
 class FractionalLayoutUnit {
 public:
@@ -73,11 +74,27 @@ public:
     
     FractionalLayoutUnit() : m_value(0) { }
 #if ENABLE(SUBPIXEL_LAYOUT)
-    FractionalLayoutUnit(int value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value * kFixedPointDenominator; }
-    FractionalLayoutUnit(unsigned short value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value * kFixedPointDenominator; }
-    FractionalLayoutUnit(unsigned int value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value * kFixedPointDenominator; }
-    FractionalLayoutUnit(float value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value * kFixedPointDenominator; }
-    FractionalLayoutUnit(double value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value * kFixedPointDenominator; }
+    FractionalLayoutUnit(int value) { setValue(value); }
+    FractionalLayoutUnit(unsigned short value) { setValue(value); }
+    FractionalLayoutUnit(unsigned int value) { setValue(value); }
+    FractionalLayoutUnit(float value)
+    {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        m_value = clampTo<float>(value * kFixedPointDenominator, INT_MIN, INT_MAX);
+#else
+        REPORT_OVERFLOW(isInBounds(value));
+        m_value = value * kFixedPointDenominator;
+#endif
+    }
+    FractionalLayoutUnit(double value)
+    {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        m_value = clampTo<double>(value * kFixedPointDenominator, INT_MIN, INT_MAX);
+#else
+        REPORT_OVERFLOW(isInBounds(value));
+        m_value = value * kFixedPointDenominator;
+#endif
+    }
 #else
     FractionalLayoutUnit(int value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; }
     FractionalLayoutUnit(unsigned short value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; }
@@ -89,25 +106,42 @@ public:
 
     static FractionalLayoutUnit fromFloatCeil(float value)
     {
-        REPORT_OVERFLOW(isInBounds(value));
         FractionalLayoutUnit v;
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        v.m_value = clampToInteger(ceilf(value * kFixedPointDenominator));
+#else
+        REPORT_OVERFLOW(isInBounds(value));
         v.m_value = ceilf(value * kFixedPointDenominator);
+#endif
         return v;
     }
 
     static FractionalLayoutUnit fromFloatFloor(float value)
     {
-        REPORT_OVERFLOW(isInBounds(value));
         FractionalLayoutUnit v;
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        v.m_value = clampToInteger(floorf(value * kFixedPointDenominator));
+#else
+        REPORT_OVERFLOW(isInBounds(value));
         v.m_value = floorf(value * kFixedPointDenominator);
+#endif
         return v;
     }
 
     static FractionalLayoutUnit fromFloatRound(float value)
     {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
         if (value >= 0)
+            return clamp(value + epsilon() / 2.0f);
+        return clamp(value - epsilon() / 2.0f);
+#else
+        if (value >= 0) {
+            REPORT_OVERFLOW(isInBounds(value + epsilon() / 2.0f));
             return FractionalLayoutUnit(value + epsilon() / 2.0f);
+        }
+        REPORT_OVERFLOW(isInBounds(value - epsilon() / 2.0f));
         return FractionalLayoutUnit(value - epsilon() / 2.0f);
+#endif
     }
 
 #if ENABLE(SUBPIXEL_LAYOUT)
@@ -143,8 +177,8 @@ public:
         return *this;
     }
 
-    int rawValue() const { return m_value; }
-    void setRawValue(int value) { m_value = value; }
+    inline int rawValue() const { return m_value; }
+    inline void setRawValue(int value) { m_value = value; }
     void setRawValue(long long value)
     {
         REPORT_OVERFLOW(value > std::numeric_limits<int>::min() && value < std::numeric_limits<int>::max());
@@ -214,7 +248,7 @@ public:
     {
         return clampTo<FractionalLayoutUnit>(value, FractionalLayoutUnit::min(), FractionalLayoutUnit::max());
     }
-    
+
 private:
     static bool isInBounds(int value)
     {
@@ -228,6 +262,33 @@ private:
     {
         return ::fabs(value) <= std::numeric_limits<int>::max() / kFixedPointDenominator;
     }
+    
+    inline void setValue(int value)
+    {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        if (value >= intMaxForLayoutUnit)
+            m_value = std::numeric_limits<int>::max();
+        else if (value <= intMinForLayoutUnit)
+            m_value = std::numeric_limits<int>::min();
+        else
+            m_value = value * kFixedPointDenominator;
+#else
+        REPORT_OVERFLOW(isInBounds(value));
+        m_value = value * kFixedPointDenominator;
+#endif
+    }
+    inline void setValue(unsigned value)
+    {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+        if (value >= static_cast<unsigned>(intMaxForLayoutUnit))
+            m_value = std::numeric_limits<int>::max();
+        else
+            m_value = value * kFixedPointDenominator;
+#else
+        REPORT_OVERFLOW(isInBounds(value));
+        m_value = value * kFixedPointDenominator;
+#endif
+    }
 
     int m_value;
 };
@@ -411,7 +472,9 @@ inline FractionalLayoutUnit boundedMultiply(const FractionalLayoutUnit& a, const
 
 inline FractionalLayoutUnit operator*(const FractionalLayoutUnit& a, const FractionalLayoutUnit& b)
 {
-#if ENABLE(SUBPIXEL_LAYOUT)
+#if ENABLE(SUBPIXEL_LAYOUT) && ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+    return boundedMultiply(a, b);
+#elif ENABLE(SUBPIXEL_LAYOUT)
     FractionalLayoutUnit returnVal;
     long long rawVal = static_cast<long long>(a.rawValue()) * b.rawValue() / kFixedPointDenominator;
     returnVal.setRawValue(rawVal);
@@ -516,7 +579,11 @@ inline FractionalLayoutUnit operator/(unsigned int a, const FractionalLayoutUnit
 inline FractionalLayoutUnit operator+(const FractionalLayoutUnit& a, const FractionalLayoutUnit& b)
 {
     FractionalLayoutUnit returnVal;
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+    returnVal.setRawValue(saturatedAddition(a.rawValue(), b.rawValue()));
+#else
     returnVal.setRawValue(a.rawValue() + b.rawValue());
+#endif
     return returnVal;
 }
 
@@ -553,7 +620,11 @@ inline double operator+(const double a, const FractionalLayoutUnit& b)
 inline FractionalLayoutUnit operator-(const FractionalLayoutUnit& a, const FractionalLayoutUnit& b)
 {
     FractionalLayoutUnit returnVal;
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+    returnVal.setRawValue(saturatedSubtraction(a.rawValue(), b.rawValue()));
+#else
     returnVal.setRawValue(a.rawValue() - b.rawValue());
+#endif
     return returnVal;
 }
 
@@ -627,7 +698,11 @@ inline FractionalLayoutUnit operator%(int a, const FractionalLayoutUnit& b)
 
 inline FractionalLayoutUnit& operator+=(FractionalLayoutUnit& a, const FractionalLayoutUnit& b)
 {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+    a.setRawValue(saturatedAddition(a.rawValue(), b.rawValue()));
+#else
     a = a + b;
+#endif
     return a;
 }
 
@@ -657,7 +732,11 @@ inline FractionalLayoutUnit& operator-=(FractionalLayoutUnit& a, int b)
 
 inline FractionalLayoutUnit& operator-=(FractionalLayoutUnit& a, const FractionalLayoutUnit& b)
 {
+#if ENABLE(SATURATED_LAYOUT_ARITHMETIC)
+    a.setRawValue(saturatedSubtraction(a.rawValue(), b.rawValue()));
+#else
     a = a - b;
+#endif
     return a;
 }
 
index a963d61e181d3df55d5144a48cf4578a59a13961..ef1b7ed9990f3ef316eab2a421b532a461fadd3a 100644 (file)
@@ -1,3 +1,21 @@
+2012-08-23  Emil A Eklund  <eae@chromium.org>
+
+        Add saturation arithmetic support to FractionalLayoutUnit
+        https://bugs.webkit.org/show_bug.cgi?id=94364
+
+        Reviewed by Benjamin Poulain.
+
+        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:
+
 2012-08-23  Ryosuke Niwa  <rniwa@webkit.org>
 
         Replay tests take forever to load
index fffbb31bb20561dbcfdfb5ae8180c38b8250ad70..5afadba2b628a2f9b9eec80b18355d7197378df1 100644 (file)
@@ -73,6 +73,7 @@ ADD_EXECUTABLE(test_wtf
     ${TESTWEBKITAPI_DIR}/Tests/WTF/HashMap.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/MetaAllocator.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/RedBlackTree.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WTF/SaturatedArithmeticOperations.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringBuilder.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringImpl.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WTF/StringOperators.cpp
index 0c575d8095c2d4e3770849b8a85e2b2191743546..56f430006df357d060ea9304ab0937d775f63ba4 100644 (file)
@@ -57,6 +57,7 @@ Programs_TestWebKitAPI_TestWTF_SOURCES = \
        Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp \
        Tools/TestWebKitAPI/Tests/WTF/MediaTime.cpp \
        Tools/TestWebKitAPI/Tests/WTF/RedBlackTree.cpp \
+       Tools/TestWebKitAPI/Tests/WTF/SaturatedArithmeticOperations.cpp \
        Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp \
        Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp \
        Tools/TestWebKitAPI/Tests/WTF/StringOperators.cpp \
index 941e776d5f4d01e9b3937ca8ce47f9dd77f45ef7..e85476303cd662a6e333ceaf457248f27b38099c 100644 (file)
@@ -36,6 +36,7 @@
             'Tests/WTF/HashMap.cpp',
             'Tests/WTF/MediaTime.cpp',
             'Tests/WTF/RedBlackTree.cpp',
+            'Tests/WTF/SaturatedArithmeticOperations.cpp',
             'Tests/WTF/StringBuilder.cpp',
             'Tests/WTF/StringOperators.cpp',
             'Tests/WTF/TemporaryChange.cpp',
index 65fe48c67b35c61441c8d31a431eabb4f0e2b100..9576250f24f682a258a72b0ed5e44f95634752d9 100644 (file)
@@ -13,6 +13,7 @@
                0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F17BBD415AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp */; };
                0FC6C4CC141027E0005B7F0C /* RedBlackTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */; };
                0FC6C4CF141034AD005B7F0C /* MetaAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */; };
+               14F3B11315E45EAB00210069 /* SaturatedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */; };
                1A02C84F125D4A8400E3F4BD /* Find.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A02C84E125D4A8400E3F4BD /* Find.cpp */; };
                1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
                1A5FEFDD1270E2A3000E2921 /* EvaluateJavaScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A5FEFDC1270E2A3000E2921 /* EvaluateJavaScript.cpp */; };
                0F17BBD415AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreStatisticsWithNoWebProcess.cpp; sourceTree = "<group>"; };
                0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RedBlackTree.cpp; path = WTF/RedBlackTree.cpp; sourceTree = "<group>"; };
                0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MetaAllocator.cpp; path = WTF/MetaAllocator.cpp; sourceTree = "<group>"; };
+               14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SaturatedArithmeticOperations.cpp; path = WTF/SaturatedArithmeticOperations.cpp; sourceTree = "<group>"; };
                1A02C84B125D4A5E00E3F4BD /* find.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = find.html; sourceTree = "<group>"; };
                1A02C84E125D4A8400E3F4BD /* Find.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Find.cpp; sourceTree = "<group>"; };
                1A5FEFDC1270E2A3000E2921 /* EvaluateJavaScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EvaluateJavaScript.cpp; sourceTree = "<group>"; };
                                1AA9E55714980A9900001A8A /* Functional.cpp */,
                                0BCD833414857CE400EA2003 /* HashMap.cpp */,
                                26B2DFF815BDE599004F691D /* HashSet.cpp */,
+                               14F3B11215E45EAB00210069 /* SaturatedArithmeticOperations.cpp */,
                                81B50192140F232300D9EB58 /* StringBuilder.cpp */,
                                26F1B44315CA434F00D1E4BF /* StringImpl.cpp */,
                                C01363C713C3997300EF3964 /* StringOperators.cpp */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               BC246D8E132F115A00B56D7C /* AboutBlankLoad.cpp in Sources */,
+                               379028B614FABD92007E6B43 /* AcceptsFirstMouse.mm in Sources */,
                                26F1B44415CA434F00D1E4BF /* AtomicString.cpp in Sources */,
+                               B55F11A01516834F00915916 /* AttributedString.mm in Sources */,
+                               00CD9F6315BE312C002DA2CE /* BackForwardList.mm in Sources */,
+                               26DF5A5E15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm in Sources */,
+                               BC246D9A132F1FE100B56D7C /* CanHandleRequest.cpp in Sources */,
+                               A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */,
+                               5142B2711517C88B00C32B19 /* ContextMenuCanCopyURL.mm in Sources */,
+                               F6F3F29113342FEB00A6BF19 /* CookieManager.cpp in Sources */,
                                26A2C72F15E2E73C005B1A14 /* CString.cpp in Sources */,
-                               BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */,
-                               BC131A9B1171316900B69727 /* main.mm in Sources */,
-                               BC131AA9117131FC00B69727 /* TestsController.cpp in Sources */,
-                               BC90955D125548AA00083756 /* PlatformWebViewMac.mm in Sources */,
-                               BC90964C125561BF00083756 /* VectorBasic.cpp in Sources */,
-                               BC90977A125571AB00083756 /* PageLoadBasic.cpp in Sources */,
-                               BC90995E12567BC100083756 /* WKString.cpp in Sources */,
-                               BC9099941256ACF100083756 /* WKStringJSString.cpp in Sources */,
-                               BCBD3710125AA2EB00D2C29F /* FrameMIMETypeHTML.cpp in Sources */,
-                               BCBD3761125ABCFE00D2C29F /* FrameMIMETypePNG.cpp in Sources */,
-                               1A02C84F125D4A8400E3F4BD /* Find.cpp in Sources */,
-                               BCC8B95B12611F4700DE46A4 /* FailedLoad.cpp in Sources */,
-                               C02B77F2126612140026BF0F /* SpacebarScrolling.cpp in Sources */,
-                               BC575AAD126E83B9006F0F12 /* InjectedBundleBasic.cpp in Sources */,
-                               BC575BC0126F5752006F0F12 /* PlatformUtilities.cpp in Sources */,
+                               3776BC63150946BC0043A66D /* DeviceScaleFactorInDashboardRegions.mm in Sources */,
+                               939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
                                BCB68040126FBFE100642A61 /* DocumentStartUserScriptAlertCrash.cpp in Sources */,
+                               37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */,
+                               51393E201523944A005F39C5 /* DOMWindowExtensionBasic.cpp in Sources */,
+                               F6F49C6915545C8E0007F39D /* DOMWindowExtensionNoCache.cpp in Sources */,
+                               C045F9451385C2EA00C0F3CD /* DownloadDecideDestinationCrash.cpp in Sources */,
+                               C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */,
+                               BCAA485814A044D40088FAC4 /* EditorCommands.mm in Sources */,
                                1A5FEFDD1270E2A3000E2921 /* EvaluateJavaScript.cpp in Sources */,
-                               333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */,
-                               BC7B61AA129A038700D174A4 /* WKPreferences.cpp in Sources */,
-                               BC2D004912A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */,
-                               C0ADBE7C12FCA4D000D2C129 /* JavaScriptTest.cpp in Sources */,
-                               C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */,
+                               BCC8B95B12611F4700DE46A4 /* FailedLoad.cpp in Sources */,
+                               1A02C84F125D4A8400E3F4BD /* Find.cpp in Sources */,
                                1ADBEFAE130C689C00D61D19 /* ForceRepaint.cpp in Sources */,
+                               BCBD3710125AA2EB00D2C29F /* FrameMIMETypeHTML.cpp in Sources */,
+                               BCBD3761125ABCFE00D2C29F /* FrameMIMETypePNG.cpp in Sources */,
+                               1AA9E55914980A9900001A8A /* Functional.cpp in Sources */,
+                               C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
+                               F660AA0D15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */,
+                               0BCD833514857CE400EA2003 /* HashMap.cpp in Sources */,
+                               26B2DFF915BDE599004F691D /* HashSet.cpp in Sources */,
                                4BFDFFA9131477770061F24B /* HitTestResultNodeHandle.cpp in Sources */,
-                               C0BD669D131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp in Sources */,
-                               BC246D8E132F115A00B56D7C /* AboutBlankLoad.cpp in Sources */,
-                               BC246D9A132F1FE100B56D7C /* CanHandleRequest.cpp in Sources */,
-                               F6F3F29113342FEB00A6BF19 /* CookieManager.cpp in Sources */,
-                               33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */,
-                               C045F9451385C2EA00C0F3CD /* DownloadDecideDestinationCrash.cpp in Sources */,
-                               37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */,
-                               C01363C813C3997300EF3964 /* StringOperators.cpp in Sources */,
-                               C081224213FC172400DC39AE /* JavaScriptTestMac.mm in Sources */,
-                               C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */,
-                               C07E6CAF13FD67650038B22B /* DynamicDeviceScaleFactor.mm in Sources */,
-                               C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */,
+                               9B4F8FA4159D52B1002D9F94 /* HTMLCollectionNamedItem.mm in Sources */,
+                               9B26FC6C159D061000CC3765 /* HTMLFormCollectionNamedItem.mm in Sources */,
+                               BC575AAD126E83B9006F0F12 /* InjectedBundleBasic.cpp in Sources */,
+                               F660AA1315A619C9003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp in Sources */,
+                               C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */,
                                C08587FC13FEC39B001EF4E5 /* InstanceMethodSwizzler.mm in Sources */,
                                C085880013FEC3A6001EF4E5 /* InstanceMethodSwizzler.mm in Sources */,
-                               37DC678D140D7C5000ABCCDB /* DOMRangeOfString.mm in Sources */,
-                               81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */,
-                               26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */,
-                               0FC6C4CC141027E0005B7F0C /* RedBlackTree.cpp in Sources */,
-                               0FC6C4CF141034AD005B7F0C /* MetaAllocator.cpp in Sources */,
-                               A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */,
-                               939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
-                               3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
+                               C0ADBE7C12FCA4D000D2C129 /* JavaScriptTest.cpp in Sources */,
+                               C081224213FC172400DC39AE /* JavaScriptTestMac.mm in Sources */,
+                               440A1D3914A0103A008A66F2 /* KURL.cpp in Sources */,
+                               52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */,
                                33DC8911141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp in Sources */,
-                               520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */,
+                               BC131A9B1171316900B69727 /* main.mm in Sources */,
+                               CD5497B415857F0C00B5BC30 /* MediaTime.cpp in Sources */,
+                               E1220DA0155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm in Sources */,
+                               517E7DFC15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */,
+                               0FC6C4CF141034AD005B7F0C /* MetaAllocator.cpp in Sources */,
+                               33BE5AF5137B5A6C00705813 /* MouseMoveAfterCrash.cpp in Sources */,
+                               93F1DB3114DA20760024C362 /* NewFirstVisuallyNonEmptyLayout.cpp in Sources */,
+                               93F1DB5514DB1B730024C362 /* NewFirstVisuallyNonEmptyLayoutFails.cpp in Sources */,
+                               93F7E86C14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */,
+                               BC90977A125571AB00083756 /* PageLoadBasic.cpp in Sources */,
+                               BC2D004912A9FDFA00E732A3 /* PageLoadDidChangeLocationWithinPageForFrame.cpp in Sources */,
+                               52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */,
+                               BC575BC0126F5752006F0F12 /* PlatformUtilities.cpp in Sources */,
+                               BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */,
+                               BC90955D125548AA00083756 /* PlatformWebViewMac.mm in Sources */,
+                               333B9CE21277F23100FEFCE3 /* PreventEmptyUserAgent.cpp in Sources */,
                                F6FDDDD314241AD4004F1729 /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */,
-                               C0991C51143C7D68007998F2 /* RetainPtrHashing.cpp in Sources */,
-                               52CB47411448FB9300873995 /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */,
-                               BC3C4C7214575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm in Sources */,
-                               BC3C4C7F14587AA60025FB62 /* WKBrowsingContextGroupTest.mm in Sources */,
-                               C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
-                               0BCD833514857CE400EA2003 /* HashMap.cpp in Sources */,
+                               0FC6C4CC141027E0005B7F0C /* RedBlackTree.cpp in Sources */,
                                3722C8691461E03E00C45D00 /* RenderedImageFromDOMRange.mm in Sources */,
-                               0BCD856A1485C98B00EA2003 /* TemporaryChange.cpp in Sources */,
-                               37A6895F148A9B50005100FA /* SubresourceErrorCrash.mm in Sources */,
+                               C0BD669D131D3CF700E18F2A /* ResponsivenessTimerDoesntFireEarly.cpp in Sources */,
+                               C0ADBE8312FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp in Sources */,
                                BC029B181486AD6400817DA9 /* RetainPtr.cpp in Sources */,
+                               C0991C51143C7D68007998F2 /* RetainPtrHashing.cpp in Sources */,
                                BC029B1C1486B25900817DA9 /* RetainPtr.mm in Sources */,
-                               BC901E241492ADCE0074A667 /* WKConnection.cpp in Sources */,
-                               1AA9E55914980A9900001A8A /* Functional.cpp in Sources */,
-                               BCAA485814A044D40088FAC4 /* EditorCommands.mm in Sources */,
-                               BC55F5F914AD78EE00484BE1 /* Vector.cpp in Sources */,
-                               440A1D3914A0103A008A66F2 /* KURL.cpp in Sources */,
-                               C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */,
-                               52E5CE4614D21E9D003B2BD8 /* ParentFrame.cpp in Sources */,
-                               93F1DB3114DA20760024C362 /* NewFirstVisuallyNonEmptyLayout.cpp in Sources */,
-                               93F1DB5514DB1B730024C362 /* NewFirstVisuallyNonEmptyLayoutFails.cpp in Sources */,
-                               93F7E86C14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */,
-                               BC22D31514DC689800FFB1DD /* UserMessage.cpp in Sources */,
+                               14F3B11315E45EAB00210069 /* SaturatedArithmeticOperations.cpp in Sources */,
+                               261516D615B0E60500A2C201 /* SetAndUpdateCacheModel.mm in Sources */,
+                               52B8CF9615868CF000281053 /* SetDocumentURI.mm in Sources */,
+                               51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */,
+                               C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */,
+                               C02B77F2126612140026BF0F /* SpacebarScrolling.cpp in Sources */,
+                               81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */,
+                               3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
+                               26F1B44515CA434F00D1E4BF /* StringImpl.cpp in Sources */,
+                               C01363C813C3997300EF3964 /* StringOperators.cpp in Sources */,
+                               37A6895F148A9B50005100FA /* SubresourceErrorCrash.mm in Sources */,
+                               C081224513FC19EC00DC39AE /* SyntheticBackingScaleFactorWindow.m in Sources */,
+                               0BCD856A1485C98B00EA2003 /* TemporaryChange.cpp in Sources */,
+                               BC131AA9117131FC00B69727 /* TestsController.cpp in Sources */,
                                E490296814E2E3A4002BEDD1 /* TypingStyleCrash.mm in Sources */,
-                               379028B614FABD92007E6B43 /* AcceptsFirstMouse.mm in Sources */,
-                               3776BC63150946BC0043A66D /* DeviceScaleFactorInDashboardRegions.mm in Sources */,
-                               B55F11A01516834F00915916 /* AttributedString.mm in Sources */,
-                               517E7DFC15110EA600D0B008 /* MemoryCachePruneWithinResourceLoadDelegate.mm in Sources */,
+                               BC22D31514DC689800FFB1DD /* UserMessage.cpp in Sources */,
+                               BC90964C125561BF00083756 /* VectorBasic.cpp in Sources */,
+                               BC55F5F914AD78EE00484BE1 /* Vector.cpp in Sources */,
+                               37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */,
+                               520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */,
+                               0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */,
+                               C08587BF13FE956C001EF4E5 /* WebKitAgnosticTest.mm in Sources */,
                                51FBBB4D1513D4E900822738 /* WebViewCanPasteURL.mm in Sources */,
-                               5142B2711517C88B00C32B19 /* ContextMenuCanCopyURL.mm in Sources */,
-                               C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */,
-                               51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */,
-                               51393E201523944A005F39C5 /* DOMWindowExtensionBasic.cpp in Sources */,
                                76E182DA1547550100F1FADD /* WillSendSubmitEvent.cpp in Sources */,
-                               E1220DA0155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm in Sources */,
-                               F6F49C6915545C8E0007F39D /* DOMWindowExtensionNoCache.cpp in Sources */,
-                               51E93017156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp in Sources */,
-                               52B8CF9615868CF000281053 /* SetDocumentURI.mm in Sources */,
-                               9B26FC6C159D061000CC3765 /* HTMLFormCollectionNamedItem.mm in Sources */,
-                               9B4F8FA4159D52B1002D9F94 /* HTMLCollectionNamedItem.mm in Sources */,
-                               26DF5A5E15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm in Sources */,
-                               F660AA0D15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */,
-                               F660AA1315A619C9003A1243 /* InjectedBundleInitializationUserDataCallbackWins.cpp in Sources */,
-                               0F17BBD615AF6C4D007AB753 /* WebCoreStatisticsWithNoWebProcess.cpp in Sources */,
-                               261516D615B0E60500A2C201 /* SetAndUpdateCacheModel.mm in Sources */,
                                A5E2027315B2181900C13E14 /* WindowlessWebViewWithMedia.mm in Sources */,
-                               26B2DFF915BDE599004F691D /* HashSet.cpp in Sources */,
-                               00CD9F6315BE312C002DA2CE /* BackForwardList.mm in Sources */,
-                               CD5497B415857F0C00B5BC30 /* MediaTime.cpp in Sources */,
+                               BC3C4C7F14587AA60025FB62 /* WKBrowsingContextGroupTest.mm in Sources */,
+                               BC3C4C7214575B6A0025FB62 /* WKBrowsingContextLoadDelegateTest.mm in Sources */,
+                               BC901E241492ADCE0074A667 /* WKConnection.cpp in Sources */,
+                               51E93017156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp in Sources */,
+                               BC7B61AA129A038700D174A4 /* WKPreferences.cpp in Sources */,
+                               BC90995E12567BC100083756 /* WKString.cpp in Sources */,
+                               BC9099941256ACF100083756 /* WKStringJSString.cpp in Sources */,
                                265AF55015D1E48A00B0CB4A /* WTFString.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
diff --git a/Tools/TestWebKitAPI/Tests/WTF/SaturatedArithmeticOperations.cpp b/Tools/TestWebKitAPI/Tests/WTF/SaturatedArithmeticOperations.cpp
new file mode 100644 (file)
index 0000000..e854e25
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2012, Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER 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.
+ */
+
+#include "config.h"
+#include "limits.h"
+#include <wtf/SaturatedArithmetic.h>
+
+namespace TestWebKitAPI {
+
+TEST(WTF, SaturatedArithmeticAddition)
+{
+    ASSERT_EQ(saturatedAddition(0, 0), 0);
+    ASSERT_EQ(saturatedAddition(0, 1), 1);
+    ASSERT_EQ(saturatedAddition(0, 100), 100);
+    ASSERT_EQ(saturatedAddition(100, 50), 150);
+
+    ASSERT_EQ(saturatedAddition(0, -1), -1);
+    ASSERT_EQ(saturatedAddition(1, -1), 0);
+    ASSERT_EQ(saturatedAddition(100, -50), 50);
+    ASSERT_EQ(saturatedAddition(50, -100), -50);
+
+    ASSERT_EQ(saturatedAddition(INT_MAX - 1, 0), INT_MAX - 1);
+    ASSERT_EQ(saturatedAddition(INT_MAX - 1, 1), INT_MAX);
+    ASSERT_EQ(saturatedAddition(INT_MAX - 1, 2), INT_MAX);
+    ASSERT_EQ(saturatedAddition(0, INT_MAX - 1), INT_MAX - 1);
+    ASSERT_EQ(saturatedAddition(1, INT_MAX - 1), INT_MAX);
+    ASSERT_EQ(saturatedAddition(2, INT_MAX - 1), INT_MAX);
+    ASSERT_EQ(saturatedAddition(INT_MAX - 1, INT_MAX - 1), INT_MAX);
+    ASSERT_EQ(saturatedAddition(INT_MAX, INT_MAX), INT_MAX);
+
+    ASSERT_EQ(saturatedAddition(INT_MIN, 0), INT_MIN);
+    ASSERT_EQ(saturatedAddition(INT_MIN + 1, 0), INT_MIN + 1);
+    ASSERT_EQ(saturatedAddition(INT_MIN + 1, 1), INT_MIN + 2);
+    ASSERT_EQ(saturatedAddition(INT_MIN + 1, 2), INT_MIN + 3);
+    ASSERT_EQ(saturatedAddition(INT_MIN + 1, -1), INT_MIN);
+    ASSERT_EQ(saturatedAddition(INT_MIN + 1, -2), INT_MIN);
+    ASSERT_EQ(saturatedAddition(0, INT_MIN + 1), INT_MIN + 1);
+    ASSERT_EQ(saturatedAddition(-1, INT_MIN + 1), INT_MIN);
+    ASSERT_EQ(saturatedAddition(-2, INT_MIN + 1), INT_MIN);
+
+    ASSERT_EQ(saturatedAddition(INT_MAX / 2, 10000), INT_MAX / 2 + 10000);
+    ASSERT_EQ(saturatedAddition(INT_MAX / 2 + 1, INT_MAX / 2 + 1), INT_MAX);
+    ASSERT_EQ(saturatedAddition(INT_MIN, INT_MAX), -1);
+}
+
+TEST(WTF, SaturatedArithmeticSubtraction)
+{
+    ASSERT_EQ(saturatedSubtraction(0, 0), 0);
+    ASSERT_EQ(saturatedSubtraction(0, 1), -1);
+    ASSERT_EQ(saturatedSubtraction(0, 100), -100);
+    ASSERT_EQ(saturatedSubtraction(100, 50), 50);
+    
+    ASSERT_EQ(saturatedSubtraction(0, -1), 1);
+    ASSERT_EQ(saturatedSubtraction(1, -1), 2);
+    ASSERT_EQ(saturatedSubtraction(100, -50), 150);
+    ASSERT_EQ(saturatedSubtraction(50, -100), 150);
+
+    ASSERT_EQ(saturatedSubtraction(INT_MAX, 0), INT_MAX);
+    ASSERT_EQ(saturatedSubtraction(INT_MAX, 1), INT_MAX - 1);
+    ASSERT_EQ(saturatedSubtraction(INT_MAX - 1, 0), INT_MAX - 1);
+    ASSERT_EQ(saturatedSubtraction(INT_MAX - 1, -1), INT_MAX);
+    ASSERT_EQ(saturatedSubtraction(INT_MAX - 1, -2), INT_MAX);
+    ASSERT_EQ(saturatedSubtraction(0, INT_MAX - 1), -INT_MAX + 1);
+    ASSERT_EQ(saturatedSubtraction(-1, INT_MAX - 1), -INT_MAX);
+    ASSERT_EQ(saturatedSubtraction(-2, INT_MAX - 1), -INT_MAX - 1);
+    ASSERT_EQ(saturatedSubtraction(-3, INT_MAX - 1), -INT_MAX - 1);
+
+    ASSERT_EQ(saturatedSubtraction(INT_MIN, 0), INT_MIN);
+    ASSERT_EQ(saturatedSubtraction(INT_MIN + 1, 0), INT_MIN + 1);
+    ASSERT_EQ(saturatedSubtraction(INT_MIN + 1, 1), INT_MIN);
+    ASSERT_EQ(saturatedSubtraction(INT_MIN + 1, 2), INT_MIN);
+
+    ASSERT_EQ(saturatedSubtraction(INT_MIN, INT_MIN), 0);
+    ASSERT_EQ(saturatedSubtraction(INT_MAX, INT_MAX), 0);
+    ASSERT_EQ(saturatedSubtraction(INT_MAX, INT_MIN), INT_MAX);
+}
+
+} // namespace TestWebKitAPI
index a941cd6868b4f0563240761a5266962ff85346d2..01c94b570ba42569c3cd6c0e7b41f3cd1e13c861 100644 (file)
                                        RelativePath="..\Tests\WTF\MediaTime.cpp"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\Tests\WTF\SaturatedArithmeticOperations.cpp"
+                                       >
+                               </File>
                                <File
                                        RelativePath="..\Tests\WTF\StringOperators.cpp"
                                        >