| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <functional> | 5 #include <functional> |
| 6 | 6 |
| 7 #include "src/codegen.h" | 7 #include "src/codegen.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
| 10 #include "test/cctest/types-fuzz.h" | 10 #include "test/cctest/types-fuzz.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 double x1 = RandomInt(r1); | 139 double x1 = RandomInt(r1); |
| 140 double x2 = RandomInt(r2); | 140 double x2 = RandomInt(r2); |
| 141 double result_value = opfun(x1, x2); | 141 double result_value = opfun(x1, x2); |
| 142 Type* result_type = Type::Constant( | 142 Type* result_type = Type::Constant( |
| 143 isolate()->factory()->NewNumber(result_value), zone()); | 143 isolate()->factory()->NewNumber(result_value), zone()); |
| 144 EXPECT_TRUE(result_type->Is(expected_type)); | 144 EXPECT_TRUE(result_type->Is(expected_type)); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Careful, this function scales poorly. |
| 150 template <class BinaryFunction> |
| 151 void TestPreciseBinaryArithOp(const Operator* op, BinaryFunction opfun, |
| 152 int32_t llow, int32_t lhigh, int32_t linc, |
| 153 int32_t rlow, int32_t rhigh, int32_t rinc) { |
| 154 for (int64_t lmin = llow; lmin <= lhigh; lmin += linc) { |
| 155 for (int64_t lmax = lmin; lmax <= lhigh; lmax += linc) { |
| 156 for (int64_t rmin = rlow; rmin <= rhigh; rmin += rinc) { |
| 157 for (int64_t rmax = rmin; rmax <= rhigh; rmax += rinc) { |
| 158 Type* r1 = NewRange(lmin, lmax); |
| 159 Type* r2 = NewRange(rmin, rmax); |
| 160 Type* derived_type = TypeBinaryOp(op, r1, r2); |
| 161 |
| 162 double min = +V8_INFINITY, max = -V8_INFINITY; |
| 163 for (int64_t x1 = lmin; x1 <= lmax; x1++) { |
| 164 for (int64_t x2 = rmin; x2 <= rmax; x2++) { |
| 165 double result_value = opfun(int32_t(x1), int32_t(x2)); |
| 166 if (result_value < min) min = result_value; |
| 167 if (result_value > max) max = result_value; |
| 168 } |
| 169 } |
| 170 Type* expected_type = NewRange(min, max); |
| 171 |
| 172 EXPECT_TRUE(derived_type->Is(expected_type)); |
| 173 EXPECT_TRUE(expected_type->Is(derived_type)); |
| 174 } |
| 175 } |
| 176 } |
| 177 } |
| 178 } |
| 179 |
| 149 template <class BinaryFunction> | 180 template <class BinaryFunction> |
| 150 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) { | 181 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) { |
| 151 for (int i = 0; i < 100; ++i) { | 182 for (int i = 0; i < 100; ++i) { |
| 152 Type::RangeType* r1 = RandomRange()->AsRange(); | 183 Type::RangeType* r1 = RandomRange()->AsRange(); |
| 153 Type::RangeType* r2 = RandomRange()->AsRange(); | 184 Type::RangeType* r2 = RandomRange()->AsRange(); |
| 154 Type* expected_type = TypeBinaryOp(op, r1, r2); | 185 Type* expected_type = TypeBinaryOp(op, r1, r2); |
| 155 for (int i = 0; i < 10; i++) { | 186 for (int i = 0; i < 10; i++) { |
| 156 double x1 = RandomInt(r1); | 187 double x1 = RandomInt(r1); |
| 157 double x2 = RandomInt(r2); | 188 double x2 = RandomInt(r2); |
| 158 bool result_value = opfun(x1, x2); | 189 bool result_value = opfun(x1, x2); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 311 |
| 281 TEST_F(TyperTest, TypeJSShiftLeft) { | 312 TEST_F(TyperTest, TypeJSShiftLeft) { |
| 282 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left); | 313 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left); |
| 283 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left); | 314 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left); |
| 284 } | 315 } |
| 285 | 316 |
| 286 | 317 |
| 287 TEST_F(TyperTest, TypeJSShiftRight) { | 318 TEST_F(TyperTest, TypeJSShiftRight) { |
| 288 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::SLOPPY), shift_right); | 319 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::SLOPPY), shift_right); |
| 289 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::STRONG), shift_right); | 320 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::STRONG), shift_right); |
| 321 TestPreciseBinaryArithOp(javascript_.ShiftRight(LanguageMode::SLOPPY), |
| 322 shift_right, -16, 15, 1, 0, 31, 1); |
| 323 TestPreciseBinaryArithOp(javascript_.ShiftRight(LanguageMode::STRONG), |
| 324 shift_right, -16, 15, 1, 0, 31, 1); |
| 325 TestPreciseBinaryArithOp(javascript_.ShiftRight(LanguageMode::SLOPPY), |
| 326 shift_right, -8, 7, 1, -64, 63, 1); |
| 327 TestPreciseBinaryArithOp(javascript_.ShiftRight(LanguageMode::STRONG), |
| 328 shift_right, -8, 7, 1, -64, 63, 1); |
| 290 } | 329 } |
| 291 | 330 |
| 292 | 331 |
| 293 TEST_F(TyperTest, TypeJSLessThan) { | 332 TEST_F(TyperTest, TypeJSLessThan) { |
| 294 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::SLOPPY), | 333 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::SLOPPY), |
| 295 std::less<double>()); | 334 std::less<double>()); |
| 296 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::STRONG), | 335 TestBinaryCompareOp(javascript_.LessThan(LanguageMode::STRONG), |
| 297 std::less<double>()); | 336 std::less<double>()); |
| 298 } | 337 } |
| 299 | 338 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 435 |
| 397 | 436 |
| 398 TEST_F(TyperTest, TypeRegressInt32Constant) { | 437 TEST_F(TyperTest, TypeRegressInt32Constant) { |
| 399 int values[] = {-5, 10}; | 438 int values[] = {-5, 10}; |
| 400 for (auto i : values) { | 439 for (auto i : values) { |
| 401 Node* c = graph()->NewNode(common()->Int32Constant(i)); | 440 Node* c = graph()->NewNode(common()->Int32Constant(i)); |
| 402 Type* type = NodeProperties::GetBounds(c).upper; | 441 Type* type = NodeProperties::GetBounds(c).upper; |
| 403 EXPECT_TRUE(type->Is(NewRange(i, i))); | 442 EXPECT_TRUE(type->Is(NewRange(i, i))); |
| 404 } | 443 } |
| 405 } | 444 } |
| OLD | NEW |