Chromium Code Reviews| Index: src/base/bits.h |
| diff --git a/src/base/bits.h b/src/base/bits.h |
| index 0e7662488428899bb8ca96677d873fcabac284db..ddac275e606a9f47706953e8f4af570acd0603c0 100644 |
| --- a/src/base/bits.h |
| +++ b/src/base/bits.h |
| @@ -7,6 +7,7 @@ |
| #include <stdint.h> |
| #include "src/base/macros.h" |
| +#include "src/base/safe_math.h" |
| #if V8_CC_MSVC |
| #include <intrin.h> |
| #endif |
| @@ -296,6 +297,29 @@ inline uint32_t UnsignedMod32(uint32_t lhs, uint32_t rhs) { |
| return rhs ? lhs % rhs : 0u; |
| } |
| + |
| +// Clamp |value| on overflow and underflow conditions. |
| +int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value); |
| + |
| + |
| +// SignedSaturatedAdd64(lhs, rhs) adds |lhs| and |rhs|, |
| +// checks and returns the result. |
| +inline int64_t SignedSaturatedAdd64(int64_t lhs, int64_t rhs) { |
| + 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.
|
| + rv += rhs; |
| + return FromCheckedNumeric(rv); |
| +} |
| + |
| + |
| +// SignedSaturatedSub64(lhs, rhs) substracts |lhs| by |rhs|, |
| +// checks and returns the result. |
| +inline int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs) { |
| + CheckedNumeric<int64_t> rv(lhs); |
|
Benedikt Meurer
2016/05/06 05:12:58
See comment above.
lpy
2016/05/06 05:28:29
Done.
|
| + rv -= rhs; |
| + return FromCheckedNumeric(rv); |
| +} |
| + |
| + |
| } // namespace bits |
| } // namespace base |
| } // namespace v8 |