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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // the ARM asm version, see SaturatedArithmetiARM.h for the equivalent asm | 79 // the ARM asm version, see SaturatedArithmetiARM.h for the equivalent asm |
80 // version. | 80 // version. |
81 return std::numeric_limits<int>::max(); | 81 return std::numeric_limits<int>::max(); |
82 } | 82 } |
83 | 83 |
84 inline int getMinSaturatedSetResultForTesting(int FractionalShift) | 84 inline int getMinSaturatedSetResultForTesting(int FractionalShift) |
85 { | 85 { |
86 return std::numeric_limits<int>::min(); | 86 return std::numeric_limits<int>::min(); |
87 } | 87 } |
88 | 88 |
89 ALWAYS_INLINE int saturatedSet(int value, int FractionalShift) | 89 template<size_t saturate, size_t fractionalShift> |
| 90 ALWAYS_INLINE int saturatedSetSigned(int value) |
90 { | 91 { |
| 92 // This function is implemented as a template to make a common interface |
| 93 // for this and the ARM version, which will only compile under all compilers |
| 94 // if it is implemented as a template specialized with constants. |
| 95 |
91 const int intMaxForLayoutUnit = | 96 const int intMaxForLayoutUnit = |
92 std::numeric_limits<int>::max() >> FractionalShift; | 97 std::numeric_limits<int>::max() >> fractionalShift; |
93 | 98 |
94 const int intMinForLayoutUnit = | 99 const int intMinForLayoutUnit = |
95 std::numeric_limits<int>::min() >> FractionalShift; | 100 std::numeric_limits<int>::min() >> fractionalShift; |
96 | 101 |
97 if (value > intMaxForLayoutUnit) | 102 if (value > intMaxForLayoutUnit) |
98 return std::numeric_limits<int>::max(); | 103 return std::numeric_limits<int>::max(); |
99 | 104 |
100 if (value < intMinForLayoutUnit) | 105 if (value < intMinForLayoutUnit) |
101 return std::numeric_limits<int>::min(); | 106 return std::numeric_limits<int>::min(); |
102 | 107 |
103 return value << FractionalShift; | 108 return value << fractionalShift; |
104 } | 109 } |
105 | 110 |
| 111 template<size_t saturate, size_t fractionalShift> |
| 112 ALWAYS_INLINE int saturatedSetUnsigned(unsigned value) |
| 113 { |
| 114 // This function is implemented as a template to make a common interface |
| 115 // for this and the ARM version, which will only compile under all compilers |
| 116 // if it is implemented as a template specialized with constants. |
106 | 117 |
107 ALWAYS_INLINE int saturatedSet(unsigned value, int FractionalShift) | |
108 { | |
109 const unsigned intMaxForLayoutUnit = | 118 const unsigned intMaxForLayoutUnit = |
110 std::numeric_limits<int>::max() >> FractionalShift; | 119 std::numeric_limits<int>::max() >> fractionalShift; |
111 | 120 |
112 if (value >= intMaxForLayoutUnit) | 121 if (value >= intMaxForLayoutUnit) |
113 return std::numeric_limits<int>::max(); | 122 return std::numeric_limits<int>::max(); |
114 | 123 |
115 return value << FractionalShift; | 124 return value << fractionalShift; |
116 } | 125 } |
117 | 126 |
118 #endif // CPU(ARM) && COMPILER(GCC) | 127 #endif // CPU(ARM) && COMPILER(GCC) |
119 #endif // SaturatedArithmetic_h | 128 #endif // SaturatedArithmetic_h |
OLD | NEW |