OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_BASE_BITS_H_ | 5 #ifndef V8_BASE_BITS_H_ |
6 #define V8_BASE_BITS_H_ | 6 #define V8_BASE_BITS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include "src/base/macros.h" | 9 #include "src/base/macros.h" |
10 #include "src/base/safe_math.h" | |
10 #if V8_CC_MSVC | 11 #if V8_CC_MSVC |
11 #include <intrin.h> | 12 #include <intrin.h> |
12 #endif | 13 #endif |
13 #if V8_OS_WIN32 | 14 #if V8_OS_WIN32 |
14 #include "src/base/win32-headers.h" | 15 #include "src/base/win32-headers.h" |
15 #endif | 16 #endif |
16 | 17 |
17 namespace v8 { | 18 namespace v8 { |
18 namespace base { | 19 namespace base { |
19 namespace bits { | 20 namespace bits { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 return rhs ? lhs / rhs : 0u; | 290 return rhs ? lhs / rhs : 0u; |
290 } | 291 } |
291 | 292 |
292 | 293 |
293 // UnsignedMod32(lhs, rhs) divides |lhs| by |rhs| and returns the remainder | 294 // UnsignedMod32(lhs, rhs) divides |lhs| by |rhs| and returns the remainder |
294 // truncated to uint32. If |rhs| is zero, then zero is returned. | 295 // truncated to uint32. If |rhs| is zero, then zero is returned. |
295 inline uint32_t UnsignedMod32(uint32_t lhs, uint32_t rhs) { | 296 inline uint32_t UnsignedMod32(uint32_t lhs, uint32_t rhs) { |
296 return rhs ? lhs % rhs : 0u; | 297 return rhs ? lhs % rhs : 0u; |
297 } | 298 } |
298 | 299 |
300 | |
301 // Clamp |value| on overflow and underflow conditions. | |
302 int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value); | |
303 | |
304 | |
305 // SignedSaturatedAdd64(lhs, rhs) adds |lhs| and |rhs|, | |
306 // checks and returns the result. | |
307 inline int64_t SignedSaturatedAdd64(int64_t lhs, int64_t rhs) { | |
308 CheckedNumeric<int64_t> rv(lhs); | |
Benedikt Meurer
2016/05/06 05:12:58
Please move the implementation and therefore the u
lpy
2016/05/06 05:28:29
Done.
| |
309 rv += rhs; | |
310 return FromCheckedNumeric(rv); | |
311 } | |
312 | |
313 | |
314 // SignedSaturatedSub64(lhs, rhs) substracts |lhs| by |rhs|, | |
315 // checks and returns the result. | |
316 inline int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs) { | |
317 CheckedNumeric<int64_t> rv(lhs); | |
Benedikt Meurer
2016/05/06 05:12:58
See comment above.
lpy
2016/05/06 05:28:29
Done.
| |
318 rv -= rhs; | |
319 return FromCheckedNumeric(rv); | |
320 } | |
321 | |
322 | |
299 } // namespace bits | 323 } // namespace bits |
300 } // namespace base | 324 } // namespace base |
301 } // namespace v8 | 325 } // namespace v8 |
302 | 326 |
303 #endif // V8_BASE_BITS_H_ | 327 #endif // V8_BASE_BITS_H_ |
OLD | NEW |