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

Unified Diff: src/base/bits.h

Issue 555833002: [turbofan] Add support for overflow add/sub to the MachineOperatorReducer. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address nit. Created 6 years, 3 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 | « include/v8config.h ('k') | src/base/bits-unittest.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 f271df9067d736e8ac512a9d13b15b04840291d3..e6a733a45dbb24ce4c95a30a817b2de2b4ee2354 100644
--- a/src/base/bits.h
+++ b/src/base/bits.h
@@ -6,6 +6,7 @@
#define V8_BASE_BITS_H_
#include "include/v8stdint.h"
+#include "src/base/macros.h"
#if V8_CC_MSVC
#include <intrin.h>
#endif
@@ -114,6 +115,34 @@ inline uint64_t RotateRight64(uint64_t value, uint64_t shift) {
return (value >> shift) | (value << (64 - shift));
}
+
+// SignedAddOverflow32(lhs,rhs,val) performs a signed summation of |lhs| and
+// |rhs| and stores the result into the variable pointed to by |val| and
+// returns true if the signed summation resulted in an overflow.
+inline bool SignedAddOverflow32(int32_t lhs, int32_t rhs, int32_t* val) {
+#if V8_HAS_BUILTIN_SADD_OVERFLOW
+ return __builtin_sadd_overflow(lhs, rhs, val);
+#else
+ uint32_t res = static_cast<uint32_t>(lhs) + static_cast<uint32_t>(rhs);
+ *val = bit_cast<int32_t>(res);
+ return ((res ^ lhs) & (res ^ rhs) & (1U << 31)) != 0;
+#endif
+}
+
+
+// SignedSubOverflow32(lhs,rhs,val) performs a signed subtraction of |lhs| and
+// |rhs| and stores the result into the variable pointed to by |val| and
+// returns true if the signed subtraction resulted in an overflow.
+inline bool SignedSubOverflow32(int32_t lhs, int32_t rhs, int32_t* val) {
+#if V8_HAS_BUILTIN_SSUB_OVERFLOW
+ return __builtin_ssub_overflow(lhs, rhs, val);
+#else
+ uint32_t res = static_cast<uint32_t>(lhs) - static_cast<uint32_t>(rhs);
+ *val = bit_cast<int32_t>(res);
+ return ((res ^ lhs) & (res ^ ~rhs) & (1U << 31)) != 0;
+#endif
+}
+
} // namespace bits
} // namespace base
} // namespace v8
« no previous file with comments | « include/v8config.h ('k') | src/base/bits-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698