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

Side by Side Diff: base/numerics/saturated_arithmetic.h

Issue 2744423002: Handle large rects better. (Closed)
Patch Set: Add comment and change constant reference. Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/numerics/saturated_arithmetic_arm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « no previous file | base/numerics/saturated_arithmetic_arm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698