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

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

Issue 563283003: Revert r23916, r23917 for breaking 64-bit tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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
« no previous file with comments | « src/types-inl.h ('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"
11 11
12 using namespace v8::internal; 12 using namespace v8::internal;
13 13
14 // Testing auxiliaries (breaking the Type abstraction). 14 // Testing auxiliaries (breaking the Type abstraction).
15 typedef uintptr_t bitset;
16
17 struct ZoneRep { 15 struct ZoneRep {
18 typedef void* Struct; 16 typedef void* Struct;
19 17
20 static bool IsStruct(Type* t, int tag) { 18 static bool IsStruct(Type* t, int tag) {
21 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag; 19 return !IsBitset(t) && reinterpret_cast<intptr_t>(AsStruct(t)[0]) == tag;
22 } 20 }
23 static bool IsBitset(Type* t) { return reinterpret_cast<bitset>(t) & 1; } 21 static bool IsBitset(Type* t) { return reinterpret_cast<intptr_t>(t) & 1; }
24 static bool IsUnion(Type* t) { return IsStruct(t, 6); } 22 static bool IsUnion(Type* t) { return IsStruct(t, 6); }
25 23
26 static Struct* AsStruct(Type* t) { 24 static Struct* AsStruct(Type* t) {
27 return reinterpret_cast<Struct*>(t); 25 return reinterpret_cast<Struct*>(t);
28 } 26 }
29 static bitset AsBitset(Type* t) { 27 static int AsBitset(Type* t) {
30 return reinterpret_cast<bitset>(t) ^ 1u; 28 return static_cast<int>(reinterpret_cast<intptr_t>(t) >> 1);
31 } 29 }
32 static Struct* AsUnion(Type* t) { 30 static Struct* AsUnion(Type* t) {
33 return AsStruct(t); 31 return AsStruct(t);
34 } 32 }
35 static int Length(Struct* structured) { 33 static int Length(Struct* structured) {
36 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1])); 34 return static_cast<int>(reinterpret_cast<intptr_t>(structured[1]));
37 } 35 }
38 36
39 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; } 37 static Zone* ToRegion(Zone* zone, Isolate* isolate) { return zone; }
40 38
41 struct BitsetType : Type::BitsetType { 39 struct BitsetType : Type::BitsetType {
42 using Type::BitsetType::New; 40 using Type::BitsetType::New;
43 using Type::BitsetType::Glb; 41 using Type::BitsetType::Glb;
44 using Type::BitsetType::Lub; 42 using Type::BitsetType::Lub;
45 using Type::BitsetType::InherentLub; 43 using Type::BitsetType::InherentLub;
46 }; 44 };
47 }; 45 };
48 46
49 47
50 struct HeapRep { 48 struct HeapRep {
51 typedef FixedArray Struct; 49 typedef FixedArray Struct;
52 50
53 static bool IsStruct(Handle<HeapType> t, int tag) { 51 static bool IsStruct(Handle<HeapType> t, int tag) {
54 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag; 52 return t->IsFixedArray() && Smi::cast(AsStruct(t)->get(0))->value() == tag;
55 } 53 }
56 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); } 54 static bool IsBitset(Handle<HeapType> t) { return t->IsSmi(); }
57 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 6); } 55 static bool IsUnion(Handle<HeapType> t) { return IsStruct(t, 6); }
58 56
59 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); } 57 static Struct* AsStruct(Handle<HeapType> t) { return FixedArray::cast(*t); }
60 static bitset AsBitset(Handle<HeapType> t) { 58 static int AsBitset(Handle<HeapType> t) { return Smi::cast(*t)->value(); }
61 return reinterpret_cast<bitset>(*t);
62 }
63 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); } 59 static Struct* AsUnion(Handle<HeapType> t) { return AsStruct(t); }
64 static int Length(Struct* structured) { return structured->length() - 1; } 60 static int Length(Struct* structured) { return structured->length() - 1; }
65 61
66 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; } 62 static Isolate* ToRegion(Zone* zone, Isolate* isolate) { return isolate; }
67 63
68 struct BitsetType : HeapType::BitsetType { 64 struct BitsetType : HeapType::BitsetType {
69 using HeapType::BitsetType::New; 65 using HeapType::BitsetType::New;
70 using HeapType::BitsetType::Glb; 66 using HeapType::BitsetType::Glb;
71 using HeapType::BitsetType::Lub; 67 using HeapType::BitsetType::Lub;
72 using HeapType::BitsetType::InherentLub; 68 using HeapType::BitsetType::InherentLub;
73 static bitset Glb(Handle<HeapType> type) { return Glb(*type); } 69 static int Glb(Handle<HeapType> type) { return Glb(*type); }
74 static bitset Lub(Handle<HeapType> type) { return Lub(*type); } 70 static int Lub(Handle<HeapType> type) { return Lub(*type); }
75 static bitset InherentLub(Handle<HeapType> type) { 71 static int InherentLub(Handle<HeapType> type) { return InherentLub(*type); }
76 return InherentLub(*type);
77 }
78 }; 72 };
79 }; 73 };
80 74
81 75
82 template<class Type, class TypeHandle, class Region> 76 template<class Type, class TypeHandle, class Region>
83 class Types { 77 class Types {
84 public: 78 public:
85 Types(Region* region, Isolate* isolate) 79 Types(Region* region, Isolate* isolate)
86 : region_(region), rng_(isolate->random_number_generator()) { 80 : region_(region), rng_(isolate->random_number_generator()) {
87 #define DECLARE_TYPE(name, value) \ 81 #define DECLARE_TYPE(name, value) \
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 358 }
365 359
366 void CheckEqual(TypeHandle type1, TypeHandle type2) { 360 void CheckEqual(TypeHandle type1, TypeHandle type2) {
367 CHECK(Equal(type1, type2)); 361 CHECK(Equal(type1, type2));
368 } 362 }
369 363
370 void CheckSub(TypeHandle type1, TypeHandle type2) { 364 void CheckSub(TypeHandle type1, TypeHandle type2) {
371 CHECK(type1->Is(type2)); 365 CHECK(type1->Is(type2));
372 CHECK(!type2->Is(type1)); 366 CHECK(!type2->Is(type1));
373 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 367 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
374 CHECK(Rep::AsBitset(type1) != Rep::AsBitset(type2)); 368 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2));
375 } 369 }
376 } 370 }
377 371
378 void CheckUnordered(TypeHandle type1, TypeHandle type2) { 372 void CheckUnordered(TypeHandle type1, TypeHandle type2) {
379 CHECK(!type1->Is(type2)); 373 CHECK(!type1->Is(type2));
380 CHECK(!type2->Is(type1)); 374 CHECK(!type2->Is(type1));
381 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 375 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
382 CHECK(Rep::AsBitset(type1) != Rep::AsBitset(type2)); 376 CHECK_NE(Rep::AsBitset(type1), Rep::AsBitset(type2));
383 } 377 }
384 } 378 }
385 379
386 void CheckOverlap(TypeHandle type1, TypeHandle type2, TypeHandle mask) { 380 void CheckOverlap(TypeHandle type1, TypeHandle type2, TypeHandle mask) {
387 CHECK(type1->Maybe(type2)); 381 CHECK(type1->Maybe(type2));
388 CHECK(type2->Maybe(type1)); 382 CHECK(type2->Maybe(type1));
389 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 383 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
390 CHECK(0 != 384 CHECK_NE(0,
391 (Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask))); 385 Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask));
392 } 386 }
393 } 387 }
394 388
395 void CheckDisjoint(TypeHandle type1, TypeHandle type2, TypeHandle mask) { 389 void CheckDisjoint(TypeHandle type1, TypeHandle type2, TypeHandle mask) {
396 CHECK(!type1->Is(type2)); 390 CHECK(!type1->Is(type2));
397 CHECK(!type2->Is(type1)); 391 CHECK(!type2->Is(type1));
398 CHECK(!type1->Maybe(type2)); 392 CHECK(!type1->Maybe(type2));
399 CHECK(!type2->Maybe(type1)); 393 CHECK(!type2->Maybe(type1));
400 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) { 394 if (Rep::IsBitset(type1) && Rep::IsBitset(type2)) {
401 CHECK(0 == 395 CHECK_EQ(0,
402 (Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask))); 396 Rep::AsBitset(type1) & Rep::AsBitset(type2) & Rep::AsBitset(mask));
403 } 397 }
404 } 398 }
405 399
406 void Bitset() { 400 void Bitset() {
407 // None and Any are bitsets. 401 // None and Any are bitsets.
408 CHECK(this->IsBitset(T.None)); 402 CHECK(this->IsBitset(T.None));
409 CHECK(this->IsBitset(T.Any)); 403 CHECK(this->IsBitset(T.Any));
410 404
411 CHECK(0 == this->AsBitset(T.None)); 405 CHECK_EQ(0, this->AsBitset(T.None));
412 CHECK(0xfffffffeu == this->AsBitset(T.Any)); 406 CHECK_EQ(-1, this->AsBitset(T.Any));
413 407
414 // Union(T1, T2) is bitset for bitsets T1,T2 408 // Union(T1, T2) is bitset for bitsets T1,T2
415 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 409 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
416 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 410 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
417 TypeHandle type1 = *it1; 411 TypeHandle type1 = *it1;
418 TypeHandle type2 = *it2; 412 TypeHandle type2 = *it2;
419 TypeHandle union12 = T.Union(type1, type2); 413 TypeHandle union12 = T.Union(type1, type2);
420 CHECK(!(this->IsBitset(type1) && this->IsBitset(type2)) || 414 CHECK(!(this->IsBitset(type1) && this->IsBitset(type2)) ||
421 this->IsBitset(union12)); 415 this->IsBitset(union12));
422 } 416 }
(...skipping 21 matching lines...) Expand all
444 } 438 }
445 } 439 }
446 440
447 // Union(T1, T2) is bitwise disjunction for bitsets T1,T2 441 // Union(T1, T2) is bitwise disjunction for bitsets T1,T2
448 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 442 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
449 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 443 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
450 TypeHandle type1 = *it1; 444 TypeHandle type1 = *it1;
451 TypeHandle type2 = *it2; 445 TypeHandle type2 = *it2;
452 TypeHandle union12 = T.Union(type1, type2); 446 TypeHandle union12 = T.Union(type1, type2);
453 if (this->IsBitset(type1) && this->IsBitset(type2)) { 447 if (this->IsBitset(type1) && this->IsBitset(type2)) {
454 CHECK( 448 CHECK_EQ(
455 (this->AsBitset(type1) | this->AsBitset(type2)) == 449 this->AsBitset(type1) | this->AsBitset(type2),
456 this->AsBitset(union12)); 450 this->AsBitset(union12));
457 } 451 }
458 } 452 }
459 } 453 }
460 454
461 // Intersect(T1, T2) is bitwise conjunction for bitsets T1,T2 455 // Intersect(T1, T2) is bitwise conjunction for bitsets T1,T2
462 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) { 456 for (TypeIterator it1 = T.types.begin(); it1 != T.types.end(); ++it1) {
463 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) { 457 for (TypeIterator it2 = T.types.begin(); it2 != T.types.end(); ++it2) {
464 TypeHandle type1 = *it1; 458 TypeHandle type1 = *it1;
465 TypeHandle type2 = *it2; 459 TypeHandle type2 = *it2;
466 TypeHandle intersect12 = T.Intersect(type1, type2); 460 TypeHandle intersect12 = T.Intersect(type1, type2);
467 if (this->IsBitset(type1) && this->IsBitset(type2)) { 461 if (this->IsBitset(type1) && this->IsBitset(type2)) {
468 CHECK( 462 CHECK_EQ(
469 (this->AsBitset(type1) & this->AsBitset(type2)) == 463 this->AsBitset(type1) & this->AsBitset(type2),
470 this->AsBitset(intersect12)); 464 this->AsBitset(intersect12));
471 } 465 }
472 } 466 }
473 } 467 }
474 } 468 }
475 469
476 void Class() { 470 void Class() {
477 // Constructor 471 // Constructor
478 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) { 472 for (MapIterator mt = T.maps.begin(); mt != T.maps.end(); ++mt) {
479 Handle<i::Map> map = *mt; 473 Handle<i::Map> map = *mt;
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1968 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>(); 1962 ZoneTests().Convert<HeapType, Handle<HeapType>, Isolate, HeapRep>();
1969 HeapTests().Convert<Type, Type*, Zone, ZoneRep>(); 1963 HeapTests().Convert<Type, Type*, Zone, ZoneRep>();
1970 } 1964 }
1971 1965
1972 1966
1973 TEST(HTypeFromType) { 1967 TEST(HTypeFromType) {
1974 CcTest::InitializeVM(); 1968 CcTest::InitializeVM();
1975 ZoneTests().HTypeFromType(); 1969 ZoneTests().HTypeFromType();
1976 HeapTests().HTypeFromType(); 1970 HeapTests().HTypeFromType();
1977 } 1971 }
OLDNEW
« no previous file with comments | « src/types-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698