Chromium Code Reviews

Side by Side Diff: src/types.h

Issue 437393005: 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.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | src/types.cc » ('j') | src/types.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #ifndef V8_TYPES_H_ 5 #ifndef V8_TYPES_H_
6 #define V8_TYPES_H_ 6 #define V8_TYPES_H_
7 7
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/ostreams.h" 10 #include "src/ostreams.h"
(...skipping 267 matching lines...)
278 static TypeHandle type(Region* region) { \ 278 static TypeHandle type(Region* region) { \
279 return BitsetType::New(BitsetType::k##type, region); \ 279 return BitsetType::New(BitsetType::k##type, region); \
280 } 280 }
281 BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) 281 BITSET_TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR)
282 #undef DEFINE_TYPE_CONSTRUCTOR 282 #undef DEFINE_TYPE_CONSTRUCTOR
283 283
284 static TypeHandle Class(i::Handle<i::Map> map, Region* region) { 284 static TypeHandle Class(i::Handle<i::Map> map, Region* region) {
285 return ClassType::New(map, region); 285 return ClassType::New(map, region);
286 } 286 }
287 static TypeHandle Constant(i::Handle<i::Object> value, Region* region) { 287 static TypeHandle Constant(i::Handle<i::Object> value, Region* region) {
288 // TODO(neis): return RangeType for numerical values 288 // TODO(neis): Return RangeType for numerical values.
289 return ConstantType::New(value, region); 289 return ConstantType::New(value, region);
290 } 290 }
291 static TypeHandle Range(double min, double max, Region* region) { 291 static TypeHandle Range(double min, double max, Region* region) {
292 return RangeType::New(min, max, region); 292 return RangeType::New(min, max, region);
293 } 293 }
294 static TypeHandle Context(TypeHandle outer, Region* region) { 294 static TypeHandle Context(TypeHandle outer, Region* region) {
295 return ContextType::New(outer, region); 295 return ContextType::New(outer, region);
296 } 296 }
297 static TypeHandle Array(TypeHandle element, Region* region) { 297 static TypeHandle Array(TypeHandle element, Region* region) {
298 return ArrayType::New(element, region); 298 return ArrayType::New(element, region);
(...skipping 208 matching lines...)
507 return (bitset1 | bitset2) == bitset2; 507 return (bitset1 | bitset2) == bitset2;
508 } 508 }
509 509
510 static int Glb(TypeImpl* type); // greatest lower bound that's a bitset 510 static int Glb(TypeImpl* type); // greatest lower bound that's a bitset
511 static int Lub(TypeImpl* type); // least upper bound that's a bitset 511 static int Lub(TypeImpl* type); // least upper bound that's a bitset
512 static int Lub(i::Object* value); 512 static int Lub(i::Object* value);
513 static int Lub(double value); 513 static int Lub(double value);
514 static int Lub(int32_t value); 514 static int Lub(int32_t value);
515 static int Lub(uint32_t value); 515 static int Lub(uint32_t value);
516 static int Lub(i::Map* map); 516 static int Lub(i::Map* map);
517 static int RangeLub(double min, double max, TypeHandle bound);
rossberg 2014/08/05 14:49:15 Is this defined anywhere?
neis 2014/08/06 13:15:01 Oops, was a leftover.
517 static int InherentLub(TypeImpl* type); 518 static int InherentLub(TypeImpl* type);
518 519
519 static const char* Name(int bitset); 520 static const char* Name(int bitset);
520 static void Print(OStream& os, int bitset); // NOLINT 521 static void Print(OStream& os, int bitset); // NOLINT
521 using TypeImpl::PrintTo; 522 using TypeImpl::PrintTo;
522 }; 523 };
523 524
524 525
525 // ----------------------------------------------------------------------------- 526 // -----------------------------------------------------------------------------
526 // Superclass for non-bitset types (internal). 527 // Superclass for non-bitset types (internal).
(...skipping 150 matching lines...)
677 // ----------------------------------------------------------------------------- 678 // -----------------------------------------------------------------------------
678 // Range types. 679 // Range types.
679 680
680 template<class Config> 681 template<class Config>
681 class TypeImpl<Config>::RangeType : public StructuralType { 682 class TypeImpl<Config>::RangeType : public StructuralType {
682 public: 683 public:
683 TypeHandle Bound() { return this->Get(0); } 684 TypeHandle Bound() { return this->Get(0); }
684 double Min() { return this->template GetValue<i::HeapNumber>(1)->value(); } 685 double Min() { return this->template GetValue<i::HeapNumber>(1)->value(); }
685 double Max() { return this->template GetValue<i::HeapNumber>(2)->value(); } 686 double Max() { return this->template GetValue<i::HeapNumber>(2)->value(); }
686 687
688 static bool le(double x, double y) {
rossberg 2014/08/05 14:49:15 These are helpers that shouldn't pollute the publi
neis 2014/08/06 13:15:01 Done.
689 return x <= y && copysign(1, x) <= copysign(1, y);
690 }
691 static bool eq(double x, double y) {
692 return le(x, y) && le(y, x);
693 }
694 static double min(double x, double y) {
695 return le(x, y) ? x : y;
696 }
697 static double max(double x, double y) {
698 return le(x, y) ? y : x;
699 }
700
701 static int InherentLub(double min, double max) {
rossberg 2014/08/05 14:49:15 Rename/move this to BitsetType::Lub(double, double
neis 2014/08/06 13:15:01 Done.
702 DCHECK(le(min, max));
703 DisallowHeapAllocation no_allocation;
704 if (min == max) {
rossberg 2014/08/05 14:49:15 eq(min, max)
neis 2014/08/06 13:15:01 Done.
705 return BitsetType::Lub(min); // Singleton range.
706 }
707 int bitset = BitsetType::kNumber ^ SEMANTIC(BitsetType::kNaN);
708 if (le(0, min) || max < 0)
709 bitset ^= SEMANTIC(BitsetType::kMinusZero);
710 return bitset;
711 // TODO(neis): Could refine this further by doing more checks on min/max.
712 }
713
687 static RangeHandle New( 714 static RangeHandle New(
688 double min, double max, TypeHandle bound, Region* region) { 715 double min, double max, TypeHandle bound, Region* region) {
689 DCHECK(BitsetType::Is(bound->AsBitset(), BitsetType::kNumber)); 716 DCHECK(le(min, max));
690 DCHECK(!std::isnan(min) && !std::isnan(max) && min <= max); 717 DCHECK(bound->IsBitset());
718 DCHECK(BitsetType::Is(bound->AsBitset(), InherentLub(min, max)));
691 RangeHandle type = Config::template cast<RangeType>( 719 RangeHandle type = Config::template cast<RangeType>(
692 StructuralType::New(StructuralType::kRangeTag, 3, region)); 720 StructuralType::New(StructuralType::kRangeTag, 3, region));
693 type->Set(0, bound); 721 type->Set(0, bound);
694 Factory* factory = Config::isolate(region)->factory(); 722 Factory* factory = Config::isolate(region)->factory();
695 Handle<HeapNumber> minV = factory->NewHeapNumber(min); 723 Handle<HeapNumber> minV = factory->NewHeapNumber(min);
696 Handle<HeapNumber> maxV = factory->NewHeapNumber(max); 724 Handle<HeapNumber> maxV = factory->NewHeapNumber(max);
697 type->SetValue(1, minV); 725 type->SetValue(1, minV);
698 type->SetValue(2, maxV); 726 type->SetValue(2, maxV);
699 return type; 727 return type;
700 } 728 }
701 729
702 static RangeHandle New(double min, double max, Region* region) { 730 static RangeHandle New(double min, double max, Region* region) {
703 TypeHandle bound = BitsetType::New(BitsetType::kNumber, region); 731 TypeHandle bound = BitsetType::New(InherentLub(min, max), region);
704 return New(min, max, bound, region); 732 return New(min, max, bound, region);
705 } 733 }
706 734
707 static RangeType* cast(TypeImpl* type) { 735 static RangeType* cast(TypeImpl* type) {
708 DCHECK(type->IsRange()); 736 DCHECK(type->IsRange());
709 return static_cast<RangeType*>(type); 737 return static_cast<RangeType*>(type);
710 } 738 }
711 }; 739 };
712 740
713 741
(...skipping 277 matching lines...)
991 bool Narrows(BoundsImpl that) { 1019 bool Narrows(BoundsImpl that) {
992 return that.lower->Is(this->lower) && this->upper->Is(that.upper); 1020 return that.lower->Is(this->lower) && this->upper->Is(that.upper);
993 } 1021 }
994 }; 1022 };
995 1023
996 typedef BoundsImpl<ZoneTypeConfig> Bounds; 1024 typedef BoundsImpl<ZoneTypeConfig> Bounds;
997 1025
998 } } // namespace v8::internal 1026 } } // namespace v8::internal
999 1027
1000 #endif // V8_TYPES_H_ 1028 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « no previous file | src/types.cc » ('j') | src/types.cc » ('J')

Powered by Google App Engine