| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "src/hydrogen-types.h" | 7 #include "src/hydrogen-types.h" |
| 8 #include "src/isolate-inl.h" | 8 #include "src/isolate-inl.h" |
| 9 #include "src/types.h" | 9 #include "src/types.h" |
| 10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 typedef std::vector<TypeHandle> TypeVector; | 182 typedef std::vector<TypeHandle> TypeVector; |
| 183 typedef std::vector<Handle<i::Map> > MapVector; | 183 typedef std::vector<Handle<i::Map> > MapVector; |
| 184 typedef std::vector<Handle<i::Object> > ValueVector; | 184 typedef std::vector<Handle<i::Object> > ValueVector; |
| 185 typedef std::vector<double> DoubleVector; | 185 typedef std::vector<double> DoubleVector; |
| 186 | 186 |
| 187 TypeVector types; | 187 TypeVector types; |
| 188 MapVector maps; | 188 MapVector maps; |
| 189 ValueVector values; | 189 ValueVector values; |
| 190 DoubleVector doubles; // Some floating-point values, excluding NaN. | 190 DoubleVector doubles; // Some floating-point values, excluding NaN. |
| 191 | 191 |
| 192 // Range type helper functions, partially copied from types.cc. | |
| 193 // Note: le(min(x,y), max(x,y)) holds iff neither x nor y is NaN. | |
| 194 bool le(double x, double y) { | |
| 195 return x <= y && copysign(1, x) <= copysign(1, y); | |
| 196 } | |
| 197 bool eq(double x, double y) { | |
| 198 return le(x, y) && le(y, x); | |
| 199 } | |
| 200 double min(double x, double y) { | |
| 201 return le(x, y) ? x : y; | |
| 202 } | |
| 203 double max(double x, double y) { | |
| 204 return le(x, y) ? y : x; | |
| 205 } | |
| 206 | |
| 207 TypeHandle Of(Handle<i::Object> value) { | 192 TypeHandle Of(Handle<i::Object> value) { |
| 208 return Type::Of(value, region_); | 193 return Type::Of(value, region_); |
| 209 } | 194 } |
| 210 | 195 |
| 211 TypeHandle NowOf(Handle<i::Object> value) { | 196 TypeHandle NowOf(Handle<i::Object> value) { |
| 212 return Type::NowOf(value, region_); | 197 return Type::NowOf(value, region_); |
| 213 } | 198 } |
| 214 | 199 |
| 215 TypeHandle Constant(Handle<i::Object> value) { | 200 TypeHandle Constant(Handle<i::Object> value) { |
| 216 return Type::Constant(value, region_); | 201 return Type::Constant(value, region_); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); | 542 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); |
| 558 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); | 543 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); |
| 559 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber)); | 544 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber)); |
| 560 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber)); | 545 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber)); |
| 561 } | 546 } |
| 562 | 547 |
| 563 void Range() { | 548 void Range() { |
| 564 // Constructor | 549 // Constructor |
| 565 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { | 550 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { |
| 566 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { | 551 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { |
| 567 double min = T.min(*i, *j); | 552 double min = std::min(*i, *j); |
| 568 double max = T.max(*i, *j); | 553 double max = std::max(*i, *j); |
| 569 TypeHandle type = T.Range(min, max); | 554 TypeHandle type = T.Range(min, max); |
| 570 CHECK(type->IsRange()); | 555 CHECK(type->IsRange()); |
| 571 } | 556 } |
| 572 } | 557 } |
| 573 | 558 |
| 574 // Range attributes | 559 // Range attributes |
| 575 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { | 560 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { |
| 576 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { | 561 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { |
| 577 double min = T.min(*i, *j); | 562 double min = std::min(*i, *j); |
| 578 double max = T.max(*i, *j); | 563 double max = std::max(*i, *j); |
| 579 printf("RangeType: min, max = %f, %f\n", min, max); | 564 printf("RangeType: min, max = %f, %f\n", min, max); |
| 580 TypeHandle type = T.Range(min, max); | 565 TypeHandle type = T.Range(min, max); |
| 581 printf("RangeType: Min, Max = %f, %f\n", | 566 printf("RangeType: Min, Max = %f, %f\n", |
| 582 type->AsRange()->Min(), type->AsRange()->Max()); | 567 type->AsRange()->Min(), type->AsRange()->Max()); |
| 583 CHECK(min == type->AsRange()->Min()); | 568 CHECK(min == type->AsRange()->Min()); |
| 584 CHECK(max == type->AsRange()->Max()); | 569 CHECK(max == type->AsRange()->Max()); |
| 585 } | 570 } |
| 586 } | 571 } |
| 587 | 572 |
| 588 // TODO(neis): enable once subtyping is updated. | 573 // TODO(neis): enable once subtyping is updated. |
| 589 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> | 574 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> |
| 590 // // min1 = min2 /\ max1 = max2 | 575 // // min1 = min2 /\ max1 = max2 |
| 591 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { | 576 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { |
| 592 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { | 577 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { |
| 593 // for (DoubleIterator i2 = T.doubles.begin(); | 578 // for (DoubleIterator i2 = T.doubles.begin(); |
| 594 // i2 != T.doubles.end(); ++i2) { | 579 // i2 != T.doubles.end(); ++i2) { |
| 595 // for (DoubleIterator j2 = T.doubles.begin(); | 580 // for (DoubleIterator j2 = T.doubles.begin(); |
| 596 // j2 != T.doubles.end(); ++j2) { | 581 // j2 != T.doubles.end(); ++j2) { |
| 597 // double min1 = T.min(*i1, *j1); | 582 // double min1 = std::min(*i1, *j1); |
| 598 // double max1 = T.max(*i1, *j1); | 583 // double max1 = std::max(*i1, *j1); |
| 599 // double min2 = T.min(*i2, *j2); | 584 // double min2 = std::min(*i2, *j2); |
| 600 // double max2 = T.max(*i2, *j2); | 585 // double max2 = std::max(*i2, *j2); |
| 601 // TypeHandle type1 = T.Range(min1, max1); | 586 // TypeHandle type1 = T.Range(min1, max1); |
| 602 // TypeHandle type2 = T.Range(min2, max2); | 587 // TypeHandle type2 = T.Range(min2, max2); |
| 603 // CHECK(Equal(type1, type2) == | 588 // CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); |
| 604 // (T.eq(min1, min2) && T.eq(max1, max2))); | |
| 605 // } | 589 // } |
| 606 // } | 590 // } |
| 607 // } | 591 // } |
| 608 // } | 592 // } |
| 609 } | 593 } |
| 610 | 594 |
| 611 void Array() { | 595 void Array() { |
| 612 // Constructor | 596 // Constructor |
| 613 for (int i = 0; i < 20; ++i) { | 597 for (int i = 0; i < 20; ++i) { |
| 614 TypeHandle type = T.Random(); | 598 TypeHandle type = T.Random(); |
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1960 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 1944 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
| 1961 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 1945 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
| 1962 } | 1946 } |
| 1963 | 1947 |
| 1964 | 1948 |
| 1965 TEST(HTypeFromType) { | 1949 TEST(HTypeFromType) { |
| 1966 CcTest::InitializeVM(); | 1950 CcTest::InitializeVM(); |
| 1967 ZoneTests().HTypeFromType(); | 1951 ZoneTests().HTypeFromType(); |
| 1968 HeapTests().HTypeFromType(); | 1952 HeapTests().HTypeFromType(); |
| 1969 } | 1953 } |
| OLD | NEW |