From cee232e6a837190d0630f610b035647240021bb6 Mon Sep 17 00:00:00 2001 From: "haitao.feng@intel.com" Date: Thu, 10 Apr 2014 01:25:28 +0000 Subject: [PATCH] Update Integer32ToSmiField, SmiToInteger32, and SmiComprare to support 31-bit SMI for x32 port R=verwaest@chromium.org Review URL: https://codereview.chromium.org/222133003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20635 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/x64/assembler-x64.h | 4 +++ src/x64/macro-assembler-x64.cc | 56 ++++++++++++++++++++++++++++++++++++------ src/x64/macro-assembler-x64.h | 8 +++--- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/x64/assembler-x64.h b/src/x64/assembler-x64.h index 92d63d2..9009e4f 100644 --- a/src/x64/assembler-x64.h +++ b/src/x64/assembler-x64.h @@ -357,6 +357,10 @@ inline Condition ReverseCondition(Condition cc) { class Immediate BASE_EMBEDDED { public: explicit Immediate(int32_t value) : value_(value) {} + explicit Immediate(Smi* value) { + ASSERT(SmiValuesAre31Bits()); // Only available for 31-bit SMI. + value_ = static_cast(reinterpret_cast(value)); + } private: int32_t value_; diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index 422ab2d..f943177 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -1108,8 +1108,15 @@ void MacroAssembler::Integer32ToSmiField(const Operand& dst, Register src) { Abort(kInteger32ToSmiFieldWritingToNonSmiLocation); bind(&ok); } - ASSERT(kSmiShift % kBitsPerByte == 0); - movl(Operand(dst, kSmiShift / kBitsPerByte), src); + + if (SmiValuesAre32Bits()) { + ASSERT(kSmiShift % kBitsPerByte == 0); + movl(Operand(dst, kSmiShift / kBitsPerByte), src); + } else { + ASSERT(SmiValuesAre31Bits()); + Integer32ToSmi(kScratchRegister, src); + movp(dst, kScratchRegister); + } } @@ -1130,12 +1137,24 @@ void MacroAssembler::SmiToInteger32(Register dst, Register src) { if (!dst.is(src)) { movp(dst, src); } - shrq(dst, Immediate(kSmiShift)); + + if (SmiValuesAre32Bits()) { + shrp(dst, Immediate(kSmiShift)); + } else { + ASSERT(SmiValuesAre31Bits()); + sarl(dst, Immediate(kSmiShift)); + } } void MacroAssembler::SmiToInteger32(Register dst, const Operand& src) { - movl(dst, Operand(src, kSmiShift / kBitsPerByte)); + if (SmiValuesAre32Bits()) { + movl(dst, Operand(src, kSmiShift / kBitsPerByte)); + } else { + ASSERT(SmiValuesAre31Bits()); + movl(dst, src); + sarl(dst, Immediate(kSmiShift)); + } } @@ -1144,12 +1163,22 @@ void MacroAssembler::SmiToInteger64(Register dst, Register src) { if (!dst.is(src)) { movp(dst, src); } - sarq(dst, Immediate(kSmiShift)); + sarp(dst, Immediate(kSmiShift)); + if (kPointerSize == kInt32Size) { + // Sign extend to 64-bit. + movsxlq(dst, dst); + } } void MacroAssembler::SmiToInteger64(Register dst, const Operand& src) { - movsxlq(dst, Operand(src, kSmiShift / kBitsPerByte)); + if (SmiValuesAre32Bits()) { + movsxlq(dst, Operand(src, kSmiShift / kBitsPerByte)); + } else { + ASSERT(SmiValuesAre31Bits()); + movp(dst, src); + SmiToInteger64(dst, dst); + } } @@ -1199,7 +1228,12 @@ void MacroAssembler::SmiCompare(const Operand& dst, Register src) { void MacroAssembler::SmiCompare(const Operand& dst, Smi* src) { AssertSmi(dst); - cmpl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(src->value())); + if (SmiValuesAre32Bits()) { + cmpl(Operand(dst, kSmiShift / kBitsPerByte), Immediate(src->value())); + } else { + ASSERT(SmiValuesAre31Bits()); + cmpl(dst, Immediate(src)); + } } @@ -1212,7 +1246,13 @@ void MacroAssembler::Cmp(const Operand& dst, Smi* src) { void MacroAssembler::SmiCompareInteger32(const Operand& dst, Register src) { - cmpl(Operand(dst, kSmiShift / kBitsPerByte), src); + if (SmiValuesAre32Bits()) { + cmpl(Operand(dst, kSmiShift / kBitsPerByte), src); + } else { + ASSERT(SmiValuesAre31Bits()); + SmiToInteger32(kScratchRegister, dst); + cmpl(kScratchRegister, src); + } } diff --git a/src/x64/macro-assembler-x64.h b/src/x64/macro-assembler-x64.h index 7685adf..7448c19 100644 --- a/src/x64/macro-assembler-x64.h +++ b/src/x64/macro-assembler-x64.h @@ -657,10 +657,10 @@ class MacroAssembler: public Assembler { Register src, int shift_value); void SmiShiftLogicalRightConstant(Register dst, - Register src, - int shift_value, - Label* on_not_smi_result, - Label::Distance near_jump = Label::kFar); + Register src, + int shift_value, + Label* on_not_smi_result, + Label::Distance near_jump = Label::kFar); void SmiShiftArithmeticRightConstant(Register dst, Register src, int shift_value); -- 2.7.4