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 <int FractionalShift> |
| 90 ALWAYS_INLINE int saturatedSet(int value) |
90 { | 91 { |
91 const int intMaxForLayoutUnit = | 92 const int intMaxForLayoutUnit = |
92 std::numeric_limits<int>::max() >> FractionalShift; | 93 std::numeric_limits<int>::max() >> FractionalShift; |
93 | 94 |
94 const int intMinForLayoutUnit = | 95 const int intMinForLayoutUnit = |
95 std::numeric_limits<int>::min() >> FractionalShift; | 96 std::numeric_limits<int>::min() >> FractionalShift; |
96 | 97 |
97 if (value > intMaxForLayoutUnit) | 98 if (value > intMaxForLayoutUnit) |
98 return std::numeric_limits<int>::max(); | 99 return std::numeric_limits<int>::max(); |
99 | 100 |
100 if (value < intMinForLayoutUnit) | 101 if (value < intMinForLayoutUnit) |
101 return std::numeric_limits<int>::min(); | 102 return std::numeric_limits<int>::min(); |
102 | 103 |
103 return value << FractionalShift; | 104 return value << FractionalShift; |
104 } | 105 } |
105 | 106 |
106 | 107 |
107 ALWAYS_INLINE int saturatedSet(unsigned value, int FractionalShift) | 108 template <int FractionalShift> |
| 109 ALWAYS_INLINE int saturatedSet(unsigned value) |
108 { | 110 { |
109 const unsigned intMaxForLayoutUnit = | 111 const unsigned intMaxForLayoutUnit = |
110 std::numeric_limits<int>::max() >> FractionalShift; | 112 std::numeric_limits<int>::max() >> FractionalShift; |
111 | 113 |
112 if (value >= intMaxForLayoutUnit) | 114 if (value >= intMaxForLayoutUnit) |
113 return std::numeric_limits<int>::max(); | 115 return std::numeric_limits<int>::max(); |
114 | 116 |
115 return value << FractionalShift; | 117 return value << FractionalShift; |
116 } | 118 } |
117 | 119 |
118 #endif // CPU(ARM) && COMPILER(GCC) | 120 #endif // CPU(ARM) && COMPILER(GCC) |
119 #endif // SaturatedArithmetic_h | 121 #endif // SaturatedArithmetic_h |
OLD | NEW |