diff --git a/src/frame-element.h b/src/frame-element.h index a37a8dd350..3714ac9e66 100644 --- a/src/frame-element.h +++ b/src/frame-element.h @@ -28,7 +28,7 @@ #ifndef V8_FRAME_ELEMENT_H_ #define V8_FRAME_ELEMENT_H_ -#include "number-info.h" +#include "number-info-inl.h" #include "macro-assembler.h" #include "zone.h" @@ -58,13 +58,7 @@ class FrameElement BASE_EMBEDDED { // Copied elements do not have number info. Instead // we have to inspect their backing element in the frame. ASSERT(!is_copy()); - if (!is_constant()) { - return NumberInfo::FromInt(NumberInfoField::decode(value_)); - } - Handle value = handle(); - if (value->IsSmi()) return NumberInfo::Smi(); - if (value->IsHeapNumber()) return NumberInfo::HeapNumber(); - return NumberInfo::Unknown(); + return NumberInfo::FromInt(NumberInfoField::decode(value_)); } inline void set_number_info(NumberInfo info) { @@ -107,7 +101,8 @@ class FrameElement BASE_EMBEDDED { // compile time. static FrameElement ConstantElement(Handle value, SyncFlag is_synced) { - FrameElement result(value, is_synced); + NumberInfo info = NumberInfo::TypeFromValue(value); + FrameElement result(value, is_synced, info); return result; } @@ -232,11 +227,11 @@ class FrameElement BASE_EMBEDDED { } // Used to construct constant elements. - FrameElement(Handle value, SyncFlag is_synced) { + FrameElement(Handle value, SyncFlag is_synced, NumberInfo info) { value_ = TypeField::encode(CONSTANT) | CopiedField::encode(false) | SyncedField::encode(is_synced != NOT_SYNCED) - | NumberInfoField::encode(NumberInfo::Uninitialized().ToInt()) + | NumberInfoField::encode(info.ToInt()) | DataField::encode(ConstantList()->length()); ConstantList()->Add(value); } diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc index d71b63988d..683b18a4ef 100644 --- a/src/ia32/codegen-ia32.cc +++ b/src/ia32/codegen-ia32.cc @@ -9728,7 +9728,7 @@ void FloatingPointHelper::LoadNumbersAsIntegers(MacroAssembler* masm, Label arg2_is_object, check_undefined_arg2; Label load_arg2, done; - if (!number_info.IsHeapNumber()) { + if (!number_info.IsDouble()) { if (!number_info.IsSmi()) { __ test(edx, Immediate(kSmiTagMask)); __ j(not_zero, &arg1_is_object); @@ -9747,7 +9747,7 @@ void FloatingPointHelper::LoadNumbersAsIntegers(MacroAssembler* masm, // Here edx has the untagged integer, eax has a Smi or a heap number. __ bind(&load_arg2); - if (!number_info.IsHeapNumber()) { + if (!number_info.IsDouble()) { // Test if arg2 is a Smi. if (!number_info.IsSmi()) { __ test(eax, Immediate(kSmiTagMask)); diff --git a/src/number-info-inl.h b/src/number-info-inl.h new file mode 100644 index 0000000000..0b5a44d73f --- /dev/null +++ b/src/number-info-inl.h @@ -0,0 +1,55 @@ +// Copyright 2010 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef V8_NUMBER_INFO_INL_H_ +#define V8_NUMBER_INFO_INL_H_ + +#include "number-info.h" +#include "objects-inl.h" + +namespace v8 { +namespace internal { + + +NumberInfo NumberInfo::TypeFromValue(Handle value) { + NumberInfo info; + if (value->IsSmi()) { + info = NumberInfo::Smi(); + } else if (value->IsHeapNumber()) { + info = NumberInfo::IsInt32Double(HeapNumber::cast(*value)->value()) + ? NumberInfo::Integer32() + : NumberInfo::Double(); + } else { + info = NumberInfo::Unknown(); + } + return info; +} + + +} } // namespace v8::internal + +#endif // V8_NUMBER_INFO_INL_H_ diff --git a/src/number-info.h b/src/number-info.h index 9537668a7d..6ecae532f6 100644 --- a/src/number-info.h +++ b/src/number-info.h @@ -37,7 +37,7 @@ namespace internal { // | \--------| // Number String // / | | -// HeapNumber Integer32 | +// Double Integer32 | // | | / // | Smi / // | / / @@ -57,7 +57,7 @@ class NumberInfo { // We know it's a Smi. static inline NumberInfo Smi(); // We know it's a heap number. - static inline NumberInfo HeapNumber(); + static inline NumberInfo Double(); // We know it's a string. static inline NumberInfo String(); // We haven't started collecting info yet. @@ -85,7 +85,7 @@ class NumberInfo { t == kNumberType || t == kInteger32Type || t == kSmiType || - t == kHeapNumberType); + t == kDoubleType); return NumberInfo(t); } @@ -100,7 +100,7 @@ class NumberInfo { t == kNumberType || t == kInteger32Type || t == kSmiType || - t == kHeapNumberType || + t == kDoubleType || t == kStringType); return NumberInfo(t); } @@ -110,6 +110,22 @@ class NumberInfo { return NumberInfo(static_cast(a.type_ & b.type_)); } + + // Integer32 is an integer that can be represented as either a signed + // 32-bit integer or as an unsigned 32-bit integer. It has to be + // in the range [-2^31, 2^32 - 1]. + static inline bool IsInt32Double(double value) { + if (value >= -0x80000000 && value <= 0xffffffffu) { + if (value <= 0x7fffffff && value == static_cast(value)) { + return true; + } + if (value == static_cast(value)) return true; + } + return false; + } + + static inline NumberInfo TypeFromValue(Handle value); + inline bool IsUnknown() { return type_ == kUnknownType; } @@ -129,9 +145,9 @@ class NumberInfo { return ((type_ & kInteger32Type) == kInteger32Type); } - inline bool IsHeapNumber() { + inline bool IsDouble() { ASSERT(type_ != kUninitializedType); - return ((type_ & kHeapNumberType) == kHeapNumberType); + return ((type_ & kDoubleType) == kDoubleType); } inline bool IsUninitialized() { @@ -145,7 +161,7 @@ class NumberInfo { case kNumberType: return "NumberType"; case kInteger32Type: return "Integer32Type"; case kSmiType: return "SmiType"; - case kHeapNumberType: return "HeapNumberType"; + case kDoubleType: return "DoubleType"; case kStringType: return "StringType"; case kUninitializedType: UNREACHABLE(); @@ -163,7 +179,7 @@ class NumberInfo { kNumberType = 0x11, // 010001 kInteger32Type = 0x13, // 010011 kSmiType = 0x17, // 010111 - kHeapNumberType = 0x19, // 011001 + kDoubleType = 0x19, // 011001 kStringType = 0x30, // 110000 kUninitializedType = 0x3f // 111111 }; @@ -198,8 +214,8 @@ NumberInfo NumberInfo::Smi() { } -NumberInfo NumberInfo::HeapNumber() { - return NumberInfo(kHeapNumberType); +NumberInfo NumberInfo::Double() { + return NumberInfo(kDoubleType); } diff --git a/src/register-allocator-inl.h b/src/register-allocator-inl.h index 8453104ee2..396c73f9fe 100644 --- a/src/register-allocator-inl.h +++ b/src/register-allocator-inl.h @@ -106,13 +106,7 @@ void RegisterAllocator::Unuse(Register reg) { NumberInfo Result::number_info() const { ASSERT(is_valid()); - if (!is_constant()) { - return NumberInfo::FromInt(NumberInfoField::decode(value_)); - } - Handle value = handle(); - if (value->IsSmi()) return NumberInfo::Smi(); - if (value->IsHeapNumber()) return NumberInfo::HeapNumber(); - return NumberInfo::Unknown(); + return NumberInfo::FromInt(NumberInfoField::decode(value_)); } @@ -138,8 +132,8 @@ bool Result::is_integer32() const { } -bool Result::is_heap_number() const { - return number_info().IsHeapNumber(); +bool Result::is_double() const { + return number_info().IsDouble(); } } } // namespace v8::internal diff --git a/src/register-allocator.h b/src/register-allocator.h index 2382f8a658..5798fa2d16 100644 --- a/src/register-allocator.h +++ b/src/register-allocator.h @@ -29,7 +29,7 @@ #define V8_REGISTER_ALLOCATOR_H_ #include "macro-assembler.h" -#include "number-info.h" +#include "number-info-inl.h" #if V8_TARGET_ARCH_IA32 #include "ia32/register-allocator-ia32.h" @@ -69,8 +69,9 @@ class Result BASE_EMBEDDED { // Construct a Result whose value is a compile-time constant. explicit Result(Handle value) { + NumberInfo info = NumberInfo::TypeFromValue(value); value_ = TypeField::encode(CONSTANT) - | NumberInfoField::encode(NumberInfo::Uninitialized().ToInt()) + | NumberInfoField::encode(info.ToInt()) | IsUntaggedInt32Field::encode(false) | DataField::encode(ConstantList()->length()); ConstantList()->Add(value); @@ -107,7 +108,7 @@ class Result BASE_EMBEDDED { inline bool is_number() const; inline bool is_smi() const; inline bool is_integer32() const; - inline bool is_heap_number() const; + inline bool is_double() const; bool is_valid() const { return type() != INVALID; } bool is_register() const { return type() == REGISTER; } diff --git a/src/x64/virtual-frame-x64.cc b/src/x64/virtual-frame-x64.cc index 79be20b1bd..ca1042334d 100644 --- a/src/x64/virtual-frame-x64.cc +++ b/src/x64/virtual-frame-x64.cc @@ -211,12 +211,7 @@ void VirtualFrame::EmitPush(Smi* smi_value) { void VirtualFrame::EmitPush(Handle value) { ASSERT(stack_pointer_ == element_count() - 1); - NumberInfo info = NumberInfo::Unknown(); - if (value->IsSmi()) { - info = NumberInfo::Smi(); - } else if (value->IsHeapNumber()) { - info = NumberInfo::HeapNumber(); - } + NumberInfo info = NumberInfo::TypeFromValue(value); elements_.Add(FrameElement::MemoryElement(info)); stack_pointer_++; __ Push(value); diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index d53143784e..9517533b9a 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -330,6 +330,7 @@ '../../src/messages.cc', '../../src/messages.h', '../../src/natives.h', + '../../src/number-info-inl.h', '../../src/number-info.h', '../../src/objects-debug.cc', '../../src/objects-inl.h', diff --git a/tools/visual_studio/v8_base.vcproj b/tools/visual_studio/v8_base.vcproj index 193e2a0968..6ab09ef5ab 100644 --- a/tools/visual_studio/v8_base.vcproj +++ b/tools/visual_studio/v8_base.vcproj @@ -688,6 +688,10 @@ RelativePath="..\..\src\natives.h" > + + diff --git a/tools/visual_studio/v8_base_arm.vcproj b/tools/visual_studio/v8_base_arm.vcproj index 9043d58acc..34dfbd0675 100644 --- a/tools/visual_studio/v8_base_arm.vcproj +++ b/tools/visual_studio/v8_base_arm.vcproj @@ -668,6 +668,10 @@ RelativePath="..\..\src\natives.h" > + + diff --git a/tools/visual_studio/v8_base_x64.vcproj b/tools/visual_studio/v8_base_x64.vcproj index 30437530a9..852fc8fc7b 100644 --- a/tools/visual_studio/v8_base_x64.vcproj +++ b/tools/visual_studio/v8_base_x64.vcproj @@ -665,6 +665,10 @@ RelativePath="..\..\src\natives.h" > + +