OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, Google Inc. All rights reserved. | 2 * Copyright (c) 2012, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 // Can only overflow if the signed bit of the two input values differ. If | 67 // Can only overflow if the signed bit of the two input values differ. If |
68 // the signed bit of the result and the first value differ it overflowed. | 68 // the signed bit of the result and the first value differ it overflowed. |
69 | 69 |
70 if ((ua ^ ub) & (result ^ ua) & (1 << 31)) | 70 if ((ua ^ ub) & (result ^ ua) & (1 << 31)) |
71 return std::numeric_limits<int>::max() + (ua >> 31); | 71 return std::numeric_limits<int>::max() + (ua >> 31); |
72 | 72 |
73 return result; | 73 return result; |
74 } | 74 } |
75 | 75 |
| 76 ALWAYS_INLINE int32_t saturatedNegative(int32_t a) |
| 77 { |
| 78 if (UNLIKELY(a == std::numeric_limits<int>::min())) |
| 79 return std::numeric_limits<int>::max(); |
| 80 return -a; |
| 81 } |
| 82 |
76 inline int getMaxSaturatedSetResultForTesting(int FractionalShift) | 83 inline int getMaxSaturatedSetResultForTesting(int FractionalShift) |
77 { | 84 { |
78 // For C version the set function maxes out to max int, this differs from | 85 // For C version the set function maxes out to max int, this differs from |
79 // the ARM asm version, see SaturatedArithmetiARM.h for the equivalent asm | 86 // the ARM asm version, see SaturatedArithmetiARM.h for the equivalent asm |
80 // version. | 87 // version. |
81 return std::numeric_limits<int>::max(); | 88 return std::numeric_limits<int>::max(); |
82 } | 89 } |
83 | 90 |
84 inline int getMinSaturatedSetResultForTesting(int FractionalShift) | 91 inline int getMinSaturatedSetResultForTesting(int FractionalShift) |
85 { | 92 { |
(...skipping 26 matching lines...) Expand all Loading... |
112 std::numeric_limits<int>::max() >> FractionalShift; | 119 std::numeric_limits<int>::max() >> FractionalShift; |
113 | 120 |
114 if (value >= intMaxForLayoutUnit) | 121 if (value >= intMaxForLayoutUnit) |
115 return std::numeric_limits<int>::max(); | 122 return std::numeric_limits<int>::max(); |
116 | 123 |
117 return value << FractionalShift; | 124 return value << FractionalShift; |
118 } | 125 } |
119 | 126 |
120 #endif // CPU(ARM) && COMPILER(GCC) | 127 #endif // CPU(ARM) && COMPILER(GCC) |
121 #endif // SaturatedArithmetic_h | 128 #endif // SaturatedArithmetic_h |
OLD | NEW |