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 #include "src/base/bits.h" | 5 #include "src/base/bits.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
10 #include "src/base/safe_math.h" | 10 #include "src/base/safe_math.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return FromCheckedNumeric(rv); | 71 return FromCheckedNumeric(rv); |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs) { | 75 int64_t SignedSaturatedSub64(int64_t lhs, int64_t rhs) { |
76 internal::CheckedNumeric<int64_t> rv(lhs); | 76 internal::CheckedNumeric<int64_t> rv(lhs); |
77 rv -= rhs; | 77 rv -= rhs; |
78 return FromCheckedNumeric(rv); | 78 return FromCheckedNumeric(rv); |
79 } | 79 } |
80 | 80 |
| 81 bool SignedMulOverflow32(int32_t lhs, int32_t rhs, int32_t* val) { |
| 82 internal::CheckedNumeric<int32_t> rv(lhs); |
| 83 rv *= rhs; |
| 84 int32_t limit = std::numeric_limits<int32_t>::max(); |
| 85 *val = rv.ValueOrDefault(limit); |
| 86 return !rv.IsValid(); |
| 87 } |
| 88 |
| 89 bool SignedMulOverflow64(int64_t lhs, int64_t rhs, int64_t* val) { |
| 90 internal::CheckedNumeric<int64_t> rv(lhs); |
| 91 rv *= rhs; |
| 92 int64_t limit = std::numeric_limits<int64_t>::max(); |
| 93 *val = rv.ValueOrDefault(limit); |
| 94 return !rv.IsValid(); |
| 95 } |
| 96 |
81 } // namespace bits | 97 } // namespace bits |
82 } // namespace base | 98 } // namespace base |
83 } // namespace v8 | 99 } // namespace v8 |
OLD | NEW |