Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: src/base/bits.h

Issue 1952843002: Create TimeBase for time related classes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/base/bits.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | src/base/bits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698