| 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 "src/compiler/operator-properties.h" | 10 #include "src/compiler/operator-properties.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 int32s.push_back(0); | 42 int32s.push_back(0); |
| 43 int32s.push_back(-1); | 43 int32s.push_back(-1); |
| 44 int32s.push_back(+1); | 44 int32s.push_back(+1); |
| 45 int32s.push_back(kMinInt); | 45 int32s.push_back(kMinInt); |
| 46 int32s.push_back(kMaxInt); | 46 int32s.push_back(kMaxInt); |
| 47 for (int i = 0; i < 10; ++i) { | 47 for (int i = 0; i < 10; ++i) { |
| 48 int32s.push_back(rng_->NextInt()); | 48 int32s.push_back(rng_->NextInt()); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 Types<Type, Type*, Zone> types_; | 52 Types types_; |
| 53 JSOperatorBuilder javascript_; | 53 JSOperatorBuilder javascript_; |
| 54 BinaryOperationHints const hints_ = BinaryOperationHints::Any(); | 54 BinaryOperationHints const hints_ = BinaryOperationHints::Any(); |
| 55 Node* context_node_; | 55 Node* context_node_; |
| 56 v8::base::RandomNumberGenerator* rng_; | 56 v8::base::RandomNumberGenerator* rng_; |
| 57 std::vector<double> integers; | 57 std::vector<double> integers; |
| 58 std::vector<double> int32s; | 58 std::vector<double> int32s; |
| 59 | 59 |
| 60 Type* TypeBinaryOp(const Operator* op, Type* lhs, Type* rhs) { | 60 Type* TypeBinaryOp(const Operator* op, Type* lhs, Type* rhs) { |
| 61 Node* p0 = Parameter(0); | 61 Node* p0 = Parameter(0); |
| 62 Node* p1 = Parameter(1); | 62 Node* p1 = Parameter(1); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (min == -V8_INFINITY && max == +V8_INFINITY) { | 108 if (min == -V8_INFINITY && max == +V8_INFINITY) { |
| 109 return rng_->NextInt() * static_cast<double>(rng_->NextInt()); | 109 return rng_->NextInt() * static_cast<double>(rng_->NextInt()); |
| 110 } | 110 } |
| 111 double result = nearbyint(min + (max - min) * rng_->NextDouble()); | 111 double result = nearbyint(min + (max - min) * rng_->NextDouble()); |
| 112 if (IsMinusZero(result)) return 0; | 112 if (IsMinusZero(result)) return 0; |
| 113 if (std::isnan(result)) return rng_->NextInt(2) ? min : max; | 113 if (std::isnan(result)) return rng_->NextInt(2) ? min : max; |
| 114 DCHECK(min <= result && result <= max); | 114 DCHECK(min <= result && result <= max); |
| 115 return result; | 115 return result; |
| 116 } | 116 } |
| 117 | 117 |
| 118 double RandomInt(Type::RangeType* range) { | 118 double RandomInt(RangeType* range) { |
| 119 return RandomInt(range->Min(), range->Max()); | 119 return RandomInt(range->Min(), range->Max()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Careful, this function runs O(max_width^5) trials. | 122 // Careful, this function runs O(max_width^5) trials. |
| 123 template <class BinaryFunction> | 123 template <class BinaryFunction> |
| 124 void TestBinaryArithOpCloseToZero(const Operator* op, BinaryFunction opfun, | 124 void TestBinaryArithOpCloseToZero(const Operator* op, BinaryFunction opfun, |
| 125 int max_width) { | 125 int max_width) { |
| 126 const int min_min = -2 - max_width / 2; | 126 const int min_min = -2 - max_width / 2; |
| 127 const int max_min = 2 + max_width / 2; | 127 const int max_min = 2 + max_width / 2; |
| 128 for (int width = 0; width < max_width; width++) { | 128 for (int width = 0; width < max_width; width++) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 template <class BinaryFunction> | 148 template <class BinaryFunction> |
| 149 void TestBinaryArithOp(const Operator* op, BinaryFunction opfun) { | 149 void TestBinaryArithOp(const Operator* op, BinaryFunction opfun) { |
| 150 TestBinaryArithOpCloseToZero(op, opfun, 8); | 150 TestBinaryArithOpCloseToZero(op, opfun, 8); |
| 151 for (int i = 0; i < 100; ++i) { | 151 for (int i = 0; i < 100; ++i) { |
| 152 Type::RangeType* r1 = RandomRange()->AsRange(); | 152 Type* r1 = RandomRange(); |
| 153 Type::RangeType* r2 = RandomRange()->AsRange(); | 153 Type* r2 = RandomRange(); |
| 154 Type* expected_type = TypeBinaryOp(op, r1, r2); | 154 Type* expected_type = TypeBinaryOp(op, r1, r2); |
| 155 for (int i = 0; i < 10; i++) { | 155 for (int i = 0; i < 10; i++) { |
| 156 double x1 = RandomInt(r1); | 156 double x1 = RandomInt(r1->AsRange()); |
| 157 double x2 = RandomInt(r2); | 157 double x2 = RandomInt(r2->AsRange()); |
| 158 double result_value = opfun(x1, x2); | 158 double result_value = opfun(x1, x2); |
| 159 Type* result_type = Type::Constant( | 159 Type* result_type = Type::Constant( |
| 160 isolate()->factory()->NewNumber(result_value), zone()); | 160 isolate()->factory()->NewNumber(result_value), zone()); |
| 161 EXPECT_TRUE(result_type->Is(expected_type)); | 161 EXPECT_TRUE(result_type->Is(expected_type)); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 template <class BinaryFunction> | 166 template <class BinaryFunction> |
| 167 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) { | 167 void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) { |
| 168 for (int i = 0; i < 100; ++i) { | 168 for (int i = 0; i < 100; ++i) { |
| 169 Type::RangeType* r1 = RandomRange()->AsRange(); | 169 Type* r1 = RandomRange(); |
| 170 Type::RangeType* r2 = RandomRange()->AsRange(); | 170 Type* r2 = RandomRange(); |
| 171 Type* expected_type = TypeBinaryOp(op, r1, r2); | 171 Type* expected_type = TypeBinaryOp(op, r1, r2); |
| 172 for (int i = 0; i < 10; i++) { | 172 for (int i = 0; i < 10; i++) { |
| 173 double x1 = RandomInt(r1); | 173 double x1 = RandomInt(r1->AsRange()); |
| 174 double x2 = RandomInt(r2); | 174 double x2 = RandomInt(r2->AsRange()); |
| 175 bool result_value = opfun(x1, x2); | 175 bool result_value = opfun(x1, x2); |
| 176 Type* result_type = | 176 Type* result_type = |
| 177 Type::Constant(result_value ? isolate()->factory()->true_value() | 177 Type::Constant(result_value ? isolate()->factory()->true_value() |
| 178 : isolate()->factory()->false_value(), | 178 : isolate()->factory()->false_value(), |
| 179 zone()); | 179 zone()); |
| 180 EXPECT_TRUE(result_type->Is(expected_type)); | 180 EXPECT_TRUE(result_type->Is(expected_type)); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| 185 template <class BinaryFunction> | 185 template <class BinaryFunction> |
| 186 void TestBinaryBitOp(const Operator* op, BinaryFunction opfun) { | 186 void TestBinaryBitOp(const Operator* op, BinaryFunction opfun) { |
| 187 for (int i = 0; i < 100; ++i) { | 187 for (int i = 0; i < 100; ++i) { |
| 188 Type::RangeType* r1 = RandomRange(true)->AsRange(); | 188 Type* r1 = RandomRange(true); |
| 189 Type::RangeType* r2 = RandomRange(true)->AsRange(); | 189 Type* r2 = RandomRange(true); |
| 190 Type* expected_type = TypeBinaryOp(op, r1, r2); | 190 Type* expected_type = TypeBinaryOp(op, r1, r2); |
| 191 for (int i = 0; i < 10; i++) { | 191 for (int i = 0; i < 10; i++) { |
| 192 int32_t x1 = static_cast<int32_t>(RandomInt(r1)); | 192 int32_t x1 = static_cast<int32_t>(RandomInt(r1->AsRange())); |
| 193 int32_t x2 = static_cast<int32_t>(RandomInt(r2)); | 193 int32_t x2 = static_cast<int32_t>(RandomInt(r2->AsRange())); |
| 194 double result_value = opfun(x1, x2); | 194 double result_value = opfun(x1, x2); |
| 195 Type* result_type = Type::Constant( | 195 Type* result_type = Type::Constant( |
| 196 isolate()->factory()->NewNumber(result_value), zone()); | 196 isolate()->factory()->NewNumber(result_value), zone()); |
| 197 EXPECT_TRUE(result_type->Is(expected_type)); | 197 EXPECT_TRUE(result_type->Is(expected_type)); |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 Type* RandomSubtype(Type* type) { | 202 Type* RandomSubtype(Type* type) { |
| 203 Type* subtype; | 203 Type* subtype; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 for (auto i : values) { | 426 for (auto i : values) { |
| 427 Node* c = graph()->NewNode(common()->Int32Constant(i)); | 427 Node* c = graph()->NewNode(common()->Int32Constant(i)); |
| 428 Type* type = NodeProperties::GetType(c); | 428 Type* type = NodeProperties::GetType(c); |
| 429 EXPECT_TRUE(type->Is(NewRange(i, i))); | 429 EXPECT_TRUE(type->Is(NewRange(i, i))); |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace compiler | 433 } // namespace compiler |
| 434 } // namespace internal | 434 } // namespace internal |
| 435 } // namespace v8 | 435 } // namespace v8 |
| OLD | NEW |