Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(849)

Side by Side Diff: test/cctest/test-types.cc

Issue 448093002: Extend some operations to range types. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/types.cc ('K') | « src/types.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 NumberArray = Type::Array(Number, region); 133 NumberArray = Type::Array(Number, region);
134 StringArray = Type::Array(String, region); 134 StringArray = Type::Array(String, region);
135 AnyArray = Type::Array(Any, region); 135 AnyArray = Type::Array(Any, region);
136 136
137 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region); 137 SignedFunction1 = Type::Function(SignedSmall, SignedSmall, region);
138 NumberFunction1 = Type::Function(Number, Number, region); 138 NumberFunction1 = Type::Function(Number, Number, region);
139 NumberFunction2 = Type::Function(Number, Number, Number, region); 139 NumberFunction2 = Type::Function(Number, Number, Number, region);
140 MethodFunction = Type::Function(String, Object, 0, region); 140 MethodFunction = Type::Function(String, Object, 0, region);
141 141
142 for (int i = 0; i < 40; ++i) { 142 for (int i = 0; i < 30; ++i) {
143 types.push_back(Fuzz()); 143 types.push_back(Fuzz());
144 } 144 }
145 } 145 }
146 146
147 Handle<i::Map> object_map; 147 Handle<i::Map> object_map;
148 Handle<i::Map> array_map; 148 Handle<i::Map> array_map;
149 Handle<i::Map> uninitialized_map; 149 Handle<i::Map> uninitialized_map;
150 150
151 Handle<i::Smi> smi; 151 Handle<i::Smi> smi;
152 Handle<i::HeapNumber> signed32; 152 Handle<i::HeapNumber> signed32;
(...skipping 29 matching lines...) Expand all
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: dle(dmin(x,y), dmax(x,y)) holds iff neither x nor y is NaN.
194 bool dle(double x, double y) {
195 return x <= y && (!IsMinusZero(y) || x != 0 || IsMinusZero(x));
196 }
197 bool deq(double x, double y) {
198 return dle(x, y) && dle(y, x);
199 }
200 double dmin(double x, double y) {
201 return dle(x, y) ? x : y;
202 }
203 double dmax(double x, double y) {
204 return dle(x, y) ? y : x;
205 }
206
192 TypeHandle Of(Handle<i::Object> value) { 207 TypeHandle Of(Handle<i::Object> value) {
193 return Type::Of(value, region_); 208 return Type::Of(value, region_);
194 } 209 }
195 210
196 TypeHandle NowOf(Handle<i::Object> value) { 211 TypeHandle NowOf(Handle<i::Object> value) {
197 return Type::NowOf(value, region_); 212 return Type::NowOf(value, region_);
198 } 213 }
199 214
200 TypeHandle Constant(Handle<i::Object> value) { 215 TypeHandle Constant(Handle<i::Object> value) {
201 return Type::Constant(value, region_); 216 return Type::Constant(value, region_);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 CHECK(T.Constant(fac->NewNumber(-1.0*0.0))->Is(T.MinusZero)); 557 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)); 558 CHECK(T.Constant(fac->NewNumber(v8::base::OS::nan_value()))->Is(T.NaN));
544 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber)); 559 CHECK(T.Constant(fac->NewNumber(V8_INFINITY))->Is(T.OtherNumber));
545 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber)); 560 CHECK(T.Constant(fac->NewNumber(-V8_INFINITY))->Is(T.OtherNumber));
546 } 561 }
547 562
548 void Range() { 563 void Range() {
549 // Constructor 564 // Constructor
550 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { 565 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) {
551 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { 566 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) {
552 double min = std::min(*i, *j); 567 double min = T.dmin(*i, *j);
553 double max = std::max(*i, *j); 568 double max = T.dmax(*i, *j);
554 TypeHandle type = T.Range(min, max); 569 TypeHandle type = T.Range(min, max);
555 CHECK(type->IsRange()); 570 CHECK(type->IsRange());
556 } 571 }
557 } 572 }
558 573
559 // Range attributes 574 // Range attributes
560 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { 575 for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) {
561 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { 576 for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) {
562 double min = std::min(*i, *j); 577 double min = T.dmin(*i, *j);
563 double max = std::max(*i, *j); 578 double max = T.dmax(*i, *j);
564 printf("RangeType: min, max = %f, %f\n", min, max); 579 printf("RangeType: min, max = %f, %f\n", min, max);
565 TypeHandle type = T.Range(min, max); 580 TypeHandle type = T.Range(min, max);
566 printf("RangeType: Min, Max = %f, %f\n", 581 printf("RangeType: Min, Max = %f, %f\n",
567 type->AsRange()->Min(), type->AsRange()->Max()); 582 type->AsRange()->Min(), type->AsRange()->Max());
568 CHECK(min == type->AsRange()->Min()); 583 CHECK(min == type->AsRange()->Min());
569 CHECK(max == type->AsRange()->Max()); 584 CHECK(max == type->AsRange()->Max());
570 } 585 }
571 } 586 }
572 587
573 // TODO(neis): enable once subtyping is updated. 588 // TODO(neis): enable once subtyping is updated.
574 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=> 589 // // Functionality & Injectivity: Range(min1, max1) = Range(min2, max2) <=>
575 // // min1 = min2 /\ max1 = max2 590 // // min1 = min2 /\ max1 = max2
576 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) { 591 // for (DoubleIterator i1 = T.doubles.begin(); i1 != T.doubles.end(); ++i1) {
577 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) { 592 // for (DoubleIterator j1 = T.doubles.begin(); j1 != T.doubles.end(); ++j1) {
578 // for (DoubleIterator i2 = T.doubles.begin(); 593 // for (DoubleIterator i2 = T.doubles.begin();
579 // i2 != T.doubles.end(); ++i2) { 594 // i2 != T.doubles.end(); ++i2) {
580 // for (DoubleIterator j2 = T.doubles.begin(); 595 // for (DoubleIterator j2 = T.doubles.begin();
581 // j2 != T.doubles.end(); ++j2) { 596 // j2 != T.doubles.end(); ++j2) {
582 // double min1 = std::min(*i1, *j1); 597 // double min1 = T.dmin(*i1, *j1);
583 // double max1 = std::max(*i1, *j1); 598 // double max1 = T.dmax(*i1, *j1);
584 // double min2 = std::min(*i2, *j2); 599 // double min2 = T.dmin(*i2, *j2);
585 // double max2 = std::max(*i2, *j2); 600 // double max2 = T.dmax(*i2, *j2);
586 // TypeHandle type1 = T.Range(min1, max1); 601 // TypeHandle type1 = T.Range(min1, max1);
587 // TypeHandle type2 = T.Range(min2, max2); 602 // TypeHandle type2 = T.Range(min2, max2);
588 // CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); 603 // CHECK(Equal(type1, type2) ==
604 // (T.deq(min1, min2) && T.deq(max1, max2)));
589 // } 605 // }
590 // } 606 // }
591 // } 607 // }
592 // } 608 // }
593 } 609 }
594 610
595 void Array() { 611 void Array() {
596 // Constructor 612 // Constructor
597 for (int i = 0; i < 20; ++i) { 613 for (int i = 0; i < 20; ++i) {
598 TypeHandle type = T.Random(); 614 TypeHandle type = T.Random();
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 1960 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
1945 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 1961 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
1946 } 1962 }
1947 1963
1948 1964
1949 TEST(HTypeFromType) { 1965 TEST(HTypeFromType) {
1950 CcTest::InitializeVM(); 1966 CcTest::InitializeVM();
1951 ZoneTests().HTypeFromType(); 1967 ZoneTests().HTypeFromType();
1952 HeapTests().HTypeFromType(); 1968 HeapTests().HTypeFromType();
1953 } 1969 }
OLDNEW
« src/types.cc ('K') | « src/types.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698