diff --git a/src/types.cc b/src/types.cc index 417f83080f..45dcea2de7 100644 --- a/src/types.cc +++ b/src/types.cc @@ -10,21 +10,6 @@ namespace v8 { namespace internal { - -// ----------------------------------------------------------------------------- -// Range-related custom order on numbers. -// We want -0 to be less than +0. - -static bool le(double x, double y) { - return x <= y && copysign(1, x) <= copysign(1, y); -} - - -static bool eq(double x, double y) { - return le(x, y) && le(y, x); -} - - // ----------------------------------------------------------------------------- // Glb and lub computation. @@ -63,8 +48,6 @@ int TypeImpl::BitsetType::Lub(TypeImpl* type) { type->AsClass()->Bound(NULL)->AsBitset(); } else if (type->IsConstant()) { return type->AsConstant()->Bound()->AsBitset(); - } else if (type->IsRange()) { - return type->AsRange()->Bound()->AsBitset(); } else if (type->IsContext()) { return type->AsContext()->Bound()->AsBitset(); } else if (type->IsArray()) { @@ -95,8 +78,6 @@ int TypeImpl::BitsetType::InherentLub(TypeImpl* type) { return Lub(*type->AsClass()->Map()); } else if (type->IsConstant()) { return Lub(*type->AsConstant()->Value()); - } else if (type->IsRange()) { - return Lub(type->AsRange()->Min(), type->AsRange()->Max()); } else if (type->IsContext()) { return kInternal & kTaggedPtr; } else if (type->IsArray()) { @@ -131,18 +112,6 @@ int TypeImpl::BitsetType::Lub(double value) { } -template -int TypeImpl::BitsetType::Lub(double min, double max) { - DisallowHeapAllocation no_allocation; - DCHECK(le(min, max)); - if (eq(min, max)) return BitsetType::Lub(min); // Singleton range. - int bitset = BitsetType::kNumber ^ SEMANTIC(BitsetType::kNaN); - if (le(0, min) || max < 0) bitset ^= SEMANTIC(BitsetType::kMinusZero); - return bitset; - // TODO(neis): Could refine this further by doing more checks on min/max. -} - - template int TypeImpl::BitsetType::Lub(int32_t value) { if (value >= 0x40000000) { @@ -287,12 +256,6 @@ bool TypeImpl::SlowIs(TypeImpl* that) { && *this->AsConstant()->Value() == *that->AsConstant()->Value() && this->AsConstant()->Bound()->Is(that->AsConstant()->Bound()); } - if (that->IsRange()) { - return this->IsRange() - && this->AsRange()->Bound()->Is(that->AsRange()->Bound()) - && le(that->AsRange()->Min(), this->AsRange()->Min()) - && le(this->AsRange()->Max(), that->AsRange()->Max()); - } if (that->IsContext()) { return this->IsContext() && this->AsContext()->Outer()->Equals(that->AsContext()->Outer()); @@ -425,12 +388,6 @@ bool TypeImpl::Maybe(TypeImpl* that) { template bool TypeImpl::Contains(i::Object* value) { DisallowHeapAllocation no_allocation; - if (this->IsRange()) { - return value->IsNumber() && - le(this->AsRange()->Min(), value->Number()) && - le(value->Number(), this->AsRange()->Max()) && - BitsetType::Is(BitsetType::Lub(value), this->BitsetLub()); - } for (Iterator it = this->Constants(); !it.Done(); it.Advance()) { if (*it.Current() == value) return true; } @@ -463,9 +420,6 @@ typename TypeImpl::TypeHandle TypeImpl::Rebound( return ClassType::New(this->AsClass()->Map(), bound, region); } else if (this->IsConstant()) { return ConstantType::New(this->AsConstant()->Value(), bound, region); - } else if (this->IsRange()) { - return RangeType::New( - this->AsRange()->Min(), this->AsRange()->Max(), bound, region); } else if (this->IsContext()) { return ContextType::New(this->AsContext()->Outer(), bound, region); } else if (this->IsArray()) { @@ -554,8 +508,8 @@ int TypeImpl::ExtendUnion( } } } else if (!type->IsBitset()) { - DCHECK(type->IsClass() || type->IsConstant() || type->IsRange() || - type->IsContext() || type->IsArray() || type->IsFunction()); + DCHECK(type->IsClass() || type->IsConstant() || + type->IsArray() || type->IsFunction() || type->IsContext()); int inherent_bound = type->InherentBitsetLub(); int old_bound = type->BitsetLub(); int other_bound = type->BoundBy(other->unhandle()) & inherent_bound; @@ -798,10 +752,6 @@ typename TypeImpl::TypeHandle TypeImpl::Convert( } else if (type->IsConstant()) { TypeHandle bound = Convert(type->AsConstant()->Bound(), region); return ConstantType::New(type->AsConstant()->Value(), bound, region); - } else if (type->IsRange()) { - TypeHandle bound = Convert(type->AsRange()->Bound(), region); - return RangeType::New( - type->AsRange()->Min(), type->AsRange()->Max(), bound, region); } else if (type->IsContext()) { TypeHandle bound = Convert(type->AsContext()->Bound(), region); TypeHandle outer = Convert(type->AsContext()->Outer(), region); diff --git a/src/types.h b/src/types.h index cca8b3167b..6d60b38db9 100644 --- a/src/types.h +++ b/src/types.h @@ -286,7 +286,7 @@ class TypeImpl : public Config::Base { return ClassType::New(map, region); } static TypeHandle Constant(i::Handle value, Region* region) { - // TODO(neis): Return RangeType for numerical values. + // TODO(neis): return RangeType for numerical values return ConstantType::New(value, region); } static TypeHandle Range(double min, double max, Region* region) { @@ -518,7 +518,6 @@ class TypeImpl::BitsetType : public TypeImpl { static int Lub(int32_t value); static int Lub(uint32_t value); static int Lub(i::Map* map); - static int Lub(double min, double max); static int InherentLub(TypeImpl* type); static const char* Name(int bitset); @@ -691,7 +690,8 @@ class TypeImpl::RangeType : public StructuralType { static RangeHandle New( double min, double max, TypeHandle bound, Region* region) { - DCHECK(BitsetType::Is(bound->AsBitset(), BitsetType::Lub(min, max))); + DCHECK(BitsetType::Is(bound->AsBitset(), BitsetType::kNumber)); + DCHECK(!std::isnan(min) && !std::isnan(max) && min <= max); RangeHandle type = Config::template cast( StructuralType::New(StructuralType::kRangeTag, 3, region)); type->Set(0, bound); @@ -704,7 +704,7 @@ class TypeImpl::RangeType : public StructuralType { } static RangeHandle New(double min, double max, Region* region) { - TypeHandle bound = BitsetType::New(BitsetType::Lub(min, max), region); + TypeHandle bound = BitsetType::New(BitsetType::kNumber, region); return New(min, max, bound, region); } diff --git a/test/cctest/test-types.cc b/test/cctest/test-types.cc index bc73babb8f..9279ccb9ed 100644 --- a/test/cctest/test-types.cc +++ b/test/cctest/test-types.cc @@ -189,21 +189,6 @@ class Types { ValueVector values; DoubleVector doubles; // Some floating-point values, excluding NaN. - // Range type helper functions, partially copied from types.cc. - // Note: le(min(x,y), max(x,y)) holds iff neither x nor y is NaN. - bool le(double x, double y) { - return x <= y && copysign(1, x) <= copysign(1, y); - } - bool eq(double x, double y) { - return le(x, y) && le(y, x); - } - double min(double x, double y) { - return le(x, y) ? x : y; - } - double max(double x, double y) { - return le(x, y) ? y : x; - } - TypeHandle Of(Handle value) { return Type::Of(value, region_); } @@ -564,8 +549,8 @@ struct Tests : Rep { // Constructor for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { - double min = T.min(*i, *j); - double max = T.max(*i, *j); + double min = std::min(*i, *j); + double max = std::max(*i, *j); TypeHandle type = T.Range(min, max); CHECK(type->IsRange()); } @@ -574,8 +559,8 @@ struct Tests : Rep { // Range attributes for (DoubleIterator i = T.doubles.begin(); i != T.doubles.end(); ++i) { for (DoubleIterator j = T.doubles.begin(); j != T.doubles.end(); ++j) { - double min = T.min(*i, *j); - double max = T.max(*i, *j); + double min = std::min(*i, *j); + double max = std::max(*i, *j); printf("RangeType: min, max = %f, %f\n", min, max); TypeHandle type = T.Range(min, max); printf("RangeType: Min, Max = %f, %f\n", @@ -594,14 +579,13 @@ struct Tests : Rep { // i2 != T.doubles.end(); ++i2) { // for (DoubleIterator j2 = T.doubles.begin(); // j2 != T.doubles.end(); ++j2) { -// double min1 = T.min(*i1, *j1); -// double max1 = T.max(*i1, *j1); -// double min2 = T.min(*i2, *j2); -// double max2 = T.max(*i2, *j2); +// double min1 = std::min(*i1, *j1); +// double max1 = std::max(*i1, *j1); +// double min2 = std::min(*i2, *j2); +// double max2 = std::max(*i2, *j2); // TypeHandle type1 = T.Range(min1, max1); // TypeHandle type2 = T.Range(min2, max2); -// CHECK(Equal(type1, type2) == -// (T.eq(min1, min2) && T.eq(max1, max2))); +// CHECK(Equal(type1, type2) == (min1 == min2 && max1 == max2)); // } // } // }