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