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

Unified Diff: test/unittests/compiler/typer-unittest.cc

Issue 1112123002: Precise bitwise-xor derived result type for all int32 input types. Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Split the bitwise-xor result type derivation into a separate function. Created 5 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
« src/compiler/typer.cc ('K') | « src/compiler/typer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/compiler/typer-unittest.cc
diff --git a/test/unittests/compiler/typer-unittest.cc b/test/unittests/compiler/typer-unittest.cc
index f977c6fddd4d26a7d6928cee22ce734e5b9fb67e..117f29be93cceebf8926b41e78ee585cbd5552e6 100644
--- a/test/unittests/compiler/typer-unittest.cc
+++ b/test/unittests/compiler/typer-unittest.cc
@@ -146,6 +146,33 @@ class TyperTest : public TypedGraphTest {
}
}
+ // Careful, this function scales poorly.
+ template <int32_t op(int32_t, int32_t), class DeriveFunction>
+ void TestPreciseBinaryArithOp(DeriveFunction derive,
+ int32_t llow, int32_t lhigh, int32_t linc,
+ int32_t rlow, int32_t rhigh, int32_t rinc) {
+ for (int64_t lmin = llow; lmin <= lhigh; lmin += linc) {
+ for (int64_t lmax = lmin; lmax <= lhigh; lmax += linc) {
+ for (int64_t rmin = rlow; rmin <= rhigh; rmin += rinc) {
+ for (int64_t rmax = rmin; rmax <= rhigh; rmax += rinc) {
+ IntType r1 = IntType(int32_t(lmin), int32_t(lmax));
+ IntType r2 = IntType(int32_t(rmin), int32_t(rmax));
+ IntType derived_type = derive(r1, r2);
+ int32_t min = kMaxInt, max = kMinInt;
+ for (int32_t x1 = int32_t(lmin); x1 <= int32_t(lmax); x1++) {
+ for (int32_t x2 = int32_t(rmin); x2 <= int32_t(rmax); x2++) {
+ int32_t result_value = op(x1, x2);
+ min = std::min(result_value, min);
+ max = std::max(result_value, max);
+ }
+ }
+ EXPECT_TRUE(derived_type.min == min && derived_type.max == max);
+ }
+ }
+ }
+ }
+ }
+
template <class BinaryFunction>
void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) {
for (int i = 0; i < 100; ++i) {
@@ -275,6 +302,22 @@ TEST_F(TyperTest, TypeJSBitwiseAnd) {
TEST_F(TyperTest, TypeJSBitwiseXor) {
TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::SLOPPY), bit_xor);
TestBinaryBitOp(javascript_.BitwiseXor(LanguageMode::STRONG), bit_xor);
+ // The derivation algorithm works one bit at a time and scales to
+ // any bit width so verify on practical bit widths.
+ TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
Sven Panne 2015/05/18 12:16:15 How long do these tests actually run? 6 nested for
+ -16, 15, 1, -16, 15, 1);
+ TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
+ kMaxInt - 32, kMaxInt, 1,
+ kMaxInt - 32, kMaxInt, 1);
+ TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
+ kMinInt, kMinInt + 32, 1,
+ kMinInt, kMinInt + 32, 1);
+ TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
+ kMaxInt - 32 * 2, kMaxInt, 2,
+ kMaxInt - 32 * 2, kMaxInt, 2);
+ TestPreciseBinaryArithOp<bit_xor>(JSBitwiseXorIntType,
+ kMinInt, kMinInt + 32 * 2, 2,
+ kMinInt, kMinInt + 32 * 2, 2);
}
« src/compiler/typer.cc ('K') | « src/compiler/typer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698