Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2641)

Unified Diff: Source/wtf/SaturatedArithmetic.h

Issue 378253003: Saturated arithmetic changed to use templates to fix build-issues (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixing up code layout issues Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/wtf/SaturatedArithmetic.h
diff --git a/Source/wtf/SaturatedArithmetic.h b/Source/wtf/SaturatedArithmetic.h
index ff4ecb3619ec9c15f0def09274a2eaa29134dc21..9cc561e8a8c7511721e9935ca81511b8ba2b5f76 100644
--- a/Source/wtf/SaturatedArithmetic.h
+++ b/Source/wtf/SaturatedArithmetic.h
@@ -86,13 +86,18 @@ inline int getMinSaturatedSetResultForTesting(int FractionalShift)
return std::numeric_limits<int>::min();
}
-ALWAYS_INLINE int saturatedSet(int value, int FractionalShift)
+template<size_t saturate, size_t fractionalShift>
+ALWAYS_INLINE int saturatedSetSigned(int value)
{
+ // This function is implemented as a template to make a common interface
+ // for this and the ARM version, which will only compile under all compilers
+ // if it is implemented as a template specialized with constants.
+
const int intMaxForLayoutUnit =
- std::numeric_limits<int>::max() >> FractionalShift;
+ std::numeric_limits<int>::max() >> fractionalShift;
const int intMinForLayoutUnit =
- std::numeric_limits<int>::min() >> FractionalShift;
+ std::numeric_limits<int>::min() >> fractionalShift;
if (value > intMaxForLayoutUnit)
return std::numeric_limits<int>::max();
@@ -100,19 +105,23 @@ ALWAYS_INLINE int saturatedSet(int value, int FractionalShift)
if (value < intMinForLayoutUnit)
return std::numeric_limits<int>::min();
- return value << FractionalShift;
+ return value << fractionalShift;
}
-
-ALWAYS_INLINE int saturatedSet(unsigned value, int FractionalShift)
+template<size_t saturate, size_t fractionalShift>
+ALWAYS_INLINE int saturatedSetUnsigned(unsigned value)
{
+ // This function is implemented as a template to make a common interface
+ // for this and the ARM version, which will only compile under all compilers
+ // if it is implemented as a template specialized with constants.
+
const unsigned intMaxForLayoutUnit =
- std::numeric_limits<int>::max() >> FractionalShift;
+ std::numeric_limits<int>::max() >> fractionalShift;
if (value >= intMaxForLayoutUnit)
return std::numeric_limits<int>::max();
- return value << FractionalShift;
+ return value << fractionalShift;
}
#endif // CPU(ARM) && COMPILER(GCC)

Powered by Google App Engine
This is Rietveld 408576698