Chromium Code Reviews| 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> |
|
Sami
2014/07/09 13:59:26
Could you not calculate |saturate| from |fractiona
picksi
2014/07/09 14:27:52
In the previous version I did exactly this, but wi
|
| +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) |