| 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 <int32_t op(int32_t, int32_t), class DeriveFunction> |
| 151 void TestPreciseBinaryArithOp(DeriveFunction derive, |
| 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 IntType r1 = IntType(int32_t(lmin), int32_t(lmax)); |
| 159 IntType r2 = IntType(int32_t(rmin), int32_t(rmax)); |
| 160 IntType derived_type = derive(r1, r2); |
| 161 int32_t min = kMaxInt, max = kMinInt; |
| 162 for (int32_t x1 = int32_t(lmin); x1 <= int32_t(lmax); x1++) { |
| 163 for (int32_t x2 = int32_t(rmin); x2 <= int32_t(rmax); x2++) { |
| 164 int32_t result_value = op(x1, x2); |
| 165 min = std::min(result_value, min); |
| 166 max = std::max(result_value, max); |
| 167 } |
| 168 } |
| 169 EXPECT_TRUE(derived_type.min == min && derived_type.max == max); |
| 170 } |
| 171 } |
| 172 } |
| 173 } |
| 174 } |
| 175 |
| 149 template <class BinaryFunction> | 176 template <class BinaryFunction> |
| 150 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) { | 177 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) { |
| 151 for (int i = 0; i < 100; ++i) { | 178 for (int i = 0; i < 100; ++i) { |
| 152 Type::RangeType* r1 = RandomRange()->AsRange(); | 179 Type::RangeType* r1 = RandomRange()->AsRange(); |
| 153 Type::RangeType* r2 = RandomRange()->AsRange(); | 180 Type::RangeType* r2 = RandomRange()->AsRange(); |
| 154 Type* expected_type = TypeBinaryOp(op, r1, r2); | 181 Type* expected_type = TypeBinaryOp(op, r1, r2); |
| 155 for (int i = 0; i < 10; i++) { | 182 for (int i = 0; i < 10; i++) { |
| 156 double x1 = RandomInt(r1); | 183 double x1 = RandomInt(r1); |
| 157 double x2 = RandomInt(r2); | 184 double x2 = RandomInt(r2); |
| 158 bool result_value = opfun(x1, x2); | 185 bool result_value = opfun(x1, x2); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 307 |
| 281 TEST_F(TyperTest, TypeJSShiftLeft) { | 308 TEST_F(TyperTest, TypeJSShiftLeft) { |
| 282 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left); | 309 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::SLOPPY), shift_left); |
| 283 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left); | 310 TestBinaryBitOp(javascript_.ShiftLeft(LanguageMode::STRONG), shift_left); |
| 284 } | 311 } |
| 285 | 312 |
| 286 | 313 |
| 287 TEST_F(TyperTest, TypeJSShiftRight) { | 314 TEST_F(TyperTest, TypeJSShiftRight) { |
| 288 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::SLOPPY), shift_right); | 315 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::SLOPPY), shift_right); |
| 289 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::STRONG), shift_right); | 316 TestBinaryBitOp(javascript_.ShiftRight(LanguageMode::STRONG), shift_right); |
| 317 TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType, |
| 318 -16, 15, 1, -64, 63, 1); |
| 319 TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType, |
| 320 kMaxInt - 16, kMaxInt, 1, -64, 63, 1); |
| 321 TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType, |
| 322 kMinInt, kMinInt + 16, 1, -64, 63, 1); |
| 323 TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType, |
| 324 kMaxInt - 16 * 2, |
| 325 kMaxInt, 2, -64, 63, 1); |
| 326 TestPreciseBinaryArithOp<shift_right>(JSShiftRightIntType, |
| 327 kMinInt, kMinInt + 16 * 2, |
| 328 2, -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 |