| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_NUMERICS_SATURATED_ARITHMETIC_H_ | 5 #ifndef BASE_NUMERICS_SATURATED_ARITHMETIC_H_ |
| 6 #define BASE_NUMERICS_SATURATED_ARITHMETIC_H_ | 6 #define BASE_NUMERICS_SATURATED_ARITHMETIC_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 return result; | 50 return result; |
| 51 } | 51 } |
| 52 | 52 |
| 53 ALWAYS_INLINE int32_t SaturatedNegative(int32_t a) { | 53 ALWAYS_INLINE int32_t SaturatedNegative(int32_t a) { |
| 54 if (UNLIKELY(a == std::numeric_limits<int>::min())) | 54 if (UNLIKELY(a == std::numeric_limits<int>::min())) |
| 55 return std::numeric_limits<int>::max(); | 55 return std::numeric_limits<int>::max(); |
| 56 return -a; | 56 return -a; |
| 57 } | 57 } |
| 58 | 58 |
| 59 ALWAYS_INLINE int32_t SaturatedAbsolute(int32_t a) { |
| 60 if (a >= 0) |
| 61 return a; |
| 62 return SaturatedNegative(a); |
| 63 } |
| 64 |
| 59 ALWAYS_INLINE int GetMaxSaturatedSetResultForTesting(int fractional_shift) { | 65 ALWAYS_INLINE int GetMaxSaturatedSetResultForTesting(int fractional_shift) { |
| 60 // For C version the set function maxes out to max int, this differs from | 66 // For C version the set function maxes out to max int, this differs from |
| 61 // the ARM asm version, see saturated_arithmetic_arm.h for the equivalent asm | 67 // the ARM asm version, see saturated_arithmetic_arm.h for the equivalent asm |
| 62 // version. | 68 // version. |
| 63 return std::numeric_limits<int>::max(); | 69 return std::numeric_limits<int>::max(); |
| 64 } | 70 } |
| 65 | 71 |
| 66 ALWAYS_INLINE int GetMinSaturatedSetResultForTesting(int fractional_shift) { | 72 ALWAYS_INLINE int GetMinSaturatedSetResultForTesting(int fractional_shift) { |
| 67 return std::numeric_limits<int>::min(); | 73 return std::numeric_limits<int>::min(); |
| 68 } | 74 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 92 if (value >= kIntMaxForLayoutUnit) | 98 if (value >= kIntMaxForLayoutUnit) |
| 93 return std::numeric_limits<int>::max(); | 99 return std::numeric_limits<int>::max(); |
| 94 | 100 |
| 95 return value << fractional_shift; | 101 return value << fractional_shift; |
| 96 } | 102 } |
| 97 | 103 |
| 98 } // namespace base | 104 } // namespace base |
| 99 | 105 |
| 100 #endif // CPU(ARM) && COMPILER(GCC) | 106 #endif // CPU(ARM) && COMPILER(GCC) |
| 101 #endif // BASE_NUMERICS_SATURATED_ARITHMETIC_H_ | 107 #endif // BASE_NUMERICS_SATURATED_ARITHMETIC_H_ |
| OLD | NEW |