From: palfia@homejinni.com Date: Fri, 24 May 2013 01:06:57 +0000 (+0000) Subject: MIPS: Improve SeqStringSetChar implementation. X-Git-Tag: upstream/4.7.83~14142 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31080249c0f6496470654b77358543bb35ef1190;p=platform%2Fupstream%2Fv8.git MIPS: Improve SeqStringSetChar implementation. Port r14769 (f0000b20) BUG= Review URL: https://codereview.chromium.org/15949002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14785 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/mips/codegen-mips.cc b/src/mips/codegen-mips.cc index e874a08..72eb00b 100644 --- a/src/mips/codegen-mips.cc +++ b/src/mips/codegen-mips.cc @@ -514,50 +514,6 @@ void StringCharLoadGenerator::Generate(MacroAssembler* masm, } -void SeqStringSetCharGenerator::Generate(MacroAssembler* masm, - String::Encoding encoding, - Register string, - Register index, - Register value) { - if (FLAG_debug_code) { - __ And(at, index, Operand(kSmiTagMask)); - __ Check(eq, "Non-smi index", at, Operand(zero_reg)); - __ And(at, value, Operand(kSmiTagMask)); - __ Check(eq, "Non-smi value", at, Operand(zero_reg)); - - __ lw(at, FieldMemOperand(string, String::kLengthOffset)); - __ Check(lt, "Index is too large", index, Operand(at)); - - __ Check(ge, "Index is negative", index, Operand(zero_reg)); - - __ lw(at, FieldMemOperand(string, HeapObject::kMapOffset)); - __ lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset)); - - __ And(at, at, Operand(kStringRepresentationMask | kStringEncodingMask)); - static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; - static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; - __ Subu(at, at, Operand(encoding == String::ONE_BYTE_ENCODING - ? one_byte_seq_type : two_byte_seq_type)); - __ Check(eq, "Unexpected string type", at, Operand(zero_reg)); - } - - __ Addu(at, - string, - Operand(SeqString::kHeaderSize - kHeapObjectTag)); - __ SmiUntag(value); - STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); - if (encoding == String::ONE_BYTE_ENCODING) { - __ SmiUntag(index); - __ Addu(at, at, index); - __ sb(value, MemOperand(at)); - } else { - // No need to untag a smi for two-byte addressing. - __ Addu(at, at, index); - __ sh(value, MemOperand(at)); - } -} - - static MemOperand ExpConstant(int index, Register base) { return MemOperand(base, index * kDoubleSize); } diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc index bdfa43b..6a3b72d 100644 --- a/src/mips/full-codegen-mips.cc +++ b/src/mips/full-codegen-mips.cc @@ -3445,19 +3445,56 @@ void FullCodeGenerator::EmitDateField(CallRuntime* expr) { } +void FullCodeGenerator::EmitSeqStringSetCharCheck(Register string, + Register index, + Register value, + uint32_t encoding_mask) { + __ And(at, index, Operand(kSmiTagMask)); + __ Check(eq, "Non-smi index", at, Operand(zero_reg)); + __ And(at, value, Operand(kSmiTagMask)); + __ Check(eq, "Non-smi value", at, Operand(zero_reg)); + + __ lw(at, FieldMemOperand(string, String::kLengthOffset)); + __ Check(lt, "Index is too large", index, Operand(at)); + + __ Check(ge, "Index is negative", index, Operand(zero_reg)); + + __ lw(at, FieldMemOperand(string, HeapObject::kMapOffset)); + __ lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset)); + + __ And(at, at, Operand(kStringRepresentationMask | kStringEncodingMask)); + __ Subu(at, at, Operand(encoding_mask)); + __ Check(eq, "Unexpected string type", at, Operand(zero_reg)); +} + + void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { ZoneList* args = expr->arguments(); ASSERT_EQ(3, args->length()); + Register string = v0; + Register index = a1; + Register value = a2; + VisitForStackValue(args->at(1)); // index VisitForStackValue(args->at(2)); // value - __ pop(a2); - __ pop(a1); + __ pop(value); + __ pop(index); VisitForAccumulatorValue(args->at(0)); // string - static const String::Encoding encoding = String::ONE_BYTE_ENCODING; - SeqStringSetCharGenerator::Generate(masm_, encoding, v0, a1, a2); - context()->Plug(v0); + if (FLAG_debug_code) { + static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; + EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); + } + + __ SmiUntag(value, value); + __ Addu(at, + string, + Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); + __ SmiUntag(index); + __ Addu(at, at, index); + __ sb(value, MemOperand(at)); + context()->Plug(string); } @@ -3465,15 +3502,29 @@ void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { ZoneList* args = expr->arguments(); ASSERT_EQ(3, args->length()); + Register string = v0; + Register index = a1; + Register value = a2; + VisitForStackValue(args->at(1)); // index VisitForStackValue(args->at(2)); // value - __ pop(a2); - __ pop(a1); + __ pop(value); + __ pop(index); VisitForAccumulatorValue(args->at(0)); // string - static const String::Encoding encoding = String::TWO_BYTE_ENCODING; - SeqStringSetCharGenerator::Generate(masm_, encoding, v0, a1, a2); - context()->Plug(v0); + if (FLAG_debug_code) { + static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; + EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); + } + + __ SmiUntag(value, value); + __ Addu(at, + string, + Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); + __ Addu(at, at, index); + STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); + __ sh(value, MemOperand(at)); + context()->Plug(string); } diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index ae3a980..231a65f 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -1605,11 +1605,35 @@ void LCodeGen::DoDateField(LDateField* instr) { void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { - SeqStringSetCharGenerator::Generate(masm(), - instr->encoding(), - ToRegister(instr->string()), - ToRegister(instr->index()), - ToRegister(instr->value())); + Register string = ToRegister(instr->string()); + Register index = ToRegister(instr->index()); + Register value = ToRegister(instr->value()); + Register scratch = scratch0(); + String::Encoding encoding = instr->encoding(); + + if (FLAG_debug_code) { + __ lw(at, FieldMemOperand(string, HeapObject::kMapOffset)); + __ lbu(at, FieldMemOperand(at, Map::kInstanceTypeOffset)); + + __ And(at, at, Operand(kStringRepresentationMask | kStringEncodingMask)); + static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; + static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; + __ Subu(at, at, Operand(encoding == String::ONE_BYTE_ENCODING + ? one_byte_seq_type : two_byte_seq_type)); + __ Check(eq, "Unexpected string type", at, Operand(zero_reg)); + } + + __ Addu(scratch, + string, + Operand(SeqString::kHeaderSize - kHeapObjectTag)); + if (encoding == String::ONE_BYTE_ENCODING) { + __ Addu(at, scratch, index); + __ sb(value, MemOperand(at)); + } else { + __ sll(at, index, 1); + __ Addu(at, scratch, at); + __ sh(value, MemOperand(at)); + } }