| 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 if (UNLIKELY(a == std::numeric_limits<int>::min())) |
| 63 return std::numeric_limits<int>::max(); |
| 64 return -a; |
| 65 } |
| 66 |
| 59 ALWAYS_INLINE int GetMaxSaturatedSetResultForTesting(int fractional_shift) { | 67 ALWAYS_INLINE int GetMaxSaturatedSetResultForTesting(int fractional_shift) { |
| 60 // For C version the set function maxes out to max int, this differs from | 68 // 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 | 69 // the ARM asm version, see saturated_arithmetic_arm.h for the equivalent asm |
| 62 // version. | 70 // version. |
| 63 return std::numeric_limits<int>::max(); | 71 return std::numeric_limits<int>::max(); |
| 64 } | 72 } |
| 65 | 73 |
| 66 ALWAYS_INLINE int GetMinSaturatedSetResultForTesting(int fractional_shift) { | 74 ALWAYS_INLINE int GetMinSaturatedSetResultForTesting(int fractional_shift) { |
| 67 return std::numeric_limits<int>::min(); | 75 return std::numeric_limits<int>::min(); |
| 68 } | 76 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 92 if (value >= kIntMaxForLayoutUnit) | 100 if (value >= kIntMaxForLayoutUnit) |
| 93 return std::numeric_limits<int>::max(); | 101 return std::numeric_limits<int>::max(); |
| 94 | 102 |
| 95 return value << fractional_shift; | 103 return value << fractional_shift; |
| 96 } | 104 } |
| 97 | 105 |
| 98 } // namespace base | 106 } // namespace base |
| 99 | 107 |
| 100 #endif // CPU(ARM) && COMPILER(GCC) | 108 #endif // CPU(ARM) && COMPILER(GCC) |
| 101 #endif // BASE_NUMERICS_SATURATED_ARITHMETIC_H_ | 109 #endif // BASE_NUMERICS_SATURATED_ARITHMETIC_H_ |
| OLD | NEW |