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 <math.h> |
5 #include <vector> | 6 #include <vector> |
6 | 7 |
7 #include "src/hydrogen-types.h" | 8 #include "src/hydrogen-types.h" |
8 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
9 #include "src/types.h" | 10 #include "src/types.h" |
10 #include "test/cctest/cctest.h" | 11 #include "test/cctest/cctest.h" |
11 | 12 |
12 using namespace v8::internal; | 13 using namespace v8::internal; |
13 | 14 |
14 // Testing auxiliaries (breaking the Type abstraction). | 15 // Testing auxiliaries (breaking the Type abstraction). |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 133 |
133 NumberArray = Type::Array(Number, region); | 134 NumberArray = Type::Array(Number, region); |
134 StringArray = Type::Array(String, region); | 135 StringArray = Type::Array(String, region); |
135 AnyArray = Type::Array(Any, region); | 136 AnyArray = Type::Array(Any, region); |
136 | 137 |
137 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); | 138 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); |
138 NumberFunction1 = Type::Function(Number, Number, region); | 139 NumberFunction1 = Type::Function(Number, Number, region); |
139 NumberFunction2 = Type::Function(Number, Number, Number, region); | 140 NumberFunction2 = Type::Function(Number, Number, Number, region); |
140 MethodFunction = Type::Function(String, Object, 0, region); | 141 MethodFunction = Type::Function(String, Object, 0, region); |
141 | 142 |
142 for (int i = 0; i < 40; ++i) { | 143 for (int i = 0; i < 30; ++i) { |
143 types.push_back(Fuzz()); | 144 types.push_back(Fuzz()); |
144 } | 145 } |
145 } | 146 } |
146 | 147 |
147 Handle<i::Map> object_map; | 148 Handle<i::Map> object_map; |
148 Handle<i::Map> array_map; | 149 Handle<i::Map> array_map; |
149 Handle<i::Map> uninitialized_map; | 150 Handle<i::Map> uninitialized_map; |
150 | 151 |
151 Handle<i::Smi> smi; | 152 Handle<i::Smi> smi; |
152 Handle<i::HeapNumber> signed32; | 153 Handle<i::HeapNumber> signed32; |
(...skipping 29 matching lines...) Expand all Loading... |
182 typedef std::vector<TypeHandle> TypeVector; | 183 typedef std::vector<TypeHandle> TypeVector; |
183 typedef std::vector<Handle<i::Map> > MapVector; | 184 typedef std::vector<Handle<i::Map> > MapVector; |
184 typedef std::vector<Handle<i::Object> > ValueVector; | 185 typedef std::vector<Handle<i::Object> > ValueVector; |
185 typedef std::vector<double> DoubleVector; | 186 typedef std::vector<double> DoubleVector; |
186 | 187 |
187 TypeVector types; | 188 TypeVector types; |
188 MapVector maps; | 189 MapVector maps; |
189 ValueVector values; | 190 ValueVector values; |
190 DoubleVector doubles; // Some floating-point values, excluding NaN. | 191 DoubleVector doubles; // Some floating-point values, excluding NaN. |
191 | 192 |
| 193 // Range type helper functions, partially copied from types.cc. |
| 194 // Note: dle(dmin(x,y), dmax(x,y)) holds iff neither x nor y is NaN. |
| 195 bool dle(double x, double y) { |
| 196 return x <= y && copysign(1, x) <= copysign(1, y); |
| 197 } |
| 198 bool deq(double x, double y) { |
| 199 return dle(x, y) && dle(y, x); |
| 200 } |
| 201 double dmin(double x, double y) { |
| 202 return dle(x, y) ? x : y; |
| 203 } |
| 204 double dmax(double x, double y) { |
| 205 return dle(x, y) ? y : x; |
| 206 } |
| 207 |
192 TypeHandle Of(Handle<i::Object> value) { | 208 TypeHandle Of(Handle<i::Object> value) { |
193 return Type::Of(value, region_); | 209 return Type::Of(value, region_); |
194 } | 210 } |
195 | 211 |
196 TypeHandle NowOf(Handle<i::Object> value) { | 212 TypeHandle NowOf(Handle<i::Object> value) { |
197 return Type::NowOf(value, region_); | 213 return Type::NowOf(value, region_); |
198 } | 214 } |
199 | 215 |
200 TypeHandle Constant(Handle<i::Object> value) { | 216 TypeHandle Constant(Handle<i::Object> value) { |
201 return Type::Constant(value, region_); | 217 return Type::Constant(value, region_); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); | 558 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); |
543 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); | 559 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN)); |
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 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber)); |
546 } | 562 } |
547 | 563 |
548 void Range() { | 564 void Range() { |
549 // Constructor | 565 // Constructor |
550 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { | 566 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { |
551 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { | 567 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { |
552 double min = std::min(*i, *j); | 568 double min = T.dmin(*i, *j); |
553 double max = std::max(*i, *j); | 569 double max = T.dmax(*i, *j); |
554 TypeHandle type = T.Range(min, max); | 570 TypeHandle type = T.Range(min, max); |
555 CHECK(type->IsRange()); | 571 CHECK(type->IsRange()); |
556 } | 572 } |
557 } | 573 } |
558 | 574 |
559 // Range attributes | 575 // Range attributes |
560 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { | 576 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { |
561 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { | 577 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { |
562 double min = std::min(*i, *j); | 578 double min = T.dmin(*i, *j); |
563 double max = std::max(*i, *j); | 579 double max = T.dmax(*i, *j); |
564 printf("RangeType: min, max = %f, %f\n", min, max); | 580 printf("RangeType: min, max = %f, %f\n", min, max); |
565 TypeHandle type = T.Range(min, max); | 581 TypeHandle type = T.Range(min, max); |
566 printf("RangeType: Min, Max = %f, %f\n", | 582 printf("RangeType: Min, Max = %f, %f\n", |
567 type->AsRange()->Min(), type->AsRange()->Max()); | 583 type->AsRange()->Min(), type->AsRange()->Max()); |
568 CHECK(min == type->AsRange()->Min()); | 584 CHECK(min == type->AsRange()->Min()); |
569 CHECK(max == type->AsRange()->Max()); | 585 CHECK(max == type->AsRange()->Max()); |
570 } | 586 } |
571 } | 587 } |
572 | 588 |
573 // TODO(neis): enable once subtyping is updated. | 589 // TODO(neis): enable once subtyping is updated. |
574 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> | 590 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> |
575 // // min1 = min2 /\ max1 = max2 | 591 // // min1 = min2 /\ max1 = max2 |
576 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { | 592 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { |
577 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { | 593 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { |
578 // for (DoubleIterator i2 = T.doubles.begin(); | 594 // for (DoubleIterator i2 = T.doubles.begin(); |
579 // i2 != T.doubles.end(); ++i2) { | 595 // i2 != T.doubles.end(); ++i2) { |
580 // for (DoubleIterator j2 = T.doubles.begin(); | 596 // for (DoubleIterator j2 = T.doubles.begin(); |
581 // j2 != T.doubles.end(); ++j2) { | 597 // j2 != T.doubles.end(); ++j2) { |
582 // double min1 = std::min(*i1, *j1); | 598 // double min1 = T.dmin(*i1, *j1); |
583 // double max1 = std::max(*i1, *j1); | 599 // double max1 = T.dmax(*i1, *j1); |
584 // double min2 = std::min(*i2, *j2); | 600 // double min2 = T.dmin(*i2, *j2); |
585 // double max2 = std::max(*i2, *j2); | 601 // double max2 = T.dmax(*i2, *j2); |
586 // TypeHandle type1 = T.Range(min1, max1); | 602 // TypeHandle type1 = T.Range(min1, max1); |
587 // TypeHandle type2 = T.Range(min2, max2); | 603 // TypeHandle type2 = T.Range(min2, max2); |
588 // CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); | 604 // CHECK(Equal(type1, type2) == |
| 605 // (T.deq(min1, min2) && T.deq(max1, max2))); |
589 // } | 606 // } |
590 // } | 607 // } |
591 // } | 608 // } |
592 // } | 609 // } |
593 } | 610 } |
594 | 611 |
595 void Array() { | 612 void Array() { |
596 // Constructor | 613 // Constructor |
597 for (int i = 0; i < 20; ++i) { | 614 for (int i = 0; i < 20; ++i) { |
598 TypeHandle type = T.Random(); | 615 TypeHandle type = T.Random(); |
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); | 1961 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); |
1945 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); | 1962 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); |
1946 } | 1963 } |
1947 | 1964 |
1948 | 1965 |
1949 TEST(HTypeFromType) { | 1966 TEST(HTypeFromType) { |
1950 CcTest::InitializeVM(); | 1967 CcTest::InitializeVM(); |
1951 ZoneTests().HTypeFromType(); | 1968 ZoneTests().HTypeFromType(); |
1952 HeapTests().HTypeFromType(); | 1969 HeapTests().HTypeFromType(); |
1953 } | 1970 } |
OLD | NEW |