| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project 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 V8_UTILS_H_ | 5 #ifndef V8_UTILS_H_ |
| 6 #define V8_UTILS_H_ | 6 #define V8_UTILS_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 | 135 |
| 136 // Returns the absolute value of its argument. | 136 // Returns the absolute value of its argument. |
| 137 template <typename T> | 137 template <typename T> |
| 138 T Abs(T a) { | 138 T Abs(T a) { |
| 139 return a < 0 ? -a : a; | 139 return a < 0 ? -a : a; |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 // Returns the negative absolute value of its argument. | |
| 144 template <typename T> | |
| 145 T NegAbs(T a) { | |
| 146 return a < 0 ? a : -a; | |
| 147 } | |
| 148 | |
| 149 | |
| 150 // TODO(svenpanne) Clean up the whole power-of-2 mess. | 143 // TODO(svenpanne) Clean up the whole power-of-2 mess. |
| 151 inline int32_t WhichPowerOf2Abs(int32_t x) { | 144 inline int32_t WhichPowerOf2Abs(int32_t x) { |
| 152 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); | 145 return (x == kMinInt) ? 31 : WhichPowerOf2(Abs(x)); |
| 153 } | 146 } |
| 154 | 147 |
| 155 | 148 |
| 156 // Obtains the unsigned type corresponding to T | 149 // Obtains the unsigned type corresponding to T |
| 157 // available in C++11 as std::make_unsigned | 150 // available in C++11 as std::make_unsigned |
| 158 template<typename T> | 151 template<typename T> |
| 159 struct make_unsigned { | 152 struct make_unsigned { |
| (...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 } | 1521 } |
| 1529 | 1522 |
| 1530 *index = result; | 1523 *index = result; |
| 1531 return true; | 1524 return true; |
| 1532 } | 1525 } |
| 1533 | 1526 |
| 1534 | 1527 |
| 1535 } } // namespace v8::internal | 1528 } } // namespace v8::internal |
| 1536 | 1529 |
| 1537 #endif // V8_UTILS_H_ | 1530 #endif // V8_UTILS_H_ |
| OLD | NEW |