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

Unified Diff: src/base/bits-unittest.cc

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 | « src/base/bits.h ('k') | src/compiler/machine-operator-reducer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/base/bits-unittest.cc
diff --git a/src/base/bits-unittest.cc b/src/base/bits-unittest.cc
index e06fd097ead23487ad9084eb91558e02171eb8e8..06c1183586732d9e59abafbe3827eb2c2764c203 100644
--- a/src/base/bits-unittest.cc
+++ b/src/base/bits-unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <limits>
+
#include "src/base/bits.h"
#include "src/base/macros.h"
#include "testing/gtest-support.h"
@@ -119,6 +121,47 @@ TEST(Bits, RotateRight64) {
EXPECT_EQ(V8_UINT64_C(0x8000000000000000), RotateRight64(1, 1));
}
+
+TEST(Bits, SignedAddOverflow32) {
+ int32_t val = 0;
+ EXPECT_FALSE(SignedAddOverflow32(0, 0, &val));
+ EXPECT_EQ(0, val);
+ EXPECT_TRUE(
+ SignedAddOverflow32(std::numeric_limits<int32_t>::max(), 1, &val));
+ EXPECT_EQ(std::numeric_limits<int32_t>::min(), val);
+ EXPECT_TRUE(
+ SignedAddOverflow32(std::numeric_limits<int32_t>::min(), -1, &val));
+ EXPECT_EQ(std::numeric_limits<int32_t>::max(), val);
+ EXPECT_TRUE(SignedAddOverflow32(std::numeric_limits<int32_t>::max(),
+ std::numeric_limits<int32_t>::max(), &val));
+ EXPECT_EQ(-2, val);
+ TRACED_FORRANGE(int32_t, i, 1, 50) {
+ TRACED_FORRANGE(int32_t, j, 1, i) {
+ EXPECT_FALSE(SignedAddOverflow32(i, j, &val));
+ EXPECT_EQ(i + j, val);
+ }
+ }
+}
+
+
+TEST(Bits, SignedSubOverflow32) {
+ int32_t val = 0;
+ EXPECT_FALSE(SignedSubOverflow32(0, 0, &val));
+ EXPECT_EQ(0, val);
+ EXPECT_TRUE(
+ SignedSubOverflow32(std::numeric_limits<int32_t>::min(), 1, &val));
+ EXPECT_EQ(std::numeric_limits<int32_t>::max(), val);
+ EXPECT_TRUE(
+ SignedSubOverflow32(std::numeric_limits<int32_t>::max(), -1, &val));
+ EXPECT_EQ(std::numeric_limits<int32_t>::min(), val);
+ TRACED_FORRANGE(int32_t, i, 1, 50) {
+ TRACED_FORRANGE(int32_t, j, 1, i) {
+ EXPECT_FALSE(SignedSubOverflow32(i, j, &val));
+ EXPECT_EQ(i - j, val);
+ }
+ }
+}
+
} // namespace bits
} // namespace base
} // namespace v8
« no previous file with comments | « src/base/bits.h ('k') | src/compiler/machine-operator-reducer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698