From b2ca7e0b0a4cd9f3b12e1b108ad48e144b443292 Mon Sep 17 00:00:00 2001 From: "haitao.feng@intel.com" Date: Tue, 27 Aug 2013 14:13:40 +0000 Subject: [PATCH] Introduce SmiValuesAre31Bits and SmiValuesAre32Bits global predicate functions R=danno@chromium.org Review URL: https://codereview.chromium.org/22350005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16365 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 2 ++ src/hydrogen-instructions.cc | 2 +- src/hydrogen-instructions.h | 4 ++-- src/ic.cc | 6 +++--- src/x64/macro-assembler-x64.cc | 4 ++-- test/cctest/test-api.cc | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/v8.h b/include/v8.h index 5cba8d3..c29bba6 100644 --- a/include/v8.h +++ b/include/v8.h @@ -5383,6 +5383,8 @@ template <> struct SmiTagging<8> { typedef SmiTagging PlatformSmiTagging; const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; +V8_INLINE(static bool SmiValuesAre31Bits()) { return kSmiValueSize == 31; } +V8_INLINE(static bool SmiValuesAre32Bits()) { return kSmiValueSize == 32; } /** * This class exports constants and functionality from within v8 that diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 70197cf..7701b9e 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -2496,7 +2496,7 @@ static void PrepareConstant(Handle object) { void HConstant::Initialize(Representation r) { if (r.IsNone()) { - if (has_smi_value_ && kSmiValueSize == 31) { + if (has_smi_value_ && SmiValuesAre31Bits()) { r = Representation::Smi(); } else if (has_int32_value_) { r = Representation::Integer32(); diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index 5b937f3..59db99c 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -3335,7 +3335,7 @@ class HConstant V8_FINAL : public HTemplateInstruction<0> { } virtual Representation KnownOptimalRepresentation() V8_OVERRIDE { - if (HasSmiValue() && kSmiValueSize == 31) return Representation::Smi(); + if (HasSmiValue() && SmiValuesAre31Bits()) return Representation::Smi(); if (HasInteger32Value()) return Representation::Integer32(); if (HasNumberValue()) return Representation::Double(); if (HasExternalReferenceValue()) return Representation::External(); @@ -5841,7 +5841,7 @@ class ArrayInstructionInterface { virtual ~ArrayInstructionInterface() { }; static Representation KeyedAccessIndexRequirement(Representation r) { - return r.IsInteger32() || kSmiValueSize != 31 + return r.IsInteger32() || SmiValuesAre32Bits() ? Representation::Integer32() : Representation::Smi(); } }; diff --git a/src/ic.cc b/src/ic.cc index a8d3527..2a1f83d 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -2581,7 +2581,7 @@ static BinaryOpIC::TypeInfo TypeInfoFromValue(Handle value, v8::internal::TypeInfo type = v8::internal::TypeInfo::FromValue(value); if (type.IsSmi()) return BinaryOpIC::SMI; if (type.IsInteger32()) { - if (kSmiValueSize == 32) return BinaryOpIC::SMI; + if (SmiValuesAre32Bits()) return BinaryOpIC::SMI; return BinaryOpIC::INT32; } if (type.IsNumber()) return BinaryOpIC::NUMBER; @@ -2593,7 +2593,7 @@ static BinaryOpIC::TypeInfo TypeInfoFromValue(Handle value, op == Token::SAR || op == Token::SHL || op == Token::SHR) { - if (kSmiValueSize == 32) return BinaryOpIC::SMI; + if (SmiValuesAre32Bits()) return BinaryOpIC::SMI; return BinaryOpIC::INT32; } return BinaryOpIC::ODDBALL; @@ -2671,7 +2671,7 @@ RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { if (op == Token::DIV || op == Token::MUL || op == Token::SHR || - kSmiValueSize == 32) { + SmiValuesAre32Bits()) { // Arithmetic on two Smi inputs has yielded a heap number. // That is the only way to get here from the Smi stub. // With 32-bit Smis, all overflows give heap numbers, but with diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index 4ff4cea..5651b57 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -966,7 +966,7 @@ bool MacroAssembler::IsUnsafeInt(const int x) { void MacroAssembler::SafeMove(Register dst, Smi* src) { ASSERT(!dst.is(kScratchRegister)); - ASSERT(kSmiValueSize == 32); // JIT cookie can be converted to Smi. + ASSERT(SmiValuesAre32Bits()); // JIT cookie can be converted to Smi. if (IsUnsafeInt(src->value()) && jit_cookie() != 0) { Move(dst, Smi::FromInt(src->value() ^ jit_cookie())); Move(kScratchRegister, Smi::FromInt(jit_cookie())); @@ -978,7 +978,7 @@ void MacroAssembler::SafeMove(Register dst, Smi* src) { void MacroAssembler::SafePush(Smi* src) { - ASSERT(kSmiValueSize == 32); // JIT cookie can be converted to Smi. + ASSERT(SmiValuesAre32Bits()); // JIT cookie can be converted to Smi. if (IsUnsafeInt(src->value()) && jit_cookie() != 0) { Push(Smi::FromInt(src->value() ^ jit_cookie())); Move(kScratchRegister, Smi::FromInt(jit_cookie())); diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 1b0674d..c4e1366 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -1358,7 +1358,7 @@ THREADED_TEST(BigSmiInteger) { int32_t value = i::Smi::kMaxValue; // We cannot add one to a Smi::kMaxValue without wrapping. - if (i::kSmiValueSize < 32) { + if (i::SmiValuesAre31Bits()) { CHECK(i::Smi::IsValid(value)); CHECK(!i::Smi::IsValid(value + 1)); @@ -1377,7 +1377,7 @@ THREADED_TEST(BigInteger) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); // We cannot add one to a Smi::kMaxValue without wrapping. - if (i::kSmiValueSize < 32) { + if (i::SmiValuesAre31Bits()) { // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1. // The code will not be run in that case, due to the "if" guard. int32_t value = -- 2.7.4